feat: add graph traversal function
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
#include "Engine/Types.h"
|
#include "Engine/Types.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <stack>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
enzo::nt::OpId enzo::nt::NetworkManager::addOperator()
|
enzo::nt::OpId enzo::nt::NetworkManager::addOperator()
|
||||||
{
|
{
|
||||||
@@ -41,8 +43,38 @@ bool enzo::nt::NetworkManager::isValidOp(nt::OpId opId)
|
|||||||
void enzo::nt::NetworkManager::setDisplayOp(OpId opId)
|
void enzo::nt::NetworkManager::setDisplayOp(OpId opId)
|
||||||
{
|
{
|
||||||
displayOp_=opId;
|
displayOp_=opId;
|
||||||
|
getTraversalGraph(opId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enzo::nt::NetworkManager::cookOp(enzo::nt::OpId opId)
|
||||||
|
{
|
||||||
|
std::cout << "COOKING: " << opId << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<enzo::nt::OpId> enzo::nt::NetworkManager::getTraversalGraph(enzo::nt::OpId opId)
|
||||||
|
{
|
||||||
|
std::stack<enzo::nt::OpId> traversalBuffer;
|
||||||
|
std::vector<enzo::nt::OpId> traversalGraph;
|
||||||
|
traversalBuffer.push(opId);
|
||||||
|
|
||||||
|
while(traversalBuffer.size()!=0)
|
||||||
|
{
|
||||||
|
enzo::nt::OpId currentOp = traversalBuffer.top();
|
||||||
|
std::cout << "cooking node: " << currentOp << "\n";
|
||||||
|
traversalBuffer.pop();
|
||||||
|
auto inputConnections = getGeoOperator(currentOp).getInputConnections();
|
||||||
|
for(auto connection : inputConnections)
|
||||||
|
{
|
||||||
|
traversalBuffer.push(connection->getInputOpId());
|
||||||
|
traversalGraph.push_back(connection->getInputOpId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::reverse(traversalGraph.begin(), traversalGraph.end());
|
||||||
|
return traversalGraph;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::optional<enzo::nt::OpId> enzo::nt::NetworkManager::getDisplayOp()
|
std::optional<enzo::nt::OpId> enzo::nt::NetworkManager::getDisplayOp()
|
||||||
{
|
{
|
||||||
return displayOp_;
|
return displayOp_;
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ private:
|
|||||||
|
|
||||||
std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> gopStore_;
|
std::unordered_map<enzo::nt::OpId, std::unique_ptr<enzo::nt::GeometryOperator>> gopStore_;
|
||||||
|
|
||||||
|
void cookOp(enzo::nt::OpId opId);
|
||||||
|
std::vector<enzo::nt::OpId> getTraversalGraph(enzo::nt::OpId opId);
|
||||||
|
|
||||||
// the highest operator id currently stored
|
// the highest operator id currently stored
|
||||||
enzo::nt::OpId maxOpId_=0;
|
enzo::nt::OpId maxOpId_=0;
|
||||||
|
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputInde
|
|||||||
// get network manager
|
// get network manager
|
||||||
auto nm = enzo::nt::NetworkManager::getInstance();
|
auto nm = enzo::nt::NetworkManager::getInstance();
|
||||||
|
|
||||||
auto inputOp = nm->getGeoOperator(inputOpId);
|
auto& inputOp = nm->getGeoOperator(inputOpId);
|
||||||
auto outputOp = nm->getGeoOperator(outputOpId);
|
auto& outputOp = nm->getGeoOperator(outputOpId);
|
||||||
|
|
||||||
auto newConnection = std::make_shared<nt::GeometryConnection>(inputOpId, inputIndex, outputOpId, outputIndex);
|
auto newConnection = std::make_shared<nt::GeometryConnection>(inputOpId, inputIndex, outputOpId, outputIndex);
|
||||||
|
|
||||||
// set output on the upper operator
|
// set output on the upper operator
|
||||||
outputOp.addOutputConnection(newConnection);
|
inputOp.addOutputConnection(newConnection);
|
||||||
|
|
||||||
// set input on the lower operator
|
// set input on the lower operator
|
||||||
inputOp.addInputConnection(newConnection);
|
outputOp.addInputConnection(newConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
nt::GeometryOperator::GeometryOperator()
|
nt::GeometryOperator::GeometryOperator()
|
||||||
@@ -30,30 +30,13 @@ nt::GeometryOperator::GeometryOperator()
|
|||||||
maxOutputs_=4;
|
maxOutputs_=4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
void nt::GeometryOperator::addInputConnection(std::shared_ptr<nt::GeometryConnection> connection)
|
||||||
{
|
{
|
||||||
|
std::cout << "Input connection added\nConnecting ops " << connection->getInputOpId() << " -> " << connection->getOutputOpId() << "\n";
|
||||||
|
std::cout << "Connecting index " << connection->getInputIndex() << " -> " << connection->getOutputIndex() << "\n";
|
||||||
inputConnections_.push_back(connection);
|
inputConnections_.push_back(connection);
|
||||||
|
std::cout << "size: " << inputConnections_.size() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void nt::GeometryOperator::addOutputConnection(std::shared_ptr<nt::GeometryConnection> connection)
|
void nt::GeometryOperator::addOutputConnection(std::shared_ptr<nt::GeometryConnection> connection)
|
||||||
@@ -61,8 +44,31 @@ void nt::GeometryOperator::addOutputConnection(std::shared_ptr<nt::GeometryConne
|
|||||||
std::cout << "Output connection added\nConnecting ops " << connection->getInputOpId() << " -> " << connection->getOutputOpId() << "\n";
|
std::cout << "Output connection added\nConnecting ops " << connection->getInputOpId() << " -> " << connection->getOutputOpId() << "\n";
|
||||||
std::cout << "Connecting index " << connection->getInputIndex() << " -> " << connection->getOutputIndex() << "\n";
|
std::cout << "Connecting index " << connection->getInputIndex() << " -> " << connection->getOutputIndex() << "\n";
|
||||||
outputConnections_.push_back(connection);
|
outputConnections_.push_back(connection);
|
||||||
|
std::cout << "size: " << outputConnections_.size() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<const nt::GeometryConnection>> nt::GeometryOperator::getInputConnections() const
|
||||||
|
{
|
||||||
|
std::vector<std::shared_ptr<const nt::GeometryConnection>> inputConnections;
|
||||||
|
std::cout << "input connections size: " << inputConnections_.size() <<"\n";
|
||||||
|
for(std::shared_ptr<nt::GeometryConnection> connection : inputConnections_)
|
||||||
|
{
|
||||||
|
inputConnections.push_back(connection);
|
||||||
|
}
|
||||||
|
return inputConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<const nt::GeometryConnection>> nt::GeometryOperator::getOutputConnections() const
|
||||||
|
{
|
||||||
|
std::vector<std::shared_ptr<const nt::GeometryConnection>> outputConnections;
|
||||||
|
for(std::shared_ptr<nt::GeometryConnection> connection : outputConnections_)
|
||||||
|
{
|
||||||
|
outputConnections.push_back(connection);
|
||||||
|
}
|
||||||
|
return outputConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// std::optional<nt::OpId> nt::GeometryOperator::getInput(unsigned int inputNumber) const
|
// std::optional<nt::OpId> nt::GeometryOperator::getInput(unsigned int inputNumber) const
|
||||||
// {
|
// {
|
||||||
|
|||||||
@@ -11,13 +11,15 @@ class GeometryOperator
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GeometryOperator();
|
GeometryOperator();
|
||||||
// bool setInput(unsigned int inputNumber, nt::OpId opId);
|
|
||||||
// bool setOutput(unsigned int outputNumber, nt::OpId opId);
|
// disable copying
|
||||||
// std::optional<nt::OpId> getInput(unsigned int inputNumber) const;
|
GeometryOperator(const GeometryOperator&) = delete;
|
||||||
// std::optional<nt::OpId> getOutput(unsigned int outputNumber) const;
|
GeometryOperator& operator=(const GeometryOperator&) = delete;
|
||||||
|
|
||||||
void addInputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
void addInputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
||||||
void addOutputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
void addOutputConnection(std::shared_ptr<nt::GeometryConnection> connection);
|
||||||
|
std::vector<std::shared_ptr<const GeometryConnection>> getInputConnections() const;
|
||||||
|
std::vector<std::shared_ptr<const GeometryConnection>> getOutputConnections() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,10 +72,8 @@ private:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
QGraphicsItem* itemOfType(QList<QGraphicsItem*> items)
|
QGraphicsItem* itemOfType(QList<QGraphicsItem*> items)
|
||||||
{
|
{
|
||||||
// std::cout << "count: " << items.size() << "\n";
|
|
||||||
for(QGraphicsItem* item : items)
|
for(QGraphicsItem* item : items)
|
||||||
{
|
{
|
||||||
std::cout << "item: " << typeid(*item).name() << "\n";
|
|
||||||
if(item && typeid(*item)==typeid(T))
|
if(item && typeid(*item)==typeid(T))
|
||||||
{
|
{
|
||||||
return item;
|
return item;
|
||||||
|
|||||||
@@ -101,9 +101,6 @@ QRectF NodeEdgeGraphic::boundingRect() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QPainterPath NodeEdgeGraphic::shape() const{
|
QPainterPath NodeEdgeGraphic::shape() const{
|
||||||
// FIX: shape not changing with node position
|
|
||||||
std::cout << "setting shape to: " << socket1_->scenePos().x() << " " << socket2_->scenePos().x() <<"\n";
|
|
||||||
|
|
||||||
QPainterPathStroker stroker;
|
QPainterPathStroker stroker;
|
||||||
stroker.setWidth(padding_);
|
stroker.setWidth(padding_);
|
||||||
return stroker.createStroke(path_);
|
return stroker.createStroke(path_);
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ TEST_CASE("network")
|
|||||||
{
|
{
|
||||||
auto newConnection = std::make_shared<nt::GeometryConnection>(newOpId, 1, newOpId2, 3);
|
auto newConnection = std::make_shared<nt::GeometryConnection>(newOpId, 1, newOpId2, 3);
|
||||||
|
|
||||||
auto inputOp = nm->getGeoOperator(newOpId);
|
auto& inputOp = nm->getGeoOperator(newOpId);
|
||||||
auto outputOp = nm->getGeoOperator(newOpId2);
|
auto& outputOp = nm->getGeoOperator(newOpId2);
|
||||||
|
|
||||||
// set output on the upper operator
|
// set output on the upper operator
|
||||||
outputOp.addOutputConnection(newConnection);
|
outputOp.addOutputConnection(newConnection);
|
||||||
|
|||||||
Reference in New Issue
Block a user