// Created on: 2013-12-20 // Created by: Denis BOGOLEPOV // Copyright (c) 2013-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. // ======================================================================= // function : Clear // purpose : // ======================================================================= template void BVH_Tree::Clear() { myDepth = 0; BVHTools::ArrayOp::Clear (myMinPointBuffer); BVHTools::ArrayOp::Clear (myMaxPointBuffer); BVHTools::ArrayOp::Clear (myNodeInfoBuffer); } // ======================================================================= // function : AddLeafNode // purpose : // ======================================================================= template Standard_Integer BVH_Tree::AddLeafNode (const BVH_VecNt& theMinPoint, const BVH_VecNt& theMaxPoint, const Standard_Integer theBegElem, const Standard_Integer theEndElem) { BVHTools::ArrayOp::Append (myMinPointBuffer, theMinPoint); BVHTools::ArrayOp::Append (myMaxPointBuffer, theMaxPoint); BVHTools::ArrayOp::Append (myNodeInfoBuffer, BVH_Vec4i (1, theBegElem, theEndElem, 0)); return static_cast (BVHTools::ArrayOp::Size (myNodeInfoBuffer) - 1); } // ======================================================================= // function : AddInnerNode // purpose : // ======================================================================= template Standard_Integer BVH_Tree::AddInnerNode (const BVH_VecNt& theMinPoint, const BVH_VecNt& theMaxPoint, const Standard_Integer theLftChild, const Standard_Integer theRghChild) { BVHTools::ArrayOp::Append (myMinPointBuffer, theMinPoint); BVHTools::ArrayOp::Append (myMaxPointBuffer, theMaxPoint); BVHTools::ArrayOp::Append (myNodeInfoBuffer, BVH_Vec4i (0, theLftChild, theRghChild, 0)); return static_cast (BVHTools::ArrayOp::Size (myNodeInfoBuffer) - 1); } // ======================================================================= // function : AddLeafNode // purpose : // ======================================================================= template Standard_Integer BVH_Tree::AddLeafNode (const BVH_Box& theAABB, const Standard_Integer theBegElem, const Standard_Integer theEndElem) { return AddLeafNode (theAABB.CornerMin(), theAABB.CornerMax(), theBegElem, theEndElem); } // ======================================================================= // function : AddInnerNode // purpose : // ======================================================================= template Standard_Integer BVH_Tree::AddInnerNode (const BVH_Box& theAABB, const Standard_Integer theLftChild, const Standard_Integer theRghChild) { return AddInnerNode (theAABB.CornerMin(), theAABB.CornerMax(), theLftChild, theRghChild); } namespace BVHTools { template void EstimateSAH (const BVH_Tree* theTree, const Standard_Integer theNode, T theProbability, T& theSAH) { BVH_Box aBox (theTree->MinPoint (theNode), theTree->MaxPoint (theNode)); if (theTree->IsOuter (theNode)) { theSAH += theProbability * (theTree->EndPrimitive (theNode) - theTree->BegPrimitive (theNode) + 1); } else { theSAH += theProbability * static_cast (2.0); BVH_Box aLftBox (theTree->MinPoint (theTree->LeftChild (theNode)), theTree->MaxPoint (theTree->LeftChild (theNode))); if (theProbability > 0.0) { EstimateSAH (theTree, theTree->LeftChild (theNode), theProbability * aLftBox.Area() / aBox.Area(), theSAH); } BVH_Box aRghBox (theTree->MinPoint (theTree->RightChild (theNode)), theTree->MaxPoint (theTree->RightChild (theNode))); if (theProbability > 0.0) { EstimateSAH (theTree, theTree->RightChild (theNode), theProbability * aRghBox.Area() / aBox.Area(), theSAH); } } } } // ======================================================================= // function : EstimateSAH // purpose : // ======================================================================= template T BVH_Tree::EstimateSAH() const { T aSAH = static_cast (0.0); BVHTools::EstimateSAH (this, 0, static_cast (1.0), aSAH); return aSAH; }