]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 19 Jan 2016 22:54:08 +0000 (17:54 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Tue, 19 Jan 2016 22:54:08 +0000 (17:54 -0500)
lib/fpaPlugins/CMakeLists.txt
lib/fpaPlugins/ImageDijkstra.cxx [new file with mode: 0644]
lib/fpaPlugins/ImageDijkstra.h [new file with mode: 0644]
lib/fpaPlugins/ImageRegionGrow.cxx

index 4b9bf2ee1a01d877745f6e74dc877795691b6c93..a71c325c599ec75d4c88fa219aef36048281783f 100644 (file)
@@ -14,6 +14,7 @@ SET(
   AllPixelsImageGrowFunctionSource.h
   ThresholdImageGrowFunctionSource.h
   ImageRegionGrow.h
+  ImageDijkstra.h
   )
 SET(
   data_LIB_SOURCES
@@ -24,6 +25,7 @@ SET(
   AllPixelsImageGrowFunctionSource.cxx
   ThresholdImageGrowFunctionSource.cxx
   ImageRegionGrow.cxx
+  ImageDijkstra.cxx
   )
 INCLUDE_DIRECTORIES(
   ${PROJECT_SOURCE_DIR}/lib/fpaPlugins
diff --git a/lib/fpaPlugins/ImageDijkstra.cxx b/lib/fpaPlugins/ImageDijkstra.cxx
new file mode 100644 (file)
index 0000000..0f88d8e
--- /dev/null
@@ -0,0 +1,133 @@
+#include "ImageDijkstra.h"
+
+#include <cpPlugins/Interface/Image.h>
+#include <cpPlugins/Interface/PointList.h>
+#include <fpa/Image/Dijkstra.h>
+
+// -------------------------------------------------------------------------
+fpaPlugins::ImageDijkstra::
+ImageDijkstra( )
+  : Superclass( )
+{
+  this->_AddInput( "Input" );
+  this->_AddInput( "Seeds" );
+  this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
+
+  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" );
+  orders.push_back( "2" );
+  this->m_Parameters->ConfigureAsChoices( "NeighborhoodOrder", orders );
+  this->m_Parameters->SetSelectedChoice( "NeighborhoodOrder", "1" );
+}
+
+// -------------------------------------------------------------------------
+fpaPlugins::ImageDijkstra::
+~ImageDijkstra( )
+{
+}
+
+// -------------------------------------------------------------------------
+std::string fpaPlugins::ImageDijkstra::
+_GenerateData( )
+{
+  cpPlugins::Interface::Image* input =
+    this->GetInput< cpPlugins::Interface::Image >( "Input" );
+  if( input == NULL )
+    return( "fpaPlugins::ImageDijkstra: No input image." );
+
+  itk::DataObject* image = NULL;
+  std::string r = "";
+  cpPlugins_Image_Demangle_AllScalarTypes( 2, input, image, r, _GD0 );
+  else cpPlugins_Image_Demangle_AllScalarTypes( 3, input, image, r, _GD0 );
+  else r = "fpaPlugins::ImageDijkstra: Input image type not supported.";
+  return( r );
+}
+
+// -------------------------------------------------------------------------
+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;
+
+  cpPlugins::Interface::PointList* seeds =
+    this->GetInput< cpPlugins::Interface::PointList >( "Seeds" );
+  if( seeds == NULL )
+    return( "fpaPlugins::ImageDijkstra: 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 );
+
+  // 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
+  for( unsigned int s = 0; s < seeds->GetNumberOfPoints( ); ++s )
+  {
+    _TPoint pnt = seeds->GetPoint< _TPoint >( s );
+    typename I::IndexType idx;
+    if( image->TransformPhysicalPointToIndex( pnt, idx ) )
+      filter->AddSeed( idx, 0 );
+
+  } // rof
+
+  // Connect visual debugger
+  // TODO: this->m_Parameters->ConfigureAsBool( "VisualDebug", false );
+
+  // Go!!!
+  filter->Update( );
+
+  // Connect output
+  cpPlugins::Interface::Image* out =
+    this->GetOutput< cpPlugins::Interface::Image >( "Output" );
+  if( out != NULL )
+  {
+    out->SetITK< _TOut >( filter->GetOutput( ) );
+    return( "" );
+  }
+  else
+    return( "fpaPlugins::ImageDijkstra: output not correctly created." );
+  */
+  return( "" );
+}
+
+// eof - $RCSfile$
diff --git a/lib/fpaPlugins/ImageDijkstra.h b/lib/fpaPlugins/ImageDijkstra.h
new file mode 100644 (file)
index 0000000..c8f9d90
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef __FPAPLUGINS__IMAGEDIJKSTRA__H__
+#define __FPAPLUGINS__IMAGEDIJKSTRA__H__
+
+#include <fpaPlugins/fpaPlugins_Export.h>
+#include <cpPlugins/Interface/BaseProcessObjects.h>
+
+namespace fpaPlugins
+{
+  /**
+   */
+  class fpaPlugins_EXPORT ImageDijkstra
+    : public cpPlugins::Interface::ImageToImageFilter
+  {
+  public:
+    typedef ImageDijkstra                          Self;
+    typedef cpPlugins::Interface::ImageToImageFilter Superclass;
+    typedef itk::SmartPointer< Self >                Pointer;
+    typedef itk::SmartPointer< const Self >          ConstPointer;
+
+  public:
+    itkNewMacro( Self );
+    itkTypeMacro(
+      ImageDijkstra, cpPlugins::Interface::ImageToImageFilter
+      );
+    cpPlugins_Id_Macro(
+      ImageDijkstra, FrontPropagationImageAlgorithm
+      );
+
+  protected:
+    ImageDijkstra( );
+    virtual ~ImageDijkstra( );
+
+    virtual std::string _GenerateData( );
+
+    template< class I >
+      std::string _GD0( itk::DataObject* data );
+
+  private:
+    // Purposely not implemented.
+    ImageDijkstra( const Self& other );
+    Self& operator=( const Self& other );
+  };
+
+  // ---------------------------------------------------------------------
+  CPPLUGINS_INHERIT_PROVIDER( ImageDijkstra );
+
+} // ecapseman
+
+#endif // __FPAPLUGINS__IMAGEDIJKSTRA__H__
+
+// eof - $RCSfile$
index 86c67e748480012ab377284e6248b6af573c03d6..0780fe028c1b604ca7494f4157494e11ec396ace 100644 (file)
@@ -1,8 +1,10 @@
 #include "ImageRegionGrow.h"
 
 #include <cpPlugins/Interface/Image.h>
+#include <cpPlugins/Interface/PointList.h>
 #include <fpa/Image/RegionGrow.h>
 #include <fpa/Image/Functors/RegionGrowAllBelongsFunction.h>
+#include <fpaPlugins/GrowFunction.h>
 
 // -------------------------------------------------------------------------
 fpaPlugins::ImageRegionGrow::
@@ -11,13 +13,14 @@ ImageRegionGrow( )
 {
   this->_AddInput( "Input" );
   this->_AddInput( "GrowFunction" );
+  this->_AddInput( "Seeds" );
   this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
 
   this->m_Parameters->ConfigureAsBool( "VisualDebug" );
   this->m_Parameters->ConfigureAsBool( "StopAtOneFront" );
   this->m_Parameters->ConfigureAsReal( "InsideValue" );
   this->m_Parameters->ConfigureAsReal( "OutsideValue" );
-  this->m_Parameters->ConfigureAsPointList( "Seeds" );
+  // TODO: this->m_Parameters->ConfigureAsPointList( "Seeds" );
 
   this->m_Parameters->SetBool( "VisualDebug", false );
   this->m_Parameters->SetBool( "StopAtOneFront", false );
@@ -28,6 +31,7 @@ ImageRegionGrow( )
   orders.push_back( "1" );
   orders.push_back( "2" );
   this->m_Parameters->ConfigureAsChoices( "NeighborhoodOrder", orders );
+  this->m_Parameters->SetSelectedChoice( "NeighborhoodOrder", "1" );
 }
 
 // -------------------------------------------------------------------------
@@ -64,6 +68,10 @@ _GD0( itk::DataObject* data )
   typedef typename _TFilter::TGrowingFunction         _TFunctor;
   typedef typename I::PointType                       _TPoint;
 
+  cpPlugins::Interface::PointList* seeds =
+    this->GetInput< cpPlugins::Interface::PointList >( "Seeds" );
+  if( seeds == NULL )
+    return( "fpaPlugins::ImageRegionGrow: No given seeds." );
   I* image = dynamic_cast< I* >( data );
 
   // Create filter and connect input
@@ -79,6 +87,7 @@ _GD0( itk::DataObject* data )
   if( functor.IsNull( ) )
     functor =
       fpa::Image::Functors::RegionGrowAllBelongsFunction< I >::New( );
+  filter->SetGrowingFunction( functor );
 
   // Set numeric parameters
   Superclass::TParameters* params = this->m_Parameters;
@@ -89,12 +98,11 @@ _GD0( itk::DataObject* data )
   filter->SetOutsideValue( _TOutPixel( params->GetReal( "OutsideValue" ) ) );
 
   // Assign seeds
-  std::vector< _TPoint > seeds =
-    params->GetPointList< _TPoint >( "Seeds", I::ImageDimension );
-  for( auto sIt = seeds.begin( ); sIt != seeds.end( ); ++sIt )
+  for( unsigned int s = 0; s < seeds->GetNumberOfPoints( ); ++s )
   {
+    _TPoint pnt = seeds->GetPoint< _TPoint >( s );
     typename I::IndexType idx;
-    if( image->TransformPhysicalPointToIndex( *sIt, idx ) )
+    if( image->TransformPhysicalPointToIndex( pnt, idx ) )
       filter->AddSeed( idx, 0 );
 
   } // rof