Path: blob/master/thirdparty/embree/kernels/bvh/bvh_refit.h
9912 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "../bvh/bvh.h"67namespace embree8{9namespace isa10{11template<int N>12class BVHNRefitter13{14public:1516/*! Type shortcuts */17typedef BVHN<N> BVH;18typedef typename BVH::AABBNode AABBNode;19typedef typename BVH::NodeRef NodeRef;2021struct LeafBoundsInterface {22virtual const BBox3fa leafBounds(NodeRef& ref) const = 0;23};2425public:2627/*! Constructor. */28BVHNRefitter (BVH* bvh, const LeafBoundsInterface& leafBounds);2930/*! refits the BVH */31void refit();3233private:34/* single-threaded subtree extraction based on BVH depth */35void gather_subtree_refs(NodeRef& ref,36size_t &subtrees,37const size_t depth = 0);3839/* single-threaded top-level refit */40BBox3fa refit_toplevel(NodeRef& ref,41size_t &subtrees,42const BBox3fa *const subTreeBounds,43const size_t depth = 0);4445/* single-threaded subtree refit */46BBox3fa recurse_bottom(NodeRef& ref);4748public:49BVH* bvh; //!< BVH to refit50const LeafBoundsInterface& leafBounds; //!< calculates bounds of leaves5152static const size_t MAX_SUB_TREE_EXTRACTION_DEPTH = (N==4) ? 4 : (N==8) ? 3 : 3;53static const size_t MAX_NUM_SUB_TREES = (N==4) ? 256 : (N==8) ? 512 : N*N*N; // N ^ MAX_SUB_TREE_EXTRACTION_DEPTH54size_t numSubTrees;55NodeRef subTrees[MAX_NUM_SUB_TREES];56};5758template<int N, typename Mesh, typename Primitive>59class BVHNRefitT : public Builder, public BVHNRefitter<N>::LeafBoundsInterface60{61public:6263/*! Type shortcuts */64typedef BVHN<N> BVH;65typedef typename BVH::AABBNode AABBNode;66typedef typename BVH::NodeRef NodeRef;6768public:69BVHNRefitT (BVH* bvh, Builder* builder, Mesh* mesh, size_t mode);7071virtual void build();7273virtual void clear();7475virtual const BBox3fa leafBounds (NodeRef& ref) const76{77size_t num; char* prim = ref.leaf(num);78if (unlikely(ref == BVH::emptyNode)) return empty;7980BBox3fa bounds = empty;81for (size_t i=0; i<num; i++)82bounds.extend(((Primitive*)prim)[i].update(mesh));83return bounds;84}8586private:87BVH* bvh;88std::unique_ptr<Builder> builder;89std::unique_ptr<BVHNRefitter<N>> refitter;90Mesh* mesh;91unsigned int topologyVersion;92};93}94}959697