#ifndef __FPA__IMAGE__ALGORITHM__HXX__ #define __FPA__IMAGE__ALGORITHM__HXX__ #include // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: Algorithm( ) : Superclass( ), m_NeighborhoodOrder( 1 ) { } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: ~Algorithm( ) { } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > void fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _BeforeGenerateData( ) { this->Superclass::_BeforeGenerateData( ); this->AllocateOutputs( ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > void fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _InitMarks( ) { TOutputImage* out = this->GetOutput( ); this->m_Marks = TMarkImage::New( ); this->m_Marks->CopyInformation( out ); this->m_Marks->SetRequestedRegion( out->GetRequestedRegion( ) ); this->m_Marks->SetBufferedRegion( out->GetBufferedRegion( ) ); this->m_Marks->Allocate( ); this->m_Marks->FillBuffer( 0 ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > void fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _InitResults( ) { this->GetOutput( )->FillBuffer( TScalar( 0 ) ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > void fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _DeallocateAuxiliary( ) { this->m_Marks = NULL; } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: TFrontId fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _GetMark( const TVertex& v ) { if( this->m_Marks->GetRequestedRegion( ).IsInside( v ) ) return( this->m_Marks->GetPixel( v ) ); else return( 0 ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > void fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _Visit( const TNode& n ) { if( this->m_Marks->GetRequestedRegion( ).IsInside( n.Vertex ) ) { this->m_Marks->SetPixel( n.Vertex, n.FrontId ); this->GetOutput( )->SetPixel( n.Vertex, n.Result ); } // fi } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: TVertices fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _GetNeighborhood( const TVertex& v ) const { TVertices neighs; auto reg = this->GetInput( )->GetRequestedRegion( ); if( this->m_NeighborhoodOrder == 1 ) { for( unsigned int d = 0; d < _TInputImage::ImageDimension; d++ ) { for( int i = -1; i <= 1; i += 2 ) { TVertex n = v; n[ d ] += i; if( reg.IsInside( n ) ) neighs.push_back( n ); } // rof } // rof } else { typedef itk::ConstNeighborhoodIterator< _TInputImage > _TNeighIt; typename _TInputImage::SizeType nSize; nSize.Fill( 1 ); _TNeighIt nIt( nSize, this->GetInput( ), reg ); nIt.SetLocation( v ); for( unsigned int i = 0; i < nIt.Size( ); i++ ) { TVertex n = nIt.GetIndex( i ); if( n == v ) continue; if( reg.IsInside( n ) ) neighs.push_back( n ); } // rof } // fi return( neighs ); } #endif // __FPA__IMAGE__ALGORITHM__HXX__ // eof - $RCSfile$