/usr/include/oce/BVH_BinnedBuilder.lxx is in liboce-foundation-dev 0.17.1-1.
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | // 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 : BVH_BinnedBuilder
// purpose :
// =======================================================================
template<class T, int N, int Bins>
BVH_BinnedBuilder<T, N, Bins>::BVH_BinnedBuilder (const Standard_Integer theLeafNodeSize,
const Standard_Integer theMaxTreeDepth)
: BVH_QueueBuilder<T, N> (theLeafNodeSize,
theMaxTreeDepth)
{
//
}
// =======================================================================
// function : ~BVH_BinnedBuilder
// purpose :
// =======================================================================
template<class T, int N, int Bins>
BVH_BinnedBuilder<T, N, Bins>::~BVH_BinnedBuilder()
{
//
}
// =======================================================================
// function : GetSubVolumes
// purpose :
// =======================================================================
template<class T, int N, int Bins>
void BVH_BinnedBuilder<T, N, Bins>::GetSubVolumes (BVH_Set<T, N>* theSet,
BVH_Tree<T, N>* theBVH,
const Standard_Integer theNode,
BVH_BinVector& theBins,
const Standard_Integer theAxis)
{
const T aMin = BVH::VecComp<T, N>::Get (theBVH->MinPoint (theNode), theAxis);
const T aMax = BVH::VecComp<T, N>::Get (theBVH->MaxPoint (theNode), theAxis);
const T anInverseStep = static_cast<T> (Bins) / (aMax - aMin);
for (Standard_Integer anIdx = theBVH->BegPrimitive (theNode); anIdx <= theBVH->EndPrimitive (theNode); ++anIdx)
{
typename BVH_Set<T, N>::BVH_BoxNt aBox = theSet->Box (anIdx);
Standard_Integer aBinIndex = BVH::IntFloor<T> (
(theSet->Center (anIdx, theAxis) - aMin) * anInverseStep);
if (aBinIndex < 0)
{
aBinIndex = 0;
}
else if (aBinIndex >= Bins)
{
aBinIndex = Bins - 1;
}
theBins[aBinIndex].Count++;
theBins[aBinIndex].Box.Combine (aBox);
}
}
namespace BVH
{
// =======================================================================
// function : SplitPrimitives
// purpose :
// =======================================================================
template<class T, int N>
Standard_Integer SplitPrimitives (BVH_Set<T, N>* theSet,
const BVH_Box<T, N>& theBox,
const Standard_Integer theBeg,
const Standard_Integer theEnd,
const Standard_Integer theBin,
const Standard_Integer theAxis,
const Standard_Integer theBins)
{
const T aMin = BVH::VecComp<T, N>::Get (theBox.CornerMin(), theAxis);
const T aMax = BVH::VecComp<T, N>::Get (theBox.CornerMax(), theAxis);
const T anInverseStep = static_cast<T> (theBins) / (aMax - aMin);
Standard_Integer aLftIdx (theBeg);
Standard_Integer aRghIdx (theEnd);
do
{
while (BVH::IntFloor<T> ((theSet->Center (aLftIdx, theAxis) - aMin) * anInverseStep) <= theBin && aLftIdx < theEnd)
{
++aLftIdx;
}
while (BVH::IntFloor<T> ((theSet->Center (aRghIdx, theAxis) - aMin) * anInverseStep) > theBin && aRghIdx > theBeg)
{
--aRghIdx;
}
if (aLftIdx <= aRghIdx)
{
if (aLftIdx != aRghIdx)
{
theSet->Swap (aLftIdx, aRghIdx);
}
++aLftIdx;
--aRghIdx;
}
} while (aLftIdx <= aRghIdx);
return aLftIdx;
}
}
#if defined (_WIN32) && defined (max)
#undef max
#endif
#include <limits>
// =======================================================================
// function : BuildNode
// purpose :
// =======================================================================
template<class T, int N, int Bins>
void BVH_BinnedBuilder<T, N, Bins>::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);
if (aNodeEndPrimitive - aNodeBegPrimitive < BVH_Builder<T, N>::myLeafNodeSize)
{
return; // node does not require partitioning
}
const BVH_Box<T, N> anAABB (theBVH->MinPoint (theNode),
theBVH->MaxPoint (theNode));
const typename BVH_Box<T, N>::BVH_VecNt aSize = anAABB.Size();
// Parameters for storing best split
Standard_Integer aMinSplitAxis = -1;
Standard_Integer aMinSplitIndex = 0;
Standard_Integer aMinSplitNumLft = 0;
Standard_Integer aMinSplitNumRgh = 0;
BVH_Box<T, N> aMinSplitBoxLft;
BVH_Box<T, N> aMinSplitBoxRgh;
Standard_Real aMinSplitCost = std::numeric_limits<Standard_Real>::max();
// Find best split
for (Standard_Integer anAxis = 0; anAxis < (N < 4 ? N : 3); ++anAxis)
{
if (BVH::VecComp<T, N>::Get (aSize, anAxis) <= BVH::THE_NODE_MIN_SIZE)
continue;
BVH_BinVector aBins;
GetSubVolumes (theSet, theBVH, theNode, aBins, anAxis);
// Choose the best split (with minimum SAH cost)
for (Standard_Integer aSplit = 1; aSplit < Bins; ++aSplit)
{
Standard_Integer aLftCount = 0;
Standard_Integer aRghCount = 0;
BVH_Box<T, N> aLftAABB;
BVH_Box<T, N> aRghAABB;
for (Standard_Integer anIndex = 0; anIndex < aSplit; ++anIndex)
{
aLftCount += aBins[anIndex].Count;
aLftAABB.Combine (aBins[anIndex].Box);
}
for (Standard_Integer anIndex = aSplit; anIndex < Bins; ++anIndex)
{
aRghCount += aBins[anIndex].Count;
aRghAABB.Combine (aBins[anIndex].Box);
}
// Simple SAH evaluation
Standard_Real aCost = (static_cast<Standard_Real> (aLftAABB.Area()) /* / aNodeArea */) * aLftCount
+ (static_cast<Standard_Real> (aRghAABB.Area()) /* / aNodeArea */) * aRghCount;
if (aCost <= aMinSplitCost)
{
aMinSplitCost = aCost;
aMinSplitAxis = anAxis;
aMinSplitIndex = aSplit;
aMinSplitBoxLft = aLftAABB;
aMinSplitBoxRgh = aRghAABB;
aMinSplitNumLft = aLftCount;
aMinSplitNumRgh = aRghCount;
}
}
}
theBVH->SetInner (theNode);
Standard_Integer aMiddle = -1;
if (aMinSplitNumLft == 0 || aMinSplitNumRgh == 0 || aMinSplitAxis == -1) // case of objects with the same center
{
aMinSplitBoxLft.Clear();
aMinSplitBoxRgh.Clear();
aMiddle = std::max (aNodeBegPrimitive + 1,
static_cast<Standard_Integer> ((aNodeBegPrimitive + aNodeEndPrimitive) / 2.f));
aMinSplitNumLft = aMiddle - aNodeBegPrimitive;
for (Standard_Integer anIndex = aNodeBegPrimitive; anIndex < aMiddle; ++anIndex)
{
aMinSplitBoxLft.Combine (theSet->Box (anIndex));
}
aMinSplitNumRgh = aNodeEndPrimitive - aMiddle + 1;
for (Standard_Integer anIndex = aNodeEndPrimitive; anIndex >= aMiddle; --anIndex)
{
aMinSplitBoxRgh.Combine (theSet->Box (anIndex));
}
}
else
{
aMiddle = BVH::SplitPrimitives<T, N> (theSet, anAABB,
aNodeBegPrimitive, aNodeEndPrimitive, aMinSplitIndex - 1, aMinSplitAxis, Bins);
}
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 aMinPoint = (aSide == aLftNode)
? aMinSplitBoxLft.CornerMin()
: aMinSplitBoxRgh.CornerMin();
typename BVH_Box<T, N>::BVH_VecNt aMaxPoint = (aSide == aLftNode)
? aMinSplitBoxLft.CornerMax()
: aMinSplitBoxRgh.CornerMax();
Standard_Integer aBegPrimitive = (aSide == aLftNode)
? aNodeBegPrimitive
: aMiddle;
Standard_Integer aEndPrimitive = (aSide == aLftNode)
? aMiddle - 1
: aNodeEndPrimitive;
Standard_Integer aChildIndex = theBVH->AddLeafNode (aMinPoint, aMaxPoint, aBegPrimitive, aEndPrimitive);
theBVH->Level (aChildIndex) = theBVH->Level (theNode) + 1;
// Check to see if child node must be split
const Standard_Integer aNbPimitives = (aSide == aLftNode)
? aMinSplitNumLft
: aMinSplitNumRgh;
if (aSide == aLftNode)
theBVH->LeftChild (theNode) = aChildIndex;
else
theBVH->RightChild (theNode) = aChildIndex;
const Standard_Boolean isLeaf = aNbPimitives <= 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));
}
}
|