Libpointing
An open-source cross-platform library to get raw events from pointing devices and master transfer functions.
Interpolation.h
1 /* -*- mode: c++ -*-
2  *
3  * pointing/transferfunctions/Interpolation.h --
4  *
5  * Initial software
6  * Authors: Izzat Mukhanov
7  * Copyright © Inria
8  *
9  * http://libpointing.org/
10  *
11  * This software may be used and distributed according to the terms of
12  * the GNU General Public License version 2 or any later version.
13  *
14  */
15 
16 #ifndef INTERPOLATION_H
17 #define INTERPOLATION_H
18 
19 #include <pointing/transferfunctions/TransferFunction.h>
20 #include <map>
21 #include <string>
22 #include <vector>
23 #include <pointing/utils/ConfigDict.h>
24 
25 namespace pointing
26 {
27  enum class InterpolationSpace { VelocityGain, VelocityVelocity };
28 
35  {
36  void constructAccMap();
37  void loadTableFromConfig(ConfigDict &accCfg);
38  void loadFromDirectory();
39 
40  protected:
41 
42  PointingDevice *pointingDevice;
43  DisplayDevice *displayDevice;
44  PointingDevice *originalInput = nullptr;
45  DisplayDevice *originalOutput = nullptr;
46 
47  InterpolationSpace space = InterpolationSpace::VelocityGain;
48 
49  bool normalize = false;
50  std::string directory;
51  std::string curAcc;
52 
53  int previousMouseRawX;
54  int previousMouseRawY;
55  float previousMouseXRemainder;
56  float previousMouseYRemainder;
57 
64  void Interpolate(std::vector<int> &lowInd, std::vector<int> &highInd);
65 
66  // Divide in order to have a coefficient, not the mapping
67  // It means not dpx = tableAcc[dp]
68  // But dpx = tableAcc[dp] * dp
69  void TableToCoefficients();
70 
71  ConfigDict cfg;
72 
73  std::string system; // System name and version
74  std::map<std::string, std::string> mapAcc;
75  std::string replaceAlias(std::string &curAcc);
76 
77  std::vector<float> tableAcc;
78  float valueFromTable(unsigned index);
79 
85  double valueFromTable(double index);
86 
87  public:
88 
89  Interpolation(URI &uri, PointingDevice *input, DisplayDevice *output);
90  ~Interpolation();
91 
92  void loadTableStr(std::string tableData);
93 
94  void clearState(void);
95 
96  void applyi(int dxMickey, int dyMickey, int *dxPixel, int *dyPixel,
97  TimeStamp::inttime timestamp=TimeStamp::undef);
98 
99  void applyd(int dxMickey, int dyMickey, double *dxPixel, double *dyPixel,
100  TimeStamp::inttime timestamp=TimeStamp::undef);
101 
102  URI getURI(bool expanded=false) const;
103  };
104 }
105 
106 #endif // INTERPOLATION_H
void clearState(void)
Method which clears the current state of the device to be the default one (without any remainders or ...
Definition: Interpolation.cpp:204
void applyi(int dxMickey, int dyMickey, int *dxPixel, int *dyPixel, TimeStamp::inttime timestamp=TimeStamp::undef)
apply The main method of the class which applies the transfer function.
Definition: Interpolation.cpp:237
The TransferFunction class is an abstract class that creates an object of its concrete subclasses...
Definition: TransferFunction.h:38
Definition: DummyPointingDevice.cpp:23
The PointingDevice class is used to represent Pointing Devices connected to the computer or pseudo-de...
Definition: PointingDevice.h:35
void Interpolate(std::vector< int > &lowInd, std::vector< int > &highInd)
Interpolate Values that do not exist in the main table are interpolated using 2 other tables which re...
Definition: Interpolation.cpp:52
DisplayDevice class is used to represent the displays connected to the computer.
Definition: DisplayDevice.h:31
URI getURI(bool expanded=false) const
getURI The method constructs URI corresponding to the type and parameters of the transfer function...
Definition: Interpolation.cpp:297
void applyd(int dxMickey, int dyMickey, double *dxPixel, double *dyPixel, TimeStamp::inttime timestamp=TimeStamp::undef)
apply The main method of the class which applies the transfer function.
Definition: Interpolation.cpp:274
The Interpolation class is subclass of TransferFunction which can interpolate between given values in...
Definition: Interpolation.h:34