From 3a7a70135ccc1928df7049616ff719fc99b98363 Mon Sep 17 00:00:00 2001 From: dbp Date: Wed, 24 Sep 2014 12:03:22 +0400 Subject: [PATCH] 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%. --- src/BVH/BVH_BinnedBuilder.lxx | 37 ++++++++++------ src/BVH/BVH_Box.hxx | 2 +- src/BVH/BVH_Box.lxx | 71 ++++++++++++++++++++++++------- src/BVH/BVH_ObjectSet.lxx | 2 +- src/BVH/BVH_Properties.hxx | 2 +- src/BVH/BVH_Properties.lxx | 24 +++++------ src/BVH/BVH_SweepPlaneBuilder.lxx | 4 +- src/BVH/BVH_Tree.hxx | 48 ++++++++++----------- src/BVH/BVH_Tree.lxx | 26 +++++------ src/BVH/BVH_Triangulation.hxx | 4 +- src/BVH/BVH_Triangulation.lxx | 41 ++++++++++-------- src/BVH/BVH_Types.hxx | 44 +++++++++---------- src/BVH/BVH_Types.lxx | 20 ++++----- 13 files changed, 191 insertions(+), 134 deletions(-) diff --git a/src/BVH/BVH_BinnedBuilder.lxx b/src/BVH/BVH_BinnedBuilder.lxx index 207c9ee025..c002b5680a 100644 --- a/src/BVH/BVH_BinnedBuilder.lxx +++ b/src/BVH/BVH_BinnedBuilder.lxx @@ -36,6 +36,17 @@ BVH_BinnedBuilder::~BVH_BinnedBuilder() // } +namespace BVH +{ + template + static inline Standard_Integer IntFloor (const T theValue) + { + const Standard_Integer aRes = static_cast (theValue); + + return aRes - static_cast (aRes > theValue); + } +} + // ======================================================================= // function : GetSubVolumes // purpose : @@ -47,16 +58,18 @@ void BVH_BinnedBuilder::GetSubVolumes (BVH_Set* theSet BVH_BinVector& theBins, const Standard_Integer theAxis) { - const T aMin = BVHTools::VecComp::Get (theBVH->MinPoint (theNode), theAxis); - const T aMax = BVHTools::VecComp::Get (theBVH->MaxPoint (theNode), theAxis); + const T aMin = BVH::VecComp::Get (theBVH->MinPoint (theNode), theAxis); + const T aMax = BVH::VecComp::Get (theBVH->MaxPoint (theNode), theAxis); - const T anInvStep = static_cast (Bins) / (aMax - aMin); + const T anInverseStep = static_cast (Bins) / (aMax - aMin); for (Standard_Integer anIdx = theBVH->BegPrimitive (theNode); anIdx <= theBVH->EndPrimitive (theNode); ++anIdx) { typename BVH_Set::BVH_BoxNt aBox = theSet->Box (anIdx); - Standard_Integer aBinIndex = static_cast (std::floor ((theSet->Center (anIdx, theAxis) - aMin) * anInvStep)); + Standard_Integer aBinIndex = BVH::IntFloor ( + (theSet->Center (anIdx, theAxis) - aMin) * anInverseStep); + if (aBinIndex < 0) { aBinIndex = 0; @@ -71,7 +84,7 @@ void BVH_BinnedBuilder::GetSubVolumes (BVH_Set* 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::Get (theBox.CornerMin(), theAxis); - const T aMax = BVHTools::VecComp::Get (theBox.CornerMax(), theAxis); + const T aMin = BVH::VecComp::Get (theBox.CornerMin(), theAxis); + const T aMax = BVH::VecComp::Get (theBox.CornerMax(), theAxis); - const T anInvStep = static_cast (theBins) / (aMax - aMin); + const T anInverseStep = static_cast (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 ((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 ((theSet->Center (aRghIdx, theAxis) - aMin) * anInverseStep) > theBin && aRghIdx > theBeg) { --aRghIdx; } @@ -163,7 +176,7 @@ void BVH_BinnedBuilder::BuildNode (BVH_Set* theSet, // Find best split for (Standard_Integer anAxis = 0; anAxis < (N < 4 ? N : 3); ++anAxis) { - if (BVHTools::VecComp::Get (aSize, anAxis) <= THE_NODE_MIN_SIZE) + if (BVH::VecComp::Get (aSize, anAxis) <= THE_NODE_MIN_SIZE) continue; BVH_BinVector aBins; @@ -235,7 +248,7 @@ void BVH_BinnedBuilder::BuildNode (BVH_Set* theSet, } else { - aMiddle = BVHTools::SplitPrimitives (theSet, anAABB, + aMiddle = BVH::SplitPrimitives (theSet, anAABB, aNodeBegPrimitive, aNodeEndPrimitive, aMinSplitIndex - 1, aMinSplitAxis, Bins); } diff --git a/src/BVH/BVH_Box.hxx b/src/BVH/BVH_Box.hxx index 70148236e3..fc1f4a76bf 100644 --- a/src/BVH/BVH_Box.hxx +++ b/src/BVH/BVH_Box.hxx @@ -24,7 +24,7 @@ class BVH_Box { public: - typedef typename BVHTools::VectorType::Type BVH_VecNt; + typedef typename BVH::VectorType::Type BVH_VecNt; public: diff --git a/src/BVH/BVH_Box.lxx b/src/BVH/BVH_Box.lxx index 80098819e6..b727561018 100644 --- a/src/BVH/BVH_Box.lxx +++ b/src/BVH/BVH_Box.lxx @@ -15,7 +15,7 @@ #include -namespace BVHTools +namespace BVH { template struct CenterAxis { @@ -126,6 +126,47 @@ void BVH_Box::Add (const BVH_VecNt& thePoint) } } +namespace BVH +{ + template + struct BoxMinMax + { + typedef typename BVH::VectorType::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 + struct BoxMinMax + { + typedef typename BVH::VectorType::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::Add (const BVH_VecNt& thePoint) template void BVH_Box::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::CwiseMin (myMinPoint, theBox.myMinPoint); + BVH::BoxMinMax::CwiseMax (myMaxPoint, theBox.myMaxPoint); + } } } -namespace BVHTools +namespace BVH { template struct SurfaceCalculator diff --git a/src/BVH/BVH_ObjectSet.lxx b/src/BVH/BVH_ObjectSet.lxx index 11dc7f4e8c..3140af31da 100644 --- a/src/BVH/BVH_ObjectSet.lxx +++ b/src/BVH/BVH_ObjectSet.lxx @@ -96,7 +96,7 @@ T BVH_ObjectSet::Center (const Standard_Integer theIndex, const Standard_Integer theAxis) const { typename BVH_Set::BVH_BoxNt aBox = myObjects.Value (theIndex)->Box(); - return BVHTools::CenterAxis::Center (aBox, theAxis); + return BVH::CenterAxis::Center (aBox, theAxis); } // ======================================================================= diff --git a/src/BVH/BVH_Properties.hxx b/src/BVH/BVH_Properties.hxx index aa47e9bd56..6cb6e2c216 100644 --- a/src/BVH/BVH_Properties.hxx +++ b/src/BVH/BVH_Properties.hxx @@ -37,7 +37,7 @@ class BVH_Transform : public BVH_Properties public: //! Type of transformation matrix. - typedef typename BVHTools::MatrixType::Type BVH_MatNt; + typedef typename BVH::MatrixType::Type BVH_MatNt; public: diff --git a/src/BVH/BVH_Properties.lxx b/src/BVH/BVH_Properties.lxx index 1c6003c58b..0fed18914d 100644 --- a/src/BVH/BVH_Properties.lxx +++ b/src/BVH/BVH_Properties.lxx @@ -54,7 +54,7 @@ const typename BVH_Transform::BVH_MatNt& BVH_Transform::Transform() return myTransform; } -namespace BVHTools +namespace BVH { template struct MatrixOp { @@ -63,7 +63,7 @@ namespace BVHTools template struct MatrixOp { - typedef typename BVHTools::MatrixType::Type BVH_Mat4t; + typedef typename BVH::MatrixType::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::Type BVH_Vec4t; + typedef typename BVH::VectorType::Type BVH_Vec4t; static BVH_Vec4t Multiply (const BVH_Mat4t& theMat, const BVH_Vec4t& theVec) @@ -90,7 +90,7 @@ template void BVH_Transform::SetTransform (const BVH_MatNt& theTransform) { myTransform = theTransform; - BVHTools::MatrixOp::Inverse (myTransform, myTransformInversed); + BVH::MatrixOp::Inverse (myTransform, myTransformInversed); } // ======================================================================= @@ -103,7 +103,7 @@ const typename BVH_Transform::BVH_MatNt& BVH_Transform::Inversed() c return myTransformInversed; } -namespace BVHTools +namespace BVH { template struct UnitVector @@ -114,7 +114,7 @@ namespace BVHTools template struct UnitVector { - typedef typename BVHTools::VectorType::Type BVH_Vec2t; + typedef typename BVH::VectorType::Type BVH_Vec2t; static BVH_Vec2t DX() { @@ -138,7 +138,7 @@ namespace BVHTools template struct UnitVector { - typedef typename BVHTools::VectorType::Type BVH_Vec3t; + typedef typename BVH::VectorType::Type BVH_Vec3t; static BVH_Vec3t DX() { @@ -165,7 +165,7 @@ namespace BVHTools template struct UnitVector { - typedef typename BVHTools::VectorType::Type BVH_Vec4t; + typedef typename BVH::VectorType::Type BVH_Vec4t; static BVH_Vec4t DX() { @@ -210,11 +210,11 @@ BVH_Box BVH_Transform::Apply (const BVH_Box& theBox) const for (Standard_Integer aZ = 0; aZ <= 1; ++aZ) { typename BVH_Box::BVH_VecNt aCorner = theBox.CornerMin() + - BVHTools::UnitVector::DX() * aSize * static_cast (aX) + - BVHTools::UnitVector::DY() * aSize * static_cast (aY) + - BVHTools::UnitVector::DZ() * aSize * static_cast (aZ); + BVH::UnitVector::DX() * aSize * static_cast (aX) + + BVH::UnitVector::DY() * aSize * static_cast (aY) + + BVH::UnitVector::DZ() * aSize * static_cast (aZ); - aBox.Add (BVHTools::MatrixOp::Multiply (myTransform, aCorner)); + aBox.Add (BVH::MatrixOp::Multiply (myTransform, aCorner)); } } } diff --git a/src/BVH/BVH_SweepPlaneBuilder.lxx b/src/BVH/BVH_SweepPlaneBuilder.lxx index 62ef763b68..cfa1255eb0 100644 --- a/src/BVH/BVH_SweepPlaneBuilder.lxx +++ b/src/BVH/BVH_SweepPlaneBuilder.lxx @@ -68,8 +68,8 @@ void BVH_SweepPlaneBuilder::BuildNode (BVH_Set* theSet, // Find best split for (Standard_Integer anAxis = 0; anAxis < (N < 4 ? N : 3); ++anAxis) { - const T aNodeSize = BVHTools::VecComp::Get (theBVH->MaxPoint (theNode), anAxis) - - BVHTools::VecComp::Get (theBVH->MinPoint (theNode), anAxis); + const T aNodeSize = BVH::VecComp::Get (theBVH->MaxPoint (theNode), anAxis) - + BVH::VecComp::Get (theBVH->MinPoint (theNode), anAxis); if (aNodeSize <= THE_NODE_MIN_SIZE) { continue; diff --git a/src/BVH/BVH_Tree.hxx b/src/BVH/BVH_Tree.hxx index 2b309d40d1..c92cddd710 100644 --- a/src/BVH/BVH_Tree.hxx +++ b/src/BVH/BVH_Tree.hxx @@ -50,73 +50,73 @@ public: //! Returns minimum point of the given node. BVH_VecNt& MinPoint (const Standard_Integer theNodeIndex) { - return BVHTools::ArrayOp::ChangeValue (myMinPointBuffer, theNodeIndex); + return BVH::ArrayOp::ChangeValue (myMinPointBuffer, theNodeIndex); } //! Returns maximum point of the given node. BVH_VecNt& MaxPoint (const Standard_Integer theNodeIndex) { - return BVHTools::ArrayOp::ChangeValue (myMaxPointBuffer, theNodeIndex); + return BVH::ArrayOp::ChangeValue (myMaxPointBuffer, theNodeIndex); } //! Returns minimum point of the given node. const BVH_VecNt& MinPoint (const Standard_Integer theNodeIndex) const { - return BVHTools::ArrayOp::Value (myMinPointBuffer, theNodeIndex); + return BVH::ArrayOp::Value (myMinPointBuffer, theNodeIndex); } //! Returns maximum point of the given node. const BVH_VecNt& MaxPoint (const Standard_Integer theNodeIndex) const { - return BVHTools::ArrayOp::Value (myMaxPointBuffer, theNodeIndex); + return BVH::ArrayOp::Value (myMaxPointBuffer, theNodeIndex); } //! Returns index of left child of the given inner node. Standard_Integer& LeftChild (const Standard_Integer theNodeIndex) { - return BVHTools::ArrayOp::ChangeValue (myNodeInfoBuffer, theNodeIndex).y(); + return BVH::ArrayOp::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::Value (myNodeInfoBuffer, theNodeIndex).y(); + return BVH::ArrayOp::Value (myNodeInfoBuffer, theNodeIndex).y(); } //! Returns index of right child of the given inner node. Standard_Integer& RightChild (const Standard_Integer theNodeIndex) { - return BVHTools::ArrayOp::ChangeValue (myNodeInfoBuffer, theNodeIndex).z(); + return BVH::ArrayOp::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::Value (myNodeInfoBuffer, theNodeIndex).z(); + return BVH::ArrayOp::Value (myNodeInfoBuffer, theNodeIndex).z(); } //! Returns index of first primitive of the given leaf node. Standard_Integer& BegPrimitive (const Standard_Integer theNodeIndex) { - return BVHTools::ArrayOp::ChangeValue (myNodeInfoBuffer, theNodeIndex).y(); + return BVH::ArrayOp::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::Value (myNodeInfoBuffer, theNodeIndex).y(); + return BVH::ArrayOp::Value (myNodeInfoBuffer, theNodeIndex).y(); } //! Returns index of last primitive of the given leaf node. Standard_Integer& EndPrimitive (const Standard_Integer theNodeIndex) { - return BVHTools::ArrayOp::ChangeValue (myNodeInfoBuffer, theNodeIndex).z(); + return BVH::ArrayOp::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::Value (myNodeInfoBuffer, theNodeIndex).z(); + return BVH::ArrayOp::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::ChangeValue (myNodeInfoBuffer, theNodeIndex).w(); + return BVH::ArrayOp::ChangeValue (myNodeInfoBuffer, theNodeIndex).w(); } //! Returns level (depth) of the given node. Standard_Integer Level (const Standard_Integer theNodeIndex) const { - return BVHTools::ArrayOp::Value (myNodeInfoBuffer, theNodeIndex).w(); + return BVH::ArrayOp::Value (myNodeInfoBuffer, theNodeIndex).w(); } //! Is node a leaf (outer)? Standard_Boolean IsOuter (const Standard_Integer theNodeIndex) const { - return BVHTools::ArrayOp::Value (myNodeInfoBuffer, theNodeIndex).x() > 0; + return BVH::ArrayOp::Value (myNodeInfoBuffer, theNodeIndex).x() > 0; } //! Sets node type to 'outer'. void SetOuter (const Standard_Integer theNodeIndex) { - BVHTools::ArrayOp::ChangeValue (myNodeInfoBuffer, theNodeIndex).x() = 1; + BVH::ArrayOp::ChangeValue (myNodeInfoBuffer, theNodeIndex).x() = 1; } //! Sets node type to 'inner'. void SetInner (const Standard_Integer theNodeIndex) { - BVHTools::ArrayOp::ChangeValue (myNodeInfoBuffer, theNodeIndex).x() = 0; + BVH::ArrayOp::ChangeValue (myNodeInfoBuffer, theNodeIndex).x() = 0; } //! Returns total number of BVH nodes. Standard_Integer Length() const { - return BVHTools::ArrayOp::Size (myNodeInfoBuffer); + return BVH::ArrayOp::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::Type& MinPointBuffer() + typename BVH::ArrayType::Type& MinPointBuffer() { return myMinPointBuffer; } //! Returns array of node min points. - const typename BVHTools::ArrayType::Type& MinPointBuffer() const + const typename BVH::ArrayType::Type& MinPointBuffer() const { return myMinPointBuffer; } //! Returns array of node max points. - typename BVHTools::ArrayType::Type& MaxPointBuffer() + typename BVH::ArrayType::Type& MaxPointBuffer() { return myMaxPointBuffer; } //! Returns array of node max points. - const typename BVHTools::ArrayType::Type& MaxPointBuffer() const + const typename BVH::ArrayType::Type& MaxPointBuffer() const { return myMaxPointBuffer; } @@ -240,10 +240,10 @@ public: protected: //! Array of node minimum points. - typename BVHTools::ArrayType::Type myMinPointBuffer; + typename BVH::ArrayType::Type myMinPointBuffer; //! Array of node maximum points. - typename BVHTools::ArrayType::Type myMaxPointBuffer; + typename BVH::ArrayType::Type myMaxPointBuffer; //! Array of node data records. BVH_Array4i myNodeInfoBuffer; diff --git a/src/BVH/BVH_Tree.lxx b/src/BVH/BVH_Tree.lxx index fe9e2a3a80..98d9b2f323 100644 --- a/src/BVH/BVH_Tree.lxx +++ b/src/BVH/BVH_Tree.lxx @@ -22,10 +22,10 @@ void BVH_Tree::Clear() { myDepth = 0; - BVHTools::ArrayOp::Clear (myMinPointBuffer); - BVHTools::ArrayOp::Clear (myMaxPointBuffer); + BVH::ArrayOp::Clear (myMinPointBuffer); + BVH::ArrayOp::Clear (myMaxPointBuffer); - BVHTools::ArrayOp::Clear (myNodeInfoBuffer); + BVH::ArrayOp::Clear (myNodeInfoBuffer); } // ======================================================================= @@ -38,12 +38,12 @@ Standard_Integer BVH_Tree::AddLeafNode (const BVH_VecNt& theMinPoint const Standard_Integer theBegElem, const Standard_Integer theEndElem) { - BVHTools::ArrayOp::Append (myMinPointBuffer, theMinPoint); - BVHTools::ArrayOp::Append (myMaxPointBuffer, theMaxPoint); + BVH::ArrayOp::Append (myMinPointBuffer, theMinPoint); + BVH::ArrayOp::Append (myMaxPointBuffer, theMaxPoint); - BVHTools::ArrayOp::Append (myNodeInfoBuffer, BVH_Vec4i (1, theBegElem, theEndElem, 0)); + BVH::ArrayOp::Append (myNodeInfoBuffer, BVH_Vec4i (1, theBegElem, theEndElem, 0)); - return static_cast (BVHTools::ArrayOp::Size (myNodeInfoBuffer) - 1); + return static_cast (BVH::ArrayOp::Size (myNodeInfoBuffer) - 1); } // ======================================================================= @@ -56,12 +56,12 @@ Standard_Integer BVH_Tree::AddInnerNode (const BVH_VecNt& theMinPoin const Standard_Integer theLftChild, const Standard_Integer theRghChild) { - BVHTools::ArrayOp::Append (myMinPointBuffer, theMinPoint); - BVHTools::ArrayOp::Append (myMaxPointBuffer, theMaxPoint); + BVH::ArrayOp::Append (myMinPointBuffer, theMinPoint); + BVH::ArrayOp::Append (myMaxPointBuffer, theMaxPoint); - BVHTools::ArrayOp::Append (myNodeInfoBuffer, BVH_Vec4i (0, theLftChild, theRghChild, 0)); + BVH::ArrayOp::Append (myNodeInfoBuffer, BVH_Vec4i (0, theLftChild, theRghChild, 0)); - return static_cast (BVHTools::ArrayOp::Size (myNodeInfoBuffer) - 1); + return static_cast (BVH::ArrayOp::Size (myNodeInfoBuffer) - 1); } // ======================================================================= @@ -88,7 +88,7 @@ Standard_Integer BVH_Tree::AddInnerNode (const BVH_Box& theAABB, return AddInnerNode (theAABB.CornerMin(), theAABB.CornerMax(), theLftChild, theRghChild); } -namespace BVHTools +namespace BVH { template void EstimateSAH (const BVH_Tree* theTree, @@ -136,6 +136,6 @@ template T BVH_Tree::EstimateSAH() const { T aSAH = static_cast (0.0); - BVHTools::EstimateSAH (this, 0, static_cast (1.0), aSAH); + BVH::EstimateSAH (this, 0, static_cast (1.0), aSAH); return aSAH; } diff --git a/src/BVH/BVH_Triangulation.hxx b/src/BVH/BVH_Triangulation.hxx index e0b84b186b..f809d5f664 100644 --- a/src/BVH/BVH_Triangulation.hxx +++ b/src/BVH/BVH_Triangulation.hxx @@ -24,7 +24,7 @@ class BVH_Triangulation : public BVH_PrimitiveSet { public: - typedef typename BVHTools::VectorType::Type BVH_VecNt; + typedef typename BVH::VectorType::Type BVH_VecNt; public: @@ -37,7 +37,7 @@ public: public: //! Array of vertex coordinates. - typename BVHTools::ArrayType::Type Vertices; + typename BVH::ArrayType::Type Vertices; //! Array of indices of triangle indicies vertices. BVH_Array4i Elements; diff --git a/src/BVH/BVH_Triangulation.lxx b/src/BVH/BVH_Triangulation.lxx index a08d26de82..fb1b1801f6 100644 --- a/src/BVH/BVH_Triangulation.lxx +++ b/src/BVH/BVH_Triangulation.lxx @@ -40,7 +40,7 @@ BVH_Triangulation::~BVH_Triangulation() template Standard_Integer BVH_Triangulation::Size() const { - return BVHTools::ArrayOp::Size (Elements); + return BVH::ArrayOp::Size (Elements); } // ======================================================================= @@ -50,14 +50,19 @@ Standard_Integer BVH_Triangulation::Size() const template BVH_Box BVH_Triangulation::Box (const Standard_Integer theIndex) const { - const BVH_Vec4i& anIndex = BVHTools::ArrayOp::Value (Elements, theIndex); + const BVH_Vec4i& anIndex = BVH::ArrayOp::Value (Elements, theIndex); - const BVH_VecNt& aPoint0 = BVHTools::ArrayOp::Value (Vertices, anIndex.x()); - const BVH_VecNt& aPoint1 = BVHTools::ArrayOp::Value (Vertices, anIndex.y()); - const BVH_VecNt& aPoint2 = BVHTools::ArrayOp::Value (Vertices, anIndex.z()); + const BVH_VecNt& aPoint0 = BVH::ArrayOp::Value (Vertices, anIndex.x()); + const BVH_VecNt& aPoint1 = BVH::ArrayOp::Value (Vertices, anIndex.y()); + const BVH_VecNt& aPoint2 = BVH::ArrayOp::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::CwiseMin (aMinPoint, aPoint1); + BVH::BoxMinMax::CwiseMin (aMinPoint, aPoint2); + BVH::BoxMinMax::CwiseMax (aMaxPoint, aPoint1); + BVH::BoxMinMax::CwiseMax (aMaxPoint, aPoint2); return BVH_Box (aMinPoint, aMaxPoint); } @@ -70,15 +75,15 @@ template T BVH_Triangulation::Center (const Standard_Integer theIndex, const Standard_Integer theAxis) const { - const BVH_Vec4i& anIndex = BVHTools::ArrayOp::Value (Elements, theIndex); + const BVH_Vec4i& anIndex = BVH::ArrayOp::Value (Elements, theIndex); - const BVH_VecNt& aPoint0 = BVHTools::ArrayOp::Value (Vertices, anIndex.x()); - const BVH_VecNt& aPoint1 = BVHTools::ArrayOp::Value (Vertices, anIndex.y()); - const BVH_VecNt& aPoint2 = BVHTools::ArrayOp::Value (Vertices, anIndex.z()); + const BVH_VecNt& aPoint0 = BVH::ArrayOp::Value (Vertices, anIndex.x()); + const BVH_VecNt& aPoint1 = BVH::ArrayOp::Value (Vertices, anIndex.y()); + const BVH_VecNt& aPoint2 = BVH::ArrayOp::Value (Vertices, anIndex.z()); - return ( BVHTools::VecComp::Get (aPoint0, theAxis) + - BVHTools::VecComp::Get (aPoint1, theAxis) + - BVHTools::VecComp::Get (aPoint2, theAxis) ) * static_cast (1.0 / 3.0); + return ( BVH::VecComp::Get (aPoint0, theAxis) + + BVH::VecComp::Get (aPoint1, theAxis) + + BVH::VecComp::Get (aPoint2, theAxis) ) * static_cast (1.0 / 3.0); } // ======================================================================= @@ -89,9 +94,9 @@ template void BVH_Triangulation::Swap (const Standard_Integer theIndex1, const Standard_Integer theIndex2) { - BVH_Vec4i anIndices1 = BVHTools::ArrayOp::Value (Elements, theIndex1); - BVH_Vec4i anIndices2 = BVHTools::ArrayOp::Value (Elements, theIndex2); + BVH_Vec4i anIndices1 = BVH::ArrayOp::Value (Elements, theIndex1); + BVH_Vec4i anIndices2 = BVH::ArrayOp::Value (Elements, theIndex2); - BVHTools::ArrayOp::ChangeValue (Elements, theIndex1) = anIndices2; - BVHTools::ArrayOp::ChangeValue (Elements, theIndex2) = anIndices1; + BVH::ArrayOp::ChangeValue (Elements, theIndex1) = anIndices2; + BVH::ArrayOp::ChangeValue (Elements, theIndex2) = anIndices1; } diff --git a/src/BVH/BVH_Types.hxx b/src/BVH/BVH_Types.hxx index 6a28af262d..53e6a94dc9 100644 --- a/src/BVH/BVH_Types.hxx +++ b/src/BVH/BVH_Types.hxx @@ -28,9 +28,9 @@ #include -namespace BVHTools +namespace BVH { - //! Allows to fast switching between Eigen and NCollection vectors. + //! Allows for fast switching between Eigen and NCollection vectors. template struct VectorType { // Not implemented @@ -78,52 +78,52 @@ namespace BVHTools } //! 2D vector of integers. -typedef BVHTools::VectorType::Type BVH_Vec2i; +typedef BVH::VectorType::Type BVH_Vec2i; //! 3D vector of integers. -typedef BVHTools::VectorType::Type BVH_Vec3i; +typedef BVH::VectorType::Type BVH_Vec3i; //! 4D vector of integers. -typedef BVHTools::VectorType::Type BVH_Vec4i; +typedef BVH::VectorType::Type BVH_Vec4i; //! Array of 2D vectors of integers. -typedef BVHTools::ArrayType::Type BVH_Array2i; +typedef BVH::ArrayType::Type BVH_Array2i; //! Array of 3D vectors of integers. -typedef BVHTools::ArrayType::Type BVH_Array3i; +typedef BVH::ArrayType::Type BVH_Array3i; //! Array of 4D vectors of integers. -typedef BVHTools::ArrayType::Type BVH_Array4i; +typedef BVH::ArrayType::Type BVH_Array4i; //! 2D vector of single precision reals. -typedef BVHTools::VectorType::Type BVH_Vec2f; +typedef BVH::VectorType::Type BVH_Vec2f; //! 3D vector of single precision reals. -typedef BVHTools::VectorType::Type BVH_Vec3f; +typedef BVH::VectorType::Type BVH_Vec3f; //! 4D vector of single precision reals. -typedef BVHTools::VectorType::Type BVH_Vec4f; +typedef BVH::VectorType::Type BVH_Vec4f; //! Array of 2D vectors of single precision reals. -typedef BVHTools::ArrayType::Type BVH_Array2f; +typedef BVH::ArrayType::Type BVH_Array2f; //! Array of 3D vectors of single precision reals. -typedef BVHTools::ArrayType::Type BVH_Array3f; +typedef BVH::ArrayType::Type BVH_Array3f; //! Array of 4D vectors of single precision reals. -typedef BVHTools::ArrayType::Type BVH_Array4f; +typedef BVH::ArrayType::Type BVH_Array4f; //! 2D vector of double precision reals. -typedef BVHTools::VectorType::Type BVH_Vec2d; +typedef BVH::VectorType::Type BVH_Vec2d; //! 3D vector of double precision reals. -typedef BVHTools::VectorType::Type BVH_Vec3d; +typedef BVH::VectorType::Type BVH_Vec3d; //! 4D vector of double precision reals. -typedef BVHTools::VectorType::Type BVH_Vec4d; +typedef BVH::VectorType::Type BVH_Vec4d; //! Array of 2D vectors of double precision reals. -typedef BVHTools::ArrayType::Type BVH_Array2d; +typedef BVH::ArrayType::Type BVH_Array2d; //! Array of 3D vectors of double precision reals. -typedef BVHTools::ArrayType::Type BVH_Array3d; +typedef BVH::ArrayType::Type BVH_Array3d; //! Array of 4D vectors of double precision reals. -typedef BVHTools::ArrayType::Type BVH_Array4d; +typedef BVH::ArrayType::Type BVH_Array4d; //! 4x4 matrix of single precision reals. -typedef BVHTools::MatrixType::Type BVH_Mat4f; +typedef BVH::MatrixType::Type BVH_Mat4f; //! 4x4 matrix of double precision reals. -typedef BVHTools::MatrixType::Type BVH_Mat4d; +typedef BVH::MatrixType::Type BVH_Mat4d; #include diff --git a/src/BVH/BVH_Types.lxx b/src/BVH/BVH_Types.lxx index 62434e7b1f..9ae79c83f3 100644 --- a/src/BVH/BVH_Types.lxx +++ b/src/BVH/BVH_Types.lxx @@ -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 struct VecComp { @@ -22,7 +22,7 @@ namespace BVHTools template struct VecComp { - typedef typename BVHTools::VectorType::Type BVH_Vec2t; + typedef typename BVH::VectorType::Type BVH_Vec2t; static T Get (const BVH_Vec2t& theVec, const Standard_Integer theAxis) @@ -33,7 +33,7 @@ namespace BVHTools template struct VecComp { - typedef typename BVHTools::VectorType::Type BVH_Vec3t; + typedef typename BVH::VectorType::Type BVH_Vec3t; static T Get (const BVH_Vec3t& theVec, const Standard_Integer theAxis) @@ -44,7 +44,7 @@ namespace BVHTools template struct VecComp { - typedef typename BVHTools::VectorType::Type BVH_Vec4t; + typedef typename BVH::VectorType::Type BVH_Vec4t; static T Get (const BVH_Vec4t& theVec, const Standard_Integer theAxis) @@ -57,11 +57,11 @@ namespace BVHTools template struct ArrayOp { - typedef typename BVHTools::ArrayType::Type BVH_ArrayNt; + typedef typename BVH::ArrayType::Type BVH_ArrayNt; static inline - const typename BVHTools::VectorType::Type& Value (const BVH_ArrayNt& theArray, - const Standard_Integer theIndex) + const typename BVH::VectorType::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::Type& ChangeValue (BVH_ArrayNt& theArray, - const Standard_Integer theIndex) + typename BVH::VectorType::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::Type& theElement) + const typename BVH::VectorType::Type& theElement) { #ifdef _BVH_USE_STD_VECTOR_ theArray.push_back (theElement); -- 2.39.5