]> Creatis software - cpPlugins.git/blobdiff - lib/ivq/ITK/FourierSeries.hxx
...
[cpPlugins.git] / lib / ivq / ITK / FourierSeries.hxx
diff --git a/lib/ivq/ITK/FourierSeries.hxx b/lib/ivq/ITK/FourierSeries.hxx
new file mode 100644 (file)
index 0000000..3ed11c5
--- /dev/null
@@ -0,0 +1,101 @@
+// =========================================================================
+// @author: Leonardo Florez-Valencia
+// @email: florez-l@javeriana.edu.co
+// =========================================================================
+#ifndef __ivq__ITK__FourierSeries__hxx__
+#define __ivq__ITK__FourierSeries__hxx__
+
+// -------------------------------------------------------------------------
+template< class _TScalar, unsigned int _VDim >
+template< class _TScalar2, unsigned int _VDim2 >
+ivq::ITK::FourierSeries< _TScalar, _VDim >::
+FourierSeries( const FourierSeries< _TScalar2, _VDim2 >& o )
+  : m_RealAxis( _VDim - 2 ),
+    m_ImagAxis( _VDim - 1 )
+{
+  int q = o.GetNumberOfHarmonics( );
+  this->SetNumberOfHarmonics( q );
+  for( int l = -q; l <= q; ++l )
+    ( *this )[ l ] =
+      TComplex( TScalar( std::real( o[ l ] ) ), TScalar( std::imag( o[ l ] ) ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TScalar, unsigned int _VDim >
+template< class _TIt >
+ivq::ITK::FourierSeries< _TScalar, _VDim >::
+FourierSeries( const _TIt& b, const _TIt& e, unsigned int q )
+  : m_RealAxis( _VDim - 2 ),
+    m_ImagAxis( _VDim - 1 )
+{
+  std::vector< TComplex > aux;
+  for( _TIt it = b; it != e; ++it )
+    aux.push_back( TComplex( TScalar( ( *it )[ 0 ] ), TScalar( ( *it )[ 1 ] ) ) );
+  this->_DFT( aux, q );
+}
+
+// -------------------------------------------------------------------------
+template< class _TScalar, unsigned int _VDim >
+template< class _TScalar2, unsigned int _VDim2 >
+typename ivq::ITK::FourierSeries< _TScalar, _VDim >::
+Self& ivq::ITK::FourierSeries< _TScalar, _VDim >::
+operator=( const FourierSeries< _TScalar2, _VDim2 >& o )
+{
+  if( _VDim == _VDim2 )
+  {
+    this->m_RealAxis = o.GetRealAxis( );
+    this->m_ImagAxis = o.GetImagAxis( );
+  }
+  else
+  {
+    this->m_RealAxis = _VDim - 2;
+    this->m_ImagAxis = _VDim - 1;
+
+  } // fi
+  int q = o.GetNumberOfHarmonics( );
+  this->SetNumberOfHarmonics( q );
+  for( int l = -q; l <= q; ++l )
+    ( *this )[ l ] =
+      TComplex( TScalar( std::real( o[ l ] ) ), TScalar( std::imag( o[ l ] ) ) );
+  return( *this );
+}
+
+// -------------------------------------------------------------------------
+template< class _TScalar, unsigned int _VDim >
+template< class _TOtherScalar >
+void ivq::ITK::FourierSeries< _TScalar, _VDim >::
+SetEllipses( const std::vector< _TOtherScalar >& ellipses )
+{
+  int Q = ( ellipses.size( ) - 2 ) >> 2;
+  Q = ( Q < 1 )? 1: Q;
+  this->SetNumberOfHarmonics( Q );
+  auto cIt = ellipses.begin( );
+  TScalar cx = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
+  if( cIt != ellipses.end( ) )
+    ++cIt;
+  TScalar cy = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
+  if( cIt != ellipses.end( ) )
+    ++cIt;
+  ( *this )[ 0 ] = TComplex( cx, cy );
+  for( int l = 1; l <= Q; ++l )
+  {
+    TScalar a = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
+    if( cIt != ellipses.end( ) )
+      ++cIt;
+    TScalar b = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
+    if( cIt != ellipses.end( ) )
+      ++cIt;
+    TScalar t = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
+    if( cIt != ellipses.end( ) )
+      ++cIt;
+    TScalar p = ( cIt != ellipses.end( ) )? *cIt: TScalar( 0 );
+    if( cIt != ellipses.end( ) )
+      ++cIt;
+    this->SetEllipse( l, a, b, t, p );
+
+  } // rof
+}
+
+#endif // __ivq__ITK__FourierSeries__hxx__
+
+// eof - $RCSfile$