0.3.0
Loading...
Searching...
No Matches
Plot.hpp
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
13
14#pragma once
15
16#include <array>
17#include <imgui.h>
18#include <implot.h>
19
20#include <map>
21#include <memory>
22#include <mutex>
23#include <unordered_set>
24
25#include "NodeData/NodeData.hpp"
29
36
53
54namespace NAV
55{
57class Plot : public Node, public CommonLog
58{
59 public:
63 ~Plot() override;
65 Plot(const Plot&) = delete;
67 Plot(Plot&&) = delete;
69 Plot& operator=(const Plot&) = delete;
71 Plot& operator=(Plot&&) = delete;
72
74 [[nodiscard]] static std::string typeStatic();
75
77 [[nodiscard]] std::string type() const override;
78
80 [[nodiscard]] static std::string category();
81
84 void guiConfig() override;
85
87 [[nodiscard]] json save() const override;
88
91 void restore(const json& j) override;
92
96 void afterCreateLink(OutputPin& startPin, InputPin& endPin) override;
97
99 struct PinData
100 {
102 struct PlotData
103 {
105 PlotData() = default;
106
110 PlotData(std::string displayName, size_t size);
111
113 std::string displayName;
117 bool hasData = false;
118
120 bool markedForDelete = false;
122 bool isDynamic = false;
123 };
124
126 enum class PinType : uint8_t
127 {
133 };
134
136 PinData() = default;
138 ~PinData() = default;
141 PinData(const PinData& other);
142
145 PinData(PinData&& other) noexcept;
146
152 PinData& operator=(PinData&& rhs) noexcept;
153
157 void addPlotDataItem(size_t dataIndex, const std::string& displayName);
158
160 int size = 0;
162 std::string dataIdentifier;
164 std::vector<PlotData> plotData;
170 int stride = 1;
172 std::mutex mutex;
176 std::vector<std::tuple<double, InsTime, std::string, int32_t>> events;
177 };
178
180 struct PlotInfo
181 {
183 struct PlotItem
184 {
186 PlotItem() = default;
187
192 PlotItem(size_t pinIndex, size_t dataIndex, std::string displayName)
194 {
195 style.colormapMaskDataCmpIdx = dataIndex;
196 style.markerColormapMaskDataCmpIdx = dataIndex;
197 }
198
204 PlotItem(size_t pinIndex, size_t dataIndex, std::string displayName, ImAxis axis)
206 {
207 this->axis = axis; // NOLINT(cppcoreguidelines-prefer-member-initializer)
208 }
209
213 constexpr bool operator==(const PlotItem& rhs) const
214 {
215 return pinIndex == rhs.pinIndex && dataIndex == rhs.dataIndex && displayName == rhs.displayName;
216 }
217
218 size_t pinIndex{};
219 size_t dataIndex{};
220 std::string displayName;
221 ImAxis axis{ ImAxis_Y1 };
231
234
236 std::array<ScrollingBuffer<double>, 2> errorBoundsData;
237
239 std::vector<std::tuple<double, double, PlotEventTooltip>> eventTooltips;
240 };
241
243 PlotInfo() = default;
244
248 PlotInfo(const std::string& title, size_t nInputPins)
249 : title(title), headerText(title), selectedXdata(nInputPins, 1) {}
250
252 ImVec2 size{ -1, 300 };
253
255 std::string title;
257 std::string headerText;
259 bool overrideXAxisLabel = false;
261 std::string xAxisLabel;
263 std::string y1AxisLabel;
265 std::string y2AxisLabel;
267 std::string y3AxisLabel;
269 size_t selectedPin = 0;
271 int plotFlags = 0;
273 ImPlotAxisFlags xAxisFlags = ImPlotAxisFlags_AutoFit;
275 ImPlotAxisFlags yAxisFlags = ImPlotAxisFlags_AutoFit;
277 ImPlotScale xAxisScale = ImPlotScale_Linear;
279 std::array<ImPlotScale, 3> yAxesScale = { ImPlotScale_Linear, ImPlotScale_Linear, ImPlotScale_Linear };
281 ImPlotLineFlags lineFlags = ImPlotLineFlags_NoClip | ImPlotLineFlags_SkipNaN;
282
284 std::vector<size_t> selectedXdata;
285
287 std::vector<PlotItem> plotItems;
288
290 float leftPaneWidth = 180.0F;
292 float rightPaneWidth = 400.0F;
293
295 bool visible = true;
296
298 std::vector<PlotTooltip> tooltips;
299 };
300
301 private:
303 bool initialize() override;
304
306 void deinitialize() override;
307
310
313 static void pinAddCallback(Node* node);
317 static void pinDeleteCallback(Node* node, size_t pinIdx);
318
320 size_t GPST_PLOT_IDX = 1;
321
323 std::vector<PinData> _pinData;
324
326 std::vector<PlotInfo> _plots;
327
329 size_t _nPlots = 0;
331 std::vector<std::string> _dataIdentifier = {
332 // General
334 // GNSS
339 // IMU
340 ImuObs::type(),
343 KvhObs::type(),
345 // State
347 Pos::type(),
348 PosVel::type(),
351 // WiFi
353 // Barometer
356
357 };
358
361
364
366 std::pair<std::unordered_set<size_t>, ImPlotRange> _forceXaxisRange;
367
369 std::optional<gui::widgets::PositionWithFrame> _originPosition;
370
373
377
383 void addEvent(size_t pinIndex, InsTime insTime, const std::string& text, int32_t dataIndex);
384
389 void addData(size_t pinIndex, size_t dataIndex, double value);
390
396 size_t addData(size_t pinIndex, std::string displayName, double value);
397
401 CommonLog::LocalPosition calcLocalPosition(const Eigen::Vector3d& lla_position);
402
406 void plotBoolean(const InsTime& insTime, size_t pinIdx);
407
411 void plotInteger(const InsTime& insTime, size_t pinIdx);
412
416 void plotFloat(const InsTime& insTime, size_t pinIdx);
417
421 void plotMatrix(const InsTime& insTime, size_t pinIdx);
422
426 void plotFlowData(InputPin::NodeDataQueue& queue, size_t pinIdx);
427
433 template<typename T>
434 void plotData(const std::shared_ptr<const T>& obs, size_t pinIndex, size_t& plotIndex, size_t startIndex = 0)
435 {
436 for (size_t i = startIndex; i < T::GetStaticDescriptorCount(); ++i)
437 {
438 addData(pinIndex, plotIndex++, obs->getValueAtOrNaN(i));
439 }
440 }
441};
442
443} // namespace NAV
Barometric Height Storage Class.
Barometric Pressure Storage Class.
Common logging variables like time into run and local positions.
Dynamic Data container.
Inputs pins which can be added dynamically.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
GNSS measurement combinations.
GNSS Observation messages.
Data storage class for simulated IMU observations.
Data storage class for one VectorNavImu observation.
Parent Class for all IMU Observations.
Loosely-coupled Kalman Filter INS/GNSS errors.
Tightly-coupled Kalman Filter INS/GNSS errors.
Data storage class for one KVH Imu observation.
Abstract NodeData Class.
Node Class.
Tooltips for a plot events.
Specifying the look of a certain line in the plot.
Plot Tooltips on hover.
Position, Velocity and Attitude Storage Class.
Position Input GUI widgets.
RTKLIB Pos Observation Class.
A buffer which is overwriting itself from the start when full.
SPP Algorithm output.
Binary Outputs from VectorNav Sensors.
Vector Utility functions.
void move(std::vector< T > &v, size_t sourceIdx, size_t targetIdx)
Moves an element within a vector to a new position.
Definition Vector.hpp:27
WiFi Positioning Algorithm output.
static std::string type()
Returns the type of the data class.
Definition BaroHgt.hpp:28
static std::string type()
Returns the type of the data class.
Definition BaroPressObs.hpp:27
CommonLog(const CommonLog &)=delete
Copy constructor.
static std::string type()
Returns the type of the data class.
Definition DynamicData.hpp:30
static std::string type()
Returns the type of the data class.
Definition GnssCombination.hpp:32
static std::string type()
Returns the type of the data class.
Definition GnssObs.hpp:150
static std::string type()
Returns the type of the data class.
Definition ImuObsSimulated.hpp:31
static std::string type()
Returns the type of the data class.
Definition ImuObsWDelta.hpp:32
static std::string type()
Returns the type of the data class.
Definition ImuObs.hpp:33
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 InsGnssLCKFSolution.hpp:30
static std::string type()
Returns the type of the data class.
Definition InsGnssTCKFSolution.hpp:26
The class is responsible for all time-related tasks.
Definition InsTime.hpp:710
static std::string type()
Returns the type of the data class.
Definition KvhObs.hpp:39
Node(std::string name)
Constructor.
Output pins of nodes.
Definition Pin.hpp:338
void plotInteger(const InsTime &insTime, size_t pinIdx)
Plots the data on this port.
gui::widgets::DynamicInputPins _dynamicInputPins
Dynamic input pins.
Definition Plot.hpp:376
size_t _screenshotFrameCnt
Frame counter for taking screenshots (> 0 when screenshot in progress)
Definition Plot.hpp:362
static void pinAddCallback(Node *node)
Function to call to add a new pin.
static void pinDeleteCallback(Node *node, size_t pinIdx)
Function to call to delete a pin.
void restore(const json &j) override
Restores the node from a json object.
void plotData(const std::shared_ptr< const T > &obs, size_t pinIndex, size_t &plotIndex, size_t startIndex=0)
Plot the data.
Definition Plot.hpp:434
Plot(const Plot &)=delete
Copy constructor.
void plotFlowData(InputPin::NodeDataQueue &queue, size_t pinIdx)
Plot the data on this port.
void plotFloat(const InsTime &insTime, size_t pinIdx)
Plots the data on this port.
int _dragAndDropHeaderIndex
Index of the Collapsible Header currently being dragged.
Definition Plot.hpp:360
std::string type() const override
String representation of the Class Type.
bool _overridePositionStartValues
Flag, whether to override the North/East startValues in the GUI.
Definition Plot.hpp:372
Plot & operator=(Plot &&)=delete
Move assignment operator.
std::vector< PinData > _pinData
Data storage for each pin.
Definition Plot.hpp:323
std::optional< gui::widgets::PositionWithFrame > _originPosition
Start position for the calculation of relative North-South and East-West.
Definition Plot.hpp:369
void deinitialize() override
Deinitialize the node.
size_t _screenShotPlotIdx
Plot index a screenshot is taken of.
Definition Plot.hpp:363
void plotMatrix(const InsTime &insTime, size_t pinIdx)
Plots the data on this port.
size_t GPST_PLOT_IDX
Index of the GPST data (unix timestamp)
Definition Plot.hpp:320
Plot()
Default constructor.
Plot & operator=(const Plot &)=delete
Copy assignment operator.
json save() const override
Saves the node into a json object.
CommonLog::LocalPosition calcLocalPosition(const Eigen::Vector3d &lla_position)
Calculate the local position offset from the plot origin.
std::pair< std::unordered_set< size_t >, ImPlotRange > _forceXaxisRange
Values to force the x axis range to and a set of plotIdx to force.
Definition Plot.hpp:366
void addEvent(size_t pinIndex, InsTime insTime, const std::string &text, int32_t dataIndex)
Adds a event to a certain point in time.
void addData(size_t pinIndex, size_t dataIndex, double value)
Add Data to the buffer of the pin.
static std::string typeStatic()
String representation of the Class Type.
void plotBoolean(const InsTime &insTime, size_t pinIdx)
Plots the data on this port.
~Plot() override
Destructor.
void updateNumberOfPlots()
Adds/Deletes Plots depending on the variable nPlots.
void afterCreateLink(OutputPin &startPin, InputPin &endPin) override
Called when a new link was established.
size_t addData(size_t pinIndex, std::string displayName, double value)
Add Data to the buffer of the pin.
static std::string category()
String representation of the Class Category.
std::vector< PlotInfo > _plots
Info for each plot window.
Definition Plot.hpp:326
void guiConfig() override
ImGui config window which is shown on double click.
size_t _nPlots
Amount of plot windows (should equal _plots.size())
Definition Plot.hpp:329
Plot(Plot &&)=delete
Move constructor.
std::vector< std::string > _dataIdentifier
Possible data identifiers to connect.
Definition Plot.hpp:331
bool initialize() override
Initialize the node.
static std::string type()
Returns the type of the data class.
Definition PosVelAtt.hpp:29
static std::string type()
Returns the type of the data class.
Definition PosVel.hpp:27
static std::string type()
Returns the type of the data class.
Definition Pos.hpp:36
static std::string type()
Returns the type of the data class.
Definition RtklibPosObs.hpp:139
A buffer which is overwriting itself from the start when full.
Definition ScrollingBuffer.hpp:29
static std::string type()
Returns the type of the data class.
Definition SppSolution.hpp:41
static std::string type()
Returns the type of the data class.
Definition VectorNavBinaryOutput.hpp:48
static std::string type()
Returns the type of the data class.
Definition WiFiPositioningSolution.hpp:29
Local position offset from a reference point.
Definition CommonLog.hpp:54
Specifying the look of a certain line in the plot.
Definition PlotItemStyle.hpp:30
bool isDynamic
Bool to show if dynamic data.
Definition Plot.hpp:122
PlotData()=default
Default constructor (needed to make serialization with json working)
bool hasData
Flag if data was received, as the buffer contains std::nan("") otherwise.
Definition Plot.hpp:117
bool markedForDelete
When connecting a new link. All data is flagged for delete and only those who are also present in the...
Definition Plot.hpp:120
ScrollingBuffer< double > buffer
Buffer for the data.
Definition Plot.hpp:115
PlotData(std::string displayName, size_t size)
Constructor.
std::string displayName
Display name of the contained data.
Definition Plot.hpp:113
std::mutex mutex
Mutex to lock the buffer so that the GUI thread and the calculation threads don't cause a data race.
Definition Plot.hpp:172
~PinData()=default
Destructor.
PinType
Possible Pin types.
Definition Plot.hpp:127
@ Int
Integer Number.
Definition Plot.hpp:130
@ Float
Floating Point Number.
Definition Plot.hpp:131
@ Bool
Boolean.
Definition Plot.hpp:129
@ Flow
NodeData Trigger.
Definition Plot.hpp:128
@ Matrix
Matrix Object.
Definition Plot.hpp:132
PinData & operator=(PinData &&rhs) noexcept
Move assignment operator.
std::vector< std::tuple< double, InsTime, std::string, int32_t > > events
Events with relative time, absolute time, tooltip text and data Index (-1 means all)
Definition Plot.hpp:176
PinData(const PinData &other)
Copy constructor.
PinData()=default
Constructor.
int size
Size of all buffers of the plotData elements.
Definition Plot.hpp:160
ScrollingBuffer< std::shared_ptr< const NodeData > > rawNodeData
List with the raw data received.
Definition Plot.hpp:166
int stride
Amount of points to skip for plotting.
Definition Plot.hpp:170
PinType pinType
Pin Type.
Definition Plot.hpp:168
PinData & operator=(const PinData &rhs)
Copy assignment operator.
PinData(PinData &&other) noexcept
Move constructor.
int dynamicDataStartIndex
Dynamic data start index.
Definition Plot.hpp:174
std::vector< PlotData > plotData
List with all the data.
Definition Plot.hpp:164
std::string dataIdentifier
Data Identifier of the connected pin.
Definition Plot.hpp:162
void addPlotDataItem(size_t dataIndex, const std::string &displayName)
Adds a plotData Element to the list.
std::string displayName
Display name of the data (not changing and unique)
Definition Plot.hpp:220
ScrollingBuffer< ImU32 > markerColormapMaskColors
Buffer for the colormap mask.
Definition Plot.hpp:228
PlotItem()=default
Default constructor (needed to make serialization with json working)
size_t pinIndex
Index of the pin where the data came in.
Definition Plot.hpp:218
std::vector< std::tuple< double, double, PlotEventTooltip > > eventTooltips
List of tooltips (x,y, tooltip)
Definition Plot.hpp:239
ScrollingBuffer< double > eventMarker
Buffer for event markers.
Definition Plot.hpp:233
PlotItem(size_t pinIndex, size_t dataIndex, std::string displayName, ImAxis axis)
Constructor.
Definition Plot.hpp:204
PlotItemStyle style
Definition Plot.hpp:222
ScrollingBuffer< ImU32 > colormapMaskColors
Buffer for the colormap mask.
Definition Plot.hpp:224
size_t colormapMaskVersion
Colormap version (to track updates of the colormap)
Definition Plot.hpp:226
size_t dataIndex
Index of the data on the pin.
Definition Plot.hpp:219
constexpr bool operator==(const PlotItem &rhs) const
Equal comparison operator (needed to search the vector with std::find)
Definition Plot.hpp:213
std::array< ScrollingBuffer< double >, 2 > errorBoundsData
Error bounds lower and upper data.
Definition Plot.hpp:236
size_t markerColormapMaskVersion
Colormap version (to track updates of the colormap)
Definition Plot.hpp:230
PlotItem(size_t pinIndex, size_t dataIndex, std::string displayName)
Constructor.
Definition Plot.hpp:192
ImAxis axis
Axis to plot the data on (Y1, Y2, Y3)
Definition Plot.hpp:221
ImVec2 size
Size of the plot.
Definition Plot.hpp:252
bool visible
Flag whether the whole plot is visible. If not, then it should be deleted.
Definition Plot.hpp:295
std::string y2AxisLabel
Y2 axis label.
Definition Plot.hpp:265
std::string headerText
Title of the CollapsingHeader.
Definition Plot.hpp:257
std::array< ImPlotScale, 3 > yAxesScale
Scale for the y-Axes.
Definition Plot.hpp:279
ImPlotLineFlags lineFlags
Line Flags for all items (each item can override the selection)
Definition Plot.hpp:281
ImPlotAxisFlags xAxisFlags
Flags for the x-Axis.
Definition Plot.hpp:273
float leftPaneWidth
Width of plot Data content.
Definition Plot.hpp:290
int plotFlags
Flags which are passed to the plot.
Definition Plot.hpp:271
bool overrideXAxisLabel
Flag, whether to override the x axis label.
Definition Plot.hpp:259
std::vector< PlotTooltip > tooltips
List of tooltip windows to show.
Definition Plot.hpp:298
std::string xAxisLabel
X axis label.
Definition Plot.hpp:261
size_t selectedPin
Selected pin in the GUI for the Drag & Drop Data.
Definition Plot.hpp:269
ImPlotScale xAxisScale
Scale for the x-Axis.
Definition Plot.hpp:277
PlotInfo(const std::string &title, size_t nInputPins)
Constructor.
Definition Plot.hpp:248
PlotInfo()=default
Default constructor.
float rightPaneWidth
Width of the plot.
Definition Plot.hpp:292
std::vector< PlotItem > plotItems
List containing all elements which should be plotted.
Definition Plot.hpp:287
std::vector< size_t > selectedXdata
Key: PinIndex, Value: plotData to use for x-Axis.
Definition Plot.hpp:284
std::string title
Title of the ImPlot.
Definition Plot.hpp:255
std::string y1AxisLabel
Y1 axis label.
Definition Plot.hpp:263
ImPlotAxisFlags yAxisFlags
Flags for the y-Axes.
Definition Plot.hpp:275
std::string y3AxisLabel
Y3 axis label.
Definition Plot.hpp:267
Inputs pins which can be added dynamically.
Definition DynamicInputPins.hpp:29