From 8480ad8f9b3e3b556aa8f3f25ff07daf1db6dc78 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Tue, 7 Apr 2015 22:24:50 -0500 Subject: [PATCH] Almost... --- ...ample_Image_Dijkstra_EndPointDetection.cxx | 14 +++--- lib/fpa/Image/DijkstraWithEndPointDetection.h | 1 + .../Image/DijkstraWithEndPointDetection.hxx | 45 +++++++++---------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/appli/examples/example_Image_Dijkstra_EndPointDetection.cxx b/appli/examples/example_Image_Dijkstra_EndPointDetection.cxx index 070a3e8..47585ad 100644 --- a/appli/examples/example_Image_Dijkstra_EndPointDetection.cxx +++ b/appli/examples/example_Image_Dijkstra_EndPointDetection.cxx @@ -139,12 +139,13 @@ int main( int argc, char* argv[] ) filter->ThrowEventsOn( ); // Go! - std::clock_t start = std::clock( ); + std::time_t start, end; + std::time( &start ); filter->Update( ); - std::clock_t end = std::clock( ); + std::time( &end ); std::cout << "Extraction time = " - << ( double( end - start ) / double( CLOCKS_PER_SEC ) ) + << std::difftime( end, start ) << " s." << std::endl; /* TODO @@ -210,12 +211,13 @@ void DistanceMap( dmap->SquaredDistanceOn( ); dmap->UseImageSpacingOn( ); - std::clock_t start = std::clock( ); + std::time_t start, end; + std::time( &start ); dmap->Update( ); - std::clock_t end = std::clock( ); + std::time( &end ); std::cout << "Distance map time = " - << ( double( end - start ) / double( CLOCKS_PER_SEC ) ) + << std::difftime( end, start ) << " s." << std::endl; output = dmap->GetOutput( ); diff --git a/lib/fpa/Image/DijkstraWithEndPointDetection.h b/lib/fpa/Image/DijkstraWithEndPointDetection.h index ecf197d..881b8f8 100644 --- a/lib/fpa/Image/DijkstraWithEndPointDetection.h +++ b/lib/fpa/Image/DijkstraWithEndPointDetection.h @@ -25,6 +25,7 @@ namespace fpa typedef typename Superclass::TInputImage TInputImage; typedef typename Superclass::TOutputImage TOutputImage; typedef typename Superclass::TVertex TVertex; + typedef typename Superclass::TVertexCompare TVertexCompare; typedef typename Superclass::TValue TValue; typedef typename Superclass::TResult TResult; typedef typename Superclass::TCostFunction TCostFunction; diff --git a/lib/fpa/Image/DijkstraWithEndPointDetection.hxx b/lib/fpa/Image/DijkstraWithEndPointDetection.hxx index 2055cc4..d8e344a 100644 --- a/lib/fpa/Image/DijkstraWithEndPointDetection.hxx +++ b/lib/fpa/Image/DijkstraWithEndPointDetection.hxx @@ -2,6 +2,7 @@ #define __FPA__IMAGE__DIJKSTRAWITHENDPOINTDETECTION__HXX__ #include +#include #include // ------------------------------------------------------------------------- @@ -130,6 +131,7 @@ _AfterGenerateData( ) label->FillBuffer( 0 ); // Prepare an object to hold marks + std::set< TVertex, TVertexCompare > tree_marks; /* TODO typename TMarkImage::Pointer marks = this->GetOutputMarkImage( ); marks->FillBuffer( 0 ); @@ -143,7 +145,7 @@ _AfterGenerateData( ) std::map< TLabel, std::pair< TVertex, TVertex > > branches; for( ; cIt != this->m_Candidates.rend( ); ++cIt ) { - // If pixel hasn't been visited, continue + // If pixel has been already labelled, pass TVertex v = cIt->second; if( label->GetPixel( v ) != 0 ) continue; @@ -166,7 +168,7 @@ _AfterGenerateData( ) } // rof - // Keep endpoint + // Re-check labelling if( label->GetPixel( max_vertex ) != 0 ) continue; this->m_EndPoints.push_back( max_vertex ); @@ -188,34 +190,29 @@ _AfterGenerateData( ) ); if( start ) { - TLabel lbl = label->GetPixel( *pIt ); - if( lbl == 0 || lbl == this->m_NumberOfBranches ) + if( tree_marks.find( *pIt ) == tree_marks.end( ) ) { + tree_marks.insert( *pIt ); + // Mark a sphere around current point as visited double dist = std::sqrt( double( input->GetPixel( *pIt ) ) ); - region = this->_Region( max_vertex, dist * double( 1.1 ) ); + region = this->_Region( max_vertex, dist * double( 1.5 ) ); itk::ImageRegionIteratorWithIndex< TLabelImage > lIt( label, region ); for( lIt.GoToBegin( ); !lIt.IsAtEnd( ); ++lIt ) - { - if( lIt.Get( ) == 0 ) - lIt.Set( this->m_NumberOfBranches ); - - } // rof + lIt.Set( this->m_NumberOfBranches ); // Next vertex in current path // TODO: this->InvokeEvent( TBacktrackingEvent( max_vertex, this->m_NumberOfBranches ) ); /* this->m_FullTree[ max_vertex ] = TTreeNode( this->_Parent( max_vertex ), this->m_NumberOfBranches ); - std::cout << "New: " << this->m_NumberOfBranches << std::endl; */ } else { // A bifurcation point has been reached! branches[ this->m_NumberOfBranches ] = std::pair< TVertex, TVertex >( last_start, *pIt ); - std::cout << "bif " << this->m_NumberOfBranches << std::endl; last_start = *pIt; this->m_BifurcationPoints.push_back( *pIt ); this->m_NumberOfBranches++; @@ -235,7 +232,7 @@ _AfterGenerateData( ) { // Mark a sphere around current point as visited double dist = std::sqrt( double( input->GetPixel( max_vertex ) ) ); - region = this->_Region( max_vertex, dist * double( 1.1 ) ); + region = this->_Region( max_vertex, dist * double( 1.5 ) ); itk::ImageRegionIteratorWithIndex< TLabelImage > lIt( label, region ); for( lIt.GoToBegin( ); !lIt.IsAtEnd( ); ++lIt ) @@ -248,14 +245,12 @@ _AfterGenerateData( ) TTreeNode( this->_Parent( max_vertex ), this->m_NumberOfBranches ); */ change = true; - // std::cout << "Change: " << this->m_NumberOfBranches << std::endl; } else { // A bifurcation point has been reached! // TODO: this->m_BifurcationPoints.push_back( max_vertex ); branches[ this->m_NumberOfBranches ] = std::pair< TVertex, TVertex >( last_start, *pIt ); - std::cout << "change " << this->m_NumberOfBranches << std::endl; last_start = *pIt; this->m_NumberOfBranches++; @@ -263,7 +258,6 @@ _AfterGenerateData( ) this->m_FullTree[ max_vertex ] = TTreeNode( this->_Parent( max_vertex ), this->m_NumberOfBranches ); */ - // std::cout << "Change bifurcation: " << this->m_NumberOfBranches << std::endl; } // fi @@ -282,20 +276,23 @@ _AfterGenerateData( ) } // rof - std::cout << this->m_NumberOfBranches << " " << branches.size( ) << std::endl; - std::cout << this->m_EndPoints.size( ) << " " << this->m_BifurcationPoints.size( ) << std::endl; - - // Re-enumerate labels - /* std::map< TLabel, unsigned long > histo; for( - typename TTree::iterator treeIt = this->m_FullTree.begin( ); - treeIt != this->m_FullTree.end( ); + typename std::set< TVertex, TVertexCompare >::iterator treeIt = tree_marks.begin( ); + treeIt != tree_marks.end( ); ++treeIt ) - histo[ treeIt->second.second ]++; + histo[ label->GetPixel( *treeIt ) ]++; + + for( + typename std::map< TLabel, unsigned long >::iterator hIt = histo.begin( ); + hIt != histo.end( ); + ++hIt + ) + std::cout << hIt->first << " " << hIt->second << std::endl; + /* std::map< TMark, TMark > changes; TMark last_change = 1; for( TMark i = 1; i <= this->m_NumberOfBranches; ++i ) -- 2.47.1