feat(geometrySpreadsheet): read all attributes of different types from geometry
This commit is contained in:
@@ -73,7 +73,7 @@ ga::Attribute::Attribute(const Attribute& other)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ga::AttributeType ga::Attribute::getType()
|
ga::AttributeType ga::Attribute::getType() const
|
||||||
{
|
{
|
||||||
return type_;
|
return type_;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace enzo{
|
|||||||
public:
|
public:
|
||||||
Attribute(std::string name, ga::AttributeType type);
|
Attribute(std::string name, ga::AttributeType type);
|
||||||
Attribute(const Attribute& other);
|
Attribute(const Attribute& other);
|
||||||
AttributeType getType();
|
AttributeType getType() const;
|
||||||
std::string getName() const;
|
std::string getName() const;
|
||||||
unsigned int getTypeSize() const;
|
unsigned int getTypeSize() const;
|
||||||
|
|
||||||
@@ -29,6 +29,8 @@ namespace enzo{
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
friend class AttributeHandle;
|
friend class AttributeHandle;
|
||||||
|
template <typename T>
|
||||||
|
friend class AttributeHandleRO;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// private attributes are attributes that are hidden from the user
|
// private attributes are attributes that are hidden from the user
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public:
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for in AttributeHandle constructor");
|
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for in AttributeHandle constructor");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addValue(T value)
|
void addValue(T value)
|
||||||
{
|
{
|
||||||
// TODO:make this private (primitive friend classes only)
|
// TODO:make this private (primitive friend classes only)
|
||||||
@@ -119,4 +119,94 @@ using AttributeHandleFloat = AttributeHandle<bt::floatT>;
|
|||||||
using AttributeHandleVector3 = AttributeHandle<enzo::bt::Vector3>;
|
using AttributeHandleVector3 = AttributeHandle<enzo::bt::Vector3>;
|
||||||
using AttributeHandleBool = AttributeHandle<enzo::bt::boolT>;
|
using AttributeHandleBool = AttributeHandle<enzo::bt::boolT>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class AttributeHandleRO
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ga::AttributeType type_;
|
||||||
|
|
||||||
|
AttributeHandleRO(std::shared_ptr<const Attribute> attribute)
|
||||||
|
{
|
||||||
|
type_ = attribute->getType();
|
||||||
|
// get attribute data pointer
|
||||||
|
// TODO: check types match
|
||||||
|
// TODO: add the other types
|
||||||
|
|
||||||
|
// int
|
||||||
|
if constexpr (std::is_same<bt::intT, T>::value)
|
||||||
|
{
|
||||||
|
data_=attribute->intStore_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// float
|
||||||
|
else if constexpr (std::is_same<bt::floatT, T>::value)
|
||||||
|
{
|
||||||
|
data_=attribute->floatStore_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// vector 3
|
||||||
|
else if constexpr (std::is_same<enzo::bt::Vector3, T>::value)
|
||||||
|
{
|
||||||
|
data_=attribute->vector3Store_;
|
||||||
|
}
|
||||||
|
else if constexpr (std::is_same<enzo::bt::boolT, T>::value)
|
||||||
|
{
|
||||||
|
data_=attribute->boolStore_;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for in AttributeHandle constructor");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: replace with iterator
|
||||||
|
std::vector<T> getAllValues() const
|
||||||
|
{
|
||||||
|
return {data_->begin(), data_->end()};
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t getSize() const
|
||||||
|
{
|
||||||
|
return data_->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
T getValue(size_t pos) const
|
||||||
|
{
|
||||||
|
// TODO:protect against invalid positions
|
||||||
|
// TODO: cast types
|
||||||
|
return (*data_)[pos];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getName() const
|
||||||
|
{
|
||||||
|
return name_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
// private attributes are attributes that are hidden from the user
|
||||||
|
// for internal use
|
||||||
|
bool private_=false;
|
||||||
|
// hidden attributes are user accessible attributes that the user may
|
||||||
|
// or may want to use
|
||||||
|
bool hidden_=false;
|
||||||
|
// allows the user to read the attributeHandle but not modify it
|
||||||
|
bool readOnly_=false;
|
||||||
|
|
||||||
|
std::string name_="";
|
||||||
|
|
||||||
|
std::shared_ptr<StoreContainer<T>> data_;
|
||||||
|
|
||||||
|
// int typeID_;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
using AttributeHandleInt = AttributeHandle<bt::intT>;
|
||||||
|
using AttributeHandleFloat = AttributeHandle<bt::floatT>;
|
||||||
|
using AttributeHandleVector3 = AttributeHandle<enzo::bt::Vector3>;
|
||||||
|
using AttributeHandleBool = AttributeHandle<enzo::bt::boolT>;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h"
|
#include "Gui/GeometrySpreadsheetPanel/GeometrySpreadsheetModel.h"
|
||||||
#include "Engine/Network/NetworkManager.h"
|
#include "Engine/Network/NetworkManager.h"
|
||||||
#include "Engine/Operator/Attribute.h"
|
#include "Engine/Operator/Attribute.h"
|
||||||
|
#include "Engine/Operator/AttributeHandle.h"
|
||||||
#include "Engine/Operator/Geometry.h"
|
#include "Engine/Operator/Geometry.h"
|
||||||
#include "Engine/Types.h"
|
#include "Engine/Types.h"
|
||||||
#include <icecream.hpp>
|
#include <icecream.hpp>
|
||||||
@@ -17,19 +18,17 @@ GeometrySpreadsheetModel::GeometrySpreadsheetModel(const QStringList &strings, Q
|
|||||||
void GeometrySpreadsheetModel::geometryChanged(enzo::geo::Geometry& geometry)
|
void GeometrySpreadsheetModel::geometryChanged(enzo::geo::Geometry& geometry)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
// enzo::nt::NetworkManager& nm = enzo::nt::nm();
|
|
||||||
IC();
|
|
||||||
geometry_ = geometry;
|
geometry_ = geometry;
|
||||||
|
|
||||||
// get sizes
|
// get sizes
|
||||||
const auto attribCount = geometry_.getNumAttributes(enzo::ga::AttributeOwner::POINT);
|
const auto attribCount = geometry_.getNumAttributes(attributeOwner_);
|
||||||
|
|
||||||
attribSizes_.clear();
|
attribSizes_.clear();
|
||||||
attribSizes_.reserve(attribCount);
|
attribSizes_.reserve(attribCount);
|
||||||
|
|
||||||
for(size_t i=0; i<attribCount; ++i)
|
for(size_t i=0; i<attribCount; ++i)
|
||||||
{
|
{
|
||||||
if(auto attrib = geometry_.getAttributeByIndex(enzo::ga::AttributeOwner::POINT, i).lock())
|
if(auto attrib = geometry_.getAttributeByIndex(attributeOwner_, i).lock())
|
||||||
{
|
{
|
||||||
const auto size = attrib->getTypeSize();
|
const auto size = attrib->getTypeSize();
|
||||||
attribSizes_.push_back(size);
|
attribSizes_.push_back(size);
|
||||||
@@ -48,7 +47,27 @@ void GeometrySpreadsheetModel::geometryChanged(enzo::geo::Geometry& geometry)
|
|||||||
|
|
||||||
int GeometrySpreadsheetModel::rowCount(const QModelIndex &parent) const
|
int GeometrySpreadsheetModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
|
switch(attributeOwner_)
|
||||||
|
{
|
||||||
|
case enzo::ga::AttributeOwner::POINT:
|
||||||
|
{
|
||||||
return geometry_.getNumPoints();
|
return geometry_.getNumPoints();
|
||||||
|
}
|
||||||
|
case enzo::ga::AttributeOwner::VERTEX:
|
||||||
|
{
|
||||||
|
return geometry_.getNumVerts();
|
||||||
|
}
|
||||||
|
case enzo::ga::AttributeOwner::PRIMITIVE:
|
||||||
|
{
|
||||||
|
return geometry_.getNumPrims();
|
||||||
|
}
|
||||||
|
case enzo::ga::AttributeOwner::GLOBAL:
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GeometrySpreadsheetModel::columnCount(const QModelIndex &parent) const
|
int GeometrySpreadsheetModel::columnCount(const QModelIndex &parent) const
|
||||||
@@ -70,15 +89,57 @@ QVariant GeometrySpreadsheetModel::data(const QModelIndex &index, int role) cons
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index.row() >= geometry_.getNumPoints())
|
// TODO: reimplement check
|
||||||
{
|
// if (index.row() >= geometry_.getNumPoints())
|
||||||
return QVariant();
|
// {
|
||||||
}
|
// return QVariant();
|
||||||
|
// }
|
||||||
|
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
{
|
{
|
||||||
std::cout << geometry_.getPointPos(index.row()).x() << "\n";
|
|
||||||
return geometry_.getPointPos(index.row()).x();
|
// std::cout << geometry_.getPointPos(index.row()).x() << "\n";
|
||||||
|
int attributeIndex = indexFromSection(index.column());
|
||||||
|
if(std::shared_ptr<const enzo::ga::Attribute> attrib = geometry_.getAttributeByIndex(attributeOwner_, attributeIndex).lock())
|
||||||
|
{
|
||||||
|
const unsigned int valueIndex = index.column()-attributeIndex;
|
||||||
|
using namespace enzo::ga;
|
||||||
|
|
||||||
|
switch(attrib->getType())
|
||||||
|
{
|
||||||
|
case(AttributeType::intT):
|
||||||
|
{
|
||||||
|
const auto attribHandle = enzo::ga::AttributeHandleRO<enzo::bt::intT>(attrib);
|
||||||
|
return static_cast<float>(attribHandle.getValue(index.row()));
|
||||||
|
}
|
||||||
|
case(AttributeType::floatT):
|
||||||
|
{
|
||||||
|
const auto attribHandle = enzo::ga::AttributeHandleRO<enzo::bt::floatT>(attrib);
|
||||||
|
return attribHandle.getValue(index.row());
|
||||||
|
}
|
||||||
|
case(AttributeType::boolT):
|
||||||
|
{
|
||||||
|
const auto attribHandle = enzo::ga::AttributeHandleRO<enzo::bt::boolT>(attrib);
|
||||||
|
return attribHandle.getValue(index.row()) ? "true" : "false";
|
||||||
|
}
|
||||||
|
case(AttributeType::vectorT):
|
||||||
|
{
|
||||||
|
const auto attribHandle = enzo::ga::AttributeHandleRO<enzo::bt::Vector3>(attrib);
|
||||||
|
return attribHandle.getValue(index.row())[valueIndex];
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return "Failed";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Couldn't lock attribute");
|
||||||
|
}
|
||||||
|
// return geometry_.getPointPos(index.row()).x();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -105,7 +166,7 @@ QVariant GeometrySpreadsheetModel::headerData(int section, Qt::Orientation orien
|
|||||||
|
|
||||||
if (orientation == Qt::Horizontal)
|
if (orientation == Qt::Horizontal)
|
||||||
{
|
{
|
||||||
if(auto attrib = geometry_.getAttributeByIndex(enzo::ga::AttributeOwner::POINT, indexFromSection(section)).lock())
|
if(auto attrib = geometry_.getAttributeByIndex(attributeOwner_, indexFromSection(section)).lock())
|
||||||
{
|
{
|
||||||
return QString::fromStdString(attrib->getName());
|
return QString::fromStdString(attrib->getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,5 +27,6 @@ private:
|
|||||||
enzo::geo::Geometry geometry_;
|
enzo::geo::Geometry geometry_;
|
||||||
std::vector<unsigned int> attribSizes_;
|
std::vector<unsigned int> attribSizes_;
|
||||||
std::vector<unsigned int> sectionAttribMap_;
|
std::vector<unsigned int> sectionAttribMap_;
|
||||||
|
enzo::ga::AttributeOwner attributeOwner_=enzo::ga::AttributeOwner::PRIMITIVE;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ EnzoUI::EnzoUI()
|
|||||||
|
|
||||||
viewportSplitter_->addWidget(spreadsheetSplitter_);
|
viewportSplitter_->addWidget(spreadsheetSplitter_);
|
||||||
viewportSplitter_->addWidget(networkSplitter_);
|
viewportSplitter_->addWidget(networkSplitter_);
|
||||||
viewportSplitter_->setSizes({100,100});
|
viewportSplitter_->setSizes({100,300});
|
||||||
|
|
||||||
networkSplitter_->addWidget(parametersPanel);
|
networkSplitter_->addWidget(parametersPanel);
|
||||||
networkSplitter_->addWidget(network);
|
networkSplitter_->addWidget(network);
|
||||||
|
|||||||
Reference in New Issue
Block a user