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