CFx SDK Documentation  2020SP3
GeExtents3d.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, 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 Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 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 
33 class OdGeExtents2d;
34 
35 #define INVALIDEXTENTS 1.0e20
44 class GE_TOOLKIT_EXPORT OdGeExtents3d
45 {
46 public:
47 
51  OdGeExtents3d();
52 
54  const OdGePoint3d& min,
55  const OdGePoint3d& max);
56 
61 
65  const OdGePoint3d& minPoint() const;
66 
70  const OdGePoint3d& maxPoint() const;
71 
78  void set(
79  const OdGePoint3d& min,
80  const OdGePoint3d& max);
81 
93  void comparingSet(
94  const OdGePoint3d& pt1,
95  const OdGePoint3d& pt2);
96 
102  void addPoint(
103  const OdGePoint3d& point);
104 
110  void addExt(
111  const OdGeExtents3d& extents);
112 
120  inline bool isValidExtents() const
121  {
122  return ( (m_max.x >= m_min.x) && (m_max.y >= m_min.y) && (m_max.z >= m_min.z));
123  }
124 
129  void expandBy(
130  const OdGeVector3d& vect);
131 
137  void transformBy(
138  const OdGeMatrix3d& xfm);
139 
146  bool contains(
147  const OdGePoint3d& point, const OdGeTol& tol = OdGeContext::gTol) const;
148 
149  bool contains(
150  const OdGeExtents3d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
151 
158  bool isDisjoint(
159  const OdGeExtents3d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
160 
162  {
163  kIntersectUnknown,// Either or both extents are invalid
164  kIntersectNot, // Extents are NOT intersecting
165  kIntersectOpIn, // Operand is completely within this extents
166  kIntersectOpOut, // This extents is completely within operand
167  kIntersectOk // Extents are intersecting, result is returned
168  };
169 
188  IntersectionStatus intersectWith(const OdGeExtents3d& extents, OdGeExtents3d* pResult = 0) const;
189 
191  {
192  return m_min + (m_max - m_min) * 0.5;
193  }
194 
196  {
197  kConvert2dPlaneXY = 0x04,
198  kConvert2dPlaneXZ = 0x0C,
199  kConvert2dPlaneYX = 0x01,
200  kConvert2dPlaneYZ = 0x0D,
201  kConvert2dPlaneZX = 0x03,
202  kConvert2dPlaneZY = 0x07
203  };
204  void convert2d(OdGeExtents2d &extents, Convert2dPlane plane = kConvert2dPlaneXY) const;
205  void setFrom2d(const OdGeExtents2d &extents, Convert2dPlane plane = kConvert2dPlaneXY);
206 
207  bool isEqualTo(const OdGeExtents3d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
208 
209  bool operator ==(const OdGeExtents3d& extents) const
210  {
211  return isEqualTo(extents);
212  }
213  bool operator !=(const OdGeExtents3d& extents) const
214  {
215  return !isEqualTo(extents);
216  }
217 
218 protected:
221 };
222 
223 // Inline implementations
224 
228 {
229 }
230 
232  : m_min(min)
233  , m_max(max)
234 {
235 }
236 
238 {
239  return m_min;
240 }
241 
243 {
244  return m_max;
245 }
246 
247 inline void OdGeExtents3d::set(const OdGePoint3d& min, const OdGePoint3d& max)
248 {
249  m_min = min;
250  m_max = max;
251 }
252 
253 inline void OdGeExtents3d::comparingSet(const OdGePoint3d& pt1, const OdGePoint3d& pt2)
254 {
255  if(pt1.x > pt2.x)
256  {
257  m_max.x = pt1.x;
258  m_min.x = pt2.x;
259  }
260  else
261  {
262  m_min.x = pt1.x;
263  m_max.x = pt2.x;
264  }
265  if(pt1.y > pt2.y)
266  {
267  m_max.y = pt1.y;
268  m_min.y = pt2.y;
269  }
270  else
271  {
272  m_min.y = pt1.y;
273  m_max.y = pt2.y;
274  }
275  if(pt1.z > pt2.z)
276  {
277  m_max.z = pt1.z;
278  m_min.z = pt2.z;
279  }
280  else
281  {
282  m_min.z = pt1.z;
283  m_max.z = pt2.z;
284  }
285 }
286 
287 #define ex_minmax(max, min, val) \
288  if (max < val) max = val;\
289  else if (min > val) min = val;
290 
291 inline void OdGeExtents3d::addPoint(const OdGePoint3d& point)
292 {
293  if ((m_max.x < m_min.x) || (m_max.y < m_min.y) || (m_max.z < m_min.z))
294  {
295  m_max = m_min = point;
296  }
297  else
298  {
299  ex_minmax(m_max.x, m_min.x, point.x);
300  ex_minmax(m_max.y, m_min.y, point.y);
301  ex_minmax(m_max.z, m_min.z, point.z);
302  }
303 }
304 #undef ex_minmax
305 
306 inline void OdGeExtents3d::addExt(const OdGeExtents3d& extents)
307 {
308  ODA_ASSERT(extents.isValidExtents());
309 
310 #if 0
311  addPoint(extents.minPoint());
312  addPoint(extents.maxPoint());
313 #else
314  // Optimization
315 #define ex_minmax(max, min, valMax, valMin) \
316  if (max < valMax) max = valMax; \
317  if (min > valMin) min = valMin;
318 
319  if ((m_max.x < m_min.x) || (m_max.y < m_min.y) || (m_max.z < m_min.z))
320  {
321  set(extents.minPoint(), extents.maxPoint());
322  }
323  else
324  {
325  ex_minmax(m_max.x, m_min.x, extents.maxPoint().x, extents.minPoint().x);
326  ex_minmax(m_max.y, m_min.y, extents.maxPoint().y, extents.minPoint().y);
327  ex_minmax(m_max.z, m_min.z, extents.maxPoint().z, extents.minPoint().z);
328  }
329 
330 #undef ex_minmax
331 #endif
332 }
333 
334 inline void OdGeExtents3d::expandBy(const OdGeVector3d& vect)
335 {
337 
338  OdGePoint3d p1 = m_min, p2 = m_max;
339  addPoint(p1 + vect);
340  addPoint(p2 + vect);
341 }
342 
344 {
346 
347  OdGeVector3d d = m_max - m_min;
348 
349  m_max = m_min = (xfm * m_min);
350  if(OdNonZero(d.x, 1.e-200))
351  expandBy(xfm * (OdGeVector3d::kXAxis * d.x));
352  if(OdNonZero(d.y, 1.e-200))
353  expandBy(xfm * (OdGeVector3d::kYAxis * d.y));
354  if(OdNonZero(d.z, 1.e-200))
355  expandBy(xfm * (OdGeVector3d::kZAxis * d.z));
356 }
357 
358 inline bool OdGeExtents3d::contains(const OdGePoint3d& point, const OdGeTol& tol) const
359 {
361 
362  return ( (point.x + tol.equalPoint()) >= m_min.x
363  && (point.y + tol.equalPoint()) >= m_min.y
364  && (point.z + tol.equalPoint()) >= m_min.z
365  && (point.x - tol.equalPoint()) <= m_max.x
366  && (point.y - tol.equalPoint()) <= m_max.y
367  && (point.z - tol.equalPoint()) <= m_max.z );
368 }
369 
370 inline bool OdGeExtents3d::contains(const OdGeExtents3d& extents, const OdGeTol& tol) const
371 {
373 
374  return ((extents.m_min.x + tol.equalPoint()) >= m_min.x
375  && (extents.m_min.y + tol.equalPoint()) >= m_min.y
376  && (extents.m_min.z + tol.equalPoint()) >= m_min.z
377  && m_max.x >= (extents.m_max.x - tol.equalPoint())
378  && m_max.y >= (extents.m_max.y - tol.equalPoint())
379  && m_max.z >= (extents.m_max.z - tol.equalPoint()));
380 }
381 
382 inline bool OdGeExtents3d::isDisjoint(const OdGeExtents3d& extents, const OdGeTol& tol) const
383 {
385 
386  return ((extents.m_min.x - tol.equalPoint()) > m_max.x
387  || (extents.m_min.y - tol.equalPoint()) > m_max.y
388  || (extents.m_min.z - tol.equalPoint()) > m_max.z
389  || m_min.x > (extents.m_max.x + tol.equalPoint())
390  || m_min.y > (extents.m_max.y + tol.equalPoint())
391  || m_min.z > (extents.m_max.z + tol.equalPoint()));
392 }
393 
394 inline bool OdGeExtents3d::isEqualTo(const OdGeExtents3d& extents, const OdGeTol& tol) const
395 {
396  const OdUInt8 bValid = ((isValidExtents()) ? 1 : 0) | ((extents.isValidExtents()) ? 2 : 0);
397  switch (bValid)
398  {
399  // Both invalid
400  case 0: return true;
401  // Both valid
402  case 3: return m_min.isEqualTo(extents.m_min, tol) && m_max.isEqualTo(extents.m_max, tol);
403  }
404  return false;
405 }
406 
407 #undef INVALIDEXTENTS
408 
409 #include "TD_PackPop.h"
410 
411 #endif //_ODGEEXTENTS3D_INCLUDED_
OdGeVector3d
Definition: GeVector3d.h:54
OdGeExtents3d::setFrom2d
void setFrom2d(const OdGeExtents2d &extents, Convert2dPlane plane=kConvert2dPlaneXY)
OdGeExtents2d::set
void set(const OdGePoint2d &min, const OdGePoint2d &max)
Definition: GeExtents2d.h:82
OdUInt8
unsigned char OdUInt8
Definition: OdPlatformSettings.h:759
OdGeExtents3d::IntersectionStatus
IntersectionStatus
Definition: GeExtents3d.h:162
tol
tol
Definition: DimVarDefs.h:2287
INVALIDEXTENTS
#define INVALIDEXTENTS
Definition: GeExtents3d.h:35
OdGeVector3d::x
double x
Definition: GeVector3d.h:601
OdGeExtents3d::kIntersectNot
@ kIntersectNot
Definition: GeExtents3d.h:164
OdGeExtents3d::comparingSet
void comparingSet(const OdGePoint3d &pt1, const OdGePoint3d &pt2)
Definition: GeExtents3d.h:253
OdGeExtents2d::isEqualTo
bool isEqualTo(const OdGeExtents2d &extents, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents2d.h:298
OdGeExtents2d::addPoint
void addPoint(const OdGePoint2d &point)
Definition: GeExtents2d.h:107
OdGeVector3d::z
double z
Definition: GeVector3d.h:603
ODA_ASSERT_ONCE
#define ODA_ASSERT_ONCE(exp)
Definition: DebugStuff.h:51
OdGeVector3d::kXAxis
static GE_STATIC_EXPORT const OdGeVector3d kXAxis
Definition: GeVector3d.h:89
OdGeExtents3d::isValidExtents
bool isValidExtents() const
Definition: GeExtents3d.h:120
FacetModelerProfile2DBool::min
const T & min(const T &x, const T &y)
Definition: FMImpProfile2DBool.h:98
OdGePoint3d::y
double y
Definition: GePoint3d.h:368
OdGePoint3d::x
double x
Definition: GePoint3d.h:367
OdGePoint2d::y
double y
Definition: GePoint2d.h:300
TD_PackPop.h
OdGeExtents3d::transformBy
void transformBy(const OdGeMatrix3d &xfm)
Definition: GeExtents3d.h:343
ex_minmax
#define ex_minmax(max, min, val)
Definition: GeExtents3d.h:287
OdGeExtents3d::kIntersectOpOut
@ kIntersectOpOut
Definition: GeExtents3d.h:166
OdGeExtents2d
Definition: GeExtents2d.h:43
OdGeMatrix3d
Definition: GeMatrix3d.h:73
OdGeExtents3d::minPoint
const OdGePoint3d & minPoint() const
Definition: GeExtents3d.h:237
OdGeExtents2d::m_min
OdGePoint2d m_min
Definition: GeExtents2d.h:268
OdGeExtents3d::isDisjoint
bool isDisjoint(const OdGeExtents3d &extents, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents3d.h:382
OdGeExtents3d::kIntersectOpIn
@ kIntersectOpIn
Definition: GeExtents3d.h:165
OdGeExtents2d::expandBy
void expandBy(const OdGeVector2d &vect)
Definition: GeExtents2d.h:154
OdGeExtents3d::intersectWith
IntersectionStatus intersectWith(const OdGeExtents3d &extents, OdGeExtents3d *pResult=0) const
OdGeVector3d::kZAxis
static GE_STATIC_EXPORT const OdGeVector3d kZAxis
Definition: GeVector3d.h:91
OdGePoint3d
Definition: GePoint3d.h:55
OdDAI::operator!=
bool DAI_EXPORT operator!=(const OdDAI::OdSelect &left, const OdDAI::OdSelect &right)
OdGeExtents3d::expandBy
void expandBy(const OdGeVector3d &vect)
Definition: GeExtents3d.h:334
OdGeExtents3d::center
OdGePoint3d center() const
Definition: GeExtents3d.h:190
OdGeExtents2d::transformBy
void transformBy(const OdGeMatrix2d &xfm)
Definition: GeExtents2d.h:172
OdGeExtents2d::minPoint
const OdGePoint2d & minPoint() const
Definition: GeExtents2d.h:67
OdGeExtents3d::isEqualTo
bool isEqualTo(const OdGeExtents3d &extents, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents3d.h:394
FacetModelerProfile2DBool::max
const T & max(const T &x, const T &y)
Definition: FMImpProfile2DBool.h:105
OdGeExtents3d::set
void set(const OdGePoint3d &min, const OdGePoint3d &max)
Definition: GeExtents3d.h:247
OdGeExtents2d::m_max
OdGePoint2d m_max
Definition: GeExtents2d.h:269
OdGeExtents3d::convert2d
void convert2d(OdGeExtents2d &extents, Convert2dPlane plane=kConvert2dPlaneXY) const
TD_PackPush.h
GeVector3d.h
OdGeExtents3d::addExt
void addExt(const OdGeExtents3d &extents)
Definition: GeExtents3d.h:306
OdGeExtents2d::contains
bool contains(const OdGePoint2d &point) const
Definition: GeExtents2d.h:192
OdGeExtents3d::m_max
OdGePoint3d m_max
Definition: GeExtents3d.h:220
OdGeExtents3d::maxPoint
const OdGePoint3d & maxPoint() const
Definition: GeExtents3d.h:242
OdGePoint3d::z
double z
Definition: GePoint3d.h:369
OdGeExtents2d::maxPoint
const OdGePoint2d & maxPoint() const
Definition: GeExtents2d.h:73
OdGeExtents3d::contains
bool contains(const OdGePoint3d &point, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents3d.h:358
ODA_ASSERT
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
OdGeContext::gTol
static GE_STATIC_EXPORT OdGeTol gTol
Definition: GeGbl.h:60
OdGeExtents3d
Definition: GeExtents3d.h:45
OdGeVector3d::kYAxis
static GE_STATIC_EXPORT const OdGeVector3d kYAxis
Definition: GeVector3d.h:90
OdGeExtents3d::addPoint
void addPoint(const OdGePoint3d &point)
Definition: GeExtents3d.h:291
OdDAI::operator==
bool DAI_EXPORT operator==(const OdFileDescriptionAuto &left, const OdFileDescriptionAuto &right)
OdGeExtents2d::addExt
void addExt(const OdGeExtents2d &extents)
Definition: GeExtents2d.h:128
OdGeExtents3d::OdGeExtents3d
OdGeExtents3d()
Definition: GeExtents3d.h:225
OdGePoint3d::isEqualTo
bool isEqualTo(const OdGePoint3d &point, const OdGeTol &tol=OdGeContext::gTol) const
OdGeExtents3d::kIntersectUnknown
@ kIntersectUnknown
Definition: GeExtents3d.h:163
OdGeExtents3d::Convert2dPlane
Convert2dPlane
Definition: GeExtents3d.h:196
OdGeExtents2d::kIntersectOk
@ kIntersectOk
Definition: GeExtents2d.h:226
GE_STATIC_EXPORT
#define GE_STATIC_EXPORT
Definition: GeExport.h:53
OdGeExtents3d::m_min
OdGePoint3d m_min
Definition: GeExtents3d.h:219
OdGeExtents3d::kInvalid
static GE_STATIC_EXPORT const OdGeExtents3d kInvalid
Definition: GeExtents3d.h:60
OdGeTol
Definition: GeTol.h:49
GeMatrix3d.h
OdGeVector3d::y
double y
Definition: GeVector3d.h:602
OdGeExtents2d::isDisjoint
bool isDisjoint(const OdGeExtents2d &extents) const
Definition: GeExtents2d.h:213
OdNonZero
bool OdNonZero(double x, double tol=1.e-10)
Definition: OdaDefs.h:518
OdGeExtents2d::comparingSet
void comparingSet(const OdGePoint2d &pt1, const OdGePoint2d &pt2)
Definition: GeExtents2d.h:274
OdGePoint2d::x
double x
Definition: GePoint2d.h:299