The abstract base class for all shape specifications.
Concrete subclasses exist for specific shapes (e.g., Box, Mesh, etc.).
The Shape class has two key properties:
Note that the Shape class hierarchy is closed to third-party extensions. All Shape classes must be defined within Drake directly (and in this h/cc file pair in particular).
#include <drake/geometry/shape_specification.h>
Public Member Functions | |
| virtual | ~Shape () |
| void | Reify (ShapeReifier *reifier, void *user_data=nullptr) const |
Causes this description to be reified in the given reifier. More... | |
| std::unique_ptr< Shape > | Clone () const |
| Creates a unique copy of this shape. More... | |
| std::string_view | type_name () const |
| Returns the (unqualified) type name of this Shape, e.g., "Box". More... | |
| std::string | to_string () const |
| Returns a string representation of this shape. More... | |
| template<typename ReturnType = void, typename Visitor > | |
| decltype(auto) | Visit (Visitor &&visitor) const |
Calls the given visitor function with *this as the sole argument, but with *this downcast to be the shape's concrete subclass. More... | |
Protected Types | |
| using | VariantShapeConstPtr = std::variant< const Box *, const Capsule *, const Convex *, const Cylinder *, const Ellipsoid *, const HalfSpace *, const Mesh *, const MeshcatCone *, const Sphere * > |
| (Internal use only) All concrete subclasses, as const pointers. More... | |
Protected Member Functions | |
| Shape () | |
| (Internal use only) Constructor for use by derived classes. More... | |
| Shape (const Shape &)=default | |
| (Internal use only) For derived classes. More... | |
| Shape & | operator= (const Shape &)=default |
| (Internal use only) For derived classes. More... | |
| Shape (Shape &&)=default | |
| (Internal use only) For derived classes. More... | |
| Shape & | operator= (Shape &&)=default |
| (Internal use only) For derived classes. More... | |
| virtual void | DoReify (ShapeReifier *, void *) const =0 |
| (Internal use only) NVI for Reify(). More... | |
| virtual std::unique_ptr< Shape > | DoClone () const =0 |
| (Internal use only) NVI for Clone(). More... | |
| virtual std::string_view | do_type_name () const =0 |
| (Internal use only) NVI for type_name(). More... | |
| virtual std::string | do_to_string () const =0 |
| (Internal use only) NVI for to_string(). More... | |
| virtual VariantShapeConstPtr | get_variant_this () const =0 |
| (Internal use only) NVI-like helper function for Visit(). More... | |
|
protected |
(Internal use only) All concrete subclasses, as const pointers.
|
virtual |
|
protected |
(Internal use only) Constructor for use by derived classes.
All subclasses of Shape must be marked final.
| std::unique_ptr<Shape> Clone | ( | ) | const |
Creates a unique copy of this shape.
|
protectedpure virtual |
(Internal use only) NVI for to_string().
|
protectedpure virtual |
(Internal use only) NVI for type_name().
|
protectedpure virtual |
(Internal use only) NVI for Clone().
|
protectedpure virtual |
(Internal use only) NVI for Reify().
|
protectedpure virtual |
(Internal use only) NVI-like helper function for Visit().
| void Reify | ( | ShapeReifier * | reifier, |
| void * | user_data = nullptr |
||
| ) | const |
Causes this description to be reified in the given reifier.
Each concrete subclass must invoke the single, matching method on the reifier. Provides optional user-data (cast as a void*) for the reifier to consume.
| std::string to_string | ( | ) | const |
Returns a string representation of this shape.
| std::string_view type_name | ( | ) | const |
Returns the (unqualified) type name of this Shape, e.g., "Box".
| decltype(auto) Visit | ( | Visitor && | visitor | ) | const |
Calls the given visitor function with *this as the sole argument, but with *this downcast to be the shape's concrete subclass.
For example, if this shape is a Box then calls visitor(static_cast<const Box&>(*this)).
| ReturnType | The return type to coerce return values into. When not void, anything returned by the visitor must be implicitly convertible to this type. When void, the return type will be whatever the Vistor's call operator returns by default. |
To see examples of how this is used, you can check the Drake source code, e.g., check the implementation of CalcVolume() for one example.