]> Creatis software - cpPlugins.git/blob - plugins/ITKImageGenericFilters_1/ImageToBoundingBoxFromThreshold.cxx
ca309c6e84aa9a56fa364334c424483899764335
[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   this->m_Parameters.ConfigureAsUint( "PAD", 0 );
19 }
20
21 // -------------------------------------------------------------------------
22 cpPluginsITKImageGenericFilters_1::ImageToBoundingBoxFromThreshold::
23 ~ImageToBoundingBoxFromThreshold( )
24 {
25 }
26
27 // -------------------------------------------------------------------------
28 void cpPluginsITKImageGenericFilters_1::ImageToBoundingBoxFromThreshold::
29 _GenerateData( )
30 {
31   auto o = this->GetInputData( "Input" );
32   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
33     this->_Error( "Invalid input image." );
34 }
35
36 // -------------------------------------------------------------------------
37 template< class _TImage >
38 void cpPluginsITKImageGenericFilters_1::ImageToBoundingBoxFromThreshold::
39 _GD0( _TImage* image )
40 {
41   typedef
42     cpExtensions::Algorithms::ImageToBoundingBoxFromThreshold< _TImage >
43     _TFilter;
44
45   // Configure filter
46   _TFilter* filter = this->_CreateITK< _TFilter >( );
47   filter->SetImage( image );
48   filter->SetLowerThreshold( this->m_Parameters.GetReal( "LowerThreshold" ) );
49   filter->SetUpperThreshold( this->m_Parameters.GetReal( "UpperThreshold" ) );
50   filter->SetPAD( this->m_Parameters.GetUint( "PAD" ) );
51   filter->Compute( );
52
53   // Create output
54   auto reg = filter->GetRegion( );
55   auto bb = this->GetOutput< cpInstances::BoundingBox >( "Output" );
56   typename _TImage::PointType p0, p1;
57   image->TransformIndexToPhysicalPoint( reg.GetIndex( ), p0 );
58   image->TransformIndexToPhysicalPoint( reg.GetIndex( ) + reg.GetSize( ), p1 );
59   bb->SetMinimum( p0 );
60   bb->SetMaximum( p1 );
61 }
62
63 // eof - $RCSfile$