Drake C++ Documentation
Shape Class Reference

Detailed Description

The base interface for all shape specifications.

It has no public constructor and cannot be instantiated directly. The Shape class has two key properties:

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

When you add a new subclass of Shape to Drake, you must:

  1. add a virtual function ImplementGeometry() for the new shape in ShapeReifier that invokes the ThrowUnsupportedGeometry method, and add to the test for it in shape_specification_test.cc.
  2. implement ImplementGeometry in derived ShapeReifiers to continue support if desired, otherwise ensure unimplemented functions are not hidden in new derivations of ShapeReifier with using, for example, using ShapeReifier::ImplementGeometry. Existing subclasses should already have this.

Otherwise, you might get a runtime error. We do not have an automatic way to enforce them at compile time.

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

Protected Member Functions

template<typename S >
 Shape (ShapeTag< S > tag)
 Constructor available for derived class construction. More...
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 Shape (const Shape &)=default
Shapeoperator= (const Shape &)=default
 Shape (Shape &&)=default
Shapeoperator= (Shape &&)=default

Constructor & Destructor Documentation

◆ ~Shape()

virtual ~Shape ( )

◆ Shape() [1/3]

Shape ( const Shape )

◆ Shape() [2/3]

Shape ( Shape &&  )

◆ Shape() [3/3]

Shape ( ShapeTag< S >  tag)

Constructor available for derived class construction.

A derived class should invoke this in its initialization list, passing a ShapeTag instantiated on its derived type, e.g.:

class MyShape final : public Shape {
MyShape() : Shape(ShapeTag<MyShape>()) {}

The base class provides infrastructure for cloning and reification. To work and to maintain sanity, we place the following requirements on derived classes:

  1. they must have a public copy constructor,
  2. they must be marked as final, and
  3. their constructors must invoke the parent constructor with a ShapeTag instance (as noted above), and
  4. The ShapeReifier class must be extended to include an invocation of ShapeReifier::ImplementGeometry() on the derived Shape class.
Template Parameters
SThe derived shape class. It must derive from Shape.

Member Function Documentation

◆ Clone()

std::unique_ptr<Shape> Clone ( ) const

Creates a unique copy of this shape.

◆ operator=() [1/2]

Shape& operator= ( Shape &&  )

◆ operator=() [2/2]

Shape& operator= ( const Shape )

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

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