1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0025227: Visualization - optimize BVH binned builder

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%.
This commit is contained in:
dbp
2014-09-24 12:03:22 +04:00
committed by bugmaster
parent 30d33e7141
commit 3a7a70135c
13 changed files with 191 additions and 134 deletions

View File

@@ -36,6 +36,17 @@ BVH_BinnedBuilder<T, N, Bins>::~BVH_BinnedBuilder()
//
}
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 :
@@ -47,16 +58,18 @@ void BVH_BinnedBuilder<T, N, Bins>::GetSubVolumes (BVH_Set<T, N>* theSet
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;
@@ -71,7 +84,7 @@ void BVH_BinnedBuilder<T, N, Bins>::GetSubVolumes (BVH_Set<T, N>* theSet
}
}
namespace BVHTools
namespace BVH
{
// =======================================================================
// function : SplitPrimitives
@@ -86,21 +99,21 @@ namespace BVHTools
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;
}
@@ -163,7 +176,7 @@ void BVH_BinnedBuilder<T, N, Bins>::BuildNode (BVH_Set<T, N>* theSet,
// 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;
@@ -235,7 +248,7 @@ void BVH_BinnedBuilder<T, N, Bins>::BuildNode (BVH_Set<T, N>* theSet,
}
else
{
aMiddle = BVHTools::SplitPrimitives<T, N> (theSet, anAABB,
aMiddle = BVH::SplitPrimitives<T, N> (theSet, anAABB,
aNodeBegPrimitive, aNodeEndPrimitive, aMinSplitIndex - 1, aMinSplitAxis, Bins);
}

View File

@@ -24,7 +24,7 @@ class BVH_Box
{
public:
typedef typename BVHTools::VectorType<T, N>::Type BVH_VecNt;
typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
public:

View File

@@ -15,7 +15,7 @@
#include <Standard_ShortReal.hxx>
namespace BVHTools
namespace BVH
{
template<class T, int N>
struct CenterAxis {
@@ -126,6 +126,47 @@ void BVH_Box<T, N>::Add (const BVH_VecNt& thePoint)
}
}
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 :
@@ -133,26 +174,24 @@ void BVH_Box<T, N>::Add (const BVH_VecNt& thePoint)
template<class T, int N>
void BVH_Box<T, N>::Combine (const BVH_Box& theBox)
{
if (!theBox.myInitialized)
if (theBox.myInitialized)
{
return;
}
if (!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

View File

@@ -96,7 +96,7 @@ T BVH_ObjectSet<T, N>::Center (const Standard_Integer theIndex,
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);
}
// =======================================================================

View File

@@ -37,7 +37,7 @@ class BVH_Transform : public BVH_Properties
public:
//! Type of transformation matrix.
typedef typename BVHTools::MatrixType<T, N>::Type BVH_MatNt;
typedef typename BVH::MatrixType<T, N>::Type BVH_MatNt;
public:

View File

@@ -54,7 +54,7 @@ const typename BVH_Transform<T, N>::BVH_MatNt& BVH_Transform<T, N>::Transform()
return myTransform;
}
namespace BVHTools
namespace BVH
{
template<class T, int N> struct MatrixOp
{
@@ -63,7 +63,7 @@ namespace BVHTools
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)
@@ -71,7 +71,7 @@ namespace BVHTools
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)
@@ -90,7 +90,7 @@ template<class T, int N>
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);
}
// =======================================================================
@@ -103,7 +103,7 @@ const typename BVH_Transform<T, N>::BVH_MatNt& BVH_Transform<T, N>::Inversed() c
return myTransformInversed;
}
namespace BVHTools
namespace BVH
{
template<class T, int N>
struct UnitVector
@@ -114,7 +114,7 @@ namespace BVHTools
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()
{
@@ -138,7 +138,7 @@ namespace BVHTools
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()
{
@@ -165,7 +165,7 @@ namespace BVHTools
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()
{
@@ -210,11 +210,11 @@ BVH_Box<T, N> BVH_Transform<T, N>::Apply (const BVH_Box<T, N>& theBox) const
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));
}
}
}

View File

@@ -68,8 +68,8 @@ void BVH_SweepPlaneBuilder<T, N>::BuildNode (BVH_Set<T, N>* theSet,
// 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;

View File

@@ -50,73 +50,73 @@ public:
//! 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.
@@ -128,37 +128,37 @@ public:
//! 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.
@@ -202,25 +202,25 @@ public:
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;
}
@@ -240,10 +240,10 @@ public:
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;

View File

@@ -22,10 +22,10 @@ void BVH_Tree<T, N>::Clear()
{
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);
}
// =======================================================================
@@ -38,12 +38,12 @@ Standard_Integer BVH_Tree<T, N>::AddLeafNode (const BVH_VecNt& theMinPoint
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);
}
// =======================================================================
@@ -56,12 +56,12 @@ Standard_Integer BVH_Tree<T, N>::AddInnerNode (const BVH_VecNt& theMinPoin
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);
}
// =======================================================================
@@ -88,7 +88,7 @@ Standard_Integer BVH_Tree<T, N>::AddInnerNode (const BVH_Box<T, N>& theAABB,
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,
@@ -136,6 +136,6 @@ template<class T, int N>
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;
}

View File

@@ -24,7 +24,7 @@ class BVH_Triangulation : public BVH_PrimitiveSet<T, N>
{
public:
typedef typename BVHTools::VectorType<T, N>::Type BVH_VecNt;
typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
public:
@@ -37,7 +37,7 @@ 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;

View File

@@ -40,7 +40,7 @@ BVH_Triangulation<T, N>::~BVH_Triangulation()
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);
}
// =======================================================================
@@ -50,14 +50,19 @@ Standard_Integer BVH_Triangulation<T, N>::Size() const
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);
}
@@ -70,15 +75,15 @@ template<class T, int N>
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);
}
// =======================================================================
@@ -89,9 +94,9 @@ template<class T, int N>
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;
}

View File

@@ -28,9 +28,9 @@
#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
@@ -78,52 +78,52 @@ namespace BVHTools
}
//! 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>

View File

@@ -13,7 +13,7 @@
// 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
{
@@ -22,7 +22,7 @@ namespace BVHTools
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)
@@ -33,7 +33,7 @@ namespace BVHTools
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)
@@ -44,7 +44,7 @@ namespace BVHTools
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)
@@ -57,11 +57,11 @@ namespace BVHTools
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);
@@ -71,8 +71,8 @@ namespace BVHTools
}
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);
@@ -82,7 +82,7 @@ namespace BVHTools
}
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);