7#ifndef _USE_MATH_DEFINES
8#define _USE_MATH_DEFINES
48 return m_cylinder.Init(pointA, pointB, normalA, normalB);
54 return m_cylinder.Distance(p);
60 return m_cylinder.SignedDistance(p);
67 m_cylinder.Normal(p, &normal);
74 std::pair<float, float>* dn)
const
77 dn->first = m_cylinder.DistanceAndNormal(p, &normal);
78 dn->second = n.dot(normal);
84 m_cylinder.Project(p, pp);
90 m_cylinder.Normal(p, n);
102 numTests, epsilon, normalThresh, rms, pc, indices);
134 std::pair<size_t, float>* score)
const
165 m_cylinder.Serialize(binary, o);
175 return m_cylinder.SerializedSize() + 1;
181 m_cylinder.Transform(scale, translate);
188 m_cylinder.Transform(rot, trans);
194 visitor->
Visit(*
this);
212 for (
unsigned int i = 0; i < 5; ++i, u += uStep)
215 for (
unsigned int j = 0; j < 5; ++j, v += vStep)
216 InSpace(u, v * m_cylinder.Radius(), &samples[i * 5 + j], &samples[i * 5 + j + 25]);
218 size_t c = samples.
size() / 2;
221 if (sphere.
Init(samples))
225 for (
size_t i = 0; i <
c; ++i)
226 if (sphere.
Distance(samples[i]) > distThresh)
234 suggestions->back()->Release();
241 for (
size_t i = 0; i <
c; ++i)
242 if (plane.
Distance(samples[i]) > distThresh)
250 suggestions->back()->Release();
293 return m_cylinder.Radius() <= (1.f + tolerance) * shape.m_cylinder.
Radius() &&
294 (1.f + tolerance) * m_cylinder.Radius() >= shape.m_cylinder.
Radius();
318 m_cylinder.Parameters(p, param);
320 param->second *= m_cylinder.Radius();
329 ParametersImpl(begin, end, bmpParams);
338 ParametersImpl(begin, end, bmpParams);
348 *uextent = size_t(std::ceil((bbox->
Max()[0] - bbox->
Min()[0]) / epsilon));
349 *vextent = size_t(std::ceil((bbox->
Max()[1] - bbox->
Min()[1]) / epsilon));
350 if ((*vextent) * (*uextent) > 1e6)
353 if (bbox->
Min()[1] > epsilon && bbox->
Max()[1] < 2 *
M_PI * m_cylinder.Radius() - epsilon)
358 for (
size_t i = 0; i < params->size(); ++i)
360 angularParams[i] = (*params)[i].second;
362 std::sort(angularParams.
begin(), angularParams.
end());
366 for (
size_t i = 1; i < angularParams.
size(); ++i)
368 float gap = angularParams[i] - angularParams[i - 1];
372 lower = angularParams[i - 1];
373 upper = angularParams[i];
376 if (maxGap > epsilon)
379 float newCut = (lower + upper) / 2.f;
380 m_cylinder.RotateAngularDirection(newCut / m_cylinder.Radius());
381 bbox->
Min()[1] = std::numeric_limits<float>::infinity();
382 bbox->
Max()[1] = -std::numeric_limits<float>::infinity();
383 for (
size_t i = 0; i < params->size(); ++i)
385 (*params)[i].second -= newCut;
386 if ((*params)[i].second < 0)
388 (*params)[i].second = 2 *
M_PI * m_cylinder.Radius() + (*params)[i].second;
390 if ((*params)[i].second < bbox->Min()[1])
392 bbox->
Min()[1] = (*params)[i].second;
394 if ((*params)[i].second > bbox->
Max()[1])
396 bbox->
Max()[1] = (*params)[i].second;
399 *vextent = size_t(std::ceil((bbox->
Max()[1] - bbox->
Min()[1]) / epsilon));
410 std::pair<int, int>* inBmp)
const
413 inBmp->first = std::floor((param.first - bbox.
Min()[0]) / epsilon);
414 inBmp->second = std::floor((param.second - bbox.
Min()[1]) / epsilon);
424 if (bbox.
Max()[1] - bbox.
Min()[1] >= 2 *
M_PI * m_cylinder.Radius() - 2 * epsilon)
444 for (
int i = 0; i < uextent; i++)
459 if (extBbox.
Min()[1] * m_cylinder.Radius() <= epsilon &&
460 extBbox.
Max()[1] * m_cylinder.Radius() >= 2 *
M_PI * m_cylinder.Radius() - epsilon)
464 size_t row = 0, j = 0;
465 for (; j < vextent; ++j)
468 for (
size_t i = 0; i < uextent; ++i)
470 if (componentsImg[row + i] == label)
488 row = (vextent - 1) * uextent, j = 0;
489 for (; j < vextent; ++j)
492 for (
size_t i = 0; i < uextent; ++i)
494 if (componentsImg[row + i] == label)
508 m_minPhi = minj * epsilon / m_cylinder.Radius() + extBbox.
Min()[1];
509 m_maxPhi = maxj * epsilon / m_cylinder.Radius() + extBbox.
Min()[1];
513 m_minPhi = extBbox.
Min()[1];
514 m_maxPhi = extBbox.
Max()[1];
523 q.RotationRad(v / m_cylinder.Radius(),
524 m_cylinder.AxisDirection()[0],
525 m_cylinder.AxisDirection()[1],
526 m_cylinder.AxisDirection()[2]);
528 q.Rotate(m_cylinder.AngularDirection(), &vvec);
529 *p = u * m_cylinder.AxisDirection() + m_cylinder.Radius() * vvec + m_cylinder.AxisPosition();
545 q.RotationRad((bbox.
Min()[1] + epsilon * (v + .5f)) / m_cylinder.Radius(),
546 m_cylinder.AxisDirection()[0],
547 m_cylinder.AxisDirection()[1],
548 m_cylinder.AxisDirection()[2]);
550 q.Rotate(m_cylinder.AngularDirection(), &vvec);
551 *p = (bbox.
Min()[0] + epsilon * (u + .5f)) * m_cylinder.AxisDirection() +
552 m_cylinder.Radius() * vvec + m_cylinder.AxisPosition();
MiscLib::performance_t totalTime_cylinderConnected
class DLL_LINKAGE SpherePrimitiveShape
class DLL_LINKAGE PlanePrimitiveShape
unsigned int ConfidenceTests(unsigned int numTests, float epsilon, float normalThresh, float rms, const PointCloud &pc, const MiscLib::Vector< size_t > &indices) const
GfxTL::AABox< GfxTL::Vector2Df > m_extBbox
void DistanceAndNormalDeviation(const Vec3f &p, const Vec3f &n, std::pair< float, float > *dn) const
unsigned int ConfidenceTests(unsigned int numTests, float epsilon, float normalThresh, float rms, const PointCloud &pc, const MiscLib::Vector< size_t > &indices) const
size_t SerializedSize() const
float SignedDistance(const Vec3f &p) const
float NormalDeviation(const Vec3f &p, const Vec3f &n) const
void PreWrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, size_t uextent, size_t vextent, MiscLib::Vector< char > *bmp) const
PrimitiveShape * Clone() const
void Normal(const Vec3f &p, Vec3f *n) const
void SuggestSimplifications(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end, float distThresh, MiscLib::Vector< MiscLib::RefCountPtr< PrimitiveShape > > *suggestions) const
void InBitmap(const std::pair< float, float > ¶m, float epsilon, const GfxTL::AABox< GfxTL::Vector2Df > &bbox, size_t uextent, size_t vextent, std::pair< int, int > *inBmp) const
void Transform(float scale, const Vec3f &translate)
PrimitiveShape * LSFit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end, std::pair< size_t, float > *score) const
size_t Identifier() const
void Visit(PrimitiveShapeVisitor *visitor) const
void Project(const Vec3f &p, Vec3f *pp) const
bool Similar(float tolerance, const CylinderPrimitiveShape &shape) const
LevMarFunc< float > * SignedDistanceFunc() const
bool Fit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
void SetExtent(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, const MiscLib::Vector< int > &componentsImg, size_t uextent, size_t vextent, float epsilon, int label)
void WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, bool *uwrap, bool *vwrap) const
float Distance(const Vec3f &p) const
void Serialize(std::ostream *o, bool binary=true) const
This is the one and only serialization function It stores all the parameters of the shape as well as ...
void BitmapExtent(float epsilon, GfxTL::AABox< GfxTL::Vector2Df > *bbox, MiscLib::Vector< std::pair< float, float > > *params, size_t *uextent, size_t *vextent)
void Description(std::string *s) const
bool Init(const Vec3f &pointA, const Vec3f &pointB, const Vec3f &normalA, const Vec3f &normalB)
void Parameters(const Vec3f &p, std::pair< float, float > *param) const
bool InSpace(float u, float v, Vec3f *p, Vec3f *n) const
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
const Point * const_iterator
void push_back(const T &v)
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
float Distance(const Vec3f &pos) const
virtual void Visit(const PlanePrimitiveShape &plane)=0
PrimtiveShape is a shape primitive in conjunction with a parametrization.
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
float Distance(const Vec3f &p) const
bool Init(const MiscLib::Vector< Vec3f > &samples)
VectorXD< 3, float > Vector3Df