]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/Algorithm.hxx
...
[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
8 // -------------------------------------------------------------------------
9 template< class _TInputImage, class _TOutputImage >
10 fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
11 Algorithm( )
12   : Superclass( )
13 {
14   typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
15   this->m_MarksIdx = this->GetNumberOfRequiredOutputs( );
16   this->itk::ProcessObject::SetNumberOfRequiredOutputs( this->m_MarksIdx + 1 );
17   typename _TMarks::Pointer marks = _TMarks::New( );
18   this->SetNthOutput( this->m_MarksIdx, marks );
19 }
20
21 // -------------------------------------------------------------------------
22 template< class _TInputImage, class _TOutputImage >
23 fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
24 ~Algorithm( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 template< class _TInputImage, class _TOutputImage >
30 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
31 _BeforeGenerateData( )
32 {
33   this->Superclass::_BeforeGenerateData( );
34   this->AllocateOutputs( );
35
36   TNeighborhoodFunction* neighFunc =
37     dynamic_cast< TNeighborhoodFunction* >( this->GetNeighborhoodFunction( ) );
38   if( neighFunc == NULL )
39     itkExceptionMacro( << "NeighborhoodFunction not well defined." );
40   neighFunc->SetImage( this->GetInput( ) );
41 }
42
43 // -------------------------------------------------------------------------
44 template< class _TInputImage, class _TOutputImage >
45 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
46 _InitMarks( )
47 {
48   typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
49   _TMarks* marks =
50     dynamic_cast< _TMarks* >(
51       this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
52       );
53   marks->FillBuffer( 0 );
54 }
55
56 // -------------------------------------------------------------------------
57 template< class _TInputImage, class _TOutputImage >
58 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
59 _InitResults( const TOutput& init_value )
60 {
61   this->GetOutput( )->FillBuffer( init_value );
62 }
63
64 // -------------------------------------------------------------------------
65 template< class _TInputImage, class _TOutputImage >
66 bool fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
67 _IsMarked( const TVertex& v ) const
68 {
69   typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
70   const _TMarks* marks =
71     dynamic_cast< const _TMarks* >(
72       this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
73       );
74   return( marks->GetPixel( v ) != 0 );
75 }
76
77 // -------------------------------------------------------------------------
78 template< class _TInputImage, class _TOutputImage >
79 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
80 _Mark( const _TQueueNode& n )
81 {
82   typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
83   _TMarks* marks =
84     dynamic_cast< _TMarks* >(
85       this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
86       );
87   marks->SetPixel( n.Vertex, n.FrontId );
88 }
89
90 // -------------------------------------------------------------------------
91 template< class _TInputImage, class _TOutputImage >
92 typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
93 TFrontId fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
94 _GetMark( const TVertex& v ) const
95 {
96   typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks;
97   const _TMarks* marks =
98     dynamic_cast< const _TMarks* >(
99       this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
100       );
101   return( marks->GetPixel( v ) );
102 }
103
104 // -------------------------------------------------------------------------
105 template< class _TInputImage, class _TOutputImage >
106 void fpa::Image::Algorithm< _TInputImage, _TOutputImage >::
107 _UpdateResult( const _TQueueNode& n )
108 {
109   this->GetOutput( )->SetPixel( n.Vertex, n.Result );
110 }
111
112 #endif // __fpa__Image__Algorithm__hxx__
113
114 // eof - $RCSfile$