From 60785c9e18cab1a338f1ce54551e97a5ddfabac1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Wed, 7 Jun 2017 20:19:44 -0500 Subject: [PATCH] ... --- examples/sandbox.cxx | 227 ++++++++++++++++++++++--------------- lib/fpa/Base/Algorithm.h | 12 +- lib/fpa/Base/Algorithm.hxx | 2 +- 3 files changed, 144 insertions(+), 97 deletions(-) diff --git a/examples/sandbox.cxx b/examples/sandbox.cxx index d27bea9..3a035be 100644 --- a/examples/sandbox.cxx +++ b/examples/sandbox.cxx @@ -1,112 +1,155 @@ +#include #include -#include -#include -#include -#include - -#include -#include +#include +#include +#include +#include // ------------------------------------------------------------------------- -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 ); } diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index b457b9e..2902628 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -7,7 +7,11 @@ #define __fpa__Base__Algorithm__h__ #include - +#include +/* TODO + #include + #include +*/ 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 ); diff --git a/lib/fpa/Base/Algorithm.hxx b/lib/fpa/Base/Algorithm.hxx index 3a52f78..6af9048 100644 --- a/lib/fpa/Base/Algorithm.hxx +++ b/lib/fpa/Base/Algorithm.hxx @@ -30,7 +30,7 @@ GenerateData( ) { // Init objects this->_ConfigureOutput( this->m_InitValue ); - this->_InitMarks( ); + this->_InitMarks( this->GetNumberOfSeeds( ) ); // Init queue this->_QueueInit( ); -- 2.47.1