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 using component = double;
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;
224 : m_tolerance(
Abs( tolerance ) )
226 PCL_PRECONDITION( tolerance >= 0 )
263 PCL_PRECONDITION( tolerance > 0 )
264 m_tolerance =
Abs( tolerance );
275 return m_enableRejection;
290 m_enableRejection = enabled;
299 EnableRejection( !disable );
311 return m_rejectFraction;
334 PCL_PRECONDITION( rejectFraction > 0 && rejectFraction < 1 )
335 m_rejectFraction =
Range( rejectFraction, 0.0F, 1.0F );
346 return m_includeCentroids;
362 m_includeCentroids = enable;
371 EnableCentroidInclusion( !disable );
401 void Simplify( C& xs, C& ys, C& zs,
const C& x,
const C& y,
const C& z )
const
403 int n = int(
Min(
Min( x.Length(), y.Length() ), z.Length() ) );
406 xs = x; ys = y; zs = z;
411 for (
int i = 0; i < n; ++i )
412 P << point( x[i], y[i], z[i] );
416 if (
int( P.Length() ) >= n )
418 xs = x; ys = y; zs = z;
425 n = int( P.Length() );
429 for (
int i = 0; i < n; ++i )
431 xs[i] =
typename C::item_type( P[i].x );
432 ys[i] =
typename C::item_type( P[i].y );
433 zs[i] =
typename C::item_type( P[i].z );
439 double m_tolerance = __PCL_SURFACE_SIMPLIFIER_DEFAULT_TOLERANCE;
440 float m_rejectFraction = __PCL_SURFACE_SIMPLIFIER_DEFAULT_REJECT_FRACTION;
441 bool m_enableRejection = __PCL_SURFACE_SIMPLIFIER_DEFAULT_REJECTION_ENABLED;
442 bool m_includeCentroids = __PCL_SURFACE_SIMPLIFIER_DEFAULT_INCLUDE_CENTROIDS;
450 point_list Simplify( tree& R )
const
454 [&Q,
this](
const rectangle& rect, point_list& points,
void*& )
456 int n = int( points.Length() );
467 for (
const point& p : points )
474 double xx = 0, xy = 0, xz = 0, yy = 0, yz = 0, zz = 0;
475 for (
const point& p : points )
477 double dx = p.x - p0.x;
478 double dy = p.y - p0.y;
479 double dz = p.z - p0.z;
504 ComputeEigenvectors( M );
508 int mr = m_enableRejection ?
Max( 1,
TruncInt( m_rejectFraction*n ) ) : 1;
510 point_list P = points;
513 double z = p0.z - (a*(p.x - p0.x) + b*(p.y - p0.y))/c;
514 if (
Abs( p.z - z ) > m_tolerance )
524 tree R( points,
TruncInt( 0.75*n ) );
530 p.z = (p.z > z) ? z + m_tolerance : z - m_tolerance;
539 if ( m_includeCentroids )
546 for (
const point& p : P )
552 Q << ConvexHull( P );
563 static void ComputeEigenvectors(
Matrix& );
569 static point_list ConvexHull( point_list& );
A generic rectangle in the two-dimensional space.
64-bit floating point real matrix.
Bucket PR quadtree for two-dimensional point data.
Shape-preserving simplification of 2-D surfaces.
bool IsCentroidInclusionEnabled() const
bool IsRejectionEnabled() const
void Simplify(C &xs, C &ys, C &zs, const C &x, const C &y, const C &z) const
float RejectFraction() const
void EnableCentroidInclusion(bool enable=true)
void DisableRejection(bool disable=true)
SurfaceSimplifier()=default
SurfaceSimplifier(const SurfaceSimplifier &)=default
SurfaceSimplifier(double tolerance)
void EnableRejection(bool enabled=true)
void DisableCentroidInclusion(bool disable=true)
void SetRejectFraction(float rejectFraction)
void SetTolerance(double tolerance)
T Abs(const Complex< T > &c) noexcept
int TruncInt(T x) noexcept
constexpr const T & Min(const T &a, const T &b) noexcept
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
constexpr const T & Max(const T &a, const T &b) noexcept