Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 2016-04-13
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2013-2016 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _BVH_QuickSorter_Header
0017 #define _BVH_QuickSorter_Header
0018 
0019 #include <BVH_Sorter.hxx>
0020 
0021 //! Performs centroid-based sorting of abstract set along
0022 //! the given axis (X - 0, Y - 1, Z - 2) using quick sort.
0023 template<class T, int N>
0024 class BVH_QuickSorter : public BVH_Sorter<T, N>
0025 {
0026 public:
0027 
0028   //! Creates new BVH quick sorter for the given axis.
0029   BVH_QuickSorter (const Standard_Integer theAxis = 0) : myAxis (theAxis) { }
0030 
0031   //! Sorts the set.
0032   virtual void Perform (BVH_Set<T, N>* theSet) Standard_OVERRIDE
0033   {
0034     Perform (theSet, 0, theSet->Size() - 1);
0035   }
0036 
0037   //! Sorts the given (inclusive) range in the set.
0038   virtual void Perform (BVH_Set<T, N>* theSet, const Standard_Integer theStart, const Standard_Integer theFinal) Standard_OVERRIDE
0039   {
0040     Standard_Integer aLft = theStart;
0041     Standard_Integer aRgh = theFinal;
0042 
0043     T aPivot = theSet->Center ((aRgh + aLft) / 2, myAxis);
0044     while (aLft < aRgh)
0045     {
0046       while (theSet->Center (aLft, myAxis) < aPivot && aLft < theFinal)
0047       {
0048         ++aLft;
0049       }
0050 
0051       while (theSet->Center (aRgh, myAxis) > aPivot && aRgh > theStart)
0052       {
0053         --aRgh;
0054       }
0055 
0056       if (aLft <= aRgh)
0057       {
0058         if (aLft != aRgh)
0059         {
0060           theSet->Swap (aLft, aRgh);
0061         }
0062         ++aLft;
0063         --aRgh;
0064       }
0065     }
0066 
0067     if (aRgh > theStart)
0068     {
0069       Perform (theSet, theStart, aRgh);
0070     }
0071 
0072     if (aLft < theFinal)
0073     {
0074       Perform (theSet, aLft, theFinal);
0075     }
0076   }
0077 
0078 protected:
0079 
0080   //! Axis used to arrange the primitives (X - 0, Y - 1, Z - 2).
0081   Standard_Integer myAxis;
0082 
0083 };
0084 
0085 #endif // _BVH_QuickSorter_Header