]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx
Multiple thresholds region grow segmentation almost added.
[FrontAlgorithms.git] / lib / fpa / Image / RegionGrowWithMultipleThresholds.hxx
index def89d95dc4dfac6c1d6de976b04b48ce31d81e6..51e474b958b9f41e8caf9c4e3a91dc5990a27a67 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
 #define __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
 
+#include <limits>
 #include <fpa/Image/Functors/RegionGrowThresholdFunction.h>
 
 // -------------------------------------------------------------------------
@@ -8,22 +9,35 @@ template< class I >
 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
 AddThreshold( const TPixel& v )
 {
-  this->m_Histogram[ v ] = 0;
+  typedef
+    fpa::Image::Functors::RegionGrowThresholdFunction< I >
+    TFunction;
+  typename TFunction::Pointer function = TFunction::New( );
+
+  if( this->GetNumberOfMembershipFunctions( ) > 0 )
+  {
+  }
+  else
+    function->SetLowerThreshold( std::numeric_limits< TPixel >::min( ) );
+  std::cout
+    << typeid( TPixel ).name( ) << " "
+    << function->GetLowerThreshold( )
+    << std::endl;
+  function->SetUpperThreshold( v );
+  this->AddMembershipFunction( function );
 
   /* TODO
-     typedef
-     fpa::Image::Functors::RegionGrowThresholdFunction< I >
-     TFunction;
+     this->m_Histogram[ v ] = 0;
+
      TFunction* function =
      dynamic_cast< TFunction* >( this->GetMembershipFunction( ) );
      if( function != NULL )
      {
      function->SetLowerThreshold( this->m_Histogram.begin( )->first );
-     function->SetUpperThreshold( this->m_Histogram.rbegin( )->first );
 
      } // fi
+     this->Modified( );
   */
-  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
@@ -43,11 +57,13 @@ RegionGrowWithMultipleThresholds( )
   : Superclass( ),
     m_DerivativeThreshold( double( 3 ) )
 {
-  typedef
-    fpa::Image::Functors::RegionGrowThresholdFunction< I >
-    TFunction;
-  typename TFunction::Pointer function = TFunction::New( );
-  this->SetMembershipFunction( function );
+  /* TODO
+     typedef
+     fpa::Image::Functors::RegionGrowThresholdFunction< I >
+     TFunction;
+     typename TFunction::Pointer function = TFunction::New( );
+     this->SetMembershipFunction( function );
+  */
 }
 
 // -------------------------------------------------------------------------
@@ -64,28 +80,50 @@ _UpdateResult( _TNode& n )
 {
   bool ret = this->Superclass::_UpdateResult( n );
 
-  if( ret )
-  {
-    TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) );
+  /* TODO
+     if( ret )
+     {
+     TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) );
 
-    typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( );
-    while( hIt != this->m_Histogram.rend( ) )
-    {
-      if( v <= hIt->first )
-      {
-        hIt->second += 1;
-        hIt++;
-      }
-      else
-        hIt = this->m_Histogram.rend( );
-
-    } // elihw
-    this->GetOutput( )->SetPixel( n.Vertex, v );
-
-  } // fi
+     typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( );
+     while( hIt != this->m_Histogram.rend( ) )
+     {
+     if( v <= hIt->first )
+     {
+     hIt->second += 1;
+     hIt++;
+     }
+     else
+     hIt = this->m_Histogram.rend( );
+
+     } // elihw
+     this->GetOutput( )->SetPixel( n.Vertex, v );
+
+     } // fi
+  */
   return( ret );
 }
 
+// -------------------------------------------------------------------------
+template< class I >
+void fpa::Image::RegionGrowWithMultipleThresholds< I >::
+_BeforeLoop( )
+{
+  std::cout << "**1" << std::endl;
+  const I* img = this->GetInput( );
+  std::cout << "**2" << std::endl;
+  typename TFunctions::iterator fIt = this->m_Functions.begin( );
+  for( ; fIt != this->m_Functions.end( ); ++fIt )
+  {
+    TMembershipFunction* f =
+      dynamic_cast< TMembershipFunction* >( fIt->GetPointer( ) );
+    if( f != NULL )
+      f->SetInputImage( this->GetInput( ) );
+
+  } // rof
+  this->Superclass::_BeforeLoop( );
+}
+
 // -------------------------------------------------------------------------
 template< class I >
 void fpa::Image::RegionGrowWithMultipleThresholds< I >::