18 int Split(
MVertex **vertices,
int arraysize,
int GrayCode0,
int GrayCode1,
19 double BoundingBoxXmin,
double BoundingBoxXmax,
20 double BoundingBoxYmin,
double BoundingBoxYmax,
21 double BoundingBoxZmin,
double BoundingBoxZmax);
22 void Sort(
MVertex **vertices,
int arraysize,
int e,
int d,
23 double BoundingBoxXmin,
double BoundingBoxXmax,
24 double BoundingBoxYmin,
double BoundingBoxYmax,
25 double BoundingBoxZmin,
double BoundingBoxZmax,
int depth);
31 double ratio,
int *depth)
36 if(arraysize >= threshold) {
38 middle = (int)(arraysize * ratio);
41 Sort(&(vertices[middle]), arraysize - middle, 0, 0,
bbox.
min().
x(),
45 void Apply(std::vector<MVertex *> &v)
47 for(
size_t i = 0; i < v.size(); i++) {
60 int gc[8], N, mask, travel_bit;
66 mask = (n == 2) ? 3 : 7;
69 for(i = 0; i < N; i++) { gc[i] = i ^ (i >> 1); }
71 for(e = 0; e < N; e++) {
72 for(d = 0; d < n; d++) {
77 for(i = 0; i < N; i++) {
79 k = gc[i] * (travel_bit * 2);
80 g = ((k | (k / N)) & mask);
91 for(i = 1; i < N; i++) {
93 v = (v ^ (v - 1)) >> 1;
94 for(
c = 0; v;
c++) { v >>= 1; }
100 int GrayCode1,
double BoundingBoxXmin,
101 double BoundingBoxXmax,
double BoundingBoxYmin,
102 double BoundingBoxYmax,
double BoundingBoxZmin,
103 double BoundingBoxZmax)
112 axis = (GrayCode0 ^ GrayCode1) >> 1;
115 if(axis == 0) { split = 0.5 * (BoundingBoxXmin + BoundingBoxXmax); }
117 split = 0.5 * (BoundingBoxYmin + BoundingBoxYmax);
120 split = 0.5 * (BoundingBoxZmin + BoundingBoxZmax);
125 d = ((GrayCode0 & (1 << axis)) == 0) ? 1 : -1;
135 for(; i < arraysize; i++) {
136 if(vertices[i]->point()[axis] >= split)
break;
139 if(vertices[j]->point()[axis] < split)
break;
142 if(i >= (j + 1))
break;
144 swapvert = vertices[i];
145 vertices[i] = vertices[j];
146 vertices[j] = swapvert;
152 for(; i < arraysize; i++) {
153 if(vertices[i]->point()[axis] <= split)
break;
156 if(vertices[j]->point()[axis] > split)
break;
159 if(i >= (j + 1))
break;
161 swapvert = vertices[i];
162 vertices[i] = vertices[j];
163 vertices[j] = swapvert;
174 double BoundingBoxXmin,
double BoundingBoxXmax,
175 double BoundingBoxYmin,
double BoundingBoxYmax,
176 double BoundingBoxZmin,
double BoundingBoxZmax,
179 double x1, x2, y1, y2, z1, z2;
180 int p[9], w, e_w, d_w, k, ei, di;
187 BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin,
188 BoundingBoxYmax, BoundingBoxZmin, BoundingBoxZmax);
190 BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin,
191 BoundingBoxYmax, BoundingBoxZmin, BoundingBoxZmax);
193 BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin,
194 BoundingBoxYmax, BoundingBoxZmin, BoundingBoxZmax);
197 BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax,
198 BoundingBoxZmin, BoundingBoxZmax) +
202 BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax,
203 BoundingBoxZmin, BoundingBoxZmax) +
207 BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax,
208 BoundingBoxZmin, BoundingBoxZmax) +
212 BoundingBoxXmin, BoundingBoxXmax, BoundingBoxYmin, BoundingBoxYmax,
213 BoundingBoxZmin, BoundingBoxZmax) +
217 if((depth + 1) ==
maxDepth) {
return; }
221 for(w = 0; w < 8; w++) {
222 if((p[w + 1] - p[w]) >
Limit) {
223 if(w == 0) { e_w = 0; }
225 k = 2 * ((w - 1) / 2);
229 e_w = ((k << (d + 1)) & mask) | ((k >> (n - d - 1)) & mask);
231 if(w == 0) { d_w = 0; }
235 di = (d + d_w + 1) % n;
237 x1 = 0.5 * (BoundingBoxXmin + BoundingBoxXmax);
238 x2 = BoundingBoxXmax;
241 x1 = BoundingBoxXmin;
242 x2 = 0.5 * (BoundingBoxXmin + BoundingBoxXmax);
245 y1 = 0.5 * (BoundingBoxYmin + BoundingBoxYmax);
246 y2 = BoundingBoxYmax;
249 y1 = BoundingBoxYmin;
250 y2 = 0.5 * (BoundingBoxYmin + BoundingBoxYmax);
253 z1 = 0.5 * (BoundingBoxZmin + BoundingBoxZmax);
254 z2 = BoundingBoxZmax;
257 z1 = BoundingBoxZmin;
258 z2 = 0.5 * (BoundingBoxZmin + BoundingBoxZmax);
260 Sort(&(vertices[p[w]]), p[w + 1] - p[w], ei, di, x1, x2, y1, y2, z1, z2,