Enzo
Loading...
Searching...
No Matches
enzo::geo::Mesh Class Reference

Polygonal mesh primitive with point, vertex, and face attributes. More...

#include <Mesh.h>

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

Classes

struct  FaceOffsets
 

Public Member Functions

 Mesh (std::string_view path="/mesh")
 
 Mesh (const Mesh &other)
 
Meshoperator= (const Mesh &rhs)
 
PrimType getType () const override
 
std::shared_ptr< Primitiveclone () const override
 
TransformClass transformType () const override
 
void applyTransform (const Matrix4 &mat, TransformClass transformClass=TransformClass::POINT) override
 
void applyTransform (const Transform &transform, TransformClass transformClass=TransformClass::POINT)
 
bool canMerge () const override
 
void merge (std::shared_ptr< Primitive > other) override
 
bool hasPoints () const override
 
Offset addFace (const std::vector< Offset > &pointOffsets, bool closed=true)
 Adds a single face. Avoid for multiple faces in a loop as a single call to addFaces is much more performant.
 
std::vector< OffsetaddFaces (std::span< const Offset > pointOffsetsFlat, std::span< const Offset > vertexCounts, bool closed=true)
 Adds many faces in a single call.
 
Offset addPoint (const Vector3 &pos)
 
std::vector< OffsetaddPoints (std::span< const Vector3 > positions)
 Adds many points in a single call.
 
std::vector< OffsetduplicatePoints (std::span< const Offset > srcPointOffsets, bool copyAttributes=true)
 Duplicates existing points into new points carrying the same positions.
 
void deleteFaces (const std::vector< Offset > &faceOffsets, bool andPoints=true)
 
void deleteAllFaces (bool andPoints=true)
 Removes every face from the mesh.
 
void deletePoints (const std::vector< Offset > &pointOffsets) override
 
void deletePoints (const std::vector< Offset > &pointOffsets, bool andFaces)
 
void deleteVertices (const std::vector< Offset > &vertOffsets)
 
bool isValidFace (Offset offset) const
 
bool isValidVertex (Offset offset) const
 
bool isValidPoint (Offset offset) const override
 
void defragment () override
 Compacts storage, removing entries marked invalid so offsets are contiguous again.
 
void merge (Mesh &other)
 
std::unordered_set< Offset >::const_iterator soloPointsBegin () const
 
std::unordered_set< Offset >::const_iterator soloPointsEnd () const
 
void setPointPos (const Offset offset, const Vector3 &pos)
 
std::span< const OffsetgetFaceStartVertices () const
 Contiguous view of each face's starting vertex offset.
 
Vector3 getPosFromVert (Offset vertexOffset) const
 
Vector3 getPointPos (Offset pointOffset) const
 
unsigned int getFaceVertCount (Offset faceOffset) const
 
unsigned int getFacePointCount (Offset faceOffset) const
 
Offset getVertexFace (Offset vertexOffset) const
 
Offset getVertexPoint (Offset vertexOffset) const
 
std::span< const intT > getFacePoints (Offset faceOffset) const
 
std::span< const intT > vertexPointSpan () const
 Contiguous view mapping each vertex offset to its point offset.
 
std::span< const Vector3 > pointPosSpan () const
 Contiguous view of every point position.
 
Offset getNumFaces () const
 
Offset getNumVerts () const
 
Offset getNumSoloPoints () const
 
FaceOffsets getFaces () const
 
attr::AttributeHandleBool addVertexGroup (std::string name)
 Returns the vertex group of this name, adding one when the name is free.
 
attr::AttributeHandleBool addFaceGroup (std::string name)
 Returns the face group of this name, adding one when the name is free.
 
void addToVertexGroup (const std::string &name, const std::vector< Offset > &offsets)
 Marks the given offsets as members of the vertex group.
 
void addToFaceGroup (const std::string &name, const std::vector< Offset > &offsets)
 Marks the given offsets as members of the face group.
 
boolT isClosed (Offset faceOffset) const
 
void computeFaceStartVertices () const
 
FaceNormalHandle getFaceNormal (bool precompute=false) const
 Returns a handle for reading per-face normals.
 
VertexNormalHandle getVertexNormal (double cuspAngle=kDefaultCuspAngle) const
 Returns a handle for reading per-vertex normals.
 
PointNormalHandle getPointNormal () const
 Returns a handle for reading per-point normals.
 
- Public Member Functions inherited from enzo::geo::Primitive
 Primitive (std::string_view path="/prim")
 
 Primitive (const Primitive &other)
 
Primitiveoperator= (const Primitive &rhs)
 
void applyTransform (const Transform &transform, TransformClass transformClass)
 
void incrementVersion ()
 
Offset getNumPoints () const
 
virtual PointOffsets getPoints ()
 
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

attr::attribVector & getAttributeStore (const attr::AttributeOwner &owner) override
 
const attr::attribVector & getAttributeStore (const attr::AttributeOwner &owner) const override
 
attr::attribVector & getGroupStore (const attr::AttributeOwner &owner) override
 
const attr::attribVector & getGroupStore (const attr::AttributeOwner &owner) const override
 
- Protected Member Functions inherited from enzo::geo::Primitive
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.
 

Friends

class FaceNormalHandle
 
class VertexNormalHandle
 

Additional Inherited Members

- Protected Attributes inherited from enzo::geo::Primitive
std::string path_ = "/prim"
 
attr::attribVector pointAttributes_
 
attr::attribVector primitiveAttributes_
 
attr::attribVector pointGroups_
 
attr::attribVector primitiveGroups_
 

Detailed Description

Polygonal mesh primitive with point, vertex, and face attributes.

Extends Primitive with mesh-specific topology: points, vertices, faces, and the intrinsic attributes that describe connectivity (vertexCount, closed, point offset, and Position).

Member Function Documentation

◆ addFace()

Offset enzo::geo::Mesh::addFace ( const std::vector< Offset > & pointOffsets,
bool closed = true )

Adds a single face. Avoid for multiple faces in a loop as a single call to addFaces is much more performant.

Returns
Offset of the new face.

◆ addFaces()

std::vector< Offset > enzo::geo::Mesh::addFaces ( std::span< const Offset > pointOffsetsFlat,
std::span< const Offset > vertexCounts,
bool closed = true )

Adds many faces in a single call.

Parameters
pointOffsetsFlatAll point offsets for every face listed one after another.
vertexCountsHow many points each face has. Read in the same order as pointOffsetsFlat.
Returns
Offsets of the newly created faces in the order they were added.

◆ addPoints()

std::vector< Offset > enzo::geo::Mesh::addPoints ( std::span< const Vector3 > positions)

Adds many points in a single call.

Parameters
positionsPosition for each new point, read in order.
Returns
Offsets of the newly created points in the order they were added.

◆ applyTransform()

void enzo::geo::Mesh::applyTransform ( const Matrix4 & mat,
TransformClass transformClass = TransformClass::POINT )
overridevirtual

Implements enzo::geo::Primitive.

◆ canMerge()

bool enzo::geo::Mesh::canMerge ( ) const
inlineoverridevirtual

Reimplemented from enzo::geo::Primitive.

◆ clone()

std::shared_ptr< Primitive > enzo::geo::Mesh::clone ( ) const
inlineoverridevirtual

Implements enzo::geo::Primitive.

◆ defragment()

void enzo::geo::Mesh::defragment ( )
overridevirtual

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

Reimplemented from enzo::geo::Primitive.

◆ deletePoints()

void enzo::geo::Mesh::deletePoints ( const std::vector< Offset > & pointOffsets)
inlineoverridevirtual

Reimplemented from enzo::geo::Primitive.

◆ duplicatePoints()

std::vector< Offset > enzo::geo::Mesh::duplicatePoints ( std::span< const Offset > srcPointOffsets,
bool copyAttributes = true )

Duplicates existing points into new points carrying the same positions.

Parameters
srcPointOffsetsOffsets of the points to duplicate, read in order.
copyAttributesWhen true, copy every point attribute from each source point. When false, only positions are copied.
Returns
Offsets of the newly created points in the same order as srcPointOffsets.

◆ getAttributeStore() [1/2]

const attr::attribVector & enzo::geo::Mesh::getAttributeStore ( const attr::AttributeOwner & owner) const
overrideprotectedvirtual

Reimplemented from enzo::geo::Primitive.

◆ getAttributeStore() [2/2]

attr::attribVector & enzo::geo::Mesh::getAttributeStore ( const attr::AttributeOwner & owner)
overrideprotectedvirtual

Reimplemented from enzo::geo::Primitive.

◆ getFaceNormal()

geo::FaceNormalHandle enzo::geo::Mesh::getFaceNormal ( bool precompute = false) const

Returns a handle for reading per-face normals.

Normals follow the right hand rule on CCW winding viewed from outside the surface. When the mesh has a face attribute named Normal the handle reads it directly. Otherwise normals are computed via Newell's method.

Parameters
precomputeWhen true and no Normal face attribute is present, every face normal is computed up front so subsequent reads are O(1). Pay this cost when the caller plans to read most faces; skip it for sparse access.
Returns
Handle whose operator[] returns the normal for a face offset.

◆ getFaceStartVertices()

std::span< const Offset > enzo::geo::Mesh::getFaceStartVertices ( ) const

Contiguous view of each face's starting vertex offset.

Returns
Span indexed by face offset. Invalid after a mutation that grows storage.

◆ getGroupStore() [1/2]

const attr::attribVector & enzo::geo::Mesh::getGroupStore ( const attr::AttributeOwner & owner) const
overrideprotectedvirtual

Reimplemented from enzo::geo::Primitive.

◆ getGroupStore() [2/2]

attr::attribVector & enzo::geo::Mesh::getGroupStore ( const attr::AttributeOwner & owner)
overrideprotectedvirtual

Reimplemented from enzo::geo::Primitive.

◆ getPointNormal()

geo::PointNormalHandle enzo::geo::Mesh::getPointNormal ( ) const

Returns a handle for reading per-point normals.

A point attribute named Normal is read when present, otherwise the normals are computed.

Returns
Handle whose operator[] returns the normal for a point offset.

◆ getType()

PrimType enzo::geo::Mesh::getType ( ) const
inlineoverridevirtual

Implements enzo::geo::Primitive.

◆ getVertexNormal()

geo::VertexNormalHandle enzo::geo::Mesh::getVertexNormal ( double cuspAngle = kDefaultCuspAngle) const

Returns a handle for reading per-vertex normals.

A vertex attribute named Normal is read first, then a point attribute of the same name, and failing both the normals are computed at the given cusp angle.

Parameters
cuspAngleThe widest angle between two faces that still counts as smooth, in degrees. Only reached when neither attribute is present.
Returns
Handle whose operator[] returns the normal for a vertex offset.

◆ hasPoints()

bool enzo::geo::Mesh::hasPoints ( ) const
inlineoverridevirtual

Reimplemented from enzo::geo::Primitive.

◆ isValidPoint()

bool enzo::geo::Mesh::isValidPoint ( Offset offset) const
overridevirtual

Reimplemented from enzo::geo::Primitive.

◆ merge()

void enzo::geo::Mesh::merge ( std::shared_ptr< Primitive > other)
overridevirtual

Reimplemented from enzo::geo::Primitive.

◆ pointPosSpan()

std::span< const Vector3 > enzo::geo::Mesh::pointPosSpan ( ) const
inline

Contiguous view of every point position.

Returns
Span indexed by point offset. Invalid after a mutation that grows storage.

◆ transformType()

TransformClass enzo::geo::Mesh::transformType ( ) const
inlineoverridevirtual

Implements enzo::geo::Primitive.

◆ vertexPointSpan()

std::span< const intT > enzo::geo::Mesh::vertexPointSpan ( ) const
inline

Contiguous view mapping each vertex offset to its point offset.

Returns
Span indexed by vertex offset. Invalid after a mutation that grows storage.

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