52 #ifndef __PCL_Complex_h
53 #define __PCL_Complex_h
58 #include <pcl/Diagnostics.h>
110 template <
typename T1>
113 real = T( c.Real() );
114 imag = T( c.Imag() );
120 constexpr T Real() const noexcept
136 constexpr T Imag() const noexcept
160 template <
typename T1>
163 real = T( c.Real() ), imag = T( c.Imag() );
171 template <
typename T1>
174 real += c.Real(), imag += c.Imag();
182 template <
typename T1>
185 real -= c.Real(), imag -= c.Imag();
193 template <
typename T1>
196 T t = T( real*c.Real() - imag*c.Imag() );
197 imag = T( imag*c.Real() + real*c.Imag() );
206 template <
typename T1>
212 PCL_PRECONDITION( c.Real() != 0 )
213 r = T( c.Imag()/c.Real() );
214 d = T( c.Real() + r*c.Imag() );
215 t = T( (real + r*imag)/d );
216 imag = (imag - r*real)/d;
220 PCL_PRECONDITION( c.Imag() != 0 )
221 r = T( c.Real()/c.Imag() );
222 d = T( c.Imag() + r*c.Real() );
223 t = T( (real*r + imag)/d );
224 imag = (imag*r - real)/d;
235 template <
typename T1>
246 template <
typename T1>
258 template <
typename T1>
270 template <
typename T1>
273 real *= x, imag *= x;
282 template <
typename T1>
285 PCL_PRECONDITION( x != 0 )
286 real /= x, imag /= x;
341 T Mag() const noexcept
365 explicit operator double() const noexcept
367 return double( Mag() );
379 explicit operator int() const noexcept
388 constexpr T
Norm() const noexcept
390 return real*real + imag*imag;
398 constexpr T Arg() const noexcept
403 return (real != 0 || imag != 0) ?
pcl::ArcTan( imag, real ) : 0;
421 template <
typename T>
422 struct PCL_AssertComplexSize
424 static_assert(
sizeof( Complex<T> ) == 2*
sizeof( T ),
"Invalid sizeof( Complex<> )" );
442 template <
typename T>
inline
454 template <
typename T>
inline
465 template <
typename T>
inline
477 template <
typename T1,
class T2>
inline
481 T1( c1.Imag() + c2.Imag() ) );
492 template <
typename T1,
class T2>
inline
506 template <
typename T1,
class T2>
inline
517 template <
typename T1,
class T2>
inline
521 T1( c1.Imag() - c2.Imag() ) );
534 template <
typename T1,
class T2>
inline
550 template <
typename T1,
class T2>
inline
561 template <
typename T1,
class T2>
inline
564 return Complex<T1>( T1( c1.Real()*c2.Real() - c1.Imag()*c2.Imag() ),
565 T1( c1.Imag()*c2.Real() + c1.Real()*c2.Imag() ) );
578 template <
typename T1,
class T2>
inline
581 return Complex<T1>( T1( c.Real()*x ), c.Imag()*x );
594 template <
typename T1,
class T2>
inline
605 template <
typename T1,
class T2>
inline
612 PCL_PRECONDITION( c2.Real() != 0 )
613 r = c2.Imag() / c2.Real();
614 d = c2.Real() + r*c2.Imag();
615 c.
Real() = T1( (c1.Real() + r*c1.Imag())/d );
616 c.
Imag() = T1( (c1.Imag() - r*c1.Real())/d );
620 PCL_PRECONDITION( c2.Imag() != 0 )
621 r = c2.Real() / c2.Imag();
622 d = c2.Imag() + r*c2.Real();
623 c.
Real() = T1( (c1.Real()*r + c1.Imag())/d );
624 c.
Imag() = T1( (c1.Imag()*r - c1.Real())/d );
639 template <
typename T1,
class T2>
inline
642 PCL_PRECONDITION( x != 0 )
643 return Complex<T1>( T1( c.Real()/x ), T1( c.Imag()/x ) );
656 template <
typename T1,
class T2>
inline
664 PCL_PRECONDITION( c.Real() != 0 )
665 r = c.Imag()/c.Real();
666 d = c.Real() + r*c.Imag();
667 c3.
Real() = T2( x/d );
668 c3.
Imag() = T2( -((r*x)/d) );
672 PCL_PRECONDITION( c.Imag() != 0 )
673 r = c.Real()/c.Imag();
674 d = c.Imag() + r*c.Real();
675 c3.
Real() = T2( (r*x)/d );
676 c3.
Imag() = T2( -(x/d) );
687 template <
typename T>
inline
690 if ( c.Real() == 0 && c.Imag() == 0 )
698 PCL_PRECONDITION( r != 0 )
704 PCL_PRECONDITION( i != 0 )
712 c1.
Imag() = c.Imag()/(m+m);
716 c1.
Imag() = (c.Imag() >= 0) ? m : -m;
727 template <
typename T>
inline
738 template <
typename T>
inline
748 template <
typename T>
inline
760 template <
typename T1,
class T2>
inline
773 template <
typename T1,
class T2>
inline
787 template <
typename T>
inline
790 if ( c2.Imag() == 0 )
792 else if ( c1.Imag() == 0 )
808 template <
typename T>
inline
819 template <
typename T>
inline
830 template <
typename T>
inline
840 template <
typename T>
inline
851 template <
typename T>
inline
862 template <
typename T>
inline
884 template <
typename T1,
class T2>
inline
887 return c1.Real() == c2.Real() && c1.Imag() == c2.Imag();
894 template <
typename T1,
class T2>
inline
897 return c.Real() == x && c.Imag() == T1( 0 );
904 template <
typename T1,
class T2>
inline
914 template <
typename T1,
class T2>
inline
917 return c1.Mag() < c2.Mag();
924 template <
typename T1,
class T2>
inline
934 template <
typename T1,
class T2>
inline
951 template <
typename T>
inline
963 template <
typename T>
inline
966 PCL_PRECONDITION( n >= 0 )
996 template <
typename T>
inline
1000 const T tiny = T( 1.0e-20 );
1001 for ( ; i < j; ++i, ++a, ++b )
1004 *i = n/
Max( tiny,
Abs( n ) );
1028 template <
typename T>
inline
1032 const T tiny = T( 1.0e-20 );
1033 for ( ; i < j; ++i, ++a, ++b )
1034 *i = (*b * ~*a)/
Max( tiny,
Abs( *a ) *
Abs( *b ) );
1056 #ifndef __PCL_NO_COMPLEX_INSTANTIATE
A complex number whose components are 32-bit floating point real numbers.
A complex number whose components are 64-bit floating point real numbers.
constexpr T Imag() const noexcept
constexpr bool IsReal() const noexcept
Complex(T r, T i=0) noexcept
constexpr T Real() const noexcept
Complex(const Complex< T1 > &c) noexcept
Complex< T > Conj() const noexcept
static constexpr T log10e()
A complex number whose components are 64-bit floating point real numbers.
A complex number whose components are 64-bit floating point real numbers.
A complex number whose components are 32-bit floating point real numbers.
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Complex< T1 > operator-(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Complex< T1 > operator*(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Complex< T1 > operator+(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Complex< T1 > operator/(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
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
Complex< T > Polar(T r, T stheta, T ctheta) 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
constexpr T ArcTan(T x) noexcept
T Norm(const T *i, const T *j, const P &p) noexcept
int TruncInt(T x) noexcept
void PhaseCorrelationMatrix(Complex< T > *__restrict__ i, const Complex< T > *__restrict__ j, const Complex< T > *__restrict__ a, const Complex< T > *__restrict__ b) noexcept
void CrossPowerSpectrumMatrix(Complex< T > *__restrict__ i, const Complex< T > *__restrict__ j, const Complex< T > *__restrict__ a, const Complex< T > *__restrict__ b) noexcept
constexpr const T & Max(const T &a, const T &b) noexcept