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