|
||||
File indexing completed on 2024-11-16 09:46:36
0001 // Created by: Eugeny MALTCHIKOV 0002 // Created on: 2019-04-17 0003 // Copyright (c) 2019 OPEN CASCADE SAS 0004 // 0005 // This file is part of Open CASCADE Technology software library. 0006 // 0007 // This library is free software; you can redistribute it and/or modify it under 0008 // the terms of the GNU Lesser General Public License version 2.1 as published 0009 // by the Free Software Foundation, with special exception defined in the file 0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0011 // distribution for complete text of the license and disclaimer of any warranty. 0012 // 0013 // Alternatively, this file may be used under the terms of Open CASCADE 0014 // commercial license or contractual agreement. 0015 0016 #ifndef _BVH_Distance_Header 0017 #define _BVH_Distance_Header 0018 0019 #include <BVH_Traverse.hxx> 0020 0021 //! Abstract class for computation of the min distance between some 0022 //! Object and elements of BVH tree. 0023 //! To use this class it is required to define two methods: 0024 //! - *RejectNode* to compute distance from the object to bounding box 0025 //! - *Accept* to compute distance from the object to the element of tree 0026 //! 0027 //! \tparam NumType Numeric data type 0028 //! \tparam Dimension Vector dimension 0029 //! \tparam ObjectType Type of the object to which the distance is required 0030 //! \tparam BVHSetType Type of the set on which BVH is built 0031 template <class NumType, int Dimension, class ObjectType, class BVHSetType> 0032 class BVH_Distance : public BVH_Traverse<NumType, Dimension, BVHSetType, NumType> 0033 { 0034 public: //! @name Constructor 0035 0036 //! Constructor 0037 BVH_Distance() 0038 : BVH_Traverse <NumType, Dimension, BVHSetType, NumType>(), 0039 myDistance (std::numeric_limits<NumType>::max()), 0040 myIsDone(Standard_False) 0041 { 0042 } 0043 0044 public: //! @name Setting object for distance computation 0045 0046 //! Sets the object to which the distance is required 0047 void SetObject (const ObjectType& theObject) 0048 { 0049 myObject = theObject; 0050 } 0051 0052 public: //! @name Compute the distance 0053 0054 //! Computes the distance between object and BVH tree 0055 NumType ComputeDistance() 0056 { 0057 myIsDone = this->Select() > 0; 0058 return myDistance; 0059 } 0060 0061 public: //! @name Accessing the results 0062 0063 //! Returns IsDone flag 0064 Standard_Boolean IsDone () const { return myIsDone; } 0065 0066 //! Returns the computed distance 0067 NumType Distance() const { return myDistance; } 0068 0069 public: //! @name Definition of the rules for tree descend 0070 0071 //! Compares the two metrics and chooses the best one 0072 virtual Standard_Boolean IsMetricBetter (const NumType& theLeft, 0073 const NumType& theRight) const Standard_OVERRIDE 0074 { 0075 return theLeft < theRight; 0076 } 0077 0078 //! Rejects the branch by the metric 0079 virtual Standard_Boolean RejectMetric (const NumType& theMetric) const Standard_OVERRIDE 0080 { 0081 return theMetric > myDistance; 0082 } 0083 0084 //! Returns the flag controlling the tree descend 0085 virtual Standard_Boolean Stop() const Standard_OVERRIDE 0086 { 0087 return myDistance == static_cast<NumType>(0); 0088 } 0089 0090 protected: //! @name Fields 0091 0092 NumType myDistance; //!< Distance 0093 Standard_Boolean myIsDone; //!< State of the algorithm 0094 ObjectType myObject; //!< Object to compute the distance to 0095 0096 }; 0097 0098 #endif // _BVH_Distance_Header
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |