Robowflex  v0.1
Making MoveIt Easy
robowflex::Geometry Class Reference

A class that manages both solid and mesh geometry for various parts of the motion planning system. More...

#include <geometry.h>

Classes

class  ShapeType
 Supported shape types. More...
 

Public Member Functions

 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. More...
 
 Geometry (const shapes::Shape &shape)
 Constructor. Builds and loads the specified geometry from a MoveIt shape. More...
 
 Geometry (const shape_msgs::SolidPrimitive &msg)
 Constructor. Builds and loads the specified geometry from a MoveIt shape message. More...
 
 Geometry (const shape_msgs::Mesh &msg)
 Constructor. Builds and loads the specified geometry from a MoveIt shape message. More...
 
 Geometry (const Geometry &)=delete
 
Geometryoperator= (const Geometry &)=delete
 
bool contains (const Eigen::Vector3d &point) const
 Checks if the geometry contains a point. More...
 
std::pair< bool, Eigen::Vector3d > sample (const unsigned int attempts=50) const
 Tries to sample a point in the geometry. More...
 
bool isMesh () const
 Checks if the geometry is a mesh geometry. More...
 
const shape_msgs::SolidPrimitive getSolidMsg () const
 Gets the message form of solid primitive geometry (all but ShapeType::MESH). More...
 
const shape_msgs::Mesh getMeshMsg () const
 Gets the message form of mesh geometry. More...
 
const shapes::ShapePtr & getShape () const
 Gets the underlying shape. More...
 
const bodies::BodyPtr & getBody () const
 Gets the underlying body. More...
 
ShapeType::Type getType () const
 Gets the type of the geometry. More...
 
const std::stringgetResource () const
 Gets the mesh resource of the geometry. More...
 
const EigenSTL::vector_Vector3d & getVertices () const
 Gets the Vertices of the primitive. More...
 
const Eigen::Vector3d & getDimensions () const
 Gets the dimensions of the geometry. More...
 
Eigen::AlignedBox3d getAABB (const RobotPose &pose=RobotPose::Identity()) const
 Compute the AABB (axis-aligned bounding box) of the geometry at a given pose. More...
 

Static Public Member Functions

static GeometryPtr makeSphere (double radius)
 Create a sphere. More...
 
static GeometryPtr makeBox (double x, double y, double z)
 Create a box. More...
 
static GeometryPtr makeBox (const Eigen::Vector3d &dimensions)
 Create a box. More...
 
static GeometryPtr makeCylinder (double radius, double length)
 Create a cylinder. More...
 
static GeometryPtr makeCone (double radius, double length)
 Create a cone. More...
 
static GeometryPtr makeSolidPrimitive (const shape_msgs::SolidPrimitive &msg)
 Create a solid primitive. More...
 
static GeometryPtr makeMesh (const std::string &resource, const Eigen::Vector3d &scale={1, 1, 1})
 Create a mesh from resource file. More...
 
static GeometryPtr makeMesh (const EigenSTL::vector_Vector3d &vertices)
 Create a mesh from triangles represented as vertices . More...
 

Private Member Functions

shapes::Shape * loadShape () const
 Loads a shape from the set type_ and dimensions_, and resource_ if a mesh. More...
 
bodies::Body * loadBody () const
 Loads a body from the loaded shape_. More...
 

Private Attributes

ShapeType::Type type_ {ShapeType::Type::BOX}
 Geometry Type. More...
 
Eigen::Vector3d dimensions_ {Eigen::Vector3d::Ones()}
 Dimensions to scale geometry. More...
 
EigenSTL::vector_Vector3d vertices_ {{}}
 Vertices of the primitive. More...
 
std::string resource_ {""}
 Resource locator for MESH types. More...
 
shapes::ShapePtr shape_ {nullptr}
 Loaded shape. More...
 
bodies::BodyPtr body_ {nullptr}
 Body operation. More...
 

Detailed Description

A class that manages both solid and mesh geometry for various parts of the motion planning system.

Definition at line 35 of file geometry.h.

Constructor & Destructor Documentation

◆ Geometry() [1/5]

Geometry::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.

Parameters
[in]typeType of the geometry to create.
[in]dimensionsDimensions of the geometry to load.
[in]resourceIf type is ShapeType::MESH, then resource or vertices must be specified
[in]verticesList of vertices that form the mesh. as the mesh file to load.

Definition at line 101 of file geometry.cpp.

103  : type_(type)
104  , dimensions_(dimensions)
105  , vertices_(vertices)
106  , resource_((resource.empty()) ? "" : IO::resolvePath(resource))
107  , shape_(loadShape())
108  , body_(loadBody())
109 {
110 }
Eigen::Vector3d dimensions_
Dimensions to scale geometry.
Definition: geometry.h:220
shapes::ShapePtr shape_
Loaded shape.
Definition: geometry.h:223
bodies::BodyPtr body_
Body operation.
Definition: geometry.h:224
shapes::Shape * loadShape() const
Loads a shape from the set type_ and dimensions_, and resource_ if a mesh.
Definition: geometry.cpp:170
bodies::Body * loadBody() const
Loads a body from the loaded shape_.
Definition: geometry.cpp:207
EigenSTL::vector_Vector3d vertices_
Vertices of the primitive.
Definition: geometry.h:221
std::string resource_
Resource locator for MESH types.
Definition: geometry.h:222
ShapeType::Type type_
Geometry Type.
Definition: geometry.h:219
T empty(T... args)
std::string resolvePath(const std::string &path)
Resolves package:// URLs and relative file paths to their canonical form.

◆ Geometry() [2/5]

Geometry::Geometry ( const shapes::Shape &  shape)

Constructor. Builds and loads the specified geometry from a MoveIt shape.

Parameters
[in]shapeShape to construct geometry from.

Definition at line 112 of file geometry.cpp.

113 {
114  switch (shape.type)
115  {
116  case shapes::ShapeType::BOX:
117  {
119  const auto &box = static_cast<const shapes::Box &>(shape);
120  dimensions_ = Eigen::Vector3d{box.size[0], box.size[1], box.size[2]};
121  shape_.reset(loadShape());
122  break;
123  }
124  case shapes::ShapeType::SPHERE:
125  {
127  const auto &sphere = static_cast<const shapes::Sphere &>(shape);
128  dimensions_ = Eigen::Vector3d{sphere.radius, 0, 0};
129  shape_.reset(loadShape());
130  break;
131  }
132  case shapes::ShapeType::CYLINDER:
133  {
135  const auto &cylinder = static_cast<const shapes::Cylinder &>(shape);
136  dimensions_ = Eigen::Vector3d{cylinder.radius, cylinder.length, 0};
137  shape_.reset(loadShape());
138  break;
139  }
140  case shapes::ShapeType::CONE:
141  {
143  const auto &cone = static_cast<const shapes::Cone &>(shape);
144  dimensions_ = Eigen::Vector3d{cone.radius, cone.length, 0};
145  shape_.reset(loadShape());
146  break;
147  }
148  case shapes::ShapeType::MESH:
149  {
151  const auto &mesh = static_cast<const shapes::Mesh &>(shape);
152  shape_.reset(mesh.clone());
153  break;
154  }
155  default:
156  throw Exception(1, "Invalid type for geometry.");
157  }
158 
159  body_.reset(loadBody());
160 }
Exception that contains a message and an error code.
Definition: util.h:15
@ CYLINDER
Solid primitive cylinder. Uses two dimensions (height, radius).
Definition: geometry.h:47
@ MESH
Mesh. Dimensions scale along x, y, z.
Definition: geometry.h:49
@ CONE
Solid primitive cone. Uses two dimensions (height, radius).
Definition: geometry.h:48
@ BOX
Solid primitive box. Uses three dimensions (x, y, z).
Definition: geometry.h:45
@ SPHERE
Solid primitive sphere. Uses one dimension (radius).
Definition: geometry.h:46

◆ Geometry() [3/5]

Geometry::Geometry ( const shape_msgs::SolidPrimitive &  msg)

Constructor. Builds and loads the specified geometry from a MoveIt shape message.

Parameters
[in]msgShape message to construct geometry from.

Definition at line 162 of file geometry.cpp.

162  : Geometry(*shapes::constructShapeFromMsg(msg))
163 {
164 }
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.
Definition: geometry.cpp:101

◆ Geometry() [4/5]

Geometry::Geometry ( const shape_msgs::Mesh &  msg)

Constructor. Builds and loads the specified geometry from a MoveIt shape message.

Parameters
[in]msgShape message to construct mesh geometry from.

Definition at line 166 of file geometry.cpp.

166  : Geometry(*shapes::constructShapeFromMsg(msg))
167 {
168 }

◆ Geometry() [5/5]

robowflex::Geometry::Geometry ( const Geometry )
delete

Member Function Documentation

◆ contains()

bool Geometry::contains ( const Eigen::Vector3d &  point) const

Checks if the geometry contains a point.

Parameters
[in]pointThe point to check, in the geometry's frame.
Returns
True if the geometry contains the point, false otherwise.

Definition at line 235 of file geometry.cpp.

236 {
237  return body_->containsPoint(point[0], point[1], point[2]);
238 }

◆ getAABB()

Eigen::AlignedBox3d Geometry::getAABB ( const RobotPose pose = RobotPose::Identity()) const

Compute the AABB (axis-aligned bounding box) of the geometry at a given pose.

Parameters
[in]posePose to compute AABB of geometry at.
Returns
The AABB.

Definition at line 304 of file geometry.cpp.

305 {
306  moveit::core::AABB aabb;
307 
308  const auto &extents = shapes::computeShapeExtents(shape_.get());
309  aabb.extendWithTransformedBox(pose, extents);
310 
311  return aabb;
312 }
void extendWithTransformedBox(const Eigen::Isometry3d &transform, const Eigen::Vector3d &box)

◆ getBody()

const bodies::BodyPtr & Geometry::getBody ( ) const

Gets the underlying body.

Returns
The body.

Definition at line 279 of file geometry.cpp.

280 {
281  return body_;
282 }

◆ getDimensions()

const Eigen::Vector3d & Geometry::getDimensions ( ) const

Gets the dimensions of the geometry.

Returns
The dimensions of geometry.

Definition at line 299 of file geometry.cpp.

300 {
301  return dimensions_;
302 }

◆ getMeshMsg()

const shape_msgs::Mesh Geometry::getMeshMsg ( ) const

Gets the message form of mesh geometry.

Returns
The message.

Definition at line 265 of file geometry.cpp.

266 {
267  shapes::ShapeMsg msg;
268  if (isMesh())
269  shapes::constructMsgFromShape(shape_.get(), msg);
270 
271  return boost::get<shape_msgs::Mesh>(msg);
272 }
bool isMesh() const
Checks if the geometry is a mesh geometry.
Definition: geometry.cpp:251

◆ getResource()

const std::string & Geometry::getResource ( ) const

Gets the mesh resource of the geometry.

Returns
The mesh resource of geometry.

Definition at line 289 of file geometry.cpp.

290 {
291  return resource_;
292 }

◆ getShape()

const shapes::ShapePtr & Geometry::getShape ( ) const

Gets the underlying shape.

Returns
The shape.

Definition at line 274 of file geometry.cpp.

275 {
276  return shape_;
277 }

◆ getSolidMsg()

const shape_msgs::SolidPrimitive Geometry::getSolidMsg ( ) const

Gets the message form of solid primitive geometry (all but ShapeType::MESH).

Returns
The message.

Definition at line 256 of file geometry.cpp.

257 {
258  shapes::ShapeMsg msg;
259  if (!isMesh())
260  shapes::constructMsgFromShape(shape_.get(), msg);
261 
262  return boost::get<shape_msgs::SolidPrimitive>(msg);
263 }

◆ getType()

Geometry::ShapeType::Type Geometry::getType ( ) const

Gets the type of the geometry.

Returns
The type of geometry.

Definition at line 284 of file geometry.cpp.

285 {
286  return type_;
287 }

◆ getVertices()

const EigenSTL::vector_Vector3d & Geometry::getVertices ( ) const

Gets the Vertices of the primitive.

Returns
The mesh resource of geometry.

Definition at line 294 of file geometry.cpp.

295 {
296  return vertices_;
297 }

◆ isMesh()

bool Geometry::isMesh ( ) const

Checks if the geometry is a mesh geometry.

Returns
True if the type_ is a mesh (ShapeType::MESH).

Definition at line 251 of file geometry.cpp.

252 {
253  return type_ == ShapeType::MESH;
254 }

◆ loadBody()

bodies::Body * Geometry::loadBody ( ) const
private

Loads a body from the loaded shape_.

Returns
A pointer to a newly allocated body.

Definition at line 207 of file geometry.cpp.

208 {
209  switch (type_)
210  {
211  case ShapeType::BOX:
212  return new bodies::Box(shape_.get());
213  break;
214 
215  case ShapeType::SPHERE:
216  return new bodies::Sphere(shape_.get());
217  break;
218 
219  case ShapeType::CYLINDER:
220  return new bodies::Cylinder(shape_.get());
221  break;
222 
223  case ShapeType::MESH:
224  return new bodies::ConvexMesh(shape_.get());
225  break;
226 
227  case ShapeType::CONE:
228  default:
229  break;
230  }
231 
232  return nullptr;
233 }

◆ loadShape()

shapes::Shape * Geometry::loadShape ( ) const
private

Loads a shape from the set type_ and dimensions_, and resource_ if a mesh.

Returns
A pointer to a newly allocated shape.

Definition at line 170 of file geometry.cpp.

171 {
172  switch (type_)
173  {
174  case ShapeType::BOX:
175  return new shapes::Box(dimensions_[0], dimensions_[1], dimensions_[2]);
176  break;
177 
178  case ShapeType::SPHERE:
179  return new shapes::Sphere(dimensions_[0]);
180  break;
181 
182  case ShapeType::CYLINDER:
183  return new shapes::Cylinder(dimensions_[0], dimensions_[1]);
184  break;
185 
186  case ShapeType::CONE:
187  return new shapes::Cone(dimensions_[0], dimensions_[1]);
188  break;
189 
190  case ShapeType::MESH:
191  if (!resource_.empty() && vertices_.empty())
192  return shapes::createMeshFromResource("file://" + resource_, dimensions_);
193  else if (resource_.empty() && !vertices_.empty())
194  return shapes::createMeshFromVertices(vertices_);
195  else
196  throw Exception(1, resource_.empty() ? "No vertices/resource specified for the mesh" :
197  "Both vertices/resource specified for the mesh");
198  break;
199 
200  default:
201  break;
202  }
203 
204  return nullptr;
205 }

◆ makeBox() [1/2]

GeometryPtr Geometry::makeBox ( const Eigen::Vector3d &  dimensions)
static

Create a box.

Parameters
[in]dimensionsThe XYZ dimensions of the box.
Returns
The created box.

Definition at line 53 of file geometry.cpp.

54 {
55  return makeBox(dimensions[0], dimensions[1], dimensions[2]);
56 }
static GeometryPtr makeBox(double x, double y, double z)
Create a box.
Definition: geometry.cpp:48

◆ makeBox() [2/2]

GeometryPtr Geometry::makeBox ( double  x,
double  y,
double  z 
)
static

Create a box.

Parameters
[in]xThe box's x dimension.
[in]yThe boy's y dimension.
[in]zThe boz's z dimension.
Returns
The created box.

Definition at line 48 of file geometry.cpp.

49 {
50  return std::make_shared<Geometry>(ShapeType::BOX, Eigen::Vector3d(x, y, z));
51 }

◆ makeCone()

GeometryPtr Geometry::makeCone ( double  radius,
double  length 
)
static

Create a cone.

Parameters
[in]radiusThe radius of the base of the cone.
[in]lengthThe height of the cone.
Returns
The created cone.

Definition at line 63 of file geometry.cpp.

64 {
65  return std::make_shared<Geometry>(ShapeType::CONE, Eigen::Vector3d(radius, length, 0));
66 }

◆ makeCylinder()

GeometryPtr Geometry::makeCylinder ( double  radius,
double  length 
)
static

Create a cylinder.

Parameters
[in]radiusThe radius of the cylinder.
[in]lengthThe length of the cylinder.
Returns
The created cylinder.

Definition at line 58 of file geometry.cpp.

59 {
60  return std::make_shared<Geometry>(ShapeType::CYLINDER, Eigen::Vector3d(radius, length, 0));
61 }

◆ makeMesh() [1/2]

GeometryPtr Geometry::makeMesh ( const EigenSTL::vector_Vector3d &  vertices)
static

Create a mesh from triangles represented as vertices .

Parameters
[in]verticesThe vertices that will create the mesh.
Returns
The created mesh.

Definition at line 96 of file geometry.cpp.

97 {
98  return std::make_shared<Geometry>(ShapeType::MESH, Eigen::Vector3d::Ones(), "", vertices);
99 }

◆ makeMesh() [2/2]

GeometryPtr Geometry::makeMesh ( const std::string resource,
const Eigen::Vector3d &  scale = {1, 1, 1} 
)
static

Create a mesh from resource file.

Parameters
[in]resourceThe resource to load for the mesh.
[in]scaleThe scale of the mesh.
Returns
The created mesh.

Definition at line 91 of file geometry.cpp.

92 {
93  return std::make_shared<Geometry>(ShapeType::MESH, scale, resource);
94 }

◆ makeSolidPrimitive()

GeometryPtr Geometry::makeSolidPrimitive ( const shape_msgs::SolidPrimitive &  msg)
static

Create a solid primitive.

Parameters
[in]msgThe solid primitive message to load.
Returns
The created shape.

Definition at line 68 of file geometry.cpp.

69 {
70  using sm = shape_msgs::SolidPrimitive;
71 
72  switch (msg.type)
73  {
74  case sm::BOX:
75  return makeBox(msg.dimensions[sm::BOX_X], //
76  msg.dimensions[sm::BOX_Y], //
77  msg.dimensions[sm::BOX_Z]);
78  case sm::SPHERE:
79  return makeSphere(msg.dimensions[sm::SPHERE_RADIUS]);
80  case sm::CYLINDER:
81  return makeCylinder(msg.dimensions[sm::CYLINDER_RADIUS], //
82  msg.dimensions[sm::CYLINDER_HEIGHT]);
83  case sm::CONE:
84  return makeCone(msg.dimensions[sm::CONE_RADIUS], //
85  msg.dimensions[sm::CONE_HEIGHT]);
86  default:
87  return nullptr;
88  }
89 }
static GeometryPtr makeSphere(double radius)
Create a sphere.
Definition: geometry.cpp:43
static GeometryPtr makeCone(double radius, double length)
Create a cone.
Definition: geometry.cpp:63
static GeometryPtr makeCylinder(double radius, double length)
Create a cylinder.
Definition: geometry.cpp:58

◆ makeSphere()

GeometryPtr Geometry::makeSphere ( double  radius)
static

Create a sphere.

Parameters
[in]radiusThe radius of the sphere.
Returns
The created sphere.

Definition at line 43 of file geometry.cpp.

44 {
45  return std::make_shared<Geometry>(ShapeType::SPHERE, Eigen::Vector3d(radius, 0, 0));
46 }

◆ operator=()

Geometry& robowflex::Geometry::operator= ( const Geometry )
delete

◆ sample()

std::pair< bool, Eigen::Vector3d > Geometry::sample ( const unsigned int  attempts = 50) const

Tries to sample a point in the geometry.

Parameters
[in]attemptsNumber of attempts to sample.
Returns
The sampled point and true, or the 0 vector and false on failure.

Definition at line 240 of file geometry.cpp.

241 {
242  bool success;
243  Eigen::Vector3d point;
244  random_numbers::RandomNumberGenerator rng;
245 
246  if (!(success = body_->samplePointInside(rng, attempts, point)))
247  point = Eigen::Vector3d{0, 0, 0};
248 
249  return std::make_pair(success, point);
250 }
T make_pair(T... args)

Member Data Documentation

◆ body_

bodies::BodyPtr robowflex::Geometry::body_ {nullptr}
private

Body operation.

Definition at line 224 of file geometry.h.

◆ dimensions_

Eigen::Vector3d robowflex::Geometry::dimensions_ {Eigen::Vector3d::Ones()}
private

Dimensions to scale geometry.

Definition at line 220 of file geometry.h.

◆ resource_

std::string robowflex::Geometry::resource_ {""}
private

Resource locator for MESH types.

Definition at line 222 of file geometry.h.

◆ shape_

shapes::ShapePtr robowflex::Geometry::shape_ {nullptr}
private

Loaded shape.

Definition at line 223 of file geometry.h.

◆ type_

ShapeType::Type robowflex::Geometry::type_ {ShapeType::Type::BOX}
private

Geometry Type.

Definition at line 219 of file geometry.h.

◆ vertices_

EigenSTL::vector_Vector3d robowflex::Geometry::vertices_ {{}}
private

Vertices of the primitive.

Definition at line 221 of file geometry.h.


The documentation for this class was generated from the following files: