3 #include <geometric_shapes/shape_operations.h>
23 if (
STRINGS[i].compare(lower) == 0)
30 throw Exception(1,
"Invalid type for geometry.");
38 throw Exception(1,
"Invalid type for geometry.");
45 return std::make_shared<Geometry>(
ShapeType::SPHERE, Eigen::Vector3d(radius, 0, 0));
50 return std::make_shared<Geometry>(
ShapeType::BOX, Eigen::Vector3d(x, y, z));
55 return makeBox(dimensions[0], dimensions[1], dimensions[2]);
65 return std::make_shared<Geometry>(
ShapeType::CONE, Eigen::Vector3d(radius, length, 0));
70 using sm = shape_msgs::SolidPrimitive;
75 return makeBox(msg.dimensions[sm::BOX_X],
76 msg.dimensions[sm::BOX_Y],
77 msg.dimensions[sm::BOX_Z]);
79 return makeSphere(msg.dimensions[sm::SPHERE_RADIUS]);
82 msg.dimensions[sm::CYLINDER_HEIGHT]);
84 return makeCone(msg.dimensions[sm::CONE_RADIUS],
85 msg.dimensions[sm::CONE_HEIGHT]);
98 return std::make_shared<Geometry>(
ShapeType::MESH, Eigen::Vector3d::Ones(),
"", vertices);
102 const EigenSTL::vector_Vector3d &vertices)
116 case shapes::ShapeType::BOX:
119 const auto &box =
static_cast<const shapes::Box &
>(shape);
120 dimensions_ = Eigen::Vector3d{box.size[0], box.size[1], box.size[2]};
124 case shapes::ShapeType::SPHERE:
127 const auto &sphere =
static_cast<const shapes::Sphere &
>(shape);
128 dimensions_ = Eigen::Vector3d{sphere.radius, 0, 0};
132 case shapes::ShapeType::CYLINDER:
135 const auto &cylinder =
static_cast<const shapes::Cylinder &
>(shape);
136 dimensions_ = Eigen::Vector3d{cylinder.radius, cylinder.length, 0};
140 case shapes::ShapeType::CONE:
143 const auto &cone =
static_cast<const shapes::Cone &
>(shape);
144 dimensions_ = Eigen::Vector3d{cone.radius, cone.length, 0};
148 case shapes::ShapeType::MESH:
151 const auto &mesh =
static_cast<const shapes::Mesh &
>(shape);
152 shape_.reset(mesh.clone());
156 throw Exception(1,
"Invalid type for geometry.");
194 return shapes::createMeshFromVertices(
vertices_);
197 "Both vertices/resource specified for the mesh");
212 return new bodies::Box(
shape_.get());
216 return new bodies::Sphere(
shape_.get());
220 return new bodies::Cylinder(
shape_.get());
224 return new bodies::ConvexMesh(
shape_.get());
237 return body_->containsPoint(point[0], point[1], point[2]);
243 Eigen::Vector3d point;
244 random_numbers::RandomNumberGenerator rng;
246 if (!(success =
body_->samplePointInside(rng, attempts, point)))
247 point = Eigen::Vector3d{0, 0, 0};
258 shapes::ShapeMsg msg;
260 shapes::constructMsgFromShape(
shape_.get(), msg);
262 return boost::get<shape_msgs::SolidPrimitive>(msg);
267 shapes::ShapeMsg msg;
269 shapes::constructMsgFromShape(
shape_.get(), msg);
271 return boost::get<shape_msgs::Mesh>(msg);
308 const auto &extents = shapes::computeShapeExtents(
shape_.get());
void extendWithTransformedBox(const Eigen::Isometry3d &transform, const Eigen::Vector3d &box)
Exception that contains a message and an error code.
A shared pointer wrapper for robowflex::Geometry.
static const std::string & toString(Type type)
Converts a ShapeType to its string.
@ CYLINDER
Solid primitive cylinder. Uses two dimensions (height, radius).
@ MESH
Mesh. Dimensions scale along x, y, z.
@ CONE
Solid primitive cone. Uses two dimensions (height, radius).
@ BOX
Solid primitive box. Uses three dimensions (x, y, z).
@ SPHERE
Solid primitive sphere. Uses one dimension (radius).
static Type toType(const std::string &str)
Converts a string into a ShapeType.
static const std::vector< std::string > STRINGS
Mapping of ShapeType to string.
static const unsigned int MAX
Maximum value of ShapeType.
A class that manages both solid and mesh geometry for various parts of the motion planning system.
const std::string & getResource() const
Gets the mesh resource of the geometry.
static GeometryPtr makeMesh(const std::string &resource, const Eigen::Vector3d &scale={1, 1, 1})
Create a mesh from resource file.
Geometry(ShapeType::Type type, const Eigen::Vector3d &dimensions, const std::string &resource="", const EigenSTL::vector_Vector3d &vertices=EigenSTL::vector_Vector3d{})
Constructor. Builds and loads the specified geometry.
Eigen::Vector3d dimensions_
Dimensions to scale geometry.
static GeometryPtr makeSphere(double radius)
Create a sphere.
static GeometryPtr makeBox(double x, double y, double z)
Create a box.
const EigenSTL::vector_Vector3d & getVertices() const
Gets the Vertices of the primitive.
const shape_msgs::Mesh getMeshMsg() const
Gets the message form of mesh geometry.
shapes::ShapePtr shape_
Loaded shape.
static GeometryPtr makeCone(double radius, double length)
Create a cone.
const Eigen::Vector3d & getDimensions() const
Gets the dimensions of the geometry.
bool isMesh() const
Checks if the geometry is a mesh geometry.
const shape_msgs::SolidPrimitive getSolidMsg() const
Gets the message form of solid primitive geometry (all but ShapeType::MESH).
Eigen::AlignedBox3d getAABB(const RobotPose &pose=RobotPose::Identity()) const
Compute the AABB (axis-aligned bounding box) of the geometry at a given pose.
const shapes::ShapePtr & getShape() const
Gets the underlying shape.
ShapeType::Type getType() const
Gets the type of the geometry.
bodies::BodyPtr body_
Body operation.
std::pair< bool, Eigen::Vector3d > sample(const unsigned int attempts=50) const
Tries to sample a point in the geometry.
shapes::Shape * loadShape() const
Loads a shape from the set type_ and dimensions_, and resource_ if a mesh.
bodies::Body * loadBody() const
Loads a body from the loaded shape_.
EigenSTL::vector_Vector3d vertices_
Vertices of the primitive.
static GeometryPtr makeCylinder(double radius, double length)
Create a cylinder.
std::string resource_
Resource locator for MESH types.
ShapeType::Type type_
Geometry Type.
const bodies::BodyPtr & getBody() const
Gets the underlying body.
static GeometryPtr makeSolidPrimitive(const shape_msgs::SolidPrimitive &msg)
Create a solid primitive.
bool contains(const Eigen::Vector3d &point) const
Checks if the geometry contains a point.
std::string resolvePath(const std::string &path)
Resolves package:// URLs and relative file paths to their canonical form.
Main namespace. Contains all library classes and functions.
std::decay< decltype(std::declval< moveit::core::Transforms >().getTransform("")) >::type RobotPose
A pose (point in SE(3)) used in various functions. Defined from what MoveIt! uses.