Drake
Drake C++ Documentation
Shape Class Referenceabstract

Detailed Description

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:

  • it is cloneable, and
  • it can be "reified" (see ShapeReifier).

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< ShapeClone () 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...
 
Shapeoperator= (const Shape &)=default
 (Internal use only) For derived classes. More...
 
 Shape (Shape &&)=default
 (Internal use only) For derived classes. More...
 
Shapeoperator= (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< ShapeDoClone () 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...
 

Member Typedef Documentation

◆ VariantShapeConstPtr

using VariantShapeConstPtr = std::variant< const Box*, const Capsule*, const Convex*, const Cylinder*, const Ellipsoid*, const HalfSpace*, const Mesh*, const MeshcatCone*, const Sphere*>
protected

(Internal use only) All concrete subclasses, as const pointers.

Constructor & Destructor Documentation

◆ ~Shape()

virtual ~Shape ( )
virtual

◆ Shape() [1/3]

Shape ( )
protected

(Internal use only) Constructor for use by derived classes.

All subclasses of Shape must be marked final.

◆ Shape() [2/3]

Shape ( const Shape )
protecteddefault

(Internal use only) For derived classes.

◆ Shape() [3/3]

Shape ( Shape &&  )
protecteddefault

(Internal use only) For derived classes.

Member Function Documentation

◆ Clone()

std::unique_ptr<Shape> Clone ( ) const

Creates a unique copy of this shape.

◆ do_to_string()

virtual std::string do_to_string ( ) const
protectedpure virtual

(Internal use only) NVI for to_string().

◆ do_type_name()

virtual std::string_view do_type_name ( ) const
protectedpure virtual

(Internal use only) NVI for type_name().

◆ DoClone()

virtual std::unique_ptr<Shape> DoClone ( ) const
protectedpure virtual

(Internal use only) NVI for Clone().

◆ DoReify()

virtual void DoReify ( ShapeReifier ,
void *   
) const
protectedpure virtual

(Internal use only) NVI for Reify().

◆ get_variant_this()

virtual VariantShapeConstPtr get_variant_this ( ) const
protectedpure virtual

(Internal use only) NVI-like helper function for Visit().

◆ operator=() [1/2]

Shape& operator= ( const Shape )
protecteddefault

(Internal use only) For derived classes.

◆ operator=() [2/2]

Shape& operator= ( Shape &&  )
protecteddefault

(Internal use only) For derived classes.

◆ Reify()

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.

◆ to_string()

std::string to_string ( ) const

Returns a string representation of this shape.

◆ type_name()

std::string_view type_name ( ) const

Returns the (unqualified) type name of this Shape, e.g., "Box".

◆ Visit()

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)).

Template Parameters
ReturnTypeThe 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.


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