X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=appli%2Fexamples%2Fexample_ImageAlgorithm_Skeletonization.cxx;h=22b85e773ec9b5ead755e23d76f51a3c8b44fe04;hb=d05a5511e69f6d333c37bf0cea5505092127fb4d;hp=7bc80a95896faac60a6972ecde2fac5f2f62b228;hpb=b63dc485b7255d1ab70ff72096beafe13a71f1be;p=FrontAlgorithms.git diff --git a/appli/examples/example_ImageAlgorithm_Skeletonization.cxx b/appli/examples/example_ImageAlgorithm_Skeletonization.cxx index 7bc80a9..22b85e7 100644 --- a/appli/examples/example_ImageAlgorithm_Skeletonization.cxx +++ b/appli/examples/example_ImageAlgorithm_Skeletonization.cxx @@ -19,7 +19,7 @@ // ------------------------------------------------------------------------- const unsigned int Dim = 3; typedef short TPixel; -typedef double TScalar; +typedef float TScalar; typedef itk::Image< TPixel, Dim > TImage; typedef itk::Image< TScalar, Dim > TDistanceMap; typedef itk::ImageToVTKImageFilter< TImage > TVTKImage; @@ -43,12 +43,12 @@ typedef fpa::VTK::Image3DObserver< TDijkstra, vtkRenderWindow > TDijkstraObs; // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { - if( argc < 7 ) + if( argc < 8 ) { std::cerr << "Usage: " << argv[ 0 ] << " input_image thr_0 thr_1 step" - << " output_segmentation output_distancemap" + << " output_segmentation output_distancemap output_dijkstra" << " visual_debug" << std::endl; return( 1 ); @@ -60,9 +60,10 @@ int main( int argc, char* argv[] ) unsigned int step = std::atoi( argv[ 4 ] ); std::string output_segmentation_fn = argv[ 5 ]; std::string output_distancemap_fn = argv[ 6 ]; + std::string output_dijkstra_fn = argv[ 7 ]; bool visual_debug = false; - if( argc > 7 ) - visual_debug = ( std::atoi( argv[ 7 ] ) == 1 ); + if( argc > 8 ) + visual_debug = ( std::atoi( argv[ 8 ] ) == 1 ); // Read image TImageReader::Pointer input_image_reader = TImageReader::New( ); @@ -133,6 +134,7 @@ int main( int argc, char* argv[] ) distanceMap->SetInput( segmentor->GetOutput( ) ); distanceMap->InputIsBinaryOn( ); distanceMap->SquaredDistanceOn( ); + distanceMap->UseImageSpacingOn( ); start = std::clock( ); distanceMap->Update( ); end = std::clock( ); @@ -155,7 +157,7 @@ int main( int argc, char* argv[] ) TDijkstra::Pointer paths = TDijkstra::New( ); paths->AddSeed( segmentor->GetSeed( 0 ), TScalar( 0 ) ); paths->SetInput( distanceMap->GetOutput( ) ); - paths->SetNeighborhoodOrder( 1 ); + paths->SetNeighborhoodOrder( 2 ); if( visual_debug ) { @@ -184,7 +186,7 @@ int main( int argc, char* argv[] ) vtkSmartPointer< vtkFloatArray >::New( ); const TDijkstra::TVertices& endpoints = paths->GetEndPoints( ); - const TDijkstra::TTree& tree = paths->GetFinalTree( ); + const TDijkstra::TTree& tree = paths->GetFullTree( ); TDijkstra::TVertices::const_iterator epIt = endpoints.begin( ); for( unsigned int epId = 0; epIt != endpoints.end( ); ++epIt, ++epId ) { @@ -205,9 +207,9 @@ int main( int argc, char* argv[] ) cells->InsertCellPoint( points->GetNumberOfPoints( ) - 1 ); } // fi - idx = tree.find( idx )->second; + idx = tree.find( idx )->second.first; - } while( idx != tree.find( idx )->second ); + } while( idx != tree.find( idx )->second.first ); } // rof @@ -221,54 +223,34 @@ int main( int argc, char* argv[] ) view.Render( ); view.Start( ); - /* TODO - TDistanceMapWriter::Pointer distancemap_writer = - TDistanceMapWriter::New( ); - distancemap_writer->SetInput( distanceMap->GetOutput( ) ); - distancemap_writer->SetFileName( output_distancemap_fn ); - distancemap_writer->Update( ); - - TImageWriter::Pointer segmentation_writer = - TImageWriter::New( ); - segmentation_writer->SetInput( segmentor->GetOutput( ) ); - segmentation_writer->SetFileName( output_segmentation_fn ); - segmentation_writer->Update( ); - */ - - // Show result - /* - TVTKImage::Pointer output_image_vtk = TVTKImage::New( ); - output_image_vtk->SetInput( segmentor->GetOutput( ) ); - output_image_vtk->Update( ); - - vtkSmartPointer< vtkImageMarchingCubes > mc = - vtkSmartPointer< vtkImageMarchingCubes >::New( ); - mc->SetInputData( output_image_vtk->GetOutput( ) ); - mc->SetValue( - 0, - double( segmentor->GetInsideValue( ) ) * double( 0.95 ) - ); - mc->Update( ); - - // Let some interaction and close program - view.AddPolyData( mc->GetOutput( ), 0.1, 0.6, 0.8, 0.5 ); - view.Start( ); + itk::ImageFileWriter< TImage >::Pointer segmentation_writer = + itk::ImageFileWriter< TImage >::New( ); + segmentation_writer->SetInput( segmentor->GetOutput( ) ); + segmentation_writer->SetFileName( output_segmentation_fn ); - // Write resulting image - TImageWriter::Pointer output_image_writer = TImageWriter::New( ); - output_image_writer->SetInput( segmentor->GetOutput( ) ); - output_image_writer->SetFileName( output_image_fn ); - try - { - output_image_writer->Update( ); - } - catch( itk::ExceptionObject& err ) - { + itk::ImageFileWriter< TDistanceMap >::Pointer dmap_writer = + itk::ImageFileWriter< TDistanceMap >::New( ); + dmap_writer->SetInput( distanceMap->GetOutput( ) ); + dmap_writer->SetFileName( output_distancemap_fn ); + + itk::ImageFileWriter< TDistanceMap >::Pointer dijk_writer = + itk::ImageFileWriter< TDistanceMap >::New( ); + dijk_writer->SetInput( paths->GetOutput( ) ); + dijk_writer->SetFileName( output_dijkstra_fn ); + + try + { + segmentation_writer->Update( ); + dmap_writer->Update( ); + dijk_writer->Update( ); + } + catch( itk::ExceptionObject& err ) + { std::cerr << "Error caught: " << err << std::endl; - return( 1 ); + return( -1 ); + + } // yrt - } // yrt - */ return( 0 ); }