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