41 return m_cone.Distance(p);
47 return m_cone.SignedDistance(p);
54 m_cone.Normal(p, &normal);
61 std::pair<float, float>* dn)
const
64 dn->first = m_cone.DistanceAndNormal(p, &normal);
65 dn->second = n.dot(normal);
71 m_cone.Project(p, pp);
89 numTests, epsilon, normalThresh, rms, pc, indices);
120 std::pair<size_t, float>* score)
const
151 m_cone.Serialize(binary, o);
161 return m_cone.SerializedSize() + 1;
167 m_cone.Parameters(p, param);
169 if (m_cone.Angle() <
float(
M_PI / 4))
174 float r = m_cone.RadiusAtLength(param->first);
175 param->second = (param->second -
float(
M_PI)) * r;
179 float l = param->first;
180 param->first = std::sin(param->second) * l;
181 param->second = std::cos(param->second) * l;
191 ParametersImpl(begin, end, bmpParams);
200 ParametersImpl(begin, end, bmpParams);
206 m_cone.Transform(scale, translate);
213 m_cone.Transform(rot, trans);
219 visitor->
Visit(*
this);
237 for (
unsigned int i = 0; i < 5; ++i, u += uStep)
240 for (
unsigned int j = 0; j < 5; ++j, v += vStep)
243 if (m_cone.Angle() >=
M_PI / 4)
245 bmpu = std::sin(v) * u;
246 bmpv = std::cos(v) * u;
251 float r = m_cone.RadiusAtLength(u);
254 InSpace(bmpu, bmpv, &samples[i * 5 + j], &samples[i * 5 + j + 25]);
257 size_t c = samples.
size() / 2;
264 for (
size_t i = 0; i <
c; ++i)
265 if (cylinder.
Distance(samples[i]) > distThresh)
273 suggestions->back()->Release();
277 if (sphere.
Init(samples))
281 for (
size_t i = 0; i <
c; ++i)
282 if (sphere.
Distance(samples[i]) > distThresh)
290 suggestions->back()->Release();
297 for (
size_t i = 0; i <
c; ++i)
298 if (plane.
Distance(samples[i]) > distThresh)
306 suggestions->back()->Release();
370 return m_cone.Angle() <= (1.f + tolerance) * shape.m_cone.
Angle() &&
371 (1.f + tolerance) * m_cone.Angle() >= shape.m_cone.
Angle();
382 std::ceil((bbox->
Max()[0] - bbox->
Min()[0]) / epsilon);
383 *vextent = std::ceil((bbox->
Max()[1] - bbox->
Min()[1]) / epsilon) + 1;
384 if ((*vextent) * (*uextent) > 1e6 && m_cone.Angle() <
float(
M_PI / 4))
389 angularParams.
reserve(params->size());
390 float outer = 3.f * std::max(abs(bbox->
Min()[0]), abs(bbox->
Max()[0])) / 4.f;
391 for (
size_t i = 0; i < params->size(); ++i)
392 if ((*params)[i].first > outer)
394 ((*params)[i].second / m_cone.RadiusAtLength((*params)[i].first)) +
396 std::sort(angularParams.
begin(), angularParams.
end());
400 for (
size_t i = 1; i < angularParams.
size(); ++i)
402 float gap = angularParams[i] - angularParams[i - 1];
406 lower = angularParams[i - 1];
407 upper = angularParams[i];
411 float newCut = (lower + upper) / 2.f;
412 m_cone.RotateAngularDirection(newCut);
413 bbox->
Min()[1] = std::numeric_limits<float>::infinity();
414 bbox->
Max()[1] = -std::numeric_limits<float>::infinity();
415 for (
size_t i = 0; i < params->size(); ++i)
417 float r = m_cone.RadiusAtLength((*params)[i].first);
418 (*params)[i].second = ((*params)[i].second / r) +
float(
M_PI) - newCut;
419 if ((*params)[i].second < 0)
421 (*params)[i].second = 2 *
float(
M_PI) + (*params)[i].second;
423 (*params)[i].second = ((*params)[i].second -
float(
M_PI)) * r;
424 if ((*params)[i].second < bbox->Min()[1])
426 bbox->
Min()[1] = (*params)[i].second;
428 if ((*params)[i].second > bbox->
Max()[1])
430 bbox->
Max()[1] = (*params)[i].second;
433 *vextent = std::floor((bbox->
Max()[1] - bbox->
Min()[1]) / epsilon) + 1;
443 std::pair<int, int>* inBmp)
const
446 inBmp->first = std::floor((param.first - bbox.
Min()[0]) / epsilon);
447 inBmp->second = std::floor((param.second - bbox.
Min()[1]) / epsilon);
457 if (m_cone.Angle() >=
float(
M_PI / 4))
462 for (
size_t u = 0; u < uextent; ++u)
466 float r = m_cone.RadiusAtLength(u * epsilon + bbox.
Min()[0]);
467 size_t v = std::floor((2 *
float(
M_PI) * r - bbox.
Min()[1]) / epsilon) + 1;
474 (*bmp)[v * uextent + u] = (*bmp)[u];
487 *uwrap = *vwrap =
false;
498 if (m_cone.Angle() >=
float(
M_PI / 4))
503 for (
size_t u = 0; u < uextent; ++u)
507 float r = m_cone.RadiusAtLength(u * epsilon + bbox.
Min()[0]);
508 size_t v = std::floor((2 *
float(
M_PI) * r - bbox.
Min()[1]) / epsilon) + 1;
513 if ((*componentImg)[u])
515 (*componentImg)[v * uextent + u] = (*componentImg)[u];
520 int curLabel = tempLabels.
size() - 1;
521 for (
size_t u = 0; u < uextent; ++u)
523 float r = m_cone.RadiusAtLength(u * epsilon + bbox.
Min()[0]);
524 size_t v = std::floor((2 *
float(
M_PI) * r - bbox.
Min()[1]) / epsilon) + 1;
529 if (!(*componentImg)[v * uextent + u])
538 size_t prevRow = (v - 1) * uextent;
541 n[i++] = (*componentImg)[prevRow + u - 1];
543 n[i++] = (*componentImg)[prevRow + u];
546 n[i++] = (*componentImg)[prevRow + u + 1];
549 size_t row = v * uextent;
552 n[i++] = (*componentImg)[row + u - 1];
556 n[i++] = (*componentImg)[row + u + 1];
560 size_t nextRow = (v + 1) * uextent;
563 n[i++] = (*componentImg)[nextRow + u - 1];
565 n[i++] = (*componentImg)[nextRow + u];
568 n[i++] = (*componentImg)[nextRow + u + 1];
572 int l = (*componentImg)[v * uextent + u];
573 for (
size_t j = 0; j < i; ++j)
580 for (
size_t i = tempLabels.
size() - 1; i > 0; --i)
586 labels->reserve(condensed.
size());
588 for (
size_t i = 0; i < tempLabels.
size(); ++i)
589 if (i == tempLabels[i].first)
591 labels->push_back(std::make_pair(count, tempLabels[i].second));
592 condensed[i] = count;
596 (*labels)[condensed[tempLabels[i].first]].second += tempLabels[i].second;
598 for (
size_t i = 0; i < componentImg->
size(); ++i)
599 (*componentImg)[i] = condensed[tempLabels[(*componentImg)[i]].first];
616 if (m_cone.Angle() >=
float(
M_PI / 4))
619 angle = std::atan2(length, arcLength);
620 length = std::sqrt(length * length + arcLength * arcLength);
625 angle = (arcLength / m_cone.RadiusAtLength(length)) +
float(
M_PI);
629 angle, m_cone.AxisDirection()[0], m_cone.AxisDirection()[1], m_cone.AxisDirection()[2]);
631 q.Rotate(m_cone.AngularDirection(), &vvec);
632 *p = std::sin(m_cone.Angle()) * abs(length) * vvec +
633 std::cos(m_cone.Angle()) * length * m_cone.AxisDirection() + m_cone.Center();
634 m_cone.Normal(*p, n);
649 if (m_cone.Angle() >=
float(
M_PI / 4))
651 float uf = ((
float(u) + .5f) * epsilon) + bbox.
Min()[0];
652 float vf = ((
float(v) + .5f) * epsilon) + bbox.
Min()[1];
653 length = std::sqrt(uf * uf + vf * vf);
655 angle = std::atan2(uf, vf);
660 length = ((
float(u) + .5f) * epsilon) + bbox.
Min()[0];
661 float arcLength = ((
float(v) + .5f) * epsilon) + bbox.
Min()[1];
662 angle = (arcLength / m_cone.RadiusAtLength(length)) +
float(
M_PI);
672 angle, m_cone.AxisDirection()[0], m_cone.AxisDirection()[1], m_cone.AxisDirection()[2]);
674 q.Rotate(m_cone.AngularDirection(), &vvec);
675 *p = std::sin(m_cone.Angle()) * abs(length) * vvec +
676 std::cos(m_cone.Angle()) * length * m_cone.AxisDirection() + m_cone.Center();
678 m_cone.Normal(*p, n);
int ReduceLabel(int a, const MiscLib::Vector< std::pair< int, size_t > > &labels)
void AssociateLabel(int a, int b, MiscLib::Vector< std::pair< int, size_t > > *labels)
MiscLib::performance_t totalTime_coneConnected
class DLL_LINKAGE CylinderPrimitiveShape
class DLL_LINKAGE SpherePrimitiveShape
class DLL_LINKAGE ConePrimitiveShape
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 WrapComponents(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, size_t uextent, size_t vextent, MiscLib::Vector< int > *componentImg, MiscLib::Vector< std::pair< int, size_t > > *labels) const
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
ConePrimitiveShape(const Cone &cone)
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
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)
bool Similar(float tolerance, const ConePrimitiveShape &shape) const
void Description(std::string *s) const
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)
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 InitAverage(const MiscLib::Vector< Vec3f > &samples)
const Point * const_iterator
void push_back(const T &v)
void reserve(size_type s)
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
double angle(const Point &a, const Point &b, const Point &c)