]> Creatis software - FrontAlgorithms.git/blobdiff - plugins/RegionGrowFunctors/BinaryThreshold.cxx
...
[FrontAlgorithms.git] / plugins / RegionGrowFunctors / BinaryThreshold.cxx
similarity index 55%
rename from plugins/Plugins/RegionGrowBinaryThresholdWithSeeds.cxx
rename to plugins/RegionGrowFunctors/BinaryThreshold.cxx
index e799ae219584e6b7a57f80afae6b8d6c8d9a039f..05010ab4974efd39bdf28d082e29b491dcbe711e 100644 (file)
@@ -1,34 +1,35 @@
-#include <Plugins/RegionGrowBinaryThresholdWithSeeds.h>
+#include <RegionGrowFunctors/BinaryThreshold.h>
 #include <cpInstances/Image.h>
-#include <cpInstances/Image_Demanglers.h>
 
 #include <fpa/Image/Functors/RegionGrowBinaryThreshold.h>
 #include <itkConstNeighborhoodIterator.h>
 #include <vtkPolyData.h>
 
 // -------------------------------------------------------------------------
-fpaPlugins::RegionGrowBinaryThresholdWithSeeds::
-RegionGrowBinaryThresholdWithSeeds( )
+fpaPluginsRegionGrowFunctors::BinaryThreshold::
+BinaryThreshold( )
   : Superclass( )
 {
   typedef cpPlugins::BaseObjects::DataObject _TData;
   typedef cpInstances::Image _TImage;
 
   this->_ConfigureInput< _TImage >( "Input", true, false );
-  this->_ConfigureInput< _TData >( "Seeds", true, false );
+  this->_ConfigureInput< _TData >( "Seeds", false, false );
   this->_ConfigureOutput< _TData >( "Output" );
 
   this->m_Parameters.ConfigureAsUint( "Radius", 1 );
+  this->m_Parameters.ConfigureAsReal( "LowerThreshold", 0 );
+  this->m_Parameters.ConfigureAsReal( "UpperThreshold", 0 );
 }
 
 // -------------------------------------------------------------------------
-fpaPlugins::RegionGrowBinaryThresholdWithSeeds::
-~RegionGrowBinaryThresholdWithSeeds( )
+fpaPluginsRegionGrowFunctors::BinaryThreshold::
+~BinaryThreshold( )
 {
 }
 
 // -------------------------------------------------------------------------
-void fpaPlugins::RegionGrowBinaryThresholdWithSeeds::
+void fpaPluginsRegionGrowFunctors::BinaryThreshold::
 _GenerateData( )
 {
   auto o = this->GetInputData( "Input" );
@@ -38,7 +39,7 @@ _GenerateData( )
 
 // -------------------------------------------------------------------------
 template< class _TImage >
-void fpaPlugins::RegionGrowBinaryThresholdWithSeeds::
+void fpaPluginsRegionGrowFunctors::BinaryThreshold::
 _GD0( _TImage* image )
 {
   typedef itk::ConstNeighborhoodIterator< _TImage > _TInIt;
@@ -57,9 +58,9 @@ _GD0( _TImage* image )
 
   // Compute thresholds from seeds
   auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
-  std::vector< typename _TImage::IndexType > indices;
   if( seeds != NULL )
   {
+    std::vector< typename _TImage::IndexType > indices;
     typename _TImage::PointType pnt;
     typename _TImage::IndexType idx;
     unsigned int dim =
@@ -77,36 +78,40 @@ _GD0( _TImage* image )
 
     } // rof
 
-  } // fi
-
-  typename _TImage::SizeType r;
-  r.Fill( this->m_Parameters.GetUint( "Radius" ) );
-  _TInIt iIt( r, image, image->GetRequestedRegion( ) );
-  double v_s1 = double( 0 );
-  double v_s2 = double( 0 );
-  double v_n = double( 0 );
-  double v_min = std::numeric_limits< double >::max( );
-  double v_max = -v_min;
-  for( auto idxIt = indices.begin( ); idxIt != indices.end( ); ++idxIt )
-  {
-    iIt.SetLocation( *idxIt );
-    for( unsigned int i = 0; i < iIt.Size( ); ++i )
+    typename _TImage::SizeType r;
+    r.Fill( this->m_Parameters.GetUint( "Radius" ) );
+    _TInIt iIt( r, image, image->GetRequestedRegion( ) );
+    double v_s1 = double( 0 );
+    double v_s2 = double( 0 );
+    double v_n = double( 0 );
+    double v_min = std::numeric_limits< double >::max( );
+    double v_max = -v_min;
+    for( auto idxIt = indices.begin( ); idxIt != indices.end( ); ++idxIt )
     {
-      double v = double( iIt.GetPixel( i ) );
-      v_s1 += v;
-      v_s2 += v * v;
-      v_n += double( 1 );
-      v_min = ( v < v_min )? v: v_min;
-      v_max = ( v_max < v )? v: v_max;
+      iIt.SetLocation( *idxIt );
+      for( unsigned int i = 0; i < iIt.Size( ); ++i )
+      {
+        double v = double( iIt.GetPixel( i ) );
+        v_s1 += v;
+        v_s2 += v * v;
+        v_n += double( 1 );
+        v_min = ( v < v_min )? v: v_min;
+        v_max = ( v_max < v )? v: v_max;
+
+      } // rof
 
     } // rof
+    double s = ( v_s2 - ( ( v_s1 * v_s1 ) / v_n ) ) / ( v_n - double( 1 ) );
+    s = std::sqrt( s ) / double( 2 );
+    f->SetLowerThreshold( v_min );
+    f->SetUpperThreshold( v_max );
+  }
+  else
+  {
+    f->SetLowerThreshold( this->m_Parameters.GetReal( "LowerThreshold" ) );
+    f->SetUpperThreshold( this->m_Parameters.GetReal( "UpperThreshold" ) );
 
-  } // rof
-  double s = ( v_s2 - ( ( v_s1 * v_s1 ) / v_n ) ) / ( v_n - double( 1 ) );
-  s = std::sqrt( s ) / double( 2 );
-
-  f->SetLowerThreshold( v_min );
-  f->SetUpperThreshold( v_max );
+  } // fi
 }
 
 // eof - $RCSfile$