-#ifndef __FPA__IMAGE__ALGORITHM__HXX__
-#define __FPA__IMAGE__ALGORITHM__HXX__
+#ifndef __fpa__Image__Algorithm__hxx__
+#define __fpa__Image__Algorithm__hxx__
-#include <cmath>
-#include <limits>
-#include <itkConstNeighborhoodIterator.h>
+// Send Piotr's code to Anna
+
+#include <itkImage.h>
+#include <fpa/Image/Functors/SimpleNeighborhood.h>
// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-fpa::Image::Algorithm< I, A, CC >::
+template< class _TInputImage, class _TOutputImage >
+fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
Algorithm( )
- : Superclass( ),
- m_NeighborhoodOrder( 1 )
+ : Superclass( )
{
- this->m_CostConversion = TCostConversionFunction::New( );
-}
+ typedef itk::ImageBase< _TInputImage::ImageDimension > _TImageBase;
+ typedef fpa::Image::Functors::SimpleNeighborhood< _TImageBase > _TNeigh;
+ typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
-// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-fpa::Image::Algorithm< I, A, CC >::
-~Algorithm( )
-{
-}
+ this->m_MarksIdx = this->GetNumberOfRequiredOutputs( );
+ this->itk::ProcessObject::SetNumberOfRequiredOutputs( this->m_MarksIdx + 1 );
+ typename _TMarks::Pointer marks = _TMarks::New( );
+ this->SetNthOutput( this->m_MarksIdx, marks );
-// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-bool fpa::Image::Algorithm< I, A, CC >::
-_UpdateResult( _TNode& n )
-{
- bool ret = this->Superclass::_UpdateResult( n );
- this->GetOutput( )->SetPixel( n.Vertex, n.Result );
- return( ret );
+ typename _TNeigh::Pointer neigh = _TNeigh::New( );
+ this->SetNeighborhoodFunction( neigh );
}
// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-unsigned long fpa::Image::Algorithm< I, A, CC >::
-_NumberOfVertices( ) const
+template< class _TInputImage, class _TOutputImage >
+fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+~Algorithm( )
{
- return(
- this->GetInput( )->GetLargestPossibleRegion( ).GetNumberOfPixels( )
- );
}
// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-typename fpa::Image::Algorithm< I, A, CC >::
-TVertexValue fpa::Image::Algorithm< I, A, CC >::
-_Value( const TVertex& v ) const
+template< class _TInputImage, class _TOutputImage >
+void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+_BeforeGenerateData( )
{
- return( this->GetInput( )->GetPixel( v ) );
-}
+ this->Superclass::_BeforeGenerateData( );
+ this->AllocateOutputs( );
-// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-typename fpa::Image::Algorithm< I, A, CC >::
-TResult fpa::Image::Algorithm< I, A, CC >::
-_Result( const TVertex& v ) const
-{
- return( this->GetOutput( )->GetPixel( v ) );
+ TNeighborhoodFunction* neighFunc =
+ dynamic_cast< TNeighborhoodFunction* >(
+ this->GetNeighborhoodFunction( )
+ );
+ if( neighFunc == NULL )
+ itkExceptionMacro( << "NeighborhoodFunction not well defined." );
+ neighFunc->SetImage( this->GetInput( ) );
}
// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-double fpa::Image::Algorithm< I, A, CC >::
-_Norm( const TVertex& a, const TVertex& b ) const
+template< class _TInputImage, class _TOutputImage >
+void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+_InitMarks( )
{
- typename I::PointType pa, pb;
- this->GetInput( )->TransformIndexToPhysicalPoint( a, pa );
- this->GetInput( )->TransformIndexToPhysicalPoint( b, pb );
- return( double( pa.EuclideanDistanceTo( pb ) ) );
+ typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
+ _TMarks* marks =
+ dynamic_cast< _TMarks* >(
+ this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
+ );
+ marks->FillBuffer( 0 );
}
// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-bool fpa::Image::Algorithm< I, A, CC >::
-_Edge( const TVertex& a, const TVertex& b ) const
+template< class _TInputImage, class _TOutputImage >
+void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+_InitResults( const TOutput& init_value )
{
- unsigned long dist = 0;
- for( unsigned int d = 0; d < I::ImageDimension; d++ )
- dist += std::abs( long( a[ d ] ) - long( b[ d ] ) );
- if( this->m_NeighborhoodOrder == 1 )
- return( dist <= 1 );
- else
- return( dist <= I::ImageDimension );
+ this->GetOutput( )->FillBuffer( init_value );
}
// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-typename fpa::Image::Algorithm< I, A, CC >::
-TCost fpa::Image::Algorithm< I, A, CC >::
-_Cost( const TVertex& a, const TVertex& b ) const
+template< class _TInputImage, class _TOutputImage >
+bool fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+_IsMarked( const TVertex& v ) const
{
- static const TCost INF_COST = std::numeric_limits< TCost >::max( );
- if( this->_Edge( a, b ) )
- {
- return(
- this->m_CostConversion->Evaluate( this->GetInput( )->GetPixel( b ) )
+ typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
+ const _TMarks* marks =
+ dynamic_cast< const _TMarks* >(
+ this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
);
- }
- else
- return( INF_COST );
+ return( marks->GetPixel( v ) != 0 );
}
// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-void fpa::Image::Algorithm< I, A, CC >::
-_Neighs( const _TNode& n, _TNodes& N ) const
+template< class _TInputImage, class _TOutputImage >
+void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+_Mark( const _TQueueNode& n )
{
- typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
-
- N.clear( );
- if( this->m_NeighborhoodOrder == 1 )
- {
- for( unsigned int d = 0; d < I::ImageDimension; d++ )
- {
- for( int i = -1; i <= 1; i += 2 )
- {
- TVertex v = n.Vertex;
- v[ d ] += i;
- if( reg.IsInside( v ) )
- N.push_back( _TNode( v, n.FrontId ) );
- else
- N.push_back( n );
-
- } // rof
-
- } // rof
- }
- else
- {
- typedef itk::ConstNeighborhoodIterator< I > TNeighIt;
- typename I::SizeType nSize;
- nSize.Fill( 1 );
-
- TNeighIt nIt( nSize, this->GetInput( ), reg );
- nIt.SetLocation( n.Vertex );
- for( unsigned int i = 0; i < nIt.Size( ); i++ )
- {
- TVertex idxN = nIt.GetIndex( i );
- if( idxN == n.Vertex )
- continue;
- if( !reg.IsInside( idxN ) )
- continue;
- N.push_back( _TNode( idxN, n.FrontId ) );
-
- } // rof
-
- } // fi
+ typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
+ _TMarks* marks =
+ dynamic_cast< _TMarks* >(
+ this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
+ );
+ marks->SetPixel( n.Vertex, n.FrontId );
}
// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-void fpa::Image::Algorithm< I, A, CC >::
-_NeighsInDim( const _TNode& n, const unsigned int& d, _TNodes& N )
+template< class _TInputImage, class _TOutputImage >
+typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+TFrontId fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+_GetMark( const TVertex& v ) const
{
- typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
-
- N.clear( );
- for( int i = -1; i <= 1; i += 2 )
- {
- TVertex v = n.Vertex;
- v[ d ] += i;
- if( reg.IsInside( v ) )
- N.push_back( _TNode( v, n.FrontId ) );
-
- } // rof
+ typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
+ const _TMarks* marks =
+ dynamic_cast< const _TMarks* >(
+ this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
+ );
+ return( marks->GetPixel( v ) );
}
// -------------------------------------------------------------------------
-template< class I, class A, class CC >
-void fpa::Image::Algorithm< I, A, CC >::
-_InitializeResults( )
+template< class _TInputImage, class _TOutputImage >
+void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+_UpdateResult( const _TQueueNode& n )
{
+ this->GetOutput( )->SetPixel( n.Vertex, n.Result );
}
-#endif // __FPA__IMAGE__ALGORITHM__HXX__
+#endif // __fpa__Image__Algorithm__hxx__
// eof - $RCSfile$