Abscissa.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 
24 template<typename GetT>
25 struct Abscissa
26 {
27  static constexpr Type type = Type::Abscissa;
28 
29  Abscissa(AxisConfiguration config, GetT get_fn) : config_(config), get_fn_(get_fn)
30  {
32  "Abscissa should return a single floating-point value");
33  cache_.reserve(16);
34  }
35 
36  void write(mc_rtc::MessagePackBuilder & builder) const
37  {
38  builder.start_array(2);
39  config_.write(builder);
40  builder.write(cache_);
41  builder.finish_array();
42  cache_.resize(0);
43  }
44 
45  void update() const { cache_.push_back(get_fn_()); }
46 
48  {
49  config_.range = range;
50  return *this;
51  }
52 
53  Abscissa & min(double min)
54  {
55  config_.range.min = min;
56  return *this;
57  }
58 
59  Abscissa & max(double max)
60  {
61  config_.range.max = max;
62  return *this;
63  }
64 
65 private:
66  AxisConfiguration config_;
67  GetT get_fn_;
68  mutable std::vector<double> cache_;
69 };
70 
71 } // namespace impl
72 
74 template<typename GetT>
76 {
77  return impl::Abscissa<GetT>(config, get_fn);
78 }
79 
81 template<typename GetT>
82 impl::Abscissa<GetT> X(std::string_view legend, GetT get_fn)
83 {
84  return impl::Abscissa<GetT>(AxisConfiguration(legend), get_fn);
85 }
86 
87 } // namespace plot
88 
89 } // namespace gui
90 
91 } // namespace mc_rtc
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
mc_rtc::gui::plot::impl::Abscissa::type
static constexpr Type type
Definition: Abscissa.h:27
types.h
mc_rtc::gui::plot::impl::Abscissa::write
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: Abscissa.h:36
mc_rtc::MessagePackBuilder::finish_array
void finish_array()
mc_rtc::gui::plot::impl::Abscissa
Definition: Abscissa.h:25
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::X
impl::Abscissa< GetT > X(AxisConfiguration config, GetT get_fn)
Definition: Abscissa.h:75
mc_rtc::gui::plot::AxisConfiguration
Definition: types.h:105
mc_rtc::MessagePackBuilder::start_array
void start_array(size_t size)
mc_rtc::gui::plot::Range::max
double max
Definition: types.h:83
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::plot::impl::Abscissa::min
Abscissa & min(double min)
Definition: Abscissa.h:53
mc_rtc::gui::plot::impl::Abscissa::max
Abscissa & max(double max)
Definition: Abscissa.h:59
mc_rtc::gui::plot::impl::Abscissa::Abscissa
Abscissa(AxisConfiguration config, GetT get_fn)
Definition: Abscissa.h:29
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::impl::Abscissa::update
void update() const
Definition: Abscissa.h:45
mc_rtc::gui::plot::Type
Type
Definition: types.h:30
traits.h
mc_rtc::gui::details::CheckReturnType
Definition: traits.h:86
mc_rtc::gui::plot::impl::Abscissa::range
Abscissa & range(const Range &range)
Definition: Abscissa.h:47
mc_rtc
Definition: Contact.h:87
mc_rtc::gui::plot::Type::Abscissa
@ Abscissa