Path: blob/master/thirdparty/embree/kernels/bvh/bvh_node_obb.h
9906 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "bvh_node_base.h"67namespace embree8{9/*! Node with unaligned bounds */10template<typename NodeRef, int N>11struct OBBNode_t : public BaseNode_t<NodeRef, N>12{13using BaseNode_t<NodeRef,N>::children;1415struct Create16{17__forceinline NodeRef operator() (const FastAllocator::CachedAllocator& alloc) const18{19OBBNode_t* node = (OBBNode_t*) alloc.malloc0(sizeof(OBBNode_t),NodeRef::byteNodeAlignment); node->clear();20return NodeRef::encodeNode(node);21}22};2324struct Set25{26__forceinline void operator() (NodeRef node, size_t i, NodeRef child, const OBBox3fa& bounds) const {27node.ungetAABBNode()->setRef(i,child);28node.ungetAABBNode()->setBounds(i,bounds);29}30};3132/*! Clears the node. */33__forceinline void clear()34{35naabb.l.vx = Vec3fa(nan);36naabb.l.vy = Vec3fa(nan);37naabb.l.vz = Vec3fa(nan);38naabb.p = Vec3fa(nan);39BaseNode_t<NodeRef,N>::clear();40}4142/*! Sets bounding box. */43__forceinline void setBounds(size_t i, const OBBox3fa& b)44{45assert(i < N);4647AffineSpace3fa space = b.space;48space.p -= b.bounds.lower;49space = AffineSpace3fa::scale(1.0f/max(Vec3fa(1E-19f),b.bounds.upper-b.bounds.lower))*space;5051naabb.l.vx.x[i] = space.l.vx.x;52naabb.l.vx.y[i] = space.l.vx.y;53naabb.l.vx.z[i] = space.l.vx.z;5455naabb.l.vy.x[i] = space.l.vy.x;56naabb.l.vy.y[i] = space.l.vy.y;57naabb.l.vy.z[i] = space.l.vy.z;5859naabb.l.vz.x[i] = space.l.vz.x;60naabb.l.vz.y[i] = space.l.vz.y;61naabb.l.vz.z[i] = space.l.vz.z;6263naabb.p.x[i] = space.p.x;64naabb.p.y[i] = space.p.y;65naabb.p.z[i] = space.p.z;66}6768/*! Sets ID of child. */69__forceinline void setRef(size_t i, const NodeRef& ref) {70assert(i < N);71children[i] = ref;72}7374/*! Returns the extent of the bounds of the ith child */75__forceinline Vec3fa extent(size_t i) const {76assert(i<N);77const Vec3fa vx(naabb.l.vx.x[i],naabb.l.vx.y[i],naabb.l.vx.z[i]);78const Vec3fa vy(naabb.l.vy.x[i],naabb.l.vy.y[i],naabb.l.vy.z[i]);79const Vec3fa vz(naabb.l.vz.x[i],naabb.l.vz.y[i],naabb.l.vz.z[i]);80return rsqrt(vx*vx + vy*vy + vz*vz);81}8283/*! Returns reference to specified child */84__forceinline NodeRef& child(size_t i) { assert(i<N); return children[i]; }85__forceinline const NodeRef& child(size_t i) const { assert(i<N); return children[i]; }8687/*! output operator */88friend embree_ostream operator<<(embree_ostream o, const OBBNode_t& n)89{90o << "UnAABBNode { " << n.naabb << " } " << embree_endl;91return o;92}9394public:95AffineSpace3vf<N> naabb; //!< non-axis aligned bounding boxes (bounds are [0,1] in specified space)96};97}9899100