Drake
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 a 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 ()=default
 
virtual void ImplementGeometry (const Sphere &sphere, void *user_data)
 
virtual void ImplementGeometry (const Cylinder &cylinder, void *user_data)
 
virtual void ImplementGeometry (const HalfSpace &half_space, void *user_data)
 
virtual void ImplementGeometry (const Box &box, void *user_data)
 
virtual void ImplementGeometry (const Capsule &capsule, void *user_data)
 
virtual void ImplementGeometry (const Ellipsoid &ellipsoid, void *user_data)
 
virtual void ImplementGeometry (const Mesh &mesh, void *user_data)
 
virtual void ImplementGeometry (const Convex &convex, void *user_data)
 

Protected Member Functions

 ShapeReifier ()=default
 
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 ( )
virtualdefault

◆ ShapeReifier() [1/3]

ShapeReifier ( const ShapeReifier )
protecteddefault

◆ ShapeReifier() [2/3]

ShapeReifier ( ShapeReifier &&  )
protecteddefault

◆ ShapeReifier() [3/3]

ShapeReifier ( )
protecteddefault

Member Function Documentation

◆ ImplementGeometry() [1/8]

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

Reimplemented in ShapeName, RenderEngineVtk, and RenderEngineGl.

◆ ImplementGeometry() [2/8]

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

Reimplemented in ShapeName, RenderEngineVtk, and RenderEngineGl.

◆ ImplementGeometry() [3/8]

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

Reimplemented in ShapeName, RenderEngineVtk, and RenderEngineGl.

◆ ImplementGeometry() [4/8]

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

Reimplemented in ShapeName, RenderEngineVtk, and RenderEngineGl.

◆ ImplementGeometry() [5/8]

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

Reimplemented in ShapeName, RenderEngineVtk, and RenderEngineGl.

◆ ImplementGeometry() [6/8]

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

Reimplemented in ShapeName, RenderEngineVtk, and RenderEngineGl.

◆ ImplementGeometry() [7/8]

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

Reimplemented in ShapeName, RenderEngineVtk, and RenderEngineGl.

◆ ImplementGeometry() [8/8]

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

Reimplemented in ShapeName, RenderEngineVtk, and RenderEngineGl.

◆ 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: