Polygon.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 
8 #include <mc_rtc/gui/elements.h>
9 #include <mc_rtc/gui/types.h>
10 
11 namespace mc_rtc::gui
12 {
13 
14 namespace details
15 {
16 
25 template<typename GetT>
26 struct PolygonImpl : public DataElement<GetT>
27 {
28  static constexpr auto type = Elements::Polygon;
29 
30  PolygonImpl(const std::string & name, const LineConfig & config, GetT get_fn)
31  : DataElement<GetT>(name, get_fn), config_(config)
32  {
33  static_assert(
34  details::CheckReturnType<GetT, std::vector<Eigen::Vector3d>, std::vector<std::vector<Eigen::Vector3d>>>::value,
35  "Polygon element data callback must return either an std::vector of Eigen::Vector3d or an std::vector of "
36  "std::vector3d of Eigen::Vector3d");
37  }
38 
41 
42  static constexpr size_t write_size() { return DataElement<GetT>::write_size() + Color::write_size(); }
43 
45  {
46  DataElement<GetT>::write(builder);
47  config_.write(builder);
48  }
49 
50 private:
51  LineConfig config_;
52 };
53 
54 } // namespace details
55 
57 template<typename GetT>
58 auto Polygon(const std::string & name, GetT get_fn)
59 {
60  return details::PolygonImpl(name, {}, get_fn);
61 }
62 
64 template<typename GetT>
65 auto Polygon(const std::string & name, const Color & color, GetT get_fn)
66 {
67  return details::PolygonImpl(name, color, get_fn);
68 }
69 
71 template<typename GetT>
72 auto Polygon(const std::string & name, const LineConfig & config, GetT get_fn)
73 {
74  return details::PolygonImpl(name, config, get_fn);
75 }
76 
77 } // namespace mc_rtc::gui
Definition: Observer.h:16
auto Polygon(const std::string &name, GetT get_fn)
Definition: Polygon.h:58
Definition: MessagePackBuilder.h:87
Definition: types.h:20
static constexpr size_t write_size()
Definition: types.h:88
Definition: elements.h:105
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
static constexpr size_t write_size()
Definition: elements.h:106
const std::string & name() const
Definition: elements.h:61
Definition: types.h:136
void write(mc_rtc::MessagePackBuilder &out) const
Definition: types.h:179
Definition: Polygon.h:27
static constexpr size_t write_size()
Definition: Polygon.h:42
void write(mc_rtc::MessagePackBuilder &builder)
Definition: Polygon.h:44
static constexpr auto type
Definition: Polygon.h:28
PolygonImpl(const std::string &name, const LineConfig &config, GetT get_fn)
Definition: Polygon.h:30
PolygonImpl()
Definition: Polygon.h:40