Newer
Older
Valenza Florian
committed
//
Valenza Florian
committed
//
#ifndef __pinocchio_multibody_fcl_hpp__
#define __pinocchio_multibody_fcl_hpp__
Valenza Florian
committed
Valenza Florian
committed
#include "pinocchio/multibody/fwd.hpp"
jcarpent
committed
#include "pinocchio/container/aligned-vector.hpp"
Valenza Florian
committed
#ifdef PINOCCHIO_WITH_HPP_FCL
#include <hpp/fcl/collision_object.h>
#include <hpp/fcl/collision.h>
#include <hpp/fcl/distance.h>
#include <hpp/fcl/shape/geometric_shapes.h>
#include "pinocchio/spatial/fcl-pinocchio-conversions.hpp"
Valenza Florian
committed
#endif
Valenza Florian
committed
#include <iostream>
#include <map>
#include <vector>
Valenza Florian
committed
#include <utility>
#include <limits>
Valenza Florian
committed
#include <assert.h>
#include <boost/foreach.hpp>
Valenza Florian
committed
#include <boost/shared_ptr.hpp>
Valenza Florian
committed
Valenza Florian
committed
{
struct CollisionPair: public std::pair<GeomIndex, GeomIndex>
{
typedef std::pair<GeomIndex, GeomIndex> Base;
CollisionPair(const GeomIndex co1, const GeomIndex co2);
bool operator == (const CollisionPair& rhs) const;
void disp (std::ostream & os) const;
friend std::ostream & operator << (std::ostream & os,const CollisionPair & X);
Valenza Florian
committed
Valenza Florian
committed
}; // struct CollisionPair
#ifndef PINOCCHIO_WITH_HPP_FCL
Valenza Florian
committed
namespace fcl
{
struct FakeCollisionGeometry
{
FakeCollisionGeometry(){};
};
struct AABB
{
AABB(): min_(0), max_(1){};
int min_;
int max_;
};
Valenza Florian
committed
typedef FakeCollisionGeometry CollisionGeometry;
}
#else
namespace fcl = hpp::fcl;
#endif // PINOCCHIO_WITH_HPP_FCL
Valenza Florian
committed
Valenza Florian
committed
enum GeometryType
{
VISUAL,
COLLISION
Valenza Florian
committed
};
struct GeometryObject
{
jcarpent
committed
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef boost::shared_ptr<fcl::CollisionGeometry> CollisionGeometryPtr;
Valenza Florian
committed
/// \brief Name of the geometry object
std::string name;
/// \brief Index of the parent frame
/// Parent frame may be unset (to the std::numeric_limits<FrameIndex>::max() value) as it is mostly used as a documentation of the tree, or in third-party libraries.
/// The URDF parser of Pinocchio is setting it to the proper value according to the urdf link-joint tree.
/// In particular, anchor joints of URDF would cause parent frame to be different to joint frame.
FrameIndex parentFrame;
/// \brief Index of the parent joint
JointIndex parentJoint;
Valenza Florian
committed
/// \brief The FCL CollisionGeometry (might be a Mesh, a Geometry Primitive, etc.)
CollisionGeometryPtr geometry;
/// \brief The former pointer to the FCL CollisionGeometry.
/// \deprecated It is now deprecated and has been renamed GeometryObject::geometry
PINOCCHIO_DEPRECATED CollisionGeometryPtr & fcl;
Valenza Florian
committed
/// \brief Position of geometry object in parent joint frame
Valenza Florian
committed
SE3 placement;
/// \brief Absolute path to the mesh file (if the fcl pointee is also a Mesh)

Nicolas Mansard
committed
std::string meshPath;
Valenza Florian
committed
/// \brief Scaling vector applied to the GeometryObject::fcl object.
Eigen::Vector3d meshScale;
/// \brief Decide whether to override the Material.
bool overrideMaterial;
/// \brief RGBA color value of the GeometryObject::fcl object.
Eigen::Vector4d meshColor;
/// \brief Absolute path to the mesh texture file.
std::string meshTexturePath;
///
/// \brief Full constructor.
///
/// \param[in] name Name of the geometry object.
/// \param[in] parent_frame Index of the parent frame.
/// \param[in] parent_joint Index of the parent joint (that supports the geometry).
/// \param[in] collision_geometry The FCL collision geometry object.
/// \param[in] placement Placement of the geometry with respect to the joint frame.
/// \param[in] meshPath Path of the mesh (may be needed extarnally to load the mesh inside a viewer for instance) [if applicable].
/// \param[in] meshScale Scale of the mesh [if applicable].
/// \param[in] overrideMaterial If true, this option allows to overrite the material [if applicable].
/// \param[in] meshColor Color of the mesh [if applicable].
/// \param[in] meshTexturePath Path to the file containing the texture information [if applicable].
///
GeometryObject(const std::string & name,
const FrameIndex parent_frame,
const CollisionGeometryPtr & collision_geometry,
const SE3 & placement,
const std::string & meshPath = "",
Rohan Budhiraja
committed
const Eigen::Vector3d & meshScale = Eigen::Vector3d::Ones(),
const bool overrideMaterial = false,
Rohan Budhiraja
committed
const Eigen::Vector4d & meshColor = Eigen::Vector4d::Zero(),
const std::string & meshTexturePath = "")
: name(name)
, parentFrame(parent_frame)
, parentJoint(parent_joint)
, geometry(collision_geometry)
, fcl(geometry)
, placement(placement)
, meshPath(meshPath)
, meshScale(meshScale)
, overrideMaterial(overrideMaterial)
, meshColor(meshColor)
, meshTexturePath(meshTexturePath)
{}
///
/// \brief Reduced constructor.
/// \remarks Compared to the other constructor, this one assumes that there is no parentFrame associated to the geometry.
///
/// \param[in] name Name of the geometry object.
/// \param[in] parent_joint Index of the parent joint (that supports the geometry).
/// \param[in] collision_geometry The FCL collision geometry object.
/// \param[in] placement Placement of the geometry with respect to the joint frame.
/// \param[in] meshPath Path of the mesh (may be needed extarnally to load the mesh inside a viewer for instance) [if applicable].
/// \param[in] meshScale Scale of the mesh [if applicable].
/// \param[in] overrideMaterial If true, this option allows to overrite the material [if applicable].
/// \param[in] meshColor Color of the mesh [if applicable].
/// \param[in] meshTexturePath Path to the file containing the texture information [if applicable].
///
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::Zero(),
const std::string & meshTexturePath = "")
: name(name)
, parentFrame(std::numeric_limits<FrameIndex>::max())
, parentJoint(parent_joint)
, geometry(collision_geometry)
, fcl(geometry)
, placement(placement)
, meshPath(meshPath)
, meshScale(meshScale)
, overrideMaterial(overrideMaterial)
, meshColor(meshColor)
Valenza Florian
committed
{}
GeometryObject(const GeometryObject & other)
: fcl(geometry)
{
*this = other;
}
Valenza Florian
committed
GeometryObject & operator=(const GeometryObject & other)
{
name = other.name;
parentFrame = other.parentFrame;
parentJoint = other.parentJoint;
geometry = other.geometry;
placement = other.placement;

Nicolas Mansard
committed
meshPath = other.meshPath;
meshScale = other.meshScale;
overrideMaterial = other.overrideMaterial;
meshColor = other.meshColor;
meshTexturePath = other.meshTexturePath;
Valenza Florian
committed
return *this;
}

Nicolas Mansard
committed
friend std::ostream & operator<< (std::ostream & os, const GeometryObject & geomObject);
Valenza Florian
committed
};
} // namespace pinocchio
Valenza Florian
committed
/* --- Details -------------------------------------------------------------- */
/* --- Details -------------------------------------------------------------- */
/* --- Details -------------------------------------------------------------- */
Valenza Florian
committed
#include "pinocchio/multibody/fcl.hxx"
Valenza Florian
committed