From: Leonardo Florez-Valencia Date: Wed, 18 Feb 2015 23:12:50 +0000 (-0500) Subject: Experiments going well :-) X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=9f7b6541d030299dff60fb93caa4371f8f9825de;p=FrontAlgorithms.git Experiments going well :-) --- diff --git a/lib/fpa/Base/Algorithm.h b/lib/fpa/Base/Algorithm.h index 187a281..fc94fa8 100644 --- a/lib/fpa/Base/Algorithm.h +++ b/lib/fpa/Base/Algorithm.h @@ -86,6 +86,8 @@ namespace fpa virtual void GenerateData( ); /// Base interface + virtual void _BeforeMainLoop ( ); + virtual void _AfterMainLoop ( ); virtual void _BeforeLoop ( ); virtual void _AfterLoop ( ); virtual void _Loop ( ); diff --git a/lib/fpa/Base/Algorithm.hxx b/lib/fpa/Base/Algorithm.hxx index 286343f..f4ccfdb 100644 --- a/lib/fpa/Base/Algorithm.hxx +++ b/lib/fpa/Base/Algorithm.hxx @@ -88,9 +88,27 @@ GenerateData( ) this->m_CollisionSites.clear( ); this->m_CollisionSites. resize( N, _TCollisionSitesRow( N, _TCollision( TVertex( ), false ) ) ); - this->_BeforeLoop( ); + + this->_BeforeMainLoop( ); + this->_InitializeMarks( ); + this->_InitializeResults( ); + this->_InitializeQueue( ); this->_Loop( ); - this->_AfterLoop( ); + this->_AfterMainLoop( ); +} + +// ------------------------------------------------------------------------- +template< class T, class B > +void fpa::Base::Algorithm< T, B >:: +_BeforeMainLoop( ) +{ +} + +// ------------------------------------------------------------------------- +template< class T, class B > +void fpa::Base::Algorithm< T, B >:: +_AfterMainLoop( ) +{ } // ------------------------------------------------------------------------- @@ -112,9 +130,7 @@ template< class T, class B > void fpa::Base::Algorithm< T, B >:: _Loop( ) { - this->_InitializeMarks( ); - this->_InitializeResults( ); - this->_InitializeQueue( ); + this->_BeforeLoop( ); while( !( this->_IsQueueEmpty( ) ) ) { _TNode n = this->_QueuePop( ); @@ -172,6 +188,7 @@ _Loop( ) } // elihw this->InvokeEvent( TEndEvent( ) ); + this->_AfterLoop( ); } // ------------------------------------------------------------------------- @@ -279,10 +296,7 @@ _Parent( const TVertex& v ) const { typename _TMarks::const_iterator mIt = this->m_Marks.find( v ); if( mIt == this->m_Marks.end( ) ) - { - TVertex v; - return( v ); - } + return( TVertex( ) ); else return( mIt->second.Parent ); } diff --git a/lib/fpa/Base/RegionGrowWithMultipleCriteria.h b/lib/fpa/Base/RegionGrowWithMultipleCriteria.h index 69fbc8e..85d0243 100644 --- a/lib/fpa/Base/RegionGrowWithMultipleCriteria.h +++ b/lib/fpa/Base/RegionGrowWithMultipleCriteria.h @@ -41,6 +41,7 @@ namespace fpa typedef typename Superclass::_TNode _TNode; typedef typename Superclass::_TNodes _TNodes; typedef typename Superclass::_TQueue _TQueue; + typedef typename Superclass::_TMarks _TMarks; public: itkTypeMacro( RegionGrowWithMultipleCriteria, RegionGrow ); @@ -54,8 +55,9 @@ namespace fpa RegionGrowWithMultipleCriteria( ); virtual ~RegionGrowWithMultipleCriteria( ); - virtual void _BeforeLoop( ); - virtual _TNode _QueuePop( ); + virtual void _BeforeMainLoop( ); + virtual void _AfterLoop( ); + virtual void _Loop( ); virtual bool _CheckMembership( const _TNode& n ) const; private: diff --git a/lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx b/lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx index 5ec51ec..0fd4378 100644 --- a/lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx +++ b/lib/fpa/Base/RegionGrowWithMultipleCriteria.hxx @@ -45,29 +45,46 @@ fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >:: // ------------------------------------------------------------------------- template< class V, class R, class VV, class VC, class B > void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >:: -_BeforeLoop( ) +_BeforeMainLoop( ) { - this->Superclass::_BeforeLoop( ); + this->Superclass::_BeforeMainLoop( ); this->m_ActualFunction = this->m_Functions.begin( ); } // ------------------------------------------------------------------------- template< class V, class R, class VV, class VC, class B > -typename fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >:: -_TNode fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >:: -_QueuePop( ) +void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >:: +_AfterLoop( ) { - _TNode node = this->Superclass::_QueuePop( ); - if( this->_IsQueueEmpty( ) ) + this->Superclass::_AfterLoop( ); + + // Replace queue + this->_QueueClear( ); + while( !( this->m_AuxiliaryQueue.empty( ) ) ) { - // Replace queue - this->m_Queue = this->m_AuxiliaryQueue; + // Get node + _TNode node = this->m_AuxiliaryQueue.front( ); + this->m_AuxiliaryQueue.pop( ); + this->_QueuePush( node ); - // Move to next function - this->m_ActualFunction++; + // Unmark it + typename _TMarks::iterator mIt = this->m_Marks.find( node.Vertex ); + if( mIt != this->m_Marks.end( ) ) + this->m_Marks.erase( mIt ); + + } // elihw + + // Move to next function + this->m_ActualFunction++; +} - } // fi - return( node ); +// ------------------------------------------------------------------------- +template< class V, class R, class VV, class VC, class B > +void fpa::Base::RegionGrowWithMultipleCriteria< V, R, VV, VC, B >:: +_Loop( ) +{ + while( this->m_ActualFunction != this->m_Functions.end( ) ) + this->Superclass::_Loop( ); } // ------------------------------------------------------------------------- diff --git a/lib/fpa/Base/TreeExtractor.h b/lib/fpa/Base/TreeExtractor.h index a0222a6..ee6499b 100644 --- a/lib/fpa/Base/TreeExtractor.h +++ b/lib/fpa/Base/TreeExtractor.h @@ -54,8 +54,8 @@ namespace fpa TreeExtractor( ); virtual ~TreeExtractor( ); - virtual void _BeforeLoop( ); - virtual void _AfterLoop( ); + virtual void _BeforeMainLoop( ); + virtual void _AfterMainLoop( ); TVertices _Path( const TVertex& s, const TVertex& e ); diff --git a/lib/fpa/Base/TreeExtractor.hxx b/lib/fpa/Base/TreeExtractor.hxx index cfeb17f..7bad1ef 100644 --- a/lib/fpa/Base/TreeExtractor.hxx +++ b/lib/fpa/Base/TreeExtractor.hxx @@ -57,18 +57,18 @@ fpa::Base::TreeExtractor< A >:: // ------------------------------------------------------------------------- template< class A > void fpa::Base::TreeExtractor< A >:: -_BeforeLoop( ) +_BeforeMainLoop( ) { - this->Superclass::_BeforeLoop( ); + this->Superclass::_BeforeMainLoop( ); this->m_Tree.clear( ); } // ------------------------------------------------------------------------- template< class A > void fpa::Base::TreeExtractor< A >:: -_AfterLoop( ) +_AfterMainLoop( ) { - this->Superclass::_AfterLoop( ); + this->Superclass::_AfterMainLoop( ); // Prepare fronts graph using Floyd-Warshall unsigned long nSeeds = this->GetNumberOfSeeds( ); diff --git a/lib/fpa/Image/Functors/RegionGrowThresholdFunction.h b/lib/fpa/Image/Functors/RegionGrowThresholdFunction.h index 6da586d..739dff4 100644 --- a/lib/fpa/Image/Functors/RegionGrowThresholdFunction.h +++ b/lib/fpa/Image/Functors/RegionGrowThresholdFunction.h @@ -48,21 +48,11 @@ namespace fpa const I* img = this->GetInputImage( ); if( img != NULL ) { - /* TODO - if( this->IsInsideBuffer( idx ) ) - { - */ TPixel v = img->GetPixel( idx ); - std::cout - << v << " " - << this->m_LowerThreshold << " " - << this->m_UpperThreshold << std::endl; return( this->m_LowerThreshold <= v && v < this->m_UpperThreshold ); - // TODO: } // fi - } // fi return( false ); } diff --git a/lib/fpa/Image/RegionGrowWithMultipleThresholds.h b/lib/fpa/Image/RegionGrowWithMultipleThresholds.h index b4c3e4e..5156b33 100644 --- a/lib/fpa/Image/RegionGrowWithMultipleThresholds.h +++ b/lib/fpa/Image/RegionGrowWithMultipleThresholds.h @@ -30,7 +30,7 @@ namespace fpa typedef typename Superclass::TMembershipFunction TMembershipFunction; typedef typename Superclass::TFunctions TFunctions; - typedef std::set< TPixel > TThresholds; + typedef std::set< TPixel > TThresholds; typedef fpa::Image::Functors::RegionGrowThresholdFunction< I > TFunction; protected: @@ -55,9 +55,10 @@ namespace fpa RegionGrowWithMultipleThresholds( ); virtual ~RegionGrowWithMultipleThresholds( ); - virtual bool _UpdateResult( _TNode& n ); - virtual void _BeforeLoop( ); + virtual void _BeforeMainLoop( ); + virtual void _AfterMainLoop( ); virtual void _AfterLoop( ); + virtual bool _UpdateResult( _TNode& n ); private: RegionGrowWithMultipleThresholds( const Self& ); // Not impl. diff --git a/lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx b/lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx index a5b2075..0cb1b66 100644 --- a/lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx +++ b/lib/fpa/Image/RegionGrowWithMultipleThresholds.hxx @@ -29,13 +29,6 @@ RegionGrowWithMultipleThresholds( ) : Superclass( ), m_DerivativeThreshold( double( 3 ) ) { - /* TODO - typedef - fpa::Image::Functors::RegionGrowThresholdFunction< I > - TFunction; - typename TFunction::Pointer function = TFunction::New( ); - this->SetMembershipFunction( function ); - */ } // ------------------------------------------------------------------------- @@ -45,61 +38,27 @@ fpa::Image::RegionGrowWithMultipleThresholds< I >:: { } -// ------------------------------------------------------------------------- -template< class I > -bool fpa::Image::RegionGrowWithMultipleThresholds< I >:: -_UpdateResult( _TNode& n ) -{ - bool ret = this->Superclass::_UpdateResult( n ); - std::cout << "Image:UpdateResult " << ret << std::endl; - - - /* TODO - if( ret ) - { - TPixel v = TPixel( this->_Cost( n.Vertex, n.Vertex ) ); - - typename THistogram::reverse_iterator hIt = this->m_Histogram.rbegin( ); - while( hIt != this->m_Histogram.rend( ) ) - { - if( v <= hIt->first ) - { - hIt->second += 1; - hIt++; - } - else - hIt = this->m_Histogram.rend( ); - - } // elihw - this->GetOutput( )->SetPixel( n.Vertex, v ); - - } // fi - */ - return( ret ); -} - // ------------------------------------------------------------------------- template< class I > void fpa::Image::RegionGrowWithMultipleThresholds< I >:: -_BeforeLoop( ) +_BeforeMainLoop( ) { const I* img = this->GetInput( ); this->ClearMembershipFunctions( ); typename TThresholds::const_iterator tIt = this->m_Thresholds.begin( ); - typename TThresholds::const_iterator prev_tIt = tIt; - for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt, ++prev_tIt ) + TPixel min_thr = *tIt; + for( ++tIt; tIt != this->m_Thresholds.end( ); ++tIt ) { typename TFunction::Pointer function = TFunction::New( ); function->SetInputImage( img ); - function->SetLowerThreshold( *prev_tIt ); + function->SetLowerThreshold( min_thr ); function->SetUpperThreshold( *tIt ); this->AddMembershipFunction( function ); - std::cout << *prev_tIt << " " << *tIt << std::endl; } // rof - this->Superclass::_BeforeLoop( ); + this->Superclass::_BeforeMainLoop( ); } // ------------------------------------------------------------------------- @@ -107,45 +66,40 @@ template< class I > void fpa::Image::RegionGrowWithMultipleThresholds< I >:: _AfterLoop( ) { - /* - typename THistogram::iterator prevIt = this->m_Histogram.begin( ); - typename THistogram::iterator currIt = prevIt; currIt++; - typename THistogram::iterator nextIt = currIt; nextIt++; - double prev_d1 = double( 0 ); - for( ; nextIt != this->m_Histogram.end( ); ++prevIt, ++currIt, ++nextIt ) - { - double d1 = double( nextIt->second ) - double( prevIt->second ); - d1 /= double( nextIt->first ) - double( prevIt->first ); - - std::cout - << currIt->first << " " - << currIt->second << " " - << d1 << " " - << ( d1 - prev_d1 ) << std::endl; - - prev_d1 = d1; - - } // rof - */ + if( this->m_ActualFunction != this->m_Functions.end( ) ) + { + TFunction* f = + dynamic_cast< TFunction* >( this->m_ActualFunction->GetPointer( ) ); + // std::cout << f->GetUpperThreshold( ) << " " << this->m_Marks.size( ) << std::endl; - /* - double prev = double( 0 ); - while( hIt != this->m_Histogram.end( ) ) - { - double curr = double( hIt->second ); - double deri = curr - prev; + } // fi + this->Superclass::_AfterLoop( ); +} - if( hIt != this->m_Histogram.begin( ) ) - std::cout << hIt->first << " " << curr << " " << deri << std::endl; +// ------------------------------------------------------------------------- +template< class I > +void fpa::Image::RegionGrowWithMultipleThresholds< I >:: +_AfterMainLoop( ) +{ + this->Superclass::_AfterMainLoop( ); +} - prev = curr; - hIt++; +// ------------------------------------------------------------------------- +template< class I > +bool fpa::Image::RegionGrowWithMultipleThresholds< I >:: +_UpdateResult( _TNode& n ) +{ + #error ACA VOY -> explicar esto!!!! cambiar salida por una especie de curva de nivel + bool ret = this->Superclass::_UpdateResult( n ); + if( this->m_ActualFunction != this->m_Functions.end( ) ) + { + TFunction* f = + dynamic_cast< TFunction* >( this->m_ActualFunction->GetPointer( ) ); + this->GetOutput( )->SetPixel( n.Vertex, f->GetUpperThreshold( ) ); - } // rof - */ - this->Superclass::_AfterLoop( ); + } // fi + return( ret ); } - #endif // __FPA__IMAGE__REGIONGROWWITHMULTIPLETHRESHOLDS__HXX__ // eof - $RCSfile$ diff --git a/lib/fpa/VTK/Image3DObserver.hxx b/lib/fpa/VTK/Image3DObserver.hxx index e79bbbe..e298622 100644 --- a/lib/fpa/VTK/Image3DObserver.hxx +++ b/lib/fpa/VTK/Image3DObserver.hxx @@ -167,7 +167,7 @@ Execute( const itk::Object* c, const itk::EventObject& e ) { vtkRenderer* ren = this->m_RenderWindow->GetRenderers( )->GetFirstRenderer( ); - ren->RemoveActor( this->m_PolyDataActor ); + // TODO: ren->RemoveActor( this->m_PolyDataActor ); this->Render( ); } // fi