Go to the documentation of this file.
7 #ifndef _USE_MATH_DEFINES
8 #define _USE_MATH_DEFINES
48 return m_cylinder.
Init(pointA, pointB, normalA, normalB);
67 m_cylinder.
Normal(p, &normal);
74 std::pair<float, float>* dn)
const
78 dn->second =
n.dot(normal);
101 return BasePrimitiveShape::ConfidenceTests<Cylinder>(
102 numTests, epsilon, normalThresh, rms,
pc,
indices);
134 std::pair<size_t, float>* score)
const
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();
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;
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 &&
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(),
545 q.RotationRad((bbox.
Min()[1] + epsilon * (
v + .5f)) / m_cylinder.
Radius(),
virtual void Visit(const PlanePrimitiveShape &plane)=0
void push_back(const T &v)
static size_t SerializedSize()
void RotateAngularDirection(float radians)
void Serialize(bool binary, std::ostream *o) const
float Distance(const Vec3f &p) const
float SignedDistance(const Vec3f &p) const
PrimitiveShape * Clone() const
bool LeastSquaresFit(const PointCloud &pc, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
const Vec3f & AxisPosition() const
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 Parameters(const Vec3f &p, std::pair< float, float > *param) const
PrimtiveShape is a shape primitive in conjunction with a parametrization.
void Normal(const Vec3f &p, Vec3f *n) const
constexpr auto n() noexcept
void SetExtent(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, const MiscLib::Vector< int > &componentsImg, size_t uextent, size_t vextent, float epsilon, int label)
void BitmapExtent(float epsilon, GfxTL::AABox< GfxTL::Vector2Df > *bbox, MiscLib::Vector< std::pair< float, float >> *params, size_t *uextent, size_t *vextent)
float Distance(const Vec3f &p) const
bool Init(const Vec3f &pointA, const Vec3f &pointB, const Vec3f &normalA, const Vec3f &normalB)
const typedef Point * const_iterator
void Transform(float scale, const Vec3f &translate)
const Vec3f & AxisDirection() const
LevMarFunc< float > * SignedDistanceFunc() const
void PreWrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, size_t uextent, size_t vextent, MiscLib::Vector< char > *bmp) const
bool Similar(float tolerance, const CylinderPrimitiveShape &shape) const
bool InSpace(float u, float v, Vec3f *p, Vec3f *n) 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...
bool Fit(const PointCloud &pc, float epsilon, float normalThresh, MiscLib::Vector< size_t >::const_iterator begin, MiscLib::Vector< size_t >::const_iterator end)
float Distance(const Vec3f &pos) 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
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 Project(const Vec3f &p, Vec3f *pp) const
size_t SerializedSize() const
class DLL_LINKAGE SpherePrimitiveShape
GfxTL::AABox< GfxTL::Vector2Df > m_extBbox
const Vec3f AngularDirection() const
void Transform(float scale, const Vec3f &translate)
bool Init(const MiscLib::Vector< Vec3f > &samples)
void Description(std::string *s) const
float NormalDeviation(const Vec3f &p, const Vec3f &n) const
double v(double t, double v0, double a0, double j)
void DistanceAndNormalDeviation(const Vec3f &p, const Vec3f &n, std::pair< float, float > *dn) const
void Visit(PrimitiveShapeVisitor *visitor) const
MiscLib::performance_t totalTime_cylinderConnected
unsigned int ConfidenceTests(unsigned int numTests, float epsilon, float normalThresh, float rms, const PointCloud &pc, const MiscLib::Vector< size_t > &indices) const
size_t Identifier() const
float SignedDistance(const Vec3f &p) const
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 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 DistanceAndNormal(const Vec3f &p, Vec3f *normal) const
void WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox, float epsilon, bool *uwrap, bool *vwrap) const
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
double s(double t, double s0, double v0, double a0, double j)
class DLL_LINKAGE PlanePrimitiveShape
bool Init(const MiscLib::Vector< Vec3f > &samples)
void Normal(const Vec3f &p, Vec3f *normal) const
void Parameters(const Vec3f &p, std::pair< float, float > *param) const