]> Creatis software - FrontAlgorithms.git/commitdiff
Experiments going well :-)
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 18 Feb 2015 23:12:50 +0000 (18:12 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Wed, 18 Feb 2015 23:12:50 +0000 (18:12 -0500)
lib/fpa/Base/Algorithm.h
lib/fpa/Base/Algorithm.hxx
lib/fpa/Base/RegionGrowWithMultipleCriteria.h
lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx
lib/fpa/Base/TreeExtractor.h
lib/fpa/Base/TreeExtractor.hxx
lib/fpa/Image/Functors/RegionGrowThresholdFunction.h
lib/fpa/Image/RegionGrowWithMultipleThresholds.h
lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx
lib/fpa/VTK/Image3DObserver.hxx

index 187a281903e8aa182403a5f7e22cb74df54b7194..fc94fa85fb3dde3a52398ca30749e6e6a626383b 100644 (file)
@@ -86,6 +86,8 @@ namespace fpa
       virtual void GenerateData( );
 
       /// Base interface
+      virtual void _BeforeMainLoop     ( );
+      virtual void _AfterMainLoop      ( );
       virtual void _BeforeLoop         ( );
       virtual void _AfterLoop          ( );
       virtual void _Loop               ( );
index 286343f647d589c4e0f44607796a5f8de3c22c08..f4ccfdb5c95ae0bdce26cac35df7869783fa7ef8 100644 (file)
@@ -88,9 +88,27 @@ GenerateData( )
   this->m_CollisionSites.clear( );
   this->m_CollisionSites.
     resize( N, _TCollisionSitesRow( N, _TCollision( TVertex( ), false ) ) );
-  this->_BeforeLoop( );
+
+  this->_BeforeMainLoop( );
+  this->_InitializeMarks( );
+  this->_InitializeResults( );
+  this->_InitializeQueue( );
   this->_Loop( );
-  this->_AfterLoop( );
+  this->_AfterMainLoop( );
+}
+
+// -------------------------------------------------------------------------
+template< class T, class B >
+void fpa::Base::Algorithm< T, B >::
+_BeforeMainLoop( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class T, class B >
+void fpa::Base::Algorithm< T, B >::
+_AfterMainLoop( )
+{
 }
 
 // -------------------------------------------------------------------------
@@ -112,9 +130,7 @@ template< class T, class B >
 void fpa::Base::Algorithm< T, B >::
 _Loop( )
 {
-  this->_InitializeMarks( );
-  this->_InitializeResults( );
-  this->_InitializeQueue( );
+  this->_BeforeLoop( );
   while( !( this->_IsQueueEmpty( ) ) )
   {
     _TNode n = this->_QueuePop( );
@@ -172,6 +188,7 @@ _Loop( )
 
   } // elihw
   this->InvokeEvent( TEndEvent( ) );
+  this->_AfterLoop( );
 }
 
 // -------------------------------------------------------------------------
@@ -279,10 +296,7 @@ _Parent( const TVertex& v ) const
 {
   typename _TMarks::const_iterator mIt = this->m_Marks.find( v );
   if( mIt == this->m_Marks.end( ) )
-  {
-    TVertex v;
-    return( v );
-  }
+    return( TVertex( ) );
   else
     return( mIt->second.Parent );
 }
index 69fbc8e0a7d684092bf581bcbe7ca0eb6dd21d77..85d024332f2b477eefa493528171db52c016d7f9 100644 (file)
@@ -41,6 +41,7 @@ namespace fpa
       typedef typename Superclass::_TNode     _TNode;
       typedef typename Superclass::_TNodes    _TNodes;
       typedef typename Superclass::_TQueue    _TQueue;
+      typedef typename Superclass::_TMarks    _TMarks;
 
     public:
       itkTypeMacro( RegionGrowWithMultipleCriteria, RegionGrow );
@@ -54,8 +55,9 @@ namespace fpa
       RegionGrowWithMultipleCriteria( );
       virtual ~RegionGrowWithMultipleCriteria( );
 
-      virtual void _BeforeLoop( );
-      virtual _TNode _QueuePop( );
+      virtual void _BeforeMainLoop( );
+      virtual void _AfterLoop( );
+      virtual void _Loop( );
       virtual bool _CheckMembership( const _TNode& n ) const;
 
     private:
index 5ec51ec6681fe044d2794a6c09d6199a31a7966c..0fd4378c5fbabef49d5cd827d25e44bcfcd927d6 100644 (file)
@@ -45,29 +45,46 @@ fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
 // -------------------------------------------------------------------------
 template< class V, class R, class VV, class VC, class B >
 void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
-_BeforeLoop( )
+_BeforeMainLoop( )
 {
-  this->Superclass::_BeforeLoop( );
+  this->Superclass::_BeforeMainLoop( );
   this->m_ActualFunction = this->m_Functions.begin( );
 }
 
 // -------------------------------------------------------------------------
 template< class V, class R, class VV, class VC, class B >
-typename fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
-_TNode fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
-_QueuePop( )
+void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
+_AfterLoop( )
 {
-  _TNode node = this->Superclass::_QueuePop( );
-  if( this->_IsQueueEmpty( ) )
+  this->Superclass::_AfterLoop( );
+
+  // Replace queue
+  this->_QueueClear( );
+  while( !( this->m_AuxiliaryQueue.empty( ) ) )
   {
-    // Replace queue
-    this->m_Queue = this->m_AuxiliaryQueue;
+    // Get node
+    _TNode node = this->m_AuxiliaryQueue.front( );
+    this->m_AuxiliaryQueue.pop( );
+    this->_QueuePush( node );
 
-    // Move to next function
-    this->m_ActualFunction++;
+    // Unmark it
+    typename _TMarks::iterator mIt = this->m_Marks.find( node.Vertex );
+    if( mIt != this->m_Marks.end( ) )
+      this->m_Marks.erase( mIt );
+    
+  } // elihw
+
+  // Move to next function
+  this->m_ActualFunction++;
+}
 
-  } // fi
-  return( node );
+// -------------------------------------------------------------------------
+template< class V, class R, class VV, class VC, class B >
+void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >::
+_Loop( )
+{
+  while( this->m_ActualFunction != this->m_Functions.end( ) )
+    this->Superclass::_Loop( );
 }
 
 // -------------------------------------------------------------------------
index a0222a65248a5d61913491c0ce3fc0efcb43aac2..ee6499bfee2380256b205372d7e6efff4fd11b7f 100644 (file)
@@ -54,8 +54,8 @@ namespace fpa
       TreeExtractor( );
       virtual ~TreeExtractor( );
 
-      virtual void _BeforeLoop( );
-      virtual void _AfterLoop( );
+      virtual void _BeforeMainLoop( );
+      virtual void _AfterMainLoop( );
 
       TVertices _Path( const TVertex& s, const TVertex& e );
 
index cfeb17f887d428acd1364da91d5a689e36989545..7bad1ef78115ed1779c8841c3fdc4f5506d15720 100644 (file)
@@ -57,18 +57,18 @@ fpa::Base::TreeExtractor< A >::
 // -------------------------------------------------------------------------
 template< class A >
 void fpa::Base::TreeExtractor< A >::
-_BeforeLoop( )
+_BeforeMainLoop( )
 {
-  this->Superclass::_BeforeLoop( );
+  this->Superclass::_BeforeMainLoop( );
   this->m_Tree.clear( );
 }
 
 // -------------------------------------------------------------------------
 template< class A >
 void fpa::Base::TreeExtractor< A >::
-_AfterLoop( )
+_AfterMainLoop( )
 {
-  this->Superclass::_AfterLoop( );
+  this->Superclass::_AfterMainLoop( );
   
   // Prepare fronts graph using Floyd-Warshall
   unsigned long nSeeds = this->GetNumberOfSeeds( );
index 6da586d2249271f1017dcf78399993d2846d7bb9..739dff4c24beb40c6d76c94e3977bef3d02bc588 100644 (file)
@@ -48,21 +48,11 @@ namespace fpa
             const I* img = this->GetInputImage( );
             if( img != NULL )
             {
-              /* TODO
-                 if( this->IsInsideBuffer( idx ) )
-                 {
-              */
               TPixel v = img->GetPixel( idx );
-              std::cout
-                << v << " "
-                << this->m_LowerThreshold << " "
-                << this->m_UpperThreshold << std::endl;
               return(
                 this->m_LowerThreshold <= v && v < this->m_UpperThreshold
                 );
 
-              // TODO: } // fi
-
             } // fi
             return( false );
           }
index b4c3e4e536480c084c1ba040fa3120c3918e99fc..5156b33dbd9bce73614bd7c28734fd4be82aa37b 100644 (file)
@@ -30,7 +30,7 @@ namespace fpa
       typedef typename Superclass::TMembershipFunction TMembershipFunction;
       typedef typename Superclass::TFunctions          TFunctions;
 
-      typedef std::set< TPixel >                                     TThresholds;
+      typedef std::set< TPixel >                                   TThresholds;
       typedef fpa::Image::Functors::RegionGrowThresholdFunction< I > TFunction;
 
     protected:
@@ -55,9 +55,10 @@ namespace fpa
       RegionGrowWithMultipleThresholds( );
       virtual ~RegionGrowWithMultipleThresholds( );
 
-      virtual bool _UpdateResult( _TNode& n );
-      virtual void _BeforeLoop( );
+      virtual void _BeforeMainLoop( );
+      virtual void _AfterMainLoop( );
       virtual void _AfterLoop( );
+      virtual bool _UpdateResult( _TNode& n );
 
     private:
       RegionGrowWithMultipleThresholds( const Self& ); // Not impl.
index a5b2075b3819a45d4eff92e57b347d1a474c4f21..0cb1b66598aa225f33799855c44a4435ed376a20 100644 (file)
@@ -29,13 +29,6 @@ RegionGrowWithMultipleThresholds( )
   : Superclass( ),
     m_DerivativeThreshold( double( 3 ) )
 {
-  /* TODO
-     typedef
-     fpa::Image::Functors::RegionGrowThresholdFunction< I >
-     TFunction;
-     typename TFunction::Pointer function = TFunction::New( );
-     this->SetMembershipFunction( function );
-  */
 }
 
 // -------------------------------------------------------------------------
@@ -45,61 +38,27 @@ fpa::Image::RegionGrowWithMultipleThresholds< I >::
 {
 }
 
-// -------------------------------------------------------------------------
-template< class I >
-bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
-_UpdateResult( _TNode& n )
-{
-  bool ret = this->Superclass::_UpdateResult( n );
-  std::cout << "Image:UpdateResult " << ret << std::endl;
-
-  
-  /* 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
-  */
-  return( ret );
-}
-
 // -------------------------------------------------------------------------
 template< class I >
 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
-_BeforeLoop( )
+_BeforeMainLoop( )
 {
   const I* img = this->GetInput( );
 
   this->ClearMembershipFunctions( );
   typename TThresholds::const_iterator tIt = this->m_Thresholds.begin( );
-  typename TThresholds::const_iterator prev_tIt = tIt;
-  for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt, ++prev_tIt )
+  TPixel min_thr = *tIt;
+  for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt )
   {
     typename TFunction::Pointer function = TFunction::New( );
     function->SetInputImage( img );
-    function->SetLowerThreshold( *prev_tIt );
+    function->SetLowerThreshold( min_thr );
     function->SetUpperThreshold( *tIt );
     this->AddMembershipFunction( function );
-    std::cout << *prev_tIt << " " << *tIt << std::endl;
 
   } // rof
 
-  this->Superclass::_BeforeLoop( );
+  this->Superclass::_BeforeMainLoop( );
 }
 
 // -------------------------------------------------------------------------
@@ -107,45 +66,40 @@ template< class I >
 void fpa::Image::RegionGrowWithMultipleThresholds< I >::
 _AfterLoop( )
 {
-  /*
-    typename THistogram::iterator prevIt = this->m_Histogram.begin( );
-    typename THistogram::iterator currIt = prevIt; currIt++;
-    typename THistogram::iterator nextIt = currIt; nextIt++;
-    double prev_d1 = double( 0 );
-    for( ; nextIt != this->m_Histogram.end( ); ++prevIt, ++currIt, ++nextIt )
-    {
-    double d1 = double( nextIt->second ) - double( prevIt->second );
-    d1 /= double( nextIt->first ) - double( prevIt->first );
-
-    std::cout
-    << currIt->first  << " "
-    << currIt->second << " "
-    << d1 << " "
-    << ( d1 - prev_d1 ) << std::endl;
-
-    prev_d1 = d1;
-
-    } // rof
-  */
+  if( this->m_ActualFunction != this->m_Functions.end( ) )
+  {
+    TFunction* f =
+      dynamic_cast< TFunction* >( this->m_ActualFunction->GetPointer( ) );
+    // std::cout << f->GetUpperThreshold( ) << " " << this->m_Marks.size( ) << std::endl;
 
-  /*
-    double prev = double( 0 );
-    while( hIt != this->m_Histogram.end( ) )
-    {
-    double curr = double( hIt->second );
-    double deri = curr - prev;
+  } // fi
+  this->Superclass::_AfterLoop( );
+}
 
-    if( hIt != this->m_Histogram.begin( ) )
-    std::cout << hIt->first << " " << curr << " " << deri << std::endl;
+// -------------------------------------------------------------------------
+template< class I >
+void fpa::Image::RegionGrowWithMultipleThresholds< I >::
+_AfterMainLoop( )
+{
+  this->Superclass::_AfterMainLoop( );
+}
 
-    prev = curr;
-    hIt++;
+// -------------------------------------------------------------------------
+template< class I >
+bool fpa::Image::RegionGrowWithMultipleThresholds< I >::
+_UpdateResult( _TNode& n )
+{
+  #error ACA VOY -> explicar esto!!!! cambiar salida por una especie de curva de nivel
+  bool ret = this->Superclass::_UpdateResult( n );
+  if( this->m_ActualFunction != this->m_Functions.end( ) )
+  {
+    TFunction* f =
+      dynamic_cast< TFunction* >( this->m_ActualFunction->GetPointer( ) );
+    this->GetOutput( )->SetPixel( n.Vertex, f->GetUpperThreshold( ) );
 
-    } // rof
-  */
-  this->Superclass::_AfterLoop( );
+  } // fi
+  return( ret );
 }
-
 #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__
 
 // eof - $RCSfile$
index e79bbbe24dc5e99e3badf6febd3fea399042193e..e2986229a821f687e205eeb82f9fc7acac8c10d6 100644 (file)
@@ -167,7 +167,7 @@ Execute( const itk::Object* c, const itk::EventObject& e )
       {
         vtkRenderer* ren =
           this->m_RenderWindow->GetRenderers( )->GetFirstRenderer( );
-        ren->RemoveActor( this->m_PolyDataActor );
+        // TODO: ren->RemoveActor( this->m_PolyDataActor );
         this->Render( );
 
       } // fi