Methods IsParallel() and SetParallel() have been added to BVH_Sorter, BVH_DistanceField and BVH_BuilderTransient to control parallel execution on low-level.
Fix compilation errors for old compilers without support of c++11 (std::begin, std::end)
//! Returns the maximum number of sub-elements in the leaf.
Standard_Integer LeafNodeSize() const { return myLeafNodeSize; }
+ //! Returns parallel flag.
+ inline Standard_Boolean IsParallel() const
+ {
+ return myIsParallel;
+ }
+
+ //! Set parallel flag contolling possibility of parallel execution.
+ inline void SetParallel(const Standard_Boolean isParallel)
+ {
+ myIsParallel = isParallel;
+ }
+
protected:
//! Creates new abstract BVH builder.
BVH_BuilderTransient (const Standard_Integer theLeafNodeSize,
const Standard_Integer theMaxTreeDepth)
: myMaxTreeDepth (theMaxTreeDepth),
- myLeafNodeSize (theLeafNodeSize) {}
+ myLeafNodeSize (theLeafNodeSize),
+ myIsParallel (Standard_False) {}
protected:
Standard_Integer myMaxTreeDepth; //!< Maximum depth of constructed BVH
Standard_Integer myLeafNodeSize; //!< Maximum number of objects per leaf
-
+ Standard_Boolean myIsParallel; //!< Parallel execution flag.
};
//! Performs construction of BVH tree using bounding
//! Builds 3D distance field from BVH geometry.
Standard_Boolean Build (BVH_Geometry<T, N>& theGeometry);
+ //! Returns parallel flag.
+ inline Standard_Boolean IsParallel() const
+ {
+ return myIsParallel;
+ }
+
+ //! Set parallel flag contolling possibility of parallel execution.
+ inline void SetParallel(const Standard_Boolean isParallel)
+ {
+ myIsParallel = isParallel;
+ }
+
public:
//! Returns packed voxel data.
//! Enables/disables signing of distance field.
Standard_Boolean myComputeSign;
+ Standard_Boolean myIsParallel;
};
#include <BVH_DistanceField.lxx>
BVH_DistanceField<T, N>::BVH_DistanceField (const Standard_Integer theMaximumSize,
const Standard_Boolean theComputeSign)
: myMaximumSize (theMaximumSize),
- myComputeSign (theComputeSign)
+ myComputeSign (theComputeSign),
+ myIsParallel (Standard_False)
{
Standard_STATIC_ASSERT (N == 3 || N == 4);
myVoxelSize.y() = (myCornerMax.y() - myCornerMin.y()) / myDimensionY;
myVoxelSize.z() = (myCornerMax.z() - myCornerMin.z()) / myDimensionZ;
- OSD_Parallel::For (0, myDimensionZ, BVH_ParallelDistanceFieldBuilder<T, N> (this, &theGeometry));
+ OSD_Parallel::For (0, myDimensionZ, BVH_ParallelDistanceFieldBuilder<T, N> (this, &theGeometry), !IsParallel());
return Standard_True;
}
{
public:
+ UpdateBoundTask (const Standard_Boolean isParallel)
+ : myIsParallel (isParallel)
+ {
+ }
+
//! Executes the task.
void operator()(const BoundData<T, N>& theData) const
{
if (!aList.empty())
{
- OSD_Parallel::ForEach (aList.begin (), aList.end (), UpdateBoundTask<T, N> ());
+ OSD_Parallel::ForEach (aList.begin (), aList.end (), UpdateBoundTask<T, N> (myIsParallel), !myIsParallel);
}
typename BVH_Box<T, N>::BVH_VecNt aLftMinPoint = theData.myBVH->MinPointBuffer()[aLftChild];
*theData.myHeight = Max (aLftHeight, aRghHeight) + 1;
}
}
+
+ private:
+
+ Standard_Boolean myIsParallel;
};
}
// Step 0 -- Initialize parameter of virtual grid
BVH_RadixSorter<T, N> aRadixSorter (theBox);
+ aRadixSorter.SetParallel (this->IsParallel());
// Step 1 - Perform radix sorting of primitive set
aRadixSorter.Perform (theSet);
Standard_Integer aHeight = 0;
BVH::BoundData<T, N> aBoundData = { theSet, theBVH, 0, 0, &aHeight };
- BVH::UpdateBoundTask<T, N> aBoundTask;
+ BVH::UpdateBoundTask<T, N> aBoundTask (this->IsParallel());
aBoundTask (aBoundData);
BVH_Builder<T, N>::updateDepth (theBVH, aHeight);
};
//! Functor class to run sorting in parallel.
- struct Functor
+ class Functor
{
+ public:
+ Functor(const SortRange (&aSplits)[2], const Standard_Boolean isParallel)
+ : mySplits (aSplits),
+ myIsParallel (isParallel)
+ {
+ }
+
//! Runs sorting function for the given range.
- void operator()(const SortRange& theRange) const
+ void operator()(const Standard_Integer theIndex) const
{
- RadixSorter::Sort (theRange.myStart, theRange.myFinal, theRange.myDigit);
+ RadixSorter::Sort (mySplits[theIndex].myStart, mySplits[theIndex].myFinal,
+ mySplits[theIndex].myDigit, myIsParallel);
}
+
+ private:
+ void operator=(const Functor&);
+
+ private:
+ const SortRange (&mySplits)[2];
+ Standard_Boolean myIsParallel;
};
public:
- static void Sort (LinkIterator theStart, LinkIterator theFinal, Standard_Integer theDigit)
+ static void Sort (LinkIterator theStart, LinkIterator theFinal, Standard_Integer theDigit, const Standard_Boolean isParallel)
{
if (theDigit < 24)
{
{anOffset, theFinal, theDigit - 1}
};
- OSD_Parallel::ForEach (std::begin (aSplits), std::end (aSplits), Functor ());
+ OSD_Parallel::For (0, 2, Functor (aSplits, isParallel), !isParallel);
}
}
}
// Step 2 -- Sort primitives by their Morton codes using radix sort
- BVH::RadixSorter::Sort (myEncodedLinks->begin(), myEncodedLinks->end(), 29);
+ BVH::RadixSorter::Sort (myEncodedLinks->begin(), myEncodedLinks->end(), 29, this->IsParallel());
NCollection_Array1<Standard_Integer> aLinkMap (theStart, theFinal);
for (Standard_Integer aLinkIdx = theStart; aLinkIdx <= theFinal; ++aLinkIdx)
{
public:
+ //! Performs default initialization.
+ BVH_Sorter()
+ : myIsParallel (Standard_False)
+ { }
+
//! Releases resources of BVH sorter.
virtual ~BVH_Sorter() { }
//! Sorts the given (inclusive) range in the set.
virtual void Perform (BVH_Set<T, N>* theSet, const Standard_Integer theStart, const Standard_Integer theFinal) = 0;
+ //! Returns parallel flag.
+ inline Standard_Boolean IsParallel() const
+ {
+ return myIsParallel;
+ }
+
+ //! Set parallel flag contolling possibility of parallel execution.
+ inline void SetParallel(const Standard_Boolean isParallel)
+ {
+ myIsParallel = isParallel;
+ }
+
+private:
+
+ Standard_Boolean myIsParallel;
};
#endif // _BVH_Sorter_Header