feat(geometrySpreadsheet): read attributes from geometry
This commit is contained in:
@@ -15,15 +15,19 @@ ga::Attribute::Attribute(std::string name, ga::AttributeType type)
|
||||
{
|
||||
case(AttrType::intT):
|
||||
intStore_=std::make_shared<std::vector<bt::intT>>();
|
||||
typeSize_=1;
|
||||
break;
|
||||
case(AttrType::floatT):
|
||||
floatStore_=std::make_shared<std::vector<bt::floatT>>();
|
||||
typeSize_=1;
|
||||
break;
|
||||
case(AttrType::vectorT):
|
||||
vector3Store_=std::make_shared<std::vector<enzo::bt::Vector3>>();
|
||||
typeSize_=3;
|
||||
break;
|
||||
case(AttrType::boolT):
|
||||
boolStore_=std::make_shared<std::vector<enzo::bt::boolT>>();
|
||||
typeSize_=1;
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Type " + std::to_string(static_cast<int>(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_;
|
||||
}
|
||||
|
||||
@@ -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_;
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ public:
|
||||
data_->push_back(value);
|
||||
}
|
||||
|
||||
|
||||
void reserve(std::size_t newCap)
|
||||
{
|
||||
data_->reserve(newCap);
|
||||
|
||||
@@ -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<const ga::Attribute> 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<ga::Offset>::const_iterator geo::Geometry::soloPointsBegin()
|
||||
{
|
||||
@@ -265,7 +295,7 @@ ga::AttributeHandle<bt::Vector3> geo::Geometry::addVector3Attribute(ga::Attribut
|
||||
return ga::AttributeHandle<bt::Vector3>(newAttribute);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<ga::Attribute>>& geo::Geometry::getAttributeStore(ga::AttributeOwner& owner)
|
||||
geo::Geometry::attribVector& geo::Geometry::getAttributeStore(const ga::AttributeOwner& owner)
|
||||
{
|
||||
switch(owner)
|
||||
{
|
||||
@@ -286,6 +316,26 @@ std::vector<std::shared_ptr<ga::Attribute>>& 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<ga::Attribute> geo::Geometry::getAttribByName(ga::AttributeOwner owner, std::string name)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <CGAL/Surface_mesh/Surface_mesh.h>
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include "Engine/Operator/AttributeHandle.h"
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
|
||||
|
||||
@@ -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<std::shared_ptr<ga::Attribute>>::iterator;
|
||||
|
||||
class Geometry
|
||||
{
|
||||
public:
|
||||
@@ -29,6 +32,12 @@ public:
|
||||
ga::AttributeHandle<bt::Vector3> addVector3Attribute(ga::AttributeOwner owner, std::string name);
|
||||
// TODO: return weak ptr
|
||||
std::shared_ptr<ga::Attribute> getAttribByName(ga::AttributeOwner owner, std::string name);
|
||||
|
||||
const size_t getNumAttributes(const ga::AttributeOwner owner) const;
|
||||
std::weak_ptr<const ga::Attribute> getAttributeByIndex(ga::AttributeOwner owner, unsigned int index) const;
|
||||
// attributeIterator attributesBegin(const ga::AttributeOwner owner);
|
||||
// attributeIterator attributesEnd(const ga::AttributeOwner owner);
|
||||
|
||||
std::vector<bt::Vector3> derivePointNormals();
|
||||
HeMesh computeHalfEdgeMesh();
|
||||
void addFace(std::vector<ga::Offset> pointOffsets, bool closed=true);
|
||||
@@ -53,7 +62,8 @@ public:
|
||||
void computePrimStartVertices();
|
||||
private:
|
||||
using attribVector = std::vector<std::shared_ptr<ga::Attribute>>;
|
||||
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);
|
||||
|
||||
|
||||
@@ -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 <icecream.hpp>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
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; i<attribCount; ++i)
|
||||
{
|
||||
if(auto attrib = geometry_.getAttributeByIndex(enzo::ga::AttributeOwner::POINT, i).lock())
|
||||
{
|
||||
const auto size = attrib->getTypeSize();
|
||||
attribSizes_.push_back(size);
|
||||
|
||||
for(size_t j=0; j<size; ++j)
|
||||
{
|
||||
sectionAttribMap_.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
@@ -26,6 +52,18 @@ int GeometrySpreadsheetModel::rowCount(const QModelIndex &parent) const
|
||||
return geometry_.getNumPoints();
|
||||
}
|
||||
|
||||
int GeometrySpreadsheetModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
|
||||
int columnCount = 0;
|
||||
for(auto size : attribSizes_)
|
||||
{
|
||||
columnCount += size;
|
||||
}
|
||||
|
||||
return columnCount;
|
||||
}
|
||||
|
||||
QVariant GeometrySpreadsheetModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
@@ -49,6 +87,17 @@ QVariant GeometrySpreadsheetModel::data(const QModelIndex &index, int role) cons
|
||||
}
|
||||
}
|
||||
|
||||
int GeometrySpreadsheetModel::indexFromSection(unsigned int section) const
|
||||
{
|
||||
if(section>=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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<unsigned int> attribSizes_;
|
||||
std::vector<unsigned int> sectionAttribMap_;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user