-
Notifications
You must be signed in to change notification settings - Fork 2
/
transformation.h
130 lines (107 loc) · 3.38 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
/*
* stair-step-detector
* Copyright (c) 2021 Peter Nebe (mail@peter-nebe.dev)
*
* This file is part of stair-step-detector.
*
* stair-step-detector 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.
*
* stair-step-detector 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 stair-step-detector. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef TRANSFORMATION_H_
#define TRANSFORMATION_H_
#include "types.h" // Coordinate_t, Point_
#include "boost/qvm/mat.hpp"
#include "boost/qvm/mat_operations.hpp"
#include "boost/qvm/vec_mat_operations.hpp"
#include "boost/qvm/vec_operations.hpp"
namespace stairs
{
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_()
: _a(boost::qvm::identity_mat<Coordinate_t, Dim>()),
_aInv(_a)
{
}
Transformation_(const RefPoints &rp, const RefPoints &rpMapping);
Transformation_(const RefPoints &triangleInPlane);
template<typename SrcPointType>
Point transform(const SrcPointType &x) const
{
using boost::qvm::operator+;
return _a * x + _b;
}
Point transformInv(const Point &x) const
{
return _aInv * (x - _b);
}
private:
Mat _a, _aInv;
Vec _b;
}; // class Transformation_
using Transformation = Transformation_<3>;
using Transformation2D = Transformation_<2>;
struct CameraToWorld
{
template<typename SrcPointType>
Point3 operator()(const SrcPointType &p) const
{
return _camera.transform(p);
}
const Transformation &_camera;
};
struct WorldToCamera
{
Point3 operator()(const Point3 &p) const;
const Transformation &_camera;
};
struct ToExternalWorld
{
Point3 operator()(const Point3 &p) const;
const Transformation2D _world;
const Coordinate_t _worldZ = 0;
};
class GeometricTransformation
{
public:
using RefPoints = Transformation::RefPoints;
GeometricTransformation(){}
GeometricTransformation(const RefPoints &worldPoints, const RefPoints &cameraPoints);
const CameraToWorld &cameraToWorld() const { return _cameraToWorld; }
const WorldToCamera &worldToCamera() const { return _worldToCamera; }
const ToExternalWorld &toExternalWorld() const { return _toExternalWorld; }
private:
GeometricTransformation(const GeometricTransformation&) = delete;
// transformation between camera coordinates and camera-dependent world coordinates
const Transformation _camera;
const CameraToWorld _cameraToWorld{ _camera };
const WorldToCamera _worldToCamera{ _camera };
// transformation into external world coordinates
const ToExternalWorld _toExternalWorld;
// only for debugging and testing
const Transformation _affinity;
}; // class GeometricTransformation
} // namespace stairs
#endif // TRANSFORMATION_H_