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 fpa::Image::Functors::SimpleNeighborhood< _TInputImage::ImageDimension > _TNeigh;
16 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
18 this->m_MarksIdx = this->GetNumberOfRequiredOutputs( );
19 this->itk::ProcessObject::SetNumberOfRequiredOutputs( this->m_MarksIdx + 1 );
20 typename _TMarks::Pointer marks = _TMarks::New( );
21 this->SetNthOutput( this->m_MarksIdx, marks );
23 typename _TNeigh::Pointer neigh = _TNeigh::New( );
24 this->SetNeighborhoodFunction( neigh );
27 // -------------------------------------------------------------------------
28 template< class _TInputImage, class _TOutputImage >
29 fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
34 // -------------------------------------------------------------------------
35 template< class _TInputImage, class _TOutputImage >
36 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
37 _BeforeGenerateData( )
39 this->Superclass::_BeforeGenerateData( );
40 this->AllocateOutputs( );
42 TNeighborhoodFunction* neighFunc =
43 dynamic_cast< TNeighborhoodFunction* >(
44 this->GetNeighborhoodFunction( )
46 if( neighFunc == NULL )
47 itkExceptionMacro( << "NeighborhoodFunction not well defined." );
48 neighFunc->SetImage( this->GetInput( ) );
50 TVertexFunction* vertexFunc =
51 dynamic_cast< TVertexFunction* >(
52 this->GetVertexFunction( )
54 if( vertexFunc == NULL )
55 itkExceptionMacro( << "VertexFunction not well defined." );
56 vertexFunc->SetImage( this->GetInput( ) );
59 // -------------------------------------------------------------------------
60 template< class _TInputImage, class _TOutputImage >
61 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
64 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
66 dynamic_cast< _TMarks* >(
67 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
69 marks->FillBuffer( 0 );
72 // -------------------------------------------------------------------------
73 template< class _TInputImage, class _TOutputImage >
74 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
75 _InitResults( const TOutput& init_value )
77 this->GetOutput( )->FillBuffer( init_value );
80 // -------------------------------------------------------------------------
81 template< class _TInputImage, class _TOutputImage >
82 bool fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
83 _IsMarked( const TVertex& v ) const
85 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
86 const _TMarks* marks =
87 dynamic_cast< const _TMarks* >(
88 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
90 return( marks->GetPixel( v ) != 0 );
93 // -------------------------------------------------------------------------
94 template< class _TInputImage, class _TOutputImage >
95 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
96 _Mark( const _TQueueNode& n )
98 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
100 dynamic_cast< _TMarks* >(
101 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
103 marks->SetPixel( n.Vertex, n.FrontId );
106 // -------------------------------------------------------------------------
107 template< class _TInputImage, class _TOutputImage >
108 typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
109 TFrontId fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
110 _GetMark( const TVertex& v ) const
112 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
113 const _TMarks* marks =
114 dynamic_cast< const _TMarks* >(
115 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
117 return( marks->GetPixel( v ) );
120 // -------------------------------------------------------------------------
121 template< class _TInputImage, class _TOutputImage >
122 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
123 _UpdateResult( const _TQueueNode& n )
125 this->GetOutput( )->SetPixel( n.Vertex, n.Result );
128 // -------------------------------------------------------------------------
129 template< class _TInputImage, class _TOutputImage >
130 typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::TOutput
131 fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
132 _GetResult( const TVertex& v ) const
134 if( this->GetOutput( )->GetLargestPossibleRegion( ).IsInside( v ) )
135 return( this->GetOutput( )->GetPixel( v ) );
137 return( this->m_InitResult );
140 // -------------------------------------------------------------------------
141 template< class _TInputImage, class _TOutputImage >
142 unsigned int fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
143 _GetNumberOfDimensions( ) const
145 return( _TInputImage::ImageDimension );
148 #endif // __fpa__Image__Algorithm__hxx__