-#ifndef __FPA__IMAGE__ALGORITHM__HXX__
-#define __FPA__IMAGE__ALGORITHM__HXX__
+#ifndef __fpa__Image__Algorithm__hxx__
+#define __fpa__Image__Algorithm__hxx__
-#include <itkConstNeighborhoodIterator.h>
+// Send Piotr's code to Anna
+
+#include <itkImage.h>
+#include <fpa/Image/Functors/SimpleNeighborhood.h>
// -------------------------------------------------------------------------
template< class _TInputImage, class _TOutputImage >
fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
Algorithm( )
- : Superclass( ),
- m_NeighborhoodOrder( 1 )
+ : Superclass( )
{
+ typedef fpa::Image::Functors::SimpleNeighborhood< _TInputImage::ImageDimension > _TNeigh;
+ typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
+
+ 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 );
+
+ typename _TNeigh::Pointer neigh = _TNeigh::New( );
+ this->SetNeighborhoodFunction( neigh );
}
// -------------------------------------------------------------------------
{
this->Superclass::_BeforeGenerateData( );
this->AllocateOutputs( );
+
+ TNeighborhoodFunction* neighFunc =
+ dynamic_cast< TNeighborhoodFunction* >(
+ this->GetNeighborhoodFunction( )
+ );
+ if( neighFunc == NULL )
+ itkExceptionMacro( << "NeighborhoodFunction not well defined." );
+ neighFunc->SetImage( this->GetInput( ) );
+
+ TVertexFunction* vertexFunc =
+ dynamic_cast< TVertexFunction* >(
+ this->GetVertexFunction( )
+ );
+ if( vertexFunc != NULL )
+ vertexFunc->SetImage( this->GetInput( ) );
}
// -------------------------------------------------------------------------
void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
_InitMarks( )
{
- TOutputImage* out = this->GetOutput( );
- this->m_Marks = TMarkImage::New( );
- this->m_Marks->CopyInformation( out );
- this->m_Marks->SetRequestedRegion( out->GetRequestedRegion( ) );
- this->m_Marks->SetBufferedRegion( out->GetBufferedRegion( ) );
- this->m_Marks->Allocate( );
- this->m_Marks->FillBuffer( 0 );
+ typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
+ _TMarks* marks =
+ dynamic_cast< _TMarks* >(
+ this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
+ );
+ marks->FillBuffer( 0 );
}
// -------------------------------------------------------------------------
template< class _TInputImage, class _TOutputImage >
void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
-_InitResults( )
+_InitResults( const TOutput& init_value )
+{
+ this->GetOutput( )->FillBuffer( init_value );
+}
+
+// -------------------------------------------------------------------------
+template< class _TInputImage, class _TOutputImage >
+bool fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+_IsMarked( const TVertex& v ) const
{
- this->GetOutput( )->FillBuffer( TScalar( 0 ) );
+ 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 ) != 0 );
}
// -------------------------------------------------------------------------
template< class _TInputImage, class _TOutputImage >
void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
-_DeallocateAuxiliary( )
+_Mark( const _TQueueNode& n )
{
- this->m_Marks = NULL;
+ 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 _TInputImage, class _TOutputImage >
typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
TFrontId fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
-_GetMark( const TVertex& v )
+_GetMark( const TVertex& v ) const
{
- if( this->m_Marks->GetRequestedRegion( ).IsInside( v ) )
- return( this->m_Marks->GetPixel( v ) );
- else
- return( 0 );
+ 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 _TInputImage, class _TOutputImage >
void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
-_Visit( const TNode& n )
+_UpdateResult( const _TQueueNode& n )
{
- if( this->m_Marks->GetRequestedRegion( ).IsInside( n.Vertex ) )
- {
- this->m_Marks->SetPixel( n.Vertex, n.FrontId );
- this->GetOutput( )->SetPixel( n.Vertex, n.Result );
-
- } // fi
+ this->GetOutput( )->SetPixel( n.Vertex, n.Result );
}
// -------------------------------------------------------------------------
template< class _TInputImage, class _TOutputImage >
-typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
-TVertices fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
-_GetNeighborhood( const TVertex& v ) const
+typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::TOutput
+fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
+_GetResult( const TVertex& v ) const
{
- TVertices neighs;
- auto reg = this->GetInput( )->GetRequestedRegion( );
- if( this->m_NeighborhoodOrder == 1 )
- {
- for( unsigned int d = 0; d < _TInputImage::ImageDimension; d++ )
- {
- for( int i = -1; i <= 1; i += 2 )
- {
- TVertex n = v;
- n[ d ] += i;
- if( reg.IsInside( n ) )
- neighs.push_back( n );
-
- } // rof
-
- } // rof
- }
+ if( this->GetOutput( )->GetLargestPossibleRegion( ).IsInside( v ) )
+ return( this->GetOutput( )->GetPixel( v ) );
else
- {
- typedef itk::ConstNeighborhoodIterator< _TInputImage > _TNeighIt;
- typename _TInputImage::SizeType nSize;
- nSize.Fill( 1 );
-
- _TNeighIt nIt( nSize, this->GetInput( ), reg );
- nIt.SetLocation( v );
- for( unsigned int i = 0; i < nIt.Size( ); i++ )
- {
- TVertex n = nIt.GetIndex( i );
- if( n == v )
- continue;
- if( reg.IsInside( n ) )
- neighs.push_back( n );
-
- } // rof
-
- } // fi
- return( neighs );
+ 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__
+#endif // __fpa__Image__Algorithm__hxx__
// eof - $RCSfile$