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 _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
12 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
14 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
17 dynamic_cast< TMarks* >(
18 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
22 // -------------------------------------------------------------------------
23 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
25 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
27 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
30 dynamic_cast< const TMarks* >(
31 this->itk::ProcessObject::GetOutput( this->m_MarksIdx )
35 // -------------------------------------------------------------------------
36 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
37 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
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 _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
49 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
54 // -------------------------------------------------------------------------
55 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
57 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
58 _ConfigureOutput( const TOutputValue& v )
60 const TInputImage* in = this->GetInput( );
62 TOutputImage* out = this->GetOutput( );
63 out->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
64 out->SetRequestedRegion( in->GetRequestedRegion( ) );
65 out->SetBufferedRegion( in->GetBufferedRegion( ) );
66 out->SetSpacing( in->GetSpacing( ) );
67 out->SetOrigin( in->GetOrigin( ) );
68 out->SetDirection( in->GetDirection( ) );
72 TMarks* marks = this->GetMarks( );
73 marks->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
74 marks->SetRequestedRegion( in->GetRequestedRegion( ) );
75 marks->SetBufferedRegion( in->GetBufferedRegion( ) );
76 marks->SetSpacing( in->GetSpacing( ) );
77 marks->SetOrigin( in->GetOrigin( ) );
78 marks->SetDirection( in->GetDirection( ) );
80 marks->FillBuffer( TFrontId( 0 ) );
83 // -------------------------------------------------------------------------
84 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
86 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
87 TNeighborhood fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
88 _GetNeighbors( const TVertex& v ) const
90 typename TInputImage::RegionType region =
91 this->GetInput( )->GetRequestedRegion( );
92 TNeighborhood neighborhood;
93 if( this->m_NeigborhoodOrder != 1 )
99 for( unsigned int d = 0; d < TInputImage::ImageDimension; ++d )
101 for( int s = -1; s <= 1; s += 2 )
105 if( region.IsInside( n ) )
106 neighborhood.push_back( n );
113 return( neighborhood );
116 // -------------------------------------------------------------------------
117 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
119 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
121 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
122 _GetInputValue( const TVertex& v ) const
124 return( this->GetInput( )->GetPixel( v ) );
127 // -------------------------------------------------------------------------
128 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
130 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
131 TOutputValue fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
132 _GetOutputValue( const TVertex& v ) const
134 return( this->GetOutput( )->GetPixel( v ) );
137 // -------------------------------------------------------------------------
138 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
140 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
141 _UpdateOutputValue( const TNode& n )
143 this->GetOutput( )->SetPixel( n.Vertex, n.Value );
146 // -------------------------------------------------------------------------
147 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
149 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
150 _IsMarked( const TVertex& v ) const
152 return( this->GetMarks( )->GetPixel( v ) > 0 );
155 // -------------------------------------------------------------------------
156 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
158 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
159 _GetMark( const TVertex& v ) const
161 return( ( unsigned long )( this->GetMarks( )->GetPixel( v ) ) );
164 // -------------------------------------------------------------------------
165 template< class _TInputImage, class _TOutputImage, class _TMarksInterface, class _TSeedsInterface >
167 fpa::Image::Algorithm< _TInputImage, _TOutputImage, _TMarksInterface, _TSeedsInterface >::
168 _Mark( const TVertex& v, unsigned long frontId )
170 this->GetMarks( )->SetPixel( v, TFrontId( frontId ) );
174 #endif // __fpa__Image__Algorithm__hxx__