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:
void ProcessShape(
const Shape& shape) {
}
...
}
};
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:
void ProcessShape(
const Shape& shape) {
ImportantData data{...};
shape.
Reify(
this, &data);
}
...
ImportantData& data = *static_cast<ImportantData*>(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.