transform_function.h
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5  */
6 
7 #ifndef PJ_TRANSFORM_FUNCTION_H
8 #define PJ_TRANSFORM_FUNCTION_H
9 
10 #include <QApplication>
11 #include <set>
12 #include <functional>
13 #include "PlotJuggler/plotdata.h"
14 #include "PlotJuggler/pj_plugin.h"
15 
16 namespace PJ
17 {
23 {
24  Q_OBJECT
25 
26 public:
27  using Ptr = std::shared_ptr<TransformFunction>;
28 
30 
31  virtual ~TransformFunction() = default;
32 
33  virtual const char* name() const = 0;
34 
45  virtual int numInputs() const = 0;
46 
50  virtual int numOutputs() const = 0;
51 
53  virtual void reset()
54  {
55  }
56 
58  {
59  return _data;
60  }
61 
62  std::vector<const PlotData*>& dataSources();
63 
64  virtual void setData(PlotDataMapRef* data, const std::vector<const PlotData*>& src_vect,
65  std::vector<PlotData*>& dst_vect);
66 
67  virtual void calculate() = 0;
68 
69  unsigned order() const
70  {
71  return _order;
72  }
73 
74 signals:
75  void parametersChanged();
76 
77 protected:
78  std::vector<const PlotData*> _src_vector;
79  std::vector<PlotData*> _dst_vector;
81 
82  unsigned _order;
83 };
84 
85 using TransformsMap = std::unordered_map<std::string, std::shared_ptr<TransformFunction>>;
86 
89 {
90  Q_OBJECT
91 public:
92  TransformFunction_SISO() = default;
93 
94  void reset() override;
95 
96  int numInputs() const override
97  {
98  return 1;
99  }
100 
101  int numOutputs() const override
102  {
103  return 1;
104  }
105 
106  void calculate() override;
107 
110  virtual std::optional<PlotData::Point> calculateNextPoint(size_t index) = 0;
111 
112  const PlotData* dataSource() const;
113 
114 protected:
115  double _last_timestamp = std::numeric_limits<double>::lowest();
116 };
117 
119 
120 class TransformFactory : public QObject
121 {
122 public:
124  {
125  }
126 
127 private:
128  TransformFactory(const TransformFactory&) = delete;
129  TransformFactory& operator=(const TransformFactory&) = delete;
130 
131  std::map<std::string, std::function<TransformFunction::Ptr()>> creators_;
132  std::set<std::string> names_;
133 
134  static TransformFactory* instance();
135 
136 public:
137  static const std::set<std::string>& registeredTransforms();
138 
139  template <typename T>
140  static void registerTransform()
141  {
142  T temp;
143  std::string name = temp.name();
144  instance()->names_.insert(name);
145  instance()->creators_[name] = []() { return std::make_shared<T>(); };
146  }
147 
148  static TransformFunction::Ptr create(const std::string& name);
149 };
150 
151 } // namespace PJ
152 
153 Q_DECLARE_OPAQUE_POINTER(PJ::TransformFactory*)
155 Q_GLOBAL_STATIC(PJ::TransformFactory, _transform_factory_ptr_from_macro)
156 
157 QT_BEGIN_NAMESPACE
158 
159 #define TransformFunction_iid "facontidavide.PlotJuggler3.TransformFunction"
160 Q_DECLARE_INTERFACE(PJ::TransformFunction, TransformFunction_iid)
161 
162 #define TransformFunctionSISO_iid "facontidavide.PlotJuggler3.TransformFunctionSISO"
164 
165 QT_END_NAMESPACE
166 
167 #endif
std::vector< const PlotData * > & dataSources()
Simplified version with Single input and Single output.
unsigned order() const
Generic interface for a multi input - multi output transformation function. Contrariwise to other plu...
virtual ~TransformFunction()=default
std::unordered_map< std::string, std::shared_ptr< TransformFunction > > TransformsMap
virtual int numOutputs() const =0
#define TransformFunctionSISO_iid
int numOutputs() const override
virtual void calculate()=0
---— The factory to create instances of a SeriesTransform ----------—
std::vector< const PlotData * > _src_vector
#define TransformFunction_iid
PlotDataMapRef * _data
virtual void setData(PlotDataMapRef *data, const std::vector< const PlotData *> &src_vect, std::vector< PlotData *> &dst_vect)
virtual const char * name() const =0
Name of the plugin type, NOT the particular instance.
std::set< std::string > names_
static void registerTransform()
int numInputs() const override
std::vector< PlotData * > _dst_vector
Q_DECLARE_METATYPE(QwtPoint3D)
const new_table create
Definition: sol.hpp:7807
PlotDataMapRef * plotData()
std::map< std::string, std::function< TransformFunction::Ptr()> > creators_
Definition: format.h:895
virtual int numInputs() const =0
std::shared_ptr< TransformFunction > Ptr
The PlotJugglerPlugin is the base class of all the plugins.
Definition: pj_plugin.h:22


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:12:53