Polygons.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 
9 
10 namespace mc_rtc
11 {
12 
13 namespace gui
14 {
15 
16 namespace plot
17 {
18 
19 namespace impl
20 {
21 
23 template<typename GetT>
24 struct Polygons
25 {
26  static constexpr Type type = Type::Polygons;
27 
28  Polygons(const std::string & name, GetT get_fn, Side side) : name_(name), get_fn_(get_fn), side_(side)
29  {
30  static_assert(details::CheckReturnType<GetT, std::vector<PolygonDescription>>::value,
31  "Polygons element callback must return a vector of PolygonDescription");
32  }
33 
34  void write(mc_rtc::MessagePackBuilder & builder) const
35  {
36  builder.start_array(4);
37  builder.write(static_cast<uint64_t>(type));
38  builder.write(name_);
39  const auto & polygons = get_fn_();
40  builder.start_array(polygons.size());
41  for(const auto & poly : polygons) { poly.write(builder); }
42  builder.finish_array();
43  builder.write(static_cast<uint64_t>(side_));
44  builder.finish_array();
45  }
46 
47  void update() const {}
48 
49  Polygons & side(Side side)
50  {
51  side_ = side;
52  return *this;
53  }
54 
55 private:
56  std::string name_;
57  GetT get_fn_;
58  Side side_;
59 };
60 
61 } // namespace impl
62 
64 template<typename GetT>
65 impl::Polygons<GetT> Polygons(const std::string & name, GetT get_fn, Side side = Side::Left)
66 {
67  return impl::Polygons<GetT>(name, get_fn, side);
68 }
69 
70 } // namespace plot
71 
72 } // namespace gui
73 
74 } // namespace mc_rtc
mc_rtc::gui::plot::impl::Polygons::Polygons
Polygons(const std::string &name, GetT get_fn, Side side)
Definition: Polygons.h:28
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
types.h
mc_rtc::MessagePackBuilder::finish_array
void finish_array()
mc_rtc::gui::plot::impl::Polygons::write
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: Polygons.h:34
mc_rtc::gui::plot::impl::Polygons::update
void update() const
Definition: Polygons.h:47
mc_rtc::gui::plot::impl::Polygons::type
static constexpr Type type
Definition: Polygons.h:26
mc_rtc::MessagePackBuilder::start_array
void start_array(size_t size)
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::plot::Type::Polygons
@ Polygons
mc_rtc::gui::plot::impl::Polygons::side
Polygons & side(Side side)
Definition: Polygons.h:49
mc_rtc::gui::plot::Polygons
impl::Polygons< GetT > Polygons(const std::string &name, GetT get_fn, Side side=Side::Left)
Definition: Polygons.h:65
mc_rtc::gui::plot::Type
Type
Definition: types.h:30
mc_rtc::gui::plot::impl::Polygons
Definition: Polygons.h:24
traits.h
mc_rtc::gui::details::CheckReturnType
Definition: traits.h:86
Left
Left
Definition: types.h:158
mc_rtc
Definition: Contact.h:87