#include <Standard_Assert.hxx>
+#include <NCollection_Array1.hxx>
+
#ifdef HAVE_TBB
// On Windows, function TryEnterCriticalSection has appeared in Windows NT
// and is surrounded by #ifdef in MS VC++ 7.1 headers.
const BVH_VecNt aSceneMin = theBox.CornerMin();
const BVH_VecNt aSceneMax = theBox.CornerMax();
- const BVH_VecNt aSceneSize = aSceneMax - aSceneMin;
+ const T aMinSize = static_cast<T> (BVH::THE_NODE_MIN_SIZE);
- const T aReverseSizeX = static_cast<T> (aDimensionX) / (aSceneMax.x() - aSceneMin.x());
- const T aReverseSizeY = static_cast<T> (aDimensionY) / (aSceneMax.y() - aSceneMin.y());
- const T aReverseSizeZ = static_cast<T> (aDimensionZ) / (aSceneMax.z() - aSceneMin.z());
+ const T aReverseSizeX = static_cast<T> (aDimensionX) / Max (aMinSize, aSceneMax.x() - aSceneMin.x());
+ const T aReverseSizeY = static_cast<T> (aDimensionY) / Max (aMinSize, aSceneMax.y() - aSceneMin.y());
+ const T aReverseSizeZ = static_cast<T> (aDimensionZ) / Max (aMinSize, aSceneMax.z() - aSceneMin.z());
std::vector<BVH_EncodedLink> anEncodedLinks (theSet->Size(), BVH_EncodedLink());
// Step 3 -- Emitting BVH hierarchy from sorted Morton codes
EmitHierachy (theBVH, 29, 0, anEncodedLinks.begin(), anEncodedLinks.end());
- Standard_Integer* aLinkMap = new Standard_Integer[theSet->Size()];
+ NCollection_Array1<Standard_Integer> aLinkMap (0, theSet->Size() - 1);
for (Standard_Integer aLinkIdx = 0; aLinkIdx < theSet->Size(); ++aLinkIdx)
{
- aLinkMap[anEncodedLinks[aLinkIdx].second] = aLinkIdx;
+ aLinkMap (anEncodedLinks[aLinkIdx].second) = aLinkIdx;
}
// Step 4 -- Rearranging primitive list according to Morton codes (in place)
while (aPrimIdx < theSet->Size())
{
- const Standard_Integer aSortIdx = aLinkMap[aPrimIdx];
+ const Standard_Integer aSortIdx = aLinkMap (aPrimIdx);
if (aPrimIdx != aSortIdx)
{
theSet->Swap (aPrimIdx, aSortIdx);
- std::swap (aLinkMap[aPrimIdx],
- aLinkMap[aSortIdx]);
+ std::swap (aLinkMap (aPrimIdx),
+ aLinkMap (aSortIdx));
}
else
{
#ifdef HAVE_TBB
+ // Note: Although TBB tasks are allocated using placement
+ // new, we do not need to delete them explicitly
BVH::UpdateBoundTask<T, N>& aRootTask = *new ( tbb::task::allocate_root() )
BVH::UpdateBoundTask<T, N> (theSet, theBVH, 0, 0, &aDepth);