]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Thu, 8 Jun 2017 01:19:44 +0000 (20:19 -0500)
committerLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Thu, 8 Jun 2017 01:19:44 +0000 (20:19 -0500)
examples/sandbox.cxx
lib/fpa/Base/Algorithm.h
lib/fpa/Base/Algorithm.hxx

index d27bea9b73e2e7258bb85dacf8e9af2838ef377e..3a035be3864ac6beac8987c04e6ec72b1cb7fe64 100644 (file)
+#include <itkFunctionBase.h>
 #include <itkImage.h>
-#include <itkImageFileReader.h>
-#include <itkImageFileWriter.h>
-#include <itkMinimumMaximumImageCalculator.h>
-#include <itkImageRegionConstIteratorWithIndex.h>
-
-#include <fpa/Image/Dijkstra.h>
-#include <fpa/Image/Functors/GaussianWeight.h>
+#include <itkImageToImageFilter.h>
+#include <fpa/Base/Algorithm.h>
+#include <fpa/Base/SeedsInterface.h>
+#include <fpa/Base/MarksInterface.h>
 
 // -------------------------------------------------------------------------
-static const unsigned int VDim = 2;
-typedef short                                        TPixel;
-typedef double                                       TScalar;
-typedef itk::Image< TPixel, VDim >                   TImage;
-typedef itk::Image< TScalar, VDim >                  TScalarImage;
-typedef itk::ImageFileReader< TImage >               TReader;
-typedef itk::ImageFileWriter< TScalarImage >         TWriter;
-typedef fpa::Image::Dijkstra< TImage, TScalarImage > TFilter;
-typedef itk::MinimumMaximumImageCalculator< TImage > TMinMax;
-typedef itk::ImageRegionConstIteratorWithIndex< TImage > TIterator;
-
-typedef fpa::Image::Functors::GaussianWeight< TImage, TScalar > TVertexFunc;
+namespace fpa
+{
+  namespace Base
+  {
+    namespace Functors
+    {
+      namespace RegionGrow
+      {
+        /**
+         */
+        template< class _TValue >
+        class Tautology
+          : public itk::FunctionBase< _TValue, bool >
+        {
+        public:
+          typedef Tautology                          Self;
+          typedef itk::FunctionBase< _TValue, bool > Superclass;
+          typedef itk::SmartPointer< Self >          Pointer;
+          typedef itk::SmartPointer< const Self >    ConstPointer;
+
+        public:
+          itkNewMacro( Self );
+          itkTypeMacro(
+            fpa::Base::Functors::RegionGrow::Tautology,
+            itk::FunctionBase
+            );
+
+        public:
+          virtual bool Evaluate( const _TValue& input ) const override
+            {
+              return( true );
+            }
+        protected:
+          Tautology( )
+            : Superclass( )
+            {
+            }
+          virtual ~Tautology( )
+            {
+            }
+        private:
+          // Purposely not implemented
+          Tautology( const Self& other );
+          Self& operator=( const Self& other );
+        };
+
+      } // ecapseman
+
+    } // ecapseman
+
+  } // ecapseman
+
+} // ecapseman
 
 // -------------------------------------------------------------------------
-int main( int argc, char* argv[] )
+namespace fpa
 {
-  // Get arguments
-  if( argc < 5 )
+  namespace Base
   {
-    std::cerr
-      << "Usage: " << argv[ 0 ]
-      << " input_image input_seeds output_image beta"
-      << std::endl;
-    return( 1 );
-
-  } // fi
-  std::string input_image_filename = argv[ 1 ];
-  std::string input_seeds_filename = argv[ 2 ];
-  std::string output_image_filename = argv[ 3 ];
-  double beta = std::atof( argv[ 4 ] );
-
-  // Read seeds
-  TReader::Pointer input_seeds = TReader::New( );
-  input_seeds->SetFileName( input_seeds_filename );
-  try
+    /**
+     */
+    template< class _TAlgorithm >
+    class RegionGrow
+      : public _TAlgorithm
+    {
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+// -------------------------------------------------------------------------
+namespace fpa
+{
+  namespace Image
   {
-    input_seeds->Update( );
-  }
-  catch( std::exception& err )
+    /**
+     */
+    template< class _TInputImage >
+    class MarksInterface
+    {
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+// -------------------------------------------------------------------------
+namespace fpa
+{
+  namespace Image
   {
-    std::cerr << "Error: " << err.what( ) << std::endl;
-    return( 1 );
+    /**
+     */
+    template< class _TInputImage, class _TOutputImage, class _TSeedsInterface, class _TMarksInterface >
+    class Algorithm
+      : public fpa::Base::Algorithm< itk::ImageToImageFilter< _TInputImage, _TOutputImage >, _TSeedsInterface, _TMarksInterface >
+    {
+    };
 
-  } // yrt
-  TMinMax::Pointer minmax = TMinMax::New( );
-  minmax->SetImage( input_seeds->GetOutput( ) );
-  minmax->Compute( );
+  } // ecapseman
 
-  // Read image
-  TReader::Pointer input_image = TReader::New( );
-  input_image->SetFileName( input_image_filename );
+} // ecapseman
 
-  // Prepare dijkstra filter
-  TFilter::Pointer filter = TFilter::New( );
-  filter->SetInput( input_image->GetOutput( ) );
-  filter->StopAtOneFrontOff( );
-
-  // Assign seeds
-  /* TODO
-     TIterator sIt(
-     input_seeds->GetOutput( ),
-     input_seeds->GetOutput( )->GetRequestedRegion( )
-     );
-     for( sIt.GoToBegin( ); !sIt.IsAtEnd( ); ++sIt )
-     if( sIt.Get( ) > minmax->GetMinimum( ) )
-     filter->AddSeed( sIt.GetIndex( ) );
-  */
-  TImage::IndexType seed;
-  /* TODO
-     seed[ 0 ] = 248;
-     seed[ 1 ] = 326;
-     seed[ 2 ] = 312;
-  */
-  seed[ 0 ] = 482;
-  seed[ 1 ] = 57;
-  filter->AddSeed( seed );
+// -------------------------------------------------------------------------
+namespace fpa
+{
+  namespace Image
+  {
+    /**
+     */
+    template< class _TInputImage, class _TOutputImage >
+    class RegionGrow
+      : public fpa::Base::RegionGrow< fpa::Image::Algorithm< _TInputImage, _TOutputImage, fpa::Base::SeedsInterface< typename _TInputImage::IndexType, typename _TInputImage::IndexType::LexicographicCompare >, fpa::Image::MarksInterface< _TInputImage > > >
+    {
+    };
 
-  seed[ 0 ] = 306;
-  seed[ 1 ] = 439;
-  filter->AddSeed( seed );
+  } // ecapseman
 
-  TVertexFunc::Pointer vertex_func = TVertexFunc::New( );
-  vertex_func->SetBeta( beta );
-  filter->SetFunctor( vertex_func );
+} // ecapseman
 
-  TWriter::Pointer writer = TWriter::New( );
-  writer->SetInput( filter->GetOutput( ) );
-  writer->SetFileName( output_image_filename );
+// -------------------------------------------------------------------------
+const unsigned int Dim = 2;
+typedef short TInputPixel;
+typedef unsigned char TOutputPixel;
+typedef itk::Image< TInputPixel, Dim >  TInputImage;
+typedef itk::Image< TOutputPixel, Dim > TOutputImage;
 
-  try
-  {
-    writer->Update( );
-  }
-  catch( std::exception& err )
-  {
-    std::cerr << "ERROR: " << err.what( ) << std::endl;
-    return( 1 );
+// -------------------------------------------------------------------------
+int main( int argc, char* argv[] )
+{
+  TInputImage::IndexType seed;
+  seed.Fill( 0 );
+
+  typedef fpa::Base::Functors::RegionGrow::Tautology< TInputPixel > TPredicate;
+  TPredicate::Pointer tautology = TPredicate::New( );
+
+  typedef fpa::Image::RegionGrow< TInputImage, TOutputImage > TFilter;
+  TFilter::Pointer filter = TFilter::New( );
+  filter->SetInput( input_image );
+  filter->AddSeed( seed );
+  filter->SetPredicate( tautology );
+  filter->Update( );
 
-  } // yrt
   return( 0 );
 }
 
index b457b9e52f0e006b0192d4ef3cf8d340355eadbe..29026288e4b6a6db486ae7ade2761637de9560b9 100644 (file)
@@ -7,7 +7,11 @@
 #define __fpa__Base__Algorithm__h__
 
 #include <vector>
-
+#include <itkObject.h>
+/* TODO
+   #include <itkMacro.h>
+   #include <itkSmartPointer.h>
+*/
 namespace fpa
 {
   namespace Base
@@ -28,15 +32,15 @@ namespace fpa
       typedef itk::SmartPointer< Self >       Pointer;
       typedef itk::SmartPointer< const Self > ConstPointer;
 
-      typedef typename _TMarksInterface::TNode        TNode;
       typedef typename _TMarksInterface::TOutputValue TOutputValue;
+      typedef typename _TSeedsInterface::TNode        TNode;
       typedef typename _TSeedsInterface::TSeeds       TSeeds;
 
       typedef std::vector< TNode > TNeighborhood;
 
     public:
-      itkTypeMacro( Algorithm, TFilter );
-
+      itkTypeMacro( fpa::Base::Algorithm, _TFilter );
+      
       itkGetConstMacro( InitValue, TOutputValue );
       itkSetMacro( InitValue, TOutputValue );
 
index 3a52f789c1a60de280cc9ffedfc0b78ffbacbd2c..6af90482cef00943d3e6ee3121cb15c4d9957c5d 100644 (file)
@@ -30,7 +30,7 @@ GenerateData( )
 {
   // Init objects
   this->_ConfigureOutput( this->m_InitValue );
-  this->_InitMarks( );
+  this->_InitMarks( this->GetNumberOfSeeds( ) );
 
   // Init queue
   this->_QueueInit( );