]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 21 Jan 2016 04:09:18 +0000 (23:09 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 21 Jan 2016 04:09:18 +0000 (23:09 -0500)
lib/fpaPlugins/ImageDijkstra.cxx
lib/fpaPlugins/ImageRegionGrow.cxx

index 75d9bebf094d02283bab7c8f08d23ccd263eddde..44c1ae6fb35b7c0dbcdb5d5a44f9a1bce3da2b4c 100644 (file)
@@ -2,7 +2,14 @@
 
 #include <cpPlugins/Interface/Image.h>
 #include <cpPlugins/Interface/PointList.h>
+
 #include <fpa/Image/Dijkstra.h>
+#include <fpa/VTK/Image2DObserver.h>
+#include <fpa/VTK/Image3DObserver.h>
+#include <fpa/Base/Functors/InvertCostFunction.h>
+
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
 
 // -------------------------------------------------------------------------
 fpaPlugins::ImageDijkstra::
@@ -15,19 +22,8 @@ ImageDijkstra( )
 
   this->m_Parameters->ConfigureAsBool( "VisualDebug" );
   this->m_Parameters->ConfigureAsBool( "StopAtOneFront" );
-
-  /*
-    this->m_Parameters->ConfigureAsReal( "InsideValue" );
-    this->m_Parameters->ConfigureAsReal( "OutsideValue" );
-    // TODO: this->m_Parameters->ConfigureAsPointList( "Seeds" );
-    */
-
   this->m_Parameters->SetBool( "VisualDebug", false );
   this->m_Parameters->SetBool( "StopAtOneFront", false );
-  /*
-    this->m_Parameters->SetReal( "InsideValue", 1 );
-    this->m_Parameters->SetReal( "OutsideValue", 0 );
-  */
 
   std::vector< std::string > orders;
   orders.push_back( "1" );
@@ -64,43 +60,35 @@ template< class I >
 std::string fpaPlugins::ImageDijkstra::
 _GD0( itk::DataObject* data )
 {
-  /* TODO
-  typedef unsigned char                               _TOutPixel;
-  typedef itk::Image< _TOutPixel, I::ImageDimension > _TOut;
-  typedef fpa::Image::Dijkstra< I, _TOut >          _TFilter;
-  typedef typename _TFilter::TGrowingFunction         _TFunctor;
-  typedef typename I::PointType                       _TPoint;
+  typedef typename I::PixelType                             _TOutPixel;
+  typedef itk::Image< _TOutPixel, I::ImageDimension >       _TOut;
+  typedef fpa::Image::Dijkstra< I, _TOut >                  _TFilter;
+  typedef typename _TFilter::TResult                        _TCost;
+  typedef fpa::Base::Functors::InvertCostFunction< _TCost > _TCostFunctor;
+  typedef typename I::PointType                             _TPoint;
 
   cpPlugins::Interface::PointList* seeds =
     this->GetInput< cpPlugins::Interface::PointList >( "Seeds" );
   if( seeds == NULL )
-    return( "fpaPlugins::ImageDijkstra: No given seeds." );
+    return( "fpaPlugins::ImageRegionGrow: No given seeds." );
   I* image = dynamic_cast< I* >( data );
 
   // Create filter and connect input
   _TFilter* filter = this->_CreateITK< _TFilter >( );
   filter->SetInput( image );
 
-  // Connect grow functor (or create a tautology)
-  typename _TFunctor::Pointer functor;
-  cpPlugins::Interface::DataObject* functor_wrapper =
-    this->GetInput< cpPlugins::Interface::DataObject >( "GrowFunction" );
-  if( functor_wrapper != NULL )
-    functor = functor_wrapper->GetITK< _TFunctor >( );
-  if( functor.IsNull( ) )
-    functor =
-      fpa::Image::Functors::DijkstraAllBelongsFunction< I >::New( );
-  filter->SetGrowingFunction( functor );
+  // Connect cost functor
+  typename _TCostFunctor::Pointer functor = _TCostFunctor::New( );
+  filter->SetConversionFunction( functor );
 
   // Set numeric parameters
   Superclass::TParameters* params = this->m_Parameters;
   std::string order = params->GetSelectedChoice( "NeighborhoodOrder" );
   filter->SetNeighborhoodOrder( order[ 0 ] - '0' );
   filter->SetStopAtOneFront( params->GetBool( "StopAtOneFront" ) );
-  filter->SetInsideValue( _TOutPixel( params->GetReal( "InsideValue" ) ) );
-  filter->SetOutsideValue( _TOutPixel( params->GetReal( "OutsideValue" ) ) );
 
   // Assign seeds
+  filter->ClearSeeds( );
   for( unsigned int s = 0; s < seeds->GetNumberOfPoints( ); ++s )
   {
     _TPoint pnt = seeds->GetPoint< _TPoint >( s );
@@ -111,11 +99,45 @@ _GD0( itk::DataObject* data )
   } // rof
 
   // Connect visual debugger
-  // TODO: this->m_Parameters->ConfigureAsBool( "VisualDebug", false );
+  std::set< unsigned long > observers;
+  if(
+    this->m_Parameters->GetBool( "VisualDebug" ) &&
+    this->m_Interactors.size( ) > 0
+    )
+  {
+    if( I::ImageDimension == 2 )
+    {
+      typedef
+        fpa::VTK::Image2DObserver< _TFilter, vtkRenderWindow >
+        _TDebugger;
+
+      for(
+        auto iIt = this->m_Interactors.begin( );
+        iIt != this->m_Interactors.end( );
+        ++iIt
+        )
+      {
+        typename _TDebugger::Pointer debugger = _TDebugger::New( );
+        debugger->SetRenderWindow( ( *iIt )->GetRenderWindow( ) );
+        debugger->SetRenderPercentage( 0.01 );
+        observers.insert( filter->AddObserver( itk::AnyEvent( ), debugger ) );
+
+      } // rof
+      filter->ThrowEventsOn( );
+    }
+    else if( I::ImageDimension == 3 )
+    {
+    } // fi
+
+  } // fi
 
   // Go!!!
   filter->Update( );
 
+  // Remove observers (if any)
+  for( auto oIt = observers.begin( ); oIt != observers.end( ); ++oIt )
+    filter->RemoveObserver( *oIt );
+
   // Connect output
   cpPlugins::Interface::Image* out =
     this->GetOutput< cpPlugins::Interface::Image >( "Output" );
@@ -126,8 +148,6 @@ _GD0( itk::DataObject* data )
   }
   else
     return( "fpaPlugins::ImageDijkstra: output not correctly created." );
-  */
-  return( "" );
 }
 
 // eof - $RCSfile$
index 21bb43cd902af905b65aa394e0b5e96b7090ef85..92904e3c91a3a16c604de50df39801fdc4f61d83 100644 (file)
@@ -105,6 +105,7 @@ _GD0( itk::DataObject* data )
   filter->SetOutsideValue( _TOutPixel( params->GetReal( "OutsideValue" ) ) );
 
   // Assign seeds
+  filter->ClearSeeds( );
   for( unsigned int s = 0; s < seeds->GetNumberOfPoints( ); ++s )
   {
     _TPoint pnt = seeds->GetPoint< _TPoint >( s );