refactor: cleanup setPosBuffer funciton, add getters for geometry

This commit is contained in:
parker
2025-08-03 03:22:52 +01:00
parent 48ad8909cc
commit 488ff9ff72
6 changed files with 139 additions and 65 deletions

View File

@@ -55,13 +55,18 @@ public:
data_->push_back(value);
}
void reserve(std::size_t newCap)
{
data_->reserve(newCap);
}
// TODO: replace with iterator
std::vector<T> getAllValues() const
{
return {data_->begin(), data_->end()};
}
size_t getSize()
size_t getSize() const
{
return data_->size();
}
@@ -70,7 +75,7 @@ public:
{
// TODO:protect against invalid positions
// TODO: cast types
return data_->at(pos);
return data_[pos];
}
void setValue(size_t pos, const T& value)

View File

@@ -10,22 +10,67 @@
#include "icecream.hpp"
using namespace enzo;
geo::Geometry::Geometry()
geo::Geometry::Geometry() :
vertexCountHandlePrim_{addIntAttribute(ga::AttrOwner::PRIMITIVE, "vertexCount")},
pointOffsetHandleVert_{addIntAttribute(ga::AttrOwner::VERTEX, "point")},
posHandlePoint_{addVector3Attribute(ga::AttrOwner::POINT, "P")}
{
addVector3Attribute(ga::AttrOwner::POINT, "P");
addIntAttribute(ga::AttrOwner::VERTEX, "point");
addIntAttribute(ga::AttrOwner::PRIMITIVE, "vertexCount");
}
geo::Geometry::Geometry(const Geometry& other)
geo::Geometry::Geometry(const Geometry& other):
pointAttributes_{deepCopyAttributes(other.pointAttributes_)},
vertexAttributes_{deepCopyAttributes(other.vertexAttributes_)},
primitiveAttributes_{deepCopyAttributes(other.primitiveAttributes_)},
globalAttributes_{deepCopyAttributes(other.globalAttributes_)},
vertexCountHandlePrim_{enzo::ga::AttributeHandleInt(getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount"))},
pointOffsetHandleVert_{enzo::ga::AttributeHandleInt(getAttribByName(ga::AttrOwner::VERTEX, "point"))},
posHandlePoint_{enzo::ga::AttributeHandleVector3(getAttribByName(ga::AttrOwner::POINT, "P"))}
{
pointAttributes_ = deepCopyAttributes(other.pointAttributes_);
vertexAttributes_ = deepCopyAttributes(other.vertexAttributes_);
primitiveAttributes_ = deepCopyAttributes(other.primitiveAttributes_);
globalAttributes_ = deepCopyAttributes(other.globalAttributes_);
}
void geo::Geometry::addFace(std::initializer_list<ga::Offset> pointOffsets)
{
for(ga::Offset pointOffset : pointOffsets)
{
pointOffsetHandleVert_.addValue(pointOffset);
}
vertexCountHandlePrim_.addValue(pointOffsets.size());
}
bt::Vector3 geo::Geometry::getPosFromVert(ga::Offset vertexOffset) const
{
// get point offset
const ga::Offset pointOffset = pointOffsetHandleVert_.getValue(vertexOffset);
// get value at point offset
return posHandlePoint_.getValue(pointOffset);
}
bt::Vector3 geo::Geometry::getPointPos(ga::Offset pointOffset) const
{
return posHandlePoint_.getValue(pointOffset);
}
unsigned int geo::Geometry::getPrimVertCount(ga::Offset primOffset) const
{
return vertexCountHandlePrim_.getValue(primOffset);
}
ga::Offset geo::Geometry::getNumPrims() const
{
return vertexCountHandlePrim_.getSize();
}
ga::Offset geo::Geometry::getNumVerts() const
{
return pointOffsetHandleVert_.getSize();
}
geo::Geometry::attribVector geo::Geometry::deepCopyAttributes(attribVector originalVector)
{
geo::Geometry::attribVector copied;
@@ -125,6 +170,25 @@ enzo::geo::HeMesh geo::Geometry::computeHalfEdgeMesh()
return heMesh;
}
unsigned int geo::Geometry::getPrimStartVertex(ga::Offset primOffset)
{
const ga::Offset handleSize = vertexCountHandlePrim_.getSize();
// TODO: add smarter system to recompute primStarts_, also move to separate function
// if size changed, recompute
if(handleSize!=primStarts_.size())
{
bt::intT primStart = 0;
for(size_t i=0; i<handleSize; ++i)
{
primStarts_.push_back(primStart);
primStart += vertexCountHandlePrim_.getValue(i);
}
}
return primStarts_[primOffset];
}
ga::AttributeHandle<int> geo::Geometry::addIntAttribute(ga::AttributeOwner owner, std::string name)
{

View File

@@ -3,6 +3,7 @@
#include "Engine/Types.h"
#include <CGAL/Surface_mesh/Surface_mesh.h>
#include <CGAL/Simple_cartesian.h>
#include "Engine/Operator/AttributeHandle.h"
#include <variant>
@@ -29,6 +30,15 @@ public:
std::shared_ptr<ga::Attribute> getAttribByName(ga::AttributeOwner owner, std::string name);
std::vector<bt::Vector3> derivePointNormals();
HeMesh computeHalfEdgeMesh();
// returns the first vertex of the primitive
unsigned int getPrimStartVertex(ga::Offset primOffset);
void addFace(std::initializer_list<ga::Offset> pointOffsets);
bt::Vector3 getPosFromVert(ga::Offset vertexOffset) const;
bt::Vector3 getPointPos(ga::Offset pointOffset) const;
unsigned int getPrimVertCount(ga::Offset primOffset) const;
ga::Offset getNumPrims() const;
ga::Offset getNumVerts() const;
private:
using attribVector = std::vector<std::shared_ptr<ga::Attribute>>;
attribVector& getAttributeStore(ga::AttributeOwner& owner);
@@ -39,5 +49,12 @@ private:
attribVector vertexAttributes_;
attribVector primitiveAttributes_;
attribVector globalAttributes_;
std::vector<ga::Offset> primStarts_;
// handles
enzo::ga::AttributeHandleInt vertexCountHandlePrim_;
enzo::ga::AttributeHandleInt pointOffsetHandleVert_;
enzo::ga::AttributeHandleVector3 posHandlePoint_;
};
}