1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__ISOIMAGESLICER__HXX__
6 #define __CPPLUGINS__EXTENSIONS__ALGORITHMS__ISOIMAGESLICER__HXX__
8 // -------------------------------------------------------------------------
9 template< class R, class I >
10 unsigned long cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
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 R, class I >
25 const typename cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
27 cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
28 GetInterpolator( ) const
30 return( this->m_Slicer->GetInterpolator( ) );
33 // -------------------------------------------------------------------------
34 template< class R, class I >
35 const typename cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
36 TMatrix& cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
39 return( this->m_Transform->GetMatrix( ) );
42 // -------------------------------------------------------------------------
43 template< class R, class I >
44 const typename cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
45 TVector& cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
46 GetTranslation( ) const
48 return( this->m_Transform->GetOffset( ) );
51 // -------------------------------------------------------------------------
52 template< class R, class I >
53 void cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
54 SetInterpolator( TInterpolateFunction* f )
56 this->m_Slicer->SetInterpolator( f );
60 // -------------------------------------------------------------------------
61 template< class R, class I >
63 void cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
64 SetRotation( const M& r )
67 for( unsigned int i = 0; i < Self::Dim; ++i )
68 for( unsigned int j = 0; j < Self::Dim; ++j )
69 rotation[ i ][ j ] = r[ i ][ j ];
70 this->m_Transform->SetMatrix( rotation );
74 // -------------------------------------------------------------------------
75 template< class R, class I >
77 void cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
78 SetTranslation( const V& t )
81 for( unsigned int i = 0; i < Self::Dim; ++i )
83 this->m_Transform->SetOffset( off );
87 // -------------------------------------------------------------------------
88 template< class R, class I >
89 void cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
92 this->m_Size.Fill( s );
96 // -------------------------------------------------------------------------
97 template< class R, class I >
98 cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
101 m_SizeFromMaximum( false ),
102 m_SizeFromMinimum( false ),
103 m_Spacing( TSpacingValue( 1 ) ),
104 m_SpacingFromMaximum( false ),
105 m_SpacingFromMinimum( false )
107 this->m_Size.Fill( TScalar( 1 ) );
110 this->m_Slicer = TSlicer::New( );
114 this->m_Slicer->SetOutputStartIndex( idx );
116 // Dimension collapsor
117 this->m_Collapsor = TCollapsor::New( );
118 this->m_Collapsor->SetInput( this->m_Slicer->GetOutput( ) );
120 this->m_Transform = TTransform::New( );
121 this->m_Transform->SetIdentity( );
124 // -------------------------------------------------------------------------
125 template< class R, class I >
126 cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
131 // -------------------------------------------------------------------------
132 template< class R, class I >
133 void cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
134 GenerateOutputInformation( )
138 // -------------------------------------------------------------------------
139 template< class R, class I >
140 void cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
141 GenerateInputRequestedRegion( )
143 TImage* input = const_cast< TImage* >( this->GetInput( ) );
145 input->SetRequestedRegionToLargestPossibleRegion( );
148 // -------------------------------------------------------------------------
149 template< class R, class I >
150 void cpPlugins::Extensions::Algorithms::BaseImageSlicer< R, I >::
153 const TImage* input = this->GetInput( );
157 if( this->m_SpacingFromMaximum || this->m_SpacingFromMinimum )
159 spac = input->GetSpacing( );
160 TSpacingValue minIso = spac[ 0 ];
161 TSpacingValue maxIso = spac[ 0 ];
162 for( unsigned int i = 1; i < Self::Dim; i++ )
164 minIso = ( spac[ i ] < minIso )? spac[ i ]: minIso;
165 maxIso = ( spac[ i ] > maxIso )? spac[ i ]: maxIso;
168 this->m_Spacing = ( this->m_SpacingFromMinimum )? minIso: maxIso;
171 spac.Fill( this->m_Spacing );
174 if( this->m_SizeFromMaximum || this->m_SizeFromMinimum )
176 TSize iSize = input->GetRequestedRegion( ).GetSize( );
177 TSpacing iSpac = input->GetSpacing( );
178 TScalar minSize = TScalar( iSize[ 0 ] ) * TScalar( iSpac[ 0 ] );
179 TScalar maxSize = minSize;
180 for( unsigned int i = 1; i < Self::Dim; i++ )
182 TScalar v = TScalar( iSize[ i ] ) * TScalar( iSpac[ i ] );
183 minSize = ( v < minSize )? v: minSize;
184 maxSize = ( v > maxSize )? v: maxSize;
187 if( this->m_SizeFromMaximum )
188 this->m_Size.Fill( maxSize );
190 this->m_Size.Fill( minSize );
195 typename TSlicer::OriginPointType origin;
198 for( unsigned int i = 1; i < Self::Dim; i++ )
200 double s = double( this->m_Size[ i ] ) / double( spac[ i ] );
201 size[ i ] = ( unsigned int )( s );
202 origin[ i ] = -( 0.5 * this->m_Size[ i ] );
207 this->m_Slicer->SetInput( input );
208 this->m_Slicer->SetTransform( this->m_Transform );
209 this->m_Slicer->SetOutputSpacing( spac );
210 this->m_Slicer->SetOutputOrigin( origin );
211 this->m_Slicer->SetSize( size );
212 this->m_Slicer->SetDefaultPixelValue( this->m_DefaultValue );
215 // Note: UpdateLargestPossibleRegion( ) is used since we need the
216 // output regions to be updated at each filter call.
217 this->m_Slicer->UpdateLargestPossibleRegion( );
220 TRegion region = this->m_Slicer->GetOutput( )->GetRequestedRegion( );
221 TSize regionSize = region.GetSize( );
223 region.SetSize( regionSize );
224 this->m_Collapsor->SetExtractionRegion( region );
226 this->m_Collapsor->GraftOutput( this->GetOutput( ) );
227 this->m_Collapsor->UpdateLargestPossibleRegion( );
228 this->GraftOutput( this->m_Collapsor->GetOutput( ) );
231 #endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__ISOIMAGESLICER__HXX__