Go to the documentation of this file.
52 const Vec3f& p,
const Vec3f& n, std::pair< float, float >* dn)
const
56 dn->second = n.
dot(normal);
70 float epsilon,
float normalThresh,
float rms,
const PointCloud&
pc,
73 return BasePrimitiveShape::ConfidenceTests< Cone >(numTests, epsilon,
99 std::pair< size_t, float >* score)
const
140 std::pair< float, float >* param)
const
150 param->second = (param->second -
float(
M_PI)) * r;
154 float l = param->first;
155 param->first = std::sin(param->second) * l;
156 param->second = std::cos(param->second) * l;
166 ParametersImpl(begin, end, bmpParams);
175 ParametersImpl(begin, end, bmpParams);
191 visitor->
Visit(*
this);
206 for (
unsigned int i = 0; i < 5; ++i, u += uStep)
209 for (
unsigned int j = 0; j < 5; ++j,
v += vStep)
214 bmpu = std::sin(
v) * u;
215 bmpv = std::cos(
v) * u;
223 InSpace(bmpu, bmpv, &samples[i * 5 + j],
224 &samples[i * 5 + j + 25]);
227 size_t c = samples.
size() / 2;
234 for (
size_t i = 0; i <
c; ++i)
235 if (cylinder.
Distance(samples[i]) > distThresh)
243 suggestions->back()->Release();
247 if (sphere.
Init(samples))
251 for (
size_t i = 0; i <
c; ++i)
252 if (sphere.
Distance(samples[i]) > distThresh)
260 suggestions->back()->Release();
267 for (
size_t i = 0; i <
c; ++i)
268 if (plane.
Distance(samples[i]) > distThresh)
276 suggestions->back()->Release();
340 return m_cone.
Angle() <= (1.f + tolerance) * shape.m_cone.
Angle()
341 && (1.f + tolerance) * m_cone.
Angle() >= shape.m_cone.
Angle();
347 size_t* uextent,
size_t* vextent)
349 *uextent = std::ceil((bbox->
Max()[0] - bbox->
Min()[0]) / epsilon);
350 *vextent = std::ceil((bbox->
Max()[1] - bbox->
Min()[1]) / epsilon) + 1;
351 if ((*vextent) * (*uextent) > 1e6 && m_cone.
Angle() <
float(
M_PI / 4))
356 angularParams.
reserve(params->size());
358 for (
size_t i = 0; i < params->size(); ++i)
359 if ((*params)[i].first > outer)
360 angularParams.
push_back(((*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];
377 float newCut = (lower + upper) / 2.f;
379 bbox->
Min()[1] = std::numeric_limits< float >::infinity();
380 bbox->
Max()[1] = -std::numeric_limits< float >::infinity();
381 for (
size_t i = 0; i < params->size(); ++i)
384 (*params)[i].second = ((*params)[i].second / r) +
float(
M_PI) - newCut;
385 if ((*params)[i].second < 0)
387 (*params)[i].second = 2 *
float(
M_PI) + (*params)[i].second;
389 (*params)[i].second = ((*params)[i].second -
float(
M_PI)) * r;
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 = std::floor((bbox->
Max()[1] - bbox->
Min()[1]) / epsilon) + 1;
405 size_t uextent,
size_t vextent, std::pair< int, int >* inBmp)
const
408 inBmp->first = std::floor((param.first - bbox.
Min()[0]) / epsilon);
409 inBmp->second = std::floor((param.second - bbox.
Min()[1]) / epsilon);
421 for (
size_t u = 0; u < uextent; ++u)
426 size_t v = std::floor((2 *
float(
M_PI) * r - bbox.
Min()[1]) / epsilon) + 1;
433 (*bmp)[
v * uextent + u] = (*bmp)[u];
444 *uwrap = *vwrap =
false;
449 float epsilon,
size_t uextent,
size_t vextent,
458 for (
size_t u = 0; u < uextent; ++u)
463 size_t v = std::floor((2 *
float(
M_PI) * r - bbox.
Min()[1]) / epsilon) + 1;
468 if ((*componentImg)[u])
470 (*componentImg)[
v * uextent + u] = (*componentImg)[u];
475 int curLabel = tempLabels.
size() - 1;
476 for (
size_t u = 0; u < uextent; ++u)
479 size_t v = std::floor((2 *
float(
M_PI) * r - bbox.
Min()[1]) / epsilon) + 1;
484 if (!(*componentImg)[
v * uextent + u])
493 size_t prevRow = (
v - 1) * uextent;
496 n[i++] = (*componentImg)[prevRow + u - 1];
498 n[i++] = (*componentImg)[prevRow + u];
501 n[i++] = (*componentImg)[prevRow + u + 1];
504 size_t row =
v * uextent;
507 n[i++] = (*componentImg)[row + u - 1];
511 n[i++] = (*componentImg)[row + u + 1];
515 size_t nextRow = (
v + 1) * uextent;
518 n[i++] = (*componentImg)[nextRow + u - 1];
520 n[i++] = (*componentImg)[nextRow + u];
523 n[i++] = (*componentImg)[nextRow + u + 1];
527 int l = (*componentImg)[
v * uextent + u];
528 for (
size_t j = 0; j < i; ++j)
535 for (
size_t i = tempLabels.
size() - 1; i > 0; --i)
541 labels->reserve(condensed.
size());
543 for (
size_t i = 0; i < tempLabels.
size(); ++i)
544 if (i == tempLabels[i].first)
546 labels->push_back(std::make_pair(count, tempLabels[i].second));
547 condensed[i] = count;
551 (*labels)[condensed[tempLabels[i].first]].second
552 += tempLabels[i].second;
554 for (
size_t i = 0; i < componentImg->
size(); ++i)
556 condensed[tempLabels[(*componentImg)[i]].first];
561 size_t vextent,
float epsilon,
int label)
571 angle = std::atan2(length, arcLength);
572 length =
std::sqrt(length * length + arcLength * arcLength);
584 *p = std::sin(m_cone.
Angle()) *
abs(length) * vvec +
598 float uf = ((
float(u) + .5f) * epsilon) + bbox.
Min()[0];
599 float vf = ((
float(
v) + .5f) * epsilon) + bbox.
Min()[1];
602 angle = std::atan2(uf, vf);
607 length = ((
float(u) + .5f) * epsilon) + bbox.
Min()[0];
608 float arcLength = ((
float(
v) + .5f) * epsilon) + bbox.
Min()[1];
622 *p = std::sin(m_cone.
Angle()) *
abs(length) * vvec +
virtual void Visit(const PlanePrimitiveShape &plane)=0
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
ConePrimitiveShape(const Cone &cone)
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
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
int ReduceLabel(int a, const MiscLib::Vector< std::pair< int, size_t > > &labels)
void push_back(const T &v)
float Distance(const Vec3f &p) 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 Parameters(const Vec3f &p, std::pair< float, float > *param) const
float Distance(const Vec3f &p) const
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
void Project(const Vec3f &p, Vec3f *pp) const
void RotateAngularDirection(float radians)
void Normal(const Vec3f &p, Vec3f *n) const
float NormalDeviation(const Vec3f &p, const Vec3f &n) const
void WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, bool *uwrap, bool *vwrap) const
PrimtiveShape is a shape primitive in conjunction with a parametrization.
size_t Identifier() const
void Visit(PrimitiveShapeVisitor *visitor) const
float DistanceAndNormal(const Vec3f &p, Vec3f *n) const
MiscLib::performance_t totalTime_coneConnected
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 ...
float SignedDistance(const Vec3f &p) const
float Distance(const Vec3f &p) const
const typedef Point * const_iterator
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
class DLL_LINKAGE CylinderPrimitiveShape
std::vector< T > abs(const std::vector< T > &v)
void PreWrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, size_t uextent, size_t vextent, MiscLib::Vector< char > *bmp) const
pcl::PointIndices::Ptr indices(const PCG &g)
Retrieve the indices of the points of the point cloud stored in a point cloud graph that actually bel...
float Distance(const Vec3f &pos) const
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
float SignedDistance(const Vec3f &p) const
bool InitAverage(const MiscLib::Vector< Vec3f > &samples)
class DLL_LINKAGE SpherePrimitiveShape
bool Fit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
bool InSpace(float u, float v, Vec3f *p, Vec3f *n) const
void Parameters(const Vec3f &p, std::pair< float, float > *param) const
void Transform(float scale, const Vec3f &translate)
void Serialize(bool binary, std::ostream *o) const
GfxTL::AABox< GfxTL::Vector2Df > m_extBbox
bool Similar(float tolerance, const ConePrimitiveShape &shape) const
const Vec3f & Center() const
void Transform(float scale, const Vec3f &translate)
float RadiusAtLength(float length) const
bool Init(const MiscLib::Vector< Vec3f > &samples)
void Project(const Vec3f &p, Vec3f *pp) const
LevMarFunc< float > * SignedDistanceFunc() 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
static size_t SerializedSize()
void SetExtent(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, const MiscLib::Vector< int > &componentsImg, size_t uextent, size_t vextent, float epsilon, int label)
void reserve(size_type s)
double v(double t, double v0, double a0, double j)
float dot(const Vec3f &v) const
size_t SerializedSize() const
void Description(std::string *s) const
void Normal(const Vec3f &p, Vec3f *n) const
double angle(const Point &a, const Point &b, const Point &c)
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
Introduction Thank you for taking interest in our work and downloading this software This library implements the algorithm described in the paper R R R Klein Efficient RANSAC for Point Cloud Shape in Computer Graphics Blackwell June If you use this software you should cite the aforementioned paper in any resulting publication Please send comments or bug reports to Ruwen Roland BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY OR CONSEQUENTIAL WHETHER IN STRICT OR EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE Example usage This section shows how to use the library to detect the shapes in a point cloud PointCloud pc
void AssociateLabel(int a, int b, MiscLib::Vector< std::pair< int, size_t > > *labels)
PrimitiveShape * Clone() const
const Vec3f AngularDirection() const
double s(double t, double s0, double v0, double a0, double j)
float Distance(const Vec3f &p) const
class DLL_LINKAGE PlanePrimitiveShape
const Vec3f & AxisDirection() const
void BitmapExtent(float epsilon, GfxTL::AABox< GfxTL::Vector2Df > *bbox, MiscLib::Vector< std::pair< float, float > > *params, size_t *uextent, size_t *vextent)
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)