Skip to content

Commit

Permalink
yassss
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenyhraz committed May 31, 2024
1 parent 02991d2 commit f51b4ef
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 71 deletions.
34 changes: 20 additions & 14 deletions src/Gui/Windows/NodeEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ struct NodeEditor
ed::EditorContext* m_Context = nullptr; // Editor context, required to trace a editor state.
bool m_FirstFrame = true; // Flag set for first frame only, some action need to be executed once.
int m_NextLinkId = 100; // Counter to help generate link ids. In real application this will probably based on pointer to user data structure.
Workflow m_Workflow;
Workflow workflow;

void OnStart()
{
ed::Config config;
config.SettingsFile = "BasicInteraction.json";
m_Context = ed::CreateEditor(&config);
m_Workflow.TestInitialize();
workflow.TestInitialize();
}

void OnStop() { ed::DestroyEditor(m_Context); }
Expand All @@ -31,15 +31,18 @@ struct NodeEditor

void ImGuiEx_EndColumn() { ImGui::EndGroup(); }

void DrawNode(Microservice& microservice)
void DrawNode(Microservice& microservice, WorkflowType workflowType)
{
ed::BeginNode(microservice.GetId());
ImGui::Text(microservice.GetName().c_str());

ImGuiEx_BeginColumn();
ed::BeginPin(microservice.GetStartId(), ed::PinKind::Input);
ImGui::Text("> ");
ed::EndPin();
if (workflowType != WorkflowType::Simple)
{
ed::BeginPin(microservice.GetStartId(), ed::PinKind::Input);
ImGui::Text("> ");
ed::EndPin();
}
for (const auto& [name, param] : microservice.GetInputParameters())
{
ed::BeginPin(param.GetId(), ed::PinKind::Input);
Expand All @@ -48,9 +51,12 @@ struct NodeEditor
}

ImGuiEx_NextColumn();
ed::BeginPin(microservice.GetFinishId(), ed::PinKind::Output);
ImGui::Text(" >");
ed::EndPin();
if (workflowType != WorkflowType::Simple)
{
ed::BeginPin(microservice.GetFinishId(), ed::PinKind::Output);
ImGui::Text(" >");
ed::EndPin();
}
for (const auto& [name, param] : microservice.GetOutputParameters())
{
ed::BeginPin(param.GetId(), ed::PinKind::Output);
Expand All @@ -72,10 +78,10 @@ struct NodeEditor
// Start interaction with editor.
ed::Begin("Microservice Editor", ImVec2(0.0, 0.0f));

for (const auto& microservice : m_Workflow.GetMicroservices())
DrawNode(*microservice);
for (const auto& microservice : workflow.GetMicroservices())
DrawNode(*microservice, workflow.GetType());

for (const auto& [microservice, connections] : m_Workflow.GetConnections())
for (const auto& [microservice, connections] : workflow.GetConnections())
for (const auto& connection : connections)
ed::Link(connection.GetId(), connection.inputParameter->GetId(), connection.outputParameter->GetId());

Expand Down Expand Up @@ -105,7 +111,7 @@ struct NodeEditor
{
// ed::AcceptNewItem() return true when user release mouse button.
if (ed::AcceptNewItem())
m_Workflow.Connect(inputPinId.Get(), outputPinId.Get());
workflow.Connect(inputPinId.Get(), outputPinId.Get());

// You may choose to reject connection between these nodes
// by calling ed::RejectNewItem(). This will allow editor to give
Expand All @@ -124,7 +130,7 @@ struct NodeEditor
{
// If you agree that link can be deleted, accept deletion.
if (ed::AcceptDeletedItem())
m_Workflow.Disconnect(deletedLinkId.Get());
workflow.Disconnect(deletedLinkId.Get());

// You may reject link deletion by calling:
// ed::RejectDeletedItem();
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/Windows/NodeEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void NodeEditorWindow::Test()
// Workflow wrk;
// wrk.TestInitialize();
// wrk.Run();
nex.m_Workflow.Run();
nex.workflow.Run();
LOG_SUCCESS("Workflow test completed");
}

Expand Down
5 changes: 2 additions & 3 deletions src/Microservice/BlurImageMicroservice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ class BlurImageMicroservice : public Microservice

void Process() override
{
LOG_DEBUG("{} processing", GetName());
auto& image = GetInputParameter<cv::Mat>("image");
const auto blurSize = 7;
auto image = GetInputParameter<cv::Mat>("image").clone();
const auto blurSize = GetNearestOdd(image.rows * 0.05);
cv::GaussianBlur(image, image, cv::Size(blurSize, blurSize), 0);
SetOutputParameter("blurred image", image);
}
Expand Down
1 change: 0 additions & 1 deletion src/Microservice/LoadImageMicroservice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class LoadImageMicroservice : public Microservice

void Process() override
{
LOG_DEBUG("{} processing", GetName());
auto image = cv::imread(GetProjectDirectoryPath("data/ml/object_detection/datasets/cats/cats2.jpg").string());
LOG_DEBUG("Loaded image size: {}x{}x{}", image.cols, image.rows, image.channels());
SetOutputParameter("image", image);
Expand Down
2 changes: 2 additions & 0 deletions src/Microservice/Microservice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class Microservice

const std::string& GetName() { return microserviceName; }

void SetName(const std::string& name) { microserviceName = name; }

uintptr_t GetId() const { return reinterpret_cast<uintptr_t>(this); }

uintptr_t GetStartId() const { return start.GetId(); }
Expand Down
15 changes: 15 additions & 0 deletions src/Microservice/PlotImageMicroservice.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include "Microservice.hpp"

class PlotImageMicroservice : public Microservice
{
void DefineInputParameters() override { DefineInputParameter<cv::Mat>("image"); }

void DefineOutputParameters() override {}

void Process() override
{
auto& image = GetInputParameter<cv::Mat>("image");
Plot::Plot(GetName(), image);
}
};
Loading

0 comments on commit f51b4ef

Please sign in to comment.