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 typename fpa::Image::Algorithm< I, O, A >::
10 TMinimumSpanningTree* fpa::Image::Algorithm< I, O, A >::
11 GetMinimumSpanningTree( )
14 dynamic_cast< TMinimumSpanningTree* >(
15 this->itk::ProcessObject::GetOutput( 1 )
20 // -------------------------------------------------------------------------
21 template< class I, class O, class A >
22 const typename fpa::Image::Algorithm< I, O, A >::
23 TMinimumSpanningTree* fpa::Image::Algorithm< I, O, A >::
24 GetMinimumSpanningTree( ) const
27 dynamic_cast< const TMinimumSpanningTree* >(
28 this->itk::ProcessObject::GetOutput( 1 )
33 // -------------------------------------------------------------------------
34 template< class I, class O, class A >
35 void fpa::Image::Algorithm< I, O, A >::
36 GraftMinimumSpanningTree( itk::DataObject* obj )
38 TMinimumSpanningTree* mst = dynamic_cast< TMinimumSpanningTree* >( obj );
40 this->GraftNthOutput( 1, mst );
43 // -------------------------------------------------------------------------
44 template< class I, class O, class A >
45 fpa::Image::Algorithm< I, O, A >::
48 m_NeighborhoodOrder( 1 )
50 this->itk::ProcessObject::SetNumberOfRequiredOutputs( 2 );
51 this->itk::ProcessObject::SetNthOutput( 0, O::New( ) );
52 this->itk::ProcessObject::SetNthOutput( 1, TMinimumSpanningTree::New( ) );
55 // -------------------------------------------------------------------------
56 template< class I, class O, class A >
57 fpa::Image::Algorithm< I, O, A >::
62 // -------------------------------------------------------------------------
63 template< class I, class O, class A >
64 void fpa::Image::Algorithm< I, O, A >::
65 _BeforeGenerateData( )
67 this->Superclass::_BeforeGenerateData( );
68 this->AllocateOutputs( );
71 // -------------------------------------------------------------------------
72 template< class I, class O, class A >
73 void fpa::Image::Algorithm< I, O, A >::
76 this->Superclass::_AfterGenerateData( );
77 this->GetMinimumSpanningTree( )->SetCollisions( this->m_Collisions );
80 // -------------------------------------------------------------------------
81 template< class I, class O, class A >
82 unsigned long fpa::Image::Algorithm< I, O, A >::
83 _NumberOfVertices( ) const
85 return( this->GetInput( )->GetRequestedRegion( ).GetNumberOfPixels( ) );
88 // -------------------------------------------------------------------------
89 template< class I, class O, class A >
90 const typename fpa::Image::Algorithm< I, O, A >::
91 TValue& fpa::Image::Algorithm< I, O, A >::
92 _VertexValue( const TVertex& v ) const
94 return( this->GetInput( )->GetPixel( v ) );
97 // -------------------------------------------------------------------------
98 template< class I, class O, class A >
99 double fpa::Image::Algorithm< I, O, A >::
100 _Distance( const TVertex& a, const TVertex& b ) const
102 typename I::PointType pa, pb;
103 this->GetInput( )->TransformIndexToPhysicalPoint( a, pa );
104 this->GetInput( )->TransformIndexToPhysicalPoint( b, pb );
105 return( double( pa.EuclideanDistanceTo( pb ) ) );
108 // -------------------------------------------------------------------------
109 template< class I, class O, class A >
110 bool fpa::Image::Algorithm< I, O, A >::
111 _HasEdge( const TVertex& a, const TVertex& b ) const
113 unsigned long dist = 0;
114 for( unsigned int d = 0; d < I::ImageDimension; d++ )
115 dist += std::abs( long( a[ d ] ) - long( b[ d ] ) );
116 if( this->m_NeighborhoodOrder == 1 )
119 return( dist <= I::ImageDimension );
122 // -------------------------------------------------------------------------
123 template< class I, class O, class A >
124 void fpa::Image::Algorithm< I, O, A >::
125 _Neighborhood( _TVertices& neighborhood, const TVertex& v ) const
127 typename I::RegionType reg = this->GetInput( )->GetRequestedRegion( );
129 neighborhood.clear( );
130 if( this->m_NeighborhoodOrder == 1 )
132 for( unsigned int d = 0; d < I::ImageDimension; d++ )
134 for( int i = -1; i <= 1; i += 2 )
138 if( reg.IsInside( n ) )
139 neighborhood.push_back( n );
147 typedef itk::ConstNeighborhoodIterator< I > TNeighIt;
148 typename I::SizeType nSize;
151 TNeighIt nIt( nSize, this->GetInput( ), reg );
152 nIt.SetLocation( v );
153 for( unsigned int i = 0; i < nIt.Size( ); i++ )
155 TVertex n = nIt.GetIndex( i );
158 if( reg.IsInside( n ) )
159 neighborhood.push_back( n );
166 // -------------------------------------------------------------------------
167 template< class I, class O, class A >
168 void fpa::Image::Algorithm< I, O, A >::
173 // -------------------------------------------------------------------------
174 template< class I, class O, class A >
175 const typename fpa::Image::Algorithm< I, O, A >::
176 TResult& fpa::Image::Algorithm< I, O, A >::
177 _Result( const TVertex& v ) const
179 return( this->GetOutput( )->GetPixel( v ) );
182 // -------------------------------------------------------------------------
183 template< class I, class O, class A >
184 void fpa::Image::Algorithm< I, O, A >::
185 _SetResult( const TVertex& v, const TResult& r )
187 this->GetOutput( )->SetPixel( v, r );
190 // -------------------------------------------------------------------------
191 template< class I, class O, class A >
192 const typename fpa::Image::Algorithm< I, O, A >::
193 _TNode& fpa::Image::Algorithm< I, O, A >::
194 _Node( const TVertex& v ) const
196 return( this->GetMinimumSpanningTree( )->GetPixel( v ) );
199 // -------------------------------------------------------------------------
200 template< class I, class O, class A >
201 void fpa::Image::Algorithm< I, O, A >::
205 far_node.Label = Self::FarLabel;
206 this->GetMinimumSpanningTree( )->FillBuffer( far_node );
209 // -------------------------------------------------------------------------
210 template< class I, class O, class A >
211 void fpa::Image::Algorithm< I, O, A >::
212 _Mark( const _TNode& node )
214 this->GetMinimumSpanningTree( )->SetPixel( node.Vertex, node );
217 #endif // __FPA__IMAGE__ALGORITHM__HXX__