]> Creatis software - cpPlugins.git/blob - plugins/ImageThresholdFilters/ImageToBoundingBoxFromThreshold.cxx
4b86d54fc8a80dcdcc67c9c9523e1adc8a4614d8
[cpPlugins.git] / plugins / ImageThresholdFilters / ImageToBoundingBoxFromThreshold.cxx
1 #include <ImageThresholdFilters/ImageToBoundingBoxFromThreshold.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
4 #include <cpPlugins/DataObjects/BoundingBox.h>
5
6 #include <itkImage.h>
7 #include <cpExtensions/Algorithms/ImageToBoundingBoxFromThreshold.h>
8
9 // -------------------------------------------------------------------------
10 cpPluginsImageThresholdFilters::ImageToBoundingBoxFromThreshold::
11 ImageToBoundingBoxFromThreshold( )
12   : Superclass( )
13 {
14   typedef cpPlugins::DataObjects::Image _TImage;
15   typedef cpPlugins::DataObjects::BoundingBox _TBBox;
16
17   this->_ConfigureInput< _TImage >( "Input", true, false );
18   this->_ConfigureOutput< _TBBox >( "Output" );
19
20   this->m_Parameters.ConfigureAsReal( "LowerThreshold", 0 );
21   this->m_Parameters.ConfigureAsReal( "UpperThreshold", 0 );
22 }
23
24 // -------------------------------------------------------------------------
25 cpPluginsImageThresholdFilters::ImageToBoundingBoxFromThreshold::
26 ~ImageToBoundingBoxFromThreshold( )
27 {
28 }
29
30 // -------------------------------------------------------------------------
31 void cpPluginsImageThresholdFilters::ImageToBoundingBoxFromThreshold::
32 _GenerateData( )
33 {
34   auto o = this->GetInputData( "Input" );
35   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
36     this->_Error( "Invalid input image." );
37 }
38
39 // -------------------------------------------------------------------------
40 template< class _TImage >
41 void cpPluginsImageThresholdFilters::ImageToBoundingBoxFromThreshold::
42 _GD0( _TImage* image )
43 {
44   typedef
45     cpExtensions::Algorithms::ImageToBoundingBoxFromThreshold< _TImage >
46     _TFilter;
47
48   // Configure filter
49   _TFilter* filter = this->_CreateITK< _TFilter >( );
50   filter->SetImage( image );
51   filter->SetLowerThreshold( this->m_Parameters.GetReal( "LowerThreshold" ) );
52   filter->SetUpperThreshold( this->m_Parameters.GetReal( "UpperThreshold" ) );
53   filter->Compute( );
54
55   // Create output
56   auto reg = filter->GetRegion( );
57   auto bb = this->GetOutput< cpPlugins::DataObjects::BoundingBox >( "Output" );
58   typename _TImage::PointType p0, p1;
59   image->TransformIndexToPhysicalPoint( reg.GetIndex( ), p0 );
60   image->TransformIndexToPhysicalPoint( reg.GetIndex( ) + reg.GetSize( ), p1 );
61   bb->SetMinimum( p0 );
62   bb->SetMaximum( p1 );
63 }
64
65 // eof - $RCSfile$