]> Creatis software - cpPlugins.git/blob - lib/ivq/ITK/RegionOfInterestWithPaddingImageFilter.hxx
...
[cpPlugins.git] / lib / ivq / ITK / RegionOfInterestWithPaddingImageFilter.hxx
1 // =======================================================================
2 // @author: Leonardo Florez-Valencia
3 // @email: florez-l@javeriana.edu.co
4 // =======================================================================
5 #ifndef __ivq__ITK__RegionOfInterestWithPaddingImageFilter__hxx__
6 #define __ivq__ITK__RegionOfInterestWithPaddingImageFilter__hxx__
7
8 // -------------------------------------------------------------------------
9 template< class _TInput, class _TOutput >
10 ivq::ITK::RegionOfInterestWithPaddingImageFilter< _TInput, _TOutput >::
11 RegionOfInterestWithPaddingImageFilter( )
12   : Superclass( ),
13     m_Padding( 0 )
14 {
15 }
16
17 // -------------------------------------------------------------------------
18 template< class _TInput, class _TOutput >
19 ivq::ITK::RegionOfInterestWithPaddingImageFilter< _TInput, _TOutput >::
20 ~RegionOfInterestWithPaddingImageFilter( )
21 {
22 }
23
24 // -------------------------------------------------------------------------
25 template< class _TInput, class _TOutput >
26 void ivq::ITK::RegionOfInterestWithPaddingImageFilter< _TInput, _TOutput >::
27 GenerateOutputInformation( )
28 {
29   if( this->m_Padding > 0 )
30   {
31     // Apply padding
32     typename _TInput::RegionType region =
33       this->GetInput( )->GetLargestPossibleRegion( );
34     typename _TInput::RegionType roi = this->GetRegionOfInterest( );
35     typename _TInput::IndexType iMin = region.GetIndex( );
36     typename _TInput::IndexType iMax = iMin + region.GetSize( );
37     typename _TInput::IndexType i0 = roi.GetIndex( );
38     typename _TInput::IndexType i1 = i0 + roi.GetSize( );
39     typename _TInput::SizeType size;
40     for( unsigned int d = 0; d < _TInput::ImageDimension; ++d )
41     {
42       i0[ d ] -= this->m_Padding;
43       i1[ d ] += this->m_Padding;
44       i0[ d ] = ( i0[ d ] < iMin[ d ] )? iMin[ d ]: i0[ d ];
45       i1[ d ] = ( iMax[ d ] < i1[ d ] )? iMax[ d ]: i1[ d ];
46       size[ d ] = i1[ d ] - i0[ d ];
47
48     } // rof
49
50     roi.SetIndex( i0 );
51     roi.SetSize( size );
52     this->SetRegionOfInterest( roi );
53
54   } // fi
55   this->Superclass::GenerateOutputInformation( );
56 }
57
58 #endif // __ivq__ITK__RegionOfInterestWithPaddingImageFilter__hxx__
59
60 // eof - $RCSfile$