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
impl::Abscissa< GetT > X(AxisConfiguration config, GetT get_fn)
Definition: Abscissa.h:75
Type
Definition: types.h:31
Definition: Contact.h:88
Definition: MessagePackBuilder.h:87
void start_array(size_t size)
Range range
Definition: types.h:108
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: types.h:133
Definition: types.h:80
double min
Definition: types.h:82
double max
Definition: types.h:83
Definition: Abscissa.h:26
Abscissa & max(double max)
Definition: Abscissa.h:59
void update() const
Definition: Abscissa.h:45
Abscissa(AxisConfiguration config, GetT get_fn)
Definition: Abscissa.h:29
static constexpr Type type
Definition: Abscissa.h:27
Abscissa & range(const Range &range)
Definition: Abscissa.h:47
Abscissa & min(double min)
Definition: Abscissa.h:53
void write(mc_rtc::MessagePackBuilder &builder) const
Definition: Abscissa.h:36