42 index = (First+last)>>1;
44 if(max>array[sorted[index]]) First = index+1;
52 #define PRUNING_SORTER RadixSort 97 if(!nb0 || !array0 || !nb1 || !array1)
return false;
105 float* MinPosList0 =
new float[nb0];
106 float* MinPosList1 =
new float[nb1];
109 for(
udword i=0;
i<nb0;
i++) MinPosList0[
i] = array0[
i]->GetMin(Axis0);
110 for(
udword i=0;
i<nb1;
i++) MinPosList1[
i] = array1[
i]->GetMin(Axis0);
115 const udword* Sorted0 = RS0->Sort(MinPosList0, nb0).GetRanks();
116 const udword* Sorted1 = RS1->Sort(MinPosList1, nb1).GetRanks();
121 const udword*
const LastSorted0 = &Sorted0[nb0];
122 const udword*
const LastSorted1 = &Sorted1[nb1];
123 const udword* RunningAddress0 = Sorted0;
124 const udword* RunningAddress1 = Sorted1;
126 while(RunningAddress1<LastSorted1 && Sorted0<LastSorted0)
130 while(RunningAddress1<LastSorted1 && MinPosList1[*RunningAddress1]<MinPosList0[Index0]) RunningAddress1++;
132 const udword* RunningAddress2_1 = RunningAddress1;
134 while(RunningAddress2_1<LastSorted1 && MinPosList1[Index1 = *RunningAddress2_1++]<=array0[Index0]->GetMax(Axis0))
136 if(array0[Index0]->
Intersect(*array1[Index1], Axis1))
138 if(array0[Index0]->
Intersect(*array1[Index1], Axis2))
148 while(RunningAddress0<LastSorted0 && Sorted1<LastSorted1)
152 while(RunningAddress0<LastSorted0 && MinPosList0[*RunningAddress0]<=MinPosList1[Index0]) RunningAddress0++;
154 const udword* RunningAddress2_0 = RunningAddress0;
156 while(RunningAddress2_0<LastSorted0 && MinPosList0[Index1 = *RunningAddress2_0++]<=array1[Index0]->GetMax(Axis0))
158 if(array0[Index1]->
Intersect(*array1[Index0], Axis1))
160 if(array0[Index1]->
Intersect(*array1[Index0], Axis2))
175 #define ORIGINAL_VERSION 191 if(!nb || !array)
return false;
198 #ifdef ORIGINAL_VERSION 201 float* PosList =
new float[nb+1];
204 for(
udword i=0;
i<nb;
i++) PosList[
i] = array[
i]->GetMin(Axis0);
209 const udword* Sorted = RS->Sort(PosList, nb).GetRanks();
212 const udword*
const LastSorted = &Sorted[nb];
213 const udword* RunningAddress = Sorted;
215 while(RunningAddress<LastSorted && Sorted<LastSorted)
220 while(PosList[*RunningAddress++]<PosList[Index0]);
222 if(RunningAddress<LastSorted)
224 const udword* RunningAddress2 = RunningAddress;
227 while(PosList[Index1 = *RunningAddress2++]<=array[Index0]->GetMax(Axis0))
231 if(array[Index0]->
Intersect(*array[Index1], Axis1))
233 if(array[Index0]->
Intersect(*array[Index1], Axis2))
249 float* MinList =
new float[nb+1];
252 for(
udword i=0;
i<nb;
i++) MinList[
i] = array[
i]->GetMin(Axis0);
257 udword* Sorted = RS->Sort(MinList, nb+1).GetRanks();
262 const udword* RunningAddress = Sorted;
267 while(RunningAddress<&Sorted[nb])
271 Index0 = *RunningAddress++;
278 const udword* RunningAddress2 = RunningAddress;
283 float CurrentMax = array[Index0]->
GetMax(Axis0);
285 while(MinList[Index1 = *RunningAddress2] <= CurrentMax)
290 if(array[Index0]->
Intersect(*array[Index1], Axis1))
292 if(array[Index0]->
Intersect(*array[Index1], Axis2))
331 if(!nb0 || !array0 || !nb1 || !array1)
return false;
356 if(!nb || !array)
return false;
static PRUNING_SORTER * gBipartitePruningSorter1
inline_ PRUNING_SORTER * GetCompletePruningSorter()
void ReleasePruningSorters()
inline_ PRUNING_SORTER * GetBipartitePruningSorter1()
inline_ void FindRunningIndex(udword &index, float *array, udword *sorted, int last, float max)
#define null
our own NULL pointer
inline_ void AddPair(const Pair &p)
FUNCTION OPCODE_API bool BipartiteBoxPruning(udword nb0, const AABB **array0, udword nb1, const AABB **array1, Pairs &pairs, const Axes &axes)
#define DELETEARRAY(x)
Deletes an array.
unsigned int udword
sizeof(udword) must be 4
static PRUNING_SORTER * gCompletePruningSorter
FUNCTION OPCODE_API bool CompleteBoxPruning(udword nb, const AABB **array, Pairs &pairs, const Axes &axes)
#define DELETESINGLE(x)
Deletes an instance of a class.
static PRUNING_SORTER * gBipartitePruningSorter0
inline_ void GetMax(Point &max) const
Get max point of the box.
#define MAX_FLOAT
max possible float value
inline_ PRUNING_SORTER * GetBipartitePruningSorter0()
FUNCTION OPCODE_API bool BruteForceCompleteBoxTest(udword nb, const AABB **array, Pairs &pairs)
inline_ BOOL Intersect(const AABB &a, const SAP_Box &b)
FUNCTION OPCODE_API bool BruteForceBipartiteBoxTest(udword nb0, const AABB **array0, udword nb1, const AABB **array1, Pairs &pairs)
static int max(int a, int b)