1 #ifndef __FPA__IMAGE__ALGORITHM__HXX__
2 #define __FPA__IMAGE__ALGORITHM__HXX__
5 #include <itkConstNeighborhoodIterator.h>
7 // -------------------------------------------------------------------------
8 template< class I, class O, class A >
9 fpa::Image::Algorithm< I, O, A >::
12 m_NeighborhoodOrder( 1 )
16 // -------------------------------------------------------------------------
17 template< class I, class O, class A >
18 fpa::Image::Algorithm< I, O, A >::
23 // -------------------------------------------------------------------------
24 template< class I, class O, class A >
25 void fpa::Image::Algorithm< I, O, A >::
26 _BeforeGenerateData( )
28 this->Superclass::_BeforeGenerateData( );
29 this->AllocateOutputs( );
32 // -------------------------------------------------------------------------
33 template< class I, class O, class A >
34 void fpa::Image::Algorithm< I, O, A >::
37 this->Superclass::_AfterGenerateData( );
38 this->GetMinimumSpanningTree( )->SetCollisions( this->m_Collisions );
41 // -------------------------------------------------------------------------
42 template< class I, class O, class A >
43 unsigned long fpa::Image::Algorithm< I, O, A >::
44 _NumberOfVertices( ) const
46 return( this->GetInput( )->GetRequestedRegion( ).GetNumberOfPixels( ) );
49 // -------------------------------------------------------------------------
50 template< class I, class O, class A >
51 const typename fpa::Image::Algorithm< I, O, A >::
52 TValue& fpa::Image::Algorithm< I, O, A >::
53 _VertexValue( const TVertex& v ) const
55 return( this->GetInput( )->GetPixel( v ) );
58 // -------------------------------------------------------------------------
59 template< class I, class O, class A >
60 double fpa::Image::Algorithm< I, O, A >::
61 _Distance( const TVertex& a, const TVertex& b ) const
63 typename I::PointType pa, pb;
64 this->GetInput( )->TransformIndexToPhysicalPoint( a, pa );
65 this->GetInput( )->TransformIndexToPhysicalPoint( b, pb );
66 return( double( pa.EuclideanDistanceTo( pb ) ) );
69 // -------------------------------------------------------------------------
70 template< class I, class O, class A >
71 bool fpa::Image::Algorithm< I, O, A >::
72 _HasEdge( const TVertex& a, const TVertex& b ) const
74 unsigned long dist = 0;
75 for( unsigned int d = 0; d < I::ImageDimension; d++ )
76 dist += std::abs( long( a[ d ] ) - long( b[ d ] ) );
77 if( this->m_NeighborhoodOrder == 1 )
80 return( dist <= I::ImageDimension );
83 // -------------------------------------------------------------------------
84 template< class I, class O, class A >
85 void fpa::Image::Algorithm< I, O, A >::
86 _Neighborhood( _TVertices& neighborhood, const TVertex& v ) const
88 typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
90 neighborhood.clear( );
91 if( this->m_NeighborhoodOrder == 1 )
93 for( unsigned int d = 0; d < I::ImageDimension; d++ )
95 for( int i = -1; i <= 1; i += 2 )
99 if( reg.IsInside( n ) )
100 neighborhood.push_back( n );
108 typedef itk::ConstNeighborhoodIterator< I > TNeighIt;
109 typename I::SizeType nSize;
112 TNeighIt nIt( nSize, this->GetInput( ), reg );
113 nIt.SetLocation( v );
114 for( unsigned int i = 0; i < nIt.Size( ); i++ )
116 TVertex n = nIt.GetIndex( i );
119 if( reg.IsInside( n ) )
120 neighborhood.push_back( n );
127 // -------------------------------------------------------------------------
128 template< class I, class O, class A >
129 void fpa::Image::Algorithm< I, O, A >::
134 // -------------------------------------------------------------------------
135 template< class I, class O, class A >
136 const typename fpa::Image::Algorithm< I, O, A >::
137 TResult& fpa::Image::Algorithm< I, O, A >::
138 _Result( const TVertex& v ) const
140 return( this->GetOutput( )->GetPixel( v ) );
143 // -------------------------------------------------------------------------
144 template< class I, class O, class A >
145 void fpa::Image::Algorithm< I, O, A >::
146 _SetResult( const TVertex& v, const _TNode& n )
148 this->GetOutput( )->SetPixel( v, n.Result );
149 this->GetMinimumSpanningTree( )->SetParent( v, n.Parent, n.FrontId );
152 #endif // __FPA__IMAGE__ALGORITHM__HXX__