Enzo
Loading...
Searching...
No Matches
Geometry.h
1#pragma once
2#include "Engine/Operator/Attribute.h"
3#include "Engine/Types.h"
4#include <CGAL/Surface_mesh/Surface_mesh.h>
5#include <CGAL/Simple_cartesian.h>
6#include "Engine/Operator/AttributeHandle.h"
7#include <memory>
8#include <tbb/spin_mutex.h>
9#include <tbb/spin_mutex.h>
10#include <variant>
11
12
13
14namespace enzo::geo
15{
16using Kernel = CGAL::Simple_cartesian<double>;
17using Point = Kernel::Point_3;
18using Vector = Kernel::Vector_3;
19using HeMesh = CGAL::Surface_mesh<Point>;
20using vertexDescriptor = HeMesh::Vertex_index;
21using faceDescriptor = HeMesh::Face_index;
22using V_index = HeMesh::Vertex_index;
23using F_index = HeMesh::Face_index;
24
25using attributeIterator = std::vector<std::shared_ptr<ga::Attribute>>::iterator;
26
53class Geometry
54{
55public:
56 Geometry();
57 Geometry(const Geometry& other);
58
64 Geometry& operator=(const Geometry& rhs);
65
72 ga::AttributeHandle<bt::intT> addIntAttribute(ga::AttributeOwner owner, std::string name);
73
80 ga::AttributeHandleBool addBoolAttribute(ga::AttributeOwner owner, std::string name);
81
88 ga::AttributeHandle<bt::Vector3> addVector3Attribute(ga::AttributeOwner owner, std::string name);
89
96 std::shared_ptr<ga::Attribute> getAttribByName(ga::AttributeOwner owner, std::string name);
97
103 const size_t getNumAttributes(const ga::AttributeOwner owner) const;
104
111 std::weak_ptr<const ga::Attribute> getAttributeByIndex(ga::AttributeOwner owner, unsigned int index) const;
112
117 // std::vector<bt::Vector3> derivePointNormals();
118
123 HeMesh computeHalfEdgeMesh();
124
130 void addFace(const std::vector<ga::Offset>& pointOffsets, bool closed=true);
131
136 void addPoint(const bt::Vector3& pos);
137
142 std::set<ga::Offset>::const_iterator soloPointsBegin();
143
148 std::set<ga::Offset>::const_iterator soloPointsEnd();
149
155 void setPointPos(const ga::Offset offset, const bt::Vector3& pos);
156
162 ga::Offset getPrimStartVertex(ga::Offset primOffset) const;
163
169 bt::Vector3 getPosFromVert(ga::Offset vertexOffset) const;
170
176 bt::Vector3 getPointPos(ga::Offset pointOffset) const;
177
183 unsigned int getPrimVertCount(ga::Offset primOffset) const;
184
190 ga::Offset getVertexPrim(ga::Offset vertexOffset) const;
191
196 ga::Offset getNumPrims() const;
197
202 ga::Offset getNumVerts() const;
203
208 ga::Offset getNumPoints() const;
209
216 ga::Offset getNumSoloPoints() const;
217
226 bt::boolT isClosed(ga::Offset primOffset) const;
227
232 void merge(Geometry& other);
233
238 void computePrimStartVertices() const;
239private:
240 using attribVector = std::vector<std::shared_ptr<ga::Attribute>>;
241 geo::Geometry::attribVector& getAttributeStore(const ga::AttributeOwner& owner);
242 const geo::Geometry::attribVector& getAttributeStore(const ga::AttributeOwner& owner) const;
243
244 attribVector deepCopyAttributes(attribVector source);
245
246 attribVector pointAttributes_;
247 attribVector vertexAttributes_;
248 attribVector primitiveAttributes_;
249 attribVector globalAttributes_;
250
251 std::set<ga::Offset> soloPoints_;
252
253 mutable std::vector<ga::Offset> primStarts_;
254 mutable std::vector<ga::Offset> vertexPrims_;
255
256 mutable std::atomic<bool> primStartsDirty_{true};
257 mutable tbb::spin_mutex primStartsMutex_;
258
259 // handles
260 enzo::ga::AttributeHandleInt vertexCountHandlePrim_;
261 enzo::ga::AttributeHandleBool closedHandlePrim_;
262 enzo::ga::AttributeHandleInt pointOffsetHandleVert_;
263 enzo::ga::AttributeHandleVector3 posHandlePoint_;
264};
265}
Basic attribute, parameter, and node types for Enzo.
AttributeOwner
The segment of geometry that owns a particular attribute.
Definition Types.h:23
Read write accessor for enzo::ga::Attribute.
Attribute based geometry container exchanged and modified by nodes.
ga::Offset getNumPrims() const
Gets the number of primitives in the geometry.
Definition Geometry.cpp:200
ga::AttributeHandle< bt::Vector3 > addVector3Attribute(ga::AttributeOwner owner, std::string name)
Adds a 3D vector attribute to the geometry.
Definition Geometry.cpp:369
std::set< ga::Offset >::const_iterator soloPointsEnd()
Iterator to the end of the set of solo (isolated) points.
Definition Geometry.cpp:164
bt::Vector3 getPosFromVert(ga::Offset vertexOffset) const
Gets the 3 dimensional position from a vertex offset.
Definition Geometry.cpp:171
ga::Offset getNumSoloPoints() const
Gets the number of isolated points in the geometry. Isolated points are points that are not connnecte...
Definition Geometry.cpp:121
void merge(Geometry &other)
Merges another geometry into this one.
std::weak_ptr< const ga::Attribute > getAttributeByIndex(ga::AttributeOwner owner, unsigned int index) const
Retrieves an attribute by its index.
Definition Geometry.cpp:144
void addFace(const std::vector< ga::Offset > &pointOffsets, bool closed=true)
Adds a polygonal face to the geometry.
Definition Geometry.cpp:101
bt::Vector3 getPointPos(ga::Offset pointOffset) const
Gets the position of a point.
Definition Geometry.cpp:179
Geometry & operator=(const Geometry &rhs)
Assignment operator. Performs a deep copy of another Geometry.
Definition Geometry.cpp:44
void addPoint(const bt::Vector3 &pos)
Adds a point to the geometry.
Definition Geometry.cpp:115
std::set< ga::Offset >::const_iterator soloPointsBegin()
Iterator to the beginning of the set of solo (isolated) points.
Definition Geometry.cpp:159
void setPointPos(const ga::Offset offset, const bt::Vector3 &pos)
Sets the position of a point.
Definition Geometry.cpp:189
ga::AttributeHandleBool addBoolAttribute(ga::AttributeOwner owner, std::string name)
Adds a boolean attribute to the geometry.
Definition Geometry.cpp:356
ga::Offset getPrimStartVertex(ga::Offset primOffset) const
Gets the first vertex of a primitive.
Definition Geometry.cpp:317
ga::AttributeHandle< bt::intT > addIntAttribute(ga::AttributeOwner owner, std::string name)
Adds an integer attribute to the geometry.
Definition Geometry.cpp:349
HeMesh computeHalfEdgeMesh()
Computes per-point normals for the geometry.
Definition Geometry.cpp:242
bt::boolT isClosed(ga::Offset primOffset) const
Checks if a primitive is closed or open.
Definition Geometry.cpp:363
std::shared_ptr< ga::Attribute > getAttribByName(ga::AttributeOwner owner, std::string name)
Retrieves an attribute by its name.
Definition Geometry.cpp:418
unsigned int getPrimVertCount(ga::Offset primOffset) const
Gets the number of vertices in a primitive.
Definition Geometry.cpp:195
const size_t getNumAttributes(const ga::AttributeOwner owner) const
Gets the number of attributes owned by a specific element type.
Definition Geometry.cpp:139
ga::Offset getNumVerts() const
Gets the number of vertices in the geometry.
Definition Geometry.cpp:205
void computePrimStartVertices() const
Computes the starting vertex for each primitive in the geometry.
Definition Geometry.cpp:332
ga::Offset getVertexPrim(ga::Offset vertexOffset) const
Gets the primitive that owns a given vertex.
Definition Geometry.cpp:184
ga::Offset getNumPoints() const
Gets the number of points in the geometry.
Definition Geometry.cpp:210