CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
GeExtents3d.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#ifndef _ODGEEXTENTS3D_INCLUDED_
25#define _ODGEEXTENTS3D_INCLUDED_
27#include "Ge/GePoint3d.h"
28#include "Ge/GeVector3d.h"
29#include "Ge/GeMatrix3d.h"
30
31#include "TD_PackPush.h"
32
33class OdGeExtents2d;
34
35#define INVALIDEXTENTS 1.0e20
36
45{
46public:
47
52
59 const OdGePoint3d& min,
60 const OdGePoint3d& max);
61
66
73 const OdGePoint3d& minPoint() const;
74
81 const OdGePoint3d& maxPoint() const;
82
90 const OdGePoint3d& operator[] (int iIndex) const {
91 return iIndex == 0 ? m_min : m_max;
92 }
93
102 OdGePoint3d& operator[] (int iIndex) {
103 return iIndex == 0 ? m_min : m_max;
104 }
105
112 void set(
113 const OdGePoint3d& min,
114 const OdGePoint3d& max);
115
128 void comparingSet(
129 const OdGePoint3d& pt1,
130 const OdGePoint3d& pt2);
131
137 OdGeExtents3d& addPoint(
138 const OdGePoint3d& point);
139
149 const OdGePoint3dArray& points);
150
159 OdGeExtents3d& addExt(
160 const OdGeExtents3d& extents);
161
172 inline bool isValidExtents() const
173 {
174 return ( (m_max.x >= m_min.x) && (m_max.y >= m_min.y) && (m_max.z >= m_min.z));
175 }
176
182 void expandBy(
183 const OdGeVector3d& vect);
184
191 const OdGeMatrix3d& xfm);
192
202 bool contains(
203 const OdGePoint3d& point, const OdGeTol& tol = OdGeContext::gTol) const;
204
214 bool contains(
215 const OdGeExtents3d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
216
226 bool isDisjoint(
227 const OdGeExtents3d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
228
242 const OdGeExtents3d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
243
252 double distanceTo(const OdGePoint3d& iPoint) const;
253
262 double distanceTo(const OdGeExtents3d& iExtents) const;
263
268 {
278 kIntersectOk
279 };
280
302 IntersectionStatus intersectWith(const OdGeExtents3d& extents, OdGeExtents3d* pResult = 0) const;
303
313 bool isWithinRange(const OdGePoint3d &pt, double radius);
314
322 {
323 return m_min + (m_max - m_min) * 0.5;
324 }
325
333 {
334 return m_max - m_min;
335 }
336
341 {
343 kConvert2dPlaneXY = 0x04,
345 kConvert2dPlaneXZ = 0x08,
347 kConvert2dPlaneYX = 0x01,
349 kConvert2dPlaneYZ = 0x09,
351 kConvert2dPlaneZX = 0x02,
353 kConvert2dPlaneZY = 0x06
354 };
355
365 void convert2d(OdGeExtents2d &extents, Convert2dPlane plane = kConvert2dPlaneXY) const;
366
376 void setFrom2d(const OdGeExtents2d &extents, Convert2dPlane plane = kConvert2dPlaneXY);
377
390 bool isEqualTo(const OdGeExtents3d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
391
400 bool operator ==(const OdGeExtents3d& extents) const
401 {
402 return isEqualTo(extents);
403 }
404
413 bool operator !=(const OdGeExtents3d& extents) const
414 {
415 return !isEqualTo(extents);
416 }
417//DOM-IGNORE-BEGIN
418protected:
421//DOM-IGNORE-END
422};
423
424// Inline implementations
425
429{
430}
431
433 : m_min(min)
434 , m_max(max)
435{
436}
437
439{
440 return m_min;
441}
442
444{
445 return m_max;
446}
447
448inline void OdGeExtents3d::set(const OdGePoint3d& min, const OdGePoint3d& max)
449{
450 //ODA_ASSERT_ONCE(min.x <= max.x);
451 //ODA_ASSERT_ONCE(min.y <= max.y);
452 //ODA_ASSERT_ONCE(min.z <= max.z);
453 m_min = min;
454 m_max = max;
455}
456
457inline void OdGeExtents3d::comparingSet(const OdGePoint3d& pt1, const OdGePoint3d& pt2)
458{
459 m_min.x = odmin(pt1.x, pt2.x);
460 m_max.x = odmax(pt1.x, pt2.x);
461 m_min.y = odmin(pt1.y, pt2.y);
462 m_max.y = odmax(pt1.y, pt2.y);
463 m_min.z = odmin(pt1.z, pt2.z);
464 m_max.z = odmax(pt1.z, pt2.z);
465}
466
468{
469 if ((m_max.x < m_min.x) || (m_max.y < m_min.y) || (m_max.z < m_min.z))
470 {
471 //TODO: it's better to remove this case for better performance!
472 m_max = m_min = point;
473 }
474 else
475 {
476 m_min.x = odmin(m_min.x, point.x);
477 m_max.x = odmax(m_max.x, point.x);
478 m_min.y = odmin(m_min.y, point.y);
479 m_max.y = odmax(m_max.y, point.y);
480 m_min.z = odmin(m_min.z, point.z);
481 m_max.z = odmax(m_max.z, point.z);
482 }
483 return *this;
484}
485
487{
488 ODA_ASSERT(extents.isValidExtents());
489
490#if 0
491 addPoint(extents.minPoint());
492 addPoint(extents.maxPoint());
493#else
494 if ((m_max.x < m_min.x) || (m_max.y < m_min.y) || (m_max.z < m_min.z))
495 {
496 //TODO: it's better to remove this case for better performance!
497 set(extents.minPoint(), extents.maxPoint());
498 }
499 else
500 {
501 m_min.x = odmin(m_min.x, extents.m_min.x);
502 m_max.x = odmax(m_max.x, extents.m_max.x);
503 m_min.y = odmin(m_min.y, extents.m_min.y);
504 m_max.y = odmax(m_max.y, extents.m_max.y);
505 m_min.z = odmin(m_min.z, extents.m_min.z);
506 m_max.z = odmax(m_max.z, extents.m_max.z);
507 }
508#endif
509 return *this;
510}
511
512inline void OdGeExtents3d::expandBy(const OdGeVector3d& vect)
513{
515
516 OdGePoint3d p1 = m_min, p2 = m_max;
517 addPoint(p1 + vect);
518 addPoint(p2 + vect);
519}
520
521inline bool OdGeExtents3d::contains(const OdGePoint3d& point, const OdGeTol& tol) const
522{
523 //ODA_ASSERT(isValidExtents()); //note: empty/invalid box does NOT contain any point
524
525 return ( (point.x + tol.equalPoint()) >= m_min.x
526 && (point.y + tol.equalPoint()) >= m_min.y
527 && (point.z + tol.equalPoint()) >= m_min.z
528 && (point.x - tol.equalPoint()) <= m_max.x
529 && (point.y - tol.equalPoint()) <= m_max.y
530 && (point.z - tol.equalPoint()) <= m_max.z );
531}
532
533inline bool OdGeExtents3d::contains(const OdGeExtents3d& extents, const OdGeTol& tol) const
534{
536
537 return ((extents.m_min.x + tol.equalPoint()) >= m_min.x
538 && (extents.m_min.y + tol.equalPoint()) >= m_min.y
539 && (extents.m_min.z + tol.equalPoint()) >= m_min.z
540 && m_max.x >= (extents.m_max.x - tol.equalPoint())
541 && m_max.y >= (extents.m_max.y - tol.equalPoint())
542 && m_max.z >= (extents.m_max.z - tol.equalPoint()));
543}
544
545inline bool OdGeExtents3d::isDisjoint(const OdGeExtents3d& extents, const OdGeTol& tol) const
546{
547 //ODA_ASSERT(isValidExtents()); //note: empty/invalid box is disjoint with everything
548
549 return ((extents.m_min.x - tol.equalPoint()) > m_max.x
550 || (extents.m_min.y - tol.equalPoint()) > m_max.y
551 || (extents.m_min.z - tol.equalPoint()) > m_max.z
552 || m_min.x > (extents.m_max.x + tol.equalPoint())
553 || m_min.y > (extents.m_max.y + tol.equalPoint())
554 || m_min.z > (extents.m_max.z + tol.equalPoint()));
555}
556
557#undef INVALIDEXTENTS
558
559#include "TD_PackPop.h"
560
561#endif //_ODGEEXTENTS3D_INCLUDED_
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:57
tol
Definition: DimVarDefs.h:2287
#define GE_TOOLKIT_EXPORT
Definition: GeExport.h:49
#define GE_STATIC_EXPORT
Definition: GeExport.h:52
#define INVALIDEXTENTS
Definition: GeExtents3d.h:35
bool operator!=(T left, const OdGiVariant::EnumType right)
Definition: GiVariant.h:403
bool operator==(T left, const OdGiVariant::EnumType right)
Definition: GiVariant.h:397
#define odmin(X, Y)
Definition: OdPlatform.h:34
#define odmax(X, Y)
Definition: OdPlatform.h:35
static GE_STATIC_EXPORT const OdGeExtents3d kInvalid
Definition: GeExtents3d.h:65
bool isDisjoint(const OdGeExtents3d &extents, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents3d.h:545
IntersectionStatus intersectWith(const OdGeExtents3d &extents, OdGeExtents3d *pResult=0) const
OdGeExtents3d & addPoint(const OdGePoint3d &point)
Definition: GeExtents3d.h:467
OdGePoint3d m_max
Definition: GeExtents3d.h:420
bool isWithinRange(const OdGePoint3d &pt, double radius)
OdGeExtents3d & addPoints(const OdGePoint3dArray &points)
OdGePoint3d center() const
Definition: GeExtents3d.h:321
void setFrom2d(const OdGeExtents2d &extents, Convert2dPlane plane=kConvert2dPlaneXY)
bool isEqualTo(const OdGeExtents3d &extents, const OdGeTol &tol=OdGeContext::gTol) const
bool isValidExtents() const
Definition: GeExtents3d.h:172
double distanceTo(const OdGePoint3d &iPoint) const
OdGePoint3d m_min
Definition: GeExtents3d.h:419
double distanceTo(const OdGeExtents3d &iExtents) const
OdGeExtents3d & addExt(const OdGeExtents3d &extents)
Definition: GeExtents3d.h:486
OdGeVector3d diagonal() const
Definition: GeExtents3d.h:332
void set(const OdGePoint3d &min, const OdGePoint3d &max)
Definition: GeExtents3d.h:448
void convert2d(OdGeExtents2d &extents, Convert2dPlane plane=kConvert2dPlaneXY) const
void expandBy(const OdGeVector3d &vect)
Definition: GeExtents3d.h:512
const OdGePoint3d & maxPoint() const
Definition: GeExtents3d.h:443
bool isDisjointEuclidean(const OdGeExtents3d &extents, const OdGeTol &tol=OdGeContext::gTol) const
bool contains(const OdGePoint3d &point, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents3d.h:521
void transformBy(const OdGeMatrix3d &xfm)
const OdGePoint3d & minPoint() const
Definition: GeExtents3d.h:438
void comparingSet(const OdGePoint3d &pt1, const OdGePoint3d &pt2)
Definition: GeExtents3d.h:457
double z
Definition: GePoint3d.h:497
double y
Definition: GePoint3d.h:496
double x
Definition: GePoint3d.h:495
Definition: GeTol.h:49
static GE_STATIC_EXPORT OdGeTol gTol
Definition: GeGbl.h:65