broadphase-callbacks.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2022 INRIA
3 //
4 
5 #ifndef __pinocchio_collision_broadphase_callback_hpp__
6 #define __pinocchio_collision_broadphase_callback_hpp__
7 
9 
12 
14 
15 namespace pinocchio
16 {
17 
20  {
21  CollisionCallBackBase(const GeometryModel & geometry_model, GeometryData & geometry_data)
22  : geometry_model_ptr(&geometry_model)
23  , geometry_data_ptr(&geometry_data)
24  , collision(false)
25  , accumulate(false)
26  {
27  }
28 
30  {
31  return *geometry_model_ptr;
32  }
33  const GeometryData & getGeometryData() const
34  {
35  return *geometry_data_ptr;
36  }
38  {
39  return *geometry_data_ptr;
40  }
41 
44  virtual bool stop() const = 0;
45 
48  virtual void done() {};
49 
50  protected:
53 
56 
57  public:
59  bool collision;
60 
63  bool accumulate;
64  };
65 
67  {
69  const GeometryModel & geometry_model,
70  GeometryData & geometry_data,
71  bool stopAtFirstCollision = false)
72  : CollisionCallBackBase(geometry_model, geometry_data)
74  , count(0)
75  // , visited(Eigen::MatrixXd::Zero(geometry_model.ngeoms,geometry_model.ngeoms))
76  {
77  }
78 
79  void init()
80  {
81  if (accumulate) // skip reseting of the parameters
82  return;
83 
84  count = 0;
85  collision = false;
87  // visited.setZero();
88  }
89 
91  {
92 
93  assert(!stop() && "must never happened");
94 
95  CollisionObject & co1 = reinterpret_cast<CollisionObject &>(*o1);
96  CollisionObject & co2 = reinterpret_cast<CollisionObject &>(*o2);
97 
98  const Eigen::DenseIndex go1_index = (Eigen::DenseIndex)co1.geometryObjectIndex;
99  const Eigen::DenseIndex go2_index = (Eigen::DenseIndex)co2.geometryObjectIndex;
100 
101  const GeometryModel & geometry_model = *geometry_model_ptr;
102 
104  go1_index < (Eigen::DenseIndex)geometry_model.ngeoms && go1_index >= 0);
106  go2_index < (Eigen::DenseIndex)geometry_model.ngeoms && go2_index >= 0);
107 
108  const int pair_index = geometry_model.collisionPairMapping(go1_index, go2_index);
109  if (pair_index == -1)
110  return false;
111 
112  const GeometryData & geometry_data = *geometry_data_ptr;
113  const CollisionPair & cp = geometry_model.collisionPairs[(PairIndex)pair_index];
114  const bool do_collision_check =
115  geometry_data.activeCollisionPairs[(PairIndex)pair_index]
116  && !(
117  geometry_model.geometryObjects[cp.first].disableCollision
118  || geometry_model.geometryObjects[cp.second].disableCollision);
119  if (!do_collision_check)
120  return false;
121 
122  count++;
123 
124  fcl::CollisionRequest collision_request(
125  geometry_data_ptr->collisionRequests[size_t(pair_index)]);
126  collision_request.gjk_variant = fcl::GJKVariant::NesterovAcceleration;
127  // collision_request.gjk_initial_guess = fcl::GJKInitialGuess::BoundingVolumeGuess;
128 
129  if (
130  co1.collisionGeometry().get()
131  != geometry_model.geometryObjects[size_t(go1_index)].geometry.get()
132  || co2.collisionGeometry().get()
133  != geometry_model.geometryObjects[size_t(go2_index)].geometry.get())
135  std::logic_error, "go1: " << go1_index << " or go2: " << go2_index
136  << " have not been updated and have missmatching pointers.");
137  // if(!(co1.collisionGeometry()->aabb_local.volume() < 0 ||
138  // co2.collisionGeometry()->aabb_local.volume() <0)) { // TODO(jcarpent): check potential
139  // bug
140  // collision_request.gjk_initial_guess = fcl::GJKInitialGuess::BoundingVolumeGuess;
141  // }
142 
143  bool res;
144  try
145  {
147  *geometry_model_ptr, *geometry_data_ptr, (PairIndex)pair_index, collision_request);
148  }
149  catch (std::logic_error & e)
150  {
152  std::logic_error, "Geometries with index go1: "
153  << go1_index << " or go2: " << go2_index
154  << " have produced an internal error within HPP-FCL.\n what:\n"
155  << e.what());
156  }
157 
158  if (res && !collision)
159  {
160  collision = true;
161  collisionPairIndex = (PairIndex)pair_index;
162  }
163 
165  return false;
166  else
167  return res;
168  }
169 
170  bool stop() const final
171  {
173  return true;
174 
175  return false;
176  }
177 
178  void done() final
179  {
180  if (collision)
181  geometry_data_ptr->collisionPairIndex = collisionPairIndex;
182  }
183 
186 
189 
191  size_t count;
192 
193  // Eigen::MatrixXd visited;
194  };
195 
196 } // namespace pinocchio
197 
198 /* --- Details -------------------------------------------------------------------- */
199 #include "pinocchio/collision/broadphase-callbacks.hxx"
200 
201 #endif // ifndef __pinocchio_collision_broadphase_callback_hpp__
pinocchio::CollisionCallBackBase::getGeometryData
GeometryData & getGeometryData()
Definition: broadphase-callbacks.hpp:37
pinocchio::CollisionCallBackDefault::stopAtFirstCollision
bool stopAtFirstCollision
Whether to stop or not when localizing a first collision.
Definition: broadphase-callbacks.hpp:185
PINOCCHIO_CHECK_INPUT_ARGUMENT
#define PINOCCHIO_CHECK_INPUT_ARGUMENT(...)
Macro to check an assert-like condition and throw a std::invalid_argument exception (with a message) ...
Definition: include/pinocchio/macros.hpp:192
pinocchio::CollisionCallBackDefault::stop
bool stop() const final
If true, the stopping criteria related to the collision callback has been met and one can stop.
Definition: broadphase-callbacks.hpp:170
broadphase_callbacks.h
pinocchio::CollisionCallBackBase::accumulate
bool accumulate
Whether the callback is used in an accumulate mode where several collide methods are called successiv...
Definition: broadphase-callbacks.hpp:63
pinocchio::CollisionCallBackDefault::init
void init()
Definition: broadphase-callbacks.hpp:79
CollisionObject
CollisionObject(const shared_ptr< CollisionGeometry > &cgeom_, bool compute_local_aabb=true)
pinocchio::CollisionCallBackDefault
Definition: broadphase-callbacks.hpp:66
pinocchio::CollisionCallBackBase::getGeometryModel
const GeometryModel & getGeometryModel() const
Definition: broadphase-callbacks.hpp:29
pinocchio::res
ReturnType res
Definition: spatial/classic-acceleration.hpp:57
pinocchio::GeometryData
Definition: multibody/geometry.hpp:233
pinocchio::CollisionCallBackBase::CollisionCallBackBase
CollisionCallBackBase(const GeometryModel &geometry_model, GeometryData &geometry_data)
Definition: broadphase-callbacks.hpp:21
pinocchio::CollisionCallBackBase
Interface for Pinocchio collision callback functors.
Definition: broadphase-callbacks.hpp:19
collision.hpp
fcl.hpp
pinocchio::GeometryModel::geometryObjects
GeometryObjectVector geometryObjects
Vector of GeometryObjects used for collision computations.
Definition: multibody/geometry.hpp:217
pinocchio::CollisionPair
Definition: multibody/geometry.hpp:21
pinocchio::CollisionCallBackBase::stop
virtual bool stop() const =0
If true, the stopping criteria related to the collision callback has been met and one can stop.
pinocchio::GeometryModel::collisionPairMapping
MatrixXi collisionPairMapping
Matrix relating the collision pair ID to a pair of two GeometryObject indexes.
Definition: multibody/geometry.hpp:223
pinocchio::GeometryData::activeCollisionPairs
std::vector< bool > activeCollisionPairs
Vector of collision pairs.
Definition: multibody/geometry.hpp:267
PINOCCHIO_THROW_PRETTY
#define PINOCCHIO_THROW_PRETTY(exception, message)
Definition: include/pinocchio/macros.hpp:164
hpp::fcl::CollisionObject
pinocchio::PairIndex
Index PairIndex
Definition: multibody/fwd.hpp:29
geometry.hpp
pinocchio::computeCollision
bool computeCollision(const GeometryModel &geom_model, GeometryData &geom_data, const PairIndex pair_id, fcl::CollisionRequest &collision_request)
Compute the collision status between a SINGLE collision pair. The result is store in the collisionRes...
pinocchio::CollisionCallBackDefault::CollisionCallBackDefault
CollisionCallBackDefault(const GeometryModel &geometry_model, GeometryData &geometry_data, bool stopAtFirstCollision=false)
Definition: broadphase-callbacks.hpp:68
pinocchio::CollisionCallBackDefault::count
size_t count
Number of visits of the collide method.
Definition: broadphase-callbacks.hpp:191
pinocchio::GeometryModel::ngeoms
Index ngeoms
The number of GeometryObjects.
Definition: multibody/geometry.hpp:214
pinocchio::CollisionCallBackDefault::collisionPairIndex
PairIndex collisionPairIndex
The collision index of the first pair in collision.
Definition: broadphase-callbacks.hpp:188
pinocchio::CollisionCallBackDefault::collide
bool collide(hpp::fcl::CollisionObject *o1, hpp::fcl::CollisionObject *o2)
Definition: broadphase-callbacks.hpp:90
collision
collisions.cp
cp
Definition: collisions.py:51
pinocchio::CollisionCallBackBase::geometry_model_ptr
const GeometryModel * geometry_model_ptr
Geometry model associated to the callback.
Definition: broadphase-callbacks.hpp:48
pinocchio::GeometryModel::collisionPairs
CollisionPairVector collisionPairs
Vector of collision pairs.
Definition: multibody/geometry.hpp:220
hpp::fcl::CollisionCallBackBase
pinocchio::GeometryModel
Definition: multibody/geometry.hpp:50
pinocchio::CollisionCallBackBase::collision
bool collision
Whether there is a collision or not.
Definition: broadphase-callbacks.hpp:59
pinocchio::CollisionCallBackBase::getGeometryData
const GeometryData & getGeometryData() const
Definition: broadphase-callbacks.hpp:33
pinocchio::CollisionCallBackBase::geometry_data_ptr
GeometryData * geometry_data_ptr
Geometry data associated to the callback.
Definition: broadphase-callbacks.hpp:55
pinocchio::CollisionCallBackBase::done
virtual void done()
Callback method called after the termination of a collisition detection algorithm....
Definition: broadphase-callbacks.hpp:48
CppAD::max
AD< Scalar > max(const AD< Scalar > &x, const AD< Scalar > &y)
Definition: autodiff/cppad.hpp:181
pinocchio::CollisionCallBackDefault::done
void done() final
Callback method called after the termination of a collisition detection algorithm....
Definition: broadphase-callbacks.hpp:178
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:39