diff --git a/CMakeLists.txt b/CMakeLists.txt index 0600e95..7e56fbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,9 @@ qt_standard_project_setup() # glm find_package(glm REQUIRED) +# eigen (math) +find_package (Eigen3 3.3 REQUIRED NO_MODULE) + qt_add_executable(${AppExec} @@ -45,7 +48,7 @@ qt_add_executable(${AppExec} src/Engine/Operator/Geometry.cpp ) -target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm) +target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm Eigen3::Eigen) target_include_directories(${AppExec} PUBLIC src) # tests @@ -56,5 +59,5 @@ add_executable(${TestExec} src/Engine/Operator/Geometry.cpp ) find_package(Catch2 3 REQUIRED) -target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain) +target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen) target_include_directories(${TestExec} PUBLIC src) diff --git a/src/Engine/Operator/Attribute.cpp b/src/Engine/Operator/Attribute.cpp index a074f56..c240e48 100644 --- a/src/Engine/Operator/Attribute.cpp +++ b/src/Engine/Operator/Attribute.cpp @@ -19,6 +19,9 @@ ga::Attribute::Attribute(std::string name, ga::AttributeType type) case(AttrType::floatT): floatStore_=std::make_shared>(); break; + case(AttrType::vectorT): + vector3Store_=std::make_shared>(); + break; default: throw std::runtime_error("Type " + std::to_string(static_cast(type_)) + " was not properly accounted for"); diff --git a/src/Engine/Operator/Attribute.h b/src/Engine/Operator/Attribute.h index 2820bc1..c4e1142 100644 --- a/src/Engine/Operator/Attribute.h +++ b/src/Engine/Operator/Attribute.h @@ -45,6 +45,7 @@ namespace enzo{ // data stores std::shared_ptr> intStore_; std::shared_ptr> floatStore_; + std::shared_ptr> vector3Store_; }; diff --git a/src/Engine/Operator/AttributeHandle.h b/src/Engine/Operator/AttributeHandle.h index 257bdfd..9f17c7e 100644 --- a/src/Engine/Operator/AttributeHandle.h +++ b/src/Engine/Operator/AttributeHandle.h @@ -5,6 +5,7 @@ #include #include #include "Engine/Operator/Attribute.h" +#include "Engine/Types.h" #include @@ -23,14 +24,24 @@ public: // get attribute data pointer // TODO: check types match // TODO: add the other types + + // int if constexpr (std::is_same::value) { data_=attribute->intStore_; } + + // float else if constexpr (std::is_same::value) { data_=attribute->floatStore_; } + + // vector 3 + else if constexpr (std::is_same::value) + { + data_=attribute->vector3Store_; + } else { throw std::runtime_error("Type " + std::to_string(static_cast(type_)) + " was not properly accounted for"); @@ -75,5 +86,6 @@ private: using AttributeHandleInt = AttributeHandle; using AttributeHandleFloat = AttributeHandle; +using AttributeHandleVector3 = AttributeHandle; } diff --git a/src/Engine/Types.h b/src/Engine/Types.h index e01cd0e..9b1cca8 100644 --- a/src/Engine/Types.h +++ b/src/Engine/Types.h @@ -1,4 +1,5 @@ #pragma once +#include namespace enzo { @@ -22,4 +23,10 @@ namespace enzo using AttrType = AttributeType; using AttrOwner = AttributeOwner; } + // basic types types + namespace bt + { + using Vector3 = Eigen::Vector3d; + using Vector4 = Eigen::Vector4d; + } } diff --git a/src/Engine/Types/Vector.cpp b/src/Engine/Types/Vector.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/gui/viewport/ViewportGLWidget.cpp b/src/gui/viewport/ViewportGLWidget.cpp index 041d56e..a40c0f5 100644 --- a/src/gui/viewport/ViewportGLWidget.cpp +++ b/src/gui/viewport/ViewportGLWidget.cpp @@ -1,4 +1,5 @@ -#include "gui/viewport/ViewportGLWidget.h" #include "gui/viewport/GLMesh.h" +#include "gui/viewport/ViewportGLWidget.h" +#include "gui/viewport/GLMesh.h" #include #include #include diff --git a/tests/OperatorTests.cpp b/tests/OperatorTests.cpp index 170cf25..8655b06 100644 --- a/tests/OperatorTests.cpp +++ b/tests/OperatorTests.cpp @@ -54,6 +54,18 @@ TEST_CASE("attrHandleFloat") REQUIRE(myHandle.getValue(1)==6.9f); } +TEST_CASE("attrHandleVector3") +{ + using namespace enzo; + + std::shared_ptr myAttrib = std::make_shared("test", ga::AttrType::vectorT); + ga::AttributeHandleVector3 myHandle(myAttrib); + myHandle.addValue(bt::Vector3(5,10,15)); + myHandle.addValue(bt::Vector3(1,2,3)); + REQUIRE(myHandle.getValue(0)==bt::Vector3(5,10,15)); + REQUIRE(myHandle.getValue(1)==bt::Vector3(1,2,3)); +} + TEST_CASE("Attribute Type") { using namespace enzo; @@ -64,3 +76,27 @@ TEST_CASE("Attribute Type") REQUIRE(ga::AttributeType::vectorT == ga::AttributeType::vectorT); } + +TEST_CASE("Vector3") +{ + using namespace enzo; + bt::Vector3 u(1,2,3); + bt::Vector3 v(1,2,3); + REQUIRE(u == v); + REQUIRE(u*2 == bt::Vector3(2,4,6)); + REQUIRE(2*u == bt::Vector3(2,4,6)); + REQUIRE(u.x() == 1); + REQUIRE(u.y() == 2); + REQUIRE(u.z() == 3); +} + +TEST_CASE("Vector4") +{ + using namespace enzo; + bt::Vector4 u(1,2,3,4); + REQUIRE(u.x() == 1); + REQUIRE(u.y() == 2); + REQUIRE(u.z() == 3); + REQUIRE(u.w() == 4); +} +