feat: add network connections
This commit is contained in:
12
src/Engine/Operator/GeometryConnection.cpp
Normal file
12
src/Engine/Operator/GeometryConnection.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "Engine/Operator/GeometryConnection.h"
|
||||
|
||||
enzo::nt::GeometryConnection::GeometryConnection(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex)
|
||||
:inputOperatorId_{inputOpId}, inputIndex_{inputIndex}, outputOperatorId_{outputOpId}, outputIndex_{outputIndex}
|
||||
{
|
||||
}
|
||||
|
||||
enzo::nt::OpId enzo::nt::GeometryConnection::getInputOpId() const {return inputOperatorId_; }
|
||||
enzo::nt::OpId enzo::nt::GeometryConnection::getOutputOpId() const {return outputOperatorId_; }
|
||||
unsigned int enzo::nt::GeometryConnection::getInputIndex() const {return inputIndex_; }
|
||||
unsigned int enzo::nt::GeometryConnection::getOutputIndex() const {return outputIndex_; }
|
||||
|
||||
25
src/Engine/Operator/GeometryConnection.h
Normal file
25
src/Engine/Operator/GeometryConnection.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Types.h"
|
||||
namespace enzo::nt
|
||||
{
|
||||
class GeometryOperator;
|
||||
class GeometryConnection
|
||||
{
|
||||
public:
|
||||
// input and output are in relation to data flow
|
||||
// the input node is the node the data flows from
|
||||
// the output node is the node the data flows to
|
||||
GeometryConnection(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex);
|
||||
|
||||
enzo::nt::OpId getInputOpId() const;
|
||||
enzo::nt::OpId getOutputOpId() const;
|
||||
unsigned int getInputIndex() const;
|
||||
unsigned int getOutputIndex() const;
|
||||
private:
|
||||
enzo::nt::OpId inputOperatorId_;
|
||||
enzo::nt::OpId outputOperatorId_;
|
||||
unsigned int inputIndex_;
|
||||
unsigned int outputIndex_;
|
||||
};
|
||||
}
|
||||
@@ -1,55 +1,93 @@
|
||||
#include "Engine/Operator/GeometryOperator.h"
|
||||
#include <memory>
|
||||
#include "Engine/Network/NetworkManager.h"
|
||||
#include <optional>
|
||||
#include <iostream>
|
||||
|
||||
using namespace enzo;
|
||||
|
||||
void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex)
|
||||
{
|
||||
// get network manager
|
||||
auto nm = enzo::nt::NetworkManager::getInstance();
|
||||
|
||||
auto inputOp = nm->getGeoOperator(inputOpId);
|
||||
auto outputOp = nm->getGeoOperator(outputOpId);
|
||||
|
||||
auto newConnection = std::make_shared<nt::GeometryConnection>(inputOpId, inputIndex, outputOpId, outputIndex);
|
||||
|
||||
// set output on the upper operator
|
||||
outputOp.addOutputConnection(newConnection);
|
||||
|
||||
// set input on the lower operator
|
||||
inputOp.addInputConnection(newConnection);
|
||||
}
|
||||
|
||||
nt::GeometryOperator::GeometryOperator()
|
||||
{
|
||||
// TODO: drive by geometry definition
|
||||
maxInputs_=4;
|
||||
maxOutputs_=4;
|
||||
|
||||
inputIds_ = std::vector<std::optional<nt::OpId>>(maxInputs_, std::nullopt);
|
||||
outputIds_ = std::vector<std::optional<nt::OpId>>(maxOutputs_, std::nullopt);
|
||||
}
|
||||
|
||||
bool nt::GeometryOperator::setInput(unsigned int inputNumber, nt::OpId opId)
|
||||
// bool nt::GeometryOperator::setInput(unsigned int inputNumber, nt::OpId opId)
|
||||
// {
|
||||
// if(inputNumber>=maxInputs_)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// inputIds_[inputNumber] = opId;
|
||||
|
||||
// return true;
|
||||
// }
|
||||
// bool nt::GeometryOperator::setOutput(unsigned int outputNumber, nt::OpId opId)
|
||||
// {
|
||||
|
||||
// if(outputNumber>=maxOutputs_)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// inputIds_[outputNumber] = opId;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
void nt::GeometryOperator::addInputConnection(std::shared_ptr<nt::GeometryConnection> connection)
|
||||
{
|
||||
if(inputNumber>=maxInputs_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
inputIds_[inputNumber] = opId;
|
||||
|
||||
return true;
|
||||
inputConnections_.push_back(connection);
|
||||
}
|
||||
bool nt::GeometryOperator::setOutput(unsigned int outputNumber, nt::OpId opId)
|
||||
|
||||
void nt::GeometryOperator::addOutputConnection(std::shared_ptr<nt::GeometryConnection> connection)
|
||||
{
|
||||
|
||||
if(outputNumber>=maxOutputs_)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
inputIds_[outputNumber] = opId;
|
||||
return true;
|
||||
std::cout << "Output connection added\nConnecting ops " << connection->getInputOpId() << " -> " << connection->getOutputOpId() << "\n";
|
||||
std::cout << "Connecting index " << connection->getInputIndex() << " -> " << connection->getOutputIndex() << "\n";
|
||||
outputConnections_.push_back(connection);
|
||||
}
|
||||
|
||||
std::optional<nt::OpId> nt::GeometryOperator::getInput(unsigned int inputNumber) const
|
||||
|
||||
// std::optional<nt::OpId> nt::GeometryOperator::getInput(unsigned int inputNumber) const
|
||||
// {
|
||||
// if(inputNumber>=maxInputs_)
|
||||
// {
|
||||
// return std::nullopt;
|
||||
// }
|
||||
// return inputIds_.at(inputNumber);
|
||||
// }
|
||||
|
||||
// std::optional<nt::OpId> nt::GeometryOperator::getOutput(unsigned int outputNumber) const
|
||||
// {
|
||||
// if(outputNumber>=maxOutputs_)
|
||||
// {
|
||||
// return std::nullopt;
|
||||
// }
|
||||
// return outputIds_.at(outputNumber);
|
||||
// }
|
||||
|
||||
|
||||
unsigned int nt::GeometryOperator::getMaxInputs() const
|
||||
{
|
||||
if(inputNumber>=maxInputs_)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
return inputIds_.at(inputNumber);
|
||||
return maxInputs_;
|
||||
}
|
||||
|
||||
std::optional<nt::OpId> nt::GeometryOperator::getOutput(unsigned int outputNumber) const
|
||||
unsigned int nt::GeometryOperator::getMaxOutputs() const
|
||||
{
|
||||
if(outputNumber>=maxOutputs_)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
return outputIds_.at(outputNumber);
|
||||
return maxOutputs_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,34 @@
|
||||
#pragma once
|
||||
#include "Engine/Operator/GeometryConnection.h"
|
||||
#include "Engine/Types.h"
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
|
||||
namespace enzo::nt {
|
||||
void connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::nt::OpId outputOpId, unsigned int outputIndex);
|
||||
|
||||
class GeometryOperator
|
||||
{
|
||||
public:
|
||||
GeometryOperator();
|
||||
bool setInput(unsigned int inputNumber, nt::OpId opId);
|
||||
bool setOutput(unsigned int outputNumber, nt::OpId opId);
|
||||
std::optional<nt::OpId> getInput(unsigned int inputNumber) const;
|
||||
std::optional<nt::OpId> getOutput(unsigned int outputNumber) const;
|
||||
// bool setInput(unsigned int inputNumber, nt::OpId opId);
|
||||
// bool setOutput(unsigned int outputNumber, nt::OpId opId);
|
||||
// std::optional<nt::OpId> getInput(unsigned int inputNumber) const;
|
||||
// std::optional<nt::OpId> getOutput(unsigned int outputNumber) const;
|
||||
|
||||
void addInputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
||||
void addOutputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
||||
|
||||
|
||||
|
||||
unsigned int getMaxInputs() const;
|
||||
unsigned int getMaxOutputs() const;
|
||||
|
||||
|
||||
private:
|
||||
std::vector<std::optional<nt::OpId>> inputIds_;
|
||||
std::vector<std::optional<nt::OpId>> outputIds_;
|
||||
// TODO: avoid duplicate connections
|
||||
std::vector<std::shared_ptr<nt::GeometryConnection>> inputConnections_;
|
||||
std::vector<std::shared_ptr<nt::GeometryConnection>> outputConnections_;
|
||||
unsigned int maxInputs_;
|
||||
unsigned int maxOutputs_;
|
||||
|
||||
|
||||
@@ -32,5 +32,10 @@ namespace enzo
|
||||
namespace nt
|
||||
{
|
||||
using OpId = uint64_t;
|
||||
|
||||
enum class SocketIOType {
|
||||
Input,
|
||||
Output
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user