CFx SDK Documentation  2023 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  //FELIX_CHANGE_BEGIN
223  {
224  return m_max - m_min;
225  }
227  const OdGeExtents3d& extents, const OdGeTol& tol = OdGeContext::gTol) const;
228 
229  double distanceTo(const OdGePoint3d& iPoint) const;
230 
232  const OdGePoint3dArray& points);
233  //FELIX_CHANGE_END
234 
235 protected:
238 };
239 
240 // Inline implementations
241 
245 {
246 }
247 
249  : m_min(min)
250  , m_max(max)
251 {
252 }
253 
255 {
256  return m_min;
257 }
258 
260 {
261  return m_max;
262 }
263 
264 inline void OdGeExtents3d::set(const OdGePoint3d& min, const OdGePoint3d& max)
265 {
266  m_min = min;
267  m_max = max;
268 }
269 
270 inline void OdGeExtents3d::comparingSet(const OdGePoint3d& pt1, const OdGePoint3d& pt2)
271 {
272  if(pt1.x > pt2.x)
273  {
274  m_max.x = pt1.x;
275  m_min.x = pt2.x;
276  }
277  else
278  {
279  m_min.x = pt1.x;
280  m_max.x = pt2.x;
281  }
282  if(pt1.y > pt2.y)
283  {
284  m_max.y = pt1.y;
285  m_min.y = pt2.y;
286  }
287  else
288  {
289  m_min.y = pt1.y;
290  m_max.y = pt2.y;
291  }
292  if(pt1.z > pt2.z)
293  {
294  m_max.z = pt1.z;
295  m_min.z = pt2.z;
296  }
297  else
298  {
299  m_min.z = pt1.z;
300  m_max.z = pt2.z;
301  }
302 }
303 
304 #define ex_minmax(max, min, val) \
305  if (max < val) max = val;\
306  else if (min > val) min = val;
307 
308 inline void OdGeExtents3d::addPoint(const OdGePoint3d& point)
309 {
310  if ((m_max.x < m_min.x) || (m_max.y < m_min.y) || (m_max.z < m_min.z))
311  {
312  m_max = m_min = point;
313  }
314  else
315  {
316  ex_minmax(m_max.x, m_min.x, point.x);
317  ex_minmax(m_max.y, m_min.y, point.y);
318  ex_minmax(m_max.z, m_min.z, point.z);
319  }
320 }
321 #undef ex_minmax
322 
323 inline void OdGeExtents3d::addExt(const OdGeExtents3d& extents)
324 {
325  ODA_ASSERT(extents.isValidExtents());
326 
327 #if 0
328  addPoint(extents.minPoint());
329  addPoint(extents.maxPoint());
330 #else
331  // Optimization
332 #define ex_minmax(max, min, valMax, valMin) \
333  if (max < valMax) max = valMax; \
334  if (min > valMin) min = valMin;
335 
336  if ((m_max.x < m_min.x) || (m_max.y < m_min.y) || (m_max.z < m_min.z))
337  {
338  set(extents.minPoint(), extents.maxPoint());
339  }
340  else
341  {
342  ex_minmax(m_max.x, m_min.x, extents.maxPoint().x, extents.minPoint().x);
343  ex_minmax(m_max.y, m_min.y, extents.maxPoint().y, extents.minPoint().y);
344  ex_minmax(m_max.z, m_min.z, extents.maxPoint().z, extents.minPoint().z);
345  }
346 
347 #undef ex_minmax
348 #endif
349 }
350 
351 inline void OdGeExtents3d::expandBy(const OdGeVector3d& vect)
352 {
354 
355  OdGePoint3d p1 = m_min, p2 = m_max;
356  addPoint(p1 + vect);
357  addPoint(p2 + vect);
358 }
359 
361 {
363 
364  OdGeVector3d d = m_max - m_min;
365 
366  m_max = m_min = (xfm * m_min);
367  if(OdNonZero(d.x, 1.e-200))
368  expandBy(xfm * (OdGeVector3d::kXAxis * d.x));
369  if(OdNonZero(d.y, 1.e-200))
370  expandBy(xfm * (OdGeVector3d::kYAxis * d.y));
371  if(OdNonZero(d.z, 1.e-200))
372  expandBy(xfm * (OdGeVector3d::kZAxis * d.z));
373 }
374 
375 inline bool OdGeExtents3d::contains(const OdGePoint3d& point, const OdGeTol& tol) const
376 {
378 
379  return ( (point.x + tol.equalPoint()) >= m_min.x
380  && (point.y + tol.equalPoint()) >= m_min.y
381  && (point.z + tol.equalPoint()) >= m_min.z
382  && (point.x - tol.equalPoint()) <= m_max.x
383  && (point.y - tol.equalPoint()) <= m_max.y
384  && (point.z - tol.equalPoint()) <= m_max.z );
385 }
386 
387 inline bool OdGeExtents3d::contains(const OdGeExtents3d& extents, const OdGeTol& tol) const
388 {
390 
391  return ((extents.m_min.x + tol.equalPoint()) >= m_min.x
392  && (extents.m_min.y + tol.equalPoint()) >= m_min.y
393  && (extents.m_min.z + tol.equalPoint()) >= m_min.z
394  && m_max.x >= (extents.m_max.x - tol.equalPoint())
395  && m_max.y >= (extents.m_max.y - tol.equalPoint())
396  && m_max.z >= (extents.m_max.z - tol.equalPoint()));
397 }
398 
399 inline bool OdGeExtents3d::isDisjoint(const OdGeExtents3d& extents, const OdGeTol& tol) const
400 {
402 
403  return ((extents.m_min.x - tol.equalPoint()) > m_max.x
404  || (extents.m_min.y - tol.equalPoint()) > m_max.y
405  || (extents.m_min.z - tol.equalPoint()) > m_max.z
406  || m_min.x > (extents.m_max.x + tol.equalPoint())
407  || m_min.y > (extents.m_max.y + tol.equalPoint())
408  || m_min.z > (extents.m_max.z + tol.equalPoint()));
409 }
410 
411 inline bool OdGeExtents3d::isEqualTo(const OdGeExtents3d& extents, const OdGeTol& tol) const
412 {
413  const OdUInt8 bValid = ((isValidExtents()) ? 1 : 0) | ((extents.isValidExtents()) ? 2 : 0);
414  switch (bValid)
415  {
416  // Both invalid
417  case 0: return true;
418  // Both valid
419  case 3: return m_min.isEqualTo(extents.m_min, tol) && m_max.isEqualTo(extents.m_max, tol);
420  }
421  return false;
422 }
423 
424 #undef INVALIDEXTENTS
425 
426 #include "TD_PackPop.h"
427 
428 #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:304
#define INVALIDEXTENTS
Definition: GeExtents3d.h:35
unsigned char OdUInt8
bool OdNonZero(double x, double tol=1.e-10)
Definition: OdaDefs.h:520
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:399
IntersectionStatus intersectWith(const OdGeExtents3d &extents, OdGeExtents3d *pResult=0) const
OdGePoint3d m_max
Definition: GeExtents3d.h:237
void addExt(const OdGeExtents3d &extents)
Definition: GeExtents3d.h:323
void addPoint(const OdGePoint3d &point)
Definition: GeExtents3d.h:308
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:411
bool isValidExtents() const
Definition: GeExtents3d.h:120
double distanceTo(const OdGePoint3d &iPoint) const
OdGeExtents3d & addPoints(const OdGePoint3dArray &points)
OdGePoint3d m_min
Definition: GeExtents3d.h:236
OdGeVector3d diagonal() const
Definition: GeExtents3d.h:222
void set(const OdGePoint3d &min, const OdGePoint3d &max)
Definition: GeExtents3d.h:264
void convert2d(OdGeExtents2d &extents, Convert2dPlane plane=kConvert2dPlaneXY) const
void expandBy(const OdGeVector3d &vect)
Definition: GeExtents3d.h:351
const OdGePoint3d & maxPoint() const
Definition: GeExtents3d.h:259
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:375
void transformBy(const OdGeMatrix3d &xfm)
Definition: GeExtents3d.h:360
const OdGePoint3d & minPoint() const
Definition: GeExtents3d.h:254
void comparingSet(const OdGePoint3d &pt1, const OdGePoint3d &pt2)
Definition: GeExtents3d.h:270
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
bool operator==(const BlockRefPath &rA, const BlockRefPath &rB)
DOM.
bool operator!=(const BlockRefPath &rA, const BlockRefPath &rB)
DOM.
const T & min(const T &x, const T &y)
const T & max(const T &x, const T &y)
static GE_STATIC_EXPORT OdGeTol gTol
Definition: GeGbl.h:60