SFCGAL  2.3.0
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
SFCGAL::Primitive Class Referenceabstract

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

#include <Primitive.h>

Inherited by SFCGAL::PrimitiveImpl< Box, Primitive >, SFCGAL::PrimitiveImpl< Cone, Primitive >, SFCGAL::PrimitiveImpl< Cube, Primitive >, SFCGAL::PrimitiveImpl< Cylinder, Primitive >, SFCGAL::PrimitiveImpl< Sphere, Primitive >, and SFCGAL::PrimitiveImpl< Torus, Primitive >.

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Friends

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

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);
}

Constructor & Destructor Documentation

SFCGAL::Primitive::Primitive ( )
default

Default constructor.

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

Destructor.

Member Function Documentation

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

Equality operator.

Parameters
otherother geometry to compare to
epsilonallowed tolerance
Returns
true when this is almost equal
virtual auto SFCGAL::Primitive::area3D ( bool  withDiscretization = false) const -> double
pure virtual

Returns the primitive area.

Parameters
withDiscretizationComputes volume with discretization (true) or as perfect primitive (false). Defaults to false.
Returns
The primitive volume
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
auto SFCGAL::Primitive::clone ( ) const -> std::unique_ptr<Primitive>
inline

Get a deep copy of the primitive.

Returns
a deep copy of the primitive as a unique_ptr
virtual auto SFCGAL::Primitive::generatePolyhedralSurface ( ) const -> PolyhedralSurface
pure virtual

Generates a surface mesh representation of the primitive.

Returns
A PolyhedralSurface object representing the torus
void SFCGAL::Primitive::invalidateCache ( )
protectedvirtual

Invalidates the cached geometries.

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

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.
auto SFCGAL::Primitive::parameters ( ) const -> std::unordered_map<std::string, PrimitiveParameter>

Retrieves the list of parameters.

Returns
the key/value parameter map
virtual auto SFCGAL::Primitive::primitiveType ( ) const -> std::string
pure virtual

returns the primitive type

Warning
use CamelCase (Cylinder, not CYLINDER)
Returns
the primitive type as string
virtual auto SFCGAL::Primitive::primitiveTypeId ( ) const -> PrimitiveType
pure virtual
Returns
a code corresponding to the type
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
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.
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.
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.
void SFCGAL::Primitive::setTransformation ( const Kernel::Aff_transformation_3 &  transform)

Sets the primitive affine transformation.

Parameters
transformThe new affine transformation
auto SFCGAL::Primitive::toString ( ) const -> std::string
virtual

Returns string representation of this object.

Can be overriden by sub-classes.

Returns
string representation of this object
auto SFCGAL::Primitive::transformation ( ) const -> Kernel::Aff_transformation_3

Retrieves the primitive affine transformation.

Returns
the primitive affine transformation
void SFCGAL::Primitive::translate ( const Kernel::Vector_3 &  vector)

Translates the primitive by the given vector.

Parameters
vectorThe translation vector.
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
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.
auto SFCGAL::Primitive::volume ( bool  withDiscretization = false) const -> double

Returns the primitive volume.

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

Friends And Related Function Documentation

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

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

Holds parameter value according to their name.

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

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

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

Holds primitive affine transformation.