#ifndef __fpa__Image__Algorithm__hxx__ #define __fpa__Image__Algorithm__hxx__ // Send Piotr's code to Anna #include #include // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: Algorithm( ) : Superclass( ) { typedef itk::ImageBase< _TInputImage::ImageDimension > _TImageBase; typedef fpa::Image::Functors::SimpleNeighborhood< _TImageBase > _TNeigh; typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks; this->m_MarksIdx = this->GetNumberOfRequiredOutputs( ); this->itk::ProcessObject::SetNumberOfRequiredOutputs( this->m_MarksIdx + 1 ); typename _TMarks::Pointer marks = _TMarks::New( ); this->SetNthOutput( this->m_MarksIdx, marks ); typename _TNeigh::Pointer neigh = _TNeigh::New( ); this->SetNeighborhoodFunction( neigh ); } // ------------------------------------------------------------------------- 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( ); TNeighborhoodFunction* neighFunc = dynamic_cast< TNeighborhoodFunction* >( this->GetNeighborhoodFunction( ) ); if( neighFunc == NULL ) itkExceptionMacro( << "NeighborhoodFunction not well defined." ); neighFunc->SetImage( this->GetInput( ) ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > void fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _InitMarks( ) { typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks; _TMarks* marks = dynamic_cast< _TMarks* >( this->itk::ProcessObject::GetOutput( this->m_MarksIdx ) ); marks->FillBuffer( 0 ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > void fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _InitResults( const TOutput& init_value ) { this->GetOutput( )->FillBuffer( init_value ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > bool fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _IsMarked( const TVertex& v ) const { typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks; const _TMarks* marks = dynamic_cast< const _TMarks* >( this->itk::ProcessObject::GetOutput( this->m_MarksIdx ) ); return( marks->GetPixel( v ) != 0 ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > void fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _Mark( const _TQueueNode& n ) { typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks; _TMarks* marks = dynamic_cast< _TMarks* >( this->itk::ProcessObject::GetOutput( this->m_MarksIdx ) ); marks->SetPixel( n.Vertex, n.FrontId ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > typename fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: TFrontId fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _GetMark( const TVertex& v ) const { typedef itk::Image< TFrontId, _TInputImage::ImageDimension > _TMarks; const _TMarks* marks = dynamic_cast< const _TMarks* >( this->itk::ProcessObject::GetOutput( this->m_MarksIdx ) ); return( marks->GetPixel( v ) ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputImage > void fpa::Image::Algorithm< _TInputImage, _TOutputImage >:: _UpdateResult( const _TQueueNode& n ) { this->GetOutput( )->SetPixel( n.Vertex, n.Result ); } #endif // __fpa__Image__Algorithm__hxx__ // eof - $RCSfile$