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