30 #ifndef __optixu_optixu_aabb_namespace_h__
31 #define __optixu_optixu_aabb_namespace_h__
37 # define RT_AABB_ASSERT assert
39 # define RT_AABB_ASSERT(x)
45 # define OPTIXU_INLINE_DEFINED 1
46 # define OPTIXU_INLINE __forceinline__
47 #endif // OPTIXU_INLINE
81 RT_HOSTDEVICE
Aabb(
const float3& min,
const float3& max );
84 RT_HOSTDEVICE
Aabb(
const float3& v0,
const float3& v1,
const float3& v2 );
87 RT_HOSTDEVICE
bool operator==(
const Aabb& other )
const;
93 RT_HOSTDEVICE
const float3&
operator[](
int i )
const;
96 RT_HOSTDEVICE
void set(
const float3& min,
const float3& max );
99 RT_HOSTDEVICE
void set(
const float3& v0,
const float3& v1,
const float3& v2 );
105 RT_HOSTDEVICE
bool valid()
const;
108 RT_HOSTDEVICE
bool contains(
const float3& p )
const;
111 RT_HOSTDEVICE
bool contains(
const Aabb& bb )
const;
114 RT_HOSTDEVICE
void include(
const float3& p );
117 RT_HOSTDEVICE
void include(
const Aabb& other );
120 RT_HOSTDEVICE
void include(
const float3& min,
const float3& max );
123 RT_HOSTDEVICE float3
center()
const;
126 RT_HOSTDEVICE
float center(
int dim )
const;
129 RT_HOSTDEVICE float3
extent()
const;
132 RT_HOSTDEVICE
float extent(
int dim )
const;
135 RT_HOSTDEVICE
float volume()
const;
138 RT_HOSTDEVICE
float area()
const;
141 RT_HOSTDEVICE
float halfArea()
const;
150 RT_HOSTDEVICE
bool intersects(
const Aabb& other )
const;
156 RT_HOSTDEVICE
void enlarge(
float amount );
159 RT_HOSTDEVICE
bool isFlat()
const;
163 RT_HOSTDEVICE
float distance(
const float3& x )
const;
167 RT_HOSTDEVICE
float distance2(
const float3& x )
const;
186 OPTIXU_INLINE RT_HOSTDEVICE
Aabb::Aabb(
const float3& min,
const float3& max )
191 OPTIXU_INLINE RT_HOSTDEVICE
Aabb::Aabb(
const float3& v0,
const float3& v1,
const float3& v2 )
208 RT_AABB_ASSERT( i>=0 && i<=1 );
214 RT_AABB_ASSERT( i>=0 && i<=1 );
218 OPTIXU_INLINE RT_HOSTDEVICE
void Aabb::set(
const float3& min,
const float3& max )
224 OPTIXU_INLINE RT_HOSTDEVICE
void Aabb::set(
const float3& v0,
const float3& v1,
const float3& v2 )
226 m_min = fminf( v0, fminf(v1,v2) );
227 m_max = fmaxf( v0, fmaxf(v1,v2) );
232 m_min = make_float3( 1e37f );
233 m_max = make_float3( -1e37f );
267 OPTIXU_INLINE RT_HOSTDEVICE
void Aabb::include(
const float3& min,
const float3& max )
275 RT_AABB_ASSERT(
valid() );
281 RT_AABB_ASSERT(
valid() );
282 RT_AABB_ASSERT( dim>=0 && dim<=2 );
283 return ( ((
float*)(&
m_min))[dim] + ((
float*)(&
m_max))[dim] ) * 0.5f;
288 RT_AABB_ASSERT(
valid() );
294 RT_AABB_ASSERT(
valid() );
295 return ((
float*)(&
m_max))[dim] - ((
float*)(&
m_min))[dim];
300 RT_AABB_ASSERT(
valid() );
301 const float3 d =
extent();
312 RT_AABB_ASSERT(
valid() );
313 const float3 d =
extent();
314 return d.x*d.y + d.y*d.z + d.z*d.x;
319 RT_AABB_ASSERT(
valid() );
320 const float3 d =
extent();
323 return d.x > d.z ? 0 : 2;
324 return d.y > d.z ? 1 : 2;
352 RT_AABB_ASSERT(
valid() );
353 m_min -= make_float3( amount );
354 m_max += make_float3( amount );
374 float distance_x = fminf( x.x -
m_min.x,
m_max.x - x.x);
375 float distance_y = fminf( x.y -
m_min.y,
m_max.y - x.y);
376 float distance_z = fminf( x.z -
m_min.z,
m_max.z - x.z);
378 float min_distance = fminf(distance_x, fminf(distance_y, distance_z));
379 return -min_distance;
390 float3 v = x -
m_min;
402 else if( v.x > box_dims.x )
403 excess = v.x - box_dims.x;
404 dist2 += excess * excess;
409 else if( v.y > box_dims.y )
410 excess = v.y - box_dims.y;
411 dist2 += excess * excess;
416 else if( v.z > box_dims.z )
417 excess = v.z - box_dims.z;
418 dist2 += excess * excess;
425 #ifdef OPTIXU_INLINE_DEFINED
426 # undef OPTIXU_INLINE_DEFINED
427 # undef OPTIXU_INLINE
430 #undef RT_AABB_ASSERT
432 #endif // #ifndef __optixu_optixu_aabb_namespace_h__
Axis-aligned bounding box.
Definition: optixu_aabb_namespace.h:73
RT_HOSTDEVICE bool isFlat() const
Definition: optixu_aabb_namespace.h:357
RT_HOSTDEVICE bool operator==(const Aabb &other) const
Definition: optixu_aabb_namespace.h:196
RT_HOSTDEVICE int longestAxis() const
Definition: optixu_aabb_namespace.h:317
RT_HOSTDEVICE float area() const
Definition: optixu_aabb_namespace.h:305
RT_HOSTDEVICE void include(const float3 &p)
Definition: optixu_aabb_namespace.h:255
RT_HOSTDEVICE void invalidate()
Definition: optixu_aabb_namespace.h:230
RT_HOSTDEVICE bool contains(const float3 &p) const
Definition: optixu_aabb_namespace.h:243
RT_HOSTDEVICE Aabb()
Definition: optixu_aabb_namespace.h:181
RT_HOSTDEVICE bool valid() const
Definition: optixu_aabb_namespace.h:236
RT_HOSTDEVICE float3 center() const
Definition: optixu_aabb_namespace.h:273
RT_HOSTDEVICE float signedDistance(const float3 &x) const
Definition: optixu_aabb_namespace.h:369
RT_HOSTDEVICE float3 extent() const
Definition: optixu_aabb_namespace.h:286
RT_HOSTDEVICE float halfArea() const
Definition: optixu_aabb_namespace.h:310
float3 m_min
Definition: optixu_aabb_namespace.h:175
RT_HOSTDEVICE float distance2(const float3 &x) const
Definition: optixu_aabb_namespace.h:385
RT_HOSTDEVICE float3 & operator[](int i)
Definition: optixu_aabb_namespace.h:206
RT_HOSTDEVICE void intersection(const Aabb &other)
Definition: optixu_aabb_namespace.h:340
RT_HOSTDEVICE float maxExtent() const
Definition: optixu_aabb_namespace.h:327
RT_HOSTDEVICE bool intersects(const Aabb &other) const
Definition: optixu_aabb_namespace.h:332
RT_HOSTDEVICE float volume() const
Definition: optixu_aabb_namespace.h:298
RT_HOSTDEVICE void set(const float3 &min, const float3 &max)
Definition: optixu_aabb_namespace.h:218
RT_HOSTDEVICE float distance(const float3 &x) const
Definition: optixu_aabb_namespace.h:364
RT_HOSTDEVICE void enlarge(float amount)
Definition: optixu_aabb_namespace.h:350
float3 m_max
Definition: optixu_aabb_namespace.h:177