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 {
47  return T::type == Type::Abscissa;
48 }
49 
50 template<bool = true>
51 constexpr bool is_not_Abscissa()
52 {
53  return true;
54 }
55 
56 template<typename T, typename... Args>
57 constexpr bool is_not_Abscissa()
58 {
59  return (T::type != Type::Abscissa) && is_not_Abscissa<Args...>();
60 }
61 
62 template<bool = true>
63 constexpr bool is_2d()
64 {
65  return true;
66 }
67 
68 template<typename T, typename... Args>
69 constexpr bool is_2d()
70 {
71  return T::type != Type::Abscissa && T::type != Type::Ordinate && is_2d<Args...>();
72 }
73 
80 {
81  static constexpr double inf = std::numeric_limits<double>::infinity();
82  double min = -inf;
83  double max = inf;
84 
85  Range() = default;
86  Range(double min, double max) : min(min), max(max) {}
87 
89  {
90  std::array<double, 2> data = config;
91  min = data[0];
92  max = data[1];
93  }
94 
95  void write(mc_rtc::MessagePackBuilder & builder) const
96  {
97  builder.start_array(2);
98  builder.write(min);
99  builder.write(max);
100  builder.finish_array();
101  }
102 };
103 
106 {
107  std::string name;
109 
110  AxisConfiguration() = default;
111  AxisConfiguration(std::string_view name) : AxisConfiguration(name, {}) {}
113  AxisConfiguration(std::string_view name, Range range) : name(name), range(range) {}
114 
115  AxisConfiguration & min(double min)
116  {
117  range.min = min;
118  return *this;
119  }
120 
121  AxisConfiguration & max(double max)
122  {
123  range.max = max;
124  return *this;
125  }
126 
128  {
129  name = static_cast<std::string>(config[0]);
130  range.fromMessagePack(config[1]);
131  }
132 
133  void write(mc_rtc::MessagePackBuilder & builder) const
134  {
135  builder.start_array(2);
136  builder.write(name);
137  range.write(builder);
138  builder.finish_array();
139  }
140 };
141 
143 enum class MC_RTC_GUI_DLLAPI Style
144 {
152  Point
153 };
154 
156 enum class MC_RTC_GUI_DLLAPI Side
157 {
159  Right
160 };
161 
164 {
166 
167  PolygonDescription(const std::vector<std::array<double, 2>> & points, Color outline)
168  : points_(points), outline_(outline)
169  {
170  }
171 
172  bool operator==(const PolygonDescription & rhs) const
173  {
174  return points_ == rhs.points_ && outline_ == rhs.outline_ && style_ == rhs.style_ && fill_ == rhs.fill_
175  && closed_ == rhs.closed_;
176  };
177 
178  bool operator!=(const PolygonDescription & rhs) const { return !(*this == rhs); }
179 
180  // clang-format off
181  std::vector<std::array<double, 2>> & points() { return points_; }
182  Color & outline() { return outline_; };
183  Style & style() { return style_; };
184  Color & fill() { return fill_; };
185  bool closed() { return closed_; };
186 
187  const std::vector<std::array<double, 2>> & points() const { return points_; }
188  const Color & outline() const { return outline_; };
189  const Style & style() const { return style_; };
190  const Color & fill() const { return fill_; };
191  bool closed() const { return closed_; };
192 
193  PolygonDescription & outline(const Color & outline) { outline_ = outline; return *this; };
194  PolygonDescription & style(const Style & style) { style_ = style; return *this; };
195  PolygonDescription & fill(const Color & fill) { fill_ = fill; return *this; };
196  PolygonDescription & closed(bool closed) { closed_ = closed; return *this; };
197  // clang-format on
198 
200  {
201  points_ = data[0];
202  outline_.fromMessagePack(data[1]);
203  style_ = static_cast<Style>(static_cast<uint64_t>(data[2]));
204  fill_.fromMessagePack(data[3]);
205  closed_ = data[4];
206  }
207 
208  void write(mc_rtc::MessagePackBuilder & builder) const
209  {
210  builder.start_array(5);
211  builder.write(points_);
212  outline_.write(builder);
213  builder.write(static_cast<uint64_t>(style_));
214  fill_.write(builder);
215  builder.write(closed_);
216  builder.finish_array();
217  }
218 
219 private:
221  std::vector<std::array<double, 2>> points_;
223  Color outline_;
225  Style style_ = Style::Solid;
227  Color fill_ = Color(0, 0, 0, 0);
229  bool closed_ = true;
230 };
231 
232 } // namespace plot
233 
234 } // namespace gui
235 
236 } // namespace mc_rtc
mc_rtc::gui::plot::PolygonDescription::style
PolygonDescription & style(const Style &style)
Definition: types.h:194
mc_rtc::Configuration
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
mc_rtc::gui::plot::PolygonDescription::style
const Style & style() const
Definition: types.h:189
mc_rtc::gui::plot::Range::fromMessagePack
void fromMessagePack(const mc_rtc::Configuration &config)
Definition: types.h:88
mc_rtc::gui::plot::is_Abscissa
constexpr bool is_Abscissa()
Definition: types.h:45
mc_rtc::gui::plot::PolygonDescription::outline
Color & outline()
Definition: types.h:182
mc_rtc::gui::plot::PolygonDescription::points
const std::vector< std::array< double, 2 > > & points() const
Definition: types.h:187
mc_rtc::gui::plot::PolygonDescription::points
std::vector< std::array< double, 2 > > & points()
Definition: types.h:181
mc_rtc::gui::plot::PolygonDescription::style
Style & style()
Definition: types.h:183
types.h
mc_rtc::gui::plot::PolygonDescription::outline
const Color & outline() const
Definition: types.h:188
mc_rtc::gui::plot::PolygonDescription::operator==
bool operator==(const PolygonDescription &rhs) const
Definition: types.h:172
mc_rtc::gui::plot::PolygonDescription::PolygonDescription
PolygonDescription()
Definition: types.h:165
mc_rtc::gui::plot::Type::Ordinate
@ Ordinate
mc_rtc::gui::plot::Plot::XY
@ XY
mc_rtc::gui::plot::Plot
Plot
Definition: types.h:21
mc_rtc::gui::plot::PolygonDescription::closed
PolygonDescription & closed(bool closed)
Definition: types.h:196
mc_rtc::MessagePackBuilder::finish_array
void finish_array()
mc_rtc::gui::plot::Type::AbscissaOrdinate
@ AbscissaOrdinate
mc_rtc::gui::plot::PolygonDescription
Definition: types.h:163
mc_rtc::gui::plot::Range
Definition: types.h:79
mc_rtc::gui::plot::AxisConfiguration::range
Range range
Definition: types.h:108
mc_rtc::gui::plot::Range::write
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: types.h:95
mc_rtc::gui::plot::AxisConfiguration
Definition: types.h:105
mc_rtc::gui::plot::PolygonDescription::PolygonDescription
PolygonDescription(const std::vector< std::array< double, 2 >> &points, Color outline)
Definition: types.h:167
mc_rtc::Configuration::fromMessagePack
static Configuration fromMessagePack(const char *data, size_t size)
Static constructor to load from MessagePack data.
mc_rtc::gui::plot::AxisConfiguration::AxisConfiguration
AxisConfiguration(std::string_view name)
Definition: types.h:111
mc_rtc::gui::plot::AxisConfiguration::min
AxisConfiguration & min(double min)
Definition: types.h:115
mc_rtc::gui::plot::PolygonDescription::closed
bool closed()
Definition: types.h:185
mc_rtc::gui::plot::PolygonDescription::fromMessagePack
void fromMessagePack(const mc_rtc::Configuration &data)
Definition: types.h:199
mc_rtc::gui::plot::PolygonDescription::fill
PolygonDescription & fill(const Color &fill)
Definition: types.h:195
mc_rtc::gui::plot::AxisConfiguration::AxisConfiguration
AxisConfiguration(Range range)
Definition: types.h:112
mc_rtc::gui::plot::AxisConfiguration::fromMessagePack
void fromMessagePack(const mc_rtc::Configuration &config)
Definition: types.h:127
mc_rtc::MessagePackBuilder::start_array
void start_array(size_t size)
mc_rtc::gui::plot::is_2d
constexpr bool is_2d()
Definition: types.h:63
mc_rtc::gui::plot::Range::max
double max
Definition: types.h:83
mc_rtc::gui::plot::PolygonDescription::fill
const Color & fill() const
Definition: types.h:190
mc_rtc::gui::plot::Range::Range
Range(double min, double max)
Definition: types.h:86
mc_rtc::gui::plot::PolygonDescription::fill
Color & fill()
Definition: types.h:184
mc_rtc::gui::plot::PolygonDescription::operator!=
bool operator!=(const PolygonDescription &rhs) const
Definition: types.h:178
mc_rtc::MessagePackBuilder::write
void write()
Solid
Solid
Definition: types.h:146
mc_rtc::gui::plot::PolygonDescription::closed
bool closed() const
Definition: types.h:191
mc_rtc::gui::Color
Definition: types.h:19
mc_rtc::gui::plot::AxisConfiguration::AxisConfiguration
AxisConfiguration(std::string_view name, Range range)
Definition: types.h:113
mc_rtc::gui::plot::Range::min
double min
Definition: types.h:82
mc_rtc::gui::plot::AxisConfiguration::write
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: types.h:133
mc_rtc::gui::plot::Type::Polygons
@ Polygons
mc_rtc::gui::plot::is_not_Abscissa
constexpr bool is_not_Abscissa()
Definition: types.h:51
Dashed
Dashed
Definition: types.h:150
mc_rtc::gui::plot::Type::Polygon
@ Polygon
mc_rtc::gui::plot::PolygonDescription::write
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: types.h:208
mc_rtc::gui::plot::AxisConfiguration::name
std::string name
Definition: types.h:107
mc_rtc::gui::plot::Type
Type
Definition: types.h:30
Dotted
Dotted
Definition: types.h:148
mc_rtc::gui::plot::Plot::Standard
@ Standard
mc_rtc::gui::plot::PolygonDescription::outline
PolygonDescription & outline(const Color &outline)
Definition: types.h:193
Left
Left
Definition: types.h:158
MC_RTC_GUI_DLLAPI
#define MC_RTC_GUI_DLLAPI
Definition: api.h:50
mc_rtc
Definition: Contact.h:87
mc_rtc::gui::plot::AxisConfiguration::max
AxisConfiguration & max(double max)
Definition: types.h:121
mc_rtc::gui::plot::Type::Abscissa
@ Abscissa