Drake
Drake C++ Documentation
Loading...
Searching...
No Matches
ShapeReifier Class Reference

Detailed Description

The interface for converting shape descriptions to real shapes.

Any entity that consumes shape descriptions must implement this interface.

This class explicitly enumerates all concrete shapes in its methods. The addition of a new concrete shape class requires the addition of a new corresponding method. There should never be an ImplementGeometry method that accepts the Shape base class as an argument; it should only operate on concrete derived classes.

The expected workflow is for a class that needs to turn shape specifications into concrete geometry instances to implement the ShapeReifier interface and invoke the Shape::Reify() method. For example, a simple reifier that requires no user data would look like:

class SimpleReifier : public ShapeReifier {
void ProcessShape(const Shape& shape) {
// Requires no user data.
shape.Reify(this);
}
...
void ImplementGeometry(const Sphere& sphere, void*) override {
// Do work to create a sphere.
}
};
The abstract base class for all shape specifications.
Definition shape_specification.h:62
void Reify(ShapeReifier *reifier, void *user_data=nullptr) const
Causes this description to be reified in the given reifier.
virtual void ImplementGeometry(const Box &box, void *user_data)
ShapeReifier(const ShapeReifier &)=default
Definition of sphere.
Definition shape_specification.h:672

Or a complex reifier that requires user data would look like:

class ComplexReifier : public ShapeReifier {
void ProcessShape(const Shape& shape) {
ImportantData data{...};
shape.Reify(this, &data);
}
...
void ImplementGeometry(const Sphere& sphere, void* data) override {
DRAKE_ASSERT(data != nullptr);
ImportantData& data = *static_cast<ImportantData*>(data);
// Do work to create a sphere using the provided user data.
}
};
#define DRAKE_ASSERT(condition)
DRAKE_ASSERT(condition) is similar to the built-in assert(condition) from the C++ system header <cass...
Definition drake_assert.h:51

Implementing a particular shape may require more data than is strictly encapsulated in the Shape. The Implement* interface supports passing user data through a type-erased void*. Because a single class invoked Shape::Reify() it is in a position to provide exactly the data the shape implementations require.

#include <drake/geometry/shape_specification.h>

Public Member Functions

virtual ~ShapeReifier ()
virtual void ImplementGeometry (const Box &box, void *user_data)
virtual void ImplementGeometry (const Capsule &capsule, void *user_data)
virtual void ImplementGeometry (const Convex &convex, void *user_data)
virtual void ImplementGeometry (const Cylinder &cylinder, void *user_data)
virtual void ImplementGeometry (const Ellipsoid &ellipsoid, void *user_data)
virtual void ImplementGeometry (const HalfSpace &half_space, void *user_data)
virtual void ImplementGeometry (const Mesh &mesh, void *user_data)
virtual void ImplementGeometry (const MeshcatCone &cone, void *user_data)
virtual void ImplementGeometry (const Sphere &sphere, void *user_data)

Protected Member Functions

 ShapeReifier ()=default
virtual void DefaultImplementGeometry (const Shape &shape)
 The default implementation of ImplementGeometry(): it throws an exception using ThrowUnsupportedGeometry().
virtual void ThrowUnsupportedGeometry (const std::string &shape_name)
 Derived ShapeReifiers can replace the default message for unsupported geometries by overriding this method.
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 ShapeReifier (const ShapeReifier &)=default
ShapeReifieroperator= (const ShapeReifier &)=default
 ShapeReifier (ShapeReifier &&)=default
ShapeReifieroperator= (ShapeReifier &&)=default

Constructor & Destructor Documentation

◆ ~ShapeReifier()

virtual ~ShapeReifier ( )
virtual

◆ ShapeReifier() [1/3]

ShapeReifier ( const ShapeReifier & )
protecteddefault

◆ ShapeReifier() [2/3]

ShapeReifier ( ShapeReifier && )
protecteddefault

◆ ShapeReifier() [3/3]

ShapeReifier ( )
protecteddefault

Member Function Documentation

◆ DefaultImplementGeometry()

virtual void DefaultImplementGeometry ( const Shape & shape)
protectedvirtual

The default implementation of ImplementGeometry(): it throws an exception using ThrowUnsupportedGeometry().

The purpose of this function is to facilitate reifiers that would call the same API on all shapes (e.g., call an API with a Shape& parameter). This reduces the implementation boilerplate.

◆ ImplementGeometry() [1/9]

virtual void ImplementGeometry ( const Box & box,
void * user_data )
virtual

◆ ImplementGeometry() [2/9]

virtual void ImplementGeometry ( const Capsule & capsule,
void * user_data )
virtual

◆ ImplementGeometry() [3/9]

virtual void ImplementGeometry ( const Convex & convex,
void * user_data )
virtual

◆ ImplementGeometry() [4/9]

virtual void ImplementGeometry ( const Cylinder & cylinder,
void * user_data )
virtual

◆ ImplementGeometry() [5/9]

virtual void ImplementGeometry ( const Ellipsoid & ellipsoid,
void * user_data )
virtual

◆ ImplementGeometry() [6/9]

virtual void ImplementGeometry ( const HalfSpace & half_space,
void * user_data )
virtual

◆ ImplementGeometry() [7/9]

virtual void ImplementGeometry ( const Mesh & mesh,
void * user_data )
virtual

◆ ImplementGeometry() [8/9]

virtual void ImplementGeometry ( const MeshcatCone & cone,
void * user_data )
virtual

◆ ImplementGeometry() [9/9]

virtual void ImplementGeometry ( const Sphere & sphere,
void * user_data )
virtual

◆ operator=() [1/2]

ShapeReifier & operator= ( const ShapeReifier & )
protecteddefault

◆ operator=() [2/2]

ShapeReifier & operator= ( ShapeReifier && )
protecteddefault

◆ ThrowUnsupportedGeometry()

virtual void ThrowUnsupportedGeometry ( const std::string & shape_name)
protectedvirtual

Derived ShapeReifiers can replace the default message for unsupported geometries by overriding this method.

The name of the unsupported shape type is given as the single parameter.


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