]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/Algorithm.hxx
ed7342130ba2389b6c64bbbac1dfc3208259ae01
[FrontAlgorithms.git] / lib / fpa / Image / Algorithm.hxx
1 #ifndef __fpa__Image__Algorithm__hxx__
2 #define __fpa__Image__Algorithm__hxx__
3
4 // Send Piotr's code to Anna
5
6 #include <itkImage.h>
7 #include <fpa/Image/Functors/SimpleNeighborhood.h>
8
9 // -------------------------------------------------------------------------
10 template< class _TInputImage, class _TOutputImage >
11 fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
12 Algorithm( )
13   : Superclass( )
14 {
15   typedef itk::ImageBase< _TInputImage::ImageDimension > _TImageBase;
16   typedef fpa::Image::Functors::SimpleNeighborhood< _TImageBase > _TNeigh;
17   typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
18
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 );
23
24   typename _TNeigh::Pointer neigh = _TNeigh::New( );
25   this->SetNeighborhoodFunction( neigh );
26 }
27
28 // -------------------------------------------------------------------------
29 template< class _TInputImage, class _TOutputImage >
30 fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
31 ~Algorithm( )
32 {
33 }
34
35 // -------------------------------------------------------------------------
36 template< class _TInputImage, class _TOutputImage >
37 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
38 _BeforeGenerateData( )
39 {
40   this->Superclass::_BeforeGenerateData( );
41   this->AllocateOutputs( );
42
43   TNeighborhoodFunction* neighFunc =
44     dynamic_cast< TNeighborhoodFunction* >(
45       this->GetNeighborhoodFunction( )
46       );
47   if( neighFunc == NULL )
48     itkExceptionMacro( << "NeighborhoodFunction not well defined." );
49   neighFunc->SetImage( this->GetInput( ) );
50 }
51
52 // -------------------------------------------------------------------------
53 template< class _TInputImage, class _TOutputImage >
54 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
55 _InitMarks( )
56 {
57   typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
58   _TMarks* marks =
59     dynamic_cast< _TMarks* >(
60       this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
61       );
62   marks->FillBuffer( 0 );
63 }
64
65 // -------------------------------------------------------------------------
66 template< class _TInputImage, class _TOutputImage >
67 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
68 _InitResults( const TOutput& init_value )
69 {
70   this->GetOutput( )->FillBuffer( init_value );
71 }
72
73 // -------------------------------------------------------------------------
74 template< class _TInputImage, class _TOutputImage >
75 bool fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
76 _IsMarked( const TVertex& v ) const
77 {
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 )
82       );
83   return( marks->GetPixel( v ) != 0 );
84 }
85
86 // -------------------------------------------------------------------------
87 template< class _TInputImage, class _TOutputImage >
88 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
89 _Mark( const _TQueueNode& n )
90 {
91   typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
92   _TMarks* marks =
93     dynamic_cast< _TMarks* >(
94       this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
95       );
96   marks->SetPixel( n.Vertex, n.FrontId );
97 }
98
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
104 {
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 )
109       );
110   return( marks->GetPixel( v ) );
111 }
112
113 // -------------------------------------------------------------------------
114 template< class _TInputImage, class _TOutputImage >
115 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
116 _UpdateResult( const _TQueueNode& n )
117 {
118   this->GetOutput( )->SetPixel( n.Vertex, n.Result );
119 }
120
121 #endif // __fpa__Image__Algorithm__hxx__
122
123 // eof - $RCSfile$