8 #ifndef _USE_MATH_DEFINES
9 #define _USE_MATH_DEFINES
79 #define ELEM_SWAP(a,b) { float t=(a);(a)=(b);(b)=t; }
87 median = (low + high) / 2;
96 if (arr[low] > arr[high])
103 middle = (low + high) / 2;
104 if (arr[middle] > arr[high])
108 if (arr[low] > arr[high])
112 if (arr[middle] > arr[low])
127 while (arr[low] > arr[ll]) ;
132 while (arr[hh] > arr[low]) ;
158 m_min =
Vec3f(fmax, fmax, fmax);
159 m_max =
Vec3f(fmin, fmin, fmin);
166 m_min =
Vec3f(fmax, fmax, fmax);
167 m_max =
Vec3f(fmin, fmin, fmin);
168 std::copy(points, points +
s, std::back_inserter(*
this));
176 m_min =
Vec3f(fmax, fmax, fmax);
177 m_max =
Vec3f(fmin, fmin, fmin);
182 float* bbox =
new float[6];
183 m_min.getValue(bbox[0], bbox[2], bbox[4]);
184 m_max.getValue(bbox[1], bbox[3], bbox[5]);
197 for (
size_t i = 0; i < size(); ++i)
210 kd.IndexedData(begin(), end());
218 vector<int> stats(91, 0);
222 for (
unsigned int i = 0; i < size(); i ++)
231 unsigned int num = (
unsigned int)nn.size();
241 at(i).normal =
Vec3f(0, 0, 0);
249 weights.
resize(nn.size());
250 if (nn.front().sqrDist > 0)
252 float h = nn.front().sqrDist / 2;
253 for (
unsigned int i = 0; i < nn.size(); ++i)
255 weights[i] = std::exp(-nn[i].sqrDist / h);
260 std::fill(weights.
begin(), weights.
end(), 1.f);
268 float score, bestScore = -1.f;
269 for (
unsigned int tries = 0; tries < maxTries; tries++)
283 while (i2 == i0 || i2 == i1);
286 if (!plane.
Init(at(nn[i0]), at(nn[i1]), at(nn[i2])))
292 float* dist =
new float[num];
293 for (
unsigned int j = 0; j < num; j++)
302 if (score < bestScore || bestScore < 0.f)
304 if (tries > maxTries / 2)