ImagingTools Core SDK
CCuboid.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// ACF includes
6#include <istd/TRange.h>
7#include <i3d/CVector3d.h>
8
9
10namespace imt3d
11{
12
13
18{
19public:
20 CCuboid(double left = 0.0,
21 double right = 0.0,
22 double bottom = 0.0,
23 double top = 0.0,
24 double near = 0.0,
25 double far = 0.0);
26
27 i3d::CVector3d GetLeftBottomNear();
28 void SetLeftBottomNear(const i3d::CVector3d& point);
29
30 i3d::CVector3d GetRightBottomNear();
31 void SetRightBottomNear(const i3d::CVector3d& point);
32
33 i3d::CVector3d GetLeftTopNear();
34 void SetLeftTopNear(const i3d::CVector3d& point);
35
36 i3d::CVector3d GetRightTopNear();
37 void SetRightTopNear(const i3d::CVector3d& point);
38
39 i3d::CVector3d GetLeftBottomFar();
40 void SetLeftBottomFar(const i3d::CVector3d& point);
41
42 i3d::CVector3d GetRightBottomFar();
43 void SetRightBottomFar(const i3d::CVector3d& point);
44
45 i3d::CVector3d GetLeftTopFar();
46 void SetLeftTopFar(const i3d::CVector3d& point);
47
48 i3d::CVector3d GetRightTopFar();
49 void SetRightTopFar(const i3d::CVector3d& point);
50
51 double GetLeft() const;
52 void SetLeft(double left);
53
54 double GetTop() const;
55 void SetTop(double top);
56
57 double GetRight() const;
58 void SetRight(double right);
59
60 double GetBottom() const;
61 void SetBottom(double bottom);
62
63 double GetNear() const;
64 void SetNear(double near);
65
66 double GetFar() const;
67 void SetFar(double far);
68
69 double GetWidth() const;
70 double GetHeight() const;
71 double GetDepth() const;
72
73 i3d::CVector3d GetCenterPoint();
74 void ExpandToPoint(const i3d::CVector3d& point);
75
76 const istd::CRange& GetHorizontalRange() const;
77 istd::CRange& GetHorizontalRangeRef();
78 void SetHorizontalRange(const istd::CRange& range);
79
80 const istd::CRange& GetVerticalRange() const;
81 istd::CRange& GetVerticalRangeRef();
82 void SetVerticalRange(const istd::CRange& range);
83
84 const istd::CRange& GetDeepRange() const;
85 istd::CRange& GetDeepRangeRef();
86 void SetDeepRange(const istd::CRange& range);
87
88 bool IsValid() const;
89
93 bool Intersects(const CCuboid& other) const;
94
98 bool Contains(const i3d::CVector3d& point) const;
99
103 static const imt3d::CCuboid& GetEmpty();
104
108 static const imt3d::CCuboid& GetInvalid();
109
110 bool operator==(const CCuboid &object);
111
112 bool operator!=(const CCuboid &object);
113
114private:
115 istd::CRange m_horizontalRange;
116 istd::CRange m_verticalRange;
117 istd::CRange m_depthRange;
118
119 // static members
120 static imt3d::CCuboid s_empty;
121 static imt3d::CCuboid s_invalid;
122};
123
124
125// public methods
126
127inline i3d::CVector3d CCuboid::GetLeftBottomNear()
128{
129 return i3d::CVector3d(m_horizontalRange.GetMinValue(), m_verticalRange.GetMinValue(), m_depthRange.GetMinValue());
130}
131
132
133inline void CCuboid::SetLeftBottomNear(const i3d::CVector3d& point)
134{
135 m_horizontalRange.SetMinValue(point.GetX());
136 m_verticalRange.SetMinValue(point.GetY());
137 m_depthRange.SetMinValue(point.GetZ());
138}
139
140
141inline i3d::CVector3d CCuboid::GetRightBottomNear()
142{
143 return i3d::CVector3d(m_horizontalRange.GetMaxValue(), m_verticalRange.GetMinValue(), m_depthRange.GetMinValue());
144}
145
146
147inline void CCuboid::SetRightBottomNear(const i3d::CVector3d& point)
148{
149 m_horizontalRange.SetMaxValue(point.GetX());
150 m_verticalRange.SetMinValue(point.GetY());
151 m_depthRange.SetMinValue(point.GetZ());
152}
153
154
155inline i3d::CVector3d CCuboid::GetLeftTopNear()
156{
157 return i3d::CVector3d(m_horizontalRange.GetMinValue(), m_verticalRange.GetMaxValue(), m_depthRange.GetMinValue());
158}
159
160
161inline void CCuboid::SetLeftTopNear(const i3d::CVector3d& point)
162{
163 m_horizontalRange.SetMinValue(point.GetX());
164 m_verticalRange.SetMaxValue(point.GetY());
165 m_depthRange.SetMinValue(point.GetZ());
166}
167
168
169inline i3d::CVector3d CCuboid::GetRightTopNear()
170{
171 return i3d::CVector3d(m_horizontalRange.GetMaxValue(), m_verticalRange.GetMaxValue(), m_depthRange.GetMinValue());
172}
173
174
175inline void CCuboid::SetRightTopNear(const i3d::CVector3d& point)
176{
177 m_horizontalRange.SetMaxValue(point.GetX());
178 m_verticalRange.SetMaxValue(point.GetY());
179 m_depthRange.SetMinValue(point.GetZ());
180}
181
182
183inline i3d::CVector3d CCuboid::GetLeftBottomFar()
184{
185 return i3d::CVector3d(m_horizontalRange.GetMinValue(), m_verticalRange.GetMinValue(), m_depthRange.GetMaxValue());
186}
187
188
189inline void CCuboid::SetLeftBottomFar(const i3d::CVector3d& point)
190{
191 m_horizontalRange.SetMinValue(point.GetX());
192 m_verticalRange.SetMinValue(point.GetY());
193 m_depthRange.SetMaxValue(point.GetZ());
194}
195
196
197inline i3d::CVector3d CCuboid::GetRightBottomFar()
198{
199 return i3d::CVector3d(m_horizontalRange.GetMaxValue(), m_verticalRange.GetMinValue(), m_depthRange.GetMaxValue());
200}
201
202
203inline void CCuboid::SetRightBottomFar(const i3d::CVector3d& point)
204{
205 m_horizontalRange.SetMaxValue(point.GetX());
206 m_verticalRange.SetMinValue(point.GetY());
207 m_depthRange.SetMaxValue(point.GetZ());
208}
209
210
211inline i3d::CVector3d CCuboid::GetLeftTopFar()
212{
213 return i3d::CVector3d(m_horizontalRange.GetMinValue(), m_verticalRange.GetMaxValue(), m_depthRange.GetMaxValue());
214}
215
216
217inline void CCuboid::SetLeftTopFar(const i3d::CVector3d& point)
218{
219 m_horizontalRange.SetMinValue(point.GetX());
220 m_verticalRange.SetMaxValue(point.GetY());
221 m_depthRange.SetMaxValue(point.GetZ());
222}
223
224
225inline i3d::CVector3d CCuboid::GetRightTopFar()
226{
227 return i3d::CVector3d(m_horizontalRange.GetMaxValue(), m_verticalRange.GetMaxValue(), m_depthRange.GetMaxValue());
228}
229
230
231inline void CCuboid::SetRightTopFar(const i3d::CVector3d& point)
232{
233 m_horizontalRange.SetMaxValue(point.GetX());
234 m_verticalRange.SetMaxValue(point.GetY());
235 m_depthRange.SetMaxValue(point.GetZ());
236}
237
238
239inline double CCuboid::GetLeft() const
240{
241 return m_horizontalRange.GetMinValue();
242}
243
244
245inline void CCuboid::SetLeft(double left)
246{
247 m_horizontalRange.SetMinValue(left);
248}
249
250
251inline double CCuboid::GetTop() const
252{
253 return m_verticalRange.GetMaxValue();
254}
255
256
257inline void CCuboid::SetTop(double top)
258{
259 m_verticalRange.SetMaxValue(top);
260}
261
262
263inline double CCuboid::GetRight() const
264{
265 return m_horizontalRange.GetMaxValue();
266}
267
268
269inline void CCuboid::SetRight(double right)
270{
271 m_horizontalRange.SetMaxValue(right);
272}
273
274
275inline double CCuboid::GetBottom() const
276{
277 return m_verticalRange.GetMinValue();
278}
279
280
281inline void CCuboid::SetBottom(double bottom)
282{
283 m_verticalRange.SetMinValue(bottom);
284}
285
286
287inline double CCuboid::GetNear() const
288{
289 return m_depthRange.GetMinValue();
290}
291
292
293inline void CCuboid::SetNear(double nearValue)
294{
295 m_depthRange.SetMinValue(nearValue);
296}
297
298
299inline double CCuboid::GetFar() const
300{
301 return m_depthRange.GetMaxValue();
302}
303
304
305inline void CCuboid::SetFar(double farValue)
306{
307 m_depthRange.SetMaxValue(farValue);
308}
309
310
311inline double CCuboid::GetWidth() const
312{
313 return m_horizontalRange.GetLength();
314}
315
316
317inline double CCuboid::GetHeight() const
318{
319 return m_verticalRange.GetLength();
320}
321
322
323inline double CCuboid::GetDepth() const
324{
325 return m_depthRange.GetLength();
326}
327
328
329inline i3d::CVector3d CCuboid::GetCenterPoint()
330{
331 return i3d::CVector3d(
332 (m_horizontalRange.GetMaxValue() + m_horizontalRange.GetMinValue()) / 2.0,
333 (m_verticalRange.GetMaxValue() + m_verticalRange.GetMinValue()) / 2.0,
334 (m_depthRange.GetMaxValue() + m_depthRange.GetMinValue()) / 2.0);
335}
336
337
338inline void CCuboid::ExpandToPoint(const i3d::CVector3d& point)
339{
340 if ((point.GetX() > m_horizontalRange.GetMaxValue())){
341 m_horizontalRange.SetMaxValue(point.GetX());
342 } else if ((point.GetX() < m_horizontalRange.GetMinValue())){
343 m_horizontalRange.SetMinValue(point.GetX());
344 }
345 if ((point.GetY() > m_verticalRange.GetMaxValue())){
346 m_verticalRange.SetMaxValue(point.GetY());
347 } else if ((point.GetY() < m_verticalRange.GetMinValue())){
348 m_verticalRange.SetMinValue(point.GetY());
349 }
350 if ((point.GetZ() > m_depthRange.GetMaxValue())){
351 m_depthRange.SetMaxValue(point.GetZ());
352 } else if ((point.GetZ() < m_depthRange.GetMinValue())){
353 m_depthRange.SetMinValue(point.GetZ());
354 }
355}
356
357
358inline const istd::CRange& CCuboid::GetHorizontalRange() const
359{
360 return m_horizontalRange;
361}
362
363
364inline istd::CRange& CCuboid::GetHorizontalRangeRef()
365{
366 return m_horizontalRange;
367}
368
369
370inline void CCuboid::SetHorizontalRange(const istd::CRange& range)
371{
372 m_horizontalRange = range;
373}
374
375
376inline const istd::CRange& CCuboid::GetVerticalRange() const
377{
378 return m_verticalRange;
379}
380
381
382inline istd::CRange& CCuboid::GetVerticalRangeRef()
383{
384 return m_verticalRange;
385}
386
387
388inline void CCuboid::SetVerticalRange(const istd::CRange& range)
389{
390 m_verticalRange = range;
391}
392
393
394inline const istd::CRange& CCuboid::GetDeepRange() const
395{
396 return m_depthRange;
397}
398
399
400inline istd::CRange& CCuboid::GetDeepRangeRef()
401{
402 return m_depthRange;
403}
404
405
406inline void CCuboid::SetDeepRange(const istd::CRange& range)
407{
408 m_depthRange = range;
409}
410
411
412inline bool CCuboid::IsValid() const
413{
414 return (m_horizontalRange.GetLength() > I_BIG_EPSILON) && (m_verticalRange.GetLength() > I_BIG_EPSILON) && (m_depthRange.GetLength() > I_BIG_EPSILON);
415}
416
417
418inline bool CCuboid::Intersects(const CCuboid& other) const
419{
420 // Two cuboids intersect if they overlap in all three dimensions
421 bool xOverlap = (GetLeft() <= other.GetRight()) && (GetRight() >= other.GetLeft());
422 bool yOverlap = (GetBottom() <= other.GetTop()) && (GetTop() >= other.GetBottom());
423 bool zOverlap = (GetNear() <= other.GetFar()) && (GetFar() >= other.GetNear());
424
425 return xOverlap && yOverlap && zOverlap;
426}
427
428
429inline bool CCuboid::Contains(const i3d::CVector3d& point) const
430{
431 // Check if point is within all three ranges
432 bool xContained = (point.GetX() >= GetLeft()) && (point.GetX() <= GetRight());
433 bool yContained = (point.GetY() >= GetBottom()) && (point.GetY() <= GetTop());
434 bool zContained = (point.GetZ() >= GetNear()) && (point.GetZ() <= GetFar());
435
436 return xContained && yContained && zContained;
437}
438
439
440// static methods
441
443{
444 return s_empty;
445}
446
447
449{
450 return s_invalid;
451}
452
453inline bool CCuboid::operator==(const CCuboid & object)
454{
455 return ((m_horizontalRange == object.m_horizontalRange)
456 && (m_verticalRange == object.m_verticalRange)
457 && (m_depthRange == object.m_depthRange));
458}
459
460inline bool CCuboid::operator!=(const CCuboid & object)
461{
462 return !(operator==(object));
463}
464
465
466} // namespace imt3d
467
468
bool Contains(const i3d::CVector3d &point) const
Definition CCuboid.h:429
static const imt3d::CCuboid & GetInvalid()
Definition CCuboid.h:448
static const imt3d::CCuboid & GetEmpty()
Definition CCuboid.h:442
bool Intersects(const CCuboid &other) const
Definition CCuboid.h:418