1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__ISOIMAGESLICER__HXX__
6 #define __CPEXTENSIONS__ALGORITHMS__ISOIMAGESLICER__HXX__
8 // -------------------------------------------------------------------------
9 template< class R, class I >
10 unsigned long cpExtensions::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 cpExtensions::Algorithms::BaseImageSlicer< R, I >::
27 cpExtensions::Algorithms::BaseImageSlicer< R, I >::
28 GetInterpolator( ) const
30 return( this->m_Slicer->GetInterpolator( ) );
33 // -------------------------------------------------------------------------
34 template< class R, class I >
35 const typename cpExtensions::Algorithms::BaseImageSlicer< R, I >::
36 TMatrix& cpExtensions::Algorithms::BaseImageSlicer< R, I >::
39 return( this->m_Transform->GetMatrix( ) );
42 // -------------------------------------------------------------------------
43 template< class R, class I >
44 const typename cpExtensions::Algorithms::BaseImageSlicer< R, I >::
45 TVector& cpExtensions::Algorithms::BaseImageSlicer< R, I >::
46 GetTranslation( ) const
48 return( this->m_Transform->GetOffset( ) );
51 // -------------------------------------------------------------------------
52 template< class R, class I >
53 void cpExtensions::Algorithms::BaseImageSlicer< R, I >::
54 SetInterpolator( TInterpolateFunction* f )
56 this->m_Slicer->SetInterpolator( f );
60 // -------------------------------------------------------------------------
61 template< class R, class I >
63 void cpExtensions::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 cpExtensions::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 cpExtensions::Algorithms::BaseImageSlicer< R, I >::
92 this->m_Size.Fill( s );
96 // -------------------------------------------------------------------------
97 template< class R, class I >
98 cpExtensions::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( ) );
119 this->m_Collapsor->SetDirectionCollapseToIdentity( );
121 this->m_Transform = TTransform::New( );
122 this->m_Transform->SetIdentity( );
125 // -------------------------------------------------------------------------
126 template< class R, class I >
127 cpExtensions::Algorithms::BaseImageSlicer< R, I >::
132 // -------------------------------------------------------------------------
133 template< class R, class I >
134 void cpExtensions::Algorithms::BaseImageSlicer< R, I >::
135 GenerateOutputInformation( )
139 // -------------------------------------------------------------------------
140 template< class R, class I >
141 void cpExtensions::Algorithms::BaseImageSlicer< R, I >::
142 GenerateInputRequestedRegion( )
144 TImage* input = const_cast< TImage* >( this->GetInput( ) );
146 input->SetRequestedRegionToLargestPossibleRegion( );
149 // -------------------------------------------------------------------------
150 template< class R, class I >
151 void cpExtensions::Algorithms::BaseImageSlicer< R, I >::
154 const TImage* input = this->GetInput( );
158 if( this->m_SpacingFromMaximum || this->m_SpacingFromMinimum )
160 spac = input->GetSpacing( );
161 TSpacingValue minIso = spac[ 0 ];
162 TSpacingValue maxIso = spac[ 0 ];
163 for( unsigned int i = 1; i < Self::Dim; i++ )
165 minIso = ( spac[ i ] < minIso )? spac[ i ]: minIso;
166 maxIso = ( spac[ i ] > maxIso )? spac[ i ]: maxIso;
169 this->m_Spacing = ( this->m_SpacingFromMinimum )? minIso: maxIso;
172 spac.Fill( this->m_Spacing );
175 if( this->m_SizeFromMaximum || this->m_SizeFromMinimum )
177 TSize iSize = input->GetRequestedRegion( ).GetSize( );
178 TSpacing iSpac = input->GetSpacing( );
179 TScalar minSize = TScalar( iSize[ 0 ] ) * TScalar( iSpac[ 0 ] );
180 TScalar maxSize = minSize;
181 for( unsigned int i = 1; i < Self::Dim; i++ )
183 TScalar v = TScalar( iSize[ i ] ) * TScalar( iSpac[ i ] );
184 minSize = ( v < minSize )? v: minSize;
185 maxSize = ( v > maxSize )? v: maxSize;
188 if( this->m_SizeFromMaximum )
189 this->m_Size.Fill( maxSize );
191 this->m_Size.Fill( minSize );
196 typename TSlicer::OriginPointType origin;
199 for( unsigned int i = 1; i < Self::Dim; i++ )
201 double s = double( this->m_Size[ i ] ) / double( spac[ i ] );
202 size[ i ] = ( unsigned int )( s );
203 origin[ i ] = -( 0.5 * this->m_Size[ i ] );
208 this->m_Slicer->SetInput( input );
209 this->m_Slicer->SetTransform( this->m_Transform );
210 this->m_Slicer->SetOutputSpacing( spac );
211 this->m_Slicer->SetOutputOrigin( origin );
212 this->m_Slicer->SetSize( size );
213 this->m_Slicer->SetDefaultPixelValue( this->m_DefaultValue );
216 // Note: UpdateLargestPossibleRegion( ) is used since we need the
217 // output regions to be updated at each filter call.
218 this->m_Slicer->UpdateLargestPossibleRegion( );
221 TRegion region = this->m_Slicer->GetOutput( )->GetRequestedRegion( );
222 TSize regionSize = region.GetSize( );
224 region.SetSize( regionSize );
225 this->m_Collapsor->SetExtractionRegion( region );
227 this->m_Collapsor->GraftOutput( this->GetOutput( ) );
228 this->m_Collapsor->UpdateLargestPossibleRegion( );
229 this->GraftOutput( this->m_Collapsor->GetOutput( ) );
232 #endif // __CPEXTENSIONS__ALGORITHMS__ISOIMAGESLICER__HXX__