-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransformation.h
145 lines (121 loc) · 3.29 KB
/
transformation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* three-point-calibration
* Copyright (c) 2020 Peter Nebe (mail@peter-nebe.dev)
*
* This file is part of three-point-calibration.
*
* three-point-calibration is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* three-point-calibration is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with three-point-calibration. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef TRANSFORMATION_H_
#define TRANSFORMATION_H_
#include "boost/qvm/mat.hpp"
#include "boost/qvm/vec_operations.hpp"
#include "boost/qvm/vec_traits_defaults.hpp"
#include "boost/qvm/deduce_vec.hpp"
#include <array>
namespace threePointCalibration
{
typedef double Coordinate_t;
template<int Dim>
struct Point_;
using Point2 = Point_<2>;
using Point3 = Point_<3>;
template<>
struct Point_<2>
{
Coordinate_t x, y;
};
template<>
struct Point_<3>
{
Coordinate_t x, y, z;
};
template<int Dim>
using Vector_ = Point_<Dim>;
template<int Dim>
using Matrix_ = boost::qvm::mat<Coordinate_t, Dim, Dim>;
template<int Dim>
using ReferencePoints_ = std::array<Point_<Dim>, Dim>;
template<int Dim>
class Transformation_
{
public:
using RefPoints = ReferencePoints_<Dim>;
using Point = Point_<Dim>;
using Mat = Matrix_<Dim>;
using Vec = Vector_<Dim>;
Transformation_(const RefPoints &rp, const RefPoints &rpMapping);
Transformation_(const RefPoints &triangleInPlane);
Point transform(const Point &x) const
{
using boost::qvm::operator+;
return _a * x + _b;
}
Point transformInv(const Point &x) const
{
using boost::qvm::operator-;
return _aInv * (x - _b);
}
Point operator()(const Point &p) const
{
return transform(p);
}
private:
Mat _a, _aInv;
Vec _b;
}; // class Transformation_
using Transformation = Transformation_<3>;
using Transformation2D = Transformation_<2>;
} // namespace threePointCalibration
namespace boost { namespace qvm
{
namespace tpc = threePointCalibration;
template<int Dim>
struct vec_traits<tpc::Point_<Dim>> : vec_traits_defaults<tpc::Point_<Dim>, tpc::Coordinate_t, Dim>
{
template<int I>
static tpc::Coordinate_t &write_element(tpc::Point_<Dim>&);
};
template<> template<>
inline tpc::Coordinate_t &vec_traits<tpc::Point2>::write_element<0>(tpc::Point2 &p)
{
return p.x;
}
template<> template<>
inline tpc::Coordinate_t &vec_traits<tpc::Point2>::write_element<1>(tpc::Point2 &p)
{
return p.y;
}
template<> template<>
inline tpc::Coordinate_t &vec_traits<tpc::Point3>::write_element<0>(tpc::Point3 &p)
{
return p.x;
}
template<> template<>
inline tpc::Coordinate_t &vec_traits<tpc::Point3>::write_element<1>(tpc::Point3 &p)
{
return p.y;
}
template<> template<>
inline tpc::Coordinate_t &vec_traits<tpc::Point3>::write_element<2>(tpc::Point3 &p)
{
return p.z;
}
template<int Dim>
struct deduce_vec2<tpc::Matrix_<Dim>, tpc::Point_<Dim>, Dim>
{
typedef tpc::Point_<Dim> type;
};
}} // namespace boost::qvm
#endif // TRANSFORMATION_H_