mc_rtc  2.16.0
types.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <mc_rtc/gui/types.h>
8 
9 #include <limits>
10 
11 namespace mc_rtc
12 {
13 
14 namespace gui
15 {
16 
17 namespace plot
18 {
19 
21 enum class Plot
22 {
24  Standard = 0,
26  XY
27 };
28 
30 enum class Type
31 {
33  Abscissa,
35  Ordinate,
37  Polygon,
39  Polygons,
42 };
43 
44 template<typename T>
45 constexpr bool is_Abscissa()
46 { return T::type == Type::Abscissa; }
47 
48 template<bool = true>
49 constexpr bool is_not_Abscissa()
50 { return true; }
51 
52 template<typename T, typename... Args>
53 constexpr bool is_not_Abscissa()
54 { return (T::type != Type::Abscissa) && is_not_Abscissa<Args...>(); }
55 
56 template<bool = true>
57 constexpr bool is_2d()
58 { return true; }
59 
60 template<typename T, typename... Args>
61 constexpr bool is_2d()
62 { return T::type != Type::Abscissa && T::type != Type::Ordinate && is_2d<Args...>(); }
63 
70 {
71  static constexpr double inf = std::numeric_limits<double>::infinity();
72  double min = -inf;
73  double max = inf;
74 
75  Range() = default;
76  Range(double min, double max) : min(min), max(max) {}
77 
79  {
80  std::array<double, 2> data = config;
81  min = data[0];
82  max = data[1];
83  }
84 
85  void write(mc_rtc::MessagePackBuilder & builder) const
86  {
87  builder.start_array(2);
88  builder.write(min);
89  builder.write(max);
90  builder.finish_array();
91  }
92 };
93 
96 {
97  std::string name;
99 
100  AxisConfiguration() = default;
101  AxisConfiguration(std::string_view name) : AxisConfiguration(name, {}) {}
103  AxisConfiguration(std::string_view name, Range range) : name(name), range(range) {}
104 
105  AxisConfiguration & min(double min)
106  {
107  range.min = min;
108  return *this;
109  }
110 
111  AxisConfiguration & max(double max)
112  {
113  range.max = max;
114  return *this;
115  }
116 
118  {
119  name = static_cast<std::string>(config[0]);
120  range.fromMessagePack(config[1]);
121  }
122 
123  void write(mc_rtc::MessagePackBuilder & builder) const
124  {
125  builder.start_array(2);
126  builder.write(name);
127  range.write(builder);
128  builder.finish_array();
129  }
130 };
131 
133 enum class MC_RTC_GUI_DLLAPI Style
134 {
142  Point
143 };
144 
146 enum class MC_RTC_GUI_DLLAPI Side
147 {
149  Right
150 };
151 
154 {
156 
157  PolygonDescription(const std::vector<std::array<double, 2>> & points, Color outline)
158  : points_(points), outline_(outline)
159  {
160  }
161 
162  bool operator==(const PolygonDescription & rhs) const
163  {
164  return points_ == rhs.points_ && outline_ == rhs.outline_ && style_ == rhs.style_ && fill_ == rhs.fill_
165  && closed_ == rhs.closed_;
166  };
167 
168  bool operator!=(const PolygonDescription & rhs) const { return !(*this == rhs); }
169 
170  // clang-format off
171  std::vector<std::array<double, 2>> & points() { return points_; }
172  Color & outline() { return outline_; };
173  Style & style() { return style_; };
174  Color & fill() { return fill_; };
175  bool closed() { return closed_; };
176 
177  const std::vector<std::array<double, 2>> & points() const { return points_; }
178  const Color & outline() const { return outline_; };
179  const Style & style() const { return style_; };
180  const Color & fill() const { return fill_; };
181  bool closed() const { return closed_; };
182 
183  PolygonDescription & outline(const Color & outline) { outline_ = outline; return *this; };
184  PolygonDescription & style(const Style & style) { style_ = style; return *this; };
185  PolygonDescription & fill(const Color & fill) { fill_ = fill; return *this; };
186  PolygonDescription & closed(bool closed) { closed_ = closed; return *this; };
187  // clang-format on
188 
190  {
191  points_ = data[0];
192  outline_.fromMessagePack(data[1]);
193  style_ = static_cast<Style>(static_cast<uint64_t>(data[2]));
194  fill_.fromMessagePack(data[3]);
195  closed_ = data[4];
196  }
197 
198  void write(mc_rtc::MessagePackBuilder & builder) const
199  {
200  builder.start_array(5);
201  builder.write(points_);
202  outline_.write(builder);
203  builder.write(static_cast<uint64_t>(style_));
204  fill_.write(builder);
205  builder.write(closed_);
206  builder.finish_array();
207  }
208 
209 private:
211  std::vector<std::array<double, 2>> points_;
213  Color outline_;
215  Style style_ = Style::Solid;
217  Color fill_ = Color(0, 0, 0, 0);
219  bool closed_ = true;
220 };
221 
222 } // namespace plot
223 
224 } // namespace gui
225 
226 } // namespace mc_rtc
#define MC_RTC_GUI_DLLAPI
Definition: api.h:50
constexpr bool is_2d()
Definition: types.h:57
Type
Definition: types.h:31
constexpr bool is_Abscissa()
Definition: types.h:45
constexpr bool is_not_Abscissa()
Definition: types.h:49
Plot
Definition: types.h:22
Definition: Contact.h:88
Eigen::Matrix< Numeric, Eigen::Dynamic, 1 > Point
Dashed
Definition: types.h:140
Left
Definition: types.h:148
Solid
Definition: types.h:136
Dotted
Definition: types.h:138
Simplify access to values hold within a JSON file.
Definition: Configuration.h:166
static Configuration fromMessagePack(const char *data, size_t size)
Static constructor to load from MessagePack data.
Definition: MessagePackBuilder.h:87
void start_array(size_t size)
Definition: types.h:20
Range range
Definition: types.h:98
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: types.h:123
AxisConfiguration & max(double max)
Definition: types.h:111
std::string name
Definition: types.h:97
AxisConfiguration(std::string_view name)
Definition: types.h:101
AxisConfiguration(Range range)
Definition: types.h:102
AxisConfiguration(std::string_view name, Range range)
Definition: types.h:103
void fromMessagePack(const mc_rtc::Configuration &config)
Definition: types.h:117
AxisConfiguration & min(double min)
Definition: types.h:105
Style & style()
Definition: types.h:173
Color & outline()
Definition: types.h:172
const Color & fill() const
Definition: types.h:180
void fromMessagePack(const mc_rtc::Configuration &data)
Definition: types.h:189
PolygonDescription(const std::vector< std::array< double, 2 >> &points, Color outline)
Definition: types.h:157
PolygonDescription & fill(const Color &fill)
Definition: types.h:185
const Style & style() const
Definition: types.h:179
PolygonDescription()
Definition: types.h:155
bool closed() const
Definition: types.h:181
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: types.h:198
bool operator!=(const PolygonDescription &rhs) const
Definition: types.h:168
bool operator==(const PolygonDescription &rhs) const
Definition: types.h:162
PolygonDescription & outline(const Color &outline)
Definition: types.h:183
bool closed()
Definition: types.h:175
std::vector< std::array< double, 2 > > & points()
Definition: types.h:171
const std::vector< std::array< double, 2 > > & points() const
Definition: types.h:177
PolygonDescription & style(const Style &style)
Definition: types.h:184
PolygonDescription & closed(bool closed)
Definition: types.h:186
Color & fill()
Definition: types.h:174
const Color & outline() const
Definition: types.h:178
Definition: types.h:70
double min
Definition: types.h:72
double max
Definition: types.h:73
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: types.h:85
Range(double min, double max)
Definition: types.h:76
void fromMessagePack(const mc_rtc::Configuration &config)
Definition: types.h:78