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()),
42 myIsDone(Standard_False)
46 public: //! @name Compute the distance
48 //! Computes the distance between two BVH trees
49 NumType ComputeDistance ()
51 myIsDone = this->Select() > 0;
55 public: //! @name Accessing the results
57 //! Returns IsDone flag
58 Standard_Boolean IsDone () const { return myIsDone; }
60 //! Returns the computed distance
61 NumType Distance() const { return myDistance; }
63 public: //! @name Definition of the rules for tree descend
65 //! Compares the two metrics and chooses the best one
66 virtual Standard_Boolean IsMetricBetter (const NumType& theLeft,
67 const NumType& theRight) const Standard_OVERRIDE
69 return theLeft < theRight;
72 //! Computes the distance between boxes of the nodes
73 virtual Standard_Boolean RejectNode (const BVH_VecNt& theCornerMin1,
74 const BVH_VecNt& theCornerMax1,
75 const BVH_VecNt& theCornerMin2,
76 const BVH_VecNt& theCornerMax2,
77 NumType& theMetric) const Standard_OVERRIDE
79 theMetric = BVH_Tools<NumType, Dimension>::BoxBoxSquareDistance (theCornerMin1, theCornerMax1,
80 theCornerMin2, theCornerMax2);
81 return theMetric > myDistance;
84 //! Rejects the branch by the metric
85 virtual Standard_Boolean RejectMetric (const NumType& theMetric) const Standard_OVERRIDE
87 return theMetric > myDistance;
90 //! Returns the flag controlling the tree descend
91 virtual Standard_Boolean Stop() const Standard_OVERRIDE
93 return myDistance == static_cast<NumType>(0);
96 protected: //! @name Fields
98 NumType myDistance; //!< Square distance
99 Standard_Boolean myIsDone; //!< State of the algorithm
103 #endif // _BVH_Distance_Header