]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/Algorithm.hxx
...
[FrontAlgorithms.git] / lib / fpa / Image / Algorithm.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #ifndef __fpa__Image__Algorithm__hxx__
7 #define __fpa__Image__Algorithm__hxx__
8
9 // -------------------------------------------------------------------------
10 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
11 typename
12 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
13 TMarks*
14 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
15 GetMarks( )
16 {
17   return(
18     dynamic_cast< TMarks* >(
19       this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
20       )
21     );
22 }
23
24 // -------------------------------------------------------------------------
25 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
26 const typename
27 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
28 TMarks*
29 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
30 GetMarks( ) const
31 {
32   return(
33     dynamic_cast< const TMarks* >(
34       this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
35       )
36     );
37 }
38
39 // -------------------------------------------------------------------------
40 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
41 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
42 Algorithm( )
43   : Superclass( ),
44     m_NeigborhoodOrder( 1 )
45 {
46   this->m_MarksIdx = this->GetNumberOfRequiredOutputs( );
47   this->itk::ProcessObject::SetNumberOfRequiredOutputs( this->m_MarksIdx + 1 );
48   this->SetNthOutput( this->m_MarksIdx, TMarks::New( ) );
49 }
50
51 // -------------------------------------------------------------------------
52 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
53 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
54 ~Algorithm( )
55 {
56 }
57
58 // -------------------------------------------------------------------------
59 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
60 typename
61 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
62 TNodes fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
63 _UnifySeeds( )
64 {
65   const TInputImage* input = this->GetInput( );
66   typename TInputImage::RegionType region = input->GetRequestedRegion( );
67   TSeeds seeds = this->GetSeeds( );
68   TNodes nodes;
69
70   typename TSeeds::iterator sIt = seeds.begin( );
71   for( ; sIt != seeds.end( ); ++sIt )
72   {
73     TNode node;
74     if( sIt->IsPoint )
75       input->TransformPhysicalPointToIndex( sIt->Point, sIt->Vertex );
76     else
77       input->TransformIndexToPhysicalPoint( sIt->Vertex, sIt->Point );
78     if( region.IsInside( sIt->Vertex ) )
79     {
80       sIt->IsUnified = true;
81       node.Vertex = sIt->Vertex;
82       node.Parent = node.Vertex;
83       node.FrontId = nodes.size( ) + 1;
84       nodes.insert( node );
85     }
86     else
87       sIt->IsUnified = false;
88       
89   } // rof
90
91   return( nodes );
92 }
93
94 // -------------------------------------------------------------------------
95 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
96 void
97 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
98 _ConfigureOutput( const TOutputValue& v )
99 {
100   const TInputImage* in = this->GetInput( );
101
102   TOutputImage* out = this->GetOutput( );
103   out->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
104   out->SetRequestedRegion( in->GetRequestedRegion( ) );
105   out->SetBufferedRegion( in->GetBufferedRegion( ) );
106   out->SetSpacing( in->GetSpacing( ) );
107   out->SetOrigin( in->GetOrigin( ) );
108   out->SetDirection( in->GetDirection( ) );
109   out->Allocate( );
110   out->FillBuffer( v );
111
112   TMarks* marks = this->GetMarks( );
113   marks->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
114   marks->SetRequestedRegion( in->GetRequestedRegion( ) );
115   marks->SetBufferedRegion( in->GetBufferedRegion( ) );
116   marks->SetSpacing( in->GetSpacing( ) );
117   marks->SetOrigin( in->GetOrigin( ) );
118   marks->SetDirection( in->GetDirection( ) );
119   marks->Allocate( );
120   marks->FillBuffer( TFrontId( 0 ) );
121 }
122
123 // -------------------------------------------------------------------------
124 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
125 typename
126 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
127 TNeighborhood fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
128 _GetNeighbors( const TVertex& v ) const
129 {
130   typename TInputImage::RegionType region =
131     this->GetInput( )->GetRequestedRegion( );
132   TNeighborhood neighborhood;
133   if( this->m_NeigborhoodOrder != 1 )
134   {
135     // TODO
136   }
137   else
138   {
139     for( unsigned int d = 0; d < TInputImage::ImageDimension; ++d )
140     {
141       for( int s = -1; s <= 1; s += 2 )
142       {
143         TVertex n = v;
144         n[ d ] += s;
145         if( region.IsInside( n ) )
146           neighborhood.push_back( n );
147
148       } // rof
149
150     } // rof
151
152   } // fi
153   return( neighborhood );
154 }
155
156 // -------------------------------------------------------------------------
157 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
158 typename
159 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
160 TInputValue
161 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
162 _GetInputValue( const TVertex& v ) const
163 {
164   return( this->GetInput( )->GetPixel( v ) );
165 }
166
167 // -------------------------------------------------------------------------
168 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
169 typename
170 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
171 TOutputValue fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
172 _GetOutputValue( const TVertex& v ) const
173 {
174   return( this->GetOutput( )->GetPixel( v ) );
175 }
176
177 // -------------------------------------------------------------------------
178 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
179 void
180 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
181 _UpdateOutputValue( const TNode& n )
182 {
183   this->GetOutput( )->SetPixel( n.Vertex, n.Value );
184 }
185
186 // -------------------------------------------------------------------------
187 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
188 bool
189 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
190 _IsMarked( const TVertex& v ) const
191 {
192   return( this->GetMarks( )->GetPixel( v ) > 0 );
193 }
194
195 // -------------------------------------------------------------------------
196 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
197 unsigned long
198 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
199 _GetMark( const TVertex& v ) const
200 {
201   return( ( unsigned long )( this->GetMarks( )->GetPixel( v ) ) );
202 }
203
204 // -------------------------------------------------------------------------
205 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
206 bool
207 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
208 _Mark( const TVertex& v, unsigned long frontId )
209 {
210   this->GetMarks( )->SetPixel( v, TFrontId( frontId ) );
211   return( true );
212 }
213
214 #endif // __fpa__Image__Algorithm__hxx__
215
216 // eof - $RCSfile$