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 );
394 T operator ()(
double x,
double y )
const
396 PCL_PRECONDITION( !m_T.IsEmpty() )
398 const double dx = m_r0*(x - m_x0);
399 const double dy = m_r0*(y - m_y0);
401 for (
double R = m_R; ; R += m_R )
406 m_T.Search(
DRect( dx-R, dy-R, dx+R, dy+R ),
409 double x = dx - v[0];
410 double y = dy - v[1];
411 double r2 = x*x + y*y;
415 double w =
PowI( 1 -
Sqrt( r2 )/R, m_mu );
436 int r =
Min(
TruncInt( m_r * m ), (m >> 1) - (m & 1)^1 );
443 for (
int i = 0; i < r; ++i )
446 V[m-i-1].y = V[m-r-1].y;
451 for (
const DPoint& v : V )
454 return T( Wz.
y/Wz.
x );
468 template <
typename Tp>
471 return operator ()(
double( p.
x ),
double( p.
y ) );
488 int m_mu = __PCL_SHEPARD_DEFAULT_POWER;
489 double m_R = __PCL_SHEPARD_DEFAULT_SEARCH_RADIUS;
490 float m_r = __PCL_SHEPARD_DEFAULT_REGULARIZATION;
500 PCL_PRECONDITION( x !=
nullptr && y !=
nullptr && z !=
nullptr )
501 PCL_PRECONDITION( n > 2 )
504 throw Error(
"ShepardInterpolation::Initialize(): At least three input nodes must be specified." );
510 if ( rect ==
nullptr )
516 for (
int i = 0; i < n; ++i )
528 for (
int i = 0; i < n; ++i )
530 double dx = x[i] - m_x0;
531 double dy = y[i] - m_y0;
532 double r =
Sqrt( dx*dx + dy*dy );
539 m_x0 = rect->CenterX();
540 m_y0 = rect->CenterY();
541 m_r0 = rect->Diagonal()/2;
545 throw Error(
"ShepardInterpolation::Initialize(): Empty or insignificant interpolation space." );
552 for (
int i = 0; i < n; ++i )
553 V <<
vector_type( m_r0*(x[i] - m_x0), m_r0*(y[i] - m_y0), z[i] );
562 return (p[0] != q[0]) ? p[0] < q[0] : p[1] < q[1];
565 for (
int i = 0, j = 1; j < n; ++i, ++j )
566 if (
Abs( V[i][0] - V[j][0] ) <= std::numeric_limits<T>::epsilon() )
567 if (
Abs( V[i][1] - V[j][1] ) <= std::numeric_limits<T>::epsilon() )
573 for (
int j : remove )
581 if ( U.Length() < 3 )
582 throw Error(
"ShepardInterpolation::Initialize(): Less than three input nodes left after sanitization." );
589 if ( rect ==
nullptr )
590 m_T.Build( V, BucketCapacity );
593 m_T.Build( *rect, V, BucketCapacity );
594 if ( m_T.Length() < 3 )
595 throw Error(
"ShepardInterpolation::Initialize(): Less than three input nodes in the specified search region." );
619 template <
class P = DPo
int>
663 int power = __PCL_SHEPARD_DEFAULT_POWER,
664 double radius = __PCL_SHEPARD_DEFAULT_SEARCH_RADIUS )
666 Initialize( P1, P2, power, radius );
678 Initialize( Sx, Sy );
726 int power = __PCL_SHEPARD_DEFAULT_POWER,
727 double radius = __PCL_SHEPARD_DEFAULT_SEARCH_RADIUS,
728 float smoothing = __PCL_SHEPARD_DEFAULT_REGULARIZATION )
730 PCL_PRECONDITION( P1.
Length() >= 3 )
732 PCL_PRECONDITION( power > 0 )
733 PCL_PRECONDITION( radius > 0 )
734 PCL_PRECONDITION( smoothing >= 0 && smoothing < 1 )
739 m_Sx.SetPower( power );
740 m_Sy.SetPower( power );
742 m_Sx.SetRadius( radius );
743 m_Sy.SetRadius( radius );
745 m_Sx.SetSmoothing( smoothing );
746 m_Sy.SetSmoothing( smoothing );
749 throw Error(
"PointShepardInterpolation::Initialize(): At least three input nodes must be specified." );
752 throw Error(
"PointShepardInterpolation::Initialize(): Incompatible point array lengths." );
758 for (
int i = 0; i < X.Length(); ++i )
765 m_Sx.Initialize( X.Begin(), Y.Begin(), Zx.Begin(), X.Length() );
766 m_Sy.Initialize( X.Begin(), Y.Begin(), Zy.
Begin(), X.Length() );
785 return m_Sx.IsValid() && m_Sy.IsValid();
809 template <
typename T>
812 return DPoint( m_Sx( x, y ), m_Sy( x, y ) );
818 template <
typename T>
821 return operator ()( p.
x, p.
y );
832 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
const surface & SurfaceY() 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.
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