58 #include <pcl/Diagnostics.h>
60 #include <pcl/Memory.h>
73 #if defined( __x86_64__ ) || defined( _M_X64 ) || defined( __PCL_MACOSX )
74 # define __PCL_HAVE_SSE2 1
75 # include <emmintrin.h>
86 #if !defined( _MSC_VER ) && !defined( __clang__ ) && defined( __GNUC__ )
87 # define __PCL_HAVE_SINCOS 1
90 #ifdef __PCL_QT_INTERFACE
91 # include <QtWidgets/QtWidgets>
98 #define __PCL_MEDIAN_HISTOGRAM_LENGTH 8192
134 __cpuid( cpuInfo, 1 );
135 edxFlags = cpuInfo[3];
136 ecxFlags = cpuInfo[2];
138 asm volatile(
"mov $0x00000001, %%eax\n\t"
142 :
"=r" (edxFlags),
"=r" (ecxFlags)
144 :
"%eax",
"%ebx",
"%ecx",
"%edx" );
147 if ( ecxFlags & (1u << 20) )
149 if ( ecxFlags & (1u << 19) )
153 if ( edxFlags & (1u << 26) )
155 if ( edxFlags & (1u << 25) )
166 #define __PCL_FLOAT_SGNMASK 0x80000000
167 #define __PCL_FLOAT_EXPMASK 0x7f800000
168 #define __PCL_FLOAT_SIGMASK 0x007fffff
180 union {
float f;
uint32 u; } v = { x };
181 return (v.u & __PCL_FLOAT_EXPMASK) != __PCL_FLOAT_EXPMASK;
194 inline bool IsNaN(
float x ) noexcept
196 union {
float f;
uint32 u; } v = { x };
197 return (v.u & __PCL_FLOAT_EXPMASK) == __PCL_FLOAT_EXPMASK &&
198 (v.u & __PCL_FLOAT_SIGMASK) != 0;
218 union {
float f;
uint32 u; } v = { x };
219 if ( (v.u & __PCL_FLOAT_EXPMASK) == __PCL_FLOAT_EXPMASK &&
220 (v.u & __PCL_FLOAT_SIGMASK) == 0 )
221 return ((v.u & __PCL_FLOAT_SGNMASK) == 0) ? +1 : -1;
233 union {
float f;
uint32 u; } v = { x };
234 return v.u == __PCL_FLOAT_SGNMASK;
237 #define __PCL_DOUBLE_SGNMASK 0x80000000
238 #define __PCL_DOUBLE_EXPMASK 0x7ff00000
239 #define __PCL_DOUBLE_SIGMASK 0x000fffff
251 union {
double d;
uint32 u[2]; } v = { x };
252 return (v.u[1] & __PCL_DOUBLE_EXPMASK) != __PCL_DOUBLE_EXPMASK;
265 inline bool IsNaN(
double x ) noexcept
267 union {
double d;
uint32 u[2]; } v = { x };
268 return (v.u[1] & __PCL_DOUBLE_EXPMASK) == __PCL_DOUBLE_EXPMASK &&
269 (v.u[0] != 0 || (v.u[1] & __PCL_DOUBLE_SIGMASK) != 0);
289 union {
double d;
uint32 u[2]; } v = { x };
291 (v.u[1] & __PCL_DOUBLE_SIGMASK) == 0 &&
292 (v.u[1] & __PCL_DOUBLE_EXPMASK) == __PCL_DOUBLE_EXPMASK )
293 return ((v.u[1] & __PCL_DOUBLE_SGNMASK) == 0) ? +1 : -1;
305 union {
double d;
uint32 u[2]; } v = { x };
306 return v.u[1] == __PCL_DOUBLE_SGNMASK &&
320 inline float Abs(
float x ) noexcept
322 return std::fabs( x );
328 inline double Abs(
double x ) noexcept
330 return std::fabs( x );
336 inline long double Abs(
long double x ) noexcept
338 return std::fabs( x );
344 inline signed int Abs(
signed int x ) noexcept
352 #if defined( __PCL_MACOSX ) && defined( __clang__ )
353 _Pragma(
"clang diagnostic push")
354 _Pragma("clang diagnostic ignored \"-Wabsolute-value\"")
356 inline signed long Abs(
signed long x ) noexcept
360 #if defined( __PCL_MACOSX ) && defined( __clang__ )
361 _Pragma(
"clang diagnostic pop")
367 #if defined( _MSC_VER )
368 inline __int64
Abs( __int64 x ) noexcept
370 return (x < 0) ? -x : +x;
372 #elif defined( __PCL_MACOSX ) && defined( __clang__ )
373 inline constexpr
signed long long Abs(
signed long long x ) noexcept
375 return (x < 0) ? -x : +x;
378 inline signed long long Abs(
signed long long x ) noexcept
387 inline signed short Abs(
signed short x ) noexcept
389 return (
signed short)::abs(
int( x ) );
395 inline signed char Abs(
signed char x ) noexcept
397 return (
signed char)::abs(
int( x ) );
403 inline wchar_t Abs(
wchar_t x ) noexcept
405 return (
wchar_t)::abs(
int( x ) );
411 inline constexpr
unsigned int Abs(
unsigned int x ) noexcept
419 inline constexpr
unsigned long Abs(
unsigned long x ) noexcept
428 inline unsigned __int64
Abs(
unsigned __int64 x ) noexcept
433 inline constexpr
unsigned long long Abs(
unsigned long long x ) noexcept
442 inline constexpr
unsigned short Abs(
unsigned short x ) noexcept
450 inline constexpr
unsigned char Abs(
unsigned char x ) noexcept
461 inline constexpr
long double Pi() noexcept
463 return (
long double)( 0.31415926535897932384626433832795029e+01L );
470 inline constexpr
long double TwoPi() noexcept
472 return (
long double)( 0.62831853071795864769252867665590058e+01L );
481 template <
typename T>
inline constexpr T
Angle(
int d, T m ) noexcept
491 template <
typename T>
inline constexpr T
Angle(
int d,
int m, T s ) noexcept
493 return Angle( d, m + s/60 );
502 template <
typename T>
inline constexpr T
ArcCos( T x ) noexcept
504 PCL_PRECONDITION( T( -1 ) <= x && x <= T( 1 ) )
505 return std::acos( x );
514 template <
typename T>
inline constexpr T
ArcSin( T x ) noexcept
516 PCL_PRECONDITION( T( -1 ) <= x && x <= T( 1 ) )
517 return std::asin( x );
526 template <
typename T>
inline constexpr T
ArcTan( T x ) noexcept
528 return std::atan( x );
537 template <
typename T>
inline constexpr T
ArcTan( T y, T x ) noexcept
539 return std::atan2( y, x );
548 template <
typename T>
inline T
ArcTan2Pi( T y, T x ) noexcept
552 r =
static_cast<T
>( r +
TwoPi() );
562 template <
typename T>
inline constexpr T
Ceil( T x ) noexcept
564 return std::ceil( x );
573 template <
typename T>
inline constexpr T
Cos( T x ) noexcept
575 return std::cos( x );
584 template <
typename T>
inline constexpr T
Cosh( T x ) noexcept
586 return std::cosh( x );
595 template <
typename T>
inline constexpr T
Cotan( T x ) noexcept
597 return T( 1 )/std::tan( x );
606 template <
typename T>
inline constexpr T
Deg( T x ) noexcept
608 return static_cast<T
>( 0.572957795130823208767981548141051700441964e+02L * x );
617 template <
typename T>
inline constexpr T
Exp( T x ) noexcept
619 return std::exp( x );
628 template <
typename T>
inline constexpr T
Floor( T x ) noexcept
630 return std::floor( x );
640 template <
typename T>
inline constexpr T
Frac( T x ) noexcept
642 return std::modf( x, &x );
653 template <
typename T>
inline void Frexp( T x, T& m,
int& p ) noexcept
655 m = std::frexp( x, &p );
669 template <
typename T>
inline constexpr T
Hav( T x ) noexcept
671 return (1 -
Cos( x ))/2;
680 template <
typename T>
inline constexpr T
Ldexp( T m,
int p ) noexcept
682 return std::ldexp( m, p );
691 template <
typename T>
inline constexpr T
Ln( T x ) noexcept
693 PCL_PRECONDITION( x >= 0 )
694 return std::log( x );
699 struct PCL_CLASS FactorialCache
701 constexpr
static int s_cacheSize = 127;
702 static const double s_lut[ s_cacheSize+1 ];
714 PCL_PRECONDITION( n >= 0 )
715 if ( n <= FactorialCache::s_cacheSize )
716 return FactorialCache::s_lut[n];
717 double x = FactorialCache::s_lut[FactorialCache::s_cacheSize];
718 for (
int m = FactorialCache::s_cacheSize; ++m <= n; )
734 PCL_PRECONDITION( n >= 0 )
735 if ( n <= FactorialCache::s_cacheSize )
736 return Ln( FactorialCache::s_lut[n] );
739 return (x - 0.5)*
Ln( x ) - x + 0.91893853320467267 + 1/12/x - 1/(360*x*x*x);
760 template <
typename T>
struct PCL_CLASS
Fact :
public FactorialCache
765 T operator()(
int n )
const noexcept
767 PCL_PRECONDITION( n >= 0 )
768 if ( n <= s_cacheSize )
769 return T( s_lut[n] );
770 double x = s_lut[s_cacheSize];
771 for (
int m = s_cacheSize; ++m <= n; )
782 T
Ln(
int n )
const noexcept
784 PCL_PRECONDITION( n >= 0 )
785 if ( n <= s_cacheSize )
786 return T(
pcl::Ln( s_lut[n] ) );
789 return T( (x - 0.5)*
pcl::Ln( x ) - x + 0.91893853320467267 + 1/12/x - 1/(360*x*x*x) );
799 inline constexpr
long double Ln2() noexcept
801 return (
long double)( 0.6931471805599453094172321214581766e+00L );
810 template <
typename T>
inline constexpr T
Log( T x ) noexcept
812 PCL_PRECONDITION( x >= 0 )
813 return std::log10( x );
822 inline constexpr
long double Log2() noexcept
826 return (
long double)( 0.3010299956639811952137388947244930416265e+00L );
835 template <
typename T>
inline constexpr T
Log2( T x ) noexcept
839 PCL_PRECONDITION( x >= 0 )
840 return std::log( x )/
Ln2();
849 inline constexpr
long double Log2e() noexcept
853 return (
long double)( 0.14426950408889634073599246810018920709799e+01L );
862 inline constexpr
long double Log2T() noexcept
866 return (
long double)( 0.33219280948873623478703194294893900118996e+01L );
875 template <
typename T>
inline constexpr T
LogN( T n, T x ) noexcept
877 PCL_PRECONDITION( x >= 0 )
878 return std::log( x )/std::log( n );
887 template <
typename T>
inline constexpr T
Mod( T x, T y ) noexcept
889 return std::fmod( x, y );
908 template <
typename T,
typename C>
inline T
Poly( T x, C c,
int n ) noexcept
910 PCL_PRECONDITION( n >= 0 )
912 for ( c += n, y = *c; n > 0; --n )
932 template <
typename T>
inline T
Poly( T x, std::initializer_list<T> c ) noexcept
934 PCL_PRECONDITION( c.size() > 0 )
935 return Poly( x, c.begin(),
int( c.size() )-1 );
951 template <
typename T>
inline constexpr
int Sign( T x ) noexcept
953 return (x < 0) ? -1 : ((x > 0) ? +1 : 0);
969 template <
typename T>
inline constexpr
char SignChar( T x ) noexcept
971 return (x < 0) ?
'-' : ((x > 0) ?
'+' :
' ');
980 template <
typename T>
inline constexpr T
Sin( T x ) noexcept
982 return std::sin( x );
991 template <
typename T>
inline constexpr T
Sinh( T x ) noexcept
993 return std::sinh( x );
998 #ifdef __PCL_HAVE_SINCOS
1000 inline void __pcl_sincos__(
float x,
float& sx,
float& cx ) noexcept
1002 ::sincosf( x, &sx, &cx );
1005 inline void __pcl_sincos__(
double x,
double& sx,
double& cx ) noexcept
1007 ::sincos( x, &sx, &cx );
1010 inline void __pcl_sincos__(
long double x,
long double& sx,
long double& cx ) noexcept
1012 ::sincosl( x, &sx, &cx );
1030 template <
typename T>
inline void SinCos( T x, T& sx, T& cx ) noexcept
1032 #ifdef __PCL_HAVE_SINCOS
1033 __pcl_sincos__( x, sx, cx );
1051 template <
typename T>
inline void Split( T x, T& i, T& f ) noexcept
1053 f = std::modf( x, &i );
1062 template <
typename T>
inline constexpr T
Sqrt( T x ) noexcept
1073 template <
typename T>
inline constexpr T
Tan( T x ) noexcept
1075 return std::tan( x );
1084 template <
typename T>
inline constexpr T
Tanh( T x ) noexcept
1086 return std::tanh( x );
1095 template <
typename T>
inline T
Trunc( T x ) noexcept
1097 (void)std::modf( x, &x );
1103 #ifdef __PCL_HAVE_SSE2
1105 inline int __pcl_trunci__(
float x ) noexcept
1107 return _mm_cvtt_ss2si( _mm_load_ss( &x ) );
1110 inline int __pcl_trunci__(
double x ) noexcept
1112 return _mm_cvttsd_si32( _mm_load_sd( &x ) );
1115 inline int __pcl_trunci__(
long double x ) noexcept
1132 template <
typename T>
inline int TruncInt( T x ) noexcept
1134 PCL_PRECONDITION( x >= int_min && x <= int_max )
1135 #ifdef __PCL_NO_PERFORMANCE_CRITICAL_MATH_ROUTINES
1138 # ifdef __PCL_HAVE_SSE2
1139 return __pcl_trunci__( x );
1154 template <
typename T>
inline int TruncI( T x ) noexcept
1159 #define TruncInt32( x ) TruncInt( x )
1160 #define TruncI32( x ) TruncInt( x )
1164 #ifdef __PCL_HAVE_SSE2
1166 #if defined( __x86_64__ ) || defined( _M_X64 )
1168 inline int64 __pcl_trunci64__(
float x ) noexcept
1170 return _mm_cvttss_si64( _mm_load_ss( &x ) );
1173 inline int64 __pcl_trunci64__(
double x ) noexcept
1175 return _mm_cvttsd_si64( _mm_load_sd( &x ) );
1180 inline int64 __pcl_trunci64__(
float x ) noexcept
1182 return int64( _mm_cvtt_ss2si( _mm_load_ss( &x ) ) );
1185 inline int64 __pcl_trunci64__(
double x ) noexcept
1192 inline int64 __pcl_trunci64__(
long double x ) noexcept
1212 #ifdef __PCL_NO_PERFORMANCE_CRITICAL_MATH_ROUTINES
1215 # ifdef __PCL_HAVE_SSE2
1216 return __pcl_trunci64__( x );
1251 template <
typename T>
inline constexpr T
Pow( T x, T y ) noexcept
1253 PCL_PRECONDITION( y < T( int_max ) )
1254 return std::pow( x, y );
1269 template <
typename T>
struct PCL_CLASS
Pow10I
1271 T operator ()(
int n )
const noexcept
1274 static const T lut[] =
1276 #define ___( x ) static_cast<T>( x )
1277 ___( 1.0e+00 ), ___( 1.0e+01 ), ___( 1.0e+02 ), ___( 1.0e+03 ), ___( 1.0e+04 ),
1278 ___( 1.0e+05 ), ___( 1.0e+06 ), ___( 1.0e+07 ), ___( 1.0e+08 ), ___( 1.0e+09 ),
1279 ___( 1.0e+10 ), ___( 1.0e+11 ), ___( 1.0e+12 ), ___( 1.0e+13 ), ___( 1.0e+14 ),
1280 ___( 1.0e+15 ), ___( 1.0e+16 ), ___( 1.0e+17 ), ___( 1.0e+18 ), ___( 1.0e+19 ),
1281 ___( 1.0e+20 ), ___( 1.0e+21 ), ___( 1.0e+22 ), ___( 1.0e+23 ), ___( 1.0e+24 ),
1282 ___( 1.0e+25 ), ___( 1.0e+26 ), ___( 1.0e+27 ), ___( 1.0e+28 ), ___( 1.0e+29 ),
1283 ___( 1.0e+30 ), ___( 1.0e+31 ), ___( 1.0e+32 ), ___( 1.0e+33 ), ___( 1.0e+34 ),
1284 ___( 1.0e+35 ), ___( 1.0e+36 ), ___( 1.0e+37 ), ___( 1.0e+38 ), ___( 1.0e+39 ),
1285 ___( 1.0e+40 ), ___( 1.0e+41 ), ___( 1.0e+42 ), ___( 1.0e+43 ), ___( 1.0e+44 ),
1286 ___( 1.0e+45 ), ___( 1.0e+46 ), ___( 1.0e+47 ), ___( 1.0e+48 ), ___( 1.0e+49 )
1297 while ( (i -= N-1) >= N )
1302 return T( (n >= 0) ? x : 1/x );
1312 template <
typename T>
inline T
Pow10( T x ) noexcept
1315 return (i == x) ?
Pow10I<T>()( i ) : T( std::pow( 10, x ) );
1332 static_assert( std::is_unsigned<T>::value,
1333 "RotL() can only be used for unsigned integer scalar types" );
1334 const uint8 mask = 8*
sizeof( x ) - 1;
1336 return (x << r) | (x >> ((-r) & mask));
1353 static_assert( std::is_unsigned<T>::value,
1354 "RotR() can only be used for unsigned integer scalar types" );
1355 const uint8 mask = 8*
sizeof( x ) - 1;
1357 return (x >> r) | (x << ((-r) & mask));
1373 inline double Round(
double x ) noexcept
1375 #ifdef __PCL_NO_PERFORMANCE_CRITICAL_MATH_ROUTINES
1377 return floor( x + 0.5 );
1383 return double( _mm_cvtsd_si64( _mm_load_sd( &x ) ) );
1390 asm volatile(
"frndint\n":
"=t" (r) :
"0" (x) );
1408 #ifdef __PCL_NO_PERFORMANCE_CRITICAL_MATH_ROUTINES
1410 return floorf( x + 0.5F );
1416 return float( _mm_cvtss_si32( _mm_load_ss( &x ) ) );
1423 asm volatile(
"frndint\n":
"=t" (r) :
"0" (x) );
1439 inline long double Round(
long double x ) noexcept
1441 #ifdef __PCL_NO_PERFORMANCE_CRITICAL_MATH_ROUTINES
1443 return floorl( x + 0.5L );
1450 return (
long double)_mm_cvtsd_si64( _mm_load_sd( &_x ) );
1457 asm volatile(
"frndint\n":
"=t" (r) :
"0" (x) );
1503 template <
typename T>
inline int RoundInt( T x ) noexcept
1505 PCL_PRECONDITION( x >= int_min && x <= int_max )
1507 #ifdef __PCL_NO_PERFORMANCE_CRITICAL_MATH_ROUTINES
1509 return int(
Round( x ) );
1513 volatile union {
double d;
int32 i; } v = { x + 6755399441055744.0 };
1544 template <
typename T>
inline int RoundI( T x ) noexcept
1588 PCL_PRECONDITION( x >= int_min && x <= int_max )
1593 if ( x - i <= T( -0.5 ) )
1598 if ( x - i >= T( +0.5 ) )
1622 #ifdef __PCL_NO_PERFORMANCE_CRITICAL_MATH_ROUTINES
1632 return _mm_cvtsd_si64( _mm_load_sd( &x ) );
1636 __asm fistp qword ptr r
1641 asm volatile(
"fistpll %0\n" :
"=m" (r) :
"t" (x) :
"st" );
1688 if ( x - i <= -0.5 )
1693 if ( x - i >= +0.5 )
1705 template <
typename T>
inline T
Round( T x,
int n ) noexcept
1707 PCL_PRECONDITION( n >= 0 )
1717 template <
typename T>
inline constexpr T
Pow2( T x ) noexcept
1736 template <
typename T>
struct PCL_CLASS
Pow2I
1738 T operator ()(
int n )
const noexcept
1741 int i = ::abs( n ), p;
1742 double x =
uint32( 1 ) << (p =
Min( i, 31 ));
1743 while ( (i -= p) != 0 )
1745 return T( (n >= 0) ? x : 1/x );
1755 template <
typename T>
inline T
PowI( T x,
int n ) noexcept
1766 while ( (i >>= 1) > 1 );
1770 return (n > 0) ? r : T( 1/r );
1777 template <
typename T>
inline T
PowI4( T x ) noexcept
1786 template <
typename T>
inline T
PowI6( T x ) noexcept
1788 x *= x*x;
return x*x;
1795 template <
typename T>
inline T
PowI8( T x ) noexcept
1797 x *= x*x*x;
return x*x;
1804 template <
typename T>
inline T
PowI10( T x ) noexcept
1806 x *= x*x*x*x;
return x*x;
1813 template <
typename T>
inline T
PowI12( T x ) noexcept
1815 x *= x*x*x*x*x;
return x*x;
1827 template <
typename T>
inline constexpr T
ArcSinh( T x ) noexcept
1829 #ifndef __PCL_NO_STD_INV_HYP_TRIG_FUNCTIONS
1830 return std::asinh( x );
1832 return Ln( x +
Sqrt( 1 + x*x ) );
1845 template <
typename T>
inline constexpr T
ArcCosh( T x ) noexcept
1847 #ifndef __PCL_NO_STD_INV_HYP_TRIG_FUNCTIONS
1848 return std::acosh( x );
1850 return 2*
Ln(
Sqrt( (x + 1)/2 ) +
Sqrt( (x - 1)/2 ) );
1863 template <
typename T>
inline constexpr T
ArcTanh( T x ) noexcept
1865 #ifndef __PCL_NO_STD_INV_HYP_TRIG_FUNCTIONS
1866 return std::atanh( x );
1868 return (
Ln( 1 + x ) -
Ln( 1 - x ))/2;
1883 template <
typename T>
inline constexpr T
ArcHav( T x ) noexcept
1894 template <
typename T>
inline constexpr T
Rad( T x ) noexcept
1896 return static_cast<T
>( 0.174532925199432957692369076848861272222e-01L * x );
1905 template <
typename T>
inline constexpr T
RadMin( T x ) noexcept
1916 template <
typename T>
inline constexpr T
RadSec( T x ) noexcept
1918 return Deg( x )*3600;
1927 template <
typename T>
inline constexpr T
MinRad( T x ) noexcept
1938 template <
typename T>
inline constexpr T
SecRad( T x ) noexcept
1940 return Rad( x/3600 );
1947 template <
typename T>
inline constexpr T
AsRad( T x ) noexcept
1958 template <
typename T>
inline constexpr T
MasRad( T x ) noexcept
1960 return Rad( x/3600000 );
1969 template <
typename T>
inline constexpr T
UasRad( T x ) noexcept
1971 return Rad( x/3600000000 );
1980 template <
typename T>
inline constexpr T
ModPi( T x ) noexcept
1982 x =
Mod( x +
static_cast<T
>(
Pi() ),
static_cast<T
>(
TwoPi() ) ) -
static_cast<T
>(
Pi() );
1983 return (x < -
static_cast<T
>(
Pi() )) ? x +
static_cast<T
>(
TwoPi() ) : x;
1993 template <
typename T>
inline constexpr T
Mod2Pi( T x ) noexcept
1995 return Mod( x,
static_cast<T
>(
TwoPi() ) );
2004 template <
typename T>
inline constexpr T
Norm2Pi( T x ) noexcept
2006 return ((x =
Mod2Pi( x )) < 0) ? x +
static_cast<T
>(
TwoPi() ) : x;
2023 template <
typename T,
typename T1,
typename T2>
2024 inline void Rotate( T& x, T& y, T1 sa, T1 ca, T2 xc, T2 yc ) noexcept
2026 T1 dx = T1( x ) - T1( xc );
2027 T1 dy = T1( y ) - T1( yc );
2028 x = T( T1( xc ) + ca*dx - sa*dy );
2029 y = T( T1( yc ) + sa*dx + ca*dy );
2042 template <
typename T1,
typename T2>
2043 inline void Rotate(
int& x,
int& y, T1 sa, T1 ca, T2 xc, T2 yc ) noexcept
2045 T1 dx = T1( x ) - T1( xc );
2046 T1 dy = T1( y ) - T1( yc );
2047 x =
RoundInt( T1( xc ) + ca*dx - sa*dy );
2048 y =
RoundInt( T1( yc ) + sa*dx + ca*dy );
2061 template <
typename T1,
typename T2>
2062 inline void Rotate(
long& x,
long& y, T1 sa, T1 ca, T2 xc, T2 yc ) noexcept
2064 T1 dx = T1( x ) - T1( xc );
2065 T1 dy = T1( y ) - T1( yc );
2066 x = (long)
RoundInt( T1( xc ) + ca*dx - sa*dy );
2067 y = (long)
RoundInt( T1( yc ) + sa*dx + ca*dy );
2080 template <
typename T1,
typename T2>
2083 T1 dx = T1( x ) - T1( xc );
2084 T1 dy = T1( y ) - T1( yc );
2104 template <
typename T,
typename T1,
typename T2>
2105 inline void Rotate( T& x, T& y, T1 a, T2 xc, T2 yc ) noexcept
2107 T1 sa, ca;
SinCos( a, sa, ca );
Rotate( x, y, sa, ca, xc, yc );
2112 template <
typename T,
typename P,
typename N>
inline
2113 N __pcl_norm__(
const T* i,
const T* j,
const P& p, N* ) noexcept
2115 PCL_PRECONDITION( p > P( 0 ) )
2117 for ( ; i < j; ++i )
2118 n +=
Pow(
Abs( N( *i ) ), N( p ) );
2119 return
Pow( n, N( 1/p ) );
2135 template <typename T, typename P> inline T
Norm( const T* i, const T* j, const P& p ) noexcept
2137 return __pcl_norm__( i, j, p, (T*)( 0 ) );
2140 template <
typename P>
inline double Norm(
const float* i,
const float* j,
const P& p ) noexcept
2142 return __pcl_norm__( i, j, p, (
double*)( 0 ) );
2144 template <
typename P>
inline double Norm(
const int* i,
const int* j,
const P& p ) noexcept
2146 return __pcl_norm__( i, j, p, (
double*)( 0 ) );
2148 template <
typename P>
inline double Norm(
const unsigned* i,
const unsigned* j,
const P& p ) noexcept
2150 return __pcl_norm__( i, j, p, (
double*)( 0 ) );
2152 template <
typename P>
inline double Norm(
const int8* i,
const int8* j,
const P& p ) noexcept
2154 return __pcl_norm__( i, j, p, (
double*)( 0 ) );
2156 template <
typename P>
inline double Norm(
const uint8* i,
const uint8* j,
const P& p ) noexcept
2158 return __pcl_norm__( i, j, p, (
double*)( 0 ) );
2160 template <
typename P>
inline double Norm(
const int16* i,
const int16* j,
const P& p ) noexcept
2162 return __pcl_norm__( i, j, p, (
double*)( 0 ) );
2164 template <
typename P>
inline double Norm(
const uint16* i,
const uint16* j,
const P& p ) noexcept
2166 return __pcl_norm__( i, j, p, (
double*)( 0 ) );
2168 template <
typename P>
inline double Norm(
const int64* i,
const int64* j,
const P& p ) noexcept
2170 return __pcl_norm__( i, j, p, (
double*)( 0 ) );
2172 template <
typename P>
inline double Norm(
const uint64* i,
const uint64* j,
const P& p ) noexcept
2174 return __pcl_norm__( i, j, p, (
double*)( 0 ) );
2179 template <
typename T,
typename N>
inline
2180 N __pcl_l1norm__(
const T* i,
const T* j, N* ) noexcept
2183 for ( ; i < j; ++i )
2184 n += N(
Abs( *i ) );
2194 template <
typename T>
inline T
L1Norm(
const T* i,
const T* j ) noexcept
2196 return __pcl_l1norm__( i, j, (T*)( 0 ) );
2199 inline double L1Norm(
const float* i,
const float* j ) noexcept
2201 return __pcl_l1norm__( i, j, (
double*)( 0 ) );
2203 inline double L1Norm(
const int* i,
const int* j ) noexcept
2205 return __pcl_l1norm__( i, j, (
double*)( 0 ) );
2207 inline double L1Norm(
const unsigned* i,
const unsigned* j ) noexcept
2209 return __pcl_l1norm__( i, j, (
double*)( 0 ) );
2213 return __pcl_l1norm__( i, j, (
double*)( 0 ) );
2217 return __pcl_l1norm__( i, j, (
double*)( 0 ) );
2221 return __pcl_l1norm__( i, j, (
double*)( 0 ) );
2225 return __pcl_l1norm__( i, j, (
double*)( 0 ) );
2229 return __pcl_l1norm__( i, j, (
double*)( 0 ) );
2233 return __pcl_l1norm__( i, j, (
double*)( 0 ) );
2238 template <
typename T,
typename N>
inline
2239 N __pcl_l2norm__(
const T* i,
const T* j, N* ) noexcept
2242 for ( ; i < j; ++i )
2243 n += N( *i ) * N( *i );
2253 template <
typename T>
inline T
L2Norm(
const T* i,
const T* j ) noexcept
2255 return __pcl_l2norm__( i, j, (T*)( 0 ) );
2258 inline double L2Norm(
const float* i,
const float* j ) noexcept
2260 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2262 inline double L2Norm(
const int* i,
const int* j ) noexcept
2264 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2266 inline double L2Norm(
const unsigned* i,
const unsigned* j ) noexcept
2268 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2272 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2276 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2280 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2284 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2288 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2292 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2303 template <
typename T>
inline T
Norm(
const T* i,
const T* j ) noexcept
2308 inline double Norm(
const float* i,
const float* j ) noexcept
2310 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2312 inline double Norm(
const int* i,
const int* j ) noexcept
2314 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2316 inline double Norm(
const unsigned* i,
const unsigned* j ) noexcept
2318 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2320 inline double Norm(
const int8* i,
const int8* j ) noexcept
2322 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2326 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2330 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2334 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2338 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2342 return __pcl_l2norm__( i, j, (
double*)( 0 ) );
2387 void PCL_FUNC
CalendarTimeToJD(
int& jdi,
double& jdf,
int year,
int month,
int day,
double dayf = 0 ) noexcept;
2466 void PCL_FUNC
JDToCalendarTime(
int& year,
int& month,
int& day,
double& dayf,
int jdi,
double jdf ) noexcept;
2497 inline void JDToCalendarTime(
int& year,
int& month,
int& day,
double& dayf,
double jd ) noexcept
2524 template <
typename S1,
typename S2,
typename S3,
typename D>
2527 double t1 =
Abs( d );
2528 double t2 =
Frac( t1 )*60;
2529 double t3 =
Frac( t2 )*60;
2530 sign = (d < 0) ? -1 : +1;
2546 template <
typename S1,
typename S2,
typename S3>
2547 inline double SexagesimalToDecimal(
int sign,
const S1& s1,
const S2& s2 = S2( 0 ),
const S3& s3 = S3( 0 ) ) noexcept
2549 double d =
Abs( s1 ) + (s2 + s3/60)/60;
2550 return (sign < 0) ? -d : d;
2573 template <
typename T>
inline double Sum(
const T* __restrict__ i,
const T* __restrict__ j ) noexcept
2577 sum += double( *i++ );
2592 template <
typename T>
inline double StableSum(
const T* __restrict__ i,
const T* __restrict__ j ) noexcept
2598 double y = double( *i++ ) - eps;
2600 eps = (t - sum) - y;
2617 template <
typename T>
inline double Modulus(
const T* __restrict__ i,
const T* __restrict__ j ) noexcept
2621 S +=
Abs(
double( *i++ ) );
2636 template <
typename T>
inline double StableModulus(
const T* __restrict__ i,
const T* __restrict__ j ) noexcept
2642 double y =
Abs(
double( *i++ ) ) - eps;
2644 eps = (t - sum) - y;
2661 template <
typename T>
inline double SumOfSquares(
const T* __restrict__ i,
const T* __restrict__ j ) noexcept
2666 double f = double( *i++ );
2683 template <
typename T>
inline double StableSumOfSquares(
const T* __restrict__ i,
const T* __restrict__ j ) noexcept
2689 double f = double( *i++ );
2690 double y = f*f - eps;
2692 eps = (t - sum) - y;
2709 template <
typename T>
inline double Mean(
const T* __restrict__ i,
const T* __restrict__ j ) noexcept
2714 return Sum( i, j )/n;
2728 template <
typename T>
inline double StableMean(
const T* __restrict__ i,
const T* __restrict__ j ) noexcept
2753 template <
typename T>
inline double Variance(
const T* __restrict__ i,
const T* __restrict__ j,
double center ) noexcept
2758 double var = 0, eps = 0;
2761 double d = double( *i++ ) - center;
2766 return (var - eps*eps/n)/(n - 1);
2785 template <
typename T>
inline double Variance(
const T* __restrict__ i,
const T* __restrict__ j ) noexcept
2791 for (
const T* f = i; f < j; ++f )
2794 double var = 0, eps = 0;
2797 double d = double( *i++ ) - m;
2802 return (var - eps*eps/n)/(n - 1);
2813 template <
typename T>
inline double StdDev(
const T* __restrict__ i,
const T* __restrict__ j,
double center ) noexcept
2825 template <
typename T>
inline double StdDev(
const T* __restrict__ i,
const T* __restrict__ j ) noexcept
2878 template <
class T>
inline double Median(
const T* __restrict__ i,
const T* __restrict__ j )
2884 return double( *i );
2885 double* d =
new double[ n ];
2886 double* __restrict__ t = d;
2888 *t++ = double( *i++ );
2890 double m = double( *
pcl::Select( d, t, n >> 1 ) );
2892 m = (m + double( *
pcl::Select( d, t, (n >> 1)-1 ) ))/2;
2897 double PCL_FUNC
Median(
const unsigned char* __restrict__ i,
const unsigned char* __restrict__ j );
2898 double PCL_FUNC
Median(
const signed char* __restrict__ i,
const signed char* __restrict__ j );
2899 double PCL_FUNC
Median(
const wchar_t* __restrict__ i,
const wchar_t* __restrict__ j );
2900 double PCL_FUNC
Median(
const unsigned short* __restrict__ i,
const unsigned short* __restrict__ j );
2901 double PCL_FUNC
Median(
const signed short* __restrict__ i,
const signed short* __restrict__ j );
2902 double PCL_FUNC
Median(
const unsigned int* __restrict__ i,
const unsigned int* __restrict__ j );
2903 double PCL_FUNC
Median(
const signed int* __restrict__ i,
const signed int* __restrict__ j );
2904 double PCL_FUNC
Median(
const unsigned long* __restrict__ i,
const unsigned long* __restrict__ j );
2905 double PCL_FUNC
Median(
const signed long* __restrict__ i,
const signed long* __restrict__ j );
2906 double PCL_FUNC
Median(
const unsigned long long* __restrict__ i,
const unsigned long long* __restrict__ j );
2907 double PCL_FUNC
Median(
const signed long long* __restrict__ i,
const signed long long* __restrict__ j );
2908 double PCL_FUNC
Median(
const float* __restrict__ i,
const float* __restrict__ j );
2909 double PCL_FUNC
Median(
const double* __restrict__ i,
const double* __restrict__ j );
2910 double PCL_FUNC
Median(
const long double* __restrict__ i,
const long double* __restrict__ j );
2912 #define CMPXCHG( a, b ) \
2913 if ( i[b] < i[a] ) pcl::Swap( i[a], i[b] )
2915 #define MEAN( a, b ) \
2916 (double( a ) + double( b ))/2
2960 template <
typename T>
inline double MedianDestructive( T* __restrict__ i, T* __restrict__ j ) noexcept
2971 return MEAN( i[0], i[1] );
2973 CMPXCHG( 0, 1 ); CMPXCHG( 1, 2 );
2976 CMPXCHG( 0, 1 ); CMPXCHG( 2, 3 ); CMPXCHG( 0, 2 );
2978 return MEAN( i[1], i[2] );
2980 CMPXCHG( 0, 1 ); CMPXCHG( 3, 4 ); CMPXCHG( 0, 3 );
2981 CMPXCHG( 1, 4 ); CMPXCHG( 1, 2 ); CMPXCHG( 2, 3 );
2984 CMPXCHG( 0, 1 ); CMPXCHG( 2, 3 ); CMPXCHG( 0, 2 );
2985 CMPXCHG( 1, 3 ); CMPXCHG( 1, 2 ); CMPXCHG( 4, 5 );
2986 CMPXCHG( 0, 4 ); CMPXCHG( 1, 5 ); CMPXCHG( 1, 4 );
2987 CMPXCHG( 2, 4 ); CMPXCHG( 3, 5 ); CMPXCHG( 3, 4 );
2988 return MEAN( i[2], i[3] );
2990 CMPXCHG( 0, 5 ); CMPXCHG( 0, 3 ); CMPXCHG( 1, 6 );
2991 CMPXCHG( 2, 4 ); CMPXCHG( 0, 1 ); CMPXCHG( 3, 5 );
2992 CMPXCHG( 2, 6 ); CMPXCHG( 2, 3 ); CMPXCHG( 3, 6 );
2993 CMPXCHG( 4, 5 ); CMPXCHG( 1, 4 ); CMPXCHG( 1, 3 );
2996 CMPXCHG( 0, 4 ); CMPXCHG( 1, 5 ); CMPXCHG( 2, 6 );
2997 CMPXCHG( 3, 7 ); CMPXCHG( 0, 2 ); CMPXCHG( 1, 3 );
2998 CMPXCHG( 4, 6 ); CMPXCHG( 5, 7 ); CMPXCHG( 2, 4 );
2999 CMPXCHG( 3, 5 ); CMPXCHG( 0, 1 ); CMPXCHG( 2, 3 );
3000 CMPXCHG( 4, 5 ); CMPXCHG( 6, 7 ); CMPXCHG( 1, 4 );
3002 return MEAN( i[3], i[4] );
3004 CMPXCHG( 1, 2 ); CMPXCHG( 4, 5 ); CMPXCHG( 7, 8 );
3005 CMPXCHG( 0, 1 ); CMPXCHG( 3, 4 ); CMPXCHG( 6, 7 );
3006 CMPXCHG( 1, 2 ); CMPXCHG( 4, 5 ); CMPXCHG( 7, 8 );
3007 CMPXCHG( 0, 3 ); CMPXCHG( 5, 8 ); CMPXCHG( 4, 7 );
3008 CMPXCHG( 3, 6 ); CMPXCHG( 1, 4 ); CMPXCHG( 2, 5 );
3009 CMPXCHG( 4, 7 ); CMPXCHG( 4, 2 ); CMPXCHG( 6, 4 );
3013 double m = double( *
pcl::Select( i, j, n >> 1 ) );
3016 return MEAN( m,
double( *
pcl::Select( i, j, (n >> 1)-1 ) ) );
3023 #define CMPXCHG( a, b ) \
3024 if ( p( i[b], i[a] ) ) pcl::Swap( i[a], i[b] )
3041 template <
typename T,
class BP>
inline double MedianDestructive( T* __restrict__ i, T* __restrict__ j, BP p ) noexcept
3052 return MEAN( i[0], i[1] );
3054 CMPXCHG( 0, 1 ); CMPXCHG( 1, 2 );
3057 CMPXCHG( 0, 1 ); CMPXCHG( 2, 3 ); CMPXCHG( 0, 2 );
3059 return MEAN( i[1], i[2] );
3061 CMPXCHG( 0, 1 ); CMPXCHG( 3, 4 ); CMPXCHG( 0, 3 );
3062 CMPXCHG( 1, 4 ); CMPXCHG( 1, 2 ); CMPXCHG( 2, 3 );
3065 CMPXCHG( 0, 1 ); CMPXCHG( 2, 3 ); CMPXCHG( 0, 2 );
3066 CMPXCHG( 1, 3 ); CMPXCHG( 1, 2 ); CMPXCHG( 4, 5 );
3067 CMPXCHG( 0, 4 ); CMPXCHG( 1, 5 ); CMPXCHG( 1, 4 );
3068 CMPXCHG( 2, 4 ); CMPXCHG( 3, 5 ); CMPXCHG( 3, 4 );
3069 return MEAN( i[2], i[3] );
3071 CMPXCHG( 0, 5 ); CMPXCHG( 0, 3 ); CMPXCHG( 1, 6 );
3072 CMPXCHG( 2, 4 ); CMPXCHG( 0, 1 ); CMPXCHG( 3, 5 );
3073 CMPXCHG( 2, 6 ); CMPXCHG( 2, 3 ); CMPXCHG( 3, 6 );
3074 CMPXCHG( 4, 5 ); CMPXCHG( 1, 4 ); CMPXCHG( 1, 3 );
3077 CMPXCHG( 0, 4 ); CMPXCHG( 1, 5 ); CMPXCHG( 2, 6 );
3078 CMPXCHG( 3, 7 ); CMPXCHG( 0, 2 ); CMPXCHG( 1, 3 );
3079 CMPXCHG( 4, 6 ); CMPXCHG( 5, 7 ); CMPXCHG( 2, 4 );
3080 CMPXCHG( 3, 5 ); CMPXCHG( 0, 1 ); CMPXCHG( 2, 3 );
3081 CMPXCHG( 4, 5 ); CMPXCHG( 6, 7 ); CMPXCHG( 1, 4 );
3083 return MEAN( i[3], i[4] );
3085 CMPXCHG( 1, 2 ); CMPXCHG( 4, 5 ); CMPXCHG( 7, 8 );
3086 CMPXCHG( 0, 1 ); CMPXCHG( 3, 4 ); CMPXCHG( 6, 7 );
3087 CMPXCHG( 1, 2 ); CMPXCHG( 4, 5 ); CMPXCHG( 7, 8 );
3088 CMPXCHG( 0, 3 ); CMPXCHG( 5, 8 ); CMPXCHG( 4, 7 );
3089 CMPXCHG( 3, 6 ); CMPXCHG( 1, 4 ); CMPXCHG( 2, 5 );
3090 CMPXCHG( 4, 7 ); CMPXCHG( 4, 2 ); CMPXCHG( 6, 4 );
3094 double m = double( *
pcl::Select( i, j, n >> 1, p ) );
3097 return MEAN( m,
double( *
pcl::Select( i, j, (n >> 1)-1, p ) ) );
3141 if ( n < 1 || k < 0 || k >= n )
3144 return double( *i );
3145 double* d =
new double[ n ];
3148 *t++ = double( *i++ );
3164 double PCL_FUNC
OrderStatistic(
const unsigned long long* __restrict__ i,
const unsigned long long* __restrict__ j,
distance_type k );
3165 double PCL_FUNC
OrderStatistic(
const signed long long* __restrict__ i,
const signed long long* __restrict__ j,
distance_type k );
3200 if ( n < 1 || k < 0 || k >= n )
3203 return double( *i );
3222 if ( n < 1 || k < 0 || k >= n )
3225 return double( *i );
3248 return Sum( i, j )/n;
3255 double x = double( *i );
3260 return s/(n - l - h);
3287 return Sum( i, j )/n;
3294 double x = double( *i );
3299 return s/(n - l - h);
3325 return Sum( i, j )/n;
3332 double x = double( *i );
3337 return s/(n - l - h);
3368 return Sum( i, j )/n;
3375 double x = double( *i );
3380 return s/(n - l - h);
3404 template <
typename T>
inline double AvgDev(
const T* __restrict__ i,
const T* __restrict__ j,
double center ) noexcept
3411 d +=
Abs(
double( *i++ ) - center );
3436 template <
typename T>
inline double StableAvgDev(
const T* __restrict__ i,
const T* __restrict__ j,
double center ) noexcept
3445 double y =
Abs(
double( *i++ ) - center ) - eps;
3447 eps = (t - sum) - y;
3473 template <
typename T>
inline double AvgDev(
const T* __restrict__ i,
const T* __restrict__ j )
3478 double m =
Median( i, j );
3481 d +=
Abs(
double( *i++ ) - m );
3505 template <
typename T>
inline double StableAvgDev(
const T* __restrict__ i,
const T* __restrict__ j )
3560 template <
typename T1,
typename T2>
3562 :
low( double( l ) )
3563 ,
high( double( h ) )
3571 template <
typename T>
3585 return IsFinite(
low ) &&
low > std::numeric_limits<double>::epsilon()
3615 explicit operator double() const noexcept
3674 return {
low/e.low,
high/e.high };
3684 return {
Sqrt( e.low ),
Sqrt( e.high ) };
3693 double x_ = double( x );
3694 return {
Pow( e.low, x_ ),
Pow( e.high, x_ ) };
3719 double dl = 0, dh = 0;
3723 double x = double( *i++ );
3735 return { (nl > 1) ? dl/nl : 0.0,
3736 (nh > 1) ? dh/nh : 0.0 };
3776 template <
typename T>
inline double MAD(
const T* __restrict__ i,
const T* __restrict__ j,
double center )
3781 double* d =
new double[ n ];
3784 *p++ =
Abs(
double( *i++ ) - center );
3791 double PCL_FUNC
MAD(
const unsigned char* __restrict__ i,
const unsigned char* __restrict__ j,
double center );
3792 double PCL_FUNC
MAD(
const signed char* __restrict__ i,
const signed char* __restrict__ j,
double center );
3793 double PCL_FUNC
MAD(
const wchar_t* __restrict__ i,
const wchar_t* __restrict__ j,
double center );
3794 double PCL_FUNC
MAD(
const unsigned short* __restrict__ i,
const unsigned short* __restrict__ j,
double center );
3795 double PCL_FUNC
MAD(
const signed short* __restrict__ i,
const signed short* __restrict__ j,
double center );
3796 double PCL_FUNC
MAD(
const unsigned int* __restrict__ i,
const unsigned int* __restrict__ j,
double center );
3797 double PCL_FUNC
MAD(
const signed int* __restrict__ i,
const signed int* __restrict__ j,
double center );
3798 double PCL_FUNC
MAD(
const unsigned long* __restrict__ i,
const unsigned long* __restrict__ j,
double center );
3799 double PCL_FUNC
MAD(
const signed long* __restrict__ i,
const signed long* __restrict__ j,
double center );
3800 double PCL_FUNC
MAD(
const unsigned long long* __restrict__ i,
const unsigned long long* __restrict__ j,
double center );
3801 double PCL_FUNC
MAD(
const signed long long* __restrict__ i,
const signed long long* __restrict__ j,
double center );
3802 double PCL_FUNC
MAD(
const float* __restrict__ i,
const float* __restrict__ j,
double center );
3803 double PCL_FUNC
MAD(
const double* __restrict__ i,
const double* __restrict__ j,
double center );
3804 double PCL_FUNC
MAD(
const long double* __restrict__ i,
const long double* __restrict__ j,
double center );
3819 template <
typename T>
inline double MAD(
const T* __restrict__ i,
const T* __restrict__ j )
3842 double* d =
new double[ n ];
3843 double* __restrict__ p = d;
3844 double* __restrict__ q = d + n;
3847 double x = double( *i++ );
3860 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const unsigned char* __restrict__ i,
const unsigned char* __restrict__ j,
double center );
3861 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const signed char* __restrict__ i,
const signed char* __restrict__ j,
double center );
3862 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const wchar_t* __restrict__ i,
const wchar_t* __restrict__ j,
double center );
3863 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const unsigned short* __restrict__ i,
const unsigned short* __restrict__ j,
double center );
3864 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const signed short* __restrict__ i,
const signed short* __restrict__ j,
double center );
3865 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const unsigned int* __restrict__ i,
const unsigned int* __restrict__ j,
double center );
3866 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const signed int* __restrict__ i,
const signed int* __restrict__ j,
double center );
3867 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const unsigned long* __restrict__ i,
const unsigned long* __restrict__ j,
double center );
3868 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const signed long* __restrict__ i,
const signed long* __restrict__ j,
double center );
3869 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const unsigned long long* __restrict__ i,
const unsigned long long* __restrict__ j,
double center );
3870 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const signed long long* __restrict__ i,
const signed long long* __restrict__ j,
double center );
3871 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const float* __restrict__ i,
const float* __restrict__ j,
double center );
3872 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const double* __restrict__ i,
const double* __restrict__ j,
double center );
3873 TwoSidedEstimate PCL_FUNC
TwoSidedMAD(
const long double* __restrict__ i,
const long double* __restrict__ j,
double center );
3924 template <
typename T>
double Sn( T* __restrict__ x, T* __restrict__ xn )
3938 double* a2 =
new double[ n ];
3939 a2[0] = double( x[n >> 1] ) - double( x[0] );
3954 while ( leftA < rightA )
3963 leftA = tryA + even;
3969 leftB = tryB + even;
3973 double medA = double( x[i-1] ) - double( x[i-2 - tryA + Amin] );
3974 double medB = double( x[tryB + i-1] ) - double( x[i-1] );
3978 leftB = tryB + even;
3981 leftA = tryA + even;
3987 a2[i-1] = double( x[leftB + i-1] ) - double( x[i-1] );
3990 double medA = double( x[i-1] ) - double( x[i-2 - leftA + Amin] );
3991 double medB = double( x[leftB + i-1] ) - double( x[i-1] );
4007 while ( leftA < rightA )
4016 leftA = tryA + even;
4022 leftB = tryB + even;
4026 double medA = double( x[i + tryA - Amin] ) - double( x[i-1] );
4027 double medB = double( x[i-1] ) - double( x[i-1 - tryB] );
4031 leftB = tryB + even;
4034 leftA = tryA + even;
4040 a2[i-1] = double( x[i-1] ) - double( x[i-1 - leftB] );
4043 double medA = double( x[i + leftA - Amin] ) - double( x[i-1] );
4044 double medB = double( x[i-1] ) - double( x[i-1 - leftB] );
4049 a2[n-1] = double( x[n-1] ) - double( x[nh-1] );
4057 case 2: cn = 0.743;
break;
4058 case 3: cn = 1.851;
break;
4059 case 4: cn = 0.954;
break;
4060 case 5: cn = 1.351;
break;
4061 case 6: cn = 0.993;
break;
4062 case 7: cn = 1.198;
break;
4063 case 8: cn = 1.005;
break;
4064 case 9: cn = 1.131;
break;
4065 default: cn = (n & 1) ? n/(n - 0.9) : 1.0;
break;
4100 else if ( a[i] == trial )
4103 if ( 2*(wrest + wleft) > wtotal )
4109 acand[kcand] = a[i];
4110 iwcand[kcand] = iw[i];
4117 if ( 2*(wrest + wleft + wmid) > wtotal )
4124 acand[kcand] = a[i];
4125 iwcand[kcand] = iw[i];
4129 wrest += wleft + wmid;
4170 template <
typename T>
double Qn( T* __restrict__ x, T* __restrict__ xn )
4176 double* y =
new double[ n ];
4177 double* work =
new double[ n ];
4178 double* acand =
new double[ n ];
4190 y[i] = double( x[i] );
4191 left[i] = n - i + 1;
4192 right[i] = (i <= h) ? n : n - i + h;
4208 if ( left[i] <= right[i] )
4210 weight[j] = right[i] - left[i] + 1;
4211 work[j] = double( y[i] ) - y[n - left[i] - (weight[j] >> 1)];
4214 qn = __pcl_whimed__( work, weight, j, acand, iwcand );
4218 while ( j < n &&
double( y[i] ) - y[n-j-1] < qn )
4225 while (
double( y[i] ) - y[n-j+1] > qn )
4244 else if ( knew > sumQ )
4261 for (
distance_type jj = left[i]; jj <= right[i]; ++jj, ++j )
4262 work[j] =
double( y[i] ) - y[n-jj];
4272 case 2: dn = 0.399;
break;
4273 case 3: dn = 0.994;
break;
4274 case 4: dn = 0.512;
break;
4275 case 5: dn = 0.844;
break;
4276 case 6: dn = 0.611;
break;
4277 case 7: dn = 0.857;
break;
4278 case 8: dn = 0.669;
break;
4279 case 9: dn = 0.872;
break;
4280 default: dn = (n & 1) ? n/(n + 1.4) : n/(n + 3.8);
break;
4340 template <
typename T>
4342 double sigma,
int k = 9,
bool reducedLength =
false ) noexcept
4348 double kd = k * sigma;
4349 if ( kd < 0 || 1 + kd == 1 )
4352 double num = 0, den = 0;
4354 for ( ; x < xn; ++x )
4356 double xc = double( *x ) - center;
4361 double y21 = 1 - y2;
4362 num += xc*xc * y21*y21*y21*y21;
4363 den += y21 * (1 - 5*y2);
4369 return (1 + den != 1) ? (reducedLength ? nr : n)*num/den : 0.0;
4403 template <
typename T>
4405 const TwoSidedEstimate& sigma,
int k = 9,
bool reducedLength =
false ) noexcept
4407 double kd0 = k * sigma.
low;
4408 double kd1 = k * sigma.
high;
4409 if ( kd0 < 0 || 1 + kd0 == 1 || kd1 < 0 || 1 + kd1 == 1 )
4412 double num0 = 0, den0 = 0, num1 = 0, den1 = 0;
4413 size_type n0 = 0, n1 = 0, nr0 = 0, nr1 = 0;
4414 for ( ; x < xn; ++x )
4416 double xc = double( *x ) - center;
4423 double y = xc/(low ? kd0 : kd1);
4427 double y21 = 1 - y2;
4428 double num = xc*xc * y21*y21*y21*y21;
4429 double den = y21 * (1 - 5*y2);
4447 return { (n0 >= 2 && 1 + den0 != 1) ? (reducedLength ? nr0 : n0)*num0/den0 : 0.0,
4448 (n1 >= 2 && 1 + den1 != 1) ? (reducedLength ? nr1 : n1)*num1/den1 : 0.0 };
4479 template <
typename T>
4480 double BendMidvariance(
const T* __restrict__ x,
const T* __restrict__ xn,
double center,
double beta = 0.2 )
4486 beta =
Range( beta, 0.0, 0.5 );
4489 double* w =
new double[ n ];
4491 w[i] =
Abs(
double( x[i] ) - center );
4499 for ( ; x < xn; ++x )
4501 double y = (double( *x ) - center)/wb;
4502 double f =
Max( -1.0,
Min( 1.0, y ) );
4509 return (1 + den != 1) ? n*wb*wb*num/den : 0.0;
4540 inline double IncompleteBeta(
double a,
double b,
double x,
double eps = 1.0e-8 ) noexcept
4542 if ( x < 0 || x > 1 )
4543 return std::numeric_limits<double>::infinity();
4548 if ( x > (a + 1)/(a + b + 2) )
4554 double lbeta_ab = lgamma( a ) + lgamma( b ) - lgamma( a + b );
4555 double front =
Exp(
Ln( x )*a +
Ln( 1 - x )*b - lbeta_ab )/a;
4560 const double tiny = 1.0e-30;
4561 double f = 1, c = 1, d = 0;
4562 for (
int i = 0; i <= 200; ++i )
4567 numerator = -((a + m)*(a + b + m)*x)/((a + 2*m)*(a + 2*m + 1));
4569 numerator = (m*(b - m)*x)/((a + 2*m - 1)*(a + 2*m));
4576 d = 1 + numerator*d;
4577 if (
Abs( d ) < tiny )
4580 c = 1 + numerator/c;
4581 if (
Abs( c ) < tiny )
4585 if (
Abs( 1 - cd ) < eps )
4586 return front*(f - 1);
4590 return std::numeric_limits<double>::infinity();
4599 template <
typename T>
inline constexpr T
Erf( T x ) noexcept
4601 return std::erf( x );
4616 template <
typename T>
inline constexpr T
ErfInv( T x ) noexcept
4618 if ( x < -1 || x > 1 )
4619 return std::numeric_limits<T>::quiet_NaN();
4621 return std::numeric_limits<T>::infinity();
4623 return -std::numeric_limits<T>::infinity();
4625 const long double A0 = 1.1975323115670912564578e0L;
4626 const long double A1 = 4.7072688112383978012285e1L;
4627 const long double A2 = 6.9706266534389598238465e2L;
4628 const long double A3 = 4.8548868893843886794648e3L;
4629 const long double A4 = 1.6235862515167575384252e4L;
4630 const long double A5 = 2.3782041382114385731252e4L;
4631 const long double A6 = 1.1819493347062294404278e4L;
4632 const long double A7 = 8.8709406962545514830200e2L;
4634 const long double B0 = 1.0000000000000000000e0L;
4635 const long double B1 = 4.2313330701600911252e1L;
4636 const long double B2 = 6.8718700749205790830e2L;
4637 const long double B3 = 5.3941960214247511077e3L;
4638 const long double B4 = 2.1213794301586595867e4L;
4639 const long double B5 = 3.9307895800092710610e4L;
4640 const long double B6 = 2.8729085735721942674e4L;
4641 const long double B7 = 5.2264952788528545610e3L;
4643 const long double C0 = 1.42343711074968357734e0L;
4644 const long double C1 = 4.63033784615654529590e0L;
4645 const long double C2 = 5.76949722146069140550e0L;
4646 const long double C3 = 3.64784832476320460504e0L;
4647 const long double C4 = 1.27045825245236838258e0L;
4648 const long double C5 = 2.41780725177450611770e-1L;
4649 const long double C6 = 2.27238449892691845833e-2L;
4650 const long double C7 = 7.74545014278341407640e-4L;
4652 const long double D0 = 1.4142135623730950488016887e0L;
4653 const long double D1 = 2.9036514445419946173133295e0L;
4654 const long double D2 = 2.3707661626024532365971225e0L;
4655 const long double D3 = 9.7547832001787427186894837e-1L;
4656 const long double D4 = 2.0945065210512749128288442e-1L;
4657 const long double D5 = 2.1494160384252876777097297e-2L;
4658 const long double D6 = 7.7441459065157709165577218e-4L;
4659 const long double D7 = 1.4859850019840355905497876e-9L;
4661 const long double E0 = 6.65790464350110377720e0L;
4662 const long double E1 = 5.46378491116411436990e0L;
4663 const long double E2 = 1.78482653991729133580e0L;
4664 const long double E3 = 2.96560571828504891230e-1L;
4665 const long double E4 = 2.65321895265761230930e-2L;
4666 const long double E5 = 1.24266094738807843860e-3L;
4667 const long double E6 = 2.71155556874348757815e-5L;
4668 const long double E7 = 2.01033439929228813265e-7L;
4670 const long double F0 = 1.414213562373095048801689e0L;
4671 const long double F1 = 8.482908416595164588112026e-1L;
4672 const long double F2 = 1.936480946950659106176712e-1L;
4673 const long double F3 = 2.103693768272068968719679e-2L;
4674 const long double F4 = 1.112800997078859844711555e-3L;
4675 const long double F5 = 2.611088405080593625138020e-5L;
4676 const long double F6 = 2.010321207683943062279931e-7L;
4677 const long double F7 = 2.891024605872965461538222e-15L;
4679 long double abs_x =
Abs( x );
4681 if ( abs_x <= 0.85L )
4683 long double r = 0.180625L - 0.25L * x*x;
4684 long double num = (((((((A7*r + A6)*r + A5)*r + A4)*r + A3)*r + A2)*r + A1)*r + A0);
4685 long double den = (((((((B7*r + B6)*r + B5)*r + B4)*r + B3)*r + B2)*r + B1)*r + B0);
4686 return T( x * num/den );
4689 long double r =
Sqrt(
Ln2() -
Ln( 1 - abs_x ) );
4690 long double num = 0, den = 0;
4694 num = (((((((C7*r + C6)*r + C5)*r + C4)*r + C3)*r + C2)*r + C1)*r + C0);
4695 den = (((((((D7*r + D6)*r + D5)*r + D4)*r + D3)*r + D2)*r + D1)*r + D0);
4700 num = (((((((E7*r + E6)*r + E5)*r + E4)*r + E3)*r + E2)*r + E1)*r + E0);
4701 den = (((((((F7*r + F6)*r + F5)*r + F4)*r + F3)*r + F2)*r + F1)*r + F0);
4704 return T( std::copysign( num/den, x ) );
4752 #define PRIME64_1 11400714785074694791ULL
4753 #define PRIME64_2 14029467366897019727ULL
4754 #define PRIME64_3 1609587929392839161ULL
4755 #define PRIME64_4 9650029242287828579ULL
4756 #define PRIME64_5 2870177450012600261ULL
4759 const uint8* end = p + size;
4767 const uint8* limit = end - 32;
4768 uint64 v1 = seed + PRIME64_1 + PRIME64_2;
4769 uint64 v2 = seed + PRIME64_2;
4771 uint64 v4 = seed - PRIME64_1;
4775 v1 += *(
uint64*)p * PRIME64_2;
4777 v1 =
RotL( v1, 31 );
4779 v2 += *(
uint64*)p * PRIME64_2;
4781 v2 =
RotL( v2, 31 );
4783 v3 += *(
uint64*)p * PRIME64_2;
4785 v3 =
RotL( v3, 31 );
4787 v4 += *(
uint64*)p * PRIME64_2;
4789 v4 =
RotL( v4, 31 );
4792 while ( p <= limit );
4797 v1 =
RotL( v1, 31 );
4800 h64 = h64 * PRIME64_1 + PRIME64_4;
4803 v2 =
RotL( v2, 31 );
4806 h64 = h64 * PRIME64_1 + PRIME64_4;
4809 v3 =
RotL( v3, 31 );
4812 h64 = h64 * PRIME64_1 + PRIME64_4;
4815 v4 =
RotL( v4, 31 );
4818 h64 = h64 * PRIME64_1 + PRIME64_4;
4822 h64 = seed + PRIME64_5;
4827 while ( p+8 <= end )
4831 k1 =
RotL( k1, 31 );
4834 h64 =
RotL( h64, 27 ) * PRIME64_1 + PRIME64_4;
4841 h64 =
RotL( h64, 23 ) * PRIME64_2 + PRIME64_3;
4847 h64 ^= *p * PRIME64_5;
4848 h64 =
RotL( h64, 11 ) * PRIME64_1;
4906 #define PRIME32_1 2654435761U
4907 #define PRIME32_2 2246822519U
4908 #define PRIME32_3 3266489917U
4909 #define PRIME32_4 668265263U
4910 #define PRIME32_5 374761393U
4913 const uint8* end = p + size;
4921 const uint8* limit = end - 16;
4922 uint32 v1 = seed + PRIME32_1 + PRIME32_2;
4923 uint32 v2 = seed + PRIME32_2;
4925 uint32 v4 = seed - PRIME32_1;
4929 v1 += *(
uint32*)p * PRIME32_2;
4930 v1 =
RotL( v1, 13 );
4933 v2 += *(
uint32*)p * PRIME32_2;
4934 v2 =
RotL( v2, 13 );
4937 v3 += *(
uint32*)p * PRIME32_2;
4938 v3 =
RotL( v3, 13 );
4941 v4 += *(
uint32*)p * PRIME32_2;
4942 v4 =
RotL( v4, 13 );
4946 while ( p <= limit );
4952 h32 = seed + PRIME32_5;
4957 while ( p+4 <= end )
4959 h32 += *(
uint32*)p * PRIME32_3;
4960 h32 =
RotL( h32, 17 ) * PRIME32_4 ;
4966 h32 += *p * PRIME32_5;
4967 h32 =
RotL( h32, 11 ) * PRIME32_1 ;
Complex< T1 > Pow(const Complex< T1 > &c, T2 x) noexcept
Complex< T > Sqrt(const Complex< T > &c) noexcept
Complex< T > Exp(const Complex< T > &c) noexcept
Complex< T > Log(const Complex< T > &c) noexcept
Complex< T > Ln(const Complex< T > &c) noexcept
T Abs(const Complex< T > &c) noexcept
Complex< T > Round(const Complex< T > &c) noexcept
Complex< T > Sinh(const Complex< T > &c) noexcept
Complex< T > Tanh(const Complex< T > &c) noexcept
Complex< T > Sin(const Complex< T > &c) noexcept
Complex< T > Cosh(const Complex< T > &c) noexcept
Complex< T > Cos(const Complex< T > &c) noexcept
Complex< T > Tan(const Complex< T > &c) noexcept
bool IsNegativeZero(float x) noexcept
bool IsFinite(float x) noexcept
int IsInfinity(float x) noexcept
bool IsNaN(float x) noexcept
uint64 Hash64(const void *data, size_type size, uint64 seed=0) noexcept
uint32 Hash32(const void *data, size_type size, uint32 seed=0) noexcept
int MaxSSEInstructionSetSupported() noexcept
constexpr T RadSec(T x) noexcept
void SinCos(T x, T &sx, T &cx) noexcept
T L1Norm(const T *i, const T *j) noexcept
constexpr T Mod2Pi(T x) noexcept
constexpr char SignChar(T x) noexcept
constexpr T AsRad(T x) noexcept
constexpr T ArcTan(T x) noexcept
constexpr long double Log2T() noexcept
constexpr T LogN(T n, T x) noexcept
constexpr T Norm2Pi(T x) noexcept
T RotL(T x, uint32 n) noexcept
constexpr T ModPi(T x) noexcept
constexpr int Sign(T x) noexcept
void Rotate(T &x, T &y, T1 sa, T1 ca, T2 xc, T2 yc) noexcept
constexpr T Hav(T x) noexcept
void PCL_FUNC CalendarTimeToJD(int &jdi, double &jdf, int year, int month, int day, double dayf=0) noexcept
void Frexp(T x, T &m, int &p) noexcept
constexpr T ArcCosh(T x) noexcept
constexpr T Frac(T x) noexcept
constexpr T SecRad(T x) noexcept
constexpr T Ceil(T x) noexcept
constexpr T ArcTanh(T x) noexcept
constexpr long double TwoPi() noexcept
void Split(T x, T &i, T &f) noexcept
constexpr T MasRad(T x) noexcept
T ArcTan2Pi(T y, T x) noexcept
double LnFactorial(int n) noexcept
constexpr T Cotan(T x) noexcept
int RoundIntArithmetic(T x) noexcept
int64 RoundInt64(double x) noexcept
constexpr T UasRad(T x) noexcept
int64 TruncI64(T x) noexcept
double SexagesimalToDecimal(int sign, const S1 &s1, const S2 &s2=S2(0), const S3 &s3=S3(0)) noexcept
void PCL_FUNC JDToCalendarTime(int &year, int &month, int &day, double &dayf, int jdi, double jdf) noexcept
constexpr T RadMin(T x) noexcept
T PowI(T x, int n) noexcept
constexpr T ArcSinh(T x) noexcept
constexpr long double Log2() noexcept
constexpr T Ldexp(T m, int p) noexcept
constexpr T ArcSin(T x) noexcept
constexpr T Rad(T x) noexcept
constexpr long double Ln2() noexcept
double Factorial(int n) noexcept
constexpr T ErfInv(T x) noexcept
constexpr T Angle(int d, T m) noexcept
void DecimalToSexagesimal(int &sign, S1 &s1, S2 &s2, S3 &s3, const D &d) noexcept
constexpr T Erf(T x) noexcept
T Poly(T x, C c, int n) noexcept
constexpr T ArcCos(T x) noexcept
int64 TruncInt64(T x) noexcept
int RoundInt(T x) noexcept
T Norm(const T *i, const T *j, const P &p) noexcept
constexpr T Mod(T x, T y) noexcept
constexpr T ArcHav(T x) noexcept
constexpr T MinRad(T x) noexcept
int TruncInt(T x) noexcept
T L2Norm(const T *i, const T *j) noexcept
constexpr T Floor(T x) noexcept
constexpr T Deg(T x) noexcept
int64 RoundInt64Arithmetic(double x) noexcept
constexpr long double Pi() noexcept
int RoundIntBanker(T x) noexcept
T RotR(T x, uint32 n) noexcept
constexpr T Pow2(T x) noexcept
constexpr long double Log2e() noexcept
unsigned long long uint64
RI Select(RI i, RI j, distance_type k)
double IncompleteBeta(double a, double b, double x, double eps=1.0e-8) noexcept
double TrimmedMeanDestructive(T *__restrict__ i, T *__restrict__ j, distance_type l=1, distance_type h=1) noexcept
double Qn(T *__restrict__ x, T *__restrict__ xn)
double BendMidvariance(const T *__restrict__ x, const T *__restrict__ xn, double center, double beta=0.2)
TwoSidedEstimate TwoSidedMAD(const T *__restrict__ i, const T *__restrict__ j, double center)
double MAD(const T *__restrict__ i, const T *__restrict__ j, double center)
double StableModulus(const T *__restrict__ i, const T *__restrict__ j) noexcept
double SumOfSquares(const T *__restrict__ i, const T *__restrict__ j) noexcept
double StableMean(const T *__restrict__ i, const T *__restrict__ j) noexcept
double TrimmedMean(const T *__restrict__ i, const T *__restrict__ j, distance_type l=1, distance_type h=1)
double MedianDestructive(T *__restrict__ i, T *__restrict__ j) noexcept
double StableSum(const T *__restrict__ i, const T *__restrict__ j) noexcept
double Variance(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
double TrimmedMeanOfSquaresDestructive(T *__restrict__ i, T *__restrict__ j, distance_type l=1, distance_type h=1) noexcept
TwoSidedEstimate TwoSidedBiweightMidvariance(const T *__restrict__ x, const T *__restrict__ xn, double center, const TwoSidedEstimate &sigma, int k=9, bool reducedLength=false) noexcept
double Sum(const T *__restrict__ i, const T *__restrict__ j) noexcept
double StableSumOfSquares(const T *__restrict__ i, const T *__restrict__ j) noexcept
double BiweightMidvariance(const T *__restrict__ x, const T *__restrict__ xn, double center, double sigma, int k=9, bool reducedLength=false) noexcept
double StdDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
double TrimmedMeanOfSquares(const T *__restrict__ i, const T *__restrict__ j, distance_type l=1, distance_type h=1)
double AvgDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
double OrderStatisticDestructive(T *__restrict__ i, T *__restrict__ j, distance_type k) noexcept
double Mean(const T *__restrict__ i, const T *__restrict__ j) noexcept
double StableAvgDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
double Median(const T *__restrict__ i, const T *__restrict__ j)
TwoSidedEstimate TwoSidedAvgDev(const T *__restrict__ i, const T *__restrict__ j, double center) noexcept
double Modulus(const T *__restrict__ i, const T *__restrict__ j) noexcept
double Sn(T *__restrict__ x, T *__restrict__ xn)
double OrderStatistic(const T *__restrict__ i, const T *__restrict__ j, distance_type k)
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
int64 RoundI64(double x) noexcept
Exponential function 10**n, n being a signed integer.
Exponential function 2**n, n being a signed integer.
Two-sided descriptive statistical estimate.
double Total() const noexcept
TwoSidedEstimate(TwoSidedEstimate &&)=default
bool IsValid() const noexcept
TwoSidedEstimate(const T1 &l, const T2 &h)
TwoSidedEstimate & operator*=(double x) noexcept
TwoSidedEstimate operator/(double x) const noexcept
double high
High estimate component.
TwoSidedEstimate(const T &x)
double Mean() const noexcept
TwoSidedEstimate(const TwoSidedEstimate &)=default
double low
Low estimate component.
TwoSidedEstimate operator*(double x) const noexcept
TwoSidedEstimate & operator=(const TwoSidedEstimate &)=default
TwoSidedEstimate()=default
TwoSidedEstimate & operator/=(double x) noexcept