Enzo
Loading...
Searching...
No Matches
enzo::geo::Primitive Class Referenceabstract

Base class for all primitive types in the engine. More...

#include <Primitive.h>

Inheritance diagram for enzo::geo::Primitive:
enzo::geo::Camera enzo::geo::Mesh

Classes

struct  PointOffsets
 

Public Member Functions

 Primitive (std::string_view path="/prim")
 
 Primitive (const Primitive &other)
 
Primitiveoperator= (const Primitive &rhs)
 
virtual PrimType getType () const =0
 
virtual std::shared_ptr< Primitiveclone () const =0
 
virtual TransformClass transformType () const =0
 
virtual void applyTransform (const Matrix4 &mat, TransformClass transformClass)=0
 
void applyTransform (const Transform &transform, TransformClass transformClass)
 
virtual bool canMerge () const
 
virtual void merge (std::shared_ptr< Primitive > other)
 
void incrementVersion ()
 
virtual bool hasPoints () const
 
Offset getNumPoints () const
 
virtual PointOffsets getPoints ()
 
virtual bool isValidPoint (Offset offset) const
 
virtual void deletePoints (const std::vector< Offset > &pointOffsets)
 
virtual void defragment ()
 Compacts storage, removing entries marked invalid so offsets are contiguous again.
 
std::shared_ptr< attr::AttributeaddAttribute (attr::AttributeOwner owner, std::string name, attr::AttributeType type, bool intrinsic=false, bool isInternal=false)
 Returns the attribute of this name and type, adding one when the name is free.
 
std::shared_ptr< attr::AttributetryAddAttribute (attr::AttributeOwner owner, std::string name, attr::AttributeType type, bool intrinsic=false, bool isInternal=false)
 Returns the attribute of this name and type, adding one when the name is free.
 
template<typename T >
attr::AttributeHandle< T > addAttribute (attr::AttributeOwner owner, std::string name, bool intrinsic=false, bool isInternal=false)
 Returns a handle to the attribute of this type stored under this name, adding one when the name is free.
 
template<typename T >
std::optional< attr::AttributeHandle< T > > tryAddAttribute (attr::AttributeOwner owner, std::string name, bool intrinsic=false, bool isInternal=false)
 Returns a handle to the attribute of this type stored under this name, adding one when the name is free.
 
std::shared_ptr< attr::AttributegetAttribByName (attr::AttributeOwner owner, std::string name, bool includeIntrinsics=false)
 
std::shared_ptr< const attr::AttributegetAttribByName (attr::AttributeOwner owner, std::string name, bool includeIntrinsics=false) const
 Const counterpart of getAttribByName.
 
const size_t getNumAttributes (const attr::AttributeOwner owner) const
 
std::weak_ptr< const attr::AttributegetAttributeByIndex (attr::AttributeOwner owner, unsigned int index) const
 
std::vector< std::shared_ptr< const attr::Attribute > > getAttributes (attr::AttributeOwner owner, bool includeIntrinsics=false) const
 Returns every attribute on the owner.
 
bool attributeExists (attr::AttributeOwner owner, std::string name)
 
attr::AttributeHandleBool addGroup (attr::AttributeOwner owner, std::string name)
 Returns the group of this name on the given owner, adding one when the name is free.
 
void addToGroup (attr::AttributeOwner owner, const std::string &name, const std::vector< Offset > &offsets)
 Marks the given offsets as members of the group.
 
std::shared_ptr< attr::AttributegetGroupByName (attr::AttributeOwner owner, const std::string &name) const
 Looks up a group by name.
 
size_t getNumGroups (attr::AttributeOwner owner) const
 Returns how many groups live on the given owner.
 
std::weak_ptr< const attr::AttributegetGroupByIndex (attr::AttributeOwner owner, unsigned int index) const
 Returns the group at the given index in the owner's group store.
 
std::vector< std::shared_ptr< const attr::Attribute > > getGroups (attr::AttributeOwner owner) const
 Returns every group on the owner.
 
void addAttributesFrom (const Primitive &source, attr::AttributeOwner owner)
 Adds each attribute and group of the source to this primitive, keeping its name and type.
 
attr::AttributeHandleBool addPointGroup (std::string name)
 Returns the point group of this name, adding one when the name is free.
 
attr::AttributeHandleBool addPrimitiveGroup (std::string name)
 Returns the primitive group of this name, adding one when the name is free.
 
void addToPointGroup (const std::string &name, const std::vector< Offset > &offsets)
 Marks the given offsets as members of the point group.
 
void addToPrimitiveGroup (const std::string &name, const std::vector< Offset > &offsets)
 Marks the given offsets as members of the primitive group.
 
String getPath () const
 
void setPath (const String &path)
 

Protected Member Functions

virtual attr::attribVector & getAttributeStore (const attr::AttributeOwner &owner)
 
virtual const attr::attribVector & getAttributeStore (const attr::AttributeOwner &owner) const
 
virtual attr::attribVector & getGroupStore (const attr::AttributeOwner &owner)
 
virtual const attr::attribVector & getGroupStore (const attr::AttributeOwner &owner) const
 
attr::attribVector deepCopyAttributes (attr::attribVector source)
 
size_t getElementCount (const attr::AttributeOwner &owner) const
 Returns the number of elements in the given owner's store.
 

Protected Attributes

std::string path_ = "/prim"
 
attr::attribVector pointAttributes_
 
attr::attribVector primitiveAttributes_
 
attr::attribVector pointGroups_
 
attr::attribVector primitiveGroups_
 

Detailed Description

Base class for all primitive types in the engine.

A Primitive is the unit of geometry exchanged between nodes. It holds primitive-level attributes (one value per object) and provides the attribute management API shared by all primitive types.

Point attributes are stored on the base class since many primitive types have points. Use hasPoints() to check before accessing them.

Subclasses (e.g. Mesh) add their own attribute owners and geometry.

Member Function Documentation

◆ addAttribute() [1/2]

std::shared_ptr< attr::Attribute > enzo::geo::Primitive::addAttribute ( attr::AttributeOwner owner,
std::string name,
attr::AttributeType type,
bool intrinsic = false,
bool isInternal = false )

Returns the attribute of this name and type, adding one when the name is free.

Exceptions
std::runtime_errorWhen the name belongs to an internal attribute or to an intrinsic of another type.
Note
An ordinary attribute of another type under the same name is replaced, dropping its values.

◆ addAttribute() [2/2]

template<typename T >
attr::AttributeHandle< T > enzo::geo::Primitive::addAttribute ( attr::AttributeOwner owner,
std::string name,
bool intrinsic = false,
bool isInternal = false )
inline

Returns a handle to the attribute of this type stored under this name, adding one when the name is free.

Exceptions
std::runtime_errorWhen the name belongs to an internal attribute or to an intrinsic of another type.
Note
An ordinary attribute of another type under the same name is replaced, dropping its values.

◆ addAttributesFrom()

void enzo::geo::Primitive::addAttributesFrom ( const Primitive & source,
attr::AttributeOwner owner )

Adds each attribute and group of the source to this primitive, keeping its name and type.

Note
Names this primitive already holds are left alone.

◆ addGroup()

attr::AttributeHandleBool enzo::geo::Primitive::addGroup ( attr::AttributeOwner owner,
std::string name )

Returns the group of this name on the given owner, adding one when the name is free.

Note
Groups are boolean flags that mark elements as members. A group and an attribute can share a name without colliding.

◆ defragment()

virtual void enzo::geo::Primitive::defragment ( )
inlinevirtual

Compacts storage, removing entries marked invalid so offsets are contiguous again.

Reimplemented in enzo::geo::Mesh.

◆ getAttribByName()

std::shared_ptr< const attr::Attribute > enzo::geo::Primitive::getAttribByName ( attr::AttributeOwner owner,
std::string name,
bool includeIntrinsics = false ) const

Const counterpart of getAttribByName.

Returns a read only shared pointer so the caller cannot mutate the attribute through a const Primitive.

◆ getAttributes()

std::vector< std::shared_ptr< const attr::Attribute > > enzo::geo::Primitive::getAttributes ( attr::AttributeOwner owner,
bool includeIntrinsics = false ) const

Returns every attribute on the owner.

Note
Internal attributes are left out, like getAttributeByIndex.

◆ getElementCount()

size_t enzo::geo::Primitive::getElementCount ( const attr::AttributeOwner & owner) const
protected

Returns the number of elements in the given owner's store.

Returns
The element count.

◆ getGroupByName()

std::shared_ptr< attr::Attribute > enzo::geo::Primitive::getGroupByName ( attr::AttributeOwner owner,
const std::string & name ) const

Looks up a group by name.

Returns
The matching group, or nullptr if no such group exists.

◆ tryAddAttribute() [1/2]

std::shared_ptr< attr::Attribute > enzo::geo::Primitive::tryAddAttribute ( attr::AttributeOwner owner,
std::string name,
attr::AttributeType type,
bool intrinsic = false,
bool isInternal = false )

Returns the attribute of this name and type, adding one when the name is free.

Returns
The attribute, or nullptr when the name belongs to an internal attribute or to an intrinsic of another type.
Note
An ordinary attribute of another type under the same name is replaced, dropping its values.

◆ tryAddAttribute() [2/2]

template<typename T >
std::optional< attr::AttributeHandle< T > > enzo::geo::Primitive::tryAddAttribute ( attr::AttributeOwner owner,
std::string name,
bool intrinsic = false,
bool isInternal = false )
inline

Returns a handle to the attribute of this type stored under this name, adding one when the name is free.

Returns
The handle, or nothing when the name belongs to an internal attribute or to an intrinsic of another type.
Note
An ordinary attribute of another type under the same name is replaced, dropping its values.

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