feat: support for multiple node types
This commit is contained in:
@@ -56,52 +56,53 @@ qt_add_executable(${AppExec}
|
|||||||
src/Engine/Network/NetworkManager.cpp
|
src/Engine/Network/NetworkManager.cpp
|
||||||
|
|
||||||
src/Engine/Operator/GOP_test.cpp
|
src/Engine/Operator/GOP_test.cpp
|
||||||
|
src/Engine/Operator/GOP_transform.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm Eigen3::Eigen TBB::tbb)
|
target_link_libraries(${AppExec} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm Eigen3::Eigen TBB::tbb)
|
||||||
target_include_directories(${AppExec} PUBLIC src)
|
target_include_directories(${AppExec} PUBLIC src)
|
||||||
|
|
||||||
# tests
|
# tests
|
||||||
Include(FetchContent)
|
# Include(FetchContent)
|
||||||
|
|
||||||
FetchContent_Declare(
|
# FetchContent_Declare(
|
||||||
Catch2
|
# Catch2
|
||||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
# GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||||
GIT_TAG v3.8.1 # or a later release
|
# GIT_TAG v3.8.1 # or a later release
|
||||||
)
|
# )
|
||||||
|
|
||||||
FetchContent_MakeAvailable(Catch2)
|
# FetchContent_MakeAvailable(Catch2)
|
||||||
|
|
||||||
add_executable(${TestExec}
|
# add_executable(${TestExec}
|
||||||
tests/main-tests.cpp
|
# tests/main-tests.cpp
|
||||||
tests/OperatorTests.cpp
|
# tests/OperatorTests.cpp
|
||||||
tests/NetworkTests.cpp
|
# tests/NetworkTests.cpp
|
||||||
|
|
||||||
src/Engine/Operator/Attribute.cpp
|
# src/Engine/Operator/Attribute.cpp
|
||||||
src/Engine/Operator/Geometry.cpp
|
# src/Engine/Operator/Geometry.cpp
|
||||||
src/Engine/Operator/GeometryOperator.cpp
|
# src/Engine/Operator/GeometryOperator.cpp
|
||||||
src/Engine/Network/NetworkManager.cpp
|
# src/Engine/Network/NetworkManager.cpp
|
||||||
src/Engine/Operator/GeometryConnection.cpp
|
# src/Engine/Operator/GeometryConnection.cpp
|
||||||
src/Engine/Operator/GeometryOpDef.cpp
|
# src/Engine/Operator/GeometryOpDef.cpp
|
||||||
src/Engine/Operator/GOP_test.cpp
|
# src/Engine/Operator/GOP_test.cpp
|
||||||
)
|
# )
|
||||||
target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb)
|
# target_link_libraries(${TestExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb)
|
||||||
target_compile_definitions(${TestExec} PRIVATE UNIT_TEST)
|
# target_compile_definitions(${TestExec} PRIVATE UNIT_TEST)
|
||||||
target_include_directories(${TestExec} PUBLIC src)
|
# target_include_directories(${TestExec} PUBLIC src)
|
||||||
|
|
||||||
# benchmarks
|
# # benchmarks
|
||||||
add_executable(${BenchExec}
|
# add_executable(${BenchExec}
|
||||||
tests/Benchmarks.cpp
|
# tests/Benchmarks.cpp
|
||||||
|
|
||||||
src/Engine/Operator/Attribute.cpp
|
# src/Engine/Operator/Attribute.cpp
|
||||||
src/Engine/Operator/Geometry.cpp
|
# src/Engine/Operator/Geometry.cpp
|
||||||
src/Engine/Operator/GeometryOperator.cpp
|
# src/Engine/Operator/GeometryOperator.cpp
|
||||||
src/Engine/Network/NetworkManager.cpp
|
# src/Engine/Network/NetworkManager.cpp
|
||||||
src/Engine/Operator/GeometryConnection.cpp
|
# src/Engine/Operator/GeometryConnection.cpp
|
||||||
src/Engine/Operator/GeometryOpDef.cpp
|
# src/Engine/Operator/GeometryOpDef.cpp
|
||||||
src/Engine/Operator/GOP_test.cpp
|
# src/Engine/Operator/GOP_test.cpp
|
||||||
)
|
# )
|
||||||
target_link_libraries(${BenchExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb)
|
# target_link_libraries(${BenchExec} PRIVATE Catch2::Catch2WithMain Eigen3::Eigen Qt6::Core TBB::tbb)
|
||||||
target_compile_definitions(${BenchExec} PRIVATE UNIT_TEST)
|
# target_compile_definitions(${BenchExec} PRIVATE UNIT_TEST)
|
||||||
target_include_directories(${BenchExec} PUBLIC src)
|
# target_include_directories(${BenchExec} PUBLIC src)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "Engine/Network/NetworkManager.h"
|
#include "Engine/Network/NetworkManager.h"
|
||||||
#include "Engine/Operator/GOP_test.h"
|
|
||||||
#include "Engine/Operator/Geometry.h"
|
#include "Engine/Operator/Geometry.h"
|
||||||
#include "Engine/Operator/GeometryOperator.h"
|
#include "Engine/Operator/GeometryOperator.h"
|
||||||
#include "Engine/Operator/Attribute.h"
|
#include "Engine/Operator/Attribute.h"
|
||||||
@@ -11,11 +10,11 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enzo::nt::OpId enzo::nt::NetworkManager::addOperator()
|
enzo::nt::OpId enzo::nt::NetworkManager::addOperator(nt::opConstructor ctorFunc)
|
||||||
{
|
{
|
||||||
|
|
||||||
maxOpId_++;
|
maxOpId_++;
|
||||||
gopStore_.emplace(maxOpId_, std::make_unique<GeometryOperator>(maxOpId_, &GOP_test::ctor));
|
gopStore_.emplace(maxOpId_, std::make_unique<GeometryOperator>(maxOpId_, ctorFunc));
|
||||||
std::cout << "adding operator " << maxOpId_ << "\n";
|
std::cout << "adding operator " << maxOpId_ << "\n";
|
||||||
|
|
||||||
return maxOpId_;
|
return maxOpId_;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public:
|
|||||||
static NetworkManager* getInstance();
|
static NetworkManager* getInstance();
|
||||||
|
|
||||||
// functions
|
// functions
|
||||||
static OpId addOperator();
|
static OpId addOperator(nt::opConstructor ctorFunc);
|
||||||
static std::optional<OpId> getDisplayOp();
|
static std::optional<OpId> getDisplayOp();
|
||||||
static bool isValidOp(nt::OpId opId);
|
static bool isValidOp(nt::OpId opId);
|
||||||
static GeometryOperator& getGeoOperator(nt::OpId opId);
|
static GeometryOperator& getGeoOperator(nt::OpId opId);
|
||||||
|
|||||||
42
src/Engine/Operator/GOP_transform.cpp
Normal file
42
src/Engine/Operator/GOP_transform.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#include "Engine/Operator/GOP_transform.h"
|
||||||
|
#include "Engine/Operator/AttributeHandle.h"
|
||||||
|
#include <oneapi/tbb/parallel_for.h>
|
||||||
|
|
||||||
|
GOP_transform::GOP_transform(enzo::nt::OpId opId)
|
||||||
|
: enzo::nt::GeometryOpDef(opId)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GOP_transform::cookOp()
|
||||||
|
{
|
||||||
|
using namespace enzo;
|
||||||
|
// std::cout << "COOKING\n";
|
||||||
|
|
||||||
|
if(outputRequested(0))
|
||||||
|
{
|
||||||
|
// copy input geometry
|
||||||
|
geo::Geometry geo = cloneInputGeo(0);
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// create geometry start
|
||||||
|
// ----
|
||||||
|
auto PAttr = geo.getAttribByName(ga::AttrOwner::POINT, "P");
|
||||||
|
ga::AttributeHandleVector3 PAttrHandle(PAttr);
|
||||||
|
|
||||||
|
for(int i=0; i<PAttrHandle.getAllValues().size(); ++i)
|
||||||
|
{
|
||||||
|
enzo::bt::Vector3 vector = PAttrHandle.getValue(i);
|
||||||
|
vector.y()+=2.5;
|
||||||
|
PAttrHandle.setValue(i, vector);
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// set output geometry
|
||||||
|
setOutputGeometry(0, geo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
15
src/Engine/Operator/GOP_transform.h
Normal file
15
src/Engine/Operator/GOP_transform.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Engine/Operator/GeometryOpDef.h"
|
||||||
|
|
||||||
|
class GOP_transform
|
||||||
|
: public enzo::nt::GeometryOpDef
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GOP_transform(enzo::nt::OpId opId);
|
||||||
|
virtual void cookOp();
|
||||||
|
static enzo::nt::GeometryOpDef* ctor(enzo::nt::OpId opId)
|
||||||
|
{
|
||||||
|
return new GOP_transform(opId);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
namespace enzo::nt
|
namespace enzo::nt
|
||||||
{
|
{
|
||||||
|
|
||||||
class GeometryOpDef
|
class GeometryOpDef
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -24,4 +25,6 @@ protected:
|
|||||||
// TODO: std::move geometry instead of copying
|
// TODO: std::move geometry instead of copying
|
||||||
void setOutputGeometry(unsigned int outputIndex, enzo::geo::Geometry geometry);
|
void setOutputGeometry(unsigned int outputIndex, enzo::geo::Geometry geometry);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using opConstructor = GeometryOpDef* (*)(enzo::nt::OpId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputInde
|
|||||||
outputOp.addInputConnection(newConnection);
|
outputOp.addInputConnection(newConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId, enzo::nt::GeometryOpDef* (*ctorFunc)(enzo::nt::OpId))
|
nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId, nt::opConstructor ctorFunc)
|
||||||
: opId_{opId}, opDef_(ctorFunc(opId))
|
: opId_{opId}, opDef_(ctorFunc(opId))
|
||||||
{
|
{
|
||||||
// TODO: drive by geometry definition
|
// TODO: drive by geometry definition
|
||||||
|
|||||||
@@ -37,5 +37,6 @@ namespace enzo
|
|||||||
Input,
|
Input,
|
||||||
Output
|
Output
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
#include <qgraphicsitem.h>
|
#include <qgraphicsitem.h>
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
#include <QLine>
|
#include <QLine>
|
||||||
|
#include "Engine/Operator/GOP_test.h"
|
||||||
|
#include "Engine/Operator/GOP_transform.h"
|
||||||
|
|
||||||
using namespace enzo;
|
using namespace enzo;
|
||||||
|
|
||||||
@@ -286,7 +288,16 @@ void Network::keyPressEvent(QKeyEvent *event)
|
|||||||
}
|
}
|
||||||
case(Qt::Key_Tab):
|
case(Qt::Key_Tab):
|
||||||
{
|
{
|
||||||
if(auto newNode = createNode())
|
if(auto newNode = createNode(&GOP_test::ctor))
|
||||||
|
{
|
||||||
|
newNode->setPos(viewPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case(Qt::Key_F):
|
||||||
|
{
|
||||||
|
if(auto newNode = createNode(&GOP_transform::ctor))
|
||||||
{
|
{
|
||||||
newNode->setPos(viewPos);
|
newNode->setPos(viewPos);
|
||||||
}
|
}
|
||||||
@@ -296,9 +307,9 @@ void Network::keyPressEvent(QKeyEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeGraphic* Network::createNode()
|
NodeGraphic* Network::createNode(nt::opConstructor ctorFunc)
|
||||||
{
|
{
|
||||||
if(nt::OpId id = nt::NetworkManager::addOperator())
|
if(nt::OpId id = nt::NetworkManager::addOperator(ctorFunc))
|
||||||
{
|
{
|
||||||
NodeGraphic* newNode = new NodeGraphic(id);
|
NodeGraphic* newNode = new NodeGraphic(id);
|
||||||
scene_->addItem(newNode);
|
scene_->addItem(newNode);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ private:
|
|||||||
void destroyFloatingEdge();
|
void destroyFloatingEdge();
|
||||||
void deleteEdge(QGraphicsItem* edge);
|
void deleteEdge(QGraphicsItem* edge);
|
||||||
|
|
||||||
NodeGraphic* createNode();
|
NodeGraphic* createNode(enzo::nt::opConstructor ctorFunc);
|
||||||
|
|
||||||
void highlightEdge(QGraphicsItem* edge, bool state);
|
void highlightEdge(QGraphicsItem* edge, bool state);
|
||||||
void leftMousePressed(QMouseEvent* event);
|
void leftMousePressed(QMouseEvent* event);
|
||||||
|
|||||||
Reference in New Issue
Block a user