Drake
Drake C++ Documentation
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.
}
};

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.
}
};

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(). More...
 
virtual void ThrowUnsupportedGeometry (const std::string &shape_name)
 Derived ShapeReifiers can replace the default message for unsupported geometries by overriding this method. More...
 
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: