Go to the documentation of this file.
61 std::pair<float, float>* dn)
const
65 dn->second =
n.dot(normal);
88 return BasePrimitiveShape::ConfidenceTests<Cone>(
89 numTests, epsilon, normalThresh, rms,
pc,
indices);
120 std::pair<size_t, float>* score)
const
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);
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)
245 bmpu = std::sin(
v) * u;
246 bmpv = std::cos(
v) * 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());
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;
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)
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);
462 for (
size_t u = 0; u < uextent; ++u)
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;
503 for (
size_t u = 0; u < uextent; ++u)
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)
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];
619 angle = std::atan2(length, arcLength);
620 length =
std::sqrt(length * length + arcLength * arcLength);
632 *p = std::sin(m_cone.
Angle()) *
abs(length) * vvec +
651 float uf = ((
float(u) + .5f) * epsilon) + bbox.
Min()[0];
652 float vf = ((
float(
v) + .5f) * epsilon) + bbox.
Min()[1];
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];
675 *p = std::sin(m_cone.
Angle()) *
abs(length) * vvec +
virtual void Visit(const PlanePrimitiveShape &plane)=0
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 push_back(const T &v)
float Distance(const Vec3f &p) 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
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
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 AssociateLabel(int a, int b, MiscLib::Vector< std::pair< int, size_t >> *labels)
constexpr auto n() noexcept
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
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
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
bool Similar(float tolerance, const ConePrimitiveShape &shape) const
GfxTL::AABox< GfxTL::Vector2Df > m_extBbox
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
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
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)
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)
int ReduceLabel(int a, const MiscLib::Vector< std::pair< int, size_t >> &labels)
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
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
void BitmapExtent(float epsilon, GfxTL::AABox< GfxTL::Vector2Df > *bbox, MiscLib::Vector< std::pair< float, float >> *params, size_t *uextent, size_t *vextent)
class DLL_LINKAGE PlanePrimitiveShape
const Vec3f & AxisDirection() const
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)