SFCGAL 2.3.0
SFCGAL::Primitive Class Referenceabstract

Abstract base class for primitive object (Cube, Cylinder, Cone, etc.). More...

#include <Primitive.h>

Public Member Functions

 Primitive ()=default
 Default constructor.
virtual ~Primitive ()=default
 Destructor.
auto clone () const -> std::unique_ptr< Primitive >
 Get a deep copy of the primitive.
virtual auto primitiveType () const -> std::string=0
 returns the primitive type
virtual auto primitiveTypeId () const -> PrimitiveType=0
virtual auto generatePolyhedralSurface () const -> PolyhedralSurface=0
 Generates a surface mesh representation of the primitive.
void setParameter (const std::string &name, const PrimitiveParameter &parameter)
 Sets the value of a primitive parameter.
auto parameter (const std::string &name) const -> PrimitiveParameter
 Retrieves the value of a primitive parameter based ont its name.
auto parameters () const -> std::unordered_map< std::string, PrimitiveParameter >
 Retrieves the list of parameters.
void setTransformation (const Kernel::Aff_transformation_3 &transform)
 Sets the primitive affine transformation.
auto transformation () const -> Kernel::Aff_transformation_3
 Retrieves the primitive affine transformation.
void translate (const Kernel::Vector_3 &vector)
 Translates the primitive by the given vector.
void rotate (const Kernel::FT &angle, const Kernel::Vector_3 &axis, const Kernel::Point_3 &center=Kernel::Point_3(0, 0, 0))
 Rotates the primitive around a specified axis and center point by a given angle.
void scale (const Kernel::Vector_3 &factors, const Kernel::Point_3 &center=Kernel::Point_3(0, 0, 0))
 Scales the primitive by the given factor.
auto volume (bool withDiscretization=false) const -> double
 Returns the primitive volume.
virtual auto baseVolume (bool withDiscretization=false) const -> double=0
 Returns the sphere volume without scaling.
virtual auto area3D (bool withDiscretization=false) const -> double=0
 Returns the primitive area.
auto almostEqual (const Primitive &other, double epsilon) const -> bool
 Equality operator.
virtual auto toString () const -> std::string
 Returns string representation of this object.

Protected Member Functions

virtual void invalidateCache ()
 Invalidates the cached geometries.
virtual void validateParameters (std::unordered_map< std::string, PrimitiveParameter > const &tempParameters) const =0
 Verifies that all parameters are valid.
virtual void validateAndSetParameter (const std::string &name, const PrimitiveParameter &parameter)
 Checks that the new value is valid and sets it.
auto scaleFactor (int columnIdx) const -> double
 Returns the scale factor for a given column of the affine transform matrix.

Protected Attributes

std::unordered_map< std::string, PrimitiveParameter > m_parameters
 Holds parameter value according to their name.
std::optional< PolyhedralSurface > m_polyhedral_surface
 Cached PolyhedralSurface to avoid regeneration each time we call generatePolyhedralSurface().
Kernel::Aff_transformation_3 m_transform = CGAL::IDENTITY
 Holds primitive affine transformation.

Friends

auto operator<< (std::ostream &out, const Primitive &prim) -> std::ostream &
 overloaded operator<<

Detailed Description

Abstract base class for primitive object (Cube, Cylinder, Cone, etc.).

This class provides generic parameter functions to set, get, list member fields. All parameters needed by inherited classes must be declared in the constructor:

SubClass::SubClass(const Kernel::FT &radius, const Kernel::FT &height,
unsigned int num)
{
m_parameters["radius"] = radius;
m_parameters["height"] = height;
m_parameters["num"] = num;
SubClass::validateParameters(m_parameters);
}
std::unordered_map< std::string, PrimitiveParameter > m_parameters
Holds parameter value according to their name.
Definition Primitive.h:282

Constructor & Destructor Documentation

◆ Primitive()

SFCGAL::Primitive::Primitive ( )
default

Default constructor.

◆ ~Primitive()

virtual SFCGAL::Primitive::~Primitive ( )
virtualdefault

Destructor.

Member Function Documentation

◆ almostEqual()

auto SFCGAL::Primitive::almostEqual ( const Primitive & other,
double epsilon ) const -> bool
nodiscard

Equality operator.

Parameters
otherother geometry to compare to
epsilonallowed tolerance
Returns
true when this is almost equal

◆ area3D()

virtual auto SFCGAL::Primitive::area3D ( bool withDiscretization = false) const -> double
nodiscardpure virtual

Returns the primitive area.

Parameters
withDiscretizationComputes volume with discretization (true) or as perfect primitive (false). Defaults to false.
Returns
The primitive volume

◆ baseVolume()

virtual auto SFCGAL::Primitive::baseVolume ( bool withDiscretization = false) const -> double
pure virtual

Returns the sphere volume without scaling.

Parameters
withDiscretizationComputes volume with discretization (true) or as perfect primitive (false). Defaults to false.
Returns
The sphere volume

◆ clone()

auto SFCGAL::Primitive::clone ( ) const -> std::unique_ptr< Primitive >
inlinenodiscard

Get a deep copy of the primitive.

Returns
a deep copy of the primitive as a unique_ptr

◆ generatePolyhedralSurface()

virtual auto SFCGAL::Primitive::generatePolyhedralSurface ( ) const -> PolyhedralSurface
pure virtual

Generates a surface mesh representation of the primitive.

Returns
A PolyhedralSurface object representing the torus

◆ invalidateCache()

void SFCGAL::Primitive::invalidateCache ( )
protectedvirtual

Invalidates the cached geometries.

◆ parameter()

auto SFCGAL::Primitive::parameter ( const std::string & name) const -> PrimitiveParameter
nodiscard

Retrieves the value of a primitive parameter based ont its name.

Parameters
nameThe name of the parameter to retrieve.
Returns
The parameter value as a ::PrimitiveParameter variant.
Precondition
The parameter identified by name must exist.
Exceptions
SFCGAL::Exceptionif the parameter does not exist or if the provided variant type is not compatible with the parameter.

◆ parameters()

auto SFCGAL::Primitive::parameters ( ) const -> std::unordered_map< std::string, PrimitiveParameter >
nodiscard

Retrieves the list of parameters.

Returns
the key/value parameter map

◆ primitiveType()

virtual auto SFCGAL::Primitive::primitiveType ( ) const -> std::string
nodiscardpure virtual

returns the primitive type

Warning
use CamelCase (Cylinder, not CYLINDER)
Returns
the primitive type as string

◆ primitiveTypeId()

virtual auto SFCGAL::Primitive::primitiveTypeId ( ) const -> PrimitiveType
nodiscardpure virtual
Returns
a code corresponding to the type

◆ rotate()

void SFCGAL::Primitive::rotate ( const Kernel::FT & angle,
const Kernel::Vector_3 & axis,
const Kernel::Point_3 & center = Kernel::Point_3(0, 0, 0) )

Rotates the primitive around a specified axis and center point by a given angle.

Parameters
angleRotation angle in radians
axisThe rotation axis.
centerThe rotation center

◆ scale()

void SFCGAL::Primitive::scale ( const Kernel::Vector_3 & factors,
const Kernel::Point_3 & center = Kernel::Point_3(0, 0, 0) )

Scales the primitive by the given factor.

Parameters
factorsThe scale factors.
centerThe scale center.

◆ scaleFactor()

auto SFCGAL::Primitive::scaleFactor ( int columnIdx) const -> double
protected

Returns the scale factor for a given column of the affine transform matrix.

Parameters
columnIdxColumn index of the transform matrix (0 = X, 1 = Y, 2 = Z).
Returns
The scale factor along the corresponding axis.

◆ setParameter()

void SFCGAL::Primitive::setParameter ( const std::string & name,
const PrimitiveParameter & parameter )

Sets the value of a primitive parameter.

Assigns a new value to the parameter identified by name.

Parameters
nameThe name of the parameter to set.
parameterThe new parameter value as a ::PrimitiveParameter.
Precondition
The parameter identified by name must exist and accept the provided variant type.
Exceptions
SFCGAL::Exceptionif the parameter does not exist or if the provided variant type is not compatible with the parameter.

◆ setTransformation()

void SFCGAL::Primitive::setTransformation ( const Kernel::Aff_transformation_3 & transform)

Sets the primitive affine transformation.

Parameters
transformThe new affine transformation

◆ toString()

auto SFCGAL::Primitive::toString ( ) const -> std::string
nodiscardvirtual

Returns string representation of this object.

Can be overriden by sub-classes.

Returns
string representation of this object

◆ transformation()

auto SFCGAL::Primitive::transformation ( ) const -> Kernel::Aff_transformation_3
nodiscard

Retrieves the primitive affine transformation.

Returns
the primitive affine transformation

◆ translate()

void SFCGAL::Primitive::translate ( const Kernel::Vector_3 & vector)

Translates the primitive by the given vector.

Parameters
vectorThe translation vector.

◆ validateAndSetParameter()

void SFCGAL::Primitive::validateAndSetParameter ( const std::string & name,
const PrimitiveParameter & parameter )
protectedvirtual

Checks that the new value is valid and sets it.

This also invalidates the cache. Unlike setParameter, this does not check that name exists and that it accepts the provided variant type. This assumes that name exists and the variant type is compatible with the parameter

Parameters
nameparameter name to check
parametervalue
Exceptions
SFCGAL::Exceptionif the parameter is not valid

◆ validateParameters()

virtual void SFCGAL::Primitive::validateParameters ( std::unordered_map< std::string, PrimitiveParameter > const & tempParameters) const
protectedpure virtual

Verifies that all parameters are valid.

For instance, it raises an error if a radius is negative.

Parameters
tempParametersa temp map of parameter with new values
Exceptions
SFCGAL::Exceptionif one of the parameters if not valid provided variant type is not compatible with the parameter.

◆ volume()

auto SFCGAL::Primitive::volume ( bool withDiscretization = false) const -> double
nodiscard

Returns the primitive volume.

Parameters
withDiscretizationComputes area with discretization (true) or as perfect primitive (false). Defaults to false.
Returns
The cone volume

◆ operator<<

auto operator<< ( std::ostream & out,
const Primitive & prim ) -> std::ostream &
friend

overloaded operator<<

Parameters
outstream to fill
primprimitive to print via Primitive::toString()
Returns
filled stream

Member Data Documentation

◆ m_parameters

std::unordered_map<std::string, PrimitiveParameter> SFCGAL::Primitive::m_parameters
protected

Holds parameter value according to their name.

◆ m_polyhedral_surface

std::optional<PolyhedralSurface> SFCGAL::Primitive::m_polyhedral_surface
mutableprotected

Cached PolyhedralSurface to avoid regeneration each time we call generatePolyhedralSurface().

◆ m_transform

Kernel::Aff_transformation_3 SFCGAL::Primitive::m_transform = CGAL::IDENTITY
protected

Holds primitive affine transformation.