/usr/include/oce/BVH_SweepPlaneBuilder.lxx is in liboce-foundation-dev 0.17.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | // Created on: 2014-01-09
// 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.
#include <BVH_Sorter.hxx>
#include <NCollection_Array1.hxx>
// =======================================================================
// function : BVH_SweepPlaneBuilder
// purpose :
// =======================================================================
template<class T, int N>
BVH_SweepPlaneBuilder<T, N>::BVH_SweepPlaneBuilder (const Standard_Integer theLeafNodeSize,
const Standard_Integer theMaxTreeDepth)
: BVH_QueueBuilder<T, N> (theLeafNodeSize,
theMaxTreeDepth)
{
//
}
// =======================================================================
// function : ~BVH_SweepPlaneBuilder
// purpose :
// =======================================================================
template<class T, int N>
BVH_SweepPlaneBuilder<T, N>::~BVH_SweepPlaneBuilder()
{
//
}
// =======================================================================
// function : BuildNode
// purpose :
// =======================================================================
template<class T, int N>
void BVH_SweepPlaneBuilder<T, N>::BuildNode (BVH_Set<T, N>* theSet,
BVH_Tree<T, N>* theBVH,
const Standard_Integer theNode)
{
const Standard_Integer aNodeBegPrimitive = theBVH->BegPrimitive (theNode);
const Standard_Integer aNodeEndPrimitive = theBVH->EndPrimitive (theNode);
const Standard_Integer aNodeNbPrimitives = theBVH->NbPrimitives (theNode);
if (aNodeEndPrimitive - aNodeBegPrimitive < BVH_Builder<T, N>::myLeafNodeSize)
{
return; // node does not require partitioning
}
// Parameters for storing best split
Standard_Integer aMinSplitAxis = -1;
Standard_Integer aMinSplitIndex = 0;
NCollection_Array1<Standard_Real> aLftSet (0, aNodeNbPrimitives - 1);
NCollection_Array1<Standard_Real> aRghSet (0, aNodeNbPrimitives - 1);
Standard_Real aMinSplitCost = std::numeric_limits<Standard_Real>::max();
// Find best split
for (Standard_Integer anAxis = 0; anAxis < (N < 4 ? N : 3); ++anAxis)
{
const T aNodeSize = BVH::VecComp<T, N>::Get (theBVH->MaxPoint (theNode), anAxis) -
BVH::VecComp<T, N>::Get (theBVH->MinPoint (theNode), anAxis);
if (aNodeSize <= BVH::THE_NODE_MIN_SIZE)
{
continue;
}
BVH_Sorter<T, N>::Perform (theSet, anAxis, aNodeBegPrimitive, aNodeEndPrimitive);
BVH_Box<T, N> aLftBox;
BVH_Box<T, N> aRghBox;
aLftSet.ChangeFirst() = std::numeric_limits<T>::max();
aRghSet.ChangeFirst() = std::numeric_limits<T>::max();
// Sweep from left
for (Standard_Integer anIndex = 1; anIndex < aNodeNbPrimitives; ++anIndex)
{
aLftBox.Combine (theSet->Box (anIndex + aNodeBegPrimitive - 1));
aLftSet (anIndex) = static_cast<Standard_Real> (aLftBox.Area());
}
// Sweep from right
for (Standard_Integer anIndex = 1; anIndex < aNodeNbPrimitives; ++anIndex)
{
aRghBox.Combine (theSet->Box (aNodeEndPrimitive - anIndex + 1));
aRghSet (anIndex) = static_cast<Standard_Real> (aRghBox.Area());
}
// Find best split using simplified SAH
for (Standard_Integer aNbLft = 1, aNbRgh = aNodeNbPrimitives - 1; aNbLft < aNodeNbPrimitives; ++aNbLft, --aNbRgh)
{
Standard_Real aCost = (aLftSet (aNbLft) /* / aNodeArea */) * aNbLft +
(aRghSet (aNbRgh) /* / aNodeArea */) * aNbRgh;
if (aCost < aMinSplitCost)
{
aMinSplitCost = aCost;
aMinSplitAxis = anAxis;
aMinSplitIndex = aNbLft;
}
}
}
if (aMinSplitAxis == -1)
{
return;
}
theBVH->SetInner (theNode);
if (aMinSplitAxis != (N < 4 ? N - 1 : 2))
{
BVH_Sorter<T, N>::Perform (theSet, aMinSplitAxis, aNodeBegPrimitive, aNodeEndPrimitive);
}
BVH_Box<T, N> aMinSplitBoxLft;
BVH_Box<T, N> aMinSplitBoxRgh;
// Compute bounding boxes for selected split plane
for (Standard_Integer anIndex = aNodeBegPrimitive; anIndex < aMinSplitIndex + aNodeBegPrimitive; ++anIndex)
{
aMinSplitBoxLft.Combine (theSet->Box (anIndex));
}
for (Standard_Integer anIndex = aNodeEndPrimitive; anIndex >= aMinSplitIndex + aNodeBegPrimitive; --anIndex)
{
aMinSplitBoxRgh.Combine (theSet->Box (anIndex));
}
const Standard_Integer aMiddle = aNodeBegPrimitive + aMinSplitIndex;
static const Standard_Integer aLftNode = 1;
static const Standard_Integer aRghNode = 2;
// Setting up tasks for child nodes
for (Standard_Integer aSide = aLftNode; aSide <= aRghNode; ++aSide)
{
typename BVH_Box<T, N>::BVH_VecNt aChildMinPoint = (aSide == aLftNode)
? aMinSplitBoxLft.CornerMin()
: aMinSplitBoxRgh.CornerMin();
typename BVH_Box<T, N>::BVH_VecNt aChildMaxPoint = (aSide == aLftNode)
? aMinSplitBoxLft.CornerMax()
: aMinSplitBoxRgh.CornerMax();
Standard_Integer aChildBegPrimitive = (aSide == aLftNode)
? aNodeBegPrimitive
: aMiddle;
Standard_Integer aChildEndPrimitive = (aSide == aLftNode)
? aMiddle - 1
: aNodeEndPrimitive;
Standard_Integer aChildIndex = theBVH->AddLeafNode (aChildMinPoint, aChildMaxPoint,
aChildBegPrimitive, aChildEndPrimitive);
theBVH->Level (aChildIndex) = theBVH->Level (theNode) + 1;
// Check to see if child node must be split
const Standard_Integer aChildNbPimitives = (aSide == aLftNode)
? aMiddle - aNodeBegPrimitive
: aNodeEndPrimitive - aMiddle + 1;
if (aSide == aLftNode)
theBVH->LeftChild (theNode) = aChildIndex;
else
theBVH->RightChild (theNode) = aChildIndex;
const Standard_Boolean isLeaf = aChildNbPimitives <= BVH_Builder<T, N>::myLeafNodeSize
|| theBVH->Level (aChildIndex) >= BVH_Builder<T, N>::myMaxTreeDepth;
if (!isLeaf)
{
BVH_QueueBuilder<T, N>::myTasksQueue.Append (aChildIndex);
}
BVH_Builder<T, N>::UpdateDepth (theBVH, theBVH->Level (aChildIndex));
}
}
|