// ========================================================================= // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) // ========================================================================= #ifndef __RandomWalkerLabelling__hxx__ #define __RandomWalkerLabelling__hxx__ #include // ------------------------------------------------------------------------- template< class _TRawImage, class _TCostsImage, class _TLabelsImage > void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: SetInputImage( const TRawImage* i ) { this->SetInput( i ); } // ------------------------------------------------------------------------- template< class _TRawImage, class _TCostsImage, class _TLabelsImage > typename RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: TLabelsImage* RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: GetOutputLabels( ) { return( this->GetOutput( ) ); } // ------------------------------------------------------------------------- template< class _TRawImage, class _TCostsImage, class _TLabelsImage > const typename RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: TLabelsImage* RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: GetOutputLabels( ) const { return( this->GetOutput( ) ); } // ------------------------------------------------------------------------- template< class _TRawImage, class _TCostsImage, class _TLabelsImage > typename RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: TLabel RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: GetOutsideLabel( ) const { return( this->GetInitValue( ) ); } // ------------------------------------------------------------------------- template< class _TRawImage, class _TCostsImage, class _TLabelsImage > void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: SetOutsideLabel( const TLabel& v ) { this->SetInitValue( v ); } // ------------------------------------------------------------------------- template< class _TRawImage, class _TCostsImage, class _TLabelsImage > RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: RandomWalkLabelling( ) : Superclass( ), m_InsideLabel( TLabel( 1 ) ), m_LowerLabel( TLabel( 3 ) ), m_UpperLabel( TLabel( 4 ) ), m_Radius( double( 1 ) ), m_LowerThreshold( double( 0 ) ), m_UpperThreshold( double( 0 ) ), m_MaxCost( std::numeric_limits< TScalar >::max( ) ) { fpaFilterInputConfigureMacro( InputCosts, TCostsImage ); fpaFilterInputConfigureMacro( InputPath, TPath ); this->SetOutsideLabel( TLabel( 2 ) ); } // ------------------------------------------------------------------------- template< class _TRawImage, class _TCostsImage, class _TLabelsImage > RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: ~RandomWalkLabelling( ) { } // ------------------------------------------------------------------------- template< class _TRawImage, class _TCostsImage, class _TLabelsImage > void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: _PrepareSeeds( const itk::DataObject* reference ) { const TPath* path = this->GetInputPath( ); if( path->GetSize( ) > 0 ) { TNode node; node.Vertex = node.Parent = path->GetVertex( 0 ); node.FrontId = 1; this->m_UnifiedSeeds.clear( ); this->m_UnifiedSeeds.insert( node ); this->m_CurrIdx = 0; } // fi } // ------------------------------------------------------------------------- template< class _TRawImage, class _TCostsImage, class _TLabelsImage > void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: _PostComputeOutputValue( TNode& n ) { const TRawImage* raw = this->GetInput( ); const TCostsImage* costs = this->GetInputCosts( ); const TPath* path = this->GetInputPath( ); TPoint c, p; raw->TransformIndexToPhysicalPoint( path->GetVertex( this->m_CurrIdx ), c ); raw->TransformIndexToPhysicalPoint( n.Vertex, p ); double d = double( c.EuclideanDistanceTo( p ) ); if( d <= this->m_Radius ) { n.FrontId = 1; if( costs->GetPixel( n.Vertex ) == this->m_MaxCost ) { double v = double( raw->GetPixel( n.Vertex ) ); if( v <= this->m_LowerThreshold ) n.Value = this->GetLowerLabel( ); else if( v >= this->m_UpperThreshold ) n.Value = this->GetUpperLabel( ); else n.Value = TLabel( 0 ); } else n.Value = this->GetInsideLabel( ); } else { n.Value = this->GetOutsideLabel( ); n.FrontId = 0; } // fi } // ------------------------------------------------------------------------- template< class _TRawImage, class _TCostsImage, class _TLabelsImage > void RandomWalkLabelling< _TRawImage, _TCostsImage, _TLabelsImage >:: _Reinitialize( ) { const TPath* path = this->GetInputPath( ); while( this->_GetMark( path->GetVertex( this->m_CurrIdx ) ) > 0 && this->m_CurrIdx < path->GetSize( ) ) this->m_CurrIdx += 1; if( this->m_CurrIdx < path->GetSize( ) ) { TNode node; node.Vertex = node.Parent = path->GetVertex( this->m_CurrIdx ); node.FrontId = 1; this->_QueuePush( node ); } // fi } #endif // __RandomWalkLabelling__hxx__ // eof - $RCSfile$