| 1 | // Copyright 2009-2021 Intel Corporation | 
| 2 | // SPDX-License-Identifier: Apache-2.0 | 
| 3 |  | 
| 4 | #pragma once | 
| 5 |  | 
| 6 | #include "bvh_node_base.h" | 
| 7 |  | 
| 8 | namespace embree | 
| 9 | { | 
| 10 |   template<typename NodeRef, int N> | 
| 11 |     struct OBBNodeMB_t : public BaseNode_t<NodeRef, N> | 
| 12 |   { | 
| 13 |     using BaseNode_t<NodeRef,N>::children; | 
| 14 |      | 
| 15 |     struct Create | 
| 16 |     { | 
| 17 |       __forceinline NodeRef operator() (const FastAllocator::CachedAllocator& alloc) const | 
| 18 |       { | 
| 19 |         OBBNodeMB_t* node = (OBBNodeMB_t*) alloc.malloc0(bytes: sizeof(OBBNodeMB_t),align: NodeRef::byteNodeAlignment); node->clear(); | 
| 20 |         return NodeRef::encodeNode(node); | 
| 21 |       } | 
| 22 |     }; | 
| 23 |      | 
| 24 |     struct Set | 
| 25 |     { | 
| 26 |       __forceinline void operator() (NodeRef node, size_t i, NodeRef child, const LinearSpace3fa& space, const LBBox3fa& lbounds, const BBox1f dt) const { | 
| 27 |         node.ungetAABBNodeMB()->setRef(i,child); | 
| 28 |         node.ungetAABBNodeMB()->setBounds(i,space,lbounds.global(dt)); | 
| 29 |       } | 
| 30 |     }; | 
| 31 |      | 
| 32 |     /*! Clears the node. */ | 
| 33 |     __forceinline void clear() | 
| 34 |     { | 
| 35 |       space0 = one; | 
| 36 |       //b0.lower = b0.upper = Vec3fa(nan); | 
| 37 |       b1.lower = b1.upper = Vec3fa(nan); | 
| 38 |       BaseNode_t<NodeRef,N>::clear(); | 
| 39 |     } | 
| 40 |      | 
| 41 |     /*! Sets space and bounding boxes. */ | 
| 42 |     __forceinline void setBounds(size_t i, const AffineSpace3fa& space, const LBBox3fa& lbounds) { | 
| 43 |       setBounds(i,space,lbounds.bounds0,lbounds.bounds1); | 
| 44 |     } | 
| 45 |      | 
| 46 |     /*! Sets space and bounding boxes. */ | 
| 47 |     __forceinline void setBounds(size_t i, const AffineSpace3fa& s0, const BBox3fa& a, const BBox3fa& c) | 
| 48 |     { | 
| 49 |       assert(i < N); | 
| 50 |        | 
| 51 |       AffineSpace3fa space = s0; | 
| 52 |       space.p -= a.lower; | 
| 53 |       Vec3fa scale = 1.0f/max(a: Vec3fa(1E-19f),b: a.upper-a.lower); | 
| 54 |       space = AffineSpace3fa::scale(s: scale)*space; | 
| 55 |       BBox3fa a1((a.lower-a.lower)*scale,(a.upper-a.lower)*scale); | 
| 56 |       BBox3fa c1((c.lower-a.lower)*scale,(c.upper-a.lower)*scale); | 
| 57 |        | 
| 58 |       space0.l.vx.x[i] = space.l.vx.x; space0.l.vx.y[i] = space.l.vx.y; space0.l.vx.z[i] = space.l.vx.z; | 
| 59 |       space0.l.vy.x[i] = space.l.vy.x; space0.l.vy.y[i] = space.l.vy.y; space0.l.vy.z[i] = space.l.vy.z; | 
| 60 |       space0.l.vz.x[i] = space.l.vz.x; space0.l.vz.y[i] = space.l.vz.y; space0.l.vz.z[i] = space.l.vz.z; | 
| 61 |       space0.p   .x[i] = space.p   .x; space0.p   .y[i] = space.p   .y; space0.p   .z[i] = space.p   .z; | 
| 62 |        | 
| 63 |       /*b0.lower.x[i] = a1.lower.x; b0.lower.y[i] = a1.lower.y; b0.lower.z[i] = a1.lower.z; | 
| 64 |         b0.upper.x[i] = a1.upper.x; b0.upper.y[i] = a1.upper.y; b0.upper.z[i] = a1.upper.z;*/ | 
| 65 |        | 
| 66 |       b1.lower.x[i] = c1.lower.x; b1.lower.y[i] = c1.lower.y; b1.lower.z[i] = c1.lower.z; | 
| 67 |       b1.upper.x[i] = c1.upper.x; b1.upper.y[i] = c1.upper.y; b1.upper.z[i] = c1.upper.z; | 
| 68 |     } | 
| 69 |      | 
| 70 |     /*! Sets ID of child. */ | 
| 71 |     __forceinline void setRef(size_t i, const NodeRef& ref) { | 
| 72 |       assert(i < N); | 
| 73 |       children[i] = ref; | 
| 74 |     } | 
| 75 |      | 
| 76 |     /*! Returns the extent of the bounds of the ith child */ | 
| 77 |     __forceinline Vec3fa extent0(size_t i) const { | 
| 78 |       assert(i < N); | 
| 79 |       const Vec3fa vx(space0.l.vx.x[i],space0.l.vx.y[i],space0.l.vx.z[i]); | 
| 80 |       const Vec3fa vy(space0.l.vy.x[i],space0.l.vy.y[i],space0.l.vy.z[i]); | 
| 81 |       const Vec3fa vz(space0.l.vz.x[i],space0.l.vz.y[i],space0.l.vz.z[i]); | 
| 82 |       return rsqrt(a: vx*vx + vy*vy + vz*vz); | 
| 83 |     } | 
| 84 |      | 
| 85 |   public: | 
| 86 |     AffineSpace3vf<N> space0; | 
| 87 |     //BBox3vf<N> b0; // these are the unit bounds | 
| 88 |     BBox3vf<N> b1; | 
| 89 |   }; | 
| 90 | } | 
| 91 |  |