1 // Created by: Eugeny MALTCHIKOV
2 // Created on: 2019-04-17
3 // Copyright (c) 2019 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _BVH_PairDistance_Header
17 #define _BVH_PairDistance_Header
19 #include <BVH_Traverse.hxx>
20 #include <BVH_Tools.hxx>
22 //! Abstract class for computation of the min distance between
23 //! elements of two BVH trees.
24 //! To use this class it is required to define only the method
25 //! *Accept* to compute the distance between elements of the trees.
27 //! \tparam NumType Numeric data type
28 //! \tparam Dimension Vector dimension
29 //! \tparam BVHSetType Type of the set on which BVH is built
30 template <class NumType, int Dimension, class BVHSetType>
31 class BVH_PairDistance : public BVH_PairTraverse<NumType, Dimension, BVHSetType, NumType>
34 typedef typename BVH_Tools<NumType, Dimension>::BVH_VecNt BVH_VecNt;
36 public: //! @name Constructor
40 : BVH_PairTraverse <NumType, Dimension, BVHSetType, NumType>(),
41 myDistance (std::numeric_limits<NumType>::max())
45 public: //! @name Compute the distance
47 //! Computes the distance between two BVH trees
48 NumType ComputeDistance ()
50 myIsDone = this->Select() > 0;
54 public: //! @name Accessing the results
56 //! Returns IsDone flag
57 Standard_Boolean IsDone () const { return myIsDone; }
59 //! Returns the computed distance
60 NumType Distance() const { return myDistance; }
62 public: //! @name Definition of the rules for tree descend
64 //! Compares the two metrics and chooses the best one
65 virtual Standard_Boolean IsMetricBetter (const NumType& theLeft,
66 const NumType& theRight) const Standard_OVERRIDE
68 return theLeft < theRight;
71 //! Computes the distance between boxes of the nodes
72 virtual Standard_Boolean RejectNode (const BVH_VecNt& theCornerMin1,
73 const BVH_VecNt& theCornerMax1,
74 const BVH_VecNt& theCornerMin2,
75 const BVH_VecNt& theCornerMax2,
76 NumType& theMetric) const Standard_OVERRIDE
78 theMetric = BVH_Tools<NumType, Dimension>::BoxBoxSquareDistance (theCornerMin1, theCornerMax1,
79 theCornerMin2, theCornerMax2);
80 return theMetric > myDistance;
83 //! Rejects the branch by the metric
84 virtual Standard_Boolean RejectMetric (const NumType& theMetric) const Standard_OVERRIDE
86 return theMetric > myDistance;
89 //! Returns the flag controlling the tree descend
90 virtual Standard_Boolean Stop() const Standard_OVERRIDE
92 return myDistance == static_cast<NumType>(0);
95 protected: //! @name Fields
97 NumType myDistance; //!< Square distance
98 Standard_Boolean myIsDone; //!< State of the algorithm
102 #endif // _BVH_Distance_Header