52 #ifndef __PCL_SurfaceSimplifier_h 53 #define __PCL_SurfaceSimplifier_h 58 #include <pcl/Diagnostics.h> 76 #define __PCL_SURFACE_SIMPLIFIER_DEFAULT_TOLERANCE 0.01 84 #define __PCL_SURFACE_SIMPLIFIER_DEFAULT_REJECTION_ENABLED true 94 #define __PCL_SURFACE_SIMPLIFIER_DEFAULT_REJECT_FRACTION 0.2F 104 #define __PCL_SURFACE_SIMPLIFIER_DEFAULT_INCLUDE_CENTROIDS false 157 typedef double component;
162 point(
const point& ) =
default;
164 template <
typename T>
165 point( T a_x, T a_y, T a_z )
172 template <
typename T>
175 x = y = z = double( k );
178 component operator[](
int i )
const 183 point& operator +=(
const point& p )
185 x += p.x; y += p.y; z += p.z;
189 template <
typename T>
190 point& operator /=( T k )
192 x /= k; y /= k; z /= k;
196 double SquaredDistanceTo(
const point& p )
const 198 double dx = p.x - x, dy = p.y - y;
199 return dx*dx + dy*dy;
228 : m_tolerance(
Abs( tolerance ) )
230 PCL_PRECONDITION( tolerance >= 0 )
267 PCL_PRECONDITION( tolerance > 0 )
268 m_tolerance =
Abs( tolerance );
279 return m_enableRejection;
294 m_enableRejection = enabled;
303 EnableRejection( !disable );
315 return m_rejectFraction;
338 PCL_PRECONDITION( rejectFraction > 0 && rejectFraction < 1 )
339 m_rejectFraction =
Range( rejectFraction, 0.0F, 1.0F );
350 return m_includeCentroids;
366 m_includeCentroids = enable;
375 EnableCentroidInclusion( !disable );
405 void Simplify( C& xs, C& ys, C& zs,
const C& x,
const C& y,
const C& z )
const 407 int n =
Min(
Min( x.Length(), y.Length() ), z.Length() );
410 xs = x; ys = y; zs = z;
415 for (
int i = 0; i < n; ++i )
416 P << point( x[i], y[i], z[i] );
420 if (
int( P.
Length() ) >= n )
422 xs = x; ys = y; zs = z;
433 for (
int i = 0; i < n; ++i )
435 xs[i] =
typename C::item_type( P[i].x );
436 ys[i] =
typename C::item_type( P[i].y );
437 zs[i] =
typename C::item_type( P[i].z );
443 double m_tolerance = __PCL_SURFACE_SIMPLIFIER_DEFAULT_TOLERANCE;
444 float m_rejectFraction = __PCL_SURFACE_SIMPLIFIER_DEFAULT_REJECT_FRACTION;
445 bool m_enableRejection = __PCL_SURFACE_SIMPLIFIER_DEFAULT_REJECTION_ENABLED;
446 bool m_includeCentroids = __PCL_SURFACE_SIMPLIFIER_DEFAULT_INCLUDE_CENTROIDS;
454 point_list Simplify( tree& R )
const 458 [&Q,
this](
const rectangle& rect, point_list& points,
void*& )
460 int n = int( points.
Length() );
471 for (
const point& p : points )
478 double xx = 0, xy = 0, xz = 0, yy = 0, yz = 0, zz = 0;
479 for (
const point& p : points )
481 double dx = p.x - p0.x;
482 double dy = p.y - p0.y;
483 double dz = p.z - p0.z;
508 ComputeEigenvectors( M );
512 int mr = m_enableRejection ?
Max( 1,
TruncInt( m_rejectFraction*n ) ) : 1;
514 point_list P = points;
517 double z = p0.z - (a*(p.x - p0.x) + b*(p.y - p0.y))/c;
518 if (
Abs( p.z - z ) > m_tolerance )
528 tree R( points,
TruncInt( 0.75*n ) );
534 p.z = (p.z > z) ? z + m_tolerance : z - m_tolerance;
543 if ( m_includeCentroids )
550 for (
const point& p : P )
556 Q << ConvexHull( P );
567 static void ComputeEigenvectors(
Matrix& );
573 static point_list ConvexHull( point_list& );
580 #endif // __PCL_SurfaceSimplifier_h void EnableRejection(bool enabled=true)
void DisableRejection(bool disable=true)
void EnableCentroidInclusion(bool enable=true)
void Simplify(C &xs, C &ys, C &zs, const C &x, const C &y, const C &z) const
void Build(const point_list &points, int bucketCapacity=40)
int TruncInt(T x) noexcept
constexpr const T & Max(const T &a, const T &b) noexcept
static void Traverse(const Node *node, F f)
64-bit floating-point rectangle in the R^2 space.
void SetTolerance(double tolerance)
64-bit floating point real matrix.
void DisableCentroidInclusion(bool disable=true)
size_type Length() const noexcept
float RejectFraction() const
bool IsRejectionEnabled() const
constexpr const T & Min(const T &a, const T &b) noexcept
T Abs(const Complex< T > &c) noexcept
Bucket PR quadtree for two-dimensional point data.
SurfaceSimplifier(double tolerance)
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
bool IsCentroidInclusionEnabled() const
void SetRejectFraction(float rejectFraction)