]> Creatis software - cpPlugins.git/blob - lib/ivq/ITK/FourierSeries.hxx
3ed11c5c0830e7194ee1f85303481b189be438e6
[cpPlugins.git] / lib / ivq / ITK / FourierSeries.hxx
1 // =========================================================================
2 // @author: Leonardo Florez-Valencia
3 // @email: florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __ivq__ITK__FourierSeries__hxx__
6 #define __ivq__ITK__FourierSeries__hxx__
7
8 // -------------------------------------------------------------------------
9 template< class _TScalar, unsigned int _VDim >
10 template< class _TScalar2, unsigned int _VDim2 >
11 ivq::ITK::FourierSeries< _TScalar, _VDim >::
12 FourierSeries( const FourierSeries< _TScalar2, _VDim2 >& o )
13   : m_RealAxis( _VDim - 2 ),
14     m_ImagAxis( _VDim - 1 )
15 {
16   int q = o.GetNumberOfHarmonics( );
17   this->SetNumberOfHarmonics( q );
18   for( int l = -q; l <= q; ++l )
19     ( *this )[ l ] =
20       TComplex( TScalar( std::real( o[ l ] ) ), TScalar( std::imag( o[ l ] ) ) );
21 }
22
23 // -------------------------------------------------------------------------
24 template< class _TScalar, unsigned int _VDim >
25 template< class _TIt >
26 ivq::ITK::FourierSeries< _TScalar, _VDim >::
27 FourierSeries( const _TIt& b, const _TIt& e, unsigned int q )
28   : m_RealAxis( _VDim - 2 ),
29     m_ImagAxis( _VDim - 1 )
30 {
31   std::vector< TComplex > aux;
32   for( _TIt it = b; it != e; ++it )
33     aux.push_back( TComplex( TScalar( ( *it )[ 0 ] ), TScalar( ( *it )[ 1 ] ) ) );
34   this->_DFT( aux, q );
35 }
36
37 // -------------------------------------------------------------------------
38 template< class _TScalar, unsigned int _VDim >
39 template< class _TScalar2, unsigned int _VDim2 >
40 typename ivq::ITK::FourierSeries< _TScalar, _VDim >::
41 Self& ivq::ITK::FourierSeries< _TScalar, _VDim >::
42 operator=( const FourierSeries< _TScalar2, _VDim2 >& o )
43 {
44   if( _VDim == _VDim2 )
45   {
46     this->m_RealAxis = o.GetRealAxis( );
47     this->m_ImagAxis = o.GetImagAxis( );
48   }
49   else
50   {
51     this->m_RealAxis = _VDim - 2;
52     this->m_ImagAxis = _VDim - 1;
53
54   } // fi
55   int q = o.GetNumberOfHarmonics( );
56   this->SetNumberOfHarmonics( q );
57   for( int l = -q; l <= q; ++l )
58     ( *this )[ l ] =
59       TComplex( TScalar( std::real( o[ l ] ) ), TScalar( std::imag( o[ l ] ) ) );
60   return( *this );
61 }
62
63 // -------------------------------------------------------------------------
64 template< class _TScalar, unsigned int _VDim >
65 template< class _TOtherScalar >
66 void ivq::ITK::FourierSeries< _TScalar, _VDim >::
67 SetEllipses( const std::vector< _TOtherScalar >& ellipses )
68 {
69   int Q = ( ellipses.size( ) - 2 ) >> 2;
70   Q = ( Q < 1 )? 1: Q;
71   this->SetNumberOfHarmonics( Q );
72   auto cIt = ellipses.begin( );
73   TScalar cx = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
74   if( cIt != ellipses.end( ) )
75     ++cIt;
76   TScalar cy = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
77   if( cIt != ellipses.end( ) )
78     ++cIt;
79   ( *this )[ 0 ] = TComplex( cx, cy );
80   for( int l = 1; l <= Q; ++l )
81   {
82     TScalar a = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
83     if( cIt != ellipses.end( ) )
84       ++cIt;
85     TScalar b = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
86     if( cIt != ellipses.end( ) )
87       ++cIt;
88     TScalar t = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
89     if( cIt != ellipses.end( ) )
90       ++cIt;
91     TScalar p = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
92     if( cIt != ellipses.end( ) )
93       ++cIt;
94     this->SetEllipse( l, a, b, t, p );
95
96   } // rof
97 }
98
99 #endif // __ivq__ITK__FourierSeries__hxx__
100
101 // eof - $RCSfile$