refactor: connect context, remove network manager pass to opDef
This commit is contained in:
@@ -69,7 +69,8 @@ void enzo::nt::NetworkManager::setDisplayOp(OpId opId)
|
||||
void enzo::nt::NetworkManager::cookOp(enzo::nt::OpId opId)
|
||||
{
|
||||
enzo::nt::GeometryOperator& op = getGeoOperator(opId);
|
||||
op.cookOp();
|
||||
enzo::op::Context context(opId, enzo::nt::nm());
|
||||
op.cookOp(context);
|
||||
}
|
||||
|
||||
std::vector<enzo::nt::OpId> enzo::nt::NetworkManager::getDependencyGraph(enzo::nt::OpId opId)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "Engine/Operator/Context.h"
|
||||
#include "Engine/Network/NetworkManager.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
enzo::op::Context::Context(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager)
|
||||
@@ -6,3 +8,18 @@ enzo::op::Context::Context(enzo::nt::OpId opId, enzo::nt::NetworkManager& networ
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
enzo::geo::Geometry enzo::op::Context::cloneInputGeo(unsigned int inputIndex)
|
||||
{
|
||||
// TODO: implement
|
||||
enzo::nt::GeometryOperator& selfOp = networkManager_.getGeoOperator(opId_);
|
||||
std::vector<std::shared_ptr<const nt::GeometryConnection>> inputConnections = selfOp.getInputConnections();
|
||||
if(inputConnections.size()==0)
|
||||
{
|
||||
std::cout << "no input\n";
|
||||
return enzo::geo::Geometry();
|
||||
}
|
||||
std::shared_ptr<const nt::GeometryConnection> inputConnection = inputConnections.at(inputIndex);
|
||||
return networkManager_.getGeoOperator(inputConnection->getInputOpId()).getOutputGeo(inputConnection->getInputIndex());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Network/NetworkManager.h"
|
||||
#include "Engine/Types.h"
|
||||
#include "Engine/Operator/Geometry.h"
|
||||
|
||||
namespace enzo::nt
|
||||
{
|
||||
class NetworkManager;
|
||||
}
|
||||
|
||||
namespace enzo::op
|
||||
{
|
||||
class Context
|
||||
{
|
||||
public:
|
||||
Context(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager);
|
||||
enzo::geo::Geometry cloneInputGeo(unsigned int inputIndex);
|
||||
private:
|
||||
enzo::nt::OpId opId_;
|
||||
enzo::nt::NetworkManager& networkManager_;
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#include "Engine/Operator/AttributeHandle.h"
|
||||
#include <oneapi/tbb/parallel_for.h>
|
||||
|
||||
GOP_test::GOP_test(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager)
|
||||
: enzo::nt::GeometryOpDef(opId, networkManager)
|
||||
GOP_test::GOP_test(enzo::nt::OpId opId)
|
||||
: enzo::nt::GeometryOpDef(opId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GOP_test::cookOp()
|
||||
void GOP_test::cookOp(enzo::op::Context context)
|
||||
{
|
||||
using namespace enzo;
|
||||
// std::cout << "COOKING\n";
|
||||
@@ -16,7 +16,7 @@ void GOP_test::cookOp()
|
||||
if(outputRequested(0))
|
||||
{
|
||||
// copy input geometry
|
||||
geo::Geometry geo = cloneInputGeo(0);
|
||||
geo::Geometry geo = context.cloneInputGeo(0);
|
||||
|
||||
// ----
|
||||
// create geometry start
|
||||
|
||||
@@ -5,11 +5,11 @@ class GOP_test
|
||||
: public enzo::nt::GeometryOpDef
|
||||
{
|
||||
public:
|
||||
GOP_test(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager);
|
||||
virtual void cookOp();
|
||||
static enzo::nt::GeometryOpDef* ctor(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager)
|
||||
GOP_test(enzo::nt::OpId opId);
|
||||
virtual void cookOp(enzo::op::Context context);
|
||||
static enzo::nt::GeometryOpDef* ctor(enzo::nt::OpId opId)
|
||||
{
|
||||
return new GOP_test(opId, networkManager);
|
||||
return new GOP_test(opId);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -20,19 +20,6 @@ const enzo::geo::Geometry& enzo::nt::GeometryOpDef::getInputGeoView(unsigned int
|
||||
|
||||
}
|
||||
|
||||
enzo::geo::Geometry enzo::nt::GeometryOpDef::cloneInputGeo(unsigned int inputIndex)
|
||||
{
|
||||
// TODO: implement
|
||||
enzo::nt::GeometryOperator& selfOp = networkManager_.getGeoOperator(opId_);
|
||||
std::vector<std::shared_ptr<const nt::GeometryConnection>> inputConnections = selfOp.getInputConnections();
|
||||
if(inputConnections.size()==0)
|
||||
{
|
||||
std::cout << "no input\n";
|
||||
return enzo::geo::Geometry();
|
||||
}
|
||||
std::shared_ptr<const nt::GeometryConnection> inputConnection = inputConnections.at(inputIndex);
|
||||
return networkManager_.getGeoOperator(inputConnection->getInputOpId()).getOutputGeo(inputConnection->getInputIndex());
|
||||
}
|
||||
|
||||
void enzo::nt::GeometryOpDef::setOutputGeometry(unsigned int outputIndex, enzo::geo::Geometry geometry)
|
||||
{
|
||||
@@ -43,8 +30,8 @@ void enzo::nt::GeometryOpDef::setOutputGeometry(unsigned int outputIndex, enzo::
|
||||
outputGeometry_[outputIndex] = geometry;
|
||||
}
|
||||
|
||||
enzo::nt::GeometryOpDef::GeometryOpDef(enzo::nt::OpId opId, NetworkManager& networkManager)
|
||||
: opId_{opId}, networkManager_{networkManager}
|
||||
enzo::nt::GeometryOpDef::GeometryOpDef(enzo::nt::OpId opId)
|
||||
: opId_{opId}
|
||||
{
|
||||
minInputs_=1;
|
||||
maxInputs_=4;
|
||||
|
||||
@@ -12,24 +12,22 @@ class NetworkManager;
|
||||
class BOOST_SYMBOL_EXPORT GeometryOpDef
|
||||
{
|
||||
public:
|
||||
GeometryOpDef(enzo::nt::OpId opId, NetworkManager& networkManager);
|
||||
virtual void cookOp() = 0;
|
||||
GeometryOpDef(enzo::nt::OpId opId);
|
||||
virtual void cookOp(op::Context context) = 0;
|
||||
geo::Geometry& getOutputGeo(unsigned outputIndex);
|
||||
private:
|
||||
std::vector<enzo::geo::Geometry> outputGeometry_;
|
||||
unsigned int minInputs_;
|
||||
unsigned int maxInputs_;
|
||||
unsigned int maxOutputs_;
|
||||
NetworkManager& networkManager_;
|
||||
protected:
|
||||
enzo::nt::OpId opId_;
|
||||
const enzo::geo::Geometry& getInputGeoView(unsigned int inputIndex);
|
||||
enzo::geo::Geometry cloneInputGeo(unsigned int inputIndex);
|
||||
bool outputRequested(unsigned int outputIndex);
|
||||
|
||||
// TODO: std::move geometry instead of copying
|
||||
void setOutputGeometry(unsigned int outputIndex, enzo::geo::Geometry geometry);
|
||||
};
|
||||
|
||||
using opConstructor = GeometryOpDef* (*)(enzo::nt::OpId, enzo::nt::NetworkManager&);
|
||||
using opConstructor = GeometryOpDef* (*)(enzo::nt::OpId);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <memory>
|
||||
#include "Engine/Network/NetworkManager.h"
|
||||
#include <optional>
|
||||
#include "Engine/Operator/Context.h"
|
||||
#include "Engine/Operator/GOP_test.h"
|
||||
#include <iostream>
|
||||
|
||||
@@ -24,16 +25,16 @@ void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputInde
|
||||
}
|
||||
|
||||
nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId, nt::opConstructor ctorFunc)
|
||||
: opId_{opId}, opDef_(ctorFunc(opId, nt::nm()))
|
||||
: opId_{opId}, opDef_(ctorFunc(opId))
|
||||
{
|
||||
// TODO: drive by geometry definition
|
||||
maxInputs_=4;
|
||||
maxOutputs_=4;
|
||||
}
|
||||
|
||||
void enzo::nt::GeometryOperator::cookOp()
|
||||
void enzo::nt::GeometryOperator::cookOp(op::Context context)
|
||||
{
|
||||
opDef_->cookOp();
|
||||
opDef_->cookOp(context);
|
||||
}
|
||||
|
||||
geo::Geometry& enzo::nt::GeometryOperator::getOutputGeo(unsigned outputIndex)
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
GeometryOperator(const GeometryOperator&) = delete;
|
||||
GeometryOperator& operator=(const GeometryOperator&) = delete;
|
||||
|
||||
void cookOp();
|
||||
void cookOp(op::Context context);
|
||||
geo::Geometry& getOutputGeo(unsigned outputIndex);
|
||||
|
||||
void addInputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
||||
|
||||
@@ -5,11 +5,11 @@ class GopTransform
|
||||
: public enzo::nt::GeometryOpDef
|
||||
{
|
||||
public:
|
||||
GopTransform(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager);
|
||||
virtual void cookOp();
|
||||
static enzo::nt::GeometryOpDef* ctor(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager)
|
||||
GopTransform(enzo::nt::OpId opId);
|
||||
virtual void cookOp(enzo::op::Context context);
|
||||
static enzo::nt::GeometryOpDef* ctor(enzo::nt::OpId opId)
|
||||
{
|
||||
return new GopTransform(opId, networkManager);
|
||||
return new GopTransform(opId);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -17,20 +17,20 @@ extern "C"
|
||||
|
||||
}
|
||||
|
||||
GopTransform::GopTransform(enzo::nt::OpId opId, enzo::nt::NetworkManager& networkManager)
|
||||
: enzo::nt::GeometryOpDef(opId, networkManager)
|
||||
GopTransform::GopTransform(enzo::nt::OpId opId)
|
||||
: enzo::nt::GeometryOpDef(opId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GopTransform::cookOp()
|
||||
void GopTransform::cookOp(enzo::op::Context context)
|
||||
{
|
||||
using namespace enzo;
|
||||
|
||||
if(outputRequested(0))
|
||||
{
|
||||
// copy input geometry
|
||||
geo::Geometry geo = cloneInputGeo(0);
|
||||
geo::Geometry geo = context.cloneInputGeo(0);
|
||||
|
||||
// ----
|
||||
// create geometry start
|
||||
|
||||
Reference in New Issue
Block a user