pinocchio  3.2.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
broadphase-manager.hpp
1 //
2 // Copyright (c) 2022 INRIA
3 //
4 
5 #ifndef __pinocchio_collision_broadphase_manager_hpp__
6 #define __pinocchio_collision_broadphase_manager_hpp__
7 
8 #include <hpp/fcl/broadphase/broadphase_collision_manager.h>
9 
10 #include "pinocchio/collision/broadphase-manager-base.hpp"
11 #include "pinocchio/multibody/geometry-object-filter.hpp"
12 
13 namespace pinocchio
14 {
15 
16  template<typename _Manager>
17  struct BroadPhaseManagerTpl : public BroadPhaseManagerBase<BroadPhaseManagerTpl<_Manager>>
18  {
19  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
20 
22  typedef std::vector<CollisionObject> CollisionObjectVector;
23  typedef Eigen::VectorXd VectorXs;
24  typedef _Manager Manager;
25 
26  typedef ::pinocchio::Model Model;
27  typedef ::pinocchio::GeometryModel GeometryModel;
28  typedef ::pinocchio::GeometryData GeometryData;
29 
31  BroadPhaseManagerTpl() // for std::vector
32  : Base()
33  {
34  }
35 
43  const Model * model_ptr,
48  {
49  const GeometryModel & geom_model = *geometry_model_ptr;
50  selected_geometry_objects = filter.apply(geom_model.geometryObjects);
51 
53  geometry_model_ptr->geometryObjects.size(), (std::numeric_limits<size_t>::max)());
55  for (size_t k = 0; k < selected_geometry_objects.size(); ++k)
56  {
57  const size_t geometry_id = selected_geometry_objects[k];
58  geometry_to_collision_index[geometry_id] = k;
59  collision_object_is_active[k] = !geom_model.geometryObjects[geometry_id].disableCollision;
60  }
61 
62  selected_collision_pairs.reserve(geom_model.collisionPairs.size());
63  for (size_t k = 0; k < geom_model.collisionPairs.size(); ++k)
64  {
65  const CollisionPair & pair = geom_model.collisionPairs[k];
66  if (
67  geometry_to_collision_index[pair.first] != (std::numeric_limits<size_t>::max)()
68  && geometry_to_collision_index[pair.second] != (std::numeric_limits<size_t>::max)())
69  {
70  selected_collision_pairs.push_back(k);
71  }
72 
74  }
75 
77  static_cast<Eigen::DenseIndex>(selected_geometry_objects.size()));
78 
79  init();
80  }
81 
87  : Base(other)
93  {
94  init();
95  }
96 
99  using Base::getModel;
100 
108  void update(bool compute_local_aabb = false);
109 
115  void update(GeometryData * geom_data_ptr_new);
116 
118 
121  bool check() const;
122 
124  bool check(CollisionCallBackBase * callback) const;
125 
127  const CollisionObjectVector & getCollisionObjects() const
128  {
129  return collision_objects;
130  }
132  CollisionObjectVector & getCollisionObjects()
133  {
134  return collision_objects;
135  }
136 
138  const VectorXs & getCollisionObjectInflation()
139  {
141  }
142 
145  bool collide(CollisionObject & obj, CollisionCallBackBase * callback) const;
146 
148  bool collide(CollisionCallBackBase * callback) const;
149 
151  bool collide(BroadPhaseManagerTpl & other_manager, CollisionCallBackBase * callback) const;
152 
153  // /// @brief Performs distance computation between one object and all the objects belonging to
154  // the manager void distance(CollisionObject* obj, DistanceCallBackBase * callback) const;
155 
156  // /// @brief Performs distance test for the objects belonging to the manager (i.e., N^2 self
157  // distance) void distance(DistanceCallBackBase * callback) const;
158 
159  // /// @brief Performs distance test with objects belonging to another manager
160  // void distance(BroadPhaseCollisionManager* other_manager, DistanceCallBackBase * callback)
161  // const;
162 
164  Manager & getManager()
165  {
166  return manager;
167  }
168 
170  const Manager & getManager() const
171  {
172  return manager;
173  }
174 
176  const std::vector<bool> & getCollisionObjectStatus() const
177  {
179  }
180 
181  protected:
183  Manager manager;
184 
186  CollisionObjectVector collision_objects;
187 
190 
192  std::vector<size_t> selected_geometry_objects;
193 
195  std::vector<size_t> geometry_to_collision_index;
196 
198  std::vector<size_t> selected_collision_pairs;
199 
201  std::vector<bool> collision_object_is_active;
202 
204  void init();
205 
206  }; // struct BroadPhaseManagerTpl<BroadPhaseManagerDerived>
207 
208 } // namespace pinocchio
209 
210 /* --- Details -------------------------------------------------------------------- */
211 #include "pinocchio/collision/broadphase-manager.hxx"
212 
213 #endif // ifndef __pinocchio_collision_broadphase_manager_hpp__
Main pinocchio namespace.
Definition: treeview.dox:11
const GeometryModel & getGeometryModel() const
Returns the geometry model associated to the manager.
const Model & getModel() const
Returns the model associated to the manager.
const GeometryModel * geometry_model_ptr
Pointer to the geometry model.
const GeometryData & getGeometryData() const
Returns the geometry data associated to the manager.
void init()
Initialialisation of BroadPhaseManagerTpl.
void update(GeometryData *geom_data_ptr_new)
Update the manager with a new geometry data.
std::vector< bool > collision_object_is_active
Disable status related to each collision objects.
BroadPhaseManagerTpl(const BroadPhaseManagerTpl &other)
Copy contructor.
Manager & getManager()
Returns internal manager.
const Manager & getManager() const
Returns internal manager.
std::vector< size_t > geometry_to_collision_index
Mapping between a given geometry index and a collision index.
bool collide(CollisionObject &obj, CollisionCallBackBase *callback) const
Performs collision test between one object and all the objects belonging to the manager.
CollisionObjectVector collision_objects
the vector of collision objects.
CollisionObjectVector & getCollisionObjects()
Returns the vector of collision objects associated to the manager.
VectorXs collision_object_inflation
the inflation value related to each collision object.
BroadPhaseManagerTpl()
Default constructor.
BroadPhaseManagerTpl(const Model *model_ptr, const GeometryModel *geometry_model_ptr, GeometryData *geometry_data_ptr, const GeometryObjectFilterBase &filter=GeometryObjectFilterNothing())
Constructor from a given geometry model and data.
const CollisionObjectVector & getCollisionObjects() const
Returns the vector of collision objects associated to the manager.
bool check() const
Check whether the base broad phase manager is aligned with the current collision_objects.
bool check(CollisionCallBackBase *callback) const
Check whether the callback is inline with *this.
std::vector< size_t > selected_collision_pairs
Selected collision pairs in the original geometry_model.
const std::vector< bool > & getCollisionObjectStatus() const
Returns the status of the collision object.
const VectorXs & getCollisionObjectInflation()
Returns the inflation value related to each collision object.
bool collide(BroadPhaseManagerTpl &other_manager, CollisionCallBackBase *callback) const
Performs collision test with objects belonging to another manager.
std::vector< size_t > selected_geometry_objects
Selected geometry objects in the original geometry_model.
void update(bool compute_local_aabb=false)
Update the manager from the current geometry positions and update the underlying FCL broad phase mana...
bool collide(CollisionCallBackBase *callback) const
Performs collision test for the objects belonging to the manager.
Interface for Pinocchio collision callback functors.
GeometryObjectVector geometryObjects
Vector of GeometryObjects used for collision computations.
Definition: geometry.hpp:217
CollisionPairVector collisionPairs
Vector of collision pairs.
Definition: geometry.hpp:220