SET(
_examples
RegionGrow_00
+ FastMarching_00
MoriRegionGrow_00
Skeleton_00
)
--- /dev/null
+#include <itkImage.h>
+#include <itkImageFileWriter.h>
+#include <fpa/Image/FastMarching.h>
+
+// -------------------------------------------------------------------------
+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$
#include <itkFunctionBase.h>
#include <fpa/Config.h>
#include <fpa/Base/Events.h>
+#include <fpa/Base/Functors/VertexCostFunctionBase.h>
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;
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( );
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;
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;
} // 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$
#ifndef __fpa__Base__Dijkstra__h__
#define __fpa__Base__Dijkstra__h__
-#include <vector>
-#include <fpa/Config.h>
-#include <itkFunctionBase.h>
-#include <fpa/Base/DijkstraCostFunctionBase.h>
+#include <fpa/Base/PriorityQueueAlgorithm.h>
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;
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
Self& operator=( const Self& other );
protected:
- _TQueue m_Queue;
- typename TCostFunction::Pointer m_CostFunction;
- typename TCostConversionFunction::Pointer m_CostConversionFunction;
-
unsigned long m_MSTIndex;
};
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;
} // 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$
+++ /dev/null
-#ifndef __fpa__Base__DijkstraCostFunctionBase__h__
-#define __fpa__Base__DijkstraCostFunctionBase__h__
-
-#include <itkObject.h>
-#include <itkObjectFactory.h>
-
-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$
--- /dev/null
+#ifndef __fpa__Base__FastMarching__h__
+#define __fpa__Base__FastMarching__h__
+
+#include <fpa/Base/PriorityQueueAlgorithm.h>
+
+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 <fpa/Base/FastMarching.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __fpa__Base__FastMarching__h__
+
+// eof - $RCSfile$
--- /dev/null
+#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$
#include <itkObject.h>
#include <itkObjectFactory.h>
+#include <fpa/Base/Functors/VertexCostFunctionBase.h>
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( )
{ }
// Purposely not defined
Base( const Self& other );
Self& operator=( const Self& other );
+
+ protected:
+ _TOutput m_InsideValue;
+ _TOutput m_OutsideValue;
};
} // ecapseman
{
/**
*/
- 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:
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:
--- /dev/null
+#ifndef __fpa__Base__Functors__VertexCostFunctionBase__h__
+#define __fpa__Base__Functors__VertexCostFunctionBase__h__
+
+#include <itkObject.h>
+#include <itkObjectFactory.h>
+
+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$
--- /dev/null
+#ifndef __fpa__Base__PriorityQueueAlgorithm__h__
+#define __fpa__Base__PriorityQueueAlgorithm__h__
+
+#include <queue>
+
+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 <fpa/Base/PriorityQueueAlgorithm.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __fpa__Base__PriorityQueueAlgorithm__h__
+
+// eof - $RCSfile$
--- /dev/null
+#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$
--- /dev/null
+#ifndef __fpa__Base__QueueAlgorithm__h__
+#define __fpa__Base__QueueAlgorithm__h__
+
+#include <queue>
+#include <itkMacro.h>
+#include <itkSmartPointer.h>
+
+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 <fpa/Base/QueueAlgorithm.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __fpa__Base__QueueAlgorithm__h__
+
+// eof - $RCSfile$
--- /dev/null
+#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$
#define __fpa__Base__RegionGrow__h__
#include <queue>
-#include <fpa/Config.h>
+#include <fpa/Base/QueueAlgorithm.h>
#include <fpa/Base/Functors/RegionGrow/Base.h>
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( );
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
// -------------------------------------------------------------------------
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__
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;
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
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( );
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( ) );
}
// -------------------------------------------------------------------------
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$
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 );
Dijkstra( );
virtual ~Dijkstra( );
- virtual void _BeforeGenerateData( ) override;
-
private:
// Purposely not defined
Dijkstra( const Self& other );
#ifndef __fpa__Image__Dijkstra__hxx__
#define __fpa__Image__Dijkstra__hxx__
-#include <fpa/Image/Functors/SimpleDijkstraCost.h>
+#include <fpa/Image/Functors/VertexCost.h>
// -------------------------------------------------------------------------
template< class _TInputImage, class _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 );
}
// -------------------------------------------------------------------------
{
}
-// -------------------------------------------------------------------------
-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$
--- /dev/null
+#ifndef __fpa__Image__FastMarching__h__
+#define __fpa__Image__FastMarching__h__
+
+#include <fpa/Base/FastMarching.h>
+#include <fpa/Image/Algorithm.h>
+
+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 <fpa/Image/FastMarching.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __fpa__Image__FastMarching__h__
+
+// eof - $RCSfile$
--- /dev/null
+#ifndef __fpa__Image__FastMarching__hxx__
+#define __fpa__Image__FastMarching__hxx__
+
+#include <fpa/Image/Functors/VertexCost.h>
+
+// -------------------------------------------------------------------------
+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$
{
/**
*/
- 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;
itkSetMacro( Upper, TPixel );
public:
- virtual bool Evaluate(
+ virtual TOutput Evaluate(
const TIndex& a, const TIndex& b
) const override;
#include <limits>
// -------------------------------------------------------------------------
-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 =
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( )
{
}
// -------------------------------------------------------------------------
-template< class _TImage >
-fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage >::
+template< class _TImage, class _TOutput >
+fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage, _TOutput >::
~BinaryThreshold( )
{
}
#include <vector>
#include <fpa/Image/Functors/Base.h>
#include <itkFunctionBase.h>
+#include <itkImageBase.h>
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;
#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 )
} // 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 ];
}
// -------------------------------------------------------------------------
-template< class _TImage >
-fpa::Image::Functors::SimpleNeighborhood< _TImage >::
+template< unsigned int _VDim >
+fpa::Image::Functors::SimpleNeighborhood< _VDim >::
SimpleNeighborhood( )
: Superclass( ),
m_Order( 1 )
}
// -------------------------------------------------------------------------
-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 );
}
// -------------------------------------------------------------------------
-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;
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 )
-#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 <fpa/Image/Functors/Base.h>
-#include <fpa/Base/DijkstraCostFunctionBase.h>
+#include <fpa/Base/Functors/VertexCostFunctionBase.h>
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 );
) 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:
} // ecapseman
#ifndef ITK_MANUAL_INSTANTIATION
-# include <fpa/Image/Functors/SimpleDijkstraCost.hxx>
+# include <fpa/Image/Functors/VertexCost.hxx>
#endif // ITK_MANUAL_INSTANTIATION
-#endif // __fpa__Image__Functors__SimpleDijkstraCost__h__
+#endif // __fpa__Image__Functors__VertexCost__h__
// eof - $RCSfile$
-#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 =
// -------------------------------------------------------------------------
template< class _TImage, class _TOutput >
-fpa::Image::Functors::SimpleDijkstraCost< _TImage, _TOutput >::
-SimpleDijkstraCost( )
+fpa::Image::Functors::VertexCost< _TImage, _TOutput >::
+VertexCost( )
: Superclass( ),
m_UseImageSpacing( false )
{
// -------------------------------------------------------------------------
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$
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;
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__
: 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( );
this->SetNeighborhoodFunction( nfunc );
typename _TInvFunc::Pointer ifunc = _TInvFunc::New( );
- this->SetCostConversionFunction( ifunc );
+ this->SetConversionFunction( ifunc );
}
// -------------------------------------------------------------------------
--- /dev/null
+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$
${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)
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# >
+++ /dev/null
-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$
--- /dev/null
+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$
--- /dev/null
+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$
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$
#include <cpInstances/DataObjects/Image.h>
#include <itkImage.h>
-#include <fpa/Image/Functors/SimpleDijkstraCost.h>
+
+// TODO: #include <fpa/Image/Functors/SimpleDijkstraCost.h>
// -------------------------------------------------------------------------
fpaPluginsDijkstraFunctors::SimpleImageDijkstraCost::
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$
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 );
#define __fpaPluginsImageAlgorithms__BaseFilter__h__
#include <fpaPluginsImageAlgorithms_Export.h>
-#include <cpPlugins/Pipeline/ProcessObject.h>
+
#include <vtkPolyData.h>
+#include <cpPlugins/Pipeline/ProcessObject.h>
+
+#define ITK_MANUAL_INSTANTIATION
#include <fpa/Image/Functors/SimpleNeighborhood.h>
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 );
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.
// -------------------------------------------------------------------------
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
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
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;
_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$
--- /dev/null
+#include <ImageAlgorithms/FastMarching.h>
+#include <cpInstances/DataObjects/Image.h>
+
+#include <fpa/Image/FastMarching.h>
+
+// -------------------------------------------------------------------------
+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$
--- /dev/null
+#ifndef __fpaPluginsImageAlgorithms__FastMarching__h__
+#define __fpaPluginsImageAlgorithms__FastMarching__h__
+
+#include <ImageAlgorithms/BaseFilter.h>
+
+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$
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# > >
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$
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( ) );
}
#include <cpInstances/DataObjects/Image.h>
#include <cpInstances/DataObjects/Skeleton.h>
-#include <fpa/Image/SkeletonFilter.h>
#include <itkImage.h>
-#include <vtkPolyData.h>
+
+/* TODO
+ #include <fpa/Image/SkeletonFilter.h>
+ #include <vtkPolyData.h>
+*/
// -------------------------------------------------------------------------
fpaPluginsImageAlgorithms::SkeletonFilter::
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$
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$
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$