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
mc_rtc::gui::DataElement::write_size
static constexpr size_t write_size()
Definition: elements.h:106
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
types.h
mc_rtc::gui::Elements::Polygon
@ Polygon
mc_rtc::gui::LineConfig
Definition: types.h:135
mc_rtc::gui::LineConfig::write
void write(mc_rtc::MessagePackBuilder &out) const
Definition: types.h:179
elements.h
mc_rtc::gui::details::PolygonImpl::PolygonImpl
PolygonImpl(const std::string &name, const LineConfig &config, GetT get_fn)
Definition: Polygon.h:30
mc_rtc::gui::Polygon
auto Polygon(const std::string &name, GetT get_fn)
Definition: Polygon.h:58
mc_rtc::gui::Color::write_size
static constexpr size_t write_size()
Definition: types.h:88
mc_rtc::gui::details::PolygonImpl::type
static constexpr auto type
Definition: Polygon.h:28
mc_rtc::gui::details::PolygonImpl
Definition: Polygon.h:26
mc_rtc::gui::DataElement
Definition: elements.h:104
mc_rtc::gui::Color
Definition: types.h:19
mc_rtc::gui::details::PolygonImpl::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: Polygon.h:44
mc_rtc::gui::details::PolygonImpl::write_size
static constexpr size_t write_size()
Definition: Polygon.h:42
mc_rtc::gui::details::PolygonImpl::PolygonImpl
PolygonImpl()
Definition: Polygon.h:40
mc_rtc::gui::DataElement::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
traits.h
mc_rtc::gui::details::CheckReturnType
Definition: traits.h:86
mc_rtc::gui
Definition: Observer.h:15
mc_rtc::gui::Element::name
const std::string & name() const
Definition: elements.h:61