Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:16:56

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_PairSelector_HeaderFile
0016 #define BOPTools_PairSelector_HeaderFile
0017 
0018 #include <BVH_Traverse.hxx>
0019 #include <BVH_BoxSet.hxx>
0020 #include <NCollection_LinearVector.hxx>
0021 
0022 #include <algorithm>
0023 
0024 //! Template Selector for selection of the elements from two BVH trees.
0025 template <int Dimension>
0026 class BOPTools_PairSelector
0027     : public BVH_PairTraverse<double, Dimension, BVH_BoxSet<double, Dimension, int>>
0028 {
0029 public: //! @name public types
0030   //! Auxiliary structure to keep the pair of indices
0031   struct PairIDs
0032   {
0033     PairIDs(const int theId1 = -1, const int theId2 = -1)
0034         : ID1(theId1),
0035           ID2(theId2)
0036     {
0037     }
0038 
0039     bool operator<(const PairIDs& theOther) const
0040     {
0041       return ID1 < theOther.ID1 || (ID1 == theOther.ID1 && ID2 < theOther.ID2);
0042     }
0043 
0044     int ID1;
0045     int ID2;
0046   };
0047 
0048   typedef typename BVH::VectorType<double, Dimension>::Type BVH_VecNd;
0049 
0050 public: //! @name Constructor
0051   //! Empty constructor
0052   BOPTools_PairSelector()
0053       : mySameBVHs(false)
0054   {
0055   }
0056 
0057 public: //! @name public interfaces
0058   //! Clears the indices
0059   void Clear() { myPairs.Clear(); }
0060 
0061   //! Sorts the indices
0062   void Sort() { std::sort(myPairs.begin(), myPairs.end()); }
0063 
0064   //! Tells to selector that BVH trees are the same.
0065   //! If the flag is set to true the resulting vector will contain
0066   //! only unique pairs (mirrored pairs will be rejected,
0067   //! e.g. (1, 2) will be taken, (2, 1) will be rejected) and will
0068   //! not contain pairs in which IDs are the same (pair (1, 1) will be rejected).
0069   //! If it is required to have a full vector of pairs even
0070   //! for the same BVH trees, just keep the false value of this flag.
0071   void SetSame(const bool theIsSame) { mySameBVHs = theIsSame; }
0072 
0073   //! Returns the list of accepted indices
0074   const NCollection_LinearVector<PairIDs>& Pairs() const { return myPairs; }
0075 
0076 public: //! @name Rejection/Acceptance rules
0077   //! Basing on the bounding boxes of the nodes checks if the pair of nodes should be rejected.
0078   bool RejectNode(const BVH_VecNd& theCMin1,
0079                   const BVH_VecNd& theCMax1,
0080                   const BVH_VecNd& theCMin2,
0081                   const BVH_VecNd& theCMax2,
0082                   double&) const override
0083   {
0084     return BVH_Box<double, 3>(theCMin1, theCMax1).IsOut(theCMin2, theCMax2);
0085   }
0086 
0087   //! Checks if the pair of elements should be rejected.
0088   bool RejectElement(const int theID1, const int theID2)
0089   {
0090     return (mySameBVHs && theID1 >= theID2)
0091            || this->myBVHSet1->Box(theID1).IsOut(this->myBVHSet2->Box(theID2));
0092   }
0093 
0094   //! Checks and accepts the pair of elements.
0095   bool Accept(const int theID1, const int theID2) override
0096   {
0097     if (!RejectElement(theID1, theID2))
0098     {
0099       myPairs.Append(PairIDs(this->myBVHSet1->Element(theID1), this->myBVHSet2->Element(theID2)));
0100       return true;
0101     }
0102     return false;
0103   }
0104 
0105 protected:                                      //! @name Fields
0106   NCollection_LinearVector<PairIDs> myPairs;    //!< Selected pairs of indices
0107   bool                              mySameBVHs; //!< Selection is performed from the same BVH trees
0108 };
0109 
0110 #endif