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 vertexFunc->SetImage( this->GetInput( ) );
58 // -------------------------------------------------------------------------
59 template< class _TInputImage, class _TOutputImage >
60 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
63 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
65 dynamic_cast< _TMarks* >(
66 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
68 marks->FillBuffer( 0 );
71 // -------------------------------------------------------------------------
72 template< class _TInputImage, class _TOutputImage >
73 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
74 _InitResults( const TOutput& init_value )
76 this->GetOutput( )->FillBuffer( init_value );
79 // -------------------------------------------------------------------------
80 template< class _TInputImage, class _TOutputImage >
81 bool fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
82 _IsMarked( const TVertex& v ) const
84 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
85 const _TMarks* marks =
86 dynamic_cast< const _TMarks* >(
87 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
89 return( marks->GetPixel( v ) != 0 );
92 // -------------------------------------------------------------------------
93 template< class _TInputImage, class _TOutputImage >
94 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
95 _Mark( const _TQueueNode& n )
97 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
99 dynamic_cast< _TMarks* >(
100 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
102 marks->SetPixel( n.Vertex, n.FrontId );
105 // -------------------------------------------------------------------------
106 template< class _TInputImage, class _TOutputImage >
107 typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
108 TFrontId fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
109 _GetMark( const TVertex& v ) const
111 typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
112 const _TMarks* marks =
113 dynamic_cast< const _TMarks* >(
114 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
116 return( marks->GetPixel( v ) );
119 // -------------------------------------------------------------------------
120 template< class _TInputImage, class _TOutputImage >
121 bool fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
122 _UpdateResult( _TQueueNode& n )
124 bool res = this->Superclass::_UpdateResult( n );
125 std::cout << n.Vertex << " " << n.Result << std::endl;
126 this->GetOutput( )->SetPixel( n.Vertex, n.Result );
130 // -------------------------------------------------------------------------
131 template< class _TInputImage, class _TOutputImage >
132 typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::TOutput
133 fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
134 _GetResult( const TVertex& v ) const
136 if( this->GetOutput( )->GetLargestPossibleRegion( ).IsInside( v ) )
137 return( this->GetOutput( )->GetPixel( v ) );
139 return( this->m_InitResult );
142 // -------------------------------------------------------------------------
143 template< class _TInputImage, class _TOutputImage >
144 unsigned int fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
145 _GetNumberOfDimensions( ) const
147 return( _TInputImage::ImageDimension );
150 #endif // __fpa__Image__Algorithm__hxx__