1 #ifndef __fpa__Image__Algorithm__hxx__
2 #define __fpa__Image__Algorithm__hxx__
4 // Send Piotr's code to Anna
7 #include <fpa/Image/Functors/SimpleNeighborhood.h>
9 // -------------------------------------------------------------------------
10 template< class _TInputImage, class _TOutputImage >
11 fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
15 typedef itk::ImageBase< _TInputImage::ImageDimension > _TImageBase;
16 typedef fpa::Image::Functors::SimpleNeighborhood< _TImageBase > _TNeigh;
17 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
19 this->m_MarksIdx = this->GetNumberOfRequiredOutputs( );
20 this->itk::ProcessObject::SetNumberOfRequiredOutputs( this->m_MarksIdx + 1 );
21 typename _TMarks::Pointer marks = _TMarks::New( );
22 this->SetNthOutput( this->m_MarksIdx, marks );
24 typename _TNeigh::Pointer neigh = _TNeigh::New( );
25 this->SetNeighborhoodFunction( neigh );
28 // -------------------------------------------------------------------------
29 template< class _TInputImage, class _TOutputImage >
30 fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
35 // -------------------------------------------------------------------------
36 template< class _TInputImage, class _TOutputImage >
37 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
38 _BeforeGenerateData( )
40 this->Superclass::_BeforeGenerateData( );
41 this->AllocateOutputs( );
43 TNeighborhoodFunction* neighFunc =
44 dynamic_cast< TNeighborhoodFunction* >(
45 this->GetNeighborhoodFunction( )
47 if( neighFunc == NULL )
48 itkExceptionMacro( << "NeighborhoodFunction not well defined." );
49 neighFunc->SetImage( this->GetInput( ) );
52 // -------------------------------------------------------------------------
53 template< class _TInputImage, class _TOutputImage >
54 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
57 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
59 dynamic_cast< _TMarks* >(
60 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
62 marks->FillBuffer( 0 );
65 // -------------------------------------------------------------------------
66 template< class _TInputImage, class _TOutputImage >
67 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
68 _InitResults( const TOutput& init_value )
70 this->GetOutput( )->FillBuffer( init_value );
73 // -------------------------------------------------------------------------
74 template< class _TInputImage, class _TOutputImage >
75 bool fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
76 _IsMarked( const TVertex& v ) const
78 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
79 const _TMarks* marks =
80 dynamic_cast< const _TMarks* >(
81 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
83 return( marks->GetPixel( v ) != 0 );
86 // -------------------------------------------------------------------------
87 template< class _TInputImage, class _TOutputImage >
88 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
89 _Mark( const _TQueueNode& n )
91 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
93 dynamic_cast< _TMarks* >(
94 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
96 marks->SetPixel( n.Vertex, n.FrontId );
99 // -------------------------------------------------------------------------
100 template< class _TInputImage, class _TOutputImage >
101 typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
102 TFrontId fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
103 _GetMark( const TVertex& v ) const
105 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
106 const _TMarks* marks =
107 dynamic_cast< const _TMarks* >(
108 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
110 return( marks->GetPixel( v ) );
113 // -------------------------------------------------------------------------
114 template< class _TInputImage, class _TOutputImage >
115 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
116 _UpdateResult( const _TQueueNode& n )
118 this->GetOutput( )->SetPixel( n.Vertex, n.Result );
121 #endif // __fpa__Image__Algorithm__hxx__