AGX Dynamics  2.37.2.0
BoundingAABB.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXCOLLIDE_BOUNDINGAABB_H
18 #define AGXCOLLIDE_BOUNDINGAABB_H
19 
20 #include <agx/agxPhysics_export.h>
21 
22 #include <agx/agx.h>
23 #include <agx/Vec3.h>
24 #include <agx/AffineMatrix4x4.h>
25 #include <agx/Bound.h>
26 #include <agxData/Type.h>
27 
28 #include <iosfwd>
29 
30 
31 namespace agxCollide
32 {
33 
38  {
39  public:
41  BoundingAABB();
42 
50  BoundingAABB(const agx::Vec3& min, const agx::Vec3& max);
51 
59 
63  void reset();
64 
71  void set(const agx::Bound3& other, const agx::AffineMatrix4x4& transform);
72 
77  void expand(const agx::Bound3& other);
78 
83  void expand(const agx::Vec3& point);
84 
93  void expand(const agx::Vec3& otherMin, const agx::Vec3& otherMax);
94 
102  void expand(const agx::Bound3& other, const agx::AffineMatrix4x4& transform);
103 
112  void expand(const agx::Vec3& otherMin, const agx::Vec3& otherMax, const agx::AffineMatrix4x4& transform);
113 
119  bool hasOverlap(const BoundingAABB* other) const;
120 
128  bool testSphereOverlap(const agx::Vec3& pos, agx::Real radius) const;
129 
133  bool isCleared() const;
134 
135  using agx::Bound3::set;
137  };
138 
139 #ifndef SWIG
140  static_assert(sizeof(agx::Bound3) == sizeof(BoundingAABB), "Size mismatch");
141 #endif
142 
143 
144 
145  /* Implementation */
147  {
148  reset();
149  }
150 
151 
153  {
154  }
155 
156 
158  {
159  this->reset();
160  this->expand(other, transform);
161  }
162 
163 
165  {
166  this->reset();
167  this->expand(other, transform);
168  }
169 
170 
172  {
173  min().set(agx::RealMax);
174  max().set(-agx::RealMax);
175  }
176 
177 
179  {
180  return min()[0] > max()[0];
181  }
182 
183 
185  {
186  expand(other.min(), other.max());
187  }
188 
189 
191  {
192  expand(point, point);
193  }
194 
195 
196  AGX_FORCE_INLINE void BoundingAABB::expand(const agx::Vec3& otherMin, const agx::Vec3& otherMax)
197  {
198  min() = agx::Vec3::componentMin(min(), otherMin);
199  max() = agx::Vec3::componentMax(max(), otherMax);
200  }
201 
202 
204  {
205  expand( other.min(), other.max(), transform );
206  }
207 
208 
210  {
211  return agx::Bound3::hasOverlap(*other);
212  }
213 
214 
216  {
217  const bool retval =
218  pos[0] > (min()[0] - radius) && pos[1] > (min()[1] - radius) && pos[2] > (min()[2] - radius) &&
219  pos[0] < (max()[0] + radius) && pos[1] < (max()[1] + radius) && pos[2] < (max()[2] + radius);
220  return retval;
221  }
222 
223 
224  inline std::ostream& operator << ( std::ostream& output, const BoundingAABB& bound )
225  {
226  output << "min(): " << bound.min() << ", max(): " << bound.max();
227  return output;
228  }
229 
230 }
231 
233 
234 #endif
Vec3T< T > min(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:861
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:855
This namespace consists of a set of classes for handling geometric intersection tests including boole...
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
const Vec3 & max() const
Definition: Bound.h:255
#define AGXPHYSICS_EXPORT
void reset()
Removes any extent of the bound.
Definition: BoundingAABB.h:171
void set(const Vec3 &min, const Vec3 &max)
Relocate the bound to the new location.
Definition: Bound.h:264
bool isCleared() const
Is the bounding volume cleared? Will be true e.g.
Definition: BoundingAABB.h:178
#define AGX_FORCE_INLINE
Definition: Object.h:59
BoundingAABB()
Creates an empty bounding volume. isCleared() will return &#39;true&#39;.
Definition: BoundingAABB.h:146
bool hasOverlap(const BoundT &other) const
Definition: Bound.h:304
std::ostream & operator<<(std::ostream &output, const BoundingAABB &bound)
Definition: BoundingAABB.h:224
void set(T x, T y, T z)
Definition: Vec3Template.h:459
void expand(const agx::Bound3 &other)
Expands a bounding volume to contain both itself and another bound.
Definition: BoundingAABB.h:184
void set(const agx::Bound3 &other, const agx::AffineMatrix4x4 &transform)
Sets a bounding volume given a bounding volume given in another coordinate-system.
Definition: BoundingAABB.h:164
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
BoundT< Vec3 > Bound3
Definition: Bound.h:147
bool hasOverlap(const BoundingAABB *other) const
Tests if the bound intersects with another bounding volume.
Definition: BoundingAABB.h:209
static Vec3T componentMax(const Vec3T &v1, const Vec3T &v2)
Creates a new vector where each component is the maximum of this and the other vector.
Definition: Vec3Template.h:385
const Vec3 & min() const
Definition: Bound.h:252
AGXCORE_EXPORT const Real RealMax
double Real
Definition: Real.h:42
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:37
bool testSphereOverlap(const agx::Vec3 &pos, agx::Real radius) const
Test if a sphere overlaps the bound.
Definition: BoundingAABB.h:215
static Vec3T componentMin(const Vec3T &v1, const Vec3T &v2)
Creates a new vector where each component is the minimum of this and the other vector.
Definition: Vec3Template.h:379