0.4.1
Loading...
Searching...
No Matches
TimeWindow.cpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#include "TimeWindow.hpp"
10
12namespace nm = NAV::NodeManager;
14
18
19// ---------------------------------------------------------- Member functions -------------------------------------------------------------
20
22{
23 LOG_TRACE("{}: called", name);
24 _hasConfig = true;
25 _guiConfigDefaultWindowSize = { 500, 290 };
26
28
30}
31
33{
34 LOG_TRACE("{}: called", nameId());
35}
36
38{
39 return "TimeWindow";
40}
41
42std::string NAV::TimeWindow::type() const
43{
44 return typeStatic();
45}
46
48{
49 return "Utility";
50}
51
53{
54 if (ImGui::Checkbox(fmt::format("Inverse Window##{}", size_t(id)).c_str(), &_inverseWindow))
55 {
57 }
58 ImGui::SameLine();
59 gui::widgets::HelpMarker("Normal: [startTime, endTime]\n"
60 "Inverse: (-∞, startTime), (endTime, ∞)");
61
62 if (ImGui::BeginTable(fmt::format("Time Window##{}", size_t(id)).c_str(), 2, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoHostExtendX, ImVec2(0.0F, 0.0F)))
63 {
64 ImGui::TableSetupColumn("Beginning");
65 ImGui::TableSetupColumn("End");
66 ImGui::TableHeadersRow();
67
68 for (size_t i = 0; i < _startEndTime.size(); i++)
69 {
70 ImGui::TableNextColumn();
71 if (gui::widgets::TimeEdit(fmt::format("Time edit##{} {}", i, size_t(id)).c_str(), _startEndTime.at(i), _timeEditFormat.at(i)))
72 {
73 LOG_DEBUG("{}: {}Time = {}", nameId(), i == 0 ? "start" : "end", _startEndTime.at(i));
75 if (_startEndTime[0] >= _startEndTime[1]) { doDeinitialize(); }
76 }
77 }
78
79 ImGui::EndTable();
80 }
81}
82
84{
85 LOG_TRACE("{}: called", nameId());
86
87 json j;
88
89 j["startEndTime"] = _startEndTime;
90 j["timeEditFormat"] = _timeEditFormat;
91 j["inverseWindow"] = _inverseWindow;
92
93 return j;
94}
95
97{
98 LOG_TRACE("{}: called", nameId());
99
100 if (j.contains("startEndTime"))
101 {
102 j.at("startEndTime").get_to(_startEndTime);
103 }
104 if (j.contains("timeEditFormat"))
105 {
106 j.at("timeEditFormat").get_to(_timeEditFormat);
107 }
108 if (j.contains("inverseWindow"))
109 {
110 j.at("inverseWindow").get_to(_inverseWindow);
111 }
112}
113
115{
116 LOG_TRACE("{}: called", nameId());
117
118 if (_startEndTime[0] >= _startEndTime[1])
119 {
120 LOG_ERROR("{}: startTime >= endTime is not allowed. Please reconfigure the node.", nameId());
121 return false;
122 }
123
124 return true;
125}
126
128{
129 LOG_TRACE("{}: called for {} ==> {}", nameId(), size_t(startPin.id), size_t(endPin.id));
130
131 if (endPin.parentNode->id != id)
132 {
133 return; // Link on Output Port
134 }
135
136 // Store previous output pin identifier
137 auto previousOutputPinDataIdentifier = outputPins.at(OUTPUT_PORT_INDEX_FLOW).dataIdentifier;
138 // Overwrite output pin identifier with input pin identifier
139 outputPins.at(OUTPUT_PORT_INDEX_FLOW).dataIdentifier = startPin.dataIdentifier;
140
141 if (previousOutputPinDataIdentifier != outputPins.at(OUTPUT_PORT_INDEX_FLOW).dataIdentifier) // If the identifier changed
142 {
143 // Check if connected links on output port are still valid
144 for (auto& link : outputPins.at(OUTPUT_PORT_INDEX_FLOW).links)
145 {
146 if (auto* endPin = link.getConnectedPin())
147 {
148 if (!outputPins.at(OUTPUT_PORT_INDEX_FLOW).canCreateLink(*endPin))
149 {
150 // If the link is not valid anymore, delete it
151 outputPins.at(OUTPUT_PORT_INDEX_FLOW).deleteLink(*endPin);
152 }
153 }
154 }
155
156 // Refresh all links connected to the output pin if the type changed
157 if (outputPins.at(OUTPUT_PORT_INDEX_FLOW).dataIdentifier != previousOutputPinDataIdentifier)
158 {
159 for (auto& link : outputPins.at(OUTPUT_PORT_INDEX_FLOW).links)
160 {
161 if (auto* connectedPin = link.getConnectedPin())
162 {
163 outputPins.at(OUTPUT_PORT_INDEX_FLOW).recreateLink(*connectedPin);
164 }
165 }
166 }
167 }
168}
169
171{
172 LOG_TRACE("{}: called for {} ==> {}", nameId(), size_t(startPin.id), size_t(endPin.id));
173
174 if ((endPin.parentNode->id != id // Link on Output port is removed
175 && !inputPins.at(INPUT_PORT_INDEX_FLOW).isPinLinked()) // and the Input port is not linked
176 || (startPin.parentNode->id != id // Link on Input port is removed
177 && !outputPins.at(OUTPUT_PORT_INDEX_FLOW).isPinLinked())) // and the Output port is not linked
178 {
179 outputPins.at(OUTPUT_PORT_INDEX_FLOW).dataIdentifier = { NodeData::type() };
180 }
181}
182
184{
185 // Check whether timestamp is within the time window
186 auto obs = queue.extract_front();
187 if (_inverseWindow)
188 {
189 if (obs->insTime < _startEndTime[0] || obs->insTime > _startEndTime[1])
190 {
192 }
193 }
194 else
195 {
196 if (obs->insTime >= _startEndTime[0] && obs->insTime <= _startEndTime[1])
197 {
199 }
200 else if (obs->insTime > _startEndTime[1])
201 {
202 inputPins.at(INPUT_PORT_INDEX_FLOW).queueBlocked = true;
203 inputPins.at(INPUT_PORT_INDEX_FLOW).queue.clear();
204 outputPins.at(OUTPUT_PORT_INDEX_FLOW).noMoreDataAvailable = true;
205 }
206 }
207}
Save/Load the Nodes.
nlohmann::json json
json namespace
Text Help Marker (?) with Tooltip.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
Definition Logger.hpp:67
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
Definition Logger.hpp:73
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Manages all Nodes.
Limits measurement data from any source to a user-defined timewindow.
Input pins of nodes.
Definition Pin.hpp:491
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
static std::string type()
Returns the type of the data class.
Definition NodeData.hpp:45
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
Definition Node.cpp:395
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:410
std::vector< OutputPin > outputPins
List of output pins.
Definition Node.hpp:399
Node(std::string name)
Constructor.
Definition Node.cpp:30
std::vector< InputPin > inputPins
List of input pins.
Definition Node.hpp:397
std::string nameId() const
Node name and id.
Definition Node.cpp:253
std::string name
Name of the Node.
Definition Node.hpp:395
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
Definition Node.cpp:180
ax::NodeEditor::NodeId id
Unique Id of the Node.
Definition Node.hpp:391
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:413
Output pins of nodes.
Definition Pin.hpp:338
Node * parentNode
Reference to the parent node.
Definition Pin.hpp:307
ax::NodeEditor::PinId id
Unique Id of the Pin.
Definition Pin.hpp:297
std::vector< std::string > dataIdentifier
One or multiple Data Identifiers (Unique name which is used for data flows)
Definition Pin.hpp:305
~TimeWindow() override
Destructor.
void receiveObs(InputPin::NodeDataQueue &queue, size_t pinIdx)
Callback when receiving data on a port.
std::array< gui::widgets::TimeEditFormat, 2 > _timeEditFormat
Time edit format for start and end times.
void guiConfig() override
ImGui config window which is shown on double click.
static std::string typeStatic()
String representation of the Class Type.
std::string type() const override
String representation of the Class Type.
void restore(const json &j) override
Restores the node from a json object.
json save() const override
Saves the node into a json object.
static constexpr size_t INPUT_PORT_INDEX_FLOW
Flow.
void afterCreateLink(OutputPin &startPin, InputPin &endPin) override
Called when a new link was established.
static constexpr size_t OUTPUT_PORT_INDEX_FLOW
Flow.
std::array< InsTime, 2 > _startEndTime
Beginning and end of the time window.
static std::string category()
String representation of the Class Category.
bool initialize() override
Initialize the node.
bool _inverseWindow
If true, the window lets only times pass through, which are out of the time frame.
void afterDeleteLink(OutputPin &startPin, InputPin &endPin) override
Called when a link was deleted.
TimeWindow()
Default constructor.
auto extract_front()
Returns a copy of the first element in the container and removes it from the container.
Definition TsDeque.hpp:494
ImGui extensions.
OutputPin * CreateOutputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier, OutputPin::PinData data=static_cast< void * >(nullptr), int idx=-1)
Create an Output Pin object.
InputPin * CreateInputPin(Node *node, const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier={}, InputPin::Callback callback=static_cast< InputPin::FlowFirableCallbackFunc >(nullptr), InputPin::FlowFirableCheckFunc firable=nullptr, int priority=0, int idx=-1)
Create an Input Pin object.
void ApplyChanges()
Signals that there have been changes to the flow.
bool TimeEdit(const char *str_id, InsTime &insTime, TimeEditFormat &timeEditFormat, float itemWidth=170.0F)
Inputs to edit an InsTime object.
Definition TimeEdit.cpp:52
void HelpMarker(const char *desc, const char *symbol="(?)")
Text Help Marker, e.g. '(?)', with Tooltip.
@ Flow
NodeData Trigger.
Definition Pin.hpp:52