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() );
374 constexpr T
Norm() const noexcept
376 return real*real + imag*imag;
384 constexpr T Arg() const noexcept
389 return (real != 0 || imag != 0) ?
pcl::ArcTan( imag, real ) : 0;
407 template <
typename T>
408 struct PCL_AssertComplexSize
410 static_assert(
sizeof( Complex<T> ) == 2*
sizeof( T ),
"Invalid sizeof( Complex<> )" );
428 template <
typename T>
inline
440 template <
typename T>
inline
451 template <
typename T>
inline
463 template <
typename T1,
class T2>
inline
467 T1( c1.Imag() + c2.Imag() ) );
478 template <
typename T1,
class T2>
inline
492 template <
typename T1,
class T2>
inline
503 template <
typename T1,
class T2>
inline
507 T1( c1.Imag() - c2.Imag() ) );
520 template <
typename T1,
class T2>
inline
536 template <
typename T1,
class T2>
inline
547 template <
typename T1,
class T2>
inline
550 return Complex<T1>( T1( c1.Real()*c2.Real() - c1.Imag()*c2.Imag() ),
551 T1( c1.Imag()*c2.Real() + c1.Real()*c2.Imag() ) );
564 template <
typename T1,
class T2>
inline
567 return Complex<T1>( T1( c.Real()*x ), c.Imag()*x );
580 template <
typename T1,
class T2>
inline
591 template <
typename T1,
class T2>
inline
598 PCL_PRECONDITION( c2.Real() != 0 )
599 r = c2.Imag() / c2.Real();
600 d = c2.Real() + r*c2.Imag();
601 c.
Real() = T1( (c1.Real() + r*c1.Imag())/d );
602 c.
Imag() = T1( (c1.Imag() - r*c1.Real())/d );
606 PCL_PRECONDITION( c2.Imag() != 0 )
607 r = c2.Real() / c2.Imag();
608 d = c2.Imag() + r*c2.Real();
609 c.
Real() = T1( (c1.Real()*r + c1.Imag())/d );
610 c.
Imag() = T1( (c1.Imag()*r - c1.Real())/d );
625 template <
typename T1,
class T2>
inline
628 PCL_PRECONDITION( x != 0 )
629 return Complex<T1>( T1( c.Real()/x ), T1( c.Imag()/x ) );
642 template <
typename T1,
class T2>
inline
650 PCL_PRECONDITION( c.Real() != 0 )
651 r = c.Imag()/c.Real();
652 d = c.Real() + r*c.Imag();
653 c3.
Real() = T2( x/d );
654 c3.
Imag() = T2( -((r*x)/d) );
658 PCL_PRECONDITION( c.Imag() != 0 )
659 r = c.Real()/c.Imag();
660 d = c.Imag() + r*c.Real();
661 c3.
Real() = T2( (r*x)/d );
662 c3.
Imag() = T2( -(x/d) );
673 template <
typename T>
inline
676 if ( c.Real() == 0 && c.Imag() == 0 )
684 PCL_PRECONDITION( r != 0 )
690 PCL_PRECONDITION( i != 0 )
698 c1.
Imag() = c.Imag()/(m+m);
702 c1.
Imag() = (c.Imag() >= 0) ? m : -m;
713 template <
typename T>
inline
724 template <
typename T>
inline
734 template <
typename T>
inline
746 template <
typename T1,
class T2>
inline
759 template <
typename T1,
class T2>
inline
773 template <
typename T>
inline
776 if ( c2.Imag() == 0 )
778 else if ( c1.Imag() == 0 )
794 template <
typename T>
inline
805 template <
typename T>
inline
816 template <
typename T>
inline
826 template <
typename T>
inline
837 template <
typename T>
inline
848 template <
typename T>
inline
870 template <
typename T1,
class T2>
inline
873 return c1.Real() == c2.Real() && c1.Imag() == c2.Imag();
880 template <
typename T1,
class T2>
inline
883 return c.Real() == x && c.Imag() == T1( 0 );
890 template <
typename T1,
class T2>
inline
900 template <
typename T1,
class T2>
inline
903 return c1.Mag() < c2.Mag();
910 template <
typename T1,
class T2>
inline
920 template <
typename T1,
class T2>
inline
937 template <
typename T>
inline
949 template <
typename T>
inline
952 PCL_PRECONDITION( n >= 0 )
982 template <
typename T>
inline
986 const T tiny = T( 1.0e-20 );
987 for ( ; i < j; ++i, ++a, ++b )
990 *i = n/
Max( tiny,
Abs( n ) );
1014 template <
typename T>
inline
1018 const T tiny = T( 1.0e-20 );
1019 for ( ; i < j; ++i, ++a, ++b )
1020 *i = (*b * ~*a)/
Max( tiny,
Abs( *a ) *
Abs( *b ) );
1042 #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
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