From: Leonardo Flórez-Valencia Date: Fri, 3 Mar 2017 16:49:42 +0000 (-0500) Subject: ... X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=40fb0405cfef444001429f8ba49c407ce9168a94;p=FrontAlgorithms.git ... --- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index acb1bc5..e6d93b8 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,6 +4,7 @@ IF(BUILD_Examples) SET( _examples RegionGrow_00 + FastMarching_00 MoriRegionGrow_00 Skeleton_00 ) diff --git a/examples/FastMarching_00.cxx b/examples/FastMarching_00.cxx new file mode 100644 index 0000000..41ed61e --- /dev/null +++ b/examples/FastMarching_00.cxx @@ -0,0 +1,55 @@ +#include +#include +#include + +// ------------------------------------------------------------------------- +typedef itk::Image< float, 2 > TImage; +typedef fpa::Image::FastMarching< TImage, TImage > TFilter; +typedef itk::ImageFileWriter< TImage > TWriter; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + TImage::SizeType size; + size.Fill( 512 ); + + TImage::SpacingType spac; + spac[ 0 ] = 0.4; + spac[ 1 ] = 1.7; + + TImage::Pointer input = TImage::New( ); + input->SetRegions( size ); + input->SetSpacing( spac ); + input->Allocate( ); + input->FillBuffer( 1 ); + + TImage::RegionType region = input->GetLargestPossibleRegion( ); + TImage::PointType p0, p1, p2, p3, p4; + input->TransformIndexToPhysicalPoint( region.GetIndex( ), p0 ); + input->TransformIndexToPhysicalPoint( + region.GetIndex( ) + region.GetSize( ), p1 + ); + p2 = ( p0.GetVectorFromOrigin( ) + p1.GetVectorFromOrigin( ) ) * 0.5; + p3 = ( p0.GetVectorFromOrigin( ) + p1.GetVectorFromOrigin( ) ) * 0.25; + p4 = ( p0.GetVectorFromOrigin( ) + p1.GetVectorFromOrigin( ) ) * 0.75; + TImage::IndexType s0, s1, s2; + input->TransformPhysicalPointToIndex( p2, s0 ); + input->TransformPhysicalPointToIndex( p3, s1 ); + input->TransformPhysicalPointToIndex( p4, s2 ); + + TFilter::Pointer filter = TFilter::New( ); + filter->SetInput( input ); + filter->AddSeed( s0, 0 ); + filter->AddSeed( s1, 0 ); + filter->AddSeed( s2, 0 ); + filter->Update( ); + + TWriter::Pointer writer = TWriter::New( ); + writer->SetInput( filter->GetOutput( ) ); + writer->SetFileName( "FastMarching_00.mhd" ); + writer->Update( ); + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index 1a2394c..6625467 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -5,6 +5,7 @@ #include #include #include +#include namespace fpa { @@ -29,6 +30,8 @@ namespace fpa // Different functions typedef std::vector< TVertex > TNeighborhood; typedef itk::FunctionBase< TVertex, TNeighborhood > TNeighborhoodFunction; + typedef itk::FunctionBase< TOutput, TOutput > TConversionFunction; + typedef fpa::Base::Functors::VertexCostFunctionBase< TVertex, TOutput > TVertexFunction; // Minigraph to represent collisions typedef std::pair< _TVertex, bool > TCollision; @@ -66,7 +69,16 @@ namespace fpa itkSetMacro( StopAtOneFront, bool ); itkGetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction ); + itkGetObjectMacro( ConversionFunction, TConversionFunction ); + itkGetObjectMacro( VertexFunction, TVertexFunction ); + + itkGetConstObjectMacro( NeighborhoodFunction, TNeighborhoodFunction ); + itkGetConstObjectMacro( ConversionFunction, TConversionFunction ); + itkGetConstObjectMacro( VertexFunction, TVertexFunction ); + itkSetObjectMacro( NeighborhoodFunction, TNeighborhoodFunction ); + itkSetObjectMacro( ConversionFunction, TConversionFunction ); + itkSetObjectMacro( VertexFunction, TVertexFunction ); public: void ClearSeeds( ); @@ -90,12 +102,16 @@ namespace fpa virtual bool _ValidLoop( ) const; virtual void _UpdateCollisions( const TVertex& a, const TVertex& b ); + virtual _TOutput _GetInputValue( const _TQueueNode& v, const _TQueueNode& p ); + virtual void _InitMarks( ) = 0; virtual void _InitResults( const TOutput& init_value ) = 0; virtual bool _IsMarked( const _TVertex& v ) const = 0; virtual void _Mark( const _TQueueNode& n ) = 0; virtual TFrontId _GetMark( const _TVertex& v ) const = 0; virtual void _UpdateResult( const _TQueueNode& n ) = 0; + virtual TOutput _GetResult( const _TVertex& v ) const = 0; + virtual unsigned int _GetNumberOfDimensions( ) const = 0; virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) = 0; virtual unsigned long _QueueSize( ) const = 0; @@ -111,7 +127,11 @@ namespace fpa protected: _TOutput m_InitResult; bool m_StopAtOneFront; + typename TNeighborhoodFunction::Pointer m_NeighborhoodFunction; + typename TConversionFunction::Pointer m_ConversionFunction; + typename TVertexFunction::Pointer m_VertexFunction; + std::vector< _TQueueNode > m_Seeds; TCollisions m_Collisions; unsigned int m_NumberOfFronts; diff --git a/lib/fpa/Base/Algorithm.hxx b/lib/fpa/Base/Algorithm.hxx index df71336..c29ff03 100644 --- a/lib/fpa/Base/Algorithm.hxx +++ b/lib/fpa/Base/Algorithm.hxx @@ -251,6 +251,19 @@ _UpdateCollisions( const TVertex& a, const TVertex& b ) } // fi } +// ------------------------------------------------------------------------- +template < class _TFilter, class _TVertex, class _TOutput > +_TOutput fpa::Base::Algorithm< _TFilter, _TVertex, _TOutput >:: +_GetInputValue( const _TQueueNode& v, const _TQueueNode& p ) +{ + _TOutput res = this->m_InitResult; + if( this->m_VertexFunction.IsNotNull( ) ) + res = this->m_VertexFunction->Evaluate( v.Vertex, p.Vertex ); + if( this->m_ConversionFunction.IsNotNull( ) ) + res = this->m_ConversionFunction->Evaluate( res ); + return( res ); +} + #endif // __fpa__Base__Algorithm__hxx__ // eof - $RCSfile$ diff --git a/lib/fpa/Base/Dijkstra.h b/lib/fpa/Base/Dijkstra.h index aa62f90..08c704e 100644 --- a/lib/fpa/Base/Dijkstra.h +++ b/lib/fpa/Base/Dijkstra.h @@ -1,10 +1,7 @@ #ifndef __fpa__Base__Dijkstra__h__ #define __fpa__Base__Dijkstra__h__ -#include -#include -#include -#include +#include namespace fpa { @@ -14,40 +11,24 @@ namespace fpa */ template< class _TSuperclass, class _TMST > class Dijkstra - : public _TSuperclass + : public fpa::Base::PriorityQueueAlgorithm< _TSuperclass > { public: - typedef Dijkstra Self; - typedef _TSuperclass Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; + typedef Dijkstra Self; + typedef fpa::Base::PriorityQueueAlgorithm< _TSuperclass > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; typedef _TMST TMST; typedef typename Superclass::TOutput TOutput; typedef typename Superclass::TVertex TVertex; - typedef itk::FunctionBase< TOutput, TOutput > TCostConversionFunction; - typedef DijkstraCostFunctionBase< TVertex, TOutput > TCostFunction; - protected: typedef typename Superclass::_TQueueNode _TQueueNode; - struct _TQueueNodeCompare - { - bool operator( )( const _TQueueNode& a, const _TQueueNode& b ) - { - return( b.Result < a.Result ); - } - }; - typedef std::vector< _TQueueNode > _TQueue; public: itkTypeMacro( Dijkstra, Algorithm ); - itkGetObjectMacro( CostFunction, TCostFunction ); - itkGetObjectMacro( CostConversionFunction, TCostConversionFunction ); - itkSetObjectMacro( CostFunction, TCostFunction ); - itkSetObjectMacro( CostConversionFunction, TCostConversionFunction ); - public: _TMST* GetMinimumSpanningTree( ); const _TMST* GetMinimumSpanningTree( ) const; @@ -62,10 +43,6 @@ namespace fpa virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) override; - virtual unsigned long _QueueSize( ) const override; - virtual void _QueueClear( ) override; - virtual void _QueuePush( const _TQueueNode& node ) override; - virtual _TQueueNode _QueuePop( ) override; private: // Purposely not defined @@ -73,10 +50,6 @@ namespace fpa Self& operator=( const Self& other ); protected: - _TQueue m_Queue; - typename TCostFunction::Pointer m_CostFunction; - typename TCostConversionFunction::Pointer m_CostConversionFunction; - unsigned long m_MSTIndex; }; diff --git a/lib/fpa/Base/Dijkstra.hxx b/lib/fpa/Base/Dijkstra.hxx index 849ff6c..df9c75e 100644 --- a/lib/fpa/Base/Dijkstra.hxx +++ b/lib/fpa/Base/Dijkstra.hxx @@ -75,9 +75,7 @@ template< class _TSuperclass, class _TMST > bool fpa::Base::Dijkstra< _TSuperclass, _TMST >:: _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) { - v.Result = this->m_CostFunction->Evaluate( p.Vertex, v.Vertex ); - if( this->m_CostConversionFunction.IsNotNull( ) ) - v.Result = this->m_CostConversionFunction->Evaluate( v.Result ); + v.Result = this->_GetInputValue( p.Vertex, v.Vertex ); if( v.Result >= TOutput( 0 ) ) { v.Result += p.Result; @@ -91,45 +89,6 @@ _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) } // fi } -// ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -unsigned long fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_QueueSize( ) const -{ - return( this->m_Queue.size( ) ); -} - -// ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -void fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_QueueClear( ) -{ - this->m_Queue.clear( ); -} - -// ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -void fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_QueuePush( const _TQueueNode& node ) -{ - static _TQueueNodeCompare cmp; - this->m_Queue.push_back( node ); - std::push_heap( this->m_Queue.begin( ), this->m_Queue.end( ), cmp ); -} - -// ------------------------------------------------------------------------- -template< class _TSuperclass, class _TMST > -typename fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_TQueueNode fpa::Base::Dijkstra< _TSuperclass, _TMST >:: -_QueuePop( ) -{ - static _TQueueNodeCompare cmp; - std::pop_heap( this->m_Queue.begin( ), this->m_Queue.end( ), cmp ); - _TQueueNode f = this->m_Queue.back( ); - this->m_Queue.pop_back( ); - return( f ); -} - #endif // __fpa__Base__Dijkstra__hxx__ // eof - $RCSfile$ diff --git a/lib/fpa/Base/DijkstraCostFunctionBase.h b/lib/fpa/Base/DijkstraCostFunctionBase.h deleted file mode 100644 index d3a86b2..0000000 --- a/lib/fpa/Base/DijkstraCostFunctionBase.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef __fpa__Base__DijkstraCostFunctionBase__h__ -#define __fpa__Base__DijkstraCostFunctionBase__h__ - -#include -#include - -namespace fpa -{ - namespace Base - { - /** - */ - template< class _TVertex, class _TOutput > - class DijkstraCostFunctionBase - : public itk::Object - { - public: - typedef DijkstraCostFunctionBase Self; - typedef itk::Object Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; - - typedef _TVertex TVertex; - typedef _TOutput TOutput; - - public: - itkTypeMacro( DijkstraCostFunctionBase, itk::Object ); - - public: - virtual TOutput Evaluate( const TVertex& a, const TVertex& b ) const = 0; - - protected: - DijkstraCostFunctionBase( ) - : Superclass( ) - { } - virtual ~DijkstraCostFunctionBase( ) - { } - - private: - // Purposely not defined - DijkstraCostFunctionBase( const Self& other ); - Self& operator=( const Self& other ); - }; - - } // ecapseman - -} // ecapseman - -#endif // __fpa__Base__DijkstraCostFunctionBase__h__ - -// eof - $RCSfile$ diff --git a/lib/fpa/Base/FastMarching.h b/lib/fpa/Base/FastMarching.h new file mode 100644 index 0000000..acea8e7 --- /dev/null +++ b/lib/fpa/Base/FastMarching.h @@ -0,0 +1,59 @@ +#ifndef __fpa__Base__FastMarching__h__ +#define __fpa__Base__FastMarching__h__ + +#include + +namespace fpa +{ + namespace Base + { + /** + */ + template< class _TSuperclass > + class FastMarching + : public fpa::Base::PriorityQueueAlgorithm< _TSuperclass > + { + public: + typedef FastMarching Self; + typedef fpa::Base::PriorityQueueAlgorithm< _TSuperclass > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef typename Superclass::TFrontId TFrontId; + typedef typename Superclass::TOutput TOutput; + typedef typename Superclass::TVertex TVertex; + + typedef std::pair< TVertex, double > TFastMarchingNeighbor; + typedef std::vector< TFastMarchingNeighbor > TFastMarchingNeighborhood; + + protected: + typedef typename Superclass::_TQueueNode _TQueueNode; + + public: + itkTypeMacro( FastMarching, Algorithm ); + + protected: + FastMarching( ); + virtual ~FastMarching( ); + + virtual TFastMarchingNeighborhood _FastMarchingNeighbors( const TVertex& v ) const = 0; + + virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) override; + + private: + // Purposely not defined + FastMarching( const Self& other ); + Self& operator=( const Self& other ); + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __fpa__Base__FastMarching__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/FastMarching.hxx b/lib/fpa/Base/FastMarching.hxx new file mode 100644 index 0000000..61ec968 --- /dev/null +++ b/lib/fpa/Base/FastMarching.hxx @@ -0,0 +1,81 @@ +#ifndef __fpa__Base__FastMarching__hxx__ +#define __fpa__Base__FastMarching__hxx__ + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +fpa::Base::FastMarching< _TSuperclass >:: +FastMarching( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +fpa::Base::FastMarching< _TSuperclass >:: +~FastMarching( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +bool fpa::Base::FastMarching< _TSuperclass >:: +_UpdateValue( _TQueueNode& v, const _TQueueNode& p ) +{ + // Compute quadratic coefficients + double a = double( 0 ); + double b = double( 0 ); + double c = double( 0 ); + TFastMarchingNeighborhood neighs = this->_FastMarchingNeighbors( v.Vertex ); + for( unsigned int i = 0; i < neighs.size( ); i += 2 ) + { + double tn = double( this->_GetResult( neighs[ i ].first ) ); + double tp = double( this->_GetResult( neighs[ i + 1 ].first ) ); + double dd = double( 0 ); + double td = this->m_InitResult; + if( tn < tp ) + { + td = tn; + dd = neighs[ i ].second; + } + else + { + td = tp; + dd = neighs[ i + 1 ].second; + + } // fi + + if( td < double( this->m_InitResult ) ) + { + dd = double( 1 ) / ( dd * dd ); + a += dd; + b += td * dd; + c += td * td * dd; + + } // fi + + } // rof + double F = double( this->_GetInputValue( v, p ) ); + c -= double( 1 ) / ( F * F ); + + // Solve quadratic equation + double d = ( b * b ) - ( a * c ); + if( d >= double( 0 ) ) + { + d = std::sqrt( d ); + b *= double( -1 ); + double s1 = std::fabs( ( b + d ) / a ); + double s2 = std::fabs( ( b - d ) / a ); + v.Result = TOutput( ( s2 < s1 )? s1: s2 ); + if( v.Result < this->_GetResult( v.Vertex ) ) + this->_UpdateResult( v ); + } + else + { + std::cout << "-----> " << v.Vertex << " " << d << std::endl; + } + return( true ); +} + +#endif // __fpa__Base__FastMarching__hxx__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/Functors/RegionGrow/Base.h b/lib/fpa/Base/Functors/RegionGrow/Base.h index 7daf46e..d2c37aa 100644 --- a/lib/fpa/Base/Functors/RegionGrow/Base.h +++ b/lib/fpa/Base/Functors/RegionGrow/Base.h @@ -3,6 +3,7 @@ #include #include +#include namespace fpa { @@ -14,29 +15,36 @@ namespace fpa { /** */ - template< class _TVertex > + template< class _TVertex, class _TOutput > class Base - : public itk::Object + : public fpa::Base::Functors::VertexCostFunctionBase< _TVertex, _TOutput > { public: + typedef fpa::Base::Functors::VertexCostFunctionBase< _TVertex, _TOutput > Superclass; typedef Base Self; - typedef itk::Object Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; typedef _TVertex TVertex; + typedef _TOutput TOutput; public: itkTypeMacro( Base, itk::Object ); + itkGetConstMacro( InsideValue, _TOutput ); + itkGetConstMacro( OutsideValue, _TOutput ); + + itkSetMacro( InsideValue, _TOutput ); + itkSetMacro( OutsideValue, _TOutput ); + public: - virtual bool Evaluate( - const TVertex& a, const TVertex& b - ) const = 0; + virtual TOutput Evaluate( const TVertex& a, const TVertex& b ) const = 0; protected: Base( ) - : Superclass( ) + : Superclass( ), + m_InsideValue( TOutput( 1 ) ), + m_OutsideValue( TOutput( 0 ) ) { } virtual ~Base( ) { } @@ -45,6 +53,10 @@ namespace fpa // Purposely not defined Base( const Self& other ); Self& operator=( const Self& other ); + + protected: + _TOutput m_InsideValue; + _TOutput m_OutsideValue; }; } // ecapseman diff --git a/lib/fpa/Base/Functors/RegionGrow/Tautology.h b/lib/fpa/Base/Functors/RegionGrow/Tautology.h index 744d618..11d016e 100644 --- a/lib/fpa/Base/Functors/RegionGrow/Tautology.h +++ b/lib/fpa/Base/Functors/RegionGrow/Tautology.h @@ -13,16 +13,17 @@ namespace fpa { /** */ - template< class _TVertex > + template< class _TVertex, class _TOutput > class Tautology - : public Base< _TVertex > + : public Base< _TVertex, _TOutput > { public: typedef Tautology Self; - typedef Base< _TVertex > Superclass; + typedef Base< _TVertex, _TOutput > Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; + typedef typename Superclass::TOutput TOutput; typedef typename Superclass::TVertex TVertex; public: @@ -30,11 +31,9 @@ namespace fpa itkTypeMacro( Tautology, Base ); public: - virtual bool Evaluate( - const TVertex& a, const TVertex& b - ) const override + virtual TOutput Evaluate( const TVertex& a, const TVertex& b ) const override { - return( true ); + return( this->m_InsideValue ); } protected: diff --git a/lib/fpa/Base/Functors/VertexCostFunctionBase.h b/lib/fpa/Base/Functors/VertexCostFunctionBase.h new file mode 100644 index 0000000..12f5c24 --- /dev/null +++ b/lib/fpa/Base/Functors/VertexCostFunctionBase.h @@ -0,0 +1,55 @@ +#ifndef __fpa__Base__Functors__VertexCostFunctionBase__h__ +#define __fpa__Base__Functors__VertexCostFunctionBase__h__ + +#include +#include + +namespace fpa +{ + namespace Base + { + namespace Functors + { + /** + */ + template< class _TVertex, class _TOutput > + class VertexCostFunctionBase + : public itk::Object + { + public: + typedef VertexCostFunctionBase Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef _TVertex TVertex; + typedef _TOutput TOutput; + + public: + itkTypeMacro( VertexCostFunctionBase, itk::Object ); + + public: + virtual TOutput Evaluate( const TVertex& a, const TVertex& b ) const = 0; + + protected: + VertexCostFunctionBase( ) + : Superclass( ) + { } + virtual ~VertexCostFunctionBase( ) + { } + + private: + // Purposely not defined + VertexCostFunctionBase( const Self& other ); + Self& operator=( const Self& other ); + }; + + } // ecapseman + + } // ecapseman + +} // ecapseman + +#endif // __fpa__Base__Functors__VertexCostFunctionBase__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/PriorityQueueAlgorithm.h b/lib/fpa/Base/PriorityQueueAlgorithm.h new file mode 100644 index 0000000..e34b823 --- /dev/null +++ b/lib/fpa/Base/PriorityQueueAlgorithm.h @@ -0,0 +1,64 @@ +#ifndef __fpa__Base__PriorityQueueAlgorithm__h__ +#define __fpa__Base__PriorityQueueAlgorithm__h__ + +#include + +namespace fpa +{ + namespace Base + { + /** + */ + template< class _TSuperclass > + class PriorityQueueAlgorithm + : public _TSuperclass + { + public: + typedef PriorityQueueAlgorithm Self; + typedef _TSuperclass Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + protected: + typedef typename Superclass::_TQueueNode _TQueueNode; + struct _TQueueNodeCompare + { + bool operator( )( const _TQueueNode& a, const _TQueueNode& b ) + { + return( b.Result < a.Result ); + } + }; + typedef std::vector< _TQueueNode > _TQueue; + + public: + itkTypeMacro( PriorityQueueAlgorithm, Algorithm ); + + protected: + PriorityQueueAlgorithm( ); + virtual ~PriorityQueueAlgorithm( ); + + virtual unsigned long _QueueSize( ) const override; + virtual void _QueueClear( ) override; + virtual void _QueuePush( const _TQueueNode& node ) override; + virtual _TQueueNode _QueuePop( ) override; + + private: + // Purposely not defined + PriorityQueueAlgorithm( const Self& other ); + Self& operator=( const Self& other ); + + protected: + _TQueue m_Queue; + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __fpa__Base__PriorityQueueAlgorithm__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/PriorityQueueAlgorithm.hxx b/lib/fpa/Base/PriorityQueueAlgorithm.hxx new file mode 100644 index 0000000..11c1408 --- /dev/null +++ b/lib/fpa/Base/PriorityQueueAlgorithm.hxx @@ -0,0 +1,60 @@ +#ifndef __fpa__Base__PriorityQueueAlgorithm__hxx__ +#define __fpa__Base__PriorityQueueAlgorithm__hxx__ + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +fpa::Base::PriorityQueueAlgorithm< _TSuperclass >:: +PriorityQueueAlgorithm( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +fpa::Base::PriorityQueueAlgorithm< _TSuperclass >:: +~PriorityQueueAlgorithm( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +unsigned long fpa::Base::PriorityQueueAlgorithm< _TSuperclass >:: +_QueueSize( ) const +{ + return( this->m_Queue.size( ) ); +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +void fpa::Base::PriorityQueueAlgorithm< _TSuperclass >:: +_QueueClear( ) +{ + this->m_Queue.clear( ); +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +void fpa::Base::PriorityQueueAlgorithm< _TSuperclass >:: +_QueuePush( const _TQueueNode& node ) +{ + static _TQueueNodeCompare cmp; + this->m_Queue.push_back( node ); + std::push_heap( this->m_Queue.begin( ), this->m_Queue.end( ), cmp ); +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +typename fpa::Base::PriorityQueueAlgorithm< _TSuperclass >:: +_TQueueNode fpa::Base::PriorityQueueAlgorithm< _TSuperclass >:: +_QueuePop( ) +{ + static _TQueueNodeCompare cmp; + std::pop_heap( this->m_Queue.begin( ), this->m_Queue.end( ), cmp ); + _TQueueNode f = this->m_Queue.back( ); + this->m_Queue.pop_back( ); + return( f ); +} + +#endif // __fpa__Base__PriorityQueueAlgorithm__hxx__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/QueueAlgorithm.h b/lib/fpa/Base/QueueAlgorithm.h new file mode 100644 index 0000000..dd077f7 --- /dev/null +++ b/lib/fpa/Base/QueueAlgorithm.h @@ -0,0 +1,59 @@ +#ifndef __fpa__Base__QueueAlgorithm__h__ +#define __fpa__Base__QueueAlgorithm__h__ + +#include +#include +#include + +namespace fpa +{ + namespace Base + { + /** + */ + template< class _TSuperclass > + class QueueAlgorithm + : public _TSuperclass + { + public: + typedef QueueAlgorithm Self; + typedef _TSuperclass Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + protected: + typedef typename Superclass::_TQueueNode _TQueueNode; + typedef std::queue< _TQueueNode > _TQueue; + + public: + itkTypeMacro( QueueAlgorithm, _TSuperclass ); + + protected: + QueueAlgorithm( ); + virtual ~QueueAlgorithm( ); + + virtual unsigned long _QueueSize( ) const override; + virtual void _QueueClear( ) override; + virtual void _QueuePush( const _TQueueNode& node ) override; + virtual _TQueueNode _QueuePop( ) override; + + private: + // Purposely not defined + QueueAlgorithm( const Self& other ); + Self& operator=( const Self& other ); + + protected: + _TQueue m_Queue; + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __fpa__Base__QueueAlgorithm__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/QueueAlgorithm.hxx b/lib/fpa/Base/QueueAlgorithm.hxx new file mode 100644 index 0000000..db5b8bc --- /dev/null +++ b/lib/fpa/Base/QueueAlgorithm.hxx @@ -0,0 +1,57 @@ +#ifndef __fpa__Base__QueueAlgorithm__hxx__ +#define __fpa__Base__QueueAlgorithm__hxx__ + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +fpa::Base::QueueAlgorithm< _TSuperclass >:: +QueueAlgorithm( ) + : Superclass( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +fpa::Base::QueueAlgorithm< _TSuperclass >:: +~QueueAlgorithm( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +unsigned long fpa::Base::QueueAlgorithm< _TSuperclass >:: +_QueueSize( ) const +{ + return( this->m_Queue.size( ) ); +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +void fpa::Base::QueueAlgorithm< _TSuperclass >:: +_QueueClear( ) +{ + while( this->m_Queue.size( ) > 0 ) + this->m_Queue.pop( ); +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +void fpa::Base::QueueAlgorithm< _TSuperclass >:: +_QueuePush( const _TQueueNode& node ) +{ + this->m_Queue.push( node ); +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +typename fpa::Base::QueueAlgorithm< _TSuperclass >:: +_TQueueNode fpa::Base::QueueAlgorithm< _TSuperclass >:: +_QueuePop( ) +{ + _TQueueNode f = this->m_Queue.front( ); + this->m_Queue.pop( ); + return( f ); +} + +#endif // __fpa__Base__QueueAlgorithm__hxx__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Base/RegionGrow.h b/lib/fpa/Base/RegionGrow.h index a8fcc93..6a3c9e6 100644 --- a/lib/fpa/Base/RegionGrow.h +++ b/lib/fpa/Base/RegionGrow.h @@ -2,7 +2,7 @@ #define __fpa__Base__RegionGrow__h__ #include -#include +#include #include namespace fpa @@ -13,33 +13,33 @@ namespace fpa */ template< class _TSuperclass > class RegionGrow - : public _TSuperclass + : public fpa::Base::QueueAlgorithm< _TSuperclass > { public: - typedef RegionGrow Self; - typedef _TSuperclass Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; + typedef RegionGrow Self; + typedef fpa::Base::QueueAlgorithm< _TSuperclass > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; typedef typename Superclass::TOutput TOutput; typedef typename Superclass::TVertex TVertex; - - typedef fpa::Base::Functors::RegionGrow::Base< TVertex > TGrowFunction; + typedef fpa::Base::Functors::RegionGrow::Base< TVertex, TOutput > TGrowFunction; protected: typedef typename Superclass::_TQueueNode _TQueueNode; - typedef std::queue< _TQueueNode > _TQueue; public: itkTypeMacro( RegionGrow, Algorithm ); - itkGetObjectMacro( GrowFunction, TGrowFunction ); - itkGetConstMacro( InsideValue, TOutput ); - itkGetConstMacro( OutsideValue, TOutput ); + public: + TGrowFunction* GetGrowFunction( ); + const TGrowFunction* GetGrowFunction( ) const; + TOutput GetInsideValue( ) const; + TOutput GetOutsideValue( ) const; - itkSetObjectMacro( GrowFunction, TGrowFunction ); - itkSetMacro( InsideValue, TOutput ); - itkSetMacro( OutsideValue, TOutput ); + void SetGrowFunction( TGrowFunction* f ); + void SetInsideValue( const TOutput& v ); + void SetOutsideValue( const TOutput& v ); protected: RegionGrow( ); @@ -48,21 +48,11 @@ namespace fpa virtual bool _UpdateValue( _TQueueNode& v, const _TQueueNode& p ) override; - virtual unsigned long _QueueSize( ) const override; - virtual void _QueueClear( ) override; - virtual void _QueuePush( const _TQueueNode& node ) override; - virtual _TQueueNode _QueuePop( ) override; private: // Purposely not defined RegionGrow( const Self& other ); Self& operator=( const Self& other ); - - protected: - TOutput m_InsideValue; - TOutput m_OutsideValue; - _TQueue m_Queue; - typename TGrowFunction::Pointer m_GrowFunction; }; } // ecapseman diff --git a/lib/fpa/Base/RegionGrow.hxx b/lib/fpa/Base/RegionGrow.hxx index e7dba1f..6865916 100644 --- a/lib/fpa/Base/RegionGrow.hxx +++ b/lib/fpa/Base/RegionGrow.hxx @@ -5,78 +5,118 @@ // ------------------------------------------------------------------------- template< class _TSuperclass > -fpa::Base::RegionGrow< _TSuperclass >:: -RegionGrow( ) - : Superclass( ), - m_InsideValue( TOutput( 1 ) ), - m_OutsideValue( TOutput( 0 ) ) +typename fpa::Base::RegionGrow< _TSuperclass >:: +TGrowFunction* fpa::Base::RegionGrow< _TSuperclass >:: +GetGrowFunction( ) { - this->m_InitResult = TOutput( 0 ); - this->SetGrowFunction( - fpa::Base::Functors::RegionGrow::Tautology< TVertex >::New( ) + return( dynamic_cast< TGrowFunction* >( this->GetVertexFunction( ) ) ); +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +const typename fpa::Base::RegionGrow< _TSuperclass >:: +TGrowFunction* fpa::Base::RegionGrow< _TSuperclass >:: +GetGrowFunction( ) const +{ + return( + dynamic_cast< const TGrowFunction* >( this->GetVertexFunction( ) ) ); } // ------------------------------------------------------------------------- template< class _TSuperclass > -fpa::Base::RegionGrow< _TSuperclass >:: -~RegionGrow( ) +typename fpa::Base::RegionGrow< _TSuperclass >:: +TOutput fpa::Base::RegionGrow< _TSuperclass >:: +GetInsideValue( ) const { + const TGrowFunction* f = this->GetGrowFunction( ); + if( f != NULL ) + return( f->GetInsideValue( ) ); + else + return( this->m_InitResult ); } // ------------------------------------------------------------------------- template< class _TSuperclass > -bool fpa::Base::RegionGrow< _TSuperclass >:: -_UpdateValue( _TQueueNode& v, const _TQueueNode& p ) +typename fpa::Base::RegionGrow< _TSuperclass >:: +TOutput fpa::Base::RegionGrow< _TSuperclass >:: +GetOutsideValue( ) const { - if( this->m_GrowFunction.IsNotNull( ) ) - { - bool in = this->m_GrowFunction->Evaluate( p.Vertex, v.Vertex ); - v.Result = ( in )? this->m_InsideValue: this->m_OutsideValue; - return( in ); - } + const TGrowFunction* f = this->GetGrowFunction( ); + if( f != NULL ) + return( f->GetOutsideValue( ) ); else + return( this->m_InitResult ); +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +void fpa::Base::RegionGrow< _TSuperclass >:: +SetGrowFunction( TGrowFunction* f ) +{ + TGrowFunction* old_f = this->GetGrowFunction( ); + if( old_f != NULL ) { - v.Result = this->m_InitResult; - return( false ); + f->SetInsideValue( old_f->GetInsideValue( ) ); + f->SetOutsideValue( old_f->GetOutsideValue( ) ); } // fi + this->SetVertexFunction( f ); } // ------------------------------------------------------------------------- template< class _TSuperclass > -unsigned long fpa::Base::RegionGrow< _TSuperclass >:: -_QueueSize( ) const +void fpa::Base::RegionGrow< _TSuperclass >:: +SetInsideValue( const TOutput& v ) { - return( this->m_Queue.size( ) ); + TGrowFunction* f = this->GetGrowFunction( ); + if( f != NULL ) + { + f->SetInsideValue( v ); + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- template< class _TSuperclass > void fpa::Base::RegionGrow< _TSuperclass >:: -_QueueClear( ) +SetOutsideValue( const TOutput& v ) { - while( this->m_Queue.size( ) > 0 ) - this->m_Queue.pop( ); + TGrowFunction* f = this->GetGrowFunction( ); + if( f != NULL ) + { + f->SetOutsideValue( v ); + this->Modified( ); + + } // fi } // ------------------------------------------------------------------------- template< class _TSuperclass > -void fpa::Base::RegionGrow< _TSuperclass >:: -_QueuePush( const _TQueueNode& node ) +fpa::Base::RegionGrow< _TSuperclass >:: +RegionGrow( ) + : Superclass( ) { - this->m_Queue.push( node ); + typedef fpa::Base::Functors::RegionGrow::Tautology< TVertex, TOutput > _TFunc; + this->SetGrowFunction( _TFunc::New( ) ); + this->m_InitResult = this->GetGrowFunction( )->GetOutsideValue( ); } // ------------------------------------------------------------------------- template< class _TSuperclass > -typename fpa::Base::RegionGrow< _TSuperclass >:: -_TQueueNode fpa::Base::RegionGrow< _TSuperclass >:: -_QueuePop( ) +fpa::Base::RegionGrow< _TSuperclass >:: +~RegionGrow( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TSuperclass > +bool fpa::Base::RegionGrow< _TSuperclass >:: +_UpdateValue( _TQueueNode& v, const _TQueueNode& p ) { - _TQueueNode f = this->m_Queue.front( ); - this->m_Queue.pop( ); - return( f ); + v.Result = this->_GetInputValue( v, p ); + return( v.Result == this->GetInsideValue( ) ); } #endif // __fpa__Base__RegionGrow__hxx__ diff --git a/lib/fpa/Image/Algorithm.h b/lib/fpa/Image/Algorithm.h index d613ce3..0105cc3 100644 --- a/lib/fpa/Image/Algorithm.h +++ b/lib/fpa/Image/Algorithm.h @@ -28,7 +28,9 @@ namespace fpa typedef typename Superclass::TFrontId TFrontId; typedef typename Superclass::TNeighborhood TNeighborhood; - typedef fpa::Image::Functors::Base< itk::ImageBase< _TInputImage::ImageDimension >, itk::FunctionBase< TVertex, TNeighborhood > > TNeighborhoodFunction; + + typedef fpa::Image::Functors::Base< itk::ImageBase< _TInputImage::ImageDimension >, typename Superclass::TNeighborhoodFunction > TNeighborhoodFunction; + typedef fpa::Image::Functors::Base< _TInputImage, typename Superclass::TVertexFunction > TVertexFunction; protected: typedef typename Superclass::_TQueueNode _TQueueNode; @@ -47,6 +49,8 @@ namespace fpa virtual void _Mark( const _TQueueNode& n ) override; virtual TFrontId _GetMark( const TVertex& v ) const override; virtual void _UpdateResult( const _TQueueNode& n ) override; + virtual TOutput _GetResult( const TVertex& v ) const override; + virtual unsigned int _GetNumberOfDimensions( ) const override; private: // Purposely not defined diff --git a/lib/fpa/Image/Algorithm.hxx b/lib/fpa/Image/Algorithm.hxx index ed73421..6e4eef1 100644 --- a/lib/fpa/Image/Algorithm.hxx +++ b/lib/fpa/Image/Algorithm.hxx @@ -12,8 +12,7 @@ fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: Algorithm( ) : Superclass( ) { - typedef itk::ImageBase< _TInputImage::ImageDimension > _TImageBase; - typedef fpa::Image::Functors::SimpleNeighborhood< _TImageBase > _TNeigh; + typedef fpa::Image::Functors::SimpleNeighborhood< _TInputImage::ImageDimension > _TNeigh; typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks; this->m_MarksIdx = this->GetNumberOfRequiredOutputs( ); @@ -47,6 +46,14 @@ _BeforeGenerateData( ) if( neighFunc == NULL ) itkExceptionMacro( << "NeighborhoodFunction not well defined." ); neighFunc->SetImage( this->GetInput( ) ); + + TVertexFunction* vertexFunc = + dynamic_cast< TVertexFunction* >( + this->GetVertexFunction( ) + ); + if( vertexFunc == NULL ) + itkExceptionMacro( << "VertexFunction not well defined." ); + vertexFunc->SetImage( this->GetInput( ) ); } // ------------------------------------------------------------------------- @@ -118,6 +125,26 @@ _UpdateResult( const _TQueueNode& n ) this->GetOutput( )->SetPixel( n.Vertex, n.Result ); } +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputImage > +typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::TOutput +fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: +_GetResult( const TVertex& v ) const +{ + if( this->GetOutput( )->GetLargestPossibleRegion( ).IsInside( v ) ) + return( this->GetOutput( )->GetPixel( v ) ); + else + return( this->m_InitResult ); +} + +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputImage > +unsigned int fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: +_GetNumberOfDimensions( ) const +{ + return( _TInputImage::ImageDimension ); +} + #endif // __fpa__Image__Algorithm__hxx__ // eof - $RCSfile$ diff --git a/lib/fpa/Image/Dijkstra.h b/lib/fpa/Image/Dijkstra.h index 96c642b..118cc27 100644 --- a/lib/fpa/Image/Dijkstra.h +++ b/lib/fpa/Image/Dijkstra.h @@ -27,8 +27,6 @@ namespace fpa typedef typename Superclass::TOutput TOutput; typedef typename Superclass::TVertex TVertex; - typedef fpa::Image::Functors::Base< _TInputImage, fpa::Base::DijkstraCostFunctionBase< TVertex, TOutput > > TCostFunction; - public: itkNewMacro( Self ); itkTypeMacro( fpa::Image::Dijkstra, fpa::Base::Dijkstra ); @@ -37,8 +35,6 @@ namespace fpa Dijkstra( ); virtual ~Dijkstra( ); - virtual void _BeforeGenerateData( ) override; - private: // Purposely not defined Dijkstra( const Self& other ); diff --git a/lib/fpa/Image/Dijkstra.hxx b/lib/fpa/Image/Dijkstra.hxx index bf6b5f0..1f21dc4 100644 --- a/lib/fpa/Image/Dijkstra.hxx +++ b/lib/fpa/Image/Dijkstra.hxx @@ -1,7 +1,7 @@ #ifndef __fpa__Image__Dijkstra__hxx__ #define __fpa__Image__Dijkstra__hxx__ -#include +#include // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > @@ -9,12 +9,9 @@ fpa::Image::Dijkstra< _TInputImage, _TOutputImage >:: Dijkstra( ) : Superclass( ) { - typedef - fpa::Image::Functors::SimpleDijkstraCost< _TInputImage, TOutput > - _TCost; - + typedef fpa::Image::Functors::VertexCost< _TInputImage, TOutput > _TCost; typename _TCost::Pointer cost = _TCost::New( ); - this->SetCostFunction( cost ); + this->SetVertexFunction( cost ); } // ------------------------------------------------------------------------- @@ -24,20 +21,6 @@ fpa::Image::Dijkstra< _TInputImage, _TOutputImage >:: { } -// ------------------------------------------------------------------------- -template< class _TInputImage, class _TOutputImage > -void fpa::Image::Dijkstra< _TInputImage, _TOutputImage >:: -_BeforeGenerateData( ) -{ - this->Superclass::_BeforeGenerateData( ); - - TCostFunction* cost = - dynamic_cast< TCostFunction* >( this->GetCostFunction( ) ); - if( cost == NULL ) - itkExceptionMacro( << "CostFunction not well defined." ); - cost->SetImage( this->GetInput( ) ); -} - #endif // __fpa__Image__Dijkstra__hxx__ // eof - $RCSfile$ diff --git a/lib/fpa/Image/FastMarching.h b/lib/fpa/Image/FastMarching.h new file mode 100644 index 0000000..2a4056f --- /dev/null +++ b/lib/fpa/Image/FastMarching.h @@ -0,0 +1,55 @@ +#ifndef __fpa__Image__FastMarching__h__ +#define __fpa__Image__FastMarching__h__ + +#include +#include + +namespace fpa +{ + namespace Image + { + /** + */ + template< class _TInputImage, class _TOutputImage > + class FastMarching + : public fpa::Base::FastMarching< fpa::Image::Algorithm< _TInputImage, _TOutputImage > > + { + public: + typedef FastMarching Self; + typedef fpa::Image::Algorithm< _TInputImage, _TOutputImage > TAlgorithm; + typedef fpa::Base::FastMarching< TAlgorithm > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef typename Superclass::TOutput TOutput; + typedef typename Superclass::TVertex TVertex; + typedef typename Superclass::TFastMarchingNeighbor TFastMarchingNeighbor; + typedef typename Superclass::TFastMarchingNeighborhood TFastMarchingNeighborhood; + + public: + itkNewMacro( Self ); + itkTypeMacro( fpa::Image::FastMarching, fpa::Base::FastMarching ); + + protected: + FastMarching( ); + virtual ~FastMarching( ); + + virtual TFastMarchingNeighborhood _FastMarchingNeighbors( const TVertex& v ) const override; + + private: + // Purposely not defined + FastMarching( const Self& other ); + Self& operator=( const Self& other ); + }; + + } // ecapseman + +} // ecapseman + +#ifndef ITK_MANUAL_INSTANTIATION +# include +#endif // ITK_MANUAL_INSTANTIATION + +#endif // __fpa__Image__FastMarching__h__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/FastMarching.hxx b/lib/fpa/Image/FastMarching.hxx new file mode 100644 index 0000000..fe75b21 --- /dev/null +++ b/lib/fpa/Image/FastMarching.hxx @@ -0,0 +1,50 @@ +#ifndef __fpa__Image__FastMarching__hxx__ +#define __fpa__Image__FastMarching__hxx__ + +#include + +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputImage > +fpa::Image::FastMarching< _TInputImage, _TOutputImage >:: +FastMarching( ) + : Superclass( ) +{ + typedef fpa::Image::Functors::VertexCost< _TInputImage, TOutput > _TCost; + typename _TCost::Pointer cost = _TCost::New( ); + this->SetVertexFunction( cost ); + this->m_InitResult = std::numeric_limits< TOutput >::max( ); +} + +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputImage > +fpa::Image::FastMarching< _TInputImage, _TOutputImage >:: +~FastMarching( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputImage > +typename fpa::Image::FastMarching< _TInputImage, _TOutputImage >:: +TFastMarchingNeighborhood +fpa::Image::FastMarching< _TInputImage, _TOutputImage >:: +_FastMarchingNeighbors( const TVertex& v ) const +{ + TFastMarchingNeighborhood neighs; + typename _TInputImage::SpacingType spac = this->GetInput( )->GetSpacing( ); + for( unsigned int d = 0; d < _TInputImage::ImageDimension; ++d ) + { + for( int i = -1; i <= 1; i += 2 ) + { + TVertex n = v; + n[ d ] += i; + neighs.push_back( TFastMarchingNeighbor( n, spac[ d ] ) ); + + } // rof + + } // rof + return( neighs ); +} + +#endif // __fpa__Image__FastMarching__hxx__ + +// eof - $RCSfile$ diff --git a/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.h b/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.h index 78c42a7..70ac8d0 100644 --- a/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.h +++ b/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.h @@ -14,16 +14,17 @@ namespace fpa { /** */ - template< class _TImage > + template< class _TImage, class _TOutput > class BinaryThreshold - : public fpa::Image::Functors::Base< _TImage, fpa::Base::Functors::RegionGrow::Base< typename _TImage::IndexType > > + : public fpa::Image::Functors::Base< _TImage, fpa::Base::Functors::RegionGrow::Base< typename _TImage::IndexType, _TOutput > > { public: typedef _TImage TImage; + typedef _TOutput TOutput; typedef typename TImage::IndexType TIndex; typedef typename TImage::PixelType TPixel; - typedef fpa::Base::Functors::RegionGrow::Base< TIndex > TBase; + typedef fpa::Base::Functors::RegionGrow::Base< TIndex, TOutput > TBase; typedef fpa::Image::Functors::Base< TImage, TBase > Superclass; typedef BinaryThreshold Self; typedef itk::SmartPointer< Self > Pointer; @@ -39,7 +40,7 @@ namespace fpa itkSetMacro( Upper, TPixel ); public: - virtual bool Evaluate( + virtual TOutput Evaluate( const TIndex& a, const TIndex& b ) const override; diff --git a/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx b/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx index 97cf465..e1853e2 100644 --- a/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx +++ b/lib/fpa/Image/Functors/RegionGrow/BinaryThreshold.hxx @@ -4,8 +4,9 @@ #include // ------------------------------------------------------------------------- -template< class _TImage > -bool fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage >:: +template< class _TImage, class _TOutput > +_TOutput +fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage, _TOutput >:: Evaluate( const TIndex& a, const TIndex& b ) const { const _TImage* im = @@ -13,15 +14,19 @@ Evaluate( const TIndex& a, const TIndex& b ) const if( im != NULL ) { TPixel v = im->GetPixel( b ); - return( this->m_Lower <= v && v <= this->m_Upper ); + return( + ( this->m_Lower <= v && v <= this->m_Upper )? + this->m_InsideValue: + this->m_OutsideValue + ); } else - return( false ); + return( this->m_OutsideValue ); } // ------------------------------------------------------------------------- -template< class _TImage > -fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage >:: +template< class _TImage, class _TOutput > +fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage, _TOutput >:: BinaryThreshold( ) : Superclass( ) { @@ -33,8 +38,8 @@ BinaryThreshold( ) } // ------------------------------------------------------------------------- -template< class _TImage > -fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage >:: +template< class _TImage, class _TOutput > +fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage, _TOutput >:: ~BinaryThreshold( ) { } diff --git a/lib/fpa/Image/Functors/SimpleNeighborhood.h b/lib/fpa/Image/Functors/SimpleNeighborhood.h index 9f777b0..0e4ebf7 100644 --- a/lib/fpa/Image/Functors/SimpleNeighborhood.h +++ b/lib/fpa/Image/Functors/SimpleNeighborhood.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace fpa { @@ -13,12 +14,12 @@ namespace fpa { /** */ - template< class _TImage > + template< unsigned int _VDim > class SimpleNeighborhood - : public fpa::Image::Functors::Base< _TImage, itk::FunctionBase< typename _TImage::IndexType, std::vector< typename _TImage::IndexType > > > + : public fpa::Image::Functors::Base< itk::ImageBase< _VDim >, itk::FunctionBase< itk::Index< _VDim >, std::vector< itk::Index< _VDim > > > > { public: - typedef _TImage TImage; + typedef itk::ImageBase< _VDim > TImage; typedef typename TImage::IndexType TIndex; typedef typename TIndex::OffsetType TOffset; typedef std::vector< TIndex > TOutput; diff --git a/lib/fpa/Image/Functors/SimpleNeighborhood.hxx b/lib/fpa/Image/Functors/SimpleNeighborhood.hxx index a09dab8..172425d 100644 --- a/lib/fpa/Image/Functors/SimpleNeighborhood.hxx +++ b/lib/fpa/Image/Functors/SimpleNeighborhood.hxx @@ -2,9 +2,9 @@ #define __fpa__Image__Functors__SimpleNeighborhood__hxx__ // ------------------------------------------------------------------------- -template< class _TImage > -typename fpa::Image::Functors::SimpleNeighborhood< _TImage >:: -TOutput fpa::Image::Functors::SimpleNeighborhood< _TImage >:: +template< unsigned int _VDim > +typename fpa::Image::Functors::SimpleNeighborhood< _VDim >:: +TOutput fpa::Image::Functors::SimpleNeighborhood< _VDim >:: Evaluate( const TIndex& center ) const { if( this->m_Offsets.size( ) == 0 ) @@ -17,7 +17,7 @@ Evaluate( const TIndex& center ) const } // fi TOutput res; - typename _TImage::RegionType reg = this->m_Image->GetRequestedRegion( ); + typename TImage::RegionType reg = this->m_Image->GetRequestedRegion( ); for( int i = 0; i < this->m_Offsets.size( ); ++i ) { TIndex idx = center + this->m_Offsets[ i ]; @@ -29,8 +29,8 @@ Evaluate( const TIndex& center ) const } // ------------------------------------------------------------------------- -template< class _TImage > -fpa::Image::Functors::SimpleNeighborhood< _TImage >:: +template< unsigned int _VDim > +fpa::Image::Functors::SimpleNeighborhood< _VDim >:: SimpleNeighborhood( ) : Superclass( ), m_Order( 1 ) @@ -38,18 +38,18 @@ SimpleNeighborhood( ) } // ------------------------------------------------------------------------- -template< class _TImage > - fpa::Image::Functors::SimpleNeighborhood< _TImage >:: +template< unsigned int _VDim > + fpa::Image::Functors::SimpleNeighborhood< _VDim >:: ~SimpleNeighborhood( ) { } // ------------------------------------------------------------------------- -template< class _TImage > -void fpa::Image::Functors::SimpleNeighborhood< _TImage >:: +template< unsigned int _VDim > +void fpa::Image::Functors::SimpleNeighborhood< _VDim >:: _1stCombination( ) const { - for( int d = 0; d < _TImage::ImageDimension; ++d ) + for( int d = 0; d < TImage::ImageDimension; ++d ) { typename TIndex::OffsetType off; off.Fill( 0 ); @@ -64,8 +64,8 @@ _1stCombination( ) const } // ------------------------------------------------------------------------- -template< class _TImage > -void fpa::Image::Functors::SimpleNeighborhood< _TImage >:: +template< unsigned int _VDim > +void fpa::Image::Functors::SimpleNeighborhood< _VDim >:: _2ndCombination( ) const { std::vector< std::vector< std::vector< int > > > M; @@ -75,7 +75,7 @@ _2ndCombination( ) const base.push_back( -1 ); base.push_back( 0 ); base.push_back( 1 ); - int dim = _TImage::ImageDimension; + int dim = TImage::ImageDimension; M.push_back( std::vector< std::vector< int > >( ) ); for( int j = 0; j < base.size( ); ++j ) diff --git a/lib/fpa/Image/Functors/SimpleDijkstraCost.h b/lib/fpa/Image/Functors/VertexCost.h similarity index 64% rename from lib/fpa/Image/Functors/SimpleDijkstraCost.h rename to lib/fpa/Image/Functors/VertexCost.h index bad9500..a6f3e45 100644 --- a/lib/fpa/Image/Functors/SimpleDijkstraCost.h +++ b/lib/fpa/Image/Functors/VertexCost.h @@ -1,8 +1,8 @@ -#ifndef __fpa__Image__Functors__SimpleDijkstraCost__h__ -#define __fpa__Image__Functors__SimpleDijkstraCost__h__ +#ifndef __fpa__Image__Functors__VertexCost__h__ +#define __fpa__Image__Functors__VertexCost__h__ #include -#include +#include namespace fpa { @@ -13,23 +13,23 @@ namespace fpa /** */ template< class _TImage, class _TOutput > - class SimpleDijkstraCost - : public fpa::Image::Functors::Base< _TImage, fpa::Base::DijkstraCostFunctionBase< typename _TImage::IndexType, _TOutput > > + class VertexCost + : public fpa::Image::Functors::Base< _TImage, fpa::Base::Functors::VertexCostFunctionBase< typename _TImage::IndexType, _TOutput > > { public: typedef _TImage TImage; typedef typename TImage::IndexType TIndex; typedef _TOutput TOutput; - typedef fpa::Base::DijkstraCostFunctionBase< TIndex, TOutput > TBaseFunctor; + typedef fpa::Base::Functors::VertexCostFunctionBase< TIndex, TOutput > TBaseFunctor; typedef fpa::Image::Functors::Base< TImage, TBaseFunctor > Superclass; - typedef SimpleDijkstraCost Self; + typedef VertexCost Self; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; public: itkNewMacro( Self ); - itkTypeMacro( SimpleDijkstraCost, Base ); + itkTypeMacro( VertexCost, Base ); itkBooleanMacro( UseImageSpacing ); itkGetConstMacro( UseImageSpacing, bool ); @@ -41,12 +41,12 @@ namespace fpa ) const override; protected: - SimpleDijkstraCost( ); - virtual ~SimpleDijkstraCost( ); + VertexCost( ); + virtual ~VertexCost( ); private: // Purposely not implemented - SimpleDijkstraCost( const Self& other ); + VertexCost( const Self& other ); Self& operator=( const Self& other ); protected: @@ -60,9 +60,9 @@ namespace fpa } // ecapseman #ifndef ITK_MANUAL_INSTANTIATION -# include +# include #endif // ITK_MANUAL_INSTANTIATION -#endif // __fpa__Image__Functors__SimpleDijkstraCost__h__ +#endif // __fpa__Image__Functors__VertexCost__h__ // eof - $RCSfile$ diff --git a/lib/fpa/Image/Functors/SimpleDijkstraCost.hxx b/lib/fpa/Image/Functors/VertexCost.hxx similarity index 64% rename from lib/fpa/Image/Functors/SimpleDijkstraCost.hxx rename to lib/fpa/Image/Functors/VertexCost.hxx index 25b8ff4..3b59c52 100644 --- a/lib/fpa/Image/Functors/SimpleDijkstraCost.hxx +++ b/lib/fpa/Image/Functors/VertexCost.hxx @@ -1,10 +1,10 @@ -#ifndef __fpa__Image__Functors__SimpleDijkstraCost__hxx__ -#define __fpa__Image__Functors__SimpleDijkstraCost__hxx__ +#ifndef __fpa__Image__Functors__VertexCost__hxx__ +#define __fpa__Image__Functors__VertexCost__hxx__ // ------------------------------------------------------------------------- template< class _TImage, class _TOutput > -typename fpa::Image::Functors::SimpleDijkstraCost< _TImage, _TOutput >:: -TOutput fpa::Image::Functors::SimpleDijkstraCost< _TImage, _TOutput >:: +typename fpa::Image::Functors::VertexCost< _TImage, _TOutput >:: +TOutput fpa::Image::Functors::VertexCost< _TImage, _TOutput >:: Evaluate( const TIndex& a, const TIndex& b ) const { const _TImage* im = @@ -23,8 +23,8 @@ Evaluate( const TIndex& a, const TIndex& b ) const // ------------------------------------------------------------------------- template< class _TImage, class _TOutput > -fpa::Image::Functors::SimpleDijkstraCost< _TImage, _TOutput >:: -SimpleDijkstraCost( ) +fpa::Image::Functors::VertexCost< _TImage, _TOutput >:: +VertexCost( ) : Superclass( ), m_UseImageSpacing( false ) { @@ -32,11 +32,11 @@ SimpleDijkstraCost( ) // ------------------------------------------------------------------------- template< class _TImage, class _TOutput > -fpa::Image::Functors::SimpleDijkstraCost< _TImage, _TOutput >:: -~SimpleDijkstraCost( ) +fpa::Image::Functors::VertexCost< _TImage, _TOutput >:: +~VertexCost( ) { } -#endif // __fpa__Image__Functors__SimpleDijkstraCost__hxx__ +#endif // __fpa__Image__Functors__VertexCost__hxx__ // eof - $RCSfile$ diff --git a/lib/fpa/Image/MoriRegionGrowHelper.h b/lib/fpa/Image/MoriRegionGrowHelper.h index 3810b87..02f51b6 100644 --- a/lib/fpa/Image/MoriRegionGrowHelper.h +++ b/lib/fpa/Image/MoriRegionGrowHelper.h @@ -25,10 +25,8 @@ namespace fpa typedef typename Superclass::TOutput TOutput; typedef typename Superclass::TVertex TVertex; typedef typename Superclass::TGrowFunction TGrowFunction; - typedef - fpa::Image::Functors::RegionGrow::BinaryThreshold< _TInputImage > - TBinThresholdFunction; - typedef typename _TInputImage::PixelType TPixel; + typedef typename _TInputImage::PixelType TPixel; + typedef fpa::Image::Functors::RegionGrow::BinaryThreshold< _TInputImage, TOutput > TBinThresholdFunction; protected: typedef typename Superclass::_TQueueNode _TQueueNode; diff --git a/lib/fpa/Image/RegionGrow.hxx b/lib/fpa/Image/RegionGrow.hxx index 5c8b76e..9df155a 100644 --- a/lib/fpa/Image/RegionGrow.hxx +++ b/lib/fpa/Image/RegionGrow.hxx @@ -21,12 +21,8 @@ template< class _TInputImage, class _TOutputImage > void fpa::Image::RegionGrow< _TInputImage, _TOutputImage >:: _BeforeGenerateData( ) { - this->m_InitResult = this->m_OutsideValue; this->Superclass::_BeforeGenerateData( ); - TGrowFunction* grow = - dynamic_cast< TGrowFunction* >( this->GetGrowFunction( ) ); - if( grow != NULL ) - grow->SetImage( this->GetInput( ) ); + this->m_InitResult = this->GetOutsideValue( ); } #endif // __fpa__Image__RegionGrow__hxx__ diff --git a/lib/fpa/Image/SkeletonFilter.hxx b/lib/fpa/Image/SkeletonFilter.hxx index bf63d89..c60e13c 100644 --- a/lib/fpa/Image/SkeletonFilter.hxx +++ b/lib/fpa/Image/SkeletonFilter.hxx @@ -29,8 +29,7 @@ SkeletonFilter( ) : Superclass( ) { typedef typename _TImage::PixelType _TPixel; - typedef typename _TImage::Superclass _TImageBase; - typedef fpa::Image::Functors::SimpleNeighborhood< _TImageBase > _TNeighFunc; + typedef fpa::Image::Functors::SimpleNeighborhood< _TImage::ImageDimension > _TNeighFunc; typedef fpa::Base::Functors::Inverse< _TPixel, _TPixel > _TInvFunc; unsigned int nOutputs = this->GetNumberOfRequiredOutputs( ); @@ -48,7 +47,7 @@ SkeletonFilter( ) this->SetNeighborhoodFunction( nfunc ); typename _TInvFunc::Pointer ifunc = _TInvFunc::New( ); - this->SetCostConversionFunction( ifunc ); + this->SetConversionFunction( ifunc ); } // ------------------------------------------------------------------------- diff --git a/lib/fpaInstances/BaseFilters.i b/lib/fpaInstances/BaseFilters.i new file mode 100644 index 0000000..0cc752f --- /dev/null +++ b/lib/fpaInstances/BaseFilters.i @@ -0,0 +1,12 @@ +header #define ITK_MANUAL_INSTANTIATION + +*define i_scalars=#scalar_types# +*define o_scalars=#scalar_types# + +*tinclude fpa/Base/Algorithm:h|hxx +*tinclude fpa/Image/Algorithm:h|hxx + +*instances fpa::Base::Algorithm< itk::ImageToImageFilter< itk::Image< #i_scalars#, #pdims# >, itk::Image< #o_scalars#, #pdims# > >, itk::Index< #pdims# >, #o_scalars# > +*instances fpa::Image::Algorithm< itk::Image< #i_scalars#, #pdims# >, itk::Image< #o_scalars#, #pdims# > > + +** eof - $RCSfile$ diff --git a/lib/fpaInstances/CMakeLists.txt b/lib/fpaInstances/CMakeLists.txt index 0d45521..f7d1114 100644 --- a/lib/fpaInstances/CMakeLists.txt +++ b/lib/fpaInstances/CMakeLists.txt @@ -7,18 +7,32 @@ IF(USE_cpPlugins) ${PROJECT_BINARY_DIR}/lib ) SET(_pfx fpaInstaces) - cpPlugins_BuildLibrary( - ${_pfx}DataObjects SHARED ${CMAKE_CURRENT_SOURCE_DIR}/DataObjects.i + SET(_instances + DataObjects + ImageFunctors + ImageFilters ) - cpPlugins_BuildLibrary( - ${_pfx}Filters SHARED ${CMAKE_CURRENT_SOURCE_DIR}/Filters.i + SET(_build_instances) + FOREACH(_i ${_instances}) + cpPlugins_BuildLibrary( + ${_pfx}${_i} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/${_i}.i + ) + TARGET_LINK_LIBRARIES( + ${_pfx}${_i} + ${cpPlugins_AllInstances} ${ITK_LIBRARIES} ${VTK_LIBRARIES} + ) + LIST(APPEND _build_instances ${_pfx}${_i}) + ENDFOREACH(_i) + + TARGET_LINK_LIBRARIES( + ${_pfx}ImageFilters + ${_pfx}DataObjects + ${_pfx}ImageFunctors + cpPlugins_ITKUnaryFunctorFilters ) - TARGET_LINK_LIBRARIES(${_pfx}DataObjects ${cpPlugins_AllInstances} ${ITK_LIBRARIES} ${VTK_LIBRARIES}) - TARGET_LINK_LIBRARIES(${_pfx}Filters ${_pfx}DataObjects) SET( fpa_AllInstances - ${_pfx}DataObjects - ${_pfx}Filters + ${_build_instances} CACHE INTERNAL "All valid instances." FORCE ) ENDIF(USE_cpPlugins) diff --git a/lib/fpaInstances/DataObjects.i b/lib/fpaInstances/DataObjects.i index cf7f883..2cc585f 100644 --- a/lib/fpaInstances/DataObjects.i +++ b/lib/fpaInstances/DataObjects.i @@ -1,16 +1,8 @@ header #define ITK_MANUAL_INSTANTIATION -tinclude fpa/Image/Functors/SimpleNeighborhood:h|hxx -tinclude fpa/Image/Functors/SimpleDijkstraCost:h|hxx -tinclude fpa/Image/MinimumSpanningTree:h|hxx tinclude fpa/Base/MinimumSpanningTree:h|hxx +tinclude fpa/Image/MinimumSpanningTree:h|hxx -cinclude set -tinclude itkSimpleDataObjectDecorator:h|hxx -instances itk::SimpleDataObjectDecorator< std::set< itk::Index< #pdims# >, itk::Functor::IndexLexicographicCompare< #pdims# > > > - -instances fpa::Image::Functors::SimpleNeighborhood< itk::ImageBase< #pdims# > > -instances fpa::Image::Functors::SimpleDijkstraCost< itk::Image< #scalar_types#, #pdims# >, #real_types# > instances fpa::Base::MinimumSpanningTree< itk::Index< #pdims# >, cpExtensions::DataStructures::PolyLineParametricPath< #pdims# >, itk::Image< itk::Offset< #pdims# >, #pdims# > > instances fpa::Image::MinimumSpanningTree< #pdims# > diff --git a/lib/fpaInstances/Filters.i b/lib/fpaInstances/Filters.i deleted file mode 100644 index 60502a2..0000000 --- a/lib/fpaInstances/Filters.i +++ /dev/null @@ -1,12 +0,0 @@ -header #define ITK_MANUAL_INSTANTIATION - -define i_scalars=#scalar_types# -define o_scalars=#scalar_types# - -tinclude fpa/Base/Algorithm:h|hxx -tinclude fpa/Image/Algorithm:h|hxx - -instances fpa::Base::Algorithm< itk::ImageToImageFilter< itk::Image< #i_scalars#, #pdims# >, itk::Image< #o_scalars#, #pdims# > >, itk::Index< #pdims# >, #o_scalars# > -instances fpa::Image::Algorithm< itk::Image< #i_scalars#, #pdims# >, itk::Image< #o_scalars#, #pdims# > > - -** eof - $RCSfile$ diff --git a/lib/fpaInstances/ImageFilters.i b/lib/fpaInstances/ImageFilters.i new file mode 100644 index 0000000..e773c11 --- /dev/null +++ b/lib/fpaInstances/ImageFilters.i @@ -0,0 +1,28 @@ +header #define ITK_MANUAL_INSTANTIATION + +define all_inputs=#scalar_types# +define all_outputs=#scalar_types# +define all_int_types=#int_types#;#uint_types# + +tinclude fpa/Base/Algorithm:h|hxx +tinclude fpa/Image/Algorithm:h|hxx +tinclude fpa/Image/RegionGrow:h|hxx +tinclude fpa/Base/RegionGrow:h|hxx +tinclude fpa/Image/Dijkstra:h|hxx +tinclude fpa/Image/FastMarching:h|hxx + +cinclude fpa/Base/QueueAlgorithm.hxx +cinclude fpa/Base/PriorityQueueAlgorithm.hxx +cinclude fpa/Base/Dijkstra.hxx +cinclude fpa/Base/FastMarching.hxx + +instances fpa::Base::Algorithm< itk::ImageToImageFilter< itk::Image< #all_inputs#, #pdims# >, itk::Image< #all_outputs#, #pdims# > >, itk::Index< #pdims# >, #all_outputs# > +instances fpa::Image::Algorithm< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > + +instances fpa::Base::RegionGrow< fpa::Image::Algorithm< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > > +instances fpa::Image::RegionGrow< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > + +instances fpa::Image::Dijkstra< itk::Image< #scalar_types#, #pdims# >, itk::Image< #real_types#, #pdims# > > +instances fpa::Image::FastMarching< itk::Image< #scalar_types#, #pdims# >, itk::Image< #real_types#, #pdims# > > + +** eof - $RCSfile$ diff --git a/lib/fpaInstances/ImageFunctors.i b/lib/fpaInstances/ImageFunctors.i new file mode 100644 index 0000000..e410091 --- /dev/null +++ b/lib/fpaInstances/ImageFunctors.i @@ -0,0 +1,16 @@ +header #define ITK_MANUAL_INSTANTIATION + +define all_int_types=#int_types#;#uint_types# +define i_scalar_types=#scalar_types# +define o_scalar_types=#scalar_types# + +tinclude fpa/Image/Functors/VertexCost:h|hxx +tinclude fpa/Image/Functors/SimpleNeighborhood:h|hxx +tinclude fpa/Image/Functors/RegionGrow/BinaryThreshold:h|hxx +cinclude itkImage.h + +instances fpa::Image::Functors::VertexCost< itk::Image< #i_scalar_types#, #pdims# >, #o_scalar_types# > +instances fpa::Image::Functors::SimpleNeighborhood< #pdims# > +instances fpa::Image::Functors::RegionGrow::BinaryThreshold< itk::Image< #scalar_types#, #pdims# >, #all_int_types# > + +** eof - $RCSfile$ diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 7305462..383c5d6 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -13,31 +13,43 @@ IF(USE_cpPlugins) SET( _dirs ImageAlgorithms - RegionGrowFunctors - DijkstraFunctors + # RegionGrowFunctors + # DijkstraFunctors ) - OPTION(BUILD_ExperimentationPlugins "Build plugins for experimentation?" OFF) - IF(BUILD_ExperimentationPlugins) - LIST(APPEND _dirs Experiments) - ENDIF(BUILD_ExperimentationPlugins) FOREACH(_d ${_dirs}) cpPlugins_BuildPluginsLibrary( - fpaPlugins${_d} ${CMAKE_CURRENT_SOURCE_DIR}/${_d} + fpaPlugins_${_d} ${CMAKE_CURRENT_SOURCE_DIR}/${_d} ) TARGET_LINK_LIBRARIES( - fpaPlugins${_d} + fpaPlugins_${_d} cpPlugins cpPluginsDataObjects cpExtensions ${fpa_AllInstances} ) ENDFOREACH(_d) - TARGET_LINK_LIBRARIES( - fpaPluginsImageAlgorithms - cpPlugins_ITKUnaryFunctorFilters - fpaPluginsRegionGrowFunctors - fpaPluginsDijkstraFunctors - ) + +# OPTION(BUILD_ExperimentationPlugins "Build plugins for experimentation?" OFF) +# IF(BUILD_ExperimentationPlugins) +# LIST(APPEND _dirs Experiments) +# ENDIF(BUILD_ExperimentationPlugins) + +# FOREACH(_d ${_dirs}) +# cpPlugins_BuildPluginsLibrary( +# fpaPlugins${_d} ${CMAKE_CURRENT_SOURCE_DIR}/${_d} +# ) +# TARGET_LINK_LIBRARIES( +# fpaPlugins${_d} +# cpPlugins cpPluginsDataObjects cpExtensions +# ${fpa_AllInstances} +# ) +# ENDFOREACH(_d) +# TARGET_LINK_LIBRARIES( +# fpaPluginsImageAlgorithms +# cpPlugins_ITKUnaryFunctorFilters +# fpaPluginsRegionGrowFunctors +# fpaPluginsDijkstraFunctors +# ) ENDIF(USE_cpPlugins) ## eof - $RCSfile$ diff --git a/plugins/DijkstraFunctors/SimpleImageDijkstraCost.cxx b/plugins/DijkstraFunctors/SimpleImageDijkstraCost.cxx index e19327a..a053e86 100644 --- a/plugins/DijkstraFunctors/SimpleImageDijkstraCost.cxx +++ b/plugins/DijkstraFunctors/SimpleImageDijkstraCost.cxx @@ -2,7 +2,8 @@ #include #include -#include + +// TODO: #include // ------------------------------------------------------------------------- fpaPluginsDijkstraFunctors::SimpleImageDijkstraCost:: @@ -53,19 +54,21 @@ template< class _TImage, class _TOutput > void fpaPluginsDijkstraFunctors::SimpleImageDijkstraCost:: _GD1( _TImage* image ) { - typedef - fpa::Image::Functors::SimpleDijkstraCost< _TImage, _TOutput > - _TFunctor; - auto out = this->GetOutput( "Output" ); - auto f = out->GetITK< _TFunctor >( ); - if( f == NULL ) - { - typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); - f = ptr_f.GetPointer( ); - out->SetITK( f ); + /* TODO + typedef + fpa::Image::Functors::SimpleDijkstraCost< _TImage, _TOutput > + _TFunctor; + auto out = this->GetOutput( "Output" ); + auto f = out->GetITK< _TFunctor >( ); + if( f == NULL ) + { + typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); + f = ptr_f.GetPointer( ); + out->SetITK( f ); - } // fi - f->SetUseImageSpacing( this->m_Parameters.GetBool( "UseImageSpacing" ) ); + } // fi + f->SetUseImageSpacing( this->m_Parameters.GetBool( "UseImageSpacing" ) ); + */ } // eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/BaseFilter.cxx b/plugins/ImageAlgorithms/BaseFilter.cxx index ae7c6c3..3772488 100644 --- a/plugins/ImageAlgorithms/BaseFilter.cxx +++ b/plugins/ImageAlgorithms/BaseFilter.cxx @@ -11,7 +11,6 @@ BaseFilter( ) this->_ConfigureInput< _TImage >( "Input", true, false ); this->_ConfigureInput< _TData >( "Seeds", true, false ); - this->_ConfigureInput< _TData >( "Neighborhood", false, false ); this->_ConfigureOutput< _TImage >( "Output" ); this->m_Parameters.ConfigureAsUint( "NeighborhoodOrder", 1 ); diff --git a/plugins/ImageAlgorithms/BaseFilter.h b/plugins/ImageAlgorithms/BaseFilter.h index 2568881..0b871a5 100644 --- a/plugins/ImageAlgorithms/BaseFilter.h +++ b/plugins/ImageAlgorithms/BaseFilter.h @@ -2,8 +2,11 @@ #define __fpaPluginsImageAlgorithms__BaseFilter__h__ #include -#include + #include +#include + +#define ITK_MANUAL_INSTANTIATION #include namespace fpaPluginsImageAlgorithms @@ -14,10 +17,10 @@ namespace fpaPluginsImageAlgorithms : public cpPlugins::Pipeline::ProcessObject { public: - typedef BaseFilter Self; + typedef BaseFilter Self; typedef cpPlugins::Pipeline::ProcessObject Superclass; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; public: itkTypeMacro( BaseFilter, cpPlugins::Pipeline::ProcessObject ); @@ -28,19 +31,10 @@ namespace fpaPluginsImageAlgorithms virtual ~BaseFilter( ); template< class _TFilter, class _TImage > - inline void _ConfigureFilter( _TFilter* filter, _TImage* image ); - - /* TODO - - template< class _TFilter > - inline void _ExecuteFilter( _TFilter* filter ); - - template< class _TFilter > - inline void _ConfigureDebugger( _TFilter* filter ); - - template< class _TFilter > - inline void _DeconfigureDebugger( _TFilter* filter ); - */ + inline void _ConfigureFilter( + _TFilter* filter, _TImage* image, + std::vector< typename _TImage::IndexType >& seeds + ); private: // Purposely not implemented. @@ -53,11 +47,14 @@ namespace fpaPluginsImageAlgorithms // ------------------------------------------------------------------------- template< class _TFilter, class _TImage > void fpaPluginsImageAlgorithms::BaseFilter:: -_ConfigureFilter( _TFilter* filter, _TImage* image ) +_ConfigureFilter( + _TFilter* filter, _TImage* image, + std::vector< typename _TImage::IndexType >& seeds + ) { typedef typename _TFilter::TNeighborhoodFunction _TNeighborhood; typedef - fpa::Image::Functors::SimpleNeighborhood< typename _TImage::Superclass > + fpa::Image::Functors::SimpleNeighborhood< _TImage::ImageDimension > _TSimpleNeigh; // Simple configuration @@ -65,35 +62,30 @@ _ConfigureFilter( _TFilter* filter, _TImage* image ) filter->SetStopAtOneFront( this->m_Parameters.GetBool( "StopAtOneFront" ) ); // Neighborhood function - auto neig = this->GetInputData< _TNeighborhood >( "Neighborhood" ); - if( neig == NULL ) - { - typename _TSimpleNeigh::Pointer sfunc = _TSimpleNeigh::New( ); - sfunc->SetOrder( this->m_Parameters.GetUint( "NeighborhoodOrder" ) ); - filter->SetNeighborhoodFunction( sfunc ); - } - else - filter->SetNeighborhoodFunction( neig ); + typename _TSimpleNeigh::Pointer sfunc = _TSimpleNeigh::New( ); + sfunc->SetOrder( this->m_Parameters.GetUint( "NeighborhoodOrder" ) ); + filter->SetNeighborhoodFunction( sfunc ); // Assign seeds - auto seeds = this->GetInputData< vtkPolyData >( "Seeds" ); - if( seeds != NULL ) + seeds.clear( ); + auto pnt_seeds = this->GetInputData< vtkPolyData >( "Seeds" ); + if( pnt_seeds != NULL ) { typename _TImage::PointType pnt; typename _TImage::IndexType idx; unsigned int dim = ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3; - for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i ) + for( int i = 0; i < pnt_seeds->GetNumberOfPoints( ); ++i ) { double buf[ 3 ]; - seeds->GetPoint( i, buf ); + pnt_seeds->GetPoint( i, buf ); pnt.Fill( 0 ); for( unsigned int d = 0; d < dim; ++d ) pnt[ d ] = buf[ d ]; if( image->TransformPhysicalPointToIndex( pnt, idx ) ) - filter->AddSeed( idx, 0 ); + seeds.push_back( idx ); } // rof diff --git a/plugins/ImageAlgorithms/Dijkstra.cxx b/plugins/ImageAlgorithms/Dijkstra.cxx index 45f0118..c15d96f 100644 --- a/plugins/ImageAlgorithms/Dijkstra.cxx +++ b/plugins/ImageAlgorithms/Dijkstra.cxx @@ -11,8 +11,8 @@ Dijkstra( ) typedef cpPlugins::Pipeline::DataObject _TData; typedef cpInstances::DataObjects::Image _TMST; - this->_ConfigureInput< _TData >( "Cost", false, false ); - this->_ConfigureInput< _TData >( "CostConversion", false, false ); + this->_ConfigureInput< _TData >( "VertexFunction", false, false ); + this->_ConfigureInput< _TData >( "ConversionFunction", false, false ); this->_ConfigureOutput< _TMST >( "MST" ); std::vector< std::string > choices; @@ -56,20 +56,31 @@ void fpaPluginsImageAlgorithms::Dijkstra:: _GD1( _TInputImage* image ) { typedef fpa::Image::Dijkstra< _TInputImage, _TOutputImage > _TFilter; - typedef typename _TFilter::TCostConversionFunction _TCostConversion; - typedef typename _TFilter::TCostFunction _TCost; + typedef typename _TFilter::TConversionFunction _TConversionFunction; + typedef typename _TFilter::TVertexFunction _TVertexFunction; auto filter = this->_CreateITK< _TFilter >( ); - this->_ConfigureFilter( filter, image ); - auto cost = this->GetInputData< _TCost >( "Cost" ); - auto conv = this->GetInputData< _TCostConversion >( "CostConversion" ); - if( cost != NULL ) - filter->SetCostFunction( cost ); - if( conv != NULL ) - filter->SetCostConversionFunction( conv ); + std::vector< typename _TInputImage::IndexType > seeds; + this->_ConfigureFilter( filter, image, seeds ); + filter->ClearSeeds( ); + for( auto seed : seeds ) + filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) ); filter->Update( ); this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); - this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) ); + + /* TODO + auto filter = this->_CreateITK< _TFilter >( ); + this->_ConfigureFilter( filter, image ); + auto cost = this->GetInputData< _TCost >( "Cost" ); + auto conv = this->GetInputData< _TCostConversion >( "CostConversion" ); + if( cost != NULL ) + filter->SetCostFunction( cost ); + if( conv != NULL ) + filter->SetCostConversionFunction( conv ); + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); + this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) ); + */ } // eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/FastMarching.cxx b/plugins/ImageAlgorithms/FastMarching.cxx new file mode 100644 index 0000000..5805e30 --- /dev/null +++ b/plugins/ImageAlgorithms/FastMarching.cxx @@ -0,0 +1,86 @@ +#include +#include + +#include + +// ------------------------------------------------------------------------- +fpaPluginsImageAlgorithms::FastMarching:: +FastMarching( ) + : Superclass( ) +{ + typedef cpPlugins::Pipeline::DataObject _TData; + typedef cpInstances::DataObjects::Image _TMST; + + this->_ConfigureInput< _TData >( "VertexFunction", false, false ); + this->_ConfigureInput< _TData >( "ConversionFunction", false, false ); + this->_ConfigureOutput< _TMST >( "MST" ); + + std::vector< std::string > choices; + choices.push_back( "float" ); + choices.push_back( "double" ); + this->m_Parameters.ConfigureAsChoices( "ResultType", choices ); + this->m_Parameters.SetSelectedChoice( "ResultType", "float" ); +} + +// ------------------------------------------------------------------------- +fpaPluginsImageAlgorithms::FastMarching:: +~FastMarching( ) +{ +} + +// ------------------------------------------------------------------------- +void fpaPluginsImageAlgorithms::FastMarching:: +_GenerateData( ) +{ + auto o = this->GetInputData( "Input" ); + cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 ) + this->_Error( "Invalid input image." ); +} + +// ------------------------------------------------------------------------- +template< class _TImage > +void fpaPluginsImageAlgorithms::FastMarching:: +_GD0( _TImage* image ) +{ + typedef itk::Image< float, _TImage::ImageDimension > _TFloat; + typedef itk::Image< double, _TImage::ImageDimension > _TDouble; + + auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" ); + if ( rtype == "float" ) this->_GD1< _TImage, _TFloat >( image ); + else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image ); +} + +// ------------------------------------------------------------------------- +template< class _TInputImage, class _TOutputImage > +void fpaPluginsImageAlgorithms::FastMarching:: +_GD1( _TInputImage* image ) +{ + typedef fpa::Image::FastMarching< _TInputImage, _TOutputImage > _TFilter; + typedef typename _TFilter::TConversionFunction _TConversionFunction; + typedef typename _TFilter::TVertexFunction _TVertexFunction; + + auto filter = this->_CreateITK< _TFilter >( ); + std::vector< typename _TInputImage::IndexType > seeds; + this->_ConfigureFilter( filter, image, seeds ); + filter->ClearSeeds( ); + for( auto seed : seeds ) + filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) ); + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); + + /* TODO + auto filter = this->_CreateITK< _TFilter >( ); + this->_ConfigureFilter( filter, image ); + auto cost = this->GetInputData< _TCost >( "Cost" ); + auto conv = this->GetInputData< _TCostConversion >( "CostConversion" ); + if( cost != NULL ) + filter->SetCostFunction( cost ); + if( conv != NULL ) + filter->SetCostConversionFunction( conv ); + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); + this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) ); + */ +} + +// eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/FastMarching.h b/plugins/ImageAlgorithms/FastMarching.h new file mode 100644 index 0000000..3238975 --- /dev/null +++ b/plugins/ImageAlgorithms/FastMarching.h @@ -0,0 +1,27 @@ +#ifndef __fpaPluginsImageAlgorithms__FastMarching__h__ +#define __fpaPluginsImageAlgorithms__FastMarching__h__ + +#include + +namespace fpaPluginsImageAlgorithms +{ + /** + */ + class fpaPluginsImageAlgorithms_EXPORT FastMarching + : public BaseFilter + { + cpPluginsObject( FastMarching, BaseFilter, fpaImageAlgorithms ); + + protected: + template< class _TImage > + inline void _GD0( _TImage* image ); + + template< class _TInputImage, class _TOutputPixel > + inline void _GD1( _TInputImage* image ); + }; + +} // ecapseman + +#endif // __fpaPluginsImageAlgorithms__FastMarching__h__ + +// eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/ImageAlgorithms.i b/plugins/ImageAlgorithms/ImageAlgorithms.i index 0dcdcec..a805d13 100644 --- a/plugins/ImageAlgorithms/ImageAlgorithms.i +++ b/plugins/ImageAlgorithms/ImageAlgorithms.i @@ -1,23 +1,23 @@ header #define ITK_MANUAL_INSTANTIATION -tinclude fpa/Image/Functors/SimpleNeighborhood:h|hxx -instances fpa::Image::Functors::SimpleNeighborhood< itk::Image< #scalar_types#, #pdims# > > - -cinclude fpa/Base/RegionGrow.hxx -define all_int_types=#int_types#;#uint_types# -tinclude fpa/Image/RegionGrow:h|hxx -tinclude fpa/Image/MoriRegionGrowHelper:h|hxx -tinclude fpa/Image/MoriRegionGrow:h|hxx -instances fpa::Image::RegionGrow< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > -instances fpa::Image::MoriRegionGrowHelper< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > -instances fpa::Image::MoriRegionGrow< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > - -cinclude fpa/Base/Dijkstra.hxx -tinclude fpa/Image/Dijkstra:h|hxx -instances fpa::Image::Dijkstra< itk::Image< #scalar_types#, #pdims# >, itk::Image< #real_types#, #pdims# > > - -tinclude fpa/Image/SkeletonFilter:h|hxx -instances fpa::Image::SkeletonFilter< itk::Image< #real_types#, #pdims# > > +*tinclude fpa/Image/Functors/SimpleNeighborhood:h|hxx +*instances fpa::Image::Functors::SimpleNeighborhood< itk::Image< #scalar_types#, #pdims# > > + +*cinclude fpa/Base/RegionGrow.hxx +*define all_int_types=#int_types#;#uint_types# +*tinclude fpa/Image/RegionGrow:h|hxx +*tinclude fpa/Image/MoriRegionGrowHelper:h|hxx +*tinclude fpa/Image/MoriRegionGrow:h|hxx +*instances fpa::Image::RegionGrow< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > +*instances fpa::Image::MoriRegionGrowHelper< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > +*instances fpa::Image::MoriRegionGrow< itk::Image< #scalar_types#, #pdims# >, itk::Image< #all_int_types#, #pdims# > > + +*cinclude fpa/Base/Dijkstra.hxx +*tinclude fpa/Image/Dijkstra:h|hxx +*instances fpa::Image::Dijkstra< itk::Image< #scalar_types#, #pdims# >, itk::Image< #real_types#, #pdims# > > + +*tinclude fpa/Image/SkeletonFilter:h|hxx +*instances fpa::Image::SkeletonFilter< itk::Image< #real_types#, #pdims# > > diff --git a/plugins/ImageAlgorithms/MoriRegionGrow.cxx b/plugins/ImageAlgorithms/MoriRegionGrow.cxx index f8e323c..cda8979 100644 --- a/plugins/ImageAlgorithms/MoriRegionGrow.cxx +++ b/plugins/ImageAlgorithms/MoriRegionGrow.cxx @@ -61,47 +61,49 @@ template< class _TInputImage, class _TOutputPixel > void fpaPluginsImageAlgorithms::MoriRegionGrow:: _GD1( _TInputImage* image ) { - typedef - itk::Image< _TOutputPixel, _TInputImage::ImageDimension > - _TOutputImage; - typedef fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage > _TFilter; + /* TODO + typedef + itk::Image< _TOutputPixel, _TInputImage::ImageDimension > + _TOutputImage; + typedef fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage > _TFilter; - auto filter = this->_CreateITK< _TFilter >( ); - filter->SetInput( image ); - filter->SetInsideValue( this->m_Parameters.GetInt( "InsideValue" ) ); - filter->SetOutsideValue( this->m_Parameters.GetInt( "OutsideValue" ) ); - filter->SetStep( this->m_Parameters.GetReal( "Step" ) ); - filter->SetLower( this->m_Parameters.GetReal( "Lower" ) ); - filter->SetUpper( this->m_Parameters.GetReal( "Upper" ) ); + auto filter = this->_CreateITK< _TFilter >( ); + filter->SetInput( image ); + filter->SetInsideValue( this->m_Parameters.GetInt( "InsideValue" ) ); + filter->SetOutsideValue( this->m_Parameters.GetInt( "OutsideValue" ) ); + filter->SetStep( this->m_Parameters.GetReal( "Step" ) ); + filter->SetLower( this->m_Parameters.GetReal( "Lower" ) ); + filter->SetUpper( this->m_Parameters.GetReal( "Upper" ) ); - // Assign seed - auto seeds = this->GetInputData< vtkPolyData >( "Seed" ); - if( seeds != NULL ) - { - typename _TInputImage::PointType pnt; - typename _TInputImage::IndexType idx; - unsigned int dim = - ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3; - if( seeds->GetNumberOfPoints( ) > 0 ) - { - double buf[ 3 ]; - seeds->GetPoint( 0, buf ); - pnt.Fill( 0 ); - for( unsigned int d = 0; d < dim; ++d ) - pnt[ d ] = buf[ d ]; + // Assign seed + auto seeds = this->GetInputData< vtkPolyData >( "Seed" ); + if( seeds != NULL ) + { + typename _TInputImage::PointType pnt; + typename _TInputImage::IndexType idx; + unsigned int dim = + ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3; + if( seeds->GetNumberOfPoints( ) > 0 ) + { + double buf[ 3 ]; + seeds->GetPoint( 0, buf ); + pnt.Fill( 0 ); + for( unsigned int d = 0; d < dim; ++d ) + pnt[ d ] = buf[ d ]; - if( image->TransformPhysicalPointToIndex( pnt, idx ) ) - filter->SetSeed( idx ); - } - else - this->_Error( "No given seeds." ); - } - else - this->_Error( "No given seeds." ); + if( image->TransformPhysicalPointToIndex( pnt, idx ) ) + filter->SetSeed( idx ); + } + else + this->_Error( "No given seeds." ); + } + else + this->_Error( "No given seeds." ); - filter->Update( ); - this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); - this->GetOutput( "AuxiliaryOutput" )->SetITK( filter->GetAuxiliaryImage( ) ); + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); + this->GetOutput( "AuxiliaryOutput" )->SetITK( filter->GetAuxiliaryImage( ) ); + */ } // eof - $RCSfile$ diff --git a/plugins/ImageAlgorithms/RegionGrow.cxx b/plugins/ImageAlgorithms/RegionGrow.cxx index bec55ee..e1aff3e 100644 --- a/plugins/ImageAlgorithms/RegionGrow.cxx +++ b/plugins/ImageAlgorithms/RegionGrow.cxx @@ -59,11 +59,18 @@ _GD1( _TInputImage* image ) typedef fpa::Image::RegionGrow< _TInputImage, _TOutputImage > _TFilter; typedef typename _TFilter::TGrowFunction _TGrow; + _TOutputPixel i_val = _TOutputPixel( this->m_Parameters.GetInt( "InsideValue" ) ); + _TOutputPixel o_val = _TOutputPixel( this->m_Parameters.GetInt( "OutsideValue" ) ); + auto filter = this->_CreateITK< _TFilter >( ); - this->_ConfigureFilter( filter, image ); + std::vector< typename _TInputImage::IndexType > seeds; + this->_ConfigureFilter( filter, image, seeds ); + filter->ClearSeeds( ); + for( auto seed : seeds ) + filter->AddSeed( seed, i_val ); filter->SetGrowFunction( this->GetInputData< _TGrow >( "GrowFunction" ) ); - filter->SetInsideValue( this->m_Parameters.GetInt( "InsideValue" ) ); - filter->SetOutsideValue( this->m_Parameters.GetInt( "OutsideValue" ) ); + filter->SetInsideValue( i_val ); + filter->SetOutsideValue( o_val ); filter->Update( ); this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); } diff --git a/plugins/ImageAlgorithms/SkeletonFilter.cxx b/plugins/ImageAlgorithms/SkeletonFilter.cxx index 8d434c7..03689aa 100644 --- a/plugins/ImageAlgorithms/SkeletonFilter.cxx +++ b/plugins/ImageAlgorithms/SkeletonFilter.cxx @@ -2,9 +2,12 @@ #include #include -#include #include -#include + +/* TODO + #include + #include +*/ // ------------------------------------------------------------------------- fpaPluginsImageAlgorithms::SkeletonFilter:: @@ -41,36 +44,38 @@ template< class _TImage > void fpaPluginsImageAlgorithms::SkeletonFilter:: _GD0( _TImage* image ) { - typedef fpa::Image::SkeletonFilter< _TImage > _TFilter; - auto filter = this->_CreateITK< _TFilter >( ); - filter->SetInput( image ); + /* TODO + typedef fpa::Image::SkeletonFilter< _TImage > _TFilter; + auto filter = this->_CreateITK< _TFilter >( ); + filter->SetInput( image ); - auto seeds = this->GetInputData< vtkPolyData >( "Seeds" ); - if( seeds != NULL ) - { - typename _TImage::PointType pnt; - typename _TImage::IndexType idx; - unsigned int dim = - ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3; + auto seeds = this->GetInputData< vtkPolyData >( "Seeds" ); + if( seeds != NULL ) + { + typename _TImage::PointType pnt; + typename _TImage::IndexType idx; + unsigned int dim = + ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3; - for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i ) - { - double buf[ 3 ]; - seeds->GetPoint( i, buf ); - pnt.Fill( 0 ); - for( unsigned int d = 0; d < dim; ++d ) - pnt[ d ] = buf[ d ]; + for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i ) + { + double buf[ 3 ]; + seeds->GetPoint( i, buf ); + pnt.Fill( 0 ); + for( unsigned int d = 0; d < dim; ++d ) + pnt[ d ] = buf[ d ]; - if( image->TransformPhysicalPointToIndex( pnt, idx ) ) - filter->AddSeed( idx, 0 ); + if( image->TransformPhysicalPointToIndex( pnt, idx ) ) + filter->AddSeed( idx, 0 ); - } // rof + } // rof - } // fi + } // fi - filter->Update( ); - this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) ); - this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) ); + filter->Update( ); + this->GetOutput( "Skeleton" )->SetITK( filter->GetSkeleton( ) ); + this->GetOutput( "Marks" )->SetITK( filter->GetMarks( ) ); + */ } // eof - $RCSfile$ diff --git a/plugins/RegionGrowFunctors/BinaryThreshold.cxx b/plugins/RegionGrowFunctors/BinaryThreshold.cxx index f385e4a..3a4da31 100644 --- a/plugins/RegionGrowFunctors/BinaryThreshold.cxx +++ b/plugins/RegionGrowFunctors/BinaryThreshold.cxx @@ -42,82 +42,84 @@ template< class _TImage > void fpaPluginsRegionGrowFunctors::BinaryThreshold:: _GD0( _TImage* image ) { - typedef itk::ConstNeighborhoodIterator< _TImage > _TInIt; - typedef - fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage > - _TFunctor; - auto out = this->GetOutput( "Output" ); - auto f = out->GetITK< _TFunctor >( ); - if( f == NULL ) - { - typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); - f = ptr_f.GetPointer( ); - out->SetITK( f ); - - } // fi - - // Compute thresholds from seeds - auto seeds = this->GetInputData< vtkPolyData >( "Seeds" ); - if( seeds != NULL ) - { - std::vector< typename _TImage::IndexType > indices; - typename _TImage::PointType pnt; - typename _TImage::IndexType idx; - unsigned int dim = - ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3; - - for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i ) - { - double buf[ 3 ]; - seeds->GetPoint( i, buf ); - pnt.Fill( 0 ); - for( unsigned int d = 0; d < dim; ++d ) - pnt[ d ] = buf[ d ]; - if( image->TransformPhysicalPointToIndex( pnt, idx ) ) - indices.push_back( idx ); - - } // rof - - typename _TImage::SizeType r; - r.Fill( this->m_Parameters.GetUint( "Radius" ) ); - - _TInIt iIt( r, image, image->GetRequestedRegion( ) ); - double v_s1 = double( 0 ); - double v_s2 = double( 0 ); - double v_n = double( 0 ); - double v_min = std::numeric_limits< double >::max( ); - double v_max = -v_min; - for( auto idxIt = indices.begin( ); idxIt != indices.end( ); ++idxIt ) - { - iIt.SetLocation( *idxIt ); - for( unsigned int i = 0; i < iIt.Size( ); ++i ) - { - double v = double( iIt.GetPixel( i ) ); - v_s1 += v; - v_s2 += v * v; - v_n += double( 1 ); - v_min = ( v < v_min )? v: v_min; - v_max = ( v_max < v )? v: v_max; - - } // rof - - } // rof - double m = v_s1 / v_n; - double s = ( v_s2 - ( ( v_s1 * v_s1 ) / v_n ) ) / ( v_n - double( 1 ) ); - s = std::sqrt( s ); - v_min = m - s; - v_max = m + s; - f->SetLower( v_min ); - f->SetUpper( v_max ); - this->m_Parameters.SetReal( "Lower", f->GetLower( ) ); - this->m_Parameters.SetReal( "Upper", f->GetUpper( ) ); - } - else - { - f->SetLower( this->m_Parameters.GetReal( "Lower" ) ); - f->SetUpper( this->m_Parameters.GetReal( "Upper" ) ); - - } // fi + /* TODO + typedef itk::ConstNeighborhoodIterator< _TImage > _TInIt; + typedef + fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage > + _TFunctor; + auto out = this->GetOutput( "Output" ); + auto f = out->GetITK< _TFunctor >( ); + if( f == NULL ) + { + typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); + f = ptr_f.GetPointer( ); + out->SetITK( f ); + + } // fi + + // Compute thresholds from seeds + auto seeds = this->GetInputData< vtkPolyData >( "Seeds" ); + if( seeds != NULL ) + { + std::vector< typename _TImage::IndexType > indices; + typename _TImage::PointType pnt; + typename _TImage::IndexType idx; + unsigned int dim = + ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3; + + for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i ) + { + double buf[ 3 ]; + seeds->GetPoint( i, buf ); + pnt.Fill( 0 ); + for( unsigned int d = 0; d < dim; ++d ) + pnt[ d ] = buf[ d ]; + if( image->TransformPhysicalPointToIndex( pnt, idx ) ) + indices.push_back( idx ); + + } // rof + + typename _TImage::SizeType r; + r.Fill( this->m_Parameters.GetUint( "Radius" ) ); + + _TInIt iIt( r, image, image->GetRequestedRegion( ) ); + double v_s1 = double( 0 ); + double v_s2 = double( 0 ); + double v_n = double( 0 ); + double v_min = std::numeric_limits< double >::max( ); + double v_max = -v_min; + for( auto idxIt = indices.begin( ); idxIt != indices.end( ); ++idxIt ) + { + iIt.SetLocation( *idxIt ); + for( unsigned int i = 0; i < iIt.Size( ); ++i ) + { + double v = double( iIt.GetPixel( i ) ); + v_s1 += v; + v_s2 += v * v; + v_n += double( 1 ); + v_min = ( v < v_min )? v: v_min; + v_max = ( v_max < v )? v: v_max; + + } // rof + + } // rof + double m = v_s1 / v_n; + double s = ( v_s2 - ( ( v_s1 * v_s1 ) / v_n ) ) / ( v_n - double( 1 ) ); + s = std::sqrt( s ); + v_min = m - s; + v_max = m + s; + f->SetLower( v_min ); + f->SetUpper( v_max ); + this->m_Parameters.SetReal( "Lower", f->GetLower( ) ); + this->m_Parameters.SetReal( "Upper", f->GetUpper( ) ); + } + else + { + f->SetLower( this->m_Parameters.GetReal( "Lower" ) ); + f->SetUpper( this->m_Parameters.GetReal( "Upper" ) ); + + } // fi + */ } // eof - $RCSfile$ diff --git a/plugins/RegionGrowFunctors/RegionGrowFunctors.i b/plugins/RegionGrowFunctors/RegionGrowFunctors.i index e43240d..8279950 100644 --- a/plugins/RegionGrowFunctors/RegionGrowFunctors.i +++ b/plugins/RegionGrowFunctors/RegionGrowFunctors.i @@ -2,6 +2,6 @@ header #define ITK_MANUAL_INSTANTIATION cinclude itkImage.h tinclude fpa/Image/Functors/RegionGrow/BinaryThreshold:h|hxx -instances fpa::Image::Functors::RegionGrow::BinaryThreshold< itk::Image< #scalar_types#, #pdims# > > +** instances fpa::Image::Functors::RegionGrow::BinaryThreshold< itk::Image< #scalar_types#, #pdims# > > ** eof - $RCSfile$