0.5.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
12
16
17// ---------------------------------------------------------- Member functions -------------------------------------------------------------
18
29
31{
32 LOG_TRACE("{}: called", nameId());
33}
34
36{
37 return "TimeWindow";
38}
39
40std::string NAV::TimeWindow::type() const
41{
42 return typeStatic();
43}
44
46{
47 return "Utility";
48}
49
51{
52 if (ImGui::Checkbox(fmt::format("Inverse Window##{}", size_t(id)).c_str(), &_inverseWindow))
53 {
55 }
56 ImGui::SameLine();
57 gui::widgets::HelpMarker("Normal: [startTime, endTime]\n"
58 "Inverse: (-∞, startTime), (endTime, ∞)");
59
60 if (ImGui::BeginTable(fmt::format("Time Window##{}", size_t(id)).c_str(), 2, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoHostExtendX, ImVec2(0.0F, 0.0F)))
61 {
62 ImGui::TableSetupColumn("Beginning");
63 ImGui::TableSetupColumn("End");
64 ImGui::TableHeadersRow();
65
66 for (size_t i = 0; i < _startEndTime.size(); i++)
67 {
68 ImGui::TableNextColumn();
69 if (gui::widgets::TimeEdit(fmt::format("Time edit##{} {}", i, size_t(id)).c_str(), _startEndTime.at(i), _timeEditFormat.at(i)))
70 {
71 LOG_DEBUG("{}: {}Time = {}", nameId(), i == 0 ? "start" : "end", _startEndTime.at(i));
73 if (_startEndTime[0] >= _startEndTime[1]) { doDeinitialize(); }
74 }
75 }
76
77 ImGui::EndTable();
78 }
79}
80
82{
83 LOG_TRACE("{}: called", nameId());
84
85 json j;
86
87 j["startEndTime"] = _startEndTime;
88 j["timeEditFormat"] = _timeEditFormat;
89 j["inverseWindow"] = _inverseWindow;
90
91 return j;
92}
93
95{
96 LOG_TRACE("{}: called", nameId());
97
98 if (j.contains("startEndTime"))
99 {
100 j.at("startEndTime").get_to(_startEndTime);
101 }
102 if (j.contains("timeEditFormat"))
103 {
104 j.at("timeEditFormat").get_to(_timeEditFormat);
105 }
106 if (j.contains("inverseWindow"))
107 {
108 j.at("inverseWindow").get_to(_inverseWindow);
109 }
110}
111
113{
114 LOG_TRACE("{}: called", nameId());
115
116 if (_startEndTime[0] >= _startEndTime[1])
117 {
118 LOG_ERROR("{}: startTime >= endTime is not allowed. Please reconfigure the node.", nameId());
119 return false;
120 }
121
122 return true;
123}
124
126{
127 LOG_TRACE("{}: called for {} ==> {}", nameId(), size_t(startPin.id), size_t(endPin.id));
128
129 if (endPin.parentNode->id != id)
130 {
131 return; // Link on Output Port
132 }
133
134 // Store previous output pin identifier
135 auto previousOutputPinDataIdentifier = outputPins.at(OUTPUT_PORT_INDEX_FLOW).dataIdentifier;
136 // Overwrite output pin identifier with input pin identifier
137 outputPins.at(OUTPUT_PORT_INDEX_FLOW).dataIdentifier = startPin.dataIdentifier;
138
139 if (previousOutputPinDataIdentifier != outputPins.at(OUTPUT_PORT_INDEX_FLOW).dataIdentifier) // If the identifier changed
140 {
141 // Check if connected links on output port are still valid
142 for (auto& link : outputPins.at(OUTPUT_PORT_INDEX_FLOW).links)
143 {
144 if (auto* endPin = link.getConnectedPin())
145 {
146 if (!outputPins.at(OUTPUT_PORT_INDEX_FLOW).canCreateLink(*endPin))
147 {
148 // If the link is not valid anymore, delete it
149 outputPins.at(OUTPUT_PORT_INDEX_FLOW).deleteLink(*endPin);
150 }
151 }
152 }
153
154 // Refresh all links connected to the output pin if the type changed
155 if (outputPins.at(OUTPUT_PORT_INDEX_FLOW).dataIdentifier != previousOutputPinDataIdentifier)
156 {
157 for (auto& link : outputPins.at(OUTPUT_PORT_INDEX_FLOW).links)
158 {
159 if (auto* connectedPin = link.getConnectedPin())
160 {
161 outputPins.at(OUTPUT_PORT_INDEX_FLOW).recreateLink(*connectedPin);
162 }
163 }
164 }
165 }
166}
167
169{
170 LOG_TRACE("{}: called for {} ==> {}", nameId(), size_t(startPin.id), size_t(endPin.id));
171
172 if ((endPin.parentNode->id != id // Link on Output port is removed
173 && !inputPins.at(INPUT_PORT_INDEX_FLOW).isPinLinked()) // and the Input port is not linked
174 || (startPin.parentNode->id != id // Link on Input port is removed
175 && !outputPins.at(OUTPUT_PORT_INDEX_FLOW).isPinLinked())) // and the Output port is not linked
176 {
177 outputPins.at(OUTPUT_PORT_INDEX_FLOW).dataIdentifier = { NodeData::type() };
178 }
179}
180
182{
183 // Check whether timestamp is within the time window
184 auto obs = queue.extract_front();
185 if (_inverseWindow)
186 {
187 if (obs->insTime < _startEndTime[0] || obs->insTime > _startEndTime[1])
188 {
190 }
191 }
192 else
193 {
194 if (obs->insTime >= _startEndTime[0] && obs->insTime <= _startEndTime[1])
195 {
197 }
198 else if (obs->insTime > _startEndTime[1])
199 {
200 inputPins.at(INPUT_PORT_INDEX_FLOW).queueBlocked = true;
201 inputPins.at(INPUT_PORT_INDEX_FLOW).queue.clear();
202 outputPins.at(OUTPUT_PORT_INDEX_FLOW).noMoreDataAvailable = true;
203 }
204 }
205}
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
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:465
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:522
std::vector< OutputPin > outputPins
List of output pins.
Definition Node.hpp:511
Node(std::string name)
Constructor.
Definition Node.cpp:29
std::vector< InputPin > inputPins
List of input pins.
Definition Node.hpp:509
OutputPin * CreateOutputPin(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.
Definition Node.cpp:278
std::string nameId() const
Node name and id.
Definition Node.cpp:323
std::string name
Name of the Node.
Definition Node.hpp:507
InputPin * CreateInputPin(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.
Definition Node.cpp:252
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
Definition Node.cpp:179
ax::NodeEditor::NodeId id
Unique Id of the Node.
Definition Node.hpp:503
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:525
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.
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, int columns=1)
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