feat: inheret from opDef
This commit is contained in:
@@ -54,6 +54,8 @@ qt_add_executable(${AppExec}
|
|||||||
src/Engine/Operator/GeometryConnection.cpp
|
src/Engine/Operator/GeometryConnection.cpp
|
||||||
src/Engine/Operator/GeometryOpDef.cpp
|
src/Engine/Operator/GeometryOpDef.cpp
|
||||||
src/Engine/Network/NetworkManager.cpp
|
src/Engine/Network/NetworkManager.cpp
|
||||||
|
|
||||||
|
src/Engine/Operator/GOP_test.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)
|
||||||
@@ -81,6 +83,7 @@ add_executable(${TestExec}
|
|||||||
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
|
||||||
)
|
)
|
||||||
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)
|
||||||
@@ -96,6 +99,7 @@ add_executable(${BenchExec}
|
|||||||
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
|
||||||
)
|
)
|
||||||
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)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#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"
|
||||||
@@ -14,7 +15,7 @@ enzo::nt::OpId enzo::nt::NetworkManager::addOperator()
|
|||||||
{
|
{
|
||||||
|
|
||||||
maxOpId_++;
|
maxOpId_++;
|
||||||
gopStore_.emplace(maxOpId_, std::make_unique<GeometryOperator>(maxOpId_));
|
gopStore_.emplace(maxOpId_, std::make_unique<GeometryOperator>(maxOpId_, std::make_unique<GOP_test>(maxOpId_)));
|
||||||
std::cout << "adding operator " << maxOpId_ << "\n";
|
std::cout << "adding operator " << maxOpId_ << "\n";
|
||||||
|
|
||||||
return maxOpId_;
|
return maxOpId_;
|
||||||
|
|||||||
81
src/Engine/Operator/GOP_test.cpp
Normal file
81
src/Engine/Operator/GOP_test.cpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
#include "Engine/Operator/GOP_test.h"
|
||||||
|
#include "Engine/Operator/AttributeHandle.h"
|
||||||
|
#include <oneapi/tbb/parallel_for.h>
|
||||||
|
|
||||||
|
GOP_test::GOP_test(enzo::nt::OpId opId)
|
||||||
|
: enzo::nt::GeometryOpDef(opId)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GOP_test::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);
|
||||||
|
int startPt = PAttrHandle.getSize();
|
||||||
|
std::vector<bt::Vector3> pts = {
|
||||||
|
{-1,-1,-1},{1,-1,-1},{1,-1,1},{-1,-1,1},
|
||||||
|
{-1,1,-1},{1,1,-1},{1,1,1},{-1,1,1},
|
||||||
|
{0,2,-1},{0,2,1}
|
||||||
|
};
|
||||||
|
for (auto& p : pts) PAttrHandle.addValue(p);
|
||||||
|
|
||||||
|
auto pointAttr = geo.getAttribByName(ga::AttrOwner::VERTEX, "point");
|
||||||
|
ga::AttributeHandleInt pointAttrHandle(pointAttr);
|
||||||
|
std::vector<std::vector<int>> faces = {
|
||||||
|
{3,2,6,9,7},{0,1,5,8,4},{0,3,7,4},{1,2,6,5},
|
||||||
|
{0,1,2,3},{4,7,9},{4,9,8},{5,6,9},{5,9,8}
|
||||||
|
};
|
||||||
|
for (auto& f : faces) for (int i : f) pointAttrHandle.addValue(startPt + i);
|
||||||
|
|
||||||
|
auto vertexCountAttr = geo.getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount");
|
||||||
|
ga::AttributeHandleInt vertexCountHandle(vertexCountAttr);
|
||||||
|
for (auto& f : faces) vertexCountHandle.addValue(f.size());
|
||||||
|
|
||||||
|
// --------
|
||||||
|
|
||||||
|
for(int i=0; i<PAttrHandle.getAllValues().size(); ++i)
|
||||||
|
{
|
||||||
|
enzo::bt::Vector3 vector = PAttrHandle.getValue(i);
|
||||||
|
vector.x()+=2.5;
|
||||||
|
PAttrHandle.setValue(i, vector);
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
|
||||||
|
constexpr int N = 10000;
|
||||||
|
std::vector<double> results(N);
|
||||||
|
|
||||||
|
oneapi::tbb::parallel_for(0, N, [&](int i) {
|
||||||
|
double val = 0;
|
||||||
|
for (int j = 0; j < 100; ++j) {
|
||||||
|
val += std::sin(i + j);
|
||||||
|
}
|
||||||
|
results[i] = val;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// set output geometry
|
||||||
|
setOutputGeometry(0, geo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if(outputRequested(1))
|
||||||
|
// {
|
||||||
|
// // create new geometry
|
||||||
|
// const geo::Geometry& geo1 = getInputGeoView(0);
|
||||||
|
// geo::Geometry geo2;
|
||||||
|
|
||||||
|
// setOutputGeometry(1, geo2);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
11
src/Engine/Operator/GOP_test.h
Normal file
11
src/Engine/Operator/GOP_test.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Engine/Operator/GeometryOpDef.h"
|
||||||
|
|
||||||
|
class GOP_test
|
||||||
|
: public enzo::nt::GeometryOpDef
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GOP_test(enzo::nt::OpId opId);
|
||||||
|
virtual void cookOp();
|
||||||
|
|
||||||
|
};
|
||||||
@@ -62,73 +62,3 @@ enzo::geo::Geometry& enzo::nt::GeometryOpDef::getOutputGeo(unsigned outputIndex)
|
|||||||
return outputGeometry_.at(outputIndex);
|
return outputGeometry_.at(outputIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void enzo::nt::GeometryOpDef::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);
|
|
||||||
int startPt = PAttrHandle.getSize();
|
|
||||||
std::vector<bt::Vector3> pts = {
|
|
||||||
{-1,-1,-1},{1,-1,-1},{1,-1,1},{-1,-1,1},
|
|
||||||
{-1,1,-1},{1,1,-1},{1,1,1},{-1,1,1},
|
|
||||||
{0,2,-1},{0,2,1}
|
|
||||||
};
|
|
||||||
for (auto& p : pts) PAttrHandle.addValue(p);
|
|
||||||
|
|
||||||
auto pointAttr = geo.getAttribByName(ga::AttrOwner::VERTEX, "point");
|
|
||||||
ga::AttributeHandleInt pointAttrHandle(pointAttr);
|
|
||||||
std::vector<std::vector<int>> faces = {
|
|
||||||
{3,2,6,9,7},{0,1,5,8,4},{0,3,7,4},{1,2,6,5},
|
|
||||||
{0,1,2,3},{4,7,9},{4,9,8},{5,6,9},{5,9,8}
|
|
||||||
};
|
|
||||||
for (auto& f : faces) for (int i : f) pointAttrHandle.addValue(startPt + i);
|
|
||||||
|
|
||||||
auto vertexCountAttr = geo.getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount");
|
|
||||||
ga::AttributeHandleInt vertexCountHandle(vertexCountAttr);
|
|
||||||
for (auto& f : faces) vertexCountHandle.addValue(f.size());
|
|
||||||
|
|
||||||
// --------
|
|
||||||
|
|
||||||
for(int i=0; i<PAttrHandle.getAllValues().size(); ++i)
|
|
||||||
{
|
|
||||||
enzo::bt::Vector3 vector = PAttrHandle.getValue(i);
|
|
||||||
vector.x()+=2.5;
|
|
||||||
PAttrHandle.setValue(i, vector);
|
|
||||||
}
|
|
||||||
// ----
|
|
||||||
|
|
||||||
constexpr int N = 10000;
|
|
||||||
std::vector<double> results(N);
|
|
||||||
|
|
||||||
oneapi::tbb::parallel_for(0, N, [&](int i) {
|
|
||||||
double val = 0;
|
|
||||||
for (int j = 0; j < 100; ++j) {
|
|
||||||
val += std::sin(i + j);
|
|
||||||
}
|
|
||||||
results[i] = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// set output geometry
|
|
||||||
setOutputGeometry(0, geo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if(outputRequested(1))
|
|
||||||
// {
|
|
||||||
// // create new geometry
|
|
||||||
// const geo::Geometry& geo1 = getInputGeoView(0);
|
|
||||||
// geo::Geometry geo2;
|
|
||||||
|
|
||||||
// setOutputGeometry(1, geo2);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class GeometryOpDef
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GeometryOpDef(enzo::nt::OpId opId);
|
GeometryOpDef(enzo::nt::OpId opId);
|
||||||
void cookOp();
|
virtual void cookOp() = 0;
|
||||||
geo::Geometry& getOutputGeo(unsigned outputIndex);
|
geo::Geometry& getOutputGeo(unsigned outputIndex);
|
||||||
private:
|
private:
|
||||||
std::vector<enzo::geo::Geometry> outputGeometry_;
|
std::vector<enzo::geo::Geometry> outputGeometry_;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include "Engine/Network/NetworkManager.h"
|
#include "Engine/Network/NetworkManager.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include "Engine/Operator/GOP_test.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace enzo;
|
using namespace enzo;
|
||||||
@@ -20,13 +21,12 @@ void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputInde
|
|||||||
outputOp.addInputConnection(newConnection);
|
outputOp.addInputConnection(newConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId)
|
nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId, std::unique_ptr<enzo::nt::GeometryOpDef> opDef)
|
||||||
: opId_{opId}
|
: opId_{opId}, opDef_(std::move(opDef))
|
||||||
{
|
{
|
||||||
// TODO: drive by geometry definition
|
// TODO: drive by geometry definition
|
||||||
maxInputs_=4;
|
maxInputs_=4;
|
||||||
maxOutputs_=4;
|
maxOutputs_=4;
|
||||||
opDef_ = new enzo::nt::GeometryOpDef(opId_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void enzo::nt::GeometryOperator::cookOp()
|
void enzo::nt::GeometryOperator::cookOp()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ void connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::n
|
|||||||
class GeometryOperator
|
class GeometryOperator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GeometryOperator(enzo::nt::OpId opId);
|
GeometryOperator(enzo::nt::OpId opId, std::unique_ptr<enzo::nt::GeometryOpDef> opDef);
|
||||||
|
|
||||||
// disable copying
|
// disable copying
|
||||||
GeometryOperator(const GeometryOperator&) = delete;
|
GeometryOperator(const GeometryOperator&) = delete;
|
||||||
@@ -37,7 +37,7 @@ private:
|
|||||||
std::vector<std::shared_ptr<nt::GeometryConnection>> outputConnections_;
|
std::vector<std::shared_ptr<nt::GeometryConnection>> outputConnections_;
|
||||||
unsigned int maxInputs_;
|
unsigned int maxInputs_;
|
||||||
unsigned int maxOutputs_;
|
unsigned int maxOutputs_;
|
||||||
enzo::nt::GeometryOpDef* opDef_;
|
std::unique_ptr<enzo::nt::GeometryOpDef> opDef_;
|
||||||
enzo::nt::OpId opId_;
|
enzo::nt::OpId opId_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user