pinocchio  3.3.1
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
geometry.hpp
1 //
2 // Copyright (c) 2015-2023 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_multibody_geometry_hpp__
6 #define __pinocchio_multibody_geometry_hpp__
7 
8 #include "pinocchio/multibody/geometry-object.hpp"
9 #include "pinocchio/container/aligned-vector.hpp"
10 
11 #include "pinocchio/serialization/serializable.hpp"
12 
13 #include <map>
14 #include <list>
15 #include <utility>
16 #include <assert.h>
17 
18 namespace pinocchio
19 {
20 
21  struct CollisionPair : public std::pair<GeomIndex, GeomIndex>
22  {
23 
24  typedef std::pair<GeomIndex, GeomIndex> Base;
25 
28 
36  CollisionPair(const GeomIndex co1, const GeomIndex co2);
37  bool operator==(const CollisionPair & rhs) const;
38  bool operator!=(const CollisionPair & rhs) const;
39  void disp(std::ostream & os) const;
40  friend std::ostream & operator<<(std::ostream & os, const CollisionPair & X);
41 
42  }; // struct CollisionPair
43 
44  template<>
46  {
47  typedef context::Scalar Scalar;
48  };
49 
51  : NumericalBase<GeometryModel>
52  , serialization::Serializable<GeometryModel>
53  {
54  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
55 
56  typedef context::Scalar Scalar;
57  enum
58  {
59  Options = context::Options
60  };
61 
63 
64  typedef ::pinocchio::GeometryObject GeometryObject;
65  typedef PINOCCHIO_ALIGNED_STD_VECTOR(GeometryObject) GeometryObjectVector;
66  typedef std::vector<CollisionPair> CollisionPairVector;
67  typedef Eigen::Matrix<bool, Eigen::Dynamic, Eigen::Dynamic, Options> MatrixXb;
68  typedef Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Options> MatrixXi;
69 
70  typedef pinocchio::GeomIndex GeomIndex;
71 
73  : ngeoms(0)
74  , geometryObjects()
75  , collisionPairs()
76  {
77  }
78 
79  GeometryModel(const GeometryModel & other) = default;
80 
81  ~GeometryModel() {};
82 
92  template<typename S2, int O2, template<typename, int> class _JointCollectionTpl>
93  GeomIndex addGeometryObject(
94  const GeometryObject & object, const ModelTpl<S2, O2, _JointCollectionTpl> & model);
95 
103  GeomIndex addGeometryObject(const GeometryObject & object);
104 
112  void removeGeometryObject(const std::string & name);
113 
121  GeomIndex getGeometryId(const std::string & name) const;
122 
130  bool existGeometryName(const std::string & name) const;
131 
138  void addCollisionPair(const CollisionPair & pair);
139 
146 
155  void setCollisionPairs(const MatrixXb & collision_map, const bool upper = true);
156 
162  void removeCollisionPair(const CollisionPair & pair);
163 
168 
177  bool existCollisionPair(const CollisionPair & pair) const;
178 
186  PairIndex findCollisionPair(const CollisionPair & pair) const;
187 
192 
196  bool operator==(const GeometryModel & other) const
197  {
198  return ngeoms == other.ngeoms && geometryObjects == other.geometryObjects
199  && collisionPairs == other.collisionPairs
201  }
202 
206  bool operator!=(const GeometryModel & other) const
207  {
208  return !(*this == other);
209  }
210 
211  friend std::ostream & operator<<(std::ostream & os, const GeometryModel & model_geom);
212 
214  Index ngeoms;
215 
217  GeometryObjectVector geometryObjects;
218 
220  CollisionPairVector collisionPairs;
221 
224 
225  }; // struct GeometryModel
226 
227  template<>
229  {
230  typedef context::Scalar Scalar;
231  };
232 
234  : NumericalBase<GeometryData>
235  , serialization::Serializable<GeometryData>
236  {
237  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
238 
239  typedef context::Scalar Scalar;
240  enum
241  {
242  Options = context::Options
243  };
244 
246  typedef std::vector<GeomIndex> GeomIndexList;
247  typedef Eigen::Matrix<bool, Eigen::Dynamic, Eigen::Dynamic, Options> MatrixXb;
248  typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options> MatrixXs;
249 
250 #ifdef PINOCCHIO_WITH_HPP_FCL
251  typedef ::pinocchio::ComputeCollision ComputeCollision;
252  typedef ::pinocchio::ComputeDistance ComputeDistance;
253 #endif
254 
263 
267  std::vector<bool> activeCollisionPairs;
268 
269 #ifdef PINOCCHIO_WITH_HPP_FCL
270 
274  std::vector<fcl::DistanceRequest> distanceRequests;
275 
279  std::vector<fcl::DistanceResult> distanceResults;
280 
284  std::vector<fcl::CollisionRequest> collisionRequests;
285 
289  std::vector<fcl::CollisionResult> collisionResults;
290 
295  std::vector<Scalar> radius;
296 
304 
307 
310 
311 #endif // PINOCCHIO_WITH_HPP_FCL
312 
318  std::map<JointIndex, GeomIndexList> innerObjects;
319 
324  std::map<JointIndex, GeomIndexList> outerObjects;
325 
331  explicit GeometryData(const GeometryModel & geom_model);
332 
338  GeometryData(const GeometryData & other);
339 
346 
349 
352 
362  void fillInnerOuterObjectMaps(const GeometryModel & geomModel);
363 
377  void activateCollisionPair(const PairIndex pair_id);
378 
386 
396  const GeometryModel & geom_model, const MatrixXb & collision_map, const bool upper = true);
397 
407  const GeometryModel & geom_model, const GeomIndex geom_id, bool enable_collision);
408 
418  void deactivateCollisionPair(const PairIndex pair_id);
419 
427 
428 #ifdef PINOCCHIO_WITH_HPP_FCL
440  const GeometryModel & geom_model,
441  const MatrixXs & security_margin_map,
442  const bool upper = true,
443  const bool sync_distance_upper_bound = false);
444 
445 #endif // ifdef PINOCCHIO_WITH_HPP_FCL
446 
447  friend std::ostream & operator<<(std::ostream & os, const GeometryData & geomData);
448 
452  bool operator==(const GeometryData & other) const
453  {
454  return oMg == other.oMg && activeCollisionPairs == other.activeCollisionPairs
455 #ifdef PINOCCHIO_WITH_HPP_FCL
457  && distanceResults == other.distanceResults
459  && collisionResults == other.collisionResults && radius == other.radius
461 #endif
462  && innerObjects == other.innerObjects && outerObjects == other.outerObjects;
463  }
464 
468  bool operator!=(const GeometryData & other) const
469  {
470  return !(*this == other);
471  }
472 
473  }; // struct GeometryData
474 
475 } // namespace pinocchio
476 
477 /* --- Details -------------------------------------------------------------- */
478 /* --- Details -------------------------------------------------------------- */
479 /* --- Details -------------------------------------------------------------- */
480 #include "pinocchio/multibody/geometry.hxx"
481 
482 #endif // ifndef __pinocchio_multibody_geometry_hpp__
Main pinocchio namespace.
Definition: treeview.dox:11
std::string name(const LieGroupGenericTpl< LieGroupCollection > &lg)
Visit a LieGroupVariant to get the name of it.
CollisionPair()
Empty constructor.
CollisionPair(const GeomIndex co1, const GeomIndex co2)
Default constructor of a collision pair from two collision object indexes.
void deactivateCollisionPair(const PairIndex pair_id)
std::vector< fcl::CollisionRequest > collisionRequests
Defines what information should be computed by collision test. There is one request per pair of geome...
Definition: geometry.hpp:284
void setActiveCollisionPairs(const GeometryModel &geom_model, const MatrixXb &collision_map, const bool upper=true)
Set the collision pair association from a given input array. Each entry of the input matrix defines t...
void activateAllCollisionPairs()
Activate all collision pairs.
GeometryData()
Empty constructor.
Definition: geometry.hpp:348
PairIndex collisionPairIndex
Index of the collision pair.
Definition: geometry.hpp:303
GeometryData & operator=(const GeometryData &other)
Copy operator.
std::vector< Scalar > radius
Radius of the bodies, i.e. distance of the further point of the geometry model attached to the body f...
Definition: geometry.hpp:295
void activateCollisionPair(const PairIndex pair_id)
void deactivateAllCollisionPairs()
Deactivate all collision pairs.
void setSecurityMargins(const GeometryModel &geom_model, const MatrixXs &security_margin_map, const bool upper=true, const bool sync_distance_upper_bound=false)
Set the security margin of all the collision request in a row, according to the values stored in the ...
std::vector< fcl::DistanceResult > distanceResults
Vector gathering the result of the distance computation for all the collision pairs.
Definition: geometry.hpp:279
std::map< JointIndex, GeomIndexList > outerObjects
A list of associated collision GeometryObjects to a given joint Id.
Definition: geometry.hpp:324
std::vector< bool > activeCollisionPairs
Vector of collision pairs.
Definition: geometry.hpp:267
GeometryData(const GeometryData &other)
Copy constructor.
std::vector< fcl::CollisionResult > collisionResults
Vector gathering the result of the collision computation for all the collision pairs.
Definition: geometry.hpp:289
bool operator!=(const GeometryData &other) const
Returns true if *this and other are not equal.
Definition: geometry.hpp:468
PINOCCHIO_ALIGNED_STD_VECTOR(ComputeDistance) distance_functors
&#160;
PINOCCHIO_ALIGNED_STD_VECTOR(SE3) oMg
Vector gathering the SE3 placements of the geometry objects relative to the world....
std::vector< fcl::DistanceRequest > distanceRequests
Defines what information should be computed by distance computation. There is one request per pair of...
Definition: geometry.hpp:274
bool operator==(const GeometryData &other) const
Returns true if *this and other are equal.
Definition: geometry.hpp:452
GeometryData(const GeometryModel &geom_model)
Default constructor from a GeometryModel.
~GeometryData()
Destructor.
void setGeometryCollisionStatus(const GeometryModel &geom_model, const GeomIndex geom_id, bool enable_collision)
Enable or disable collision for the given geometry given by its geometry id with all the other geomet...
PINOCCHIO_ALIGNED_STD_VECTOR(ComputeCollision) collision_functors
&#160;
void fillInnerOuterObjectMaps(const GeometryModel &geomModel)
std::map< JointIndex, GeomIndexList > innerObjects
Map over vector GeomModel::geometryObjects, indexed by joints.
Definition: geometry.hpp:318
void setCollisionPairs(const MatrixXb &collision_map, const bool upper=true)
Set the collision pairs from a given input array. Each entry of the input matrix defines the activati...
GeomIndex addGeometryObject(const GeometryObject &object, const ModelTpl< S2, O2, _JointCollectionTpl > &model)
Add a geometry object to a GeometryModel and set its parent joint.
PairIndex findCollisionPair(const CollisionPair &pair) const
Return the index of a given collision pair in collisionPairs.
bool existCollisionPair(const CollisionPair &pair) const
Check if a collision pair exists in collisionPairs. See also findCollisitionPair(const CollisionPair ...
void removeAllCollisionPairs()
Remove all collision pairs from collisionPairs. Same as collisionPairs.clear().
void addCollisionPair(const CollisionPair &pair)
Add a collision pair into the vector of collision_pairs. The method check before if the given Collisi...
bool operator==(const GeometryModel &other) const
Returns true if *this and other are equal.
Definition: geometry.hpp:196
GeometryObjectVector geometryObjects
Vector of GeometryObjects used for collision computations.
Definition: geometry.hpp:217
GeomIndex getGeometryId(const std::string &name) const
Return the index of a GeometryObject given by its name.
bool existGeometryName(const std::string &name) const
Check if a GeometryObject given by its name exists.
MatrixXi collisionPairMapping
Matrix relating the collision pair ID to a pair of two GeometryObject indexes.
Definition: geometry.hpp:223
void addAllCollisionPairs()
Add all possible collision pairs.
void removeGeometryObject(const std::string &name)
Remove a GeometryObject.
Index ngeoms
The number of GeometryObjects.
Definition: geometry.hpp:214
GeometryModel clone() const
Create a deep copy of *this.
CollisionPairVector collisionPairs
Vector of collision pairs.
Definition: geometry.hpp:220
GeomIndex addGeometryObject(const GeometryObject &object)
Add a geometry object to a GeometryModel.
void removeCollisionPair(const CollisionPair &pair)
Remove if exists the CollisionPair from the vector collision_pairs.
bool operator!=(const GeometryModel &other) const
Returns true if *this and other are not equal.
Definition: geometry.hpp:206
Common traits structure to fully define base classes for CRTP.
Definition: fwd.hpp:72