52 #ifndef __PCL_ShepardInterpolation_h
53 #define __PCL_ShepardInterpolation_h
58 #include <pcl/Diagnostics.h>
63 #ifndef __PCL_BUILDING_PIXINSIGHT_APPLICATION
77 #define __PCL_SHEPARD_DEFAULT_SEARCH_RADIUS 0.10
84 #define __PCL_SHEPARD_DEFAULT_POWER 4
91 #define __PCL_SHEPARD_DEFAULT_REGULARIZATION 0
124 template <
typename T>
152 constexpr
static int BucketCapacity = 16;
196 return !m_T.IsEmpty();
222 PCL_PRECONDITION( m > 0 )
223 m_mu = (m > 0) ? m : __PCL_SHEPARD_DEFAULT_POWER;
264 PCL_PRECONDITION( R > 0 )
265 m_R = (R < 0 || 1 + R == 1) ? __PCL_SHEPARD_DEFAULT_SEARCH_RADIUS : R;
296 PCL_PRECONDITION( r >= 0 && r < 1 )
297 m_r = (r < 0 || r >= 1) ? __PCL_SHEPARD_DEFAULT_REGULARIZATION : r;
334 DoInitialize(
nullptr, x, y, z, n );
374 DoInitialize( &rect, x, y, z, n );
403 T operator ()(
double x,
double y )
const
405 PCL_PRECONDITION( !m_T.IsEmpty() )
407 const double dx = m_r0*(x - m_x0);
408 const double dy = m_r0*(y - m_y0);
410 for (
double R = m_R; ; R += m_R )
415 m_T.Search(
DRect( dx-R, dy-R, dx+R, dy+R ),
418 double x = dx - v[0];
419 double y = dy - v[1];
420 double r2 = x*x + y*y;
424 double w =
PowI( 1 -
Sqrt( r2 )/R, m_mu );
445 int r =
Min(
TruncInt( m_r * m ), (m >> 1) - (m & 1)^1 );
452 for (
int i = 0; i < r; ++i )
455 V[m-i-1].y = V[m-r-1].y;
460 for (
const DPoint& v : V )
463 return T( Wz.
y/Wz.
x );
477 template <
typename Tp>
480 return operator ()(
double( p.
x ),
double( p.
y ) );
494 template <
typename T1>
497 PCL_PRECONDITION( !m_T.IsEmpty() )
498 PCL_PRECONDITION( X !=
nullptr && Y !=
nullptr && Z !=
nullptr )
499 PCL_PRECONDITION( n > 0 )
501 Z[i] = T1(
operator()(
double( X[i] ),
double( Y[i] ) ) );
523 int m_mu = __PCL_SHEPARD_DEFAULT_POWER;
524 double m_R = __PCL_SHEPARD_DEFAULT_SEARCH_RADIUS;
525 float m_r = __PCL_SHEPARD_DEFAULT_REGULARIZATION;
535 PCL_PRECONDITION( x !=
nullptr && y !=
nullptr && z !=
nullptr )
536 PCL_PRECONDITION( n > 2 )
539 throw Error(
"ShepardInterpolation::Initialize(): At least three input nodes must be specified." );
545 if ( rect ==
nullptr )
551 for (
int i = 0; i < n; ++i )
563 for (
int i = 0; i < n; ++i )
565 double dx = x[i] - m_x0;
566 double dy = y[i] - m_y0;
567 double r =
Sqrt( dx*dx + dy*dy );
574 m_x0 = rect->CenterX();
575 m_y0 = rect->CenterY();
576 m_r0 = rect->Diagonal()/2;
580 throw Error(
"ShepardInterpolation::Initialize(): Empty or insignificant interpolation space." );
587 for (
int i = 0; i < n; ++i )
588 V <<
vector_type( m_r0*(x[i] - m_x0), m_r0*(y[i] - m_y0), z[i] );
597 return (p[0] != q[0]) ? p[0] < q[0] : p[1] < q[1];
600 for (
int i = 0, j = 1; j < n; ++i, ++j )
601 if (
Abs( V[i][0] - V[j][0] ) <= std::numeric_limits<T>::epsilon() )
602 if (
Abs( V[i][1] - V[j][1] ) <= std::numeric_limits<T>::epsilon() )
608 for (
int j : remove )
616 if ( U.Length() < 3 )
617 throw Error(
"ShepardInterpolation::Initialize(): Less than three input nodes left after sanitization." );
624 if ( rect ==
nullptr )
625 m_T.Build( V, BucketCapacity );
628 m_T.Build( *rect, V, BucketCapacity );
629 if ( m_T.Length() < 3 )
630 throw Error(
"ShepardInterpolation::Initialize(): Less than three input nodes in the specified search region." );
654 template <
class P = DPo
int>
698 int power = __PCL_SHEPARD_DEFAULT_POWER,
699 double radius = __PCL_SHEPARD_DEFAULT_SEARCH_RADIUS )
701 Initialize( P1, P2, power, radius );
713 Initialize( Sx, Sy );
761 int power = __PCL_SHEPARD_DEFAULT_POWER,
762 double radius = __PCL_SHEPARD_DEFAULT_SEARCH_RADIUS,
763 float smoothing = __PCL_SHEPARD_DEFAULT_REGULARIZATION )
765 PCL_PRECONDITION( P1.
Length() >= 3 )
767 PCL_PRECONDITION( power > 0 )
768 PCL_PRECONDITION( radius > 0 )
769 PCL_PRECONDITION( smoothing >= 0 && smoothing < 1 )
774 m_Sx.SetPower( power );
775 m_Sy.SetPower( power );
777 m_Sx.SetRadius( radius );
778 m_Sy.SetRadius( radius );
780 m_Sx.SetSmoothing( smoothing );
781 m_Sy.SetSmoothing( smoothing );
784 throw Error(
"PointShepardInterpolation::Initialize(): At least three input nodes must be specified." );
787 throw Error(
"PointShepardInterpolation::Initialize(): Incompatible point array lengths." );
793 for (
int i = 0; i < X.Length(); ++i )
800 m_Sx.Initialize( X.Begin(), Y.Begin(), Zx.Begin(), X.Length() );
801 m_Sy.Initialize( X.Begin(), Y.Begin(), Zy.
Begin(), X.Length() );
820 return m_Sx.IsValid() && m_Sy.IsValid();
844 template <
typename T>
847 return DPoint( m_Sx( x, y ), m_Sy( x, y ) );
853 template <
typename T>
856 return operator ()( p.
x, p.
y );
870 template <
typename T>
873 PCL_PRECONDITION( ISValid() )
874 m_Sx.Evaluate( ZX, X, Y, n );
875 m_Sy.Evaluate( ZY, X, Y, n );
900 friend class DrizzleDataDecoder;
bool IsEmpty() const noexcept
size_type Length() const noexcept
Drizzle integration data parser and generator.
A simple exception with an associated error message.
A generic point in the two-dimensional space.
component x
Abscissa (horizontal, or X-axis coordinate).
component y
Ordinate (vertical, or Y-axis coordinate).
A generic rectangle in the two-dimensional space.
Generic vector of arbitrary length.
Vector Shepard interpolation/approximation in two dimensions.
const surface & SurfaceX() const
PointShepardInterpolation(const surface &Sx, const surface &Sy)
PointShepardInterpolation(const point_list &P1, const point_list &P2, int power=__PCL_SHEPARD_DEFAULT_POWER, double radius=__PCL_SHEPARD_DEFAULT_SEARCH_RADIUS)
PointShepardInterpolation(const PointShepardInterpolation &)=default
bool HasFastVectorEvaluation() const
const surface & SurfaceY() const
void Evaluate(T *ZX, T *ZY, const T *X, const T *Y, size_type n) const
PointShepardInterpolation()=default
void Initialize(const point_list &P1, const point_list &P2, int power=__PCL_SHEPARD_DEFAULT_POWER, double radius=__PCL_SHEPARD_DEFAULT_SEARCH_RADIUS, float smoothing=__PCL_SHEPARD_DEFAULT_REGULARIZATION)
PointShepardInterpolation(PointShepardInterpolation &&)=default
Two-dimensional surface interpolation with the local Shepard method.
void Evaluate(T1 *Z, const T1 *X, const T1 *Y, size_type n) const
bool HasFastVectorEvaluation() const
virtual ~ShepardInterpolation()
ShepardInterpolation(const ShepardInterpolation &)=delete
ShepardInterpolation(ShepardInterpolation &&)=default
void DoInitialize(const search_rect *rect, const T *x, const T *y, const T *z, int n)
typename vector_type::scalar scalar
ShepardInterpolation()=default
typename search_tree::rectangle search_rect
void Initialize(const search_rect &rect, const T *x, const T *y, const T *z, int n)
void Initialize(const T *x, const T *y, const T *z, int n)
void SetSmoothing(float r)
Complex< T > Sqrt(const Complex< T > &c) noexcept
T Abs(const Complex< T > &c) noexcept
T PowI(T x, int n) noexcept
int TruncInt(T x) noexcept
constexpr const T & Min(const T &a, const T &b) noexcept