AACube.hpp
Go to the documentation of this file.
1 
2 namespace GfxTL
3 {
4 
5  template< class Point >
7  : _width(std::numeric_limits< ScalarType >::infinity())
8  {
9  for (unsigned int i = 0; i < Dim; ++i)
10  _backBottomLeft[i] =
11  -std::numeric_limits< ScalarType >::infinity();
12  }
13 
14  template< class Point >
15  AACube< Point >::AACube(const Point& backBottomLeft, ScalarType width)
16  : _backBottomLeft(backBottomLeft)
17  , _width(width)
18  {}
19 
20  template< class Point >
21  AACube< Point >::AACube(const Point* points, size_t size)
22  {
23  Bound(points, size);
24  }
25 
26  template< class Point >
27  AACube< Point >::AACube(unsigned int box, const AACube< Point >& cube)
28  {
29  cube.SubCube(box, this);
30  }
31 
32  template< class Point >
33  void AACube< Point >::DividingPlane(unsigned int axis, Point* n,
34  ScalarType* d) const
35  {
36  for (int i = 0; i < Dim; ++i)
37  (*n)[i] = (i == axis) ? (ScalarType) - 1
38  : (ScalarType)0;
39  Point center;
40  Center(&center);
41  *d = center * (*n);
42  }
43 
44  template< class Point >
45  void AACube< Point >::DividingPlane(unsigned int axis, ScalarType* s)
46  {
47  Point center;
48  Center(&center);
49  *s = center[axis];
50  }
51 
52  template< class Point >
54  {
55  ScalarType r = _width / 2;
56  *c = _backBottomLeft;
57  for (int i = 0; i < Dim; ++i)
58  {
59  (*c)[i] += r;
60  }
61  }
62 
63  template< class Point >
65  {
66  ScalarType r = _width / 2;
67  _backBottomLeft = c;
68  for (int i = 0; i < Dim; ++i)
69  {
70  _backBottomLeft[i] -= r;
71  }
72  }
73 
74  template< class Point >
75  void AACube< Point >::SubCube(unsigned int box,
76  AACube< Point >* cube) const
77  {
78  cube->_backBottomLeft = _backBottomLeft;
79  ScalarType r = _width / 2;
80  for (int i = 0; i < Dim; ++i)
81  {
82  if (!(box & (1 << i)))
83  {
84  cube->_backBottomLeft[i] += r;
85  }
86  }
87  cube->_width = r;
88  }
89 
90  template< class Point >
91  bool AACube< Point >::IsSubCube(unsigned int* box,
92  const AACube< Point >& cube) const
93  {
94  ScalarType r = _width / 2;
95  if (r != cube._width)
96  {
97  return false;
98  }
99  for (unsigned int i = 0; i < NCorners; ++i)
100  {
101  Point p = _backBottomLeft;
102  for (int j = 0; j < Dim; ++j)
103  {
104  if (!(i & (1 << j)))
105  {
106  p[j] += r;
107  }
108  }
109  if (p == cube._backBottomLeft)
110  {
111  *box = i;
112  return true;
113  }
114  }
115  return false;
116  }
117 
118  template< class Point >
119  bool AACube< Point >::IsInside(const Point& p) const
120  {
121  for (unsigned int i = 0; i < Dim; ++i)
122  if (p[i] < _backBottomLeft[i] || p[i] > _backBottomLeft[i] + _width)
123  {
124  return false;
125  }
126  return true;
127  }
128 
129  template< class Point >
132  {
133  return _width;
134  }
135 
136  template< class Point >
138  {
139  _width = w;
140  }
141 
142  template< class Point >
144  {
145  return _backBottomLeft;
146  }
147 
148  template< class Point >
150  {
151  _backBottomLeft = lbb;
152  }
153 
154  template< class Point >
156  {
157  Point p = _backBottomLeft;
158  for (int i = 0; i < Dim; ++i)
159  {
160  if (!(index & (1 << i)))
161  {
162  p[i] += _width;
163  }
164  }
165  return p;
166  }
167 
168  template< class Point >
171  {
172  return std::sqrt(ScalarType(Dim)) * _width;
173  }
174 
175  template< class Point >
177  {
178  for (unsigned int i = 0; i < Dim; ++i)
179  {
180  _backBottomLeft[i] -= v;
181  }
182  _width += 2 * v;
183  }
184 
185  template< class Point >
187  Distance(const PointType& x) const
188  {
189  Point p, cMin, cMax;
190  cMin = (*this)[AACube< Point >::NCorners - 1];
191  cMax = (*this)[0];
192  for (unsigned int i = 0; i < Point::Dim; ++i)
193  {
194  if (x[i] <= cMin[i])
195  {
196  p[i] = cMin[i];
197  }
198  else if (x[i] < cMax[i])
199  {
200  p[i] = x[i];
201  }
202  else
203  {
204  p[i] = cMax[i];
205  }
206  }
207  return (p - x).Length();
208  }
209 
210  template< class Point >
212  SqrDistance(const PointType& x) const
213  {
214  Point p, cMin, cMax;
215  cMin = (*this)[AACube< Point >::NCorners - 1];
216  cMax = (*this)[0];
217  for (unsigned int i = 0; i < Point::Dim; ++i)
218  {
219  if (x[i] <= cMin[i])
220  {
221  p[i] = cMin[i];
222  }
223  else if (x[i] < cMax[i])
224  {
225  p[i] = x[i];
226  }
227  else
228  {
229  p[i] = cMax[i];
230  }
231  }
232  return (p - x).SqrLength();
233  }
234 
235  template< class Point >
237  {
238  _backBottomLeft += t;
239  }
240 
241  template< class Point >
243  {
244  _backBottomLeft *= s;
245  _width *= s;
246  }
247 
248 };
249 
GfxTL::sqrt
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition: VectorXD.h:662
GfxTL::AACube
Definition: AACube.h:11
GfxTL::VectorXD< DimT, ScalarType >
index
uint8_t index
Definition: EtherCATFrame.h:59
GfxTL::AACube::SubCube
void SubCube(unsigned int box, AACube< Point > *cube) const
Definition: AACube.hpp:75
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
GfxTL::AACube::AACube
AACube()
Definition: AACube.hpp:6
Point
Definition: PointCloud.h:21
GfxTL
Definition: AABox.h:8
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
std
Definition: Application.h:66
GfxTL::AACube< GfxTL::VectorXD< DimT, ScalarType > >::ScalarType
GfxTL::VectorXD< DimT, ScalarType > ::ScalarType ScalarType
Definition: AACube.h:15
Point::Dim
@ Dim
Definition: PointCloud.h:23
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33