BVH binned builder is used for different rendering aspects, such as view frustum culling, ray-tracing, and (in future) for selection. It is desirable to improve builder performance. This simple patch decreases BVH building time for 30-35%.
//
}
+namespace BVH
+{
+ template<class T>
+ static inline Standard_Integer IntFloor (const T theValue)
+ {
+ const Standard_Integer aRes = static_cast<Standard_Integer> (theValue);
+
+ return aRes - static_cast<Standard_Integer> (aRes > theValue);
+ }
+}
+
// =======================================================================
// function : GetSubVolumes
// purpose :
BVH_BinVector& theBins,
const Standard_Integer theAxis)
{
- const T aMin = BVHTools::VecComp<T, N>::Get (theBVH->MinPoint (theNode), theAxis);
- const T aMax = BVHTools::VecComp<T, N>::Get (theBVH->MaxPoint (theNode), 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 anInvStep = static_cast<T> (Bins) / (aMax - aMin);
+ 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 = static_cast<Standard_Integer> (std::floor ((theSet->Center (anIdx, theAxis) - aMin) * anInvStep));
+ Standard_Integer aBinIndex = BVH::IntFloor<T> (
+ (theSet->Center (anIdx, theAxis) - aMin) * anInverseStep);
+
if (aBinIndex < 0)
{
aBinIndex = 0;
}
}
-namespace BVHTools
+namespace BVH
{
// =======================================================================
// function : SplitPrimitives
const Standard_Integer theAxis,
const Standard_Integer theBins)
{
- const T aMin = BVHTools::VecComp<T, N>::Get (theBox.CornerMin(), theAxis);
- const T aMax = BVHTools::VecComp<T, N>::Get (theBox.CornerMax(), theAxis);
+ const T aMin = BVH::VecComp<T, N>::Get (theBox.CornerMin(), theAxis);
+ const T aMax = BVH::VecComp<T, N>::Get (theBox.CornerMax(), theAxis);
- const T anInvStep = static_cast<T> (theBins) / (aMax - aMin);
+ const T anInverseStep = static_cast<T> (theBins) / (aMax - aMin);
Standard_Integer aLftIdx (theBeg);
Standard_Integer aRghIdx (theEnd);
do
{
- while ((Standard_Integer) std::floor ((theSet->Center (aLftIdx, theAxis) - aMin) * anInvStep) <= theBin && aLftIdx < theEnd)
+ while (BVH::IntFloor<T> ((theSet->Center (aLftIdx, theAxis) - aMin) * anInverseStep) <= theBin && aLftIdx < theEnd)
{
++aLftIdx;
}
- while ((Standard_Integer) std::floor ((theSet->Center (aRghIdx, theAxis) - aMin) * anInvStep) > theBin && aRghIdx > theBeg)
+ while (BVH::IntFloor<T> ((theSet->Center (aRghIdx, theAxis) - aMin) * anInverseStep) > theBin && aRghIdx > theBeg)
{
--aRghIdx;
}
// Find best split
for (Standard_Integer anAxis = 0; anAxis < (N < 4 ? N : 3); ++anAxis)
{
- if (BVHTools::VecComp<T, N>::Get (aSize, anAxis) <= THE_NODE_MIN_SIZE)
+ if (BVH::VecComp<T, N>::Get (aSize, anAxis) <= THE_NODE_MIN_SIZE)
continue;
BVH_BinVector aBins;
}
else
{
- aMiddle = BVHTools::SplitPrimitives<T, N> (theSet, anAABB,
+ aMiddle = BVH::SplitPrimitives<T, N> (theSet, anAABB,
aNodeBegPrimitive, aNodeEndPrimitive, aMinSplitIndex - 1, aMinSplitAxis, Bins);
}
{
public:
- typedef typename BVHTools::VectorType<T, N>::Type BVH_VecNt;
+ typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
public:
#include <Standard_ShortReal.hxx>
-namespace BVHTools
+namespace BVH
{
template<class T, int N>
struct CenterAxis {
}
}
+namespace BVH
+{
+ template<class T, int N>
+ struct BoxMinMax
+ {
+ typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
+
+ static void CwiseMin (BVH_VecNt& theVec1, const BVH_VecNt& theVec2)
+ {
+ theVec1.x() = Min (theVec1.x(), theVec2.x());
+ theVec1.y() = Min (theVec1.y(), theVec2.y());
+ theVec1.z() = Min (theVec1.z(), theVec2.z());
+ }
+
+ static void CwiseMax (BVH_VecNt& theVec1, const BVH_VecNt& theVec2)
+ {
+ theVec1.x() = Max (theVec1.x(), theVec2.x());
+ theVec1.y() = Max (theVec1.y(), theVec2.y());
+ theVec1.z() = Max (theVec1.z(), theVec2.z());
+ }
+ };
+
+ template<class T>
+ struct BoxMinMax<T, 2>
+ {
+ typedef typename BVH::VectorType<T, 2>::Type BVH_VecNt;
+
+ static void CwiseMin (BVH_VecNt& theVec1, const BVH_VecNt& theVec2)
+ {
+ theVec1.x() = Min (theVec1.x(), theVec2.x());
+ theVec1.y() = Min (theVec1.y(), theVec2.y());
+ }
+
+ static void CwiseMax (BVH_VecNt& theVec1, const BVH_VecNt& theVec2)
+ {
+ theVec1.x() = Max (theVec1.x(), theVec2.x());
+ theVec1.y() = Max (theVec1.y(), theVec2.y());
+ }
+ };
+}
+
// =======================================================================
// function : Combine
// purpose :
template<class T, int N>
void BVH_Box<T, N>::Combine (const BVH_Box& theBox)
{
- if (!theBox.myInitialized)
- {
- return;
- }
-
- if (!myInitialized)
+ if (theBox.myInitialized)
{
- myMinPoint = theBox.myMinPoint;
- myMaxPoint = theBox.myMaxPoint;
+ if (!myInitialized)
+ {
+ myMinPoint = theBox.myMinPoint;
+ myMaxPoint = theBox.myMaxPoint;
- myInitialized = Standard_True;
- }
- else
- {
- myMinPoint = myMinPoint.cwiseMin (theBox.myMinPoint);
- myMaxPoint = myMaxPoint.cwiseMax (theBox.myMaxPoint);
+ myInitialized = Standard_True;
+ }
+ else
+ {
+ BVH::BoxMinMax<T, N>::CwiseMin (myMinPoint, theBox.myMinPoint);
+ BVH::BoxMinMax<T, N>::CwiseMax (myMaxPoint, theBox.myMaxPoint);
+ }
}
}
-namespace BVHTools
+namespace BVH
{
template<class T, int N>
struct SurfaceCalculator
const Standard_Integer theAxis) const
{
typename BVH_Set<T, N>::BVH_BoxNt aBox = myObjects.Value (theIndex)->Box();
- return BVHTools::CenterAxis<T, N>::Center (aBox, theAxis);
+ return BVH::CenterAxis<T, N>::Center (aBox, theAxis);
}
// =======================================================================
public:
//! Type of transformation matrix.
- typedef typename BVHTools::MatrixType<T, N>::Type BVH_MatNt;
+ typedef typename BVH::MatrixType<T, N>::Type BVH_MatNt;
public:
return myTransform;
}
-namespace BVHTools
+namespace BVH
{
template<class T, int N> struct MatrixOp
{
template<class T> struct MatrixOp<T, 4>
{
- typedef typename BVHTools::MatrixType<T, 4>::Type BVH_Mat4t;
+ typedef typename BVH::MatrixType<T, 4>::Type BVH_Mat4t;
static void Inverse (const BVH_Mat4t& theIn,
BVH_Mat4t& theOut)
theIn.Inverted (theOut);
}
- typedef typename BVHTools::VectorType<T, 4>::Type BVH_Vec4t;
+ typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
static BVH_Vec4t Multiply (const BVH_Mat4t& theMat,
const BVH_Vec4t& theVec)
void BVH_Transform<T, N>::SetTransform (const BVH_MatNt& theTransform)
{
myTransform = theTransform;
- BVHTools::MatrixOp<T, N>::Inverse (myTransform, myTransformInversed);
+ BVH::MatrixOp<T, N>::Inverse (myTransform, myTransformInversed);
}
// =======================================================================
return myTransformInversed;
}
-namespace BVHTools
+namespace BVH
{
template<class T, int N>
struct UnitVector
template<class T>
struct UnitVector<T, 2>
{
- typedef typename BVHTools::VectorType<T, 2>::Type BVH_Vec2t;
+ typedef typename BVH::VectorType<T, 2>::Type BVH_Vec2t;
static BVH_Vec2t DX()
{
template<class T>
struct UnitVector<T, 3>
{
- typedef typename BVHTools::VectorType<T, 3>::Type BVH_Vec3t;
+ typedef typename BVH::VectorType<T, 3>::Type BVH_Vec3t;
static BVH_Vec3t DX()
{
template<class T>
struct UnitVector<T, 4>
{
- typedef typename BVHTools::VectorType<T, 4>::Type BVH_Vec4t;
+ typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
static BVH_Vec4t DX()
{
for (Standard_Integer aZ = 0; aZ <= 1; ++aZ)
{
typename BVH_Box<T, N>::BVH_VecNt aCorner = theBox.CornerMin() +
- BVHTools::UnitVector<T, N>::DX() * aSize * static_cast<T> (aX) +
- BVHTools::UnitVector<T, N>::DY() * aSize * static_cast<T> (aY) +
- BVHTools::UnitVector<T, N>::DZ() * aSize * static_cast<T> (aZ);
+ BVH::UnitVector<T, N>::DX() * aSize * static_cast<T> (aX) +
+ BVH::UnitVector<T, N>::DY() * aSize * static_cast<T> (aY) +
+ BVH::UnitVector<T, N>::DZ() * aSize * static_cast<T> (aZ);
- aBox.Add (BVHTools::MatrixOp<T, N>::Multiply (myTransform, aCorner));
+ aBox.Add (BVH::MatrixOp<T, N>::Multiply (myTransform, aCorner));
}
}
}
// Find best split
for (Standard_Integer anAxis = 0; anAxis < (N < 4 ? N : 3); ++anAxis)
{
- const T aNodeSize = BVHTools::VecComp<T, N>::Get (theBVH->MaxPoint (theNode), anAxis) -
- BVHTools::VecComp<T, N>::Get (theBVH->MinPoint (theNode), anAxis);
+ const T aNodeSize = BVH::VecComp<T, N>::Get (theBVH->MaxPoint (theNode), anAxis) -
+ BVH::VecComp<T, N>::Get (theBVH->MinPoint (theNode), anAxis);
if (aNodeSize <= THE_NODE_MIN_SIZE)
{
continue;
//! Returns minimum point of the given node.
BVH_VecNt& MinPoint (const Standard_Integer theNodeIndex)
{
- return BVHTools::ArrayOp<T, N>::ChangeValue (myMinPointBuffer, theNodeIndex);
+ return BVH::ArrayOp<T, N>::ChangeValue (myMinPointBuffer, theNodeIndex);
}
//! Returns maximum point of the given node.
BVH_VecNt& MaxPoint (const Standard_Integer theNodeIndex)
{
- return BVHTools::ArrayOp<T, N>::ChangeValue (myMaxPointBuffer, theNodeIndex);
+ return BVH::ArrayOp<T, N>::ChangeValue (myMaxPointBuffer, theNodeIndex);
}
//! Returns minimum point of the given node.
const BVH_VecNt& MinPoint (const Standard_Integer theNodeIndex) const
{
- return BVHTools::ArrayOp<T, N>::Value (myMinPointBuffer, theNodeIndex);
+ return BVH::ArrayOp<T, N>::Value (myMinPointBuffer, theNodeIndex);
}
//! Returns maximum point of the given node.
const BVH_VecNt& MaxPoint (const Standard_Integer theNodeIndex) const
{
- return BVHTools::ArrayOp<T, N>::Value (myMaxPointBuffer, theNodeIndex);
+ return BVH::ArrayOp<T, N>::Value (myMaxPointBuffer, theNodeIndex);
}
//! Returns index of left child of the given inner node.
Standard_Integer& LeftChild (const Standard_Integer theNodeIndex)
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).y();
+ return BVH::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).y();
}
//! Returns index of left child of the given inner node.
Standard_Integer LeftChild (const Standard_Integer theNodeIndex) const
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).y();
+ return BVH::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).y();
}
//! Returns index of right child of the given inner node.
Standard_Integer& RightChild (const Standard_Integer theNodeIndex)
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).z();
+ return BVH::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).z();
}
//! Returns index of right child of the given inner node.
Standard_Integer RightChild (const Standard_Integer theNodeIndex) const
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).z();
+ return BVH::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).z();
}
//! Returns index of first primitive of the given leaf node.
Standard_Integer& BegPrimitive (const Standard_Integer theNodeIndex)
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).y();
+ return BVH::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).y();
}
//! Returns index of first primitive of the given leaf node.
Standard_Integer BegPrimitive (const Standard_Integer theNodeIndex) const
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).y();
+ return BVH::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).y();
}
//! Returns index of last primitive of the given leaf node.
Standard_Integer& EndPrimitive (const Standard_Integer theNodeIndex)
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).z();
+ return BVH::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).z();
}
//! Returns index of last primitive of the given leaf node.
Standard_Integer EndPrimitive (const Standard_Integer theNodeIndex) const
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).z();
+ return BVH::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).z();
}
//! Returns number of primitives for the given tree node.
//! Returns level (depth) of the given node.
Standard_Integer& Level (const Standard_Integer theNodeIndex)
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).w();
+ return BVH::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).w();
}
//! Returns level (depth) of the given node.
Standard_Integer Level (const Standard_Integer theNodeIndex) const
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).w();
+ return BVH::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).w();
}
//! Is node a leaf (outer)?
Standard_Boolean IsOuter (const Standard_Integer theNodeIndex) const
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).x() > 0;
+ return BVH::ArrayOp<Standard_Integer, 4>::Value (myNodeInfoBuffer, theNodeIndex).x() > 0;
}
//! Sets node type to 'outer'.
void SetOuter (const Standard_Integer theNodeIndex)
{
- BVHTools::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).x() = 1;
+ BVH::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).x() = 1;
}
//! Sets node type to 'inner'.
void SetInner (const Standard_Integer theNodeIndex)
{
- BVHTools::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).x() = 0;
+ BVH::ArrayOp<Standard_Integer, 4>::ChangeValue (myNodeInfoBuffer, theNodeIndex).x() = 0;
}
//! Returns total number of BVH nodes.
Standard_Integer Length() const
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::Size (myNodeInfoBuffer);
+ return BVH::ArrayOp<Standard_Integer, 4>::Size (myNodeInfoBuffer);
}
//! Returns depth of BVH tree from last build.
public:
//! Returns array of node min points.
- typename BVHTools::ArrayType<T, N>::Type& MinPointBuffer()
+ typename BVH::ArrayType<T, N>::Type& MinPointBuffer()
{
return myMinPointBuffer;
}
//! Returns array of node min points.
- const typename BVHTools::ArrayType<T, N>::Type& MinPointBuffer() const
+ const typename BVH::ArrayType<T, N>::Type& MinPointBuffer() const
{
return myMinPointBuffer;
}
//! Returns array of node max points.
- typename BVHTools::ArrayType<T, N>::Type& MaxPointBuffer()
+ typename BVH::ArrayType<T, N>::Type& MaxPointBuffer()
{
return myMaxPointBuffer;
}
//! Returns array of node max points.
- const typename BVHTools::ArrayType<T, N>::Type& MaxPointBuffer() const
+ const typename BVH::ArrayType<T, N>::Type& MaxPointBuffer() const
{
return myMaxPointBuffer;
}
protected:
//! Array of node minimum points.
- typename BVHTools::ArrayType<T, N>::Type myMinPointBuffer;
+ typename BVH::ArrayType<T, N>::Type myMinPointBuffer;
//! Array of node maximum points.
- typename BVHTools::ArrayType<T, N>::Type myMaxPointBuffer;
+ typename BVH::ArrayType<T, N>::Type myMaxPointBuffer;
//! Array of node data records.
BVH_Array4i myNodeInfoBuffer;
{
myDepth = 0;
- BVHTools::ArrayOp<T, N>::Clear (myMinPointBuffer);
- BVHTools::ArrayOp<T, N>::Clear (myMaxPointBuffer);
+ BVH::ArrayOp<T, N>::Clear (myMinPointBuffer);
+ BVH::ArrayOp<T, N>::Clear (myMaxPointBuffer);
- BVHTools::ArrayOp<Standard_Integer, 4>::Clear (myNodeInfoBuffer);
+ BVH::ArrayOp<Standard_Integer, 4>::Clear (myNodeInfoBuffer);
}
// =======================================================================
const Standard_Integer theBegElem,
const Standard_Integer theEndElem)
{
- BVHTools::ArrayOp<T, N>::Append (myMinPointBuffer, theMinPoint);
- BVHTools::ArrayOp<T, N>::Append (myMaxPointBuffer, theMaxPoint);
+ BVH::ArrayOp<T, N>::Append (myMinPointBuffer, theMinPoint);
+ BVH::ArrayOp<T, N>::Append (myMaxPointBuffer, theMaxPoint);
- BVHTools::ArrayOp<Standard_Integer, 4>::Append (myNodeInfoBuffer, BVH_Vec4i (1, theBegElem, theEndElem, 0));
+ BVH::ArrayOp<Standard_Integer, 4>::Append (myNodeInfoBuffer, BVH_Vec4i (1, theBegElem, theEndElem, 0));
- return static_cast<Standard_Integer> (BVHTools::ArrayOp<Standard_Integer, 4>::Size (myNodeInfoBuffer) - 1);
+ return static_cast<Standard_Integer> (BVH::ArrayOp<Standard_Integer, 4>::Size (myNodeInfoBuffer) - 1);
}
// =======================================================================
const Standard_Integer theLftChild,
const Standard_Integer theRghChild)
{
- BVHTools::ArrayOp<T, N>::Append (myMinPointBuffer, theMinPoint);
- BVHTools::ArrayOp<T, N>::Append (myMaxPointBuffer, theMaxPoint);
+ BVH::ArrayOp<T, N>::Append (myMinPointBuffer, theMinPoint);
+ BVH::ArrayOp<T, N>::Append (myMaxPointBuffer, theMaxPoint);
- BVHTools::ArrayOp<Standard_Integer, 4>::Append (myNodeInfoBuffer, BVH_Vec4i (0, theLftChild, theRghChild, 0));
+ BVH::ArrayOp<Standard_Integer, 4>::Append (myNodeInfoBuffer, BVH_Vec4i (0, theLftChild, theRghChild, 0));
- return static_cast<Standard_Integer> (BVHTools::ArrayOp<Standard_Integer, 4>::Size (myNodeInfoBuffer) - 1);
+ return static_cast<Standard_Integer> (BVH::ArrayOp<Standard_Integer, 4>::Size (myNodeInfoBuffer) - 1);
}
// =======================================================================
return AddInnerNode (theAABB.CornerMin(), theAABB.CornerMax(), theLftChild, theRghChild);
}
-namespace BVHTools
+namespace BVH
{
template<class T, int N>
void EstimateSAH (const BVH_Tree<T, N>* theTree,
T BVH_Tree<T, N>::EstimateSAH() const
{
T aSAH = static_cast<T> (0.0);
- BVHTools::EstimateSAH (this, 0, static_cast<T> (1.0), aSAH);
+ BVH::EstimateSAH (this, 0, static_cast<T> (1.0), aSAH);
return aSAH;
}
{
public:
- typedef typename BVHTools::VectorType<T, N>::Type BVH_VecNt;
+ typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
public:
public:
//! Array of vertex coordinates.
- typename BVHTools::ArrayType<T, N>::Type Vertices;
+ typename BVH::ArrayType<T, N>::Type Vertices;
//! Array of indices of triangle indicies vertices.
BVH_Array4i Elements;
template<class T, int N>
Standard_Integer BVH_Triangulation<T, N>::Size() const
{
- return BVHTools::ArrayOp<Standard_Integer, 4>::Size (Elements);
+ return BVH::ArrayOp<Standard_Integer, 4>::Size (Elements);
}
// =======================================================================
template<class T, int N>
BVH_Box<T, N> BVH_Triangulation<T, N>::Box (const Standard_Integer theIndex) const
{
- const BVH_Vec4i& anIndex = BVHTools::ArrayOp<Standard_Integer, 4>::Value (Elements, theIndex);
+ const BVH_Vec4i& anIndex = BVH::ArrayOp<Standard_Integer, 4>::Value (Elements, theIndex);
- const BVH_VecNt& aPoint0 = BVHTools::ArrayOp<T, N>::Value (Vertices, anIndex.x());
- const BVH_VecNt& aPoint1 = BVHTools::ArrayOp<T, N>::Value (Vertices, anIndex.y());
- const BVH_VecNt& aPoint2 = BVHTools::ArrayOp<T, N>::Value (Vertices, anIndex.z());
+ const BVH_VecNt& aPoint0 = BVH::ArrayOp<T, N>::Value (Vertices, anIndex.x());
+ const BVH_VecNt& aPoint1 = BVH::ArrayOp<T, N>::Value (Vertices, anIndex.y());
+ const BVH_VecNt& aPoint2 = BVH::ArrayOp<T, N>::Value (Vertices, anIndex.z());
- const BVH_VecNt aMinPoint = aPoint0.cwiseMin (aPoint1.cwiseMin (aPoint2));
- const BVH_VecNt aMaxPoint = aPoint0.cwiseMax (aPoint1.cwiseMax (aPoint2));
+ BVH_VecNt aMinPoint = aPoint0;
+ BVH_VecNt aMaxPoint = aPoint0;
+
+ BVH::BoxMinMax<T, N>::CwiseMin (aMinPoint, aPoint1);
+ BVH::BoxMinMax<T, N>::CwiseMin (aMinPoint, aPoint2);
+ BVH::BoxMinMax<T, N>::CwiseMax (aMaxPoint, aPoint1);
+ BVH::BoxMinMax<T, N>::CwiseMax (aMaxPoint, aPoint2);
return BVH_Box<T, N> (aMinPoint, aMaxPoint);
}
T BVH_Triangulation<T, N>::Center (const Standard_Integer theIndex,
const Standard_Integer theAxis) const
{
- const BVH_Vec4i& anIndex = BVHTools::ArrayOp<Standard_Integer, 4>::Value (Elements, theIndex);
+ const BVH_Vec4i& anIndex = BVH::ArrayOp<Standard_Integer, 4>::Value (Elements, theIndex);
- const BVH_VecNt& aPoint0 = BVHTools::ArrayOp<T, N>::Value (Vertices, anIndex.x());
- const BVH_VecNt& aPoint1 = BVHTools::ArrayOp<T, N>::Value (Vertices, anIndex.y());
- const BVH_VecNt& aPoint2 = BVHTools::ArrayOp<T, N>::Value (Vertices, anIndex.z());
+ const BVH_VecNt& aPoint0 = BVH::ArrayOp<T, N>::Value (Vertices, anIndex.x());
+ const BVH_VecNt& aPoint1 = BVH::ArrayOp<T, N>::Value (Vertices, anIndex.y());
+ const BVH_VecNt& aPoint2 = BVH::ArrayOp<T, N>::Value (Vertices, anIndex.z());
- return ( BVHTools::VecComp<T, N>::Get (aPoint0, theAxis) +
- BVHTools::VecComp<T, N>::Get (aPoint1, theAxis) +
- BVHTools::VecComp<T, N>::Get (aPoint2, theAxis) ) * static_cast<T> (1.0 / 3.0);
+ return ( BVH::VecComp<T, N>::Get (aPoint0, theAxis) +
+ BVH::VecComp<T, N>::Get (aPoint1, theAxis) +
+ BVH::VecComp<T, N>::Get (aPoint2, theAxis) ) * static_cast<T> (1.0 / 3.0);
}
// =======================================================================
void BVH_Triangulation<T, N>::Swap (const Standard_Integer theIndex1,
const Standard_Integer theIndex2)
{
- BVH_Vec4i anIndices1 = BVHTools::ArrayOp<Standard_Integer, 4>::Value (Elements, theIndex1);
- BVH_Vec4i anIndices2 = BVHTools::ArrayOp<Standard_Integer, 4>::Value (Elements, theIndex2);
+ BVH_Vec4i anIndices1 = BVH::ArrayOp<Standard_Integer, 4>::Value (Elements, theIndex1);
+ BVH_Vec4i anIndices2 = BVH::ArrayOp<Standard_Integer, 4>::Value (Elements, theIndex2);
- BVHTools::ArrayOp<Standard_Integer, 4>::ChangeValue (Elements, theIndex1) = anIndices2;
- BVHTools::ArrayOp<Standard_Integer, 4>::ChangeValue (Elements, theIndex2) = anIndices1;
+ BVH::ArrayOp<Standard_Integer, 4>::ChangeValue (Elements, theIndex1) = anIndices2;
+ BVH::ArrayOp<Standard_Integer, 4>::ChangeValue (Elements, theIndex2) = anIndices1;
}
#include <vector>
-namespace BVHTools
+namespace BVH
{
- //! Allows to fast switching between Eigen and NCollection vectors.
+ //! Allows for fast switching between Eigen and NCollection vectors.
template<class T, int N> struct VectorType
{
// Not implemented
}
//! 2D vector of integers.
-typedef BVHTools::VectorType<Standard_Integer, 2>::Type BVH_Vec2i;
+typedef BVH::VectorType<Standard_Integer, 2>::Type BVH_Vec2i;
//! 3D vector of integers.
-typedef BVHTools::VectorType<Standard_Integer, 3>::Type BVH_Vec3i;
+typedef BVH::VectorType<Standard_Integer, 3>::Type BVH_Vec3i;
//! 4D vector of integers.
-typedef BVHTools::VectorType<Standard_Integer, 4>::Type BVH_Vec4i;
+typedef BVH::VectorType<Standard_Integer, 4>::Type BVH_Vec4i;
//! Array of 2D vectors of integers.
-typedef BVHTools::ArrayType<Standard_Integer, 2>::Type BVH_Array2i;
+typedef BVH::ArrayType<Standard_Integer, 2>::Type BVH_Array2i;
//! Array of 3D vectors of integers.
-typedef BVHTools::ArrayType<Standard_Integer, 3>::Type BVH_Array3i;
+typedef BVH::ArrayType<Standard_Integer, 3>::Type BVH_Array3i;
//! Array of 4D vectors of integers.
-typedef BVHTools::ArrayType<Standard_Integer, 4>::Type BVH_Array4i;
+typedef BVH::ArrayType<Standard_Integer, 4>::Type BVH_Array4i;
//! 2D vector of single precision reals.
-typedef BVHTools::VectorType<Standard_ShortReal, 2>::Type BVH_Vec2f;
+typedef BVH::VectorType<Standard_ShortReal, 2>::Type BVH_Vec2f;
//! 3D vector of single precision reals.
-typedef BVHTools::VectorType<Standard_ShortReal, 3>::Type BVH_Vec3f;
+typedef BVH::VectorType<Standard_ShortReal, 3>::Type BVH_Vec3f;
//! 4D vector of single precision reals.
-typedef BVHTools::VectorType<Standard_ShortReal, 4>::Type BVH_Vec4f;
+typedef BVH::VectorType<Standard_ShortReal, 4>::Type BVH_Vec4f;
//! Array of 2D vectors of single precision reals.
-typedef BVHTools::ArrayType<Standard_ShortReal, 2>::Type BVH_Array2f;
+typedef BVH::ArrayType<Standard_ShortReal, 2>::Type BVH_Array2f;
//! Array of 3D vectors of single precision reals.
-typedef BVHTools::ArrayType<Standard_ShortReal, 3>::Type BVH_Array3f;
+typedef BVH::ArrayType<Standard_ShortReal, 3>::Type BVH_Array3f;
//! Array of 4D vectors of single precision reals.
-typedef BVHTools::ArrayType<Standard_ShortReal, 4>::Type BVH_Array4f;
+typedef BVH::ArrayType<Standard_ShortReal, 4>::Type BVH_Array4f;
//! 2D vector of double precision reals.
-typedef BVHTools::VectorType<Standard_Real, 2>::Type BVH_Vec2d;
+typedef BVH::VectorType<Standard_Real, 2>::Type BVH_Vec2d;
//! 3D vector of double precision reals.
-typedef BVHTools::VectorType<Standard_Real, 3>::Type BVH_Vec3d;
+typedef BVH::VectorType<Standard_Real, 3>::Type BVH_Vec3d;
//! 4D vector of double precision reals.
-typedef BVHTools::VectorType<Standard_Real, 4>::Type BVH_Vec4d;
+typedef BVH::VectorType<Standard_Real, 4>::Type BVH_Vec4d;
//! Array of 2D vectors of double precision reals.
-typedef BVHTools::ArrayType<Standard_Real, 2>::Type BVH_Array2d;
+typedef BVH::ArrayType<Standard_Real, 2>::Type BVH_Array2d;
//! Array of 3D vectors of double precision reals.
-typedef BVHTools::ArrayType<Standard_Real, 3>::Type BVH_Array3d;
+typedef BVH::ArrayType<Standard_Real, 3>::Type BVH_Array3d;
//! Array of 4D vectors of double precision reals.
-typedef BVHTools::ArrayType<Standard_Real, 4>::Type BVH_Array4d;
+typedef BVH::ArrayType<Standard_Real, 4>::Type BVH_Array4d;
//! 4x4 matrix of single precision reals.
-typedef BVHTools::MatrixType<Standard_ShortReal, 4>::Type BVH_Mat4f;
+typedef BVH::MatrixType<Standard_ShortReal, 4>::Type BVH_Mat4f;
//! 4x4 matrix of double precision reals.
-typedef BVHTools::MatrixType<Standard_Real, 4>::Type BVH_Mat4d;
+typedef BVH::MatrixType<Standard_Real, 4>::Type BVH_Mat4d;
#include <BVH_Types.lxx>
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-namespace BVHTools
+namespace BVH
{
template<class T, int N> struct VecComp
{
template<class T> struct VecComp<T, 2>
{
- typedef typename BVHTools::VectorType<T, 2>::Type BVH_Vec2t;
+ typedef typename BVH::VectorType<T, 2>::Type BVH_Vec2t;
static T Get (const BVH_Vec2t& theVec,
const Standard_Integer theAxis)
template<class T> struct VecComp<T, 3>
{
- typedef typename BVHTools::VectorType<T, 3>::Type BVH_Vec3t;
+ typedef typename BVH::VectorType<T, 3>::Type BVH_Vec3t;
static T Get (const BVH_Vec3t& theVec,
const Standard_Integer theAxis)
template<class T> struct VecComp<T, 4>
{
- typedef typename BVHTools::VectorType<T, 4>::Type BVH_Vec4t;
+ typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
static T Get (const BVH_Vec4t& theVec,
const Standard_Integer theAxis)
template<class T, int N = 1> struct ArrayOp
{
- typedef typename BVHTools::ArrayType<T, N>::Type BVH_ArrayNt;
+ typedef typename BVH::ArrayType<T, N>::Type BVH_ArrayNt;
static inline
- const typename BVHTools::VectorType<T, N>::Type& Value (const BVH_ArrayNt& theArray,
- const Standard_Integer theIndex)
+ const typename BVH::VectorType<T, N>::Type& Value (const BVH_ArrayNt& theArray,
+ const Standard_Integer theIndex)
{
#ifdef _BVH_USE_STD_VECTOR_
return theArray.at (theIndex);
}
static inline
- typename BVHTools::VectorType<T, N>::Type& ChangeValue (BVH_ArrayNt& theArray,
- const Standard_Integer theIndex)
+ typename BVH::VectorType<T, N>::Type& ChangeValue (BVH_ArrayNt& theArray,
+ const Standard_Integer theIndex)
{
#ifdef _BVH_USE_STD_VECTOR_
return theArray.at (theIndex);
}
static inline void Append (BVH_ArrayNt& theArray,
- const typename BVHTools::VectorType<T, N>::Type& theElement)
+ const typename BVH::VectorType<T, N>::Type& theElement)
{
#ifdef _BVH_USE_STD_VECTOR_
theArray.push_back (theElement);