Program Listing for File default_broadphase_callbacks.h

Return to documentation for file (/tmp/ws/src/hpp-fcl/include/hpp/fcl/broadphase/default_broadphase_callbacks.h)

/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2020, Toyota Research Institute
 *  Copyright (c) 2022, INRIA
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of the copyright holder nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef HPP_FCL_BROADPHASE_DEFAULT_BROADPHASE_CALLBACKS_H
#define HPP_FCL_BROADPHASE_DEFAULT_BROADPHASE_CALLBACKS_H

#include "hpp/fcl/broadphase/broadphase_callbacks.h"
#include "hpp/fcl/collision.h"
#include "hpp/fcl/distance.h"
// #include "hpp/fcl/narrowphase/continuous_collision.h"
// #include "hpp/fcl/narrowphase/continuous_collision_request.h"
// #include "hpp/fcl/narrowphase/continuous_collision_result.h"
// #include "hpp/fcl/narrowphase/distance_request.h"
// #include "hpp/fcl/narrowphase/distance_result.h"

namespace hpp {
namespace fcl {

struct CollisionData {
  CollisionData() { done = false; }

  CollisionRequest request;

  CollisionResult result;

  bool done;

  void clear() {
    result.clear();
    done = false;
  }
};

struct DistanceData {
  DistanceData() { done = false; }

  DistanceRequest request;

  DistanceResult result;

  bool done;

  void clear() {
    result.clear();
    done = false;
  }
};

bool defaultCollisionFunction(CollisionObject* o1, CollisionObject* o2,
                              void* data);

// struct DefaultContinuousCollisionData {
//   ContinuousCollisionRequest request;
//   ContinuousCollisionResult result;
//
//   /// If `true`, requests that the broadphase evaluation stop.
//   bool done{false};
// };

// bool DefaultContinuousCollisionFunction(ContinuousCollisionObject* o1,
//                                         ContinuousCollisionObject* o2,
//                                         void* data) {
//   assert(data != nullptr);
//   auto* cdata = static_cast<DefaultContinuousCollisionData*>(data);
//
//   if (cdata->done) return true;
//
//   const ContinuousCollisionRequest& request = cdata->request;
//   ContinuousCollisionResult& result = cdata->result;
//   collide(o1, o2, request, result);
//
//   return cdata->done;
// }

bool defaultDistanceFunction(CollisionObject* o1, CollisionObject* o2,
                             void* data, FCL_REAL& dist);

struct HPP_FCL_DLLAPI CollisionCallBackDefault : CollisionCallBackBase {
  void init() { data.clear(); }

  bool collide(CollisionObject* o1, CollisionObject* o2);

  CollisionData data;

  virtual ~CollisionCallBackDefault(){};
};

struct HPP_FCL_DLLAPI DistanceCallBackDefault : DistanceCallBackBase {
  void init() { data.clear(); }

  bool distance(CollisionObject* o1, CollisionObject* o2, FCL_REAL& dist);

  DistanceData data;

  virtual ~DistanceCallBackDefault(){};
};

struct HPP_FCL_DLLAPI CollisionCallBackCollect : CollisionCallBackBase {
  typedef std::pair<CollisionObject*, CollisionObject*> CollisionPair;

  CollisionCallBackCollect(const size_t max_size);

  bool collide(CollisionObject* o1, CollisionObject* o2);

  size_t numCollisionPairs() const;

  const std::vector<CollisionPair>& getCollisionPairs() const;

  void init();

  bool exist(const CollisionPair& pair) const;

  virtual ~CollisionCallBackCollect(){};

 protected:
  std::vector<CollisionPair> collision_pairs;
  size_t max_size;
};

}  // namespace fcl

}  // namespace hpp

#endif  // HPP_FCL_BROADPHASE_DEFAULT_BROADPHASE_CALLBACKS_H