Dynamic Neural Field Composer 0.0.0
A C++20 library and interactive application for building and simulating Dynamic Neural Field (DNF) architectures.
Loading...
Searching...
No Matches
node_graph_window.h
Go to the documentation of this file.
1#pragma once
2
3#include <unordered_map>
4#include <unordered_set>
5#include <implot.h>
6#include <imgui-platform-kit/user_interface_window.h>
7
32#include "widgets.h"
37
38
40{
42 {
43 switch (label) {
45 return IM_COL32(86, 128, 191, 255); // Soft Blue
47 return IM_COL32(223, 148, 84, 255); // Warm Orange
49 return IM_COL32(210, 110, 60, 255); // Deep Orange
51 return IM_COL32(191, 63, 63, 255); // Muted Red
53 return IM_COL32(127, 191, 127, 255); // Sage Green
55 return IM_COL32(154, 121, 191, 255); // Lavender
57 return IM_COL32(165, 102, 71, 255); // Warm Brown
59 return IM_COL32(212, 192, 121, 255); // Cream Gold
61 return IM_COL32(175, 133, 187, 255); // Dusty Rose
63 return IM_COL32(148, 178, 182, 255); // Soft Teal
65 return IM_COL32(242, 209, 83, 255); // Warm Yellow
67 return IM_COL32(110, 160, 140, 255); // Sage Green
69 return IM_COL32(70, 110, 175, 255); // Deeper Blue
71 return IM_COL32(105, 175, 105, 255); // Deeper Sage Green
73 return IM_COL32(175, 48, 48, 255); // Deeper Muted Red
75 return IM_COL32(138, 105, 175, 255); // Deeper Lavender
77 return IM_COL32(207, 132, 68, 255); // Deeper Warm Orange
79 return IM_COL32(152, 116, 163, 255); // Deeper Dusty Rose
81 return IM_COL32(97, 161, 97, 255); // Darker Sage Green
83 return IM_COL32(80, 133, 80, 255); // Deepest Sage Green
85 return IM_COL32(210, 182, 72, 255); // Deeper Warm Yellow
87 return IM_COL32(182, 109, 44, 255); // Deeper Deep Orange
89 return IM_COL32(129, 155, 159, 255); // Deeper Soft Teal
91 return IM_COL32(96, 139, 122, 255); // Deeper Sage Green
92 default:
93 return IM_COL32(127, 127, 127, 255); // Neutral Gray
94 }
95 }
96
98 {
99 bool isFirstFrame = true;
101 ImVec2 size = { 540.0F, 620.0F };
102 bool autoFit = true;
103 float xMin = 0.F, xMax = 100.F, yMin = -20.F, yMax = 20.F;
104 float xStep = 1.0F;
105 float lineThickness = 2.5F;
106 char title[128] = "";
107 char xLabel[64] = "Spatial location";
108 char yLabel[64] = "Amplitude";
109 // 2D heatmap options
110 int colormap = ImPlotColormap_Deep;
111 float scaleMin = -20.0F;
112 float scaleMax = 20.0F;
113 bool autoScale = true;
114 char selectedComponent[64] = "";
115 char autoTitleComponent[64] = "";
116 };
117
118 class NodeGraphWindow final : public imgui_kit::UserInterfaceWindow
119 {
120 private:
121 std::shared_ptr<Simulation> simulation;
122 ImNodeEditor::Config config;
123 ImNodeEditor::EditorContext* context;
124 static constexpr uint16_t startingInputPinId = 1000;
125 static constexpr uint16_t startingOutputPinId = 2000;
126 static constexpr uint16_t startingLinkId = 3000;
127
128 // Initial-layout state: nodes not yet seen in this session get a grid position
129 // on the frame after their first render (when we can read their actual position).
130 mutable std::unordered_set<size_t> positionedNodeIds;
131 mutable std::unordered_map<size_t, ImVec2> pendingInitialPositions;
132
133 // Per-node floating plot cards (toggled by double-click).
134 mutable std::unordered_map<size_t, PlotCardState> plotCards;
135
136 // Node graph panel bounds (updated every frame) for plot card clamping.
137 mutable ImVec2 ngBoundsMin;
138 mutable ImVec2 ngBoundsMax;
139
140 // Mini-map cache (filled each frame inside Begin/End while editor context is active).
141 mutable std::vector<std::pair<ImVec2, ImVec2>> cachedNodeRects;
142 mutable std::vector<element::ElementLabel> cachedNodeLabels;
143 mutable std::vector<size_t> cachedNodeIds;
144 mutable ImVec2 cachedVpMin{};
145 mutable ImVec2 cachedVpMax{};
146
147 // Overlap prevention: baseline positions and drag-start positions for snap-on-drop.
148 mutable std::unordered_map<size_t, ImVec2> prevNodePositions;
149 mutable std::unordered_map<size_t, ImVec2> dragStartPositions;
150 public:
151 explicit NodeGraphWindow(const std::shared_ptr<Simulation>& simulation);
152
157
158 void render() override;
159 void renderEmbedded() const;
160 ~NodeGraphWindow() override = default;
161 private:
162 void renderGraphContent() const;
163 void renderElementNodes() const;
164 static void renderElementNode(const std::shared_ptr<element::Element>& element);
165 static void renderElementNodeConnections(const std::shared_ptr<element::Element>& element);
166 void handleInteractions() const;
167 void handlePinInteractions() const;
168 void handleLinkInteractions() const;
169 void handleNodeSelection() const;
170 void renderNodePlotCards() const;
171 static size_t getNodeId(const std::shared_ptr<element::Element>& element);
172 static int getColumnForElement(element::ElementLabel label);
173 static void applyCanvasStyle();
174 static void restoreCanvasStyle();
175 static void renderElementTooltip(const std::shared_ptr<element::Element>& element);
176 static bool isWeightMapElement(element::ElementLabel label);
177 static void drawWeightHeatmap(ImDrawList* dl, ImRect rect, const std::vector<double>& weights,
178 int rows, int cols);
179 static void draw2DFieldHeatmap(ImDrawList* dl, ImRect rect, const std::vector<double>& data,
180 int rows, int cols, double wMin, double wMax, int colormap = ImPlotColormap_Deep);
181 static void drawInlineHeatmapAxes(ImDrawList* dl, const ImRect& hmRect, int rows, int cols,
182 double dMin, double dMax, int colormap = ImPlotColormap_Deep);
183 static void renderNodeScrollingName(const std::shared_ptr<element::Element>& element, float minNodeSize);
184 static void renderNodeInlinePreview(const std::shared_ptr<element::Element>& element, float minNodeSize);
185 static void renderNodePins(const std::shared_ptr<element::Element>& element, float minNodeSize);
186 static void renderPlotCardMenuBar(PlotCardState& state, bool is2DField,
187 const std::shared_ptr<element::Element>& element, bool isWM = false);
188 static void renderPlotCardContent(const std::shared_ptr<element::Element>& element, PlotCardState& state,
189 bool isWM, bool is2DField);
190 void renderNavigationControls(ImVec2 winPos, ImVec2 winSize) const;
191 void renderMiniMap(ImVec2 winPos, ImVec2 winSize) const;
192 };
193}
Definition node_graph_window.h:119
NodeGraphWindow & operator=(const NodeGraphWindow &)=delete
void renderEmbedded() const
Definition node_graph_window.cpp:152
void render() override
Definition node_graph_window.cpp:101
NodeGraphWindow(NodeGraphWindow &&)=delete
NodeGraphWindow(const NodeGraphWindow &)=delete
NodeGraphWindow & operator=(NodeGraphWindow &&)=delete
ElementLabel
Definition element_parameters.h:12
@ NORMAL_NOISE_2D
Definition element_parameters.h:31
@ ASYMMETRIC_GAUSS_KERNEL
Definition element_parameters.h:20
@ BOOST_STIMULUS_2D
Definition element_parameters.h:35
@ CORRELATED_NORMAL_NOISE_2D
Definition element_parameters.h:36
@ GAUSS_KERNEL_2D
Definition element_parameters.h:29
@ ASYMMETRIC_GAUSS_KERNEL_2D
Definition element_parameters.h:37
@ MEXICAN_HAT_KERNEL_2D
Definition element_parameters.h:30
@ OSCILLATORY_KERNEL
Definition element_parameters.h:19
@ GAUSS_KERNEL
Definition element_parameters.h:17
@ NORMAL_NOISE
Definition element_parameters.h:21
@ MEXICAN_HAT_KERNEL
Definition element_parameters.h:18
@ TIMED_GAUSS_STIMULUS_2D
Definition element_parameters.h:34
@ MEMORY_TRACE_2D
Definition element_parameters.h:38
@ MEMORY_TRACE
Definition element_parameters.h:25
@ GAUSS_STIMULUS
Definition element_parameters.h:15
@ NEURAL_FIELD_2D
Definition element_parameters.h:27
@ BOOST_STIMULUS
Definition element_parameters.h:16
@ FIELD_COUPLING
Definition element_parameters.h:23
@ NEURAL_FIELD
Definition element_parameters.h:14
@ OSCILLATORY_KERNEL_2D
Definition element_parameters.h:32
@ TIMED_GAUSS_STIMULUS
Definition element_parameters.h:33
@ CORRELATED_NORMAL_NOISE
Definition element_parameters.h:22
@ GAUSS_STIMULUS_2D
Definition element_parameters.h:28
@ GAUSS_FIELD_COUPLING
Definition element_parameters.h:24
Definition control_bar_window.h:10
ImU32 getHeaderColorForElementType(const element::ElementLabel label)
Definition node_graph_window.h:41
Definition node_graph_window.h:98
float xMin
Definition node_graph_window.h:103
float xStep
Definition node_graph_window.h:104
char autoTitleComponent[64]
Definition node_graph_window.h:115
float scaleMin
Definition node_graph_window.h:111
ImVec2 size
Definition node_graph_window.h:101
float xMax
Definition node_graph_window.h:103
bool autoScale
Definition node_graph_window.h:113
float yMin
Definition node_graph_window.h:103
char xLabel[64]
Definition node_graph_window.h:107
ImVec2 initialPos
Definition node_graph_window.h:100
float lineThickness
Definition node_graph_window.h:105
float yMax
Definition node_graph_window.h:103
bool autoFit
Definition node_graph_window.h:102
char selectedComponent[64]
Definition node_graph_window.h:114
bool isFirstFrame
Definition node_graph_window.h:99
float scaleMax
Definition node_graph_window.h:112
char yLabel[64]
Definition node_graph_window.h:108
int colormap
Definition node_graph_window.h:110
char title[128]
Definition node_graph_window.h:106