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