0031035: Coding - uninitialized class fields reported by Visual Studio Code Analysis
[occt.git] / src / BVH / BVH_PairDistance.hxx
1 // Created by: Eugeny MALTCHIKOV
2 // Created on: 2019-04-17
3 // Copyright (c) 2019 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BVH_PairDistance_Header
17 #define _BVH_PairDistance_Header
18
19 #include <BVH_Traverse.hxx>
20 #include <BVH_Tools.hxx>
21
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.
26 //!
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>
32 {
33 public:
34   typedef typename BVH_Tools<NumType, Dimension>::BVH_VecNt BVH_VecNt;
35
36 public: //! @name Constructor
37
38   //! Constructor
39   BVH_PairDistance()
40     : BVH_PairTraverse <NumType, Dimension, BVHSetType, NumType>(),
41       myDistance (std::numeric_limits<NumType>::max()),
42       myIsDone(Standard_False)
43   {
44   }
45
46 public: //! @name Compute the distance
47
48   //! Computes the distance between two BVH trees
49   NumType ComputeDistance ()
50   {
51     myIsDone = this->Select() > 0;
52     return myDistance;
53   }
54
55 public: //! @name Accessing the results
56
57   //! Returns IsDone flag
58   Standard_Boolean IsDone () const { return myIsDone; }
59
60   //! Returns the computed distance
61   NumType Distance() const { return myDistance; }
62
63 public: //! @name Definition of the rules for tree descend
64
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
68   {
69     return theLeft < theRight;
70   }
71
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
78   {
79     theMetric = BVH_Tools<NumType, Dimension>::BoxBoxSquareDistance (theCornerMin1, theCornerMax1,
80                                                                      theCornerMin2, theCornerMax2);
81     return theMetric > myDistance;
82   }
83
84   //! Rejects the branch by the metric
85   virtual Standard_Boolean RejectMetric (const NumType& theMetric) const Standard_OVERRIDE
86   {
87     return theMetric > myDistance;
88   }
89
90   //! Returns the flag controlling the tree descend
91   virtual Standard_Boolean Stop() const Standard_OVERRIDE
92   {
93     return myDistance == static_cast<NumType>(0);
94   }
95
96 protected: //! @name Fields
97
98   NumType myDistance;      //!< Square distance
99   Standard_Boolean myIsDone; //!< State of the algorithm
100
101 };
102
103 #endif // _BVH_Distance_Header