Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-02 09:11:28

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 <NCollection_List.hxx>
0023 
0024 //! Template Selector for elements selection from BVH tree.
0025 template <int Dimension>
0026 class BOPTools_BoxSelector
0027     : public BVH_Traverse<double, Dimension, BVH_BoxSet<double, Dimension, int>, bool>
0028 {
0029 public:
0030   typedef typename BVH::VectorType<double, Dimension>::Type BVH_VecNd;
0031 
0032 public: //! @name Constructor
0033   //! Empty constructor
0034   BOPTools_BoxSelector() = default;
0035 
0036 public: //! @name public interfaces
0037   //! Clears the indices
0038   void Clear() { myIndices.Clear(); }
0039 
0040   //! Sets the box
0041   void SetBox(const BVH_Box<double, Dimension>& theBox) { myBox = theBox; }
0042 
0043   //! Returns the list of accepted indices
0044   const NCollection_List<int>& Indices() const { return myIndices; }
0045 
0046 public: //! @name Rejection/Acceptance rules
0047   //! Checks if the box should be rejected
0048   bool RejectNode(const BVH_VecNd& theCMin,
0049                   const BVH_VecNd& theCMax,
0050                   bool&            theIsInside) const override
0051   {
0052     bool hasOverlap;
0053     theIsInside = myBox.Contains(theCMin, theCMax, hasOverlap);
0054     return !hasOverlap;
0055   }
0056 
0057   //! Checks if the element should be rejected
0058   bool RejectElement(const int theIndex) { return myBox.IsOut(this->myBVHSet->Box(theIndex)); }
0059 
0060   //! Checks if the metric of the node may be accepted
0061   bool AcceptMetric(const bool& theIsInside) const override { return theIsInside; }
0062 
0063   //! Accepts the element with the index <theIndex> in BVH tree
0064   bool Accept(const int theIndex, const bool& theIsInside) override
0065   {
0066     if (theIsInside || !RejectElement(theIndex))
0067     {
0068       myIndices.Append(this->myBVHSet->Element(theIndex));
0069       return true;
0070     }
0071     return false;
0072   }
0073 
0074 protected:                              //! @name Fields
0075   BVH_Box<double, Dimension> myBox;     //!< Selection box
0076   NCollection_List<int>      myIndices; //!< Selected indices
0077 };
0078 
0079 #endif