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