From: Leonardo Florez-Valencia Date: Tue, 17 Mar 2015 23:59:50 +0000 (-0500) Subject: Even more tests X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=52239e1c93355a6543e6f1c9357cfc86d11b9218;p=FrontAlgorithms.git Even more tests --- diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index 2d0ebe6..93d3c1d 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -27,7 +27,11 @@ IF(BUILD_EXAMPLES) FOREACH(APP ${vtk_APPLIS}) ADD_EXECUTABLE(${APP} ${APP}.cxx) - TARGET_LINK_LIBRARIES(${APP} FrontAlgorithms) + TARGET_LINK_LIBRARIES( + ${APP} + FrontAlgorithms + ${VTK_LIBRARIES} vtkIOLegacy + ) ENDFOREACH(APP) ENDIF(USE_VTK) ENDIF(BUILD_EXAMPLES) diff --git a/appli/examples/example_ImageAlgorithmDijkstra_03.cxx b/appli/examples/example_ImageAlgorithmDijkstra_03.cxx index 0de8126..613378b 100644 --- a/appli/examples/example_ImageAlgorithmDijkstra_03.cxx +++ b/appli/examples/example_ImageAlgorithmDijkstra_03.cxx @@ -21,8 +21,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -138,19 +140,22 @@ int main( int argc, char* argv[] ) vtkSmartPointer< vtkFloatArray > scalars = vtkSmartPointer< vtkFloatArray >::New( ); + const TDijkstra::TMarkImage* marks = paths->GetOutputMarkImage( ); + TDijkstra::TMark max_mark = paths->GetNumberOfBranches( ); const TDijkstra::TVertices& endpoints = paths->GetEndPoints( ); const TDijkstra::TTree& tree = paths->GetFinalTree( ); TDijkstra::TVertices::const_iterator epIt = endpoints.begin( ); for( unsigned int epId = 0; epIt != endpoints.end( ); ++epIt, ++epId ) { - double pd = double( epId ) / double( endpoints.size( ) - 1 ); - TDijkstra::TVertex idx = *epIt; do { TImage::PointType pnt; input_image->TransformIndexToPhysicalPoint( idx, pnt ); + TDijkstra::TMark mark = marks->GetPixel( idx ); + double pd = double( mark ); + points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] ); scalars->InsertNextTuple1( pd ); if( idx != *epIt ) @@ -172,10 +177,28 @@ int main( int argc, char* argv[] ) vtk_tree->SetLines( cells ); vtk_tree->GetPointData( )->SetScalars( scalars ); - view.AddPolyData( vtk_tree ); + vtkSmartPointer lut = + vtkSmartPointer::New( ); + lut->SetNumberOfTableValues( max_mark + 1 ); + lut->SetTableRange( 0, max_mark ); + lut->Build( ); + + view.AddPolyData( vtk_tree, lut ); view.Render( ); view.Start( ); + vtkSmartPointer< vtkPolyDataWriter > writer = + vtkSmartPointer< vtkPolyDataWriter >::New( ); + writer->SetInputData( vtk_tree ); + writer->SetFileName( output_image_fn.c_str( ) ); + writer->Update( ); + + itk::ImageFileWriter< TDijkstra::TMarkImage >::Pointer marks_writer = + itk::ImageFileWriter< TDijkstra::TMarkImage >::New( ); + marks_writer->SetInput( marks ); + marks_writer->SetFileName( "marks.mhd" ); + marks_writer->Update( ); + /* TODO TImageWriter::Pointer dijkstra_writer = TImageWriter::New( ); diff --git a/lib/fpa/Image/DijkstraWithSphereBacktracking.h b/lib/fpa/Image/DijkstraWithSphereBacktracking.h index 070a01a..febfcc9 100644 --- a/lib/fpa/Image/DijkstraWithSphereBacktracking.h +++ b/lib/fpa/Image/DijkstraWithSphereBacktracking.h @@ -31,6 +31,10 @@ namespace fpa typedef typename Superclass::TTraits::TVertexCmp TVertexCmp; typedef std::map< TVertex, TVertex, TVertexCmp > TTree; + typedef unsigned short TMark; + typedef itk::Image< TMark, I::ImageDimension > TMarkImage; + + typedef typename Superclass::TEndEvent TEndEvent; typedef typename Superclass::TBacktrackingEvent TBacktrackingEvent; typedef typename Superclass::TEndBacktrackingEvent TEndBacktrackingEvent; @@ -51,6 +55,11 @@ namespace fpa itkGetConstMacro( FinalTree, TTree ); itkGetConstMacro( EndPoints, TVertices ); itkGetConstMacro( BifurcationPoints, TVertices ); + itkGetConstMacro( NumberOfBranches, TMark ); + + public: + TMarkImage* GetOutputMarkImage( ); + const TMarkImage* GetOutputMarkImage( ) const; protected: DijkstraWithSphereBacktracking( ); @@ -72,6 +81,7 @@ namespace fpa TTree m_FinalTree; TVertices m_BifurcationPoints; TVertices m_EndPoints; + TMark m_NumberOfBranches; }; } // ecapseman diff --git a/lib/fpa/Image/DijkstraWithSphereBacktracking.hxx b/lib/fpa/Image/DijkstraWithSphereBacktracking.hxx index 95f8dcb..346103b 100644 --- a/lib/fpa/Image/DijkstraWithSphereBacktracking.hxx +++ b/lib/fpa/Image/DijkstraWithSphereBacktracking.hxx @@ -5,12 +5,42 @@ #include #include +// ------------------------------------------------------------------------- +template< class I, class C > +typename fpa::Image::DijkstraWithSphereBacktracking< I, C >:: +TMarkImage* fpa::Image::DijkstraWithSphereBacktracking< I, C >:: +GetOutputMarkImage( ) +{ + return( + dynamic_cast< TMarkImage* >( + this->itk::ProcessObject::GetOutput( 1 ) + ) + ); +} + +// ------------------------------------------------------------------------- +template< class I, class C > +const typename fpa::Image::DijkstraWithSphereBacktracking< I, C >:: +TMarkImage* fpa::Image::DijkstraWithSphereBacktracking< I, C >:: +GetOutputMarkImage( ) const +{ + return( + dynamic_cast< const TMarkImage* >( + this->itk::ProcessObject::GetOutput( 1 ) + ) + ); +} + // ------------------------------------------------------------------------- template< class I, class C > fpa::Image::DijkstraWithSphereBacktracking< I, C >:: DijkstraWithSphereBacktracking( ) - : Superclass( ) + : Superclass( ), + m_NumberOfBranches( 0 ) { + this->SetNumberOfRequiredOutputs( 2 ); + this->SetNthOutput( 0, I::New( ) ); + this->SetNthOutput( 1, TMarkImage::New( ) ); } // ------------------------------------------------------------------------- @@ -67,8 +97,6 @@ template< class I, class C > void fpa::Image::DijkstraWithSphereBacktracking< I, C >:: _AfterMainLoop( ) { - typedef itk::Image< bool, I::ImageDimension > _TMarkImage; - // Finish base algorithm this->Superclass::_AfterMainLoop( ); this->m_FinalTree.clear( ); @@ -88,25 +116,19 @@ _AfterMainLoop( ) max_spac *= double( 3 ); // Prepare an object to hold marks - typename _TMarkImage::Pointer marks = _TMarkImage::New( ); - marks->SetLargestPossibleRegion( input->GetLargestPossibleRegion( ) ); - marks->SetRequestedRegion( input->GetRequestedRegion( ) ); - marks->SetBufferedRegion( input->GetBufferedRegion( ) ); - marks->SetOrigin( input->GetOrigin( ) ); - marks->SetSpacing( input->GetSpacing( ) ); - marks->SetDirection( input->GetDirection( ) ); - marks->Allocate( ); - marks->FillBuffer( false ); + typename TMarkImage::Pointer marks = this->GetOutputMarkImage( ); + marks->FillBuffer( 0 ); // Iterate over the candidates, starting from the candidates that // are near thin branches typename _TCandidates::const_reverse_iterator cIt = this->m_Candidates.rbegin( ); - for( int backId = 0; cIt != this->m_Candidates.rend( ); ++cIt ) + this->m_NumberOfBranches = 0; + for( ; cIt != this->m_Candidates.rend( ); ++cIt ) { // If pixel hasn't been visited, continue TVertex v = cIt->second; - if( marks->GetPixel( v ) ) + if( marks->GetPixel( v ) != 0 ) continue; // Compute nearest start candidate @@ -128,46 +150,81 @@ _AfterMainLoop( ) } // rof // Keep endpoint - if( marks->GetPixel( max_vertex ) ) + if( marks->GetPixel( max_vertex ) != 0 ) continue; - backId++; + this->m_NumberOfBranches++; this->m_EndPoints.push_back( max_vertex ); // Construct path (at least the part that hasn't been iterated) - bool terminate = false; do { - if( this->m_FinalTree.find( max_vertex ) == this->m_FinalTree.end( ) ) + if( + std::find( + this->m_BifurcationPoints.begin( ), + this->m_BifurcationPoints.end( ), + max_vertex + ) == this->m_BifurcationPoints.end( ) + ) { // 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.25 ) ); - itk::ImageRegionIteratorWithIndex< _TMarkImage > + region = this->_Region( max_vertex, dist * double( 1.1 ) ); + itk::ImageRegionIteratorWithIndex< TMarkImage > mIt( marks, region ); for( mIt.GoToBegin( ); !mIt.IsAtEnd( ); ++mIt ) - mIt.Set( true ); + mIt.Set( this->m_NumberOfBranches ); // Next vertex in current path - this->InvokeEvent( TBacktrackingEvent( max_vertex, backId ) ); + this->InvokeEvent( TBacktrackingEvent( max_vertex, this->m_NumberOfBranches ) ); this->m_FinalTree[ max_vertex ] = this->_Parent( max_vertex ); } else { // A bifurcation point has been reached! this->m_BifurcationPoints.push_back( max_vertex ); - terminate = true; + this->m_NumberOfBranches++; } // fi max_vertex = this->_Parent( max_vertex ); - } while( max_vertex != this->_Parent( max_vertex ) && !terminate ); - - if( !terminate ) - { - this->m_FinalTree[ max_vertex ] = max_vertex; - this->InvokeEvent( TEndBacktrackingEvent( backId ) ); - - } // fi + } while( max_vertex != this->_Parent( max_vertex ) ); + + /* TODO + bool terminate = false; + do + { + if( this->m_FinalTree.find( max_vertex ) == this->m_FinalTree.end( ) ) + { + // 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.25 ) ); + itk::ImageRegionIteratorWithIndex< TMarkImage > + mIt( marks, region ); + for( mIt.GoToBegin( ); !mIt.IsAtEnd( ); ++mIt ) + mIt.Set( true ); + + // Next vertex in current path + this->InvokeEvent( TBacktrackingEvent( max_vertex, this->m_NumberOfBranches ) ); + this->m_FinalTree[ max_vertex ] = this->_Parent( max_vertex ); + } + else + { + // A bifurcation point has been reached! + this->m_BifurcationPoints.push_back( max_vertex ); + terminate = true; + + } // fi + max_vertex = this->_Parent( max_vertex ); + + } while( max_vertex != this->_Parent( max_vertex ) && !terminate ); + + if( !terminate ) + { + this->m_FinalTree[ max_vertex ] = max_vertex; + this->InvokeEvent( TEndBacktrackingEvent( this->m_NumberOfBranches ) ); + + } // fi + */ } // rof } diff --git a/lib/fpa/VTK/ImageMPR.cxx b/lib/fpa/VTK/ImageMPR.cxx index 8484a03..9acfa12 100644 --- a/lib/fpa/VTK/ImageMPR.cxx +++ b/lib/fpa/VTK/ImageMPR.cxx @@ -255,6 +255,24 @@ AddPolyData( vtkPolyData* pd, double r, double g, double b, double opacity ) this->m_Renderer->AddActor( this->m_Actors[ i ] ); } +// ------------------------------------------------------------------------- +void fpa::VTK::ImageMPR:: +AddPolyData( vtkPolyData* pd, vtkLookupTable* lut, double opacity ) +{ + unsigned int i = this->m_PolyDatas.size( ); + + this->m_PolyDatas.push_back( pd ); + this->m_Mappers.push_back( vtkSmartPointer< vtkPolyDataMapper >::New( ) ); + this->m_Actors.push_back( vtkSmartPointer< vtkActor >::New( ) ); + + this->m_Mappers[ i ]->SetInputData( pd ); + this->m_Mappers[ i ]->SetLookupTable( lut ); + this->m_Actors[ i ]->SetMapper( this->m_Mappers[ i ] ); + this->m_Actors[ i ]->GetProperty( )->SetOpacity( opacity ); + this->m_Renderer->AddActor( this->m_Actors[ i ] ); +} + + // ------------------------------------------------------------------------- unsigned int fpa::VTK::ImageMPR:: GetNumberOfSeeds( ) const diff --git a/lib/fpa/VTK/ImageMPR.h b/lib/fpa/VTK/ImageMPR.h index 21a1c5c..e64ff8a 100644 --- a/lib/fpa/VTK/ImageMPR.h +++ b/lib/fpa/VTK/ImageMPR.h @@ -20,6 +20,7 @@ #include #include #include +#include namespace fpa { @@ -42,6 +43,11 @@ namespace fpa vtkPolyData* pd, double r, double g, double b, double opacity = double( 1 ) ); + void AddPolyData( + vtkPolyData* pd, + vtkLookupTable* lut, + double opacity = double( 1 ) + ); unsigned int GetNumberOfSeeds( ) const; void GetSeed( int n, double* s ) const;