PxBounds3.h
Go to the documentation of this file.
1 //
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions
4 // are met:
5 // * Redistributions of source code must retain the above copyright
6 // notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright
8 // notice, this list of conditions and the following disclaimer in the
9 // documentation and/or other materials provided with the distribution.
10 // * Neither the name of NVIDIA CORPORATION nor the names of its
11 // contributors may be used to endorse or promote products derived
12 // from this software without specific prior written permission.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29 
30 #ifndef PXFOUNDATION_PXBOUNDS3_H
31 #define PXFOUNDATION_PXBOUNDS3_H
32 
37 #include "foundation/PxTransform.h"
38 #include "foundation/PxMat33.h"
39 
40 #if !PX_DOXYGEN
41 namespace physx
42 {
43 #endif
44 
45 // maximum extents defined such that floating point exceptions are avoided for standard use cases
46 #define PX_MAX_BOUNDS_EXTENTS (PX_MAX_REAL * 0.25f)
47 
58 class PxBounds3
59 {
60  public:
66  {
67  }
68 
72  PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3(const PxVec3& minimum, const PxVec3& maximum);
73 
78 
84  static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 boundsOfPoints(const PxVec3& v0, const PxVec3& v1);
85 
91  static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 centerExtents(const PxVec3& center, const PxVec3& extent);
92 
97  basisExtent(const PxVec3& center, const PxMat33& basis, const PxVec3& extent);
98 
102  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 poseExtent(const PxTransform& pose, const PxVec3& extent);
103 
112  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transformSafe(const PxMat33& matrix, const PxBounds3& bounds);
113 
122  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transformFast(const PxMat33& matrix, const PxBounds3& bounds);
123 
132  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transformSafe(const PxTransform& transform, const PxBounds3& bounds);
133 
142  static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transformFast(const PxTransform& transform, const PxBounds3& bounds);
143 
147  PX_CUDA_CALLABLE PX_FORCE_INLINE void setEmpty();
148 
152  PX_CUDA_CALLABLE PX_FORCE_INLINE void setMaximal();
153 
158  PX_CUDA_CALLABLE PX_FORCE_INLINE void include(const PxVec3& v);
159 
164  PX_CUDA_CALLABLE PX_FORCE_INLINE void include(const PxBounds3& b);
165 
166  PX_CUDA_CALLABLE PX_FORCE_INLINE bool isEmpty() const;
167 
172  PX_CUDA_CALLABLE PX_FORCE_INLINE bool intersects(const PxBounds3& b) const;
173 
179  PX_CUDA_CALLABLE PX_FORCE_INLINE bool intersects1D(const PxBounds3& a, uint32_t axis) const;
180 
185  PX_CUDA_CALLABLE PX_FORCE_INLINE bool contains(const PxVec3& v) const;
186 
191  PX_CUDA_CALLABLE PX_FORCE_INLINE bool isInside(const PxBounds3& box) const;
192 
196  PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getCenter() const;
197 
201  PX_CUDA_CALLABLE PX_FORCE_INLINE float getCenter(uint32_t axis) const;
202 
206  PX_CUDA_CALLABLE PX_FORCE_INLINE float getExtents(uint32_t axis) const;
207 
211  PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getDimensions() const;
212 
216  PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getExtents() const;
217 
225  PX_CUDA_CALLABLE PX_FORCE_INLINE void scaleSafe(float scale);
226 
234  PX_CUDA_CALLABLE PX_FORCE_INLINE void scaleFast(float scale);
235 
241  PX_CUDA_CALLABLE PX_FORCE_INLINE void fattenSafe(float distance);
242 
248  PX_CUDA_CALLABLE PX_FORCE_INLINE void fattenFast(float distance);
249 
254 
258  PX_CUDA_CALLABLE PX_FORCE_INLINE bool isValid() const;
259 
260  PxVec3 minimum, maximum;
261 };
262 
264 : minimum(minimum_), maximum(maximum_)
265 {
266 }
267 
269 {
271 }
272 
274 {
275  return minimum.isFinite() && maximum.isFinite();
276 }
277 
279 {
280  return PxBounds3(v0.minimum(v1), v0.maximum(v1));
281 }
282 
284 {
285  return PxBounds3(center - extent, center + extent);
286 }
287 
289 PxBounds3::basisExtent(const PxVec3& center, const PxMat33& basis, const PxVec3& extent)
290 {
291  // extended basis vectors
292  PxVec3 c0 = basis.column0 * extent.x;
293  PxVec3 c1 = basis.column1 * extent.y;
294  PxVec3 c2 = basis.column2 * extent.z;
295 
296  PxVec3 w;
297  // find combination of base vectors that produces max. distance for each component = sum of abs()
298  w.x = PxAbs(c0.x) + PxAbs(c1.x) + PxAbs(c2.x);
299  w.y = PxAbs(c0.y) + PxAbs(c1.y) + PxAbs(c2.y);
300  w.z = PxAbs(c0.z) + PxAbs(c1.z) + PxAbs(c2.z);
301 
302  return PxBounds3(center - w, center + w);
303 }
304 
306 {
307  return basisExtent(pose.p, PxMat33(pose.q), extent);
308 }
309 
311 {
314 }
315 
317 {
320 }
321 
323 {
325  minimum = minimum.minimum(v);
326  maximum = maximum.maximum(v);
327 }
328 
330 {
334 }
335 
337 {
339  return minimum.x > maximum.x;
340 }
341 
343 {
344  PX_SHARED_ASSERT(isValid() && b.isValid());
345  return !(b.minimum.x > maximum.x || minimum.x > b.maximum.x || b.minimum.y > maximum.y || minimum.y > b.maximum.y ||
346  b.minimum.z > maximum.z || minimum.z > b.maximum.z);
347 }
348 
350 {
351  PX_SHARED_ASSERT(isValid() && a.isValid());
352  return maximum[axis] >= a.minimum[axis] && a.maximum[axis] >= minimum[axis];
353 }
354 
356 {
358 
359  return !(v.x < minimum.x || v.x > maximum.x || v.y < minimum.y || v.y > maximum.y || v.z < minimum.z ||
360  v.z > maximum.z);
361 }
362 
364 {
365  PX_SHARED_ASSERT(isValid() && box.isValid());
366  if(box.minimum.x > minimum.x)
367  return false;
368  if(box.minimum.y > minimum.y)
369  return false;
370  if(box.minimum.z > minimum.z)
371  return false;
372  if(box.maximum.x < maximum.x)
373  return false;
374  if(box.maximum.y < maximum.y)
375  return false;
376  if(box.maximum.z < maximum.z)
377  return false;
378  return true;
379 }
380 
382 {
384  return (minimum + maximum) * 0.5f;
385 }
386 
388 {
390  return (minimum[axis] + maximum[axis]) * 0.5f;
391 }
392 
394 {
396  return (maximum[axis] - minimum[axis]) * 0.5f;
397 }
398 
400 {
402  return maximum - minimum;
403 }
404 
406 {
408  return getDimensions() * 0.5f;
409 }
410 
412 {
414  if(!isEmpty())
415  scaleFast(scale);
416 }
417 
419 {
421  *this = centerExtents(getCenter(), getExtents() * scale);
422 }
423 
425 {
427  if(!isEmpty())
428  fattenFast(distance);
429 }
430 
432 {
434  minimum.x -= distance;
435  minimum.y -= distance;
436  minimum.z -= distance;
437 
438  maximum.x += distance;
439  maximum.y += distance;
440  maximum.z += distance;
441 }
442 
444 {
445  PX_SHARED_ASSERT(bounds.isValid());
446  return !bounds.isEmpty() ? transformFast(matrix, bounds) : bounds;
447 }
448 
450 {
451  PX_SHARED_ASSERT(bounds.isValid());
452  return PxBounds3::basisExtent(matrix * bounds.getCenter(), matrix, bounds.getExtents());
453 }
454 
456 {
457  PX_SHARED_ASSERT(bounds.isValid());
458  return !bounds.isEmpty() ? transformFast(transform, bounds) : bounds;
459 }
460 
462 {
463  PX_SHARED_ASSERT(bounds.isValid());
464  return PxBounds3::basisExtent(transform.transform(bounds.getCenter()), PxMat33(transform.q), bounds.getExtents());
465 }
466 
468 {
469  return (isFinite() && (((minimum.x <= maximum.x) && (minimum.y <= maximum.y) && (minimum.z <= maximum.z)) ||
473 }
474 
475 #if !PX_DOXYGEN
476 } // namespace physx
477 #endif
478 
480 #endif // #ifndef PXFOUNDATION_PXBOUNDS3_H
Definition: GuContactBuffer.h:37
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isEmpty() const
Definition: PxBounds3.h:336
PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
returns true if all 3 elems of the vector are finite (not NAN or INF, etc.)
Definition: PxVec3.h:156
PX_CUDA_CALLABLE PX_FORCE_INLINE void setEmpty()
Sets empty to true.
Definition: PxBounds3.h:310
static PX_CUDA_CALLABLE PX_INLINE PxBounds3 poseExtent(const PxTransform &pose, const PxVec3 &extent)
Construct from pose and extent.
Definition: PxBounds3.h:305
PxVec3 minimum
Definition: PxBounds3.h:260
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:351
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 minimum(const PxVec3 &v) const
element-wise minimum
Definition: PxVec3.h:344
static PX_CUDA_CALLABLE PX_INLINE PxBounds3 basisExtent(const PxVec3 &center, const PxMat33 &basis, const PxVec3 &extent)
Construct from center, extent, and (not necessarily orthogonal) basis.
Definition: PxBounds3.h:289
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getCenter() const
returns the center of this axis aligned box.
Definition: PxBounds3.h:381
PX_CUDA_CALLABLE PX_FORCE_INLINE void setMaximal()
Sets the bounds to maximum size [-PX_MAX_BOUNDS_EXTENTS, PX_MAX_BOUNDS_EXTENTS].
Definition: PxBounds3.h:316
PxQuat q
Definition: PxTransform.h:51
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isInside(const PxBounds3 &box) const
checks a box is inside another box.
Definition: PxBounds3.h:363
#define PX_SHARED_ASSERT(exp)
Definition: PxSharedAssert.h:39
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 centerExtents(const PxVec3 &center, const PxVec3 &extent)
returns the AABB from center and extents vectors.
Definition: PxBounds3.h:283
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 empty()
Return empty bounds.
Definition: PxBounds3.h:268
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite(float a)
platform-specific finiteness check (not INF or NAN)
Definition: PxUnixIntrinsics.h:127
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getExtents() const
returns the extents, which are half of the width/height/depth.
Definition: PxBounds3.h:405
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite() const
Definition: PxBounds3.h:273
PX_CUDA_CALLABLE PX_FORCE_INLINE void fattenFast(float distance)
Definition: PxBounds3.h:431
PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3()
Default constructor, not performing any initialization for performance reason.
Definition: PxBounds3.h:65
static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transformFast(const PxMat33 &matrix, const PxBounds3 &bounds)
gets the transformed bounds of the passed AABB (resulting in a bigger AABB).
Definition: PxBounds3.h:449
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 transform(const PxVec3 &input) const
Definition: PxTransform.h:111
float y
Definition: PxVec3.h:381
PX_CUDA_CALLABLE PX_FORCE_INLINE void scaleSafe(float scale)
scales the AABB.
Definition: PxBounds3.h:411
static PX_CUDA_CALLABLE PX_INLINE PxBounds3 transformSafe(const PxMat33 &matrix, const PxBounds3 &bounds)
gets the transformed bounds of the passed AABB (resulting in a bigger AABB).
Definition: PxBounds3.h:443
class representing a rigid euclidean transform as a quaternion and a vector
Definition: PxTransform.h:48
PX_CUDA_CALLABLE PX_FORCE_INLINE void include(const PxVec3 &v)
expands the volume to include v
Definition: PxBounds3.h:322
PX_CUDA_CALLABLE PX_FORCE_INLINE float PxAbs(float a)
abs returns the absolute value of its argument.
Definition: PxMath.h:107
#define PX_MAX_BOUNDS_EXTENTS
Definition: PxBounds3.h:46
PxVec3 column2
Definition: PxMat33.h:353
3x3 matrix class
Definition: PxMat33.h:90
Class representing 3D range or axis aligned bounding box.
Definition: PxBounds3.h:58
PxVec3 column0
Definition: PxMat33.h:353
static PX_CUDA_CALLABLE PX_FORCE_INLINE PxBounds3 boundsOfPoints(const PxVec3 &v0, const PxVec3 &v1)
returns the AABB containing v0 and v1.
Definition: PxBounds3.h:278
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 maximum(const PxVec3 &v) const
element-wise maximum
Definition: PxVec3.h:360
PX_CUDA_CALLABLE PX_FORCE_INLINE void scaleFast(float scale)
scales the AABB.
Definition: PxBounds3.h:418
PX_CUDA_CALLABLE PX_FORCE_INLINE bool contains(const PxVec3 &v) const
indicates if these bounds contain v.
Definition: PxBounds3.h:355
PxU8 box[sizeof(PxBoxGeometry)]
Definition: PxGeometryHelpers.h:216
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isValid() const
Definition: PxBounds3.h:467
PX_CUDA_CALLABLE PX_FORCE_INLINE bool intersects(const PxBounds3 &b) const
indicates whether the intersection of this and b is empty or not.
Definition: PxBounds3.h:342
PX_CUDA_CALLABLE PX_FORCE_INLINE bool intersects1D(const PxBounds3 &a, uint32_t axis) const
computes the 1D-intersection between two AABBs, on a given axis.
Definition: PxBounds3.h:349
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 getDimensions() const
returns the dimensions (width/height/depth) of this axis aligned box.
Definition: PxBounds3.h:399
PX_CUDA_CALLABLE PX_FORCE_INLINE void fattenSafe(float distance)
Definition: PxBounds3.h:424
PX_CUDA_CALLABLE PX_FORCE_INLINE float getExtents(uint32_t axis) const
get component of the box&#39;s extents along a given axis
Definition: PxBounds3.h:393
float z
Definition: PxVec3.h:381
PxVec3 column1
Definition: PxMat33.h:353
#define PX_INLINE
Definition: PxPreprocessor.h:336
#define PX_CUDA_CALLABLE
Definition: PxPreprocessor.h:460
PxVec3 p
Definition: PxTransform.h:52
PxVec3 maximum
Definition: PxBounds3.h:260
3 Element vector class.
Definition: PxVec3.h:49
float x
Definition: PxVec3.h:381