// Created by: Eugeny MALTCHIKOV // Created on: 2019-04-17 // Copyright (c) 2019 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #ifndef _BVH_PairDistance_Header #define _BVH_PairDistance_Header #include "BVH_Traverse.hxx" #include "BVH_Tools.hxx" //! Abstract class for computation of the min distance between //! elements of two BVH trees. //! To use this class it is required to define only the method //! *Accept* to compute the distance between elements of the trees. //! //! \tparam NumType Numeric data type //! \tparam Dimension Vector dimension //! \tparam BVHSetType Type of the set on which BVH is built template class BVH_PairDistance : public BVH_PairTraverse { public: typedef typename BVH_Tools::BVH_VecNt BVH_VecNt; public: //! @name Constructor //! Constructor BVH_PairDistance() : BVH_PairTraverse(), myDistance(std::numeric_limits::max()), myIsDone(false) { } public: //! @name Compute the distance //! Computes the distance between two BVH trees NumType ComputeDistance() { myIsDone = this->Select() > 0; return myDistance; } public: //! @name Accessing the results //! Returns IsDone flag bool IsDone() const { return myIsDone; } //! Returns the computed distance NumType Distance() const { return myDistance; } public: //! @name Definition of the rules for tree descend //! Compares the two metrics and chooses the best one bool IsMetricBetter(const NumType& theLeft, const NumType& theRight) const override { return theLeft < theRight; } //! Computes the distance between boxes of the nodes bool RejectNode(const BVH_VecNt& theCornerMin1, const BVH_VecNt& theCornerMax1, const BVH_VecNt& theCornerMin2, const BVH_VecNt& theCornerMax2, NumType& theMetric) const override { theMetric = BVH_Tools::BoxBoxSquareDistance(theCornerMin1, theCornerMax1, theCornerMin2, theCornerMax2); return theMetric > myDistance; } //! Rejects the branch by the metric bool RejectMetric(const NumType& theMetric) const override { return theMetric > myDistance; } //! Returns the flag controlling the tree descend bool Stop() const override { return myDistance == static_cast(0); } protected: //! @name Fields NumType myDistance; //!< Square distance bool myIsDone; //!< State of the algorithm }; #endif // _BVH_Distance_Header