1 // Created on: 2016-04-13
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _BVH_QuickSorter_Header
17 #define _BVH_QuickSorter_Header
19 #include <BVH_Sorter.hxx>
21 //! Performs centroid-based sorting of abstract set along
22 //! the given axis (X - 0, Y - 1, Z - 2) using quick sort.
23 template<class T, int N>
24 class BVH_QuickSorter : public BVH_Sorter<T, N>
28 //! Creates new BVH quick sorter for the given axis.
29 BVH_QuickSorter (const Standard_Integer theAxis = 0) : myAxis (theAxis) { }
32 virtual void Perform (BVH_Set<T, N>* theSet) Standard_OVERRIDE
34 Perform (theSet, 0, theSet->Size() - 1);
37 //! Sorts the given (inclusive) range in the set.
38 virtual void Perform (BVH_Set<T, N>* theSet, const Standard_Integer theStart, const Standard_Integer theFinal) Standard_OVERRIDE
40 Standard_Integer aLft = theStart;
41 Standard_Integer aRgh = theFinal;
43 T aPivot = theSet->Center ((aRgh + aLft) / 2, myAxis);
46 while (theSet->Center (aLft, myAxis) < aPivot && aLft < theFinal)
51 while (theSet->Center (aRgh, myAxis) > aPivot && aRgh > theStart)
60 theSet->Swap (aLft, aRgh);
69 Perform (theSet, theStart, aRgh);
74 Perform (theSet, aLft, theFinal);
80 //! Axis used to arrange the primitives (X - 0, Y - 1, Z - 2).
81 Standard_Integer myAxis;
85 #endif // _BVH_QuickSorter_Header