refactor: move GOP_test to plugin system

This commit is contained in:
parker
2025-07-16 16:37:14 +01:00
parent 1ac5af190b
commit d2dda549eb
8 changed files with 60 additions and 56 deletions

View File

@@ -8,7 +8,7 @@ find_package (Eigen3 3.3 REQUIRED NO_MODULE)
set(libName enzoOps1)
add_library(${libName} SHARED
main.cpp
RegisterPlugin.cpp
../Engine/Operator/OperatorTable.cpp
../Engine/Operator/GeometryOpDef.cpp
../Engine/Operator/GeometryOperator.cpp
@@ -17,6 +17,8 @@ add_library(${libName} SHARED
../Engine/Operator/Geometry.cpp
../Engine/Operator/Attribute.cpp
../Engine/Network/NetworkManager.cpp
GopTransform.cpp
GopHouse.cpp
)
target_link_libraries(${libName} PRIVATE Qt6::Core Qt6::Widgets Qt6::SvgWidgets Qt6::OpenGLWidgets glm::glm Eigen3::Eigen TBB::tbb)

81
src/OpDefs/GopHouse.cpp Normal file
View File

@@ -0,0 +1,81 @@
#include "OpDefs/GopHouse.h"
#include "Engine/Operator/AttributeHandle.h"
#include <oneapi/tbb/parallel_for.h>
GOP_house::GOP_house(enzo::nt::OpId opId)
: enzo::nt::GeometryOpDef(opId)
{
}
void GOP_house::cookOp(enzo::op::Context context)
{
using namespace enzo;
// std::cout << "COOKING\n";
if(outputRequested(0))
{
// copy input geometry
geo::Geometry geo = context.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);
// }
}

15
src/OpDefs/GopHouse.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include "Engine/Operator/GeometryOpDef.h"
class GOP_house
: public enzo::nt::GeometryOpDef
{
public:
GOP_house(enzo::nt::OpId opId);
virtual void cookOp(enzo::op::Context context);
static enzo::nt::GeometryOpDef* ctor(enzo::nt::OpId opId)
{
return new GOP_house(opId);
}
};

View File

@@ -1,23 +1,5 @@
#include "Engine/Operator/OperatorTable.h"
#include "OpDefs/GopTransform.hpp"
#include <boost/config.hpp>
#include <boost/dll.hpp>
#include <string>
#include "Engine/Operator/AttributeHandle.h"
#include <iostream>
extern "C"
{
BOOST_SYMBOL_EXPORT void newSopOperator(enzo::op::addOperatorPtr addOperator)
{
addOperator(
"transform",
"Transform",
&GopTransform::ctor
);
}
}
GopTransform::GopTransform(enzo::nt::OpId opId)
: enzo::nt::GeometryOpDef(opId)

View File

@@ -0,0 +1,23 @@
#include "Engine/Operator/OperatorTable.h"
#include "GopHouse.h"
#include "OpDefs/GopTransform.hpp"
#include <boost/config.hpp>
#include <boost/dll.hpp>
extern "C"
{
BOOST_SYMBOL_EXPORT void newSopOperator(enzo::op::addOperatorPtr addOperator)
{
addOperator(
"transform",
"Transform",
&GopTransform::ctor
);
addOperator(
"house",
"House",
&GOP_house::ctor
);
}
}