Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:05

0001 // Created by: Eugeny MALTCHIKOV
0002 // Copyright (c) 2017 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef BOPTools_BoxSelector_HeaderFile
0016 #define BOPTools_BoxSelector_HeaderFile
0017 
0018 #include <BVH_Traverse.hxx>
0019 #include <BVH_BoxSet.hxx>
0020 
0021 #include <Standard_Integer.hxx>
0022 #include <TColStd_ListOfInteger.hxx>
0023 
0024 //! Template Selector for elements selection from BVH tree.
0025 template <int Dimension>
0026 class BOPTools_BoxSelector :
0027   public BVH_Traverse <Standard_Real, Dimension, BVH_BoxSet <Standard_Real, Dimension, Standard_Integer>, Standard_Boolean>
0028 {
0029 public:
0030 
0031   typedef typename BVH::VectorType<Standard_Real, Dimension>::Type BVH_VecNd;
0032 
0033 public: //! @name Constructor
0034 
0035   //! Empty constructor
0036   BOPTools_BoxSelector() {};
0037 
0038 public: //! @name public interfaces
0039 
0040   //! Clears the indices
0041   void Clear()
0042   {
0043     myIndices.Clear();
0044   }
0045 
0046   //! Sets the box
0047   void SetBox (const BVH_Box <Standard_Real, Dimension>& theBox)
0048   {
0049     myBox = theBox;
0050   }
0051 
0052   //! Returns the list of accepted indices
0053   const TColStd_ListOfInteger& Indices() const
0054   {
0055     return myIndices;
0056   }
0057 
0058 public: //! @name Rejection/Acceptance rules
0059 
0060   //! Checks if the box should be rejected
0061   virtual Standard_Boolean RejectNode (const BVH_VecNd& theCMin,
0062                                        const BVH_VecNd& theCMax,
0063                                        Standard_Boolean& theIsInside) const Standard_OVERRIDE
0064   {
0065     Standard_Boolean hasOverlap;
0066     theIsInside = myBox.Contains (theCMin, theCMax, hasOverlap);
0067     return !hasOverlap;
0068   }
0069 
0070   //! Checks if the element should be rejected
0071   Standard_Boolean RejectElement (const Standard_Integer theIndex)
0072   {
0073     return myBox.IsOut (this->myBVHSet->Box (theIndex));
0074   }
0075 
0076   //! Checks if the metric of the node may be accepted
0077   virtual Standard_Boolean AcceptMetric (const Standard_Boolean& theIsInside) const Standard_OVERRIDE
0078   {
0079     return theIsInside;
0080   }
0081 
0082   //! Accepts the element with the index <theIndex> in BVH tree
0083   virtual Standard_Boolean Accept (const Standard_Integer theIndex,
0084                                    const Standard_Boolean& theIsInside) Standard_OVERRIDE
0085   {
0086     if (theIsInside || !RejectElement (theIndex))
0087     {
0088       myIndices.Append (this->myBVHSet->Element (theIndex));
0089       return Standard_True;
0090     }
0091     return Standard_False;
0092   }
0093 
0094 protected: //! @name Fields
0095 
0096   BVH_Box <Standard_Real, Dimension> myBox; //!< Selection box
0097   TColStd_ListOfInteger myIndices;          //!< Selected indices
0098 };
0099 
0100 #endif