1 // =======================================================================
2 // @author: Leonardo Florez-Valencia
3 // @email: florez-l@javeriana.edu.co
4 // =======================================================================
5 #ifndef __ivq__ITK__IsoImageSlicer__hxx__
6 #define __ivq__ITK__IsoImageSlicer__hxx__
8 // -------------------------------------------------------------------------
9 template< class _TSlicer, class _TInterpolateFunction >
10 unsigned long ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
13 unsigned long t = this->Superclass::GetMTime( );
14 unsigned long sT = this->m_Slicer->GetMTime( );
15 unsigned long cT = this->m_Collapsor->GetMTime( );
16 unsigned long tT = this->m_Transform->GetMTime( );
17 t = ( sT > t )? sT: t;
18 t = ( cT > t )? cT: t;
19 t = ( tT > t )? tT: t;
23 // -------------------------------------------------------------------------
24 template< class _TSlicer, class _TInterpolateFunction >
25 const typename ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
27 ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
28 GetInterpolator( ) const
30 return( this->m_Slicer->GetInterpolator( ) );
33 // -------------------------------------------------------------------------
34 template< class _TSlicer, class _TInterpolateFunction >
35 const typename ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
36 TMatrix& ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
39 return( this->m_Transform->GetMatrix( ) );
42 // -------------------------------------------------------------------------
43 template< class _TSlicer, class _TInterpolateFunction >
44 const typename ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
45 TVector& ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
46 GetTranslation( ) const
48 return( this->m_Transform->GetOffset( ) );
51 // -------------------------------------------------------------------------
52 template< class _TSlicer, class _TInterpolateFunction >
53 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
54 SetInterpolator( TInterpolateFunction* f )
56 this->m_Slicer->SetInterpolator( f );
60 // -------------------------------------------------------------------------
61 template< class _TSlicer, class _TInterpolateFunction >
62 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
65 this->m_Size.Fill( s );
69 // -------------------------------------------------------------------------
70 template< class _TSlicer, class _TInterpolateFunction >
71 ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
74 m_SizeFromMaximum( false ),
75 m_SizeFromMinimum( false ),
76 m_Spacing( TSpacingValue( 1 ) ),
77 m_SpacingFromMaximum( false ),
78 m_SpacingFromMinimum( false )
80 this->m_Size.Fill( TScalar( 1 ) );
83 this->m_Slicer = TSlicer::New( );
87 this->m_Slicer->SetOutputStartIndex( idx );
89 // Dimension collapsor
90 this->m_Collapsor = TCollapsor::New( );
91 this->m_Collapsor->SetInput( this->m_Slicer->GetOutput( ) );
92 this->m_Collapsor->SetDirectionCollapseToIdentity( );
94 this->m_Transform = TTransform::New( );
95 this->m_Transform->SetIdentity( );
98 // -------------------------------------------------------------------------
99 template< class _TSlicer, class _TInterpolateFunction >
100 ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
105 // -------------------------------------------------------------------------
106 template< class _TSlicer, class _TInterpolateFunction >
107 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
108 GenerateOutputInformation( )
112 // -------------------------------------------------------------------------
113 template< class _TSlicer, class _TInterpolateFunction >
114 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
115 GenerateInputRequestedRegion( )
117 TImage* input = const_cast< TImage* >( this->GetInput( ) );
119 input->SetRequestedRegionToLargestPossibleRegion( );
122 // -------------------------------------------------------------------------
123 template< class _TSlicer, class _TInterpolateFunction >
124 void ivq::ITK::BaseImageSlicer< _TSlicer, _TInterpolateFunction >::
127 const TImage* input = this->GetInput( );
131 if( this->m_SpacingFromMaximum || this->m_SpacingFromMinimum )
133 spac = input->GetSpacing( );
134 TSpacingValue minIso = spac[ 0 ];
135 TSpacingValue maxIso = spac[ 0 ];
136 for( unsigned int i = 1; i < Self::Dim; i++ )
138 minIso = ( spac[ i ] < minIso )? spac[ i ]: minIso;
139 maxIso = ( spac[ i ] > maxIso )? spac[ i ]: maxIso;
142 this->m_Spacing = ( this->m_SpacingFromMinimum )? minIso: maxIso;
145 spac.Fill( this->m_Spacing );
148 if( this->m_SizeFromMaximum || this->m_SizeFromMinimum )
150 TSize iSize = input->GetRequestedRegion( ).GetSize( );
151 TSpacing iSpac = input->GetSpacing( );
152 TScalar minSize = TScalar( iSize[ 0 ] ) * TScalar( iSpac[ 0 ] );
153 TScalar maxSize = minSize;
154 for( unsigned int i = 1; i < Self::Dim; i++ )
156 TScalar v = TScalar( iSize[ i ] ) * TScalar( iSpac[ i ] );
157 minSize = ( v < minSize )? v: minSize;
158 maxSize = ( v > maxSize )? v: maxSize;
161 if( this->m_SizeFromMaximum )
162 this->m_Size.Fill( maxSize );
164 this->m_Size.Fill( minSize );
169 typename TSlicer::OriginPointType origin;
172 for( unsigned int i = 1; i < Self::Dim; i++ )
174 double s = double( this->m_Size[ i ] ) / double( spac[ i ] );
175 size[ i ] = ( unsigned int )( s );
176 origin[ i ] = -( 0.5 * this->m_Size[ i ] );
181 this->m_Slicer->SetInput( input );
182 this->m_Slicer->SetTransform( this->m_Transform );
183 this->m_Slicer->SetOutputSpacing( spac );
184 this->m_Slicer->SetOutputOrigin( origin );
185 this->m_Slicer->SetSize( size );
186 this->m_Slicer->SetDefaultPixelValue( this->m_DefaultValue );
189 // Note: UpdateLargestPossibleRegion( ) is used since we need the
190 // output regions to be updated at each filter call.
191 this->m_Slicer->UpdateLargestPossibleRegion( );
194 TRegion region = this->m_Slicer->GetOutput( )->GetRequestedRegion( );
195 TSize regionSize = region.GetSize( );
197 region.SetSize( regionSize );
198 this->m_Collapsor->SetExtractionRegion( region );
200 this->m_Collapsor->GraftOutput( this->GetOutput( ) );
201 this->m_Collapsor->UpdateLargestPossibleRegion( );
202 this->GraftOutput( this->m_Collapsor->GetOutput( ) );
205 #endif // __ivq__ITK__IsoImageSlicer__hxx__