diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d7068e..662b66b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,8 @@ qt_standard_project_setup() # glm find_package(glm REQUIRED) + + qt_add_executable(${AppExec} static/resources.qrc src/gui/main.cpp @@ -44,6 +46,12 @@ target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets target_include_directories(${AppExec} PUBLIC src) # tests -add_executable(${TestExec} tests/main-tests.cpp) +add_executable(${TestExec} + tests/main-tests.cpp + tests/OperatorTests.cpp + src/Engine/Operator/Attribute.cpp + # src/Engine/Operator/Primitive.cpp +) find_package(Catch2 3 REQUIRED) target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain) +target_include_directories(${TestExec} PUBLIC src) diff --git a/src/Engine/Operator/Attribute.cpp b/src/Engine/Operator/Attribute.cpp new file mode 100644 index 0000000..5217b16 --- /dev/null +++ b/src/Engine/Operator/Attribute.cpp @@ -0,0 +1,34 @@ +#include "Engine/Operator/Attribute.h" +#include "Engine/Types.h" +#include +#include +#include + +using namespace enzo; + + +ga::Attribute::Attribute(std::string name, ga::AttributeType type) +: name_{name}, type_{type} +{ + // init store + switch(type_) + { + case(AttrType::intT): + intStore_=std::make_shared>(); + break; + case(AttrType::floatT): + floatStore_=std::make_shared>(); + break; + default: + throw std::runtime_error("Type " + std::to_string(static_cast(type_)) + " was not accounted for"); + + } + +} + +ga::AttributeType ga::Attribute::getType() +{ + return type_; +} + + diff --git a/src/Engine/Operator/Attribute.h b/src/Engine/Operator/Attribute.h new file mode 100644 index 0000000..0601a2e --- /dev/null +++ b/src/Engine/Operator/Attribute.h @@ -0,0 +1,50 @@ +#pragma once +#include +#include +#include +#include "Engine/Types.h" +#include + + +namespace enzo{ + namespace ga{ + + template + class AttributeHandle; + + class Attribute + { + public: + Attribute(std::string name, ga::AttributeType type); + AttributeType getType(); + + + + template + friend class AttributeHandle; + + 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 attribute but not modify it + bool readOnly_=false; + + ga::AttributeType type_; + + std::string name_; + + void* data_; + + + // data stores + std::shared_ptr> intStore_; + std::shared_ptr> floatStore_; + }; + + + } +} diff --git a/src/Engine/Operator/AttributeHandle.h b/src/Engine/Operator/AttributeHandle.h new file mode 100644 index 0000000..f62932f --- /dev/null +++ b/src/Engine/Operator/AttributeHandle.h @@ -0,0 +1,94 @@ +#pragma once +#include +#include +#include +#include +#include "Engine/Operator/Attribute.h" + +#include + + +namespace enzo::ga{ + +template +class AttributeHandle +{ +public: + ga::AttributeType type_; + + AttributeHandle(Attribute& attribute) + { + type_ = attribute.getType(); + // get attribute data pointer + // TODO: check types match + // TODO: add the other types + if constexpr (std::is_same::value) + { + data_=attribute.intStore_; + } + else if constexpr (std::is_same::value) + { + data_=attribute.floatStore_; + } + else + { + throw std::runtime_error("Type " + std::to_string(static_cast(type_)) + " was not accounted for"); + } + // switch(type_) + // { + // case(AttrType::intT): + // { + // data_=attribute.intStore_; + // break; + // } + // case(AttrType::floatT): + // { + // data_=attribute.floatStore_; + // break; + // } + // default: + // throw std::runtime_error("Type " + std::to_string(static_cast(type_)) + " was not accounted for"); + + // } + + } + void addValue(T value) + { + // TODO:make this private (primitive friend classes only) + data_->push_back(value); + } + T getValue(uint pos) + { + // TODO:protect against invalid positions + // TODO: cast types + return data_->at(pos); + } + std::string getName() + { + 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> data_; + + // int typeID_; + +}; + +using AttributeHandleInt = AttributeHandle; +using AttributeHandleFloat = AttributeHandle; + +} diff --git a/src/Engine/Operator/Primitive.cpp b/src/Engine/Operator/Primitive.cpp new file mode 100644 index 0000000..c67b1d3 --- /dev/null +++ b/src/Engine/Operator/Primitive.cpp @@ -0,0 +1,24 @@ +#include "Engine/Operator/Primitive.h" +#include "Engine/Operator/Attribute.h" +#include "Engine/Types.h" + +enzo::Primitive::Primitive() +{ + +} + +bool enzo::Primitive::addIntAttrib(AttributeOwner owner, AttributeInt attribute) +{ + bool status = true; + + switch(owner) + { + case enzo::AttributeOwner::POINT: + pointAttribs_.push_back(attribute); + break; + + + } + pointAttribs_.push_back(attribute); + return status; +} diff --git a/src/Engine/Operator/Primitive.h b/src/Engine/Operator/Primitive.h new file mode 100644 index 0000000..2c04a1f --- /dev/null +++ b/src/Engine/Operator/Primitive.h @@ -0,0 +1,20 @@ +#pragma once +#include "Engine/Operator/Attribute.h" +#include "Engine/Types.h" +#include + +namespace enzo +{ +class Primitive +{ +public: + Primitive(); + bool addIntAttrib(AttributeOwner owner, AttributeInt attribute); + AttributeInt findAttribByName(AttributeOwner owner, std::string name); +private: + std::vector> pointAttribs_; +}; +} diff --git a/src/Engine/Types.h b/src/Engine/Types.h new file mode 100644 index 0000000..e01cd0e --- /dev/null +++ b/src/Engine/Types.h @@ -0,0 +1,25 @@ +#pragma once + +namespace enzo +{ + + namespace ga + { + enum class AttributeOwner + { + POINT, + VERTEX, + PRIMITIVE, + GLOBAL + }; + enum class AttributeType + { + intT, + floatT, + listT, + vectorT, + }; + using AttrType = AttributeType; + using AttrOwner = AttributeOwner; + } +} diff --git a/tests/OperatorTests.cpp b/tests/OperatorTests.cpp new file mode 100644 index 0000000..3193f32 --- /dev/null +++ b/tests/OperatorTests.cpp @@ -0,0 +1,41 @@ +#include +#include "Engine/Operator/Attribute.h" +#include "Engine/Operator/AttributeHandle.h" +#include "Engine/Types.h" +// #include "Engine/Operator/Primitive.h" + + +TEST_CASE("attrHandleInt") +{ + using namespace enzo; + + ga::Attribute myAttrib("test", ga::AttrType::intT); + ga::AttributeHandleInt myHandle(myAttrib); + myHandle.addValue(5); + myHandle.addValue(6); + REQUIRE(myHandle.getValue(0)==5); + REQUIRE(myHandle.getValue(1)==6); +} + +TEST_CASE("attrHandleFloat") +{ + using namespace enzo; + + ga::Attribute myAttrib("test", ga::AttrType::floatT); + ga::AttributeHandleFloat myHandle(myAttrib); + myHandle.addValue(5.3f); + myHandle.addValue(6.9f); + REQUIRE(myHandle.getValue(0)==5.3f); + REQUIRE(myHandle.getValue(1)==6.9f); +} + +TEST_CASE("Attribute Type") +{ + using namespace enzo; + REQUIRE(ga::AttributeType::intT == ga::AttributeType::intT); + REQUIRE(ga::AttributeType::intT != ga::AttributeType::floatT); + REQUIRE(ga::AttributeType::floatT == ga::AttributeType::floatT); + REQUIRE(ga::AttributeType::listT == ga::AttributeType::listT); + REQUIRE(ga::AttributeType::vectorT == ga::AttributeType::vectorT); + +}