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_Distance_Header
17 #define _BVH_Distance_Header
19 #include <BVH_Traverse.hxx>
21 //! Abstract class for computation of the min distance between some
22 //! Object and elements of BVH tree.
23 //! To use this class it is required to define two methods:
24 //! - *RejectNode* to compute distance from the object to bounding box
25 //! - *Accept* to compute distance from the object to the element of tree
27 //! \tparam NumType Numeric data type
28 //! \tparam Dimension Vector dimension
29 //! \tparam ObjectType Type of the object to which the distance is required
30 //! \tparam BVHSetType Type of the set on which BVH is built
31 template <class NumType, int Dimension, class ObjectType, class BVHSetType>
32 class BVH_Distance : public BVH_Traverse<NumType, Dimension, BVHSetType, NumType>
34 public: //! @name Constructor
38 : BVH_Traverse <NumType, Dimension, BVHSetType, NumType>(),
39 myDistance (std::numeric_limits<NumType>::max()),
40 myIsDone(Standard_False)
44 public: //! @name Setting object for distance computation
46 //! Sets the object to which the distance is required
47 void SetObject (const ObjectType& theObject)
52 public: //! @name Compute the distance
54 //! Computes the distance between object and BVH tree
55 NumType ComputeDistance()
57 myIsDone = this->Select() > 0;
61 public: //! @name Accessing the results
63 //! Returns IsDone flag
64 Standard_Boolean IsDone () const { return myIsDone; }
66 //! Returns the computed distance
67 NumType Distance() const { return myDistance; }
69 public: //! @name Definition of the rules for tree descend
71 //! Compares the two metrics and chooses the best one
72 virtual Standard_Boolean IsMetricBetter (const NumType& theLeft,
73 const NumType& theRight) const Standard_OVERRIDE
75 return theLeft < theRight;
78 //! Rejects the branch by the metric
79 virtual Standard_Boolean RejectMetric (const NumType& theMetric) const Standard_OVERRIDE
81 return theMetric > myDistance;
84 //! Returns the flag controlling the tree descend
85 virtual Standard_Boolean Stop() const Standard_OVERRIDE
87 return myDistance == static_cast<NumType>(0);
90 protected: //! @name Fields
92 NumType myDistance; //!< Distance
93 Standard_Boolean myIsDone; //!< State of the algorithm
94 ObjectType myObject; //!< Object to compute the distance to
98 #endif // _BVH_Distance_Header