File indexing completed on 2025-01-18 10:03:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _BVH_QuickSorter_Header
0017 #define _BVH_QuickSorter_Header
0018
0019 #include <BVH_Sorter.hxx>
0020
0021
0022
0023 template<class T, int N>
0024 class BVH_QuickSorter : public BVH_Sorter<T, N>
0025 {
0026 public:
0027
0028
0029 BVH_QuickSorter (const Standard_Integer theAxis = 0) : myAxis (theAxis) { }
0030
0031
0032 virtual void Perform (BVH_Set<T, N>* theSet) Standard_OVERRIDE
0033 {
0034 Perform (theSet, 0, theSet->Size() - 1);
0035 }
0036
0037
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
0081 Standard_Integer myAxis;
0082
0083 };
0084
0085 #endif