1 /* =======================================================================
2 * @author: Leonardo Florez-Valencia
3 * @email: florez-l@javeriana.edu.co
4 * =======================================================================
7 #ifndef __ivq__ITK__IsoImageSlicer__hxx__
8 #define __ivq__ITK__IsoImageSlicer__hxx__
10 // -------------------------------------------------------------------------
11 template< class _TSlicer, class _TInterpolateFunction >
12 unsigned long ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
15 unsigned long t = this->Superclass::GetMTime( );
16 unsigned long sT = this->m_Slicer->GetMTime( );
17 unsigned long cT = this->m_Collapsor->GetMTime( );
18 unsigned long tT = this->m_Transform->GetMTime( );
19 t = ( sT > t )? sT: t;
20 t = ( cT > t )? cT: t;
21 t = ( tT > t )? tT: t;
25 // -------------------------------------------------------------------------
26 template< class _TSlicer, class _TInterpolateFunction >
27 const typename ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
29 ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
30 GetInterpolator( ) const
32 return( this->m_Slicer->GetInterpolator( ) );
35 // -------------------------------------------------------------------------
36 template< class _TSlicer, class _TInterpolateFunction >
37 const typename ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
38 TMatrix& ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
41 return( this->m_Transform->GetMatrix( ) );
44 // -------------------------------------------------------------------------
45 template< class _TSlicer, class _TInterpolateFunction >
46 const typename ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
47 TVector& ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
48 GetTranslation( ) const
50 return( this->m_Transform->GetOffset( ) );
53 // -------------------------------------------------------------------------
54 template< class _TSlicer, class _TInterpolateFunction >
55 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
56 SetInterpolator( TInterpolateFunction* f )
58 this->m_Slicer->SetInterpolator( f );
62 // -------------------------------------------------------------------------
63 template< class _TSlicer, class _TInterpolateFunction >
64 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
67 this->m_Size.Fill( s );
71 // -------------------------------------------------------------------------
72 template< class _TSlicer, class _TInterpolateFunction >
73 ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
76 m_SizeFromMaximum( false ),
77 m_SizeFromMinimum( false ),
78 m_Spacing( TSpacingValue( 1 ) ),
79 m_SpacingFromMaximum( false ),
80 m_SpacingFromMinimum( false )
82 this->m_Size.Fill( TScalar( 1 ) );
85 this->m_Slicer = TSlicer::New( );
89 this->m_Slicer->SetOutputStartIndex( idx );
91 // Dimension collapsor
92 this->m_Collapsor = TCollapsor::New( );
93 this->m_Collapsor->SetInput( this->m_Slicer->GetOutput( ) );
94 this->m_Collapsor->SetDirectionCollapseToIdentity( );
96 this->m_Transform = TTransform::New( );
97 this->m_Transform->SetIdentity( );
100 // -------------------------------------------------------------------------
101 template< class _TSlicer, class _TInterpolateFunction >
102 ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
107 // -------------------------------------------------------------------------
108 template< class _TSlicer, class _TInterpolateFunction >
109 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
110 GenerateOutputInformation( )
114 // -------------------------------------------------------------------------
115 template< class _TSlicer, class _TInterpolateFunction >
116 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
117 GenerateInputRequestedRegion( )
119 TImage* input = const_cast< TImage* >( this->GetInput( ) );
121 input->SetRequestedRegionToLargestPossibleRegion( );
124 // -------------------------------------------------------------------------
125 template< class _TSlicer, class _TInterpolateFunction >
126 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
129 const TImage* input = this->GetInput( );
133 if( this->m_SpacingFromMaximum || this->m_SpacingFromMinimum )
135 spac = input->GetSpacing( );
136 TSpacingValue minIso = spac[ 0 ];
137 TSpacingValue maxIso = spac[ 0 ];
138 for( unsigned int i = 1; i < Self::Dim; i++ )
140 minIso = ( spac[ i ] < minIso )? spac[ i ]: minIso;
141 maxIso = ( spac[ i ] > maxIso )? spac[ i ]: maxIso;
144 this->m_Spacing = ( this->m_SpacingFromMinimum )? minIso: maxIso;
147 spac.Fill( this->m_Spacing );
150 if( this->m_SizeFromMaximum || this->m_SizeFromMinimum )
152 TSize iSize = input->GetRequestedRegion( ).GetSize( );
153 TSpacing iSpac = input->GetSpacing( );
154 TScalar minSize = TScalar( iSize[ 0 ] ) * TScalar( iSpac[ 0 ] );
155 TScalar maxSize = minSize;
156 for( unsigned int i = 1; i < Self::Dim; i++ )
158 TScalar v = TScalar( iSize[ i ] ) * TScalar( iSpac[ i ] );
159 minSize = ( v < minSize )? v: minSize;
160 maxSize = ( v > maxSize )? v: maxSize;
163 if( this->m_SizeFromMaximum )
164 this->m_Size.Fill( maxSize );
166 this->m_Size.Fill( minSize );
171 typename TSlicer::OriginPointType origin;
174 for( unsigned int i = 1; i < Self::Dim; i++ )
176 double s = double( this->m_Size[ i ] ) / double( spac[ i ] );
177 size[ i ] = ( unsigned int )( s );
178 origin[ i ] = -( 0.5 * this->m_Size[ i ] );
183 this->m_Slicer->SetInput( input );
184 this->m_Slicer->SetTransform( this->m_Transform );
185 this->m_Slicer->SetOutputSpacing( spac );
186 this->m_Slicer->SetOutputOrigin( origin );
187 this->m_Slicer->SetSize( size );
188 this->m_Slicer->SetDefaultPixelValue( this->m_DefaultValue );
191 // Note: UpdateLargestPossibleRegion( ) is used since we need the
192 // output regions to be updated at each filter call.
193 this->m_Slicer->UpdateLargestPossibleRegion( );
196 TRegion region = this->m_Slicer->GetOutput( )->GetRequestedRegion( );
197 TSize regionSize = region.GetSize( );
199 region.SetSize( regionSize );
200 this->m_Collapsor->SetExtractionRegion( region );
202 this->m_Collapsor->GraftOutput( this->GetOutput( ) );
203 this->m_Collapsor->UpdateLargestPossibleRegion( );
204 this->GraftOutput( this->m_Collapsor->GetOutput( ) );
207 #endif // __ivq__ITK__IsoImageSlicer__hxx__