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