1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Image__Algorithm__hxx__
7 #define __fpa__Image__Algorithm__hxx__
9 // -------------------------------------------------------------------------
10 template< class _TTraits, class _TMarks, class _TSeeds >
11 typename fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::TMarks*
12 fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
16 dynamic_cast< TMarks* >(
17 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
22 // -------------------------------------------------------------------------
23 template< class _TTraits, class _TMarks, class _TSeeds >
24 const typename fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::TMarks*
25 fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
29 dynamic_cast< const TMarks* >(
30 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
35 // -------------------------------------------------------------------------
36 template< class _TTraits, class _TMarks, class _TSeeds >
37 fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
40 m_NeigborhoodOrder( 1 )
42 this->m_MarksIdx = this->GetNumberOfRequiredOutputs( );
43 this->itk::ProcessObject::SetNumberOfRequiredOutputs( this->m_MarksIdx + 1 );
44 this->SetNthOutput( this->m_MarksIdx, TMarks::New( ) );
47 // -------------------------------------------------------------------------
48 template< class _TTraits, class _TMarks, class _TSeeds >
49 fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
54 // -------------------------------------------------------------------------
55 template< class _TTraits, class _TMarks, class _TSeeds >
56 typename fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::TNodes
57 fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
60 const TInputImage* input = this->GetInput( );
61 typename TInputImage::RegionType region = input->GetRequestedRegion( );
62 TSeeds& seeds = this->GetSeeds( );
65 typename TSeeds::iterator sIt = seeds.begin( );
66 for( ; sIt != seeds.end( ); ++sIt )
70 input->TransformPhysicalPointToIndex( sIt->Point, sIt->Vertex );
72 input->TransformIndexToPhysicalPoint( sIt->Vertex, sIt->Point );
73 if( region.IsInside( sIt->Vertex ) )
75 sIt->IsUnified = true;
76 node.Vertex = sIt->Vertex;
77 node.Parent = node.Vertex;
78 if( sIt->FrontId == 0 )
79 node.FrontId = nodes.size( ) + 1;
81 node.FrontId = sIt->FrontId;
85 sIt->IsUnified = false;
92 // -------------------------------------------------------------------------
93 template< class _TTraits, class _TMarks, class _TSeeds >
94 void fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
95 _ConfigureOutput( const TOutputValue& v )
97 const TInputImage* in = this->GetInput( );
99 TOutputImage* out = this->GetOutput( );
100 out->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
101 out->SetRequestedRegion( in->GetRequestedRegion( ) );
102 out->SetBufferedRegion( in->GetBufferedRegion( ) );
103 out->SetSpacing( in->GetSpacing( ) );
104 out->SetOrigin( in->GetOrigin( ) );
105 out->SetDirection( in->GetDirection( ) );
107 out->FillBuffer( v );
109 TMarks* marks = this->GetMarks( );
110 marks->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
111 marks->SetRequestedRegion( in->GetRequestedRegion( ) );
112 marks->SetBufferedRegion( in->GetBufferedRegion( ) );
113 marks->SetSpacing( in->GetSpacing( ) );
114 marks->SetOrigin( in->GetOrigin( ) );
115 marks->SetDirection( in->GetDirection( ) );
117 marks->FillBuffer( TFrontId( 0 ) );
120 // -------------------------------------------------------------------------
121 template< class _TTraits, class _TMarks, class _TSeeds >
122 typename fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::TNeighborhood
123 fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
124 _GetNeighbors( const TVertex& v ) const
126 typename TInputImage::RegionType region =
127 this->GetInput( )->GetRequestedRegion( );
128 TNeighborhood neighborhood;
129 if( this->m_NeigborhoodOrder != 1 )
135 for( unsigned int d = 0; d < TInputImage::ImageDimension; ++d )
137 for( int s = -1; s <= 1; s += 2 )
141 if( region.IsInside( n ) )
142 neighborhood.push_back( n );
149 return( neighborhood );
152 // -------------------------------------------------------------------------
153 template< class _TTraits, class _TMarks, class _TSeeds >
154 typename fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::TInputValue
155 fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
156 _GetInputValue( const TVertex& v ) const
158 return( this->GetInput( )->GetPixel( v ) );
161 // -------------------------------------------------------------------------
162 template< class _TTraits, class _TMarks, class _TSeeds >
163 typename fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::TOutputValue
164 fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
165 _GetOutputValue( const TVertex& v ) const
167 return( this->GetOutput( )->GetPixel( v ) );
170 // -------------------------------------------------------------------------
171 template< class _TTraits, class _TMarks, class _TSeeds >
172 void fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
173 _UpdateOutputValue( TNode& n )
175 this->GetOutput( )->SetPixel( n.Vertex, n.Value );
178 // -------------------------------------------------------------------------
179 template< class _TTraits, class _TMarks, class _TSeeds >
180 bool fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
181 _IsMarked( const TVertex& v ) const
183 return( this->GetMarks( )->GetPixel( v ) > 0 );
186 // -------------------------------------------------------------------------
187 template< class _TTraits, class _TMarks, class _TSeeds >
188 unsigned long fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
189 _GetMark( const TVertex& v ) const
191 return( ( unsigned long )( this->GetMarks( )->GetPixel( v ) ) );
194 // -------------------------------------------------------------------------
195 template< class _TTraits, class _TMarks, class _TSeeds >
196 void fpa::Image::Algorithm< _TTraits, _TMarks, _TSeeds >::
197 _Mark( const TVertex& v, unsigned long frontId )
199 this->GetMarks( )->SetPixel( v, TFrontId( frontId ) );
202 #endif // __fpa__Image__Algorithm__hxx__