pinocchio  2.7.1
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
fcl.hpp
1 //
2 // Copyright (c) 2015-2023 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_multibody_fcl_hpp__
6 #define __pinocchio_multibody_fcl_hpp__
7 
8 #include "pinocchio/spatial/se3.hpp"
9 #include "pinocchio/multibody/fwd.hpp"
10 #include "pinocchio/container/aligned-vector.hpp"
11 
16 #include <boost/variant.hpp>
17 
18 #ifdef PINOCCHIO_WITH_HPP_FCL
19 
20  #if(WIN32)
21  // It appears that std::snprintf is missing for Windows.
22  #if !(( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) ))
23  #include <cstdio>
24  #include <stdarg.h>
25  namespace std
26  {
27  inline int _snprintf(char* buffer, std::size_t buf_size, const char* format, ...)
28  {
29  int res;
30 
31  va_list args;
32  va_start(args, format);
33  res = vsnprintf(buffer, buf_size, format, args);
34  va_end(args);
35 
36  return res;
37  }
38  }
39  #endif
40  #endif
41 
42  #include <hpp/fcl/collision_object.h>
43  #include <hpp/fcl/collision.h>
44  #include <hpp/fcl/distance.h>
45  #include <hpp/fcl/shape/geometric_shapes.h>
46  #include "pinocchio/spatial/fcl-pinocchio-conversions.hpp"
47 #endif
48 
49 #include <iostream>
50 #include <map>
51 #include <vector>
52 #include <utility>
53 #include <limits>
54 #include <assert.h>
55 
56 #include <memory>
57 
58 #include <boost/foreach.hpp>
59 
60 namespace pinocchio
61 {
62  using std::shared_ptr;
63  using std::make_shared;
64 
66  : public std::pair<GeomIndex, GeomIndex>
67  {
68 
69  typedef std::pair<GeomIndex, GeomIndex> Base;
70 
72  CollisionPair();
73 
81  CollisionPair(const GeomIndex co1, const GeomIndex co2);
82  bool operator == (const CollisionPair& rhs) const;
83  bool operator != (const CollisionPair& rhs) const;
84  void disp (std::ostream & os) const;
85  friend std::ostream & operator << (std::ostream & os,const CollisionPair & X);
86 
87  }; // struct CollisionPair
88 
89 #ifndef PINOCCHIO_WITH_HPP_FCL
90 
91  namespace fcl
92  {
93 
94  struct FakeCollisionGeometry
95  {
96  FakeCollisionGeometry(){};
97 
98  bool operator==(const FakeCollisionGeometry &) const
99  {
100  return true;
101  }
102  };
103 
104  struct AABB
105  {
106  AABB(): min_(0), max_(1){};
107 
108  int min_;
109  int max_;
110  };
111 
112  typedef FakeCollisionGeometry CollisionGeometry;
113 
114  }
115 
116 #else
117 
118  namespace fcl = hpp::fcl;
119 
120 #endif // PINOCCHIO_WITH_HPP_FCL
121 
122 enum GeometryType
123 {
124  VISUAL,
125  COLLISION
126 };
127 
130 {
131 };
132 
136 {
137  GeometryPhongMaterial() = default;
138  GeometryPhongMaterial(const Eigen::Vector4d& meshEmissionColor,
139  const Eigen::Vector4d& meshSpecularColor,
140  double meshShininess)
144  {}
145 
147  Eigen::Vector4d meshEmissionColor{Eigen::Vector4d(0., 0., 0., 1.)};
148 
150  Eigen::Vector4d meshSpecularColor{Eigen::Vector4d(0., 0., 0., 1.)};
151 
155  double meshShininess{0.};
156 };
157 
158 typedef boost::variant<GeometryNoMaterial, GeometryPhongMaterial> GeometryMaterial;
159 
161 {
162  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
163 
164  typedef shared_ptr<fcl::CollisionGeometry> CollisionGeometryPtr;
165 
167  std::string name;
168 
174  FrameIndex parentFrame;
175 
177  JointIndex parentJoint;
178 
180  CollisionGeometryPtr geometry;
181 
184  PINOCCHIO_DEPRECATED CollisionGeometryPtr & fcl;
185 
188 
190  std::string meshPath;
191 
193  Eigen::Vector3d meshScale;
194 
197 
199  Eigen::Vector4d meshColor;
200 
204  GeometryMaterial meshMaterial;
205 
207  std::string meshTexturePath;
208 
211 
212 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
213 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
229  GeometryObject(const std::string & name,
230  const FrameIndex parent_frame,
231  const JointIndex parent_joint,
232  const CollisionGeometryPtr & collision_geometry,
233  const SE3 & placement,
234  const std::string & meshPath = "",
235  const Eigen::Vector3d & meshScale = Eigen::Vector3d::Ones(),
236  const bool overrideMaterial = false,
237  const Eigen::Vector4d & meshColor = Eigen::Vector4d(0,0,0,1),
238  const std::string & meshTexturePath = "",
239  const GeometryMaterial& meshMaterial = GeometryNoMaterial())
240  : name(name)
241  , parentFrame(parent_frame)
242  , parentJoint(parent_joint)
243  , geometry(collision_geometry)
244  , fcl(geometry)
246  , meshPath(meshPath)
252  , disableCollision(false)
253  {}
254 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
255 
256 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
257 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
273  GeometryObject(const std::string & name,
274  const JointIndex parent_joint,
275  const CollisionGeometryPtr & collision_geometry,
276  const SE3 & placement,
277  const std::string & meshPath = "",
278  const Eigen::Vector3d & meshScale = Eigen::Vector3d::Ones(),
279  const bool overrideMaterial = false,
280  const Eigen::Vector4d & meshColor = Eigen::Vector4d::Ones(),
281  const std::string & meshTexturePath = "",
282  const GeometryMaterial& meshMaterial = GeometryNoMaterial())
283  : name(name)
284  , parentFrame(std::numeric_limits<FrameIndex>::max())
285  , parentJoint(parent_joint)
286  , geometry(collision_geometry)
287  , fcl(geometry)
289  , meshPath(meshPath)
295  , disableCollision(false)
296  {}
297 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
298 
299 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
300 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS
301  GeometryObject(const GeometryObject & other)
302  : fcl(geometry)
303  {
304  *this = other;
305 
306  }
307 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
308 
309  GeometryObject & operator=(const GeometryObject & other)
310  {
311  name = other.name;
312  parentFrame = other.parentFrame;
313  parentJoint = other.parentJoint;
314  geometry = other.geometry;
315  placement = other.placement;
316  meshPath = other.meshPath;
317  meshScale = other.meshScale;
318  overrideMaterial = other.overrideMaterial;
319  meshColor = other.meshColor;
320  meshMaterial = other.meshMaterial;
321  meshTexturePath = other.meshTexturePath;
322  disableCollision = other.disableCollision;
323  return *this;
324  }
325 
326  friend std::ostream & operator<< (std::ostream & os, const GeometryObject & geomObject);
327 };
328 
329 #ifdef PINOCCHIO_WITH_HPP_FCL
330 
332  : ::hpp::fcl::ComputeCollision
333  {
334  typedef ::hpp::fcl::ComputeCollision Base;
335  typedef shared_ptr<const fcl::CollisionGeometry> ConstCollisionGeometryPtr;
336 
337  ComputeCollision(const GeometryObject & o1, const GeometryObject & o2)
338  : Base(o1.geometry.get(),o2.geometry.get())
339  , o1(o1.geometry)
340  , o2(o2.geometry)
341  {}
342 
343  virtual ~ComputeCollision() {};
344 
345  protected:
346  ConstCollisionGeometryPtr o1;
347  ConstCollisionGeometryPtr o2;
348 
349  virtual std::size_t run(const fcl::Transform3f& tf1, const fcl::Transform3f& tf2,
350  const fcl::CollisionRequest& request, fcl::CollisionResult& result) const
351  {
352  typedef ::hpp::fcl::CollisionGeometry const * Pointer;
353  const_cast<Pointer&>(Base::o1) = o1.get();
354  const_cast<Pointer&>(Base::o2) = o2.get();
355  return Base::run(tf1, tf2, request, result);
356  }
357  };
358 
360  : ::hpp::fcl::ComputeDistance
361  {
362  typedef ::hpp::fcl::ComputeDistance Base;
363  typedef shared_ptr<fcl::CollisionGeometry> ConstCollisionGeometryPtr;
364 
365  ComputeDistance(const GeometryObject & o1, const GeometryObject & o2)
366  : Base(o1.geometry.get(),o2.geometry.get())
367  , o1(o1.geometry)
368  , o2(o2.geometry)
369  {}
370 
371  virtual ~ComputeDistance() {};
372 
373  protected:
374  ConstCollisionGeometryPtr o1;
375  ConstCollisionGeometryPtr o2;
376 
377  virtual hpp::fcl::FCL_REAL run(const fcl::Transform3f& tf1, const fcl::Transform3f& tf2,
378  const fcl::DistanceRequest& request, fcl::DistanceResult& result) const
379  {
380  typedef ::hpp::fcl::CollisionGeometry const * Pointer;
381  const_cast<Pointer&>(Base::o1) = o1.get();
382  const_cast<Pointer&>(Base::o2) = o2.get();
383  return Base::run(tf1, tf2, request, result);
384  }
385  };
386 
387 #endif
388 
389 } // namespace pinocchio
390 
391 /* --- Details -------------------------------------------------------------- */
392 /* --- Details -------------------------------------------------------------- */
393 /* --- Details -------------------------------------------------------------- */
394 #include "pinocchio/multibody/fcl.hxx"
395 
396 #endif // ifndef __pinocchio_multibody_fcl_hpp__
pinocchio::GeometryObject::meshTexturePath
std::string meshTexturePath
Absolute path to the mesh texture file.
Definition: fcl.hpp:207
pinocchio::GeometryPhongMaterial::meshShininess
double meshShininess
Shininess associated to the specular lighting model.
Definition: fcl.hpp:155
pinocchio::GeometryObject::placement
SE3 placement
Position of geometry object in parent joint frame.
Definition: fcl.hpp:187
pinocchio::SE3Tpl< double, 0 >
pinocchio::GeometryObject::parentFrame
FrameIndex parentFrame
Index of the parent frame.
Definition: fcl.hpp:174
pinocchio::GeometryObject::fcl
PINOCCHIO_DEPRECATED CollisionGeometryPtr & fcl
The former pointer to the FCL CollisionGeometry.
Definition: fcl.hpp:184
pinocchio::GeometryObject
Definition: fcl.hpp:160
pinocchio::GeometryObject::parentJoint
JointIndex parentJoint
Index of the parent joint.
Definition: fcl.hpp:177
pinocchio::ComputeCollision
Definition: fcl.hpp:331
pinocchio::GeometryNoMaterial
No material associated to a geometry.
Definition: fcl.hpp:129
pinocchio::CollisionPair::CollisionPair
CollisionPair()
&#160;
pinocchio::CollisionPair
Definition: fcl.hpp:65
pinocchio::GeometryObject::disableCollision
bool disableCollision
If true, no collision or distance check will be done between the Geometry and any other geometry.
Definition: fcl.hpp:210
pinocchio::GeometryObject::name
std::string name
Name of the geometry object.
Definition: fcl.hpp:167
pinocchio::GeometryObject::GeometryObject
PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS GeometryObject(const std::string &name, const FrameIndex parent_frame, const JointIndex parent_joint, const CollisionGeometryPtr &collision_geometry, const SE3 &placement, const std::string &meshPath="", const Eigen::Vector3d &meshScale=Eigen::Vector3d::Ones(), const bool overrideMaterial=false, const Eigen::Vector4d &meshColor=Eigen::Vector4d(0, 0, 0, 1), const std::string &meshTexturePath="", const GeometryMaterial &meshMaterial=GeometryNoMaterial())
Full constructor.
Definition: fcl.hpp:229
pinocchio::GeometryObject::meshPath
std::string meshPath
Absolute path to the mesh file (if the geometry pointee is also a Mesh)
Definition: fcl.hpp:190
pinocchio::GeometryObject::overrideMaterial
bool overrideMaterial
Decide whether to override the Material.
Definition: fcl.hpp:196
pinocchio::GeometryObject::geometry
CollisionGeometryPtr geometry
The FCL CollisionGeometry (might be a Mesh, a Geometry Primitive, etc.)
Definition: fcl.hpp:180
pinocchio::GeometryPhongMaterial::meshSpecularColor
Eigen::Vector4d meshSpecularColor
RGBA specular color value of the GeometryObject::geometry object.
Definition: fcl.hpp:150
pinocchio::ComputeDistance
Definition: fcl.hpp:359
pinocchio::GeometryPhongMaterial
Definition: fcl.hpp:135
pinocchio::GeometryPhongMaterial::meshEmissionColor
Eigen::Vector4d meshEmissionColor
RGBA emission (ambient) color value of the GeometryObject::geometry object.
Definition: fcl.hpp:147
pinocchio::GeometryObject::GeometryObject
PINOCCHIO_COMPILER_DIAGNOSTIC_POP PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_DEPRECECATED_DECLARATIONS GeometryObject(const std::string &name, const JointIndex parent_joint, const CollisionGeometryPtr &collision_geometry, const SE3 &placement, const std::string &meshPath="", const Eigen::Vector3d &meshScale=Eigen::Vector3d::Ones(), const bool overrideMaterial=false, const Eigen::Vector4d &meshColor=Eigen::Vector4d::Ones(), const std::string &meshTexturePath="", const GeometryMaterial &meshMaterial=GeometryNoMaterial())
Reduced constructor.
Definition: fcl.hpp:273
pinocchio::GeometryObject::meshScale
Eigen::Vector3d meshScale
Scaling vector applied to the GeometryObject::geometry object.
Definition: fcl.hpp:193
pinocchio::GeometryObject::meshColor
Eigen::Vector4d meshColor
RGBA diffuse color value of the GeometryObject::geometry object.
Definition: fcl.hpp:199
pinocchio::GeometryObject::meshMaterial
GeometryMaterial meshMaterial
Material associated to the mesh. This material should be used only if overrideMaterial is set to true...
Definition: fcl.hpp:204
pinocchio
Main pinocchio namespace.
Definition: treeview.dox:11