10#ifndef _USE_MATH_DEFINES
11#define _USE_MATH_DEFINES
58#define ELEM_SWAP(a, b) \
73 median = (low + high) / 2;
82 if (arr[low] > arr[high])
89 middle = (low + high) / 2;
90 if (arr[middle] > arr[high])
94 if (arr[low] > arr[high])
98 if (arr[middle] > arr[low])
112 }
while (arr[low] > arr[ll]);
116 }
while (arr[hh] > arr[low]);
141 float fmax = numeric_limits<float>::max();
143 m_min =
Vec3f(fmax, fmax, fmax);
144 m_max =
Vec3f(fmin, fmin, fmin);
149 float fmax = numeric_limits<float>::max();
151 m_min =
Vec3f(fmax, fmax, fmax);
152 m_max =
Vec3f(fmin, fmin, fmin);
153 std::copy(points, points + s, std::back_inserter(*
this));
160 float fmax = numeric_limits<float>::max();
162 m_min =
Vec3f(fmax, fmax, fmax);
163 m_max =
Vec3f(fmin, fmin, fmin);
169 float* bbox =
new float[6];
170 m_min.getValue(bbox[0], bbox[2], bbox[4]);
171 m_max.getValue(bbox[1], bbox[3], bbox[5]);
186 for (
size_t i = 0; i <
size(); ++i)
204 KdTree3Df::NearestNeighborsAuxData<value_type> nnAux;
208 vector<int> stats(91, 0);
212 for (
unsigned int i = 0; i <
size(); i++)
220 kd.NearestNeighbors(
at(i), kNN, &nn, &nnAux);
221 unsigned int num = (
unsigned int)nn.
size();
240 if (nn.
front().sqrDist > 0)
242 float h = nn.
front().sqrDist / 2;
243 for (
unsigned int i = 0; i < nn.
size(); ++i)
245 weights[i] = std::exp(-nn[i].sqrDist / h);
250 std::fill(weights.
begin(), weights.
end(), 1.f);
259 float score, bestScore = -1.f;
260 for (
unsigned int tries = 0; tries < maxTries; tries++)
272 }
while (i2 == i0 || i2 == i1);
275 if (!plane.
Init(
at(nn[i0]),
at(nn[i1]),
at(nn[i2])))
281 float* dist =
new float[num];
282 for (
unsigned int j = 0; j < num; j++)
291 if (score < bestScore || bestScore < 0.f)
293 if (tries > maxTries / 2)
296 int index = std::floor(
298 std::acos(std::min(1.f, abs(plane.
getNormal().
dot(
at(i).normal)))));
bool Fit(const PointType &origin, PointsForwardIt begin, PointsForwardIt end, WeightsForwardIt weights)
void Normal(PointType *normal) const
void resize(size_type s, const value_type &v)
void resize(size_type s, const value_type &v)
const Point * const_iterator
float getDistance(const Vec3f &pos) const
const Vec3f & getNormal() const
bool Init(Vec3f p1, Vec3f p2, Vec3f p3)
void GetCurrentBBox(Vec3f *min, Vec3f *max) const
void Translate(const Vec3f &trans)
void calcNormals(float radius, unsigned int kNN=20, unsigned int maxTries=100)
float dot(const Vec3f &v) const
IndexedIterator< IndexIteratorT, IteratorT > IndexIterate(IndexIteratorT idxIt, IteratorT it)