diff --git a/src/Engine/Operator/Attribute.cpp b/src/Engine/Operator/Attribute.cpp index 637aa72..bfbd264 100644 --- a/src/Engine/Operator/Attribute.cpp +++ b/src/Engine/Operator/Attribute.cpp @@ -15,15 +15,19 @@ ga::Attribute::Attribute(std::string name, ga::AttributeType type) { case(AttrType::intT): intStore_=std::make_shared>(); + typeSize_=1; break; case(AttrType::floatT): floatStore_=std::make_shared>(); + typeSize_=1; break; case(AttrType::vectorT): vector3Store_=std::make_shared>(); + typeSize_=3; break; case(AttrType::boolT): boolStore_=std::make_shared>(); + typeSize_=1; break; default: throw std::runtime_error("Type " + std::to_string(static_cast(type_)) + " was not properly accounted for in Attribute constructor"); @@ -32,6 +36,13 @@ ga::Attribute::Attribute(std::string name, ga::AttributeType type) } +unsigned int ga::Attribute::Attribute::getTypeSize() const +{ + return typeSize_; +} + + + ga::Attribute::Attribute(const Attribute& other) { type_ = other.type_; @@ -39,6 +50,7 @@ ga::Attribute::Attribute(const Attribute& other) hidden_ = other.hidden_; readOnly_ = other.readOnly_; name_ = other.name_; + typeSize_ = other.typeSize_; switch(type_) { @@ -66,7 +78,7 @@ ga::AttributeType ga::Attribute::getType() return type_; } -std::string ga::Attribute::getName() +std::string ga::Attribute::getName() const { return name_; } diff --git a/src/Engine/Operator/Attribute.h b/src/Engine/Operator/Attribute.h index 8f4c6ad..4a7bdb2 100644 --- a/src/Engine/Operator/Attribute.h +++ b/src/Engine/Operator/Attribute.h @@ -22,7 +22,8 @@ namespace enzo{ Attribute(std::string name, ga::AttributeType type); Attribute(const Attribute& other); AttributeType getType(); - std::string getName(); + std::string getName() const; + unsigned int getTypeSize() const; @@ -40,6 +41,7 @@ namespace enzo{ bool readOnly_=false; ga::AttributeType type_; + unsigned int typeSize_=1; std::string name_; diff --git a/src/Engine/Operator/AttributeHandle.h b/src/Engine/Operator/AttributeHandle.h index 0178409..5f0909a 100644 --- a/src/Engine/Operator/AttributeHandle.h +++ b/src/Engine/Operator/AttributeHandle.h @@ -59,6 +59,7 @@ public: data_->push_back(value); } + void reserve(std::size_t newCap) { data_->reserve(newCap); diff --git a/src/Engine/Operator/Geometry.cpp b/src/Engine/Operator/Geometry.cpp index a3e1cdc..a66204c 100644 --- a/src/Engine/Operator/Geometry.cpp +++ b/src/Engine/Operator/Geometry.cpp @@ -63,6 +63,36 @@ ga::Offset geo::Geometry::getNumSoloPoints() const } +// enzo::geo::attributeIterator geo::Geometry::attributesBegin(const ga::AttributeOwner owner) +// { +// return getAttributeStore(owner).begin(); + +// } + +// enzo::geo::attributeIterator geo::Geometry::attributesEnd(const ga::AttributeOwner owner) +// { +// return getAttributeStore(owner).end(); +// } + +const size_t geo::Geometry::getNumAttributes(const ga::AttributeOwner owner) const +{ + return getAttributeStore(owner).size(); +} + +std::weak_ptr geo::Geometry::getAttributeByIndex(ga::AttributeOwner owner, unsigned int index) const +{ + auto attribStore = getAttributeStore(owner); + if(index>=attribStore.size()) + { + throw std::out_of_range("Attribute index out of range: " + std::to_string(index) + " max size: " + std::to_string(attribStore.size()) + "\n"); + } + return getAttributeStore(owner)[index]; + +} + + + + std::set::const_iterator geo::Geometry::soloPointsBegin() { @@ -265,7 +295,7 @@ ga::AttributeHandle geo::Geometry::addVector3Attribute(ga::Attribut return ga::AttributeHandle(newAttribute); } -std::vector>& geo::Geometry::getAttributeStore(ga::AttributeOwner& owner) +geo::Geometry::attribVector& geo::Geometry::getAttributeStore(const ga::AttributeOwner& owner) { switch(owner) { @@ -286,6 +316,26 @@ std::vector>& geo::Geometry::getAttributeStore(ga } } +const geo::Geometry::attribVector& geo::Geometry::getAttributeStore(const ga::AttributeOwner& owner) const +{ + switch(owner) + { + case ga::AttributeOwner::POINT: + return pointAttributes_; + break; + case ga::AttributeOwner::VERTEX: + return vertexAttributes_; + break; + case ga::AttributeOwner::PRIMITIVE: + return primitiveAttributes_; + break; + case ga::AttributeOwner::GLOBAL: + return globalAttributes_; + break; + default: + throw std::runtime_error("Unexpected, owner could not be found"); + } +} std::shared_ptr geo::Geometry::getAttribByName(ga::AttributeOwner owner, std::string name) { diff --git a/src/Engine/Operator/Geometry.h b/src/Engine/Operator/Geometry.h index 5d9516a..8e9f0e5 100644 --- a/src/Engine/Operator/Geometry.h +++ b/src/Engine/Operator/Geometry.h @@ -4,6 +4,7 @@ #include #include #include "Engine/Operator/AttributeHandle.h" +#include #include @@ -19,6 +20,8 @@ using faceDescriptor = HeMesh::Face_index; using V_index = HeMesh::Vertex_index; using F_index = HeMesh::Face_index; +using attributeIterator = std::vector>::iterator; + class Geometry { public: @@ -29,6 +32,12 @@ public: ga::AttributeHandle addVector3Attribute(ga::AttributeOwner owner, std::string name); // TODO: return weak ptr std::shared_ptr getAttribByName(ga::AttributeOwner owner, std::string name); + + const size_t getNumAttributes(const ga::AttributeOwner owner) const; + std::weak_ptr getAttributeByIndex(ga::AttributeOwner owner, unsigned int index) const; + // attributeIterator attributesBegin(const ga::AttributeOwner owner); + // attributeIterator attributesEnd(const ga::AttributeOwner owner); + std::vector derivePointNormals(); HeMesh computeHalfEdgeMesh(); void addFace(std::vector pointOffsets, bool closed=true); @@ -53,7 +62,8 @@ public: void computePrimStartVertices(); private: using attribVector = std::vector>; - attribVector& getAttributeStore(ga::AttributeOwner& owner); + geo::Geometry::attribVector& getAttributeStore(const ga::AttributeOwner& owner); + const geo::Geometry::attribVector& getAttributeStore(const ga::AttributeOwner& owner) const; attribVector deepCopyAttributes(attribVector source); diff --git a/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.cpp b/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.cpp index 89877a0..cb5c395 100644 --- a/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.cpp +++ b/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.cpp @@ -1,8 +1,11 @@ #include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h" #include "Engine/Network/NetworkManager.h" +#include "Engine/Operator/Attribute.h" #include "Engine/Operator/Geometry.h" #include "Engine/Types.h" #include +#include +#include GeometrySpreadsheetModel::GeometrySpreadsheetModel(const QStringList &strings, QObject *parent) @@ -18,6 +21,29 @@ void GeometrySpreadsheetModel::selectionChanged(enzo::nt::OpId opId) opId_ = opId; IC(); geometry_ = nm.getGeoOperator(opId).getOutputGeo(0); + + // get sizes + const auto attribCount = geometry_.getNumAttributes(enzo::ga::AttributeOwner::POINT); + + attribSizes_.clear(); + attribSizes_.reserve(attribCount); + + for(size_t i=0; igetTypeSize(); + attribSizes_.push_back(size); + + for(size_t j=0; j=sectionAttribMap_.size()) + { + throw std::out_of_range("Section is out of range of sectionAttributMap_"); + } + IC(sectionAttribMap_); + return sectionAttribMap_[section]; +} + + QVariant GeometrySpreadsheetModel::headerData(int section, Qt::Orientation orientation, int role) const { @@ -56,7 +105,19 @@ QVariant GeometrySpreadsheetModel::headerData(int section, Qt::Orientation orien return QVariant(); if (orientation == Qt::Horizontal) - return QStringLiteral("Column %1").arg(section); + { + if(auto attrib = geometry_.getAttributeByIndex(enzo::ga::AttributeOwner::POINT, indexFromSection(section)).lock()) + { + return QString::fromStdString(attrib->getName()); + } + else + { + throw std::runtime_error("failed to lock attriubte index"); + } + + } else + { return QStringLiteral("Row %1").arg(section); + } } diff --git a/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h b/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h index 953cbfa..a4385df 100644 --- a/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h +++ b/src/Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h @@ -12,9 +12,11 @@ public: GeometrySpreadsheetModel(const QStringList &strings, QObject *parent = nullptr); int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + int indexFromSection(unsigned int section) const; void selectionChanged(enzo::nt::OpId opId); @@ -23,5 +25,7 @@ private: QStringList stringList; enzo::nt::OpId opId_; enzo::geo::Geometry geometry_; + std::vector attribSizes_; + std::vector sectionAttribMap_; };