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