From 90aa3b63151713043911a94a408bca1ebb97e3bd Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Thu, 14 Apr 2016 09:49:02 -0500 Subject: [PATCH] ... --- appli/TempAirwaysAppli/TempAirwaysAppli.cxx | 103 ++++++++++++-------- lib/fpa/Image/MinimumSpanningTree.hxx | 1 + 2 files changed, 66 insertions(+), 38 deletions(-) diff --git a/appli/TempAirwaysAppli/TempAirwaysAppli.cxx b/appli/TempAirwaysAppli/TempAirwaysAppli.cxx index 3dfbcc3..d5cc42f 100644 --- a/appli/TempAirwaysAppli/TempAirwaysAppli.cxx +++ b/appli/TempAirwaysAppli/TempAirwaysAppli.cxx @@ -23,10 +23,38 @@ namespace typedef std::vector< AirwaysTree > AirwaysVector; +#include + // Auxiliar struct to save info for execution. typedef void* TImagePointer; struct TreeInfo{ - TImagePointer image; + + TreeInfo( ) + { + this->myWorkspace = new cpPlugins::Workspace( ); + } + ~TreeInfo( ) + { + /* + if( this->IsMyWorkspace ) + delete this->myWorkspace; + */ + } + + void CastImage( ) + { + auto image = this->myWorkspace->GetFilter( "reader" )->GetOutputData( "Output" )->GetITK< itk::Image< unsigned char, 3 > >( ); + typedef itk::CastImageFilter< itk::Image< unsigned char, 3 >, TInputImage > _TCast; + _TCast::Pointer cast = _TCast::New( ); + cast->SetInput( image ); + cast->Update( ); + this->Image = cast->GetOutput( ); + this->Image->DisconnectPipeline( ); + } + + TInputImage::Pointer Image; + cpPlugins::Workspace* myWorkspace; + bool IsMyWorkspace; Vec3 seed; std::string folderpath_pigResults; std::string pig_name; @@ -42,13 +70,12 @@ unsigned char purple[3]= { 255, 0, 255 }; unsigned char cyan[3]= { 0, 255, 255 }; cpPlugins::Interface myPlugins; -cpPlugins::Workspace myWorkspace; // ------------------------------------------------------------------------- -void Load_cpPlugins( const std::string& plugins, const std::string& ws ); +void Load_cpPlugins( const std::string& plugins ); void CreateResultDirectory(AirwaysTree tree); void DrawVTKLinesFromTree(AirwaysTree& tree, const std::string filename, bool common); -AirwaysTree& CreateAirwaysTreeFromSegmentation(Vec3 seed, TImagePointer input_image); +AirwaysTree& CreateAirwaysTreeFromSegmentation(Vec3 seed, TInputImage* input_image, cpPlugins::Workspace& ws ); vector ReadInputFile(const char* filename); void printCommonTreeBetweenTwoTrees(AirwaysTree tree_A, AirwaysTree tree_B, std::vector< std::pair< std::pair, std::pair > > vector_pair_edges_A_to_B, unsigned int Q, unsigned int F); void printMatchingResultToFile(AirwaysTree tree_A, AirwaysTree tree_B, std::map< unsigned int, std::vector > map_A_to_B, std::map< unsigned int, std::vector > map_B_to_A, unsigned int Q, unsigned int F); @@ -57,6 +84,8 @@ void createLinesAndPointsForVTK(const Node* node, vtkSmartPointer& pt // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { + Load_cpPlugins( "./plugins.cfg" ); + try { // Define and parse the program options @@ -92,7 +121,15 @@ int main( int argc, char* argv[] ) { for(unsigned int i = 0; i < treeInfoVector.size(); ++ i){ TreeInfo info = treeInfoVector[i]; - AirwaysTree tree = CreateAirwaysTreeFromSegmentation(info.seed, info.image); + std::string err = info.myWorkspace->Execute( "eb" ); + if( err != "" ) + { + std::cerr << "Error: " << err << std::endl; + std::exit( 1 ); + + } // fi + info.CastImage( ); + AirwaysTree tree = CreateAirwaysTreeFromSegmentation( info.seed, info.Image, *(info.myWorkspace )); tree.SetResultPath(info.folderpath_pigResults); tree.SetImageName(info.image_name); aVector.push_back(tree); @@ -326,17 +363,9 @@ int main( int argc, char* argv[] ) } // ------------------------------------------------------------------------- -void Load_cpPlugins( const std::string& plugins, const std::string& ws ) +void Load_cpPlugins( const std::string& plugins ) { myPlugins.LoadConfiguration( plugins ); - myWorkspace.SetInterface( &myPlugins ); - std::string err = myWorkspace.LoadWorkspace( ws ); - if( err != "" ) - { - std::cerr << "Error: " << err << std::endl; - std::exit( 1 ); - - } // fi } // ------------------------------------------------------------------------- @@ -446,7 +475,7 @@ Node* FAVertexToNode( TVertex vertex, TImage* image ) return new Node(alfPoint); } -AirwaysTree& ConvertFilterToAirwaysTree( ) +AirwaysTree& ConvertFilterToAirwaysTree( TInputImage* input_image, cpPlugins::Workspace& ws ) { /* typedef FilterType TFilter; @@ -474,12 +503,12 @@ AirwaysTree& ConvertFilterToAirwaysTree( ) std::time(&start); std::cout << "Starting conversion " << std::endl; - auto w_filter = myWorkspace.GetFilter( "eb" ); + auto w_filter = ws.GetFilter( "eb" ); auto branches = w_filter->GetOutputData( "Skeleton" )->GetITK< TFASkeleton >( ); auto& endpoints = w_filter->GetOutputData( "EndPoints" )->GetITK< TVerticesFA >( )->Get( ); auto& bifurcations = w_filter->GetOutputData( "Bifurcations" )->GetITK< TVerticesFA >( )->Get( ); - auto image = myWorkspace.GetFilter( "reader" )->GetOutputData( "Output" )->GetITK< itk::ImageBase< 3 > >( ); - auto distance_map = myWorkspace.GetFilter( "dmap" )->GetOutputData( "Output" )->GetITK< itk::Image< float, 3 > >( ); + auto image = ws.GetFilter( "reader" )->GetOutputData( "Output" )->GetITK< itk::ImageBase< 3 > >( ); + auto distance_map = ws.GetFilter( "dmap" )->GetOutputData( "Output" )->GetITK< itk::Image< float, 3 > >( ); /* TBranchesFA* branches = filter->GetBranches( ); @@ -488,7 +517,7 @@ AirwaysTree& ConvertFilterToAirwaysTree( ) int leoTreeWeigth = endpoints.size()+bifurcations.size()+1; std::cout<< "Creates FA Tree with : "<GetOutputData( "Output" )->GetITK< TVerticesFA >( )->Get( )[ 0 ]; + auto seed0 = ws.GetFilter( "seed" )->GetOutputData( "Output" )->GetITK< TVerticesFA >( )->Get( )[ 0 ]; //Fill vertex map. Gotta do it with bifurcations, endpoints and the root. //Do the root vertexMap[ seed0 ] = FAVertexToNode( seed0, image ); @@ -496,7 +525,7 @@ AirwaysTree& ConvertFilterToAirwaysTree( ) auto eIt = endpoints.begin(); for( ; eIt != endpoints.end(); ++eIt ) { - vertexMap[*eIt]=FAVertexToNode( *eIt,image ); + vertexMap[*eIt]=FAVertexToNode( *eIt, image ); } auto biIt = bifurcations.begin(); @@ -529,15 +558,13 @@ AirwaysTree& ConvertFilterToAirwaysTree( ) destination->SetFather(source); source->AddChild(destination); TEdgeAirways* edge = new Edge(); - edge->SetSource(source); - edge->SetTarget(destination); //Update path info for the edge. This is why we don't need to call UpdateEdges on the constructor of the tree. auto edgePath = brIt->second->GetVertexList( ); for( unsigned int pIt = 0; pIt < edgePath->Size( ); ++pIt ) { - auto cidx = edgePath->GetElement(pIt); itk::ImageBase< 3 >::PointType pnt; + auto cidx = edgePath->GetElement( pIt ); image->TransformContinuousIndexToPhysicalPoint(cidx,pnt); TVertexFA idx; image->TransformPhysicalPointToIndex(pnt,idx); @@ -545,26 +572,19 @@ AirwaysTree& ConvertFilterToAirwaysTree( ) pair_posVox_rad skPair(coords,distance_map->GetPixel(idx)); edge->AddSkeletonPairInfo(skPair); } - destination->SetEdge(edge); } } - AirwaysTree* tree = new AirwaysTree(dynamic_cast< TInputImage* >( image ), NULL, vertexMap[seed0], false); + AirwaysTree* tree = new AirwaysTree( input_image, NULL, vertexMap[seed0], false); std::time(&end); + std::cout << input_image << std::endl; std::cout << "Finished conversion. New AlfTree has weight: "<GetWeight()<<". Takes "<<(end-start)<<" s." << std::endl; return *tree; } // ------------------------------------------------------------------------- -AirwaysTree& CreateAirwaysTreeFromSegmentation(Vec3 seed, TImagePointer input_image) +AirwaysTree& CreateAirwaysTreeFromSegmentation(Vec3 seed, TInputImage* input_image, cpPlugins::Workspace& ws ) { - std::string err = myWorkspace.Execute( "eb" ); - if( err != "" ) - { - std::cerr << "Error: " << err << std::endl; - std::exit( 1 ); - - } // fi - return( ConvertFilterToAirwaysTree( ) ); + return( ConvertFilterToAirwaysTree( input_image, ws ) ); } // ------------------------------------------------------------------------- @@ -621,16 +641,23 @@ vector ReadInputFile(const char* filename) /* treeInfo.image = ReadImage(filepath_airwayImage); */ - Load_cpPlugins( "./plugins.cfg", "./workspace_airwaysappli.wxml" ); - // Execute first pipeline's part std::stringstream seed_stream; seed_stream << point_trachea[0] << " " << point_trachea[1] << " " << point_trachea[2]; - myWorkspace.SetParameter( "FileNames@reader", filepath_airwayImage ); - myWorkspace.SetParameter( "Text@seed", seed_stream.str( ) ); + + treeInfo.myWorkspace->SetInterface( &myPlugins ); + std::string err = treeInfo.myWorkspace->LoadWorkspace( "./workspace_airwaysappli.wxml" ); + if( err != "" ) + { + std::cerr << "Error: " << err << std::endl; + std::exit( 1 ); + + } // fi + treeInfo.myWorkspace->SetParameter( "FileNames@reader", filepath_airwayImage ); + treeInfo.myWorkspace->SetParameter( "Text@seed", seed_stream.str( ) ); vectorInfo.push_back(treeInfo); } //else diff --git a/lib/fpa/Image/MinimumSpanningTree.hxx b/lib/fpa/Image/MinimumSpanningTree.hxx index a4dc47e..616365e 100644 --- a/lib/fpa/Image/MinimumSpanningTree.hxx +++ b/lib/fpa/Image/MinimumSpanningTree.hxx @@ -142,6 +142,7 @@ _Path( TVertices& path, const TVertex& a ) const it += this->GetPixel( it ).Parent; } while( this->GetPixel( it ).Parent != zero ); + path.push_back( it ); } // fi } -- 2.47.1