]> Creatis software - cpPlugins.git/blob - plugins/ImageGenericFilters/RegionOfInterestImageFilter.cxx
b6bc5465f2f37f49c137c020c2f65731009b1abe
[cpPlugins.git] / plugins / ImageGenericFilters / RegionOfInterestImageFilter.cxx
1 #include <ImageGenericFilters/RegionOfInterestImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/BoundingBox.h>
4
5 #include <itkRegionOfInterestImageFilter.h>
6
7 // -------------------------------------------------------------------------
8 cpPluginsImageGenericFilters::RegionOfInterestImageFilter::
9 RegionOfInterestImageFilter( )
10   : Superclass( )
11 {
12   this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
13   this->_ConfigureInput< cpPlugins::DataObjects::BoundingBox >( "BoundingBox", true, false );
14   this->_ConfigureOutput< cpPlugins::DataObjects::Image >( "Output" );
15 }
16
17 // -------------------------------------------------------------------------
18 cpPluginsImageGenericFilters::RegionOfInterestImageFilter::
19 ~RegionOfInterestImageFilter( )
20 {
21 }
22
23 // -------------------------------------------------------------------------
24 void cpPluginsImageGenericFilters::RegionOfInterestImageFilter::
25 _GenerateData( )
26 {
27   auto o = this->GetInputData( "Input" );
28   cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
29   else this->_Error( "Invalid input image." );
30 }
31
32 // -------------------------------------------------------------------------
33 template< class _TImage >
34 void cpPluginsImageGenericFilters::RegionOfInterestImageFilter::
35 _GD0( _TImage* input )
36 {
37   typedef itk::RegionOfInterestImageFilter< _TImage, _TImage > _TFilter;
38   typedef typename _TImage::IndexType  _TIndex;
39   typedef typename _TImage::PointType  _TPoint;
40   typedef typename _TImage::RegionType _TRegion;
41   typedef typename _TImage::SizeType   _TSize;
42
43   auto bb = this->GetInput< cpPlugins::DataObjects::BoundingBox >( "BoundingBox" );
44
45   _TIndex i0, i1;
46   input->TransformPhysicalPointToIndex( bb->GetMinimum< _TPoint >( ), i0 );
47   input->TransformPhysicalPointToIndex( bb->GetMaximum< _TPoint >( ), i1 );
48
49   _TSize size;
50   for( unsigned int d = 0; d < _TImage::ImageDimension; ++d )
51     size[ d ] = i1[ d ] - i0[ d ] + 1;
52
53   _TRegion region;
54   region.SetIndex( i0 );
55   region.SetSize( size );
56
57   auto filter = this->_CreateITK< _TFilter >( );
58   filter->SetInput( input );
59   filter->SetRegionOfInterest( region );
60   filter->Update( );
61   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
62 }
63
64 // eof - $RCSfile$