Frame.h
Go to the documentation of this file.
1#ifndef GfxTL__FRAME_HEADER__
2#define GfxTL__FRAME_HEADER__
4#include <GfxTL/MatrixXX.h>
5#include <GfxTL/VectorXD.h>
6
7namespace GfxTL
8{
9
10 template <unsigned int DimT, class ScalarT>
11 class Frame
12 {
13 };
14
15 template <class ScalarT>
16 class Frame<2, ScalarT>
17 {
18 public:
19 typedef ScalarT ScalarType;
20
21 enum
22 {
23 Dim = 2
24 };
25
27
28 void Canonical();
29
30 template <class V>
31 void
32 FromNormal(const V& v)
33 {
34 m_hcs.FromNormal(v);
35 for (unsigned int i = 0; i < Dim; ++i)
36 {
37 m_xaxis[i] = v[i];
38 }
39 }
40
41 void ToLocal(const PointType& p, PointType* l) const;
42 void ToGlobal(const PointType& p, PointType* g) const;
43 void RotateFrame(ScalarType radians);
44
45 operator PointType*()
46 {
47 return reinterpret_cast<PointType*>(this);
48 }
49
50 operator const PointType*() const
51 {
52 return reinterpret_cast<const PointType*>(this);
53 }
54
55 private:
56 PointType m_xaxis;
58 };
59
60 template <class ScalarT>
61 void
63 {
64 for (unsigned int i = 0; i < Dim; ++i)
65 {
66 for (unsigned int j = 0; j < Dim; ++j)
67 {
68 (*this)[i][j] = 0;
69 }
70 (*this)[i][i] = 1;
71 }
72 }
73
74 template <class ScalarT>
75 void
77 {
78 for (unsigned int i = 0; i < Dim; ++i)
79 {
80 (*l)[i] = (*this)[i] * p;
81 }
82 }
83
84 template <class ScalarT>
85 void
87 {
88 *g = p[0] * (*this)[0];
89 for (unsigned int i = 1; i < Dim; ++i)
90 {
91 *g += p[i] * (*this)[i];
92 }
93 }
94
95 template <class ScalarT>
96 void
98 {
100 GfxTL::Rotation(radians, &r);
101 for (unsigned int i = 0; i < Dim; ++i)
102 {
103 (*this)[i] = r * (*this)[i];
104 }
105 }
106
107 template <class ScalarT>
108 class Frame<3, ScalarT>
109 {
110 public:
111 typedef ScalarT ScalarType;
112
113 enum
114 {
115 Dim = 3
116 };
117
119
120 void Canonical();
121
122 template <class V>
123 void
124 FromNormal(const V& v)
125 {
126 m_hcs.FromNormal(v);
127 for (unsigned int i = 0; i < Dim; ++i)
128 {
129 m_normal[i] = v[i];
130 }
131 }
132 template <class GPointT, class LPointT>
133 void ToLocal(const GPointT& p, LPointT* l) const;
134 void ToTangent(const PointType& p, GfxTL::VectorXD<Dim - 1, ScalarType>* t) const;
135 ScalarType Height(const PointType& p) const;
136 template <class LPointT, class GPointT>
137 void ToGlobal(const LPointT& p, GPointT* g) const;
138 void RotateOnNormal(ScalarType radians);
139
140 operator PointType*()
141 {
142 return reinterpret_cast<PointType*>(this);
143 }
144
145 operator const PointType*() const
146 {
147 return reinterpret_cast<const PointType*>(this);
148 }
149
150 private:
152 PointType m_normal;
153 };
154
155 template <class ScalarT>
156 void
158 {
159 for (unsigned int i = 0; i < Dim; ++i)
160 {
161 for (unsigned int j = 0; j < Dim; ++j)
162 {
163 (*this)[i][j] = 0;
164 }
165 (*this)[i][i] = 1;
166 }
167 }
168
169 template <class ScalarT>
170 template <class GPointT, class LPointT>
171 void
172 Frame<3, ScalarT>::ToLocal(const GPointT& p, LPointT* l) const
173 {
174 if (&p != l)
175 {
176 for (unsigned int i = 0; i < Dim; ++i)
177 {
178 (*l)[i] = (*this)[i] * PointType(p);
179 }
180 }
181 else
182 {
183 LPointT tmp;
184 for (unsigned int i = 0; i < Dim; ++i)
185 {
186 tmp[i] = (*this)[i] * PointType(p);
187 }
188 *l = tmp;
189 }
190 }
191
192 template <class ScalarT>
193 void
195 {
196 for (unsigned int i = 0; i < Dim - 1; ++i)
197 {
198 (*t)[i] = (*this)[i] * p;
199 }
200 }
201
202 template <class ScalarT>
205 {
206 return p * (*this)[Dim - 1];
207 }
208
209 template <class ScalarT>
210 template <class LPointT, class GPointT>
211 void
212 Frame<3, ScalarT>::ToGlobal(const LPointT& p, GPointT* g) const
213 {
214 if (&p != g)
215 {
216 *g = ScalarType(p[0]) * (*this)[0];
217 for (unsigned int i = 1; i < Dim; ++i)
218 {
219 *g += GPointT(ScalarType(p[i]) * (*this)[i]);
220 }
221 }
222 else
223 {
224 GPointT tmp;
225 tmp = ScalarType(p[0]) * (*this)[0];
226 for (unsigned int i = 1; i < Dim; ++i)
227 {
228 tmp += GPointT(ScalarType(p[i]) * (*this)[i]);
229 }
230 *g = tmp;
231 }
232 }
233
234 template <class ScalarT>
235 void
237 {
238 PointType newDirs[Dim - 1];
239 ScalarType c = std::cos(radians), s = std::sin(radians);
240 newDirs[0] = c * (*this)[0] + s * (*this)[1];
241 newDirs[1] = -s * (*this)[0] + c * (*this)[1];
242 (*this)[0] = newDirs[0];
243 (*this)[1] = newDirs[1];
244 }
245
246}; // namespace GfxTL
247
248#endif
constexpr T c
void FromNormal(const V &v)
Definition Frame.h:32
HyperplaneCoordinateSystem< ScalarType, Dim >::PointType PointType
Definition Frame.h:26
void FromNormal(const V &v)
Definition Frame.h:124
HyperplaneCoordinateSystem< ScalarType, Dim >::PointType PointType
Definition Frame.h:118
Definition AABox.h:10
void Rotation(T rad, MatrixXX< 2, 2, T > *a)
Definition MatrixXX.h:560