CFx SDK Documentation  2022 SP0
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
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_
#define ODA_ASSERT_ONCE(exp)
Definition: DebugStuff.h:51
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
tol
Definition: DimVarDefs.h:2287
#define GE_TOOLKIT_EXPORT
Definition: GeExport.h:49
#define GE_STATIC_EXPORT
Definition: GeExport.h:53
#define ex_minmax(max, min, val)
Definition: GeExtents3d.h:287
#define INVALIDEXTENTS
Definition: GeExtents3d.h:35
unsigned char OdUInt8
bool OdNonZero(double x, double tol=1.e-10)
Definition: OdaDefs.h:518
static GE_STATIC_EXPORT const OdGeExtents3d kInvalid
Definition: GeExtents3d.h:60
bool isDisjoint(const OdGeExtents3d &extents, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents3d.h:382
IntersectionStatus intersectWith(const OdGeExtents3d &extents, OdGeExtents3d *pResult=0) const
OdGePoint3d m_max
Definition: GeExtents3d.h:220
void addExt(const OdGeExtents3d &extents)
Definition: GeExtents3d.h:306
void addPoint(const OdGePoint3d &point)
Definition: GeExtents3d.h:291
OdGePoint3d center() const
Definition: GeExtents3d.h:190
void setFrom2d(const OdGeExtents2d &extents, Convert2dPlane plane=kConvert2dPlaneXY)
bool isEqualTo(const OdGeExtents3d &extents, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents3d.h:394
bool isValidExtents() const
Definition: GeExtents3d.h:120
OdGePoint3d m_min
Definition: GeExtents3d.h:219
void set(const OdGePoint3d &min, const OdGePoint3d &max)
Definition: GeExtents3d.h:247
void convert2d(OdGeExtents2d &extents, Convert2dPlane plane=kConvert2dPlaneXY) const
void expandBy(const OdGeVector3d &vect)
Definition: GeExtents3d.h:334
const OdGePoint3d & maxPoint() const
Definition: GeExtents3d.h:242
bool contains(const OdGePoint3d &point, const OdGeTol &tol=OdGeContext::gTol) const
Definition: GeExtents3d.h:358
void transformBy(const OdGeMatrix3d &xfm)
Definition: GeExtents3d.h:343
const OdGePoint3d & minPoint() const
Definition: GeExtents3d.h:237
void comparingSet(const OdGePoint3d &pt1, const OdGePoint3d &pt2)
Definition: GeExtents3d.h:253
bool isEqualTo(const OdGePoint3d &point, const OdGeTol &tol=OdGeContext::gTol) const
double z
Definition: GePoint3d.h:369
double y
Definition: GePoint3d.h:368
double x
Definition: GePoint3d.h:367
Definition: GeTol.h:49
static GE_STATIC_EXPORT const OdGeVector3d kZAxis
Definition: GeVector3d.h:91
static GE_STATIC_EXPORT const OdGeVector3d kYAxis
Definition: GeVector3d.h:90
static GE_STATIC_EXPORT const OdGeVector3d kXAxis
Definition: GeVector3d.h:89
const T & min(const T &x, const T &y)
const T & max(const T &x, const T &y)
bool DAI_EXPORT operator!=(const OdDAI::OdSelect &left, const OdDAI::OdSelect &right)
bool DAI_EXPORT operator==(const OdFileDescriptionAuto &left, const OdFileDescriptionAuto &right)
static GE_STATIC_EXPORT OdGeTol gTol
Definition: GeGbl.h:60