AACube.h
Go to the documentation of this file.
1 #ifndef __AACUBE_HEADER__
2 #define __AACUBE_HEADER__
3 #include <algorithm>
4 #include <utility>
5 #include <limits>
6 
7 namespace GfxTL
8 {
9 
10  template< class Point >
11  class AACube
12  {
13  public:
14  typedef Point PointType;
15  typedef typename Point::ScalarType ScalarType;
16  enum
17  {
20  };
21 
22  AACube();
23  AACube(const Point& backBottomLeft, ScalarType width);
24  AACube(const Point* points, size_t size);
25  AACube(unsigned int box, const AACube< Point >& cube);
26 
27  template< class Points >
28  void Bound(const Points& points, size_t size);
29  template< class IteratorT >
30  void Bound(IteratorT begin, IteratorT end);
31  template< class IteratorT >
32  void BoundNonCentered(IteratorT begin, IteratorT end);
33  template< class Points >
34  void BoundRotationInvariant(const Points& points, size_t size);
35  void DividingPlane(unsigned int axis, Point* n,
36  ScalarType* d) const;
37  void DividingPlane(unsigned int axis, ScalarType* s);
38  void Center(Point* c) const;
39  void Center(const Point& c);
40  void SubCube(unsigned int box, AACube< Point >* cube) const;
41  bool IsSubCube(unsigned int* box,
42  const AACube< Point >& cube) const;
43  bool IsInside(const Point& p) const;
44  ScalarType Width() const;
45  void Width(ScalarType w);
46  const Point& LeftBottomBack() const;
47  void LeftBottomBack(const Point& lbb);
48  Point operator[](int index) const;
49  ScalarType DiagLength() const;
50  void Inflate(ScalarType v);
51  ScalarType Distance(const PointType& p) const;
52  ScalarType SqrDistance(const PointType& p) const;
53  void Translate(const PointType& t);
54  void Scale(ScalarType s);
55  const Point& Min() const
56  {
57  return _backBottomLeft;
58  }
60  {
61  return _backBottomLeft;
62  }
63  Point Max() const
64  {
65  Point m(_backBottomLeft);
66  for (unsigned int i = 0; i < Dim; ++i)
67  {
68  m[i] += _width;
69  }
70  return m;
71  }
72 
73  private:
74  Point _backBottomLeft;
75  ScalarType _width;
76  };
77 
78  template< class Point >
79  template< class Points >
80  void AACube< Point >::Bound(const Points& points, size_t size)
81  {
82  _width = 0;
83  if (size > 0)
84  {
85  Point pmax, pmin;
86  for (unsigned int u = 0; u < Dim; ++u)
87  {
88  pmax[u] = pmin[u] = points[0][u];
89  }
90  for (size_t i = 1; i < size; ++i)
91  {
92  for (unsigned int j = 0; j < Dim; ++j)
93  {
94  if (pmin[j] > points[i][j])
95  {
96  pmin[j] = points[i][j];
97  }
98  else if (pmax[j] < points[i][j])
99  {
100  pmax[j] = points[i][j];
101  }
102  }
103  }
104  Point center = pmin +
105  (ScalarType).5 * (pmax - pmin);
106  Point r = pmax - center;
107  ScalarType rmax = r[0];
108  for (unsigned int u = 1; u < Dim; ++u)
109  if (r[u] > rmax)
110  {
111  rmax = r[u];
112  }
113  _backBottomLeft = center;
114  for (unsigned int u = 0; u < Dim; ++u)
115  {
116  _backBottomLeft[u] -= rmax;
117  }
118  _width = 2 * rmax;
119  }
120  }
121 
122  template< class Point >
123  template< class IteratorT >
124  void AACube< Point >::Bound(IteratorT begin, IteratorT end)
125  {
126  _width = 0;
127  if (end - begin > 0)
128  {
129  Point pmax, pmin;
130  for (unsigned int u = 0; u < Dim; ++u)
131  {
132  pmax[u] = pmin[u] = (*begin)[u];
133  }
134  IteratorT i = begin;
135  for (++i; i != end; ++i)
136  {
137  for (unsigned int j = 0; j < Dim; ++j)
138  {
139  if (pmin[j] > (*i)[j])
140  {
141  pmin[j] = (*i)[j];
142  }
143  else if (pmax[j] < (*i)[j])
144  {
145  pmax[j] = (*i)[j];
146  }
147  }
148  }
149  Point center = pmin +
150  (ScalarType).5 * (pmax - pmin);
151  Point r = pmax - center;
152  ScalarType rmax = r[0];
153  for (unsigned int u = 1; u < Dim; ++u)
154  if (r[u] > rmax)
155  {
156  rmax = r[u];
157  }
158  _backBottomLeft = center;
159  for (unsigned int u = 0; u < Dim; ++u)
160  {
161  _backBottomLeft[u] -= rmax;
162  }
163  _width = 2 * rmax;
164  }
165  }
166 
167  template< class Point >
168  template< class IteratorT >
169  void AACube< Point >::BoundNonCentered(IteratorT begin, IteratorT end)
170  {
171  using namespace std;
172  _width = 0;
173  if (end - begin > 0)
174  {
175  Point pmax, pmin;
176  for (unsigned int u = 0; u < Dim; ++u)
177  {
178  pmax[u] = pmin[u] = (*begin)[u];
179  }
180  IteratorT i = begin;
181  for (++i; i != end; ++i)
182  {
183  for (unsigned int j = 0; j < Dim; ++j)
184  {
185  if (pmin[j] > (*i)[j])
186  {
187  pmin[j] = (*i)[j];
188  }
189  else if (pmax[j] < (*i)[j])
190  {
191  pmax[j] = (*i)[j];
192  }
193  }
194  }
195  _backBottomLeft = pmin;
196  _width = pmax[0] - pmin[0];
197  for (unsigned int i = 1; i < Dim; ++i)
198  {
199  _width = max(_width, pmax[i] - pmin[i]);
200  }
201  }
202  }
203 
204  template< class Point >
205  template< class Points >
207  size_t size)
208  {
209  _width = 0;
210  if (size > 0)
211  {
212  Point pmax, pmin;
213  pmax = pmin = points[0];
214  for (size_t i = 1; i < size; ++i)
215  {
216  for (unsigned int j = 0; j < Dim; ++j)
217  {
218  if (pmin[j] > points[i][j])
219  {
220  pmin[j] = points[i][j];
221  }
222  else if (pmax[j] < points[i][j])
223  {
224  pmax[j] = points[i][j];
225  }
226  }
227  }
228  _width = (pmax - pmin).Length();
229  Point center = pmin + (ScalarType).5 * (pmax - pmin);
230  _backBottomLeft = center;
231  for (unsigned int u = 0; u < Dim; ++u)
232  {
233  _backBottomLeft[u] -= _width / 2;
234  }
235  }
236  }
237 
238 };
239 
240 #include "AACube.hpp"
241 
242 #endif
GfxTL::AACube
Definition: AACube.h:11
GfxTL::AACube::LeftBottomBack
const Point & LeftBottomBack() const
Definition: AACube.hpp:143
index
uint8_t index
Definition: EtherCATFrame.h:59
GfxTL::max
MatrixXX< C, R, T > max(const MatrixXX< C, R, T > &a, const MatrixXX< C, R, T > &b)
Definition: MatrixXX.h:581
GfxTL::AACube::SubCube
void SubCube(unsigned int box, AACube< Point > *cube) const
Definition: AACube.hpp:75
visionx::Points
std::vector< Point > Points
Definition: ObjectShapeClassification.h:70
GfxTL::AACube::Bound
void Bound(const Points &points, size_t size)
Definition: AACube.h:80
GfxTL::AACube::BoundNonCentered
void BoundNonCentered(IteratorT begin, IteratorT end)
Definition: AACube.h:169
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
AACube.hpp
Point::ScalarType
float ScalarType
Definition: PointCloud.h:24
GfxTL::AACube::DiagLength
ScalarType DiagLength() const
Definition: AACube.hpp:170
GfxTL::AACube::Min
Point & Min()
Definition: AACube.h:59
GfxTL::AACube::Center
void Center(Point *c) const
Definition: AACube.hpp:53
GfxTL::AACube::DividingPlane
void DividingPlane(unsigned int axis, Point *n, ScalarType *d) const
Definition: AACube.hpp:33
GfxTL::AACube::Max
Point Max() const
Definition: AACube.h:63
GfxTL::AACube::BoundRotationInvariant
void BoundRotationInvariant(const Points &points, size_t size)
Definition: AACube.h:206
GfxTL::AACube::Scale
void Scale(ScalarType s)
Definition: AACube.hpp:242
GfxTL::AACube::AACube
AACube()
Definition: AACube.hpp:6
GfxTL::AACube::PointType
Point PointType
Definition: AACube.h:14
GfxTL::AACube::Translate
void Translate(const PointType &t)
Definition: AACube.hpp:236
Point
Definition: PointCloud.h:21
GfxTL::AACube::operator[]
Point operator[](int index) const
Definition: AACube.hpp:155
GfxTL::AACube::Dim
@ Dim
Definition: AACube.h:18
GfxTL
Definition: AABox.h:8
GfxTL::AACube::IsInside
bool IsInside(const Point &p) const
Definition: AACube.hpp:119
GfxTL::AACube::Min
const Point & Min() const
Definition: AACube.h:55
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
std
Definition: Application.h:66
GfxTL::AACube::IsSubCube
bool IsSubCube(unsigned int *box, const AACube< Point > &cube) const
Definition: AACube.hpp:91
GfxTL::AACube::Width
ScalarType Width() const
Definition: AACube.hpp:131
GfxTL::AACube::NCorners
@ NCorners
Definition: AACube.h:19
GfxTL::AACube::Distance
ScalarType Distance(const PointType &p) const
Definition: AACube.hpp:187
GfxTL::AACube::ScalarType
Point::ScalarType ScalarType
Definition: AACube.h:15
Point::Dim
@ Dim
Definition: PointCloud.h:23
GfxTL::AACube::SqrDistance
ScalarType SqrDistance(const PointType &p) const
Definition: AACube.hpp:212
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
GfxTL::AACube::Inflate
void Inflate(ScalarType v)
Definition: AACube.hpp:176