AACube.hpp
Go to the documentation of this file.
1
2namespace GfxTL
3{
4
5 template <class Point>
6 AACube<Point>::AACube() : _width(std::numeric_limits<ScalarType>::infinity())
7 {
8 for (unsigned int i = 0; i < Dim; ++i)
9 _backBottomLeft[i] = -std::numeric_limits<ScalarType>::infinity();
10 }
11
12 template <class Point>
13 AACube<Point>::AACube(const Point& backBottomLeft, ScalarType width) :
14 _backBottomLeft(backBottomLeft), _width(width)
15 {
16 }
17
18 template <class Point>
19 AACube<Point>::AACube(const Point* points, size_t size)
20 {
21 Bound(points, size);
22 }
24 template <class Point>
25 AACube<Point>::AACube(unsigned int box, const AACube<Point>& cube)
26 {
27 cube.SubCube(box, this);
28 }
29
30 template <class Point>
31 void
32 AACube<Point>::DividingPlane(unsigned int axis, Point* n, ScalarType* d) const
33 {
34 for (int i = 0; i < Dim; ++i)
35 (*n)[i] = (i == axis) ? (ScalarType)-1 : (ScalarType)0;
36 Point center;
37 Center(&center);
38 *d = center * (*n);
39 }
41 template <class Point>
42 void
44 {
45 Point center;
46 Center(&center);
47 *s = center[axis];
48 }
50 template <class Point>
51 void
53 {
54 ScalarType r = _width / 2;
55 *c = _backBottomLeft;
56 for (int i = 0; i < Dim; ++i)
57 {
58 (*c)[i] += r;
59 }
60 }
61
62 template <class Point>
63 void
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
76 AACube<Point>::SubCube(unsigned int box, 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
92 AACube<Point>::IsSubCube(unsigned int* box, 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
121 {
122 for (unsigned int i = 0; i < Dim; ++i)
123 if (p[i] < _backBottomLeft[i] || p[i] > _backBottomLeft[i] + _width)
124 {
125 return false;
126 }
127 return true;
128 }
129
130 template <class Point>
133 {
134 return _width;
135 }
136
137 template <class Point>
138 void
140 {
141 _width = w;
142 }
143
144 template <class Point>
145 const Point&
147 {
148 return _backBottomLeft;
149 }
150
151 template <class Point>
152 void
154 {
155 _backBottomLeft = lbb;
156 }
157
158 template <class Point>
159 Point
161 {
162 Point p = _backBottomLeft;
163 for (int i = 0; i < Dim; ++i)
164 {
165 if (!(index & (1 << i)))
166 {
167 p[i] += _width;
168 }
169 }
170 return p;
171 }
172
173 template <class Point>
176 {
177 return std::sqrt(ScalarType(Dim)) * _width;
178 }
179
180 template <class Point>
181 void
183 {
184 for (unsigned int i = 0; i < Dim; ++i)
185 {
186 _backBottomLeft[i] -= v;
187 }
188 _width += 2 * v;
189 }
190
191 template <class Point>
194 {
195 Point p, cMin, cMax;
196 cMin = (*this)[AACube<Point>::NCorners - 1];
197 cMax = (*this)[0];
198 for (unsigned int i = 0; i < Point::Dim; ++i)
199 {
200 if (x[i] <= cMin[i])
201 {
202 p[i] = cMin[i];
203 }
204 else if (x[i] < cMax[i])
205 {
206 p[i] = x[i];
207 }
208 else
209 {
210 p[i] = cMax[i];
211 }
212 }
213 return (p - x).Length();
214 }
215
216 template <class Point>
219 {
220 Point p, cMin, cMax;
221 cMin = (*this)[AACube<Point>::NCorners - 1];
222 cMax = (*this)[0];
223 for (unsigned int i = 0; i < Point::Dim; ++i)
224 {
225 if (x[i] <= cMin[i])
226 {
227 p[i] = cMin[i];
228 }
229 else if (x[i] < cMax[i])
230 {
231 p[i] = x[i];
232 }
233 else
234 {
235 p[i] = cMax[i];
236 }
237 }
238 return (p - x).SqrLength();
239 }
240
241 template <class Point>
242 void
244 {
245 _backBottomLeft += t;
246 }
247
248 template <class Point>
249 void
251 {
252 _backBottomLeft *= s;
253 _width *= s;
254 }
255
256}; // namespace GfxTL
uint8_t index
constexpr T c
Point operator[](int index) const
Definition AACube.hpp:160
void SubCube(unsigned int box, AACube< Point > *cube) const
Definition AACube.hpp:76
ScalarType DiagLength() const
Definition AACube.hpp:175
Point::ScalarType ScalarType
Definition AACube.h:15
void Scale(ScalarType s)
Definition AACube.hpp:250
void Bound(const Points &points, size_t size)
Definition AACube.h:86
void Inflate(ScalarType v)
Definition AACube.hpp:182
void Center(VectorXD< Dim, ScalarType > *c) const
bool IsSubCube(unsigned int *box, const AACube< Point > &cube) const
Definition AACube.hpp:92
void DividingPlane(unsigned int axis, Point *n, ScalarType *d) const
Definition AACube.hpp:32
bool IsInside(const Point &p) const
Definition AACube.hpp:120
void Translate(const PointType &t)
Definition AACube.hpp:243
ScalarType SqrDistance(const PointType &p) const
Definition AACube.hpp:218
ScalarType Distance(const PointType &p) const
Definition AACube.hpp:193
const Point & LeftBottomBack() const
Definition AACube.hpp:146
Point PointType
Definition AACube.h:14
ScalarType Width() const
Definition AACube.hpp:132
Definition AABox.h:10
This file offers overloads of toIce() and fromIce() functions for STL container types.