0.2.0
Loading...
Searching...
No Matches
Colormap.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 <imgui.h>
17#include <imgui_internal.h>
18#include <optional>
19#include <functional>
20#include <string>
21#include <vector>
22#include "util/Json.hpp"
23
24namespace NAV
25{
26
27class Colormap;
28
35bool ColormapButton(const char* label, Colormap& cmap, const ImVec2& size_arg);
36
40void to_json(json& j, const Colormap& cmap);
44void from_json(const json& j, Colormap& cmap);
45
48{
49 public:
52
56 void addColor(double value, ImColor color);
57
60 void removeColor(size_t idx);
61
66 [[nodiscard]] ImColor getColor(double value, const ImColor& defaultColor) const;
67
69 [[nodiscard]] int64_t getId() const;
70
72 [[nodiscard]] const std::vector<std::pair<double, ImColor>>& getColormap() const;
73
74 std::string name = "Colormap";
75 bool discrete = false;
76 size_t version = 0;
77
78 private:
80 int64_t id;
82 std::vector<std::pair<double, ImColor>> colormap = { { 0.0, ImColor(1.0F, 1.0F, 1.0F, 1.0F) } };
83
86 void render() const;
87
91 void render(const ImRect& bounds) const;
92
99 friend bool NAV::ColormapButton(const char* label, Colormap& cmap, const ImVec2& size_arg);
100
104 friend void to_json(json& j, const Colormap& cmap);
108 friend void from_json(const json& j, Colormap& cmap);
109};
110
112extern std::vector<Colormap> ColormapsGlobal;
114extern std::vector<Colormap> ColormapsFlow;
115
117enum class ColormapMaskType : int
118{
119 None,
120 Global,
121 Flow,
122};
123
129bool ShowColormapSelector(ColormapMaskType& type, int64_t& id, const char* label = "");
130
135std::optional<std::reference_wrapper<const Colormap>> ColormapSearch(const ColormapMaskType& type, const int64_t& id);
136
137} // namespace NAV
bool ShowColormapSelector(ColormapMaskType &type, int64_t &id, const char *label="")
Shows a combobox to select a colormap.
std::vector< Colormap > ColormapsGlobal
Global colormaps.
std::vector< Colormap > ColormapsFlow
Flow colormaps.
bool ColormapButton(const char *label, Colormap &cmap, const ImVec2 &size_arg)
Display a colormap button.
std::optional< std::reference_wrapper< const Colormap > > ColormapSearch(const ColormapMaskType &type, const int64_t &id)
Searches for the colormap in the Global and Flow colormaps.
ColormapMaskType
Type of the Colormap mask.
Definition Colormap.hpp:118
@ Global
Use the global colormap.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
@ None
None.
Definition GlobalActions.hpp:19
Defines how to save certain datatypes to json.
void from_json(const json &j, ImColor &color)
Converts the provided json object into a color.
void to_json(json &j, const ImColor &color)
Converts the provided color into a json object.
Colormap class.
Definition Colormap.hpp:48
friend void to_json(json &j, const Colormap &cmap)
Converts the provided object into a json object.
const std::vector< std::pair< double, ImColor > > & getColormap() const
Return the map.
ImColor getColor(double value, const ImColor &defaultColor) const
Gets the color for the given value.
void removeColor(size_t idx)
Remove the entry at the index (if past the last index or empty, NoOp)
bool discrete
Whether to have discrete changes of the colors or continuous.
Definition Colormap.hpp:75
std::string name
Name of the Colormap.
Definition Colormap.hpp:74
int64_t getId() const
Return the id of the colormap.
size_t version
Version, to tell nodes that the colormap was updated.
Definition Colormap.hpp:76
friend void from_json(const json &j, Colormap &cmap)
Converts the provided json object into a struct.
Colormap()
Constructor.
void addColor(double value, ImColor color)
Add a color with value.