feat: add eigen vector type

This commit is contained in:
parker
2025-07-02 12:43:20 +01:00
parent 6463fe2a7f
commit f1d825d513
8 changed files with 66 additions and 3 deletions

View File

@@ -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)

View File

@@ -19,6 +19,9 @@ ga::Attribute::Attribute(std::string name, ga::AttributeType type)
case(AttrType::floatT):
floatStore_=std::make_shared<std::vector<float>>();
break;
case(AttrType::vectorT):
vector3Store_=std::make_shared<std::vector<enzo::bt::Vector3>>();
break;
default:
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for");

View File

@@ -45,6 +45,7 @@ namespace enzo{
// data stores
std::shared_ptr<std::vector<int>> intStore_;
std::shared_ptr<std::vector<float>> floatStore_;
std::shared_ptr<std::vector<enzo::bt::Vector3>> vector3Store_;
};

View File

@@ -5,6 +5,7 @@
#include <optional>
#include <vector>
#include "Engine/Operator/Attribute.h"
#include "Engine/Types.h"
#include <iostream>
@@ -23,14 +24,24 @@ public:
// get attribute data pointer
// TODO: check types match
// TODO: add the other types
// int
if constexpr (std::is_same<int, T>::value)
{
data_=attribute->intStore_;
}
// float
else if constexpr (std::is_same<float, T>::value)
{
data_=attribute->floatStore_;
}
// vector 3
else if constexpr (std::is_same<enzo::bt::Vector3, T>::value)
{
data_=attribute->vector3Store_;
}
else
{
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for");
@@ -75,5 +86,6 @@ private:
using AttributeHandleInt = AttributeHandle<int>;
using AttributeHandleFloat = AttributeHandle<float>;
using AttributeHandleVector3 = AttributeHandle<enzo::bt::Vector3>;
}

View File

@@ -1,4 +1,5 @@
#pragma once
#include <Eigen/Dense>
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;
}
}

View File

View File

@@ -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 <glm/mat4x4.hpp>
#include <glm/ext/matrix_clip_space.hpp>
#include <glm/gtc/matrix_transform.hpp>

View File

@@ -54,6 +54,18 @@ TEST_CASE("attrHandleFloat")
REQUIRE(myHandle.getValue(1)==6.9f);
}
TEST_CASE("attrHandleVector3")
{
using namespace enzo;
std::shared_ptr<ga::Attribute> myAttrib = std::make_shared<ga::Attribute>("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);
}