0.2.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 <implot.h>
18
19#include <map>
20#include <mutex>
21#include <unordered_set>
22
26
31
45
46namespace NAV
47{
49class Plot : public Node, public CommonLog
50{
51 public:
55 ~Plot() override;
57 Plot(const Plot&) = delete;
59 Plot(Plot&&) = delete;
61 Plot& operator=(const Plot&) = delete;
63 Plot& operator=(Plot&&) = delete;
64
66 [[nodiscard]] static std::string typeStatic();
67
69 [[nodiscard]] std::string type() const override;
70
72 [[nodiscard]] static std::string category();
73
76 void guiConfig() override;
77
79 [[nodiscard]] json save() const override;
80
83 void restore(const json& j) override;
84
88 void afterCreateLink(OutputPin& startPin, InputPin& endPin) override;
89
91 struct PinData
92 {
94 struct PlotData
95 {
97 PlotData() = default;
98
102 PlotData(std::string displayName, size_t size);
103
105 std::string displayName;
109 bool hasData = false;
110
112 bool markedForDelete = false;
114 bool isDynamic = false;
115 };
116
118 enum class PinType : int
119 {
120 Flow,
121 Bool,
122 Int,
123 Float,
124 Matrix,
125 };
126
128 PinData() = default;
130 ~PinData() = default;
134
137 PinData(PinData&& other) noexcept;
138
145
149 void addPlotDataItem(size_t dataIndex, const std::string& displayName);
150
152 int size = 0;
154 std::string dataIdentifier;
156 std::vector<PlotData> plotData;
160 int stride = 1;
162 std::mutex mutex;
166 std::vector<std::tuple<double, InsTime, std::string, int32_t>> events;
167 };
168
170 struct PlotInfo
171 {
173 struct PlotItem
174 {
176 struct Style
177 {
179 enum class LineType : int
180 {
181 Scatter,
182 Line,
183 };
184
186 std::string legendName;
188 std::string legendNameGui;
192 ImVec4 color = IMPLOT_AUTO_COL;
194 std::pair<ColormapMaskType, int64_t> colormapMask = { ColormapMaskType::None, -1 };
198 float thickness = 1.0F;
200 std::optional<ImPlotLineFlags> lineFlags;
201
203 int stride = 0;
204
206 std::pair<ColormapMaskType, int64_t> markerColormapMask = { ColormapMaskType::None, -1 };
210 bool markers = false;
212 ImPlotMarker markerStyle = ImPlotMarker_Cross;
214 float markerSize = 1.0F;
216 float markerWeight = 1.0F;
218 ImVec4 markerFillColor = IMPLOT_AUTO_COL;
220 ImVec4 markerOutlineColor = IMPLOT_AUTO_COL;
221
223 bool eventsEnabled = false;
225 ImPlotMarker eventMarkerStyle = ImPlotMarker_Cross;
227 float eventMarkerSize = 6.0F;
229 float eventMarkerWeight = 2.0F;
231 ImVec4 eventMarkerFillColor = ImVec4(1.0, 0.0, 0.0, 1.0);
233 ImVec4 eventMarkerOutlineColor = ImVec4(1.0, 0.0, 0.0, 1.0);
236 };
237
239 PlotItem() = default;
240
251
257 PlotItem(size_t pinIndex, size_t dataIndex, std::string displayName, ImAxis axis)
259 {
260 this->axis = axis; // NOLINT(cppcoreguidelines-prefer-member-initializer)
261 }
262
266 constexpr bool operator==(const PlotItem& rhs) const
267 {
268 return pinIndex == rhs.pinIndex && dataIndex == rhs.dataIndex && displayName == rhs.displayName;
269 }
270
271 size_t pinIndex{};
272 size_t dataIndex{};
273 std::string displayName;
274 ImAxis axis{ ImAxis_Y1 };
284
287
289 struct Tooltip
290 {
292 std::vector<std::string> texts;
293 };
295 std::vector<std::tuple<double, double, Tooltip>> eventTooltips;
296 };
297
299 PlotInfo() = default;
300
304 PlotInfo(const std::string& title, size_t nInputPins)
305 : title(title), headerText(title), selectedXdata(nInputPins, 1) {}
306
308 ImVec2 size{ -1, 300 };
309
311 std::string title;
313 std::string headerText;
315 bool overrideXAxisLabel = false;
317 std::string xAxisLabel;
319 std::string y1AxisLabel;
321 std::string y2AxisLabel;
323 std::string y3AxisLabel;
325 size_t selectedPin = 0;
327 int plotFlags = 0;
329 ImPlotAxisFlags xAxisFlags = ImPlotAxisFlags_AutoFit;
331 ImPlotAxisFlags yAxisFlags = ImPlotAxisFlags_AutoFit;
333 ImPlotScale xAxisScale = ImPlotScale_Linear;
335 std::array<ImPlotScale, 3> yAxesScale = { ImPlotScale_Linear, ImPlotScale_Linear, ImPlotScale_Linear };
337 ImPlotLineFlags lineFlags = ImPlotLineFlags_NoClip | ImPlotLineFlags_SkipNaN;
338
340 std::vector<size_t> selectedXdata;
341
343 std::vector<PlotItem> plotItems;
344
346 float leftPaneWidth = 180.0F;
348 float rightPaneWidth = 400.0F;
349
351 bool visible = true;
352 };
353
354 private:
356 bool initialize() override;
357
359 void deinitialize() override;
360
362 void updateNumberOfPlots();
363
366 static void pinAddCallback(Node* node);
370 static void pinDeleteCallback(Node* node, size_t pinIdx);
371
373 size_t GPST_PLOT_IDX = 1;
374
376 std::vector<PinData> _pinData;
377
379 std::vector<PlotInfo> _plots;
380
382 size_t _nPlots = 0;
384 std::vector<std::string> _dataIdentifier = {
385 // General
387 // GNSS
392 // IMU
393 ImuObs::type(),
396 KvhObs::type(),
398 // State
400 Pos::type(),
401 PosVel::type(),
404 };
405
407 int _dragAndDropHeaderIndex = -1;
408
410 std::pair<std::unordered_set<size_t>, ImPlotRange> _forceXaxisRange{};
411
413 std::optional<gui::widgets::PositionWithFrame> _originPosition;
414
416 bool _overridePositionStartValues = false;
417
420 gui::widgets::DynamicInputPins _dynamicInputPins{ 0, this, pinAddCallback, pinDeleteCallback, 1 };
421
427 void addEvent(size_t pinIndex, InsTime insTime, const std::string& text, int32_t dataIndex);
428
433 void addData(size_t pinIndex, size_t dataIndex, double value);
434
440 size_t addData(size_t pinIndex, std::string displayName, double value);
441
445 CommonLog::LocalPosition calcLocalPosition(const Eigen::Vector3d& lla_position);
446
450 void plotBoolean(const InsTime& insTime, size_t pinIdx);
451
455 void plotInteger(const InsTime& insTime, size_t pinIdx);
456
460 void plotFloat(const InsTime& insTime, size_t pinIdx);
461
465 void plotMatrix(const InsTime& insTime, size_t pinIdx);
466
470 void plotFlowData(InputPin::NodeDataQueue& queue, size_t pinIdx);
471
477 template<typename T>
478 void plotData(const std::shared_ptr<const T>& obs, size_t pinIndex, size_t& plotIndex, size_t startIndex = 0)
479 {
480 for (size_t i = startIndex; i < T::GetStaticDescriptorCount(); ++i)
481 {
482 addData(pinIndex, plotIndex++, obs->getValueAtOrNaN(i));
483 }
484 }
485
490 void plotDynamicData(const std::shared_ptr<const DynamicData>& obs, size_t pinIndex, size_t& plotIndex);
491
496 void plotGnssCombination(const std::shared_ptr<const GnssCombination>& obs, size_t pinIndex, size_t& plotIndex);
497
502 void plotGnssObs(const std::shared_ptr<const GnssObs>& obs, size_t pinIndex, size_t& plotIndex);
503
507 void plotSppSolutionDynamicData(const std::shared_ptr<const SppSolution>& obs, size_t pinIndex);
508};
509
510} // namespace NAV
Colormap.
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.
Node Class.
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:26
Common logging variables like time into run and local positions.
Definition CommonLog.hpp:26
static std::string type()
Returns the type of the data class.
Definition DynamicData.hpp:29
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:149
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:31
static std::string type()
Returns the type of the data class.
Definition ImuObs.hpp:34
Input pins of nodes.
Definition Pin.hpp:491
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:703
static std::string type()
Returns the type of the data class.
Definition InsGnssLCKFSolution.hpp:29
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:667
static std::string type()
Returns the type of the data class.
Definition KvhObs.hpp:39
Abstract parent class for all nodes.
Definition Node.hpp:86
Output pins of nodes.
Definition Pin.hpp:338
Plot node which plots all kind of observations.
Definition Plot.hpp:50
void restore(const json &j) override
Restores the node from a json object.
Plot(const Plot &)=delete
Copy constructor.
std::string type() const override
String representation of the Class Type.
Plot & operator=(Plot &&)=delete
Move assignment operator.
Plot()
Default constructor.
Plot & operator=(const Plot &)=delete
Copy assignment operator.
json save() const override
Saves the node into a json object.
static std::string typeStatic()
String representation of the Class Type.
~Plot() override
Destructor.
void afterCreateLink(OutputPin &startPin, InputPin &endPin) override
Called when a new link was established.
static std::string category()
String representation of the Class Category.
void guiConfig() override
ImGui config window which is shown on double click.
Plot(Plot &&)=delete
Move constructor.
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:33
static std::string type()
Returns the type of the data class.
Definition RtklibPosObs.hpp:131
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:38
static std::string type()
Returns the type of the data class.
Definition VectorNavBinaryOutput.hpp:41
Stores the actual data coming from a pin.
Definition Plot.hpp:95
bool isDynamic
Bool to show if dynamic data.
Definition Plot.hpp:114
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:109
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:112
ScrollingBuffer< double > buffer
Buffer for the data.
Definition Plot.hpp:107
PlotData(std::string displayName, size_t size)
Constructor.
std::string displayName
Display name of the contained data.
Definition Plot.hpp:105
Information needed to plot the data on a certain pin.
Definition Plot.hpp:92
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:162
~PinData()=default
Destructor.
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:166
PinData(const PinData &other)
Copy constructor.
PinData()=default
Constructor.
int size
Size of all buffers of the plotData elements.
Definition Plot.hpp:152
int stride
Amount of points to skip for plotting.
Definition Plot.hpp:160
PinType pinType
Pin Type.
Definition Plot.hpp:158
PinData & operator=(const PinData &rhs)
Copy assignment operator.
PinData(PinData &&other) noexcept
Move constructor.
int dynamicDataStartIndex
Dynamic data start index.
Definition Plot.hpp:164
std::vector< PlotData > plotData
List with all the data.
Definition Plot.hpp:156
std::string dataIdentifier
Data Identifier of the connected pin.
Definition Plot.hpp:154
void addPlotDataItem(size_t dataIndex, const std::string &displayName)
Adds a plotData Element to the list.
PinType
Possible Pin types.
Definition Plot.hpp:119
@ Float
Floating Point Number.
@ Flow
NodeData Trigger.
Specifying the look of a certain line in the plot.
Definition Plot.hpp:177
ImVec4 color
Line Color.
Definition Plot.hpp:192
float eventMarkerWeight
Weight of the markers (increases thickness of marker lines)
Definition Plot.hpp:229
std::pair< ColormapMaskType, int64_t > markerColormapMask
Colormap mask (pair: type and id)
Definition Plot.hpp:206
size_t markerColormapMaskDataCmpIdx
Index of the plot data to compare for the color.
Definition Plot.hpp:208
std::string legendName
Display name in the legend (if not set falls back to PlotData::displayName)
Definition Plot.hpp:186
ImVec4 eventMarkerOutlineColor
Outline/Border color for markers.
Definition Plot.hpp:233
LineType
Possible line types.
Definition Plot.hpp:180
float markerSize
Size of the markers (makes the marker smaller/bigger)
Definition Plot.hpp:214
std::optional< ImPlotLineFlags > lineFlags
Line Flags (overrides the plot selection)
Definition Plot.hpp:200
std::pair< ColormapMaskType, int64_t > colormapMask
Colormap mask (pair: type and id)
Definition Plot.hpp:194
ImVec4 markerOutlineColor
Outline/Border color for markers.
Definition Plot.hpp:220
std::string eventTooltipFilterRegex
Tooltip search regex.
Definition Plot.hpp:235
ImVec4 markerFillColor
Fill color for markers.
Definition Plot.hpp:218
int stride
Amount of points to skip for plotting.
Definition Plot.hpp:203
LineType lineType
Line type.
Definition Plot.hpp:190
ImPlotMarker markerStyle
Style of the marker to display.
Definition Plot.hpp:212
ImVec4 eventMarkerFillColor
Fill color for markers.
Definition Plot.hpp:231
std::string legendNameGui
Legend name which gets changed in the gui.
Definition Plot.hpp:188
bool eventsEnabled
Show events on this data.
Definition Plot.hpp:223
float thickness
Line thickness.
Definition Plot.hpp:198
size_t colormapMaskDataCmpIdx
Index of the plot data to compare for the color.
Definition Plot.hpp:196
float markerWeight
Weight of the markers (increases thickness of marker lines)
Definition Plot.hpp:216
ImPlotMarker eventMarkerStyle
Style of the marker to display.
Definition Plot.hpp:225
bool markers
Display markers for the line plot (no effect for scatter type)
Definition Plot.hpp:210
float eventMarkerSize
Size of the markers (makes the marker smaller/bigger)
Definition Plot.hpp:227
Tooltip info.
Definition Plot.hpp:290
InsTime time
Time of the event.
Definition Plot.hpp:291
std::vector< std::string > texts
List of event texts.
Definition Plot.hpp:292
Info needed to draw a data set.
Definition Plot.hpp:174
std::string displayName
Display name of the data (not changing and unique)
Definition Plot.hpp:273
ScrollingBuffer< ImU32 > markerColormapMaskColors
Buffer for the colormap mask.
Definition Plot.hpp:281
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:271
ScrollingBuffer< double > eventMarker
Buffer for event markers.
Definition Plot.hpp:286
PlotItem(size_t pinIndex, size_t dataIndex, std::string displayName, ImAxis axis)
Constructor.
Definition Plot.hpp:257
ScrollingBuffer< ImU32 > colormapMaskColors
Buffer for the colormap mask.
Definition Plot.hpp:277
size_t colormapMaskVersion
Colormap version (to track updates of the colormap)
Definition Plot.hpp:279
size_t dataIndex
Index of the data on the pin.
Definition Plot.hpp:272
constexpr bool operator==(const PlotItem &rhs) const
Equal comparison operator (needed to search the vector with std::find)
Definition Plot.hpp:266
std::vector< std::tuple< double, double, Tooltip > > eventTooltips
List of tooltips (x,y, tooltip)
Definition Plot.hpp:295
size_t markerColormapMaskVersion
Colormap version (to track updates of the colormap)
Definition Plot.hpp:283
Style style
Definition Plot.hpp:275
PlotItem(size_t pinIndex, size_t dataIndex, std::string displayName)
Constructor.
Definition Plot.hpp:245
ImAxis axis
Axis to plot the data on (Y1, Y2, Y3)
Definition Plot.hpp:274
Information specifying the look of each plot.
Definition Plot.hpp:171
ImVec2 size
Size of the plot.
Definition Plot.hpp:308
bool visible
Flag whether the whole plot is visible. If not, then it should be deleted.
Definition Plot.hpp:351
std::string y2AxisLabel
Y2 axis label.
Definition Plot.hpp:321
std::string headerText
Title of the CollapsingHeader.
Definition Plot.hpp:313
std::array< ImPlotScale, 3 > yAxesScale
Scale for the y-Axes.
Definition Plot.hpp:335
ImPlotLineFlags lineFlags
Line Flags for all items (each item can override the selection)
Definition Plot.hpp:337
ImPlotAxisFlags xAxisFlags
Flags for the x-Axis.
Definition Plot.hpp:329
float leftPaneWidth
Width of plot Data content.
Definition Plot.hpp:346
int plotFlags
Flags which are passed to the plot.
Definition Plot.hpp:327
bool overrideXAxisLabel
Flag, whether to override the x axis label.
Definition Plot.hpp:315
std::string xAxisLabel
X axis label.
Definition Plot.hpp:317
size_t selectedPin
Selected pin in the GUI for the Drag & Drop Data.
Definition Plot.hpp:325
ImPlotScale xAxisScale
Scale for the x-Axis.
Definition Plot.hpp:333
PlotInfo(const std::string &title, size_t nInputPins)
Constructor.
Definition Plot.hpp:304
PlotInfo()=default
Default constructor.
float rightPaneWidth
Width of the plot.
Definition Plot.hpp:348
std::vector< PlotItem > plotItems
List containing all elements which should be plotted.
Definition Plot.hpp:343
std::vector< size_t > selectedXdata
Key: PinIndex, Value: plotData to use for x-Axis.
Definition Plot.hpp:340
std::string title
Title of the ImPlot.
Definition Plot.hpp:311
std::string y1AxisLabel
Y1 axis label.
Definition Plot.hpp:319
ImPlotAxisFlags yAxisFlags
Flags for the y-Axes.
Definition Plot.hpp:331
std::string y3AxisLabel
Y3 axis label.
Definition Plot.hpp:323