From ea925d9989804add2613413ae8cdf002f2afbcab Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Thu, 14 Apr 2016 14:46:22 -0500 Subject: [PATCH] On my way... it does not work yet, but I think I'm on the good track. --- appli/TempAirwaysAppli/TempAirwaysAppli.cxx | 123 +++++++----------- lib/fpa/Base/ImageSkeleton.hxx | 9 +- ...AndBifurcationsFromMinimumSpanningTree.hxx | 2 +- 3 files changed, 50 insertions(+), 84 deletions(-) diff --git a/appli/TempAirwaysAppli/TempAirwaysAppli.cxx b/appli/TempAirwaysAppli/TempAirwaysAppli.cxx index d5cc42f..1bb5573 100644 --- a/appli/TempAirwaysAppli/TempAirwaysAppli.cxx +++ b/appli/TempAirwaysAppli/TempAirwaysAppli.cxx @@ -477,15 +477,6 @@ Node* FAVertexToNode( TVertex vertex, TImage* image ) AirwaysTree& ConvertFilterToAirwaysTree( TInputImage* input_image, cpPlugins::Workspace& ws ) { - /* - typedef FilterType TFilter; - typedef typename TFilter::TVertex TVertexFA; - typedef typename TFilter::TVertices TVerticesFA; - typedef typename TFilter::TUniqueVertices TUniqueVerticesFA; - typedef typename TFilter::TVertexCompare TVertexCompareFA; - typedef typename TFilter::TBranches TBranchesFA; - typedef typename TFilter::TMinimumSpanningTree TMst; - */ typedef fpa::Base::ImageSkeleton< fpa::Image::MinimumSpanningTree< 3 > > TFASkeleton; @@ -504,79 +495,59 @@ AirwaysTree& ConvertFilterToAirwaysTree( TInputImage* input_image, cpPlugins::Wo std::cout << "Starting conversion " << std::endl; 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 = 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( ); - TMst* mst = filter->GetMinimumSpanningTree(); - */ - int leoTreeWeigth = endpoints.size()+bifurcations.size()+1; - std::cout<< "Creates FA Tree with : "<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 ); - //Do Endpoints - auto eIt = endpoints.begin(); - for( ; eIt != endpoints.end(); ++eIt ) + auto distance_map = + ws.GetFilter( "dmap" )->GetOutputData( "Output" )-> + GetITK< itk::Image< float, 3 > >( ); + auto branches = + w_filter->GetOutputData( "Skeleton" )->GetITK< TFASkeleton >( ); + auto sIt = branches->Get( ).begin( ); + for( ; sIt!=branches->Get( ).end( ); ++sIt ) { - vertexMap[*eIt]=FAVertexToNode( *eIt, image ); - } - - auto biIt = bifurcations.begin(); - for(; biIt != bifurcations.end(); ++biIt) - { - vertexMap[*biIt]=FAVertexToNode(*biIt,image); - } - - //Now navigate branches to make the edges of the tree. - auto bIt = branches->Get( ).begin(); - for(; bIt!=branches->Get( ).end(); ++bIt) - { - auto dVertex = bIt->first; - TVertexAirways* destination = vertexMap[dVertex]; - if( destination == NULL ) - { - vertexMap[dVertex]=FAVertexToNode(dVertex,image); - destination = vertexMap[dVertex]; - } - auto brIt = bIt->second.begin( ); - for( ; brIt != bIt->second.end( ); ++brIt ) + auto srcIt = vertexMap.find( sIt->first ); + if( srcIt == vertexMap.end( ) ) + srcIt = vertexMap.insert( + VertexMap::value_type( + sIt->first, FAVertexToNode( sIt->first, input_image ) + ) + ).first; + auto eIt = sIt->second.begin( ); + for( ; eIt != sIt->second.end( ); ++eIt ) { - auto sVertex = brIt->first; - TVertexAirways* source = vertexMap[sVertex]; - if( source == NULL ) - { - vertexMap[sVertex]=FAVertexToNode(sVertex,image); - source = vertexMap[sVertex]; - } - destination->SetFather(source); - source->AddChild(destination); - TEdgeAirways* edge = new Edge(); - //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 dstIt = vertexMap.find( eIt->first ); + if( dstIt != vertexMap.end( ) ) + continue; + dstIt = vertexMap.insert( + VertexMap::value_type( + eIt->first, FAVertexToNode( eIt->first, input_image ) + ) + ).first; + + dstIt->second->SetFather( srcIt->second ); + srcIt->second->AddChild( dstIt->second ); + TEdgeAirways* edge = new Edge( ); + auto path = eIt->second->GetVertexList( ); + for( unsigned int pIt = 0; pIt < path->Size( ); ++pIt ) { itk::ImageBase< 3 >::PointType pnt; - auto cidx = edgePath->GetElement( pIt ); - image->TransformContinuousIndexToPhysicalPoint(cidx,pnt); + auto cidx = path->GetElement( pIt ); + input_image->TransformContinuousIndexToPhysicalPoint( cidx, pnt ); TVertexFA idx; - image->TransformPhysicalPointToIndex(pnt,idx); - Vec3 coords = FAVertexToNode(idx,image)->GetCoords(); - pair_posVox_rad skPair(coords,distance_map->GetPixel(idx)); - edge->AddSkeletonPairInfo(skPair); - } - } - } - AirwaysTree* tree = new AirwaysTree( input_image, NULL, vertexMap[seed0], false); + input_image->TransformPhysicalPointToIndex( pnt, idx ); + Vec3 coords = FAVertexToNode( idx, input_image )->GetCoords( ); + pair_posVox_rad skPair( coords, distance_map->GetPixel( idx ) ); + edge->AddSkeletonPairInfo( skPair ); + + } // rof + + } // rof + + } // rof + auto seed0 = + ws.GetFilter( "seed" )->GetOutputData( "Output" )-> + GetITK< TVerticesFA >( )->Get( )[ 0 ]; + 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; } diff --git a/lib/fpa/Base/ImageSkeleton.hxx b/lib/fpa/Base/ImageSkeleton.hxx index cd2daec..9625795 100644 --- a/lib/fpa/Base/ImageSkeleton.hxx +++ b/lib/fpa/Base/ImageSkeleton.hxx @@ -22,13 +22,11 @@ AddBranch( const TVertex& a, const TVertex& b ) typename TPath::Pointer path = TPath::New( ); for( auto vIt = vertices.begin( ); vIt != vertices.end( ); ++vIt ) path->AddVertex( *vIt ); - + // Assign path vertices path->SetReferenceImage( this->m_MinimumSpanningTree ); this->Get( )[ a ][ b ] = path; - - // Create symmetric path - this->AddBranch( b, a ); + this->Modified( ); } // ------------------------------------------------------------------------- @@ -37,9 +35,6 @@ const typename fpa::Base::ImageSkeleton< _TMST >:: TPath* fpa::Base::ImageSkeleton< _TMST >:: GetBranch( const TVertex& a, const TVertex& b ) const { - if( this->m_MinimumSpanningTree.IsNull( ) ) - return( NULL ); - auto aIt = this->Get( ).find( a ); if( aIt != this->Get( ).end( ) ) { diff --git a/lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx b/lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx index 3e7a32b..a089fed 100644 --- a/lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx +++ b/lib/fpa/Image/ExtractEndPointsAndBifurcationsFromMinimumSpanningTree.hxx @@ -121,7 +121,7 @@ GenerateData( ) sk->SetMinimumSpanningTree( this->GetMinimumSpanningTree( ) ); auto bIt = this->m_Branches.begin( ); for( ; bIt != this->m_Branches.end( ); ++bIt ) - sk->AddBranch( bIt->first, bIt->second ); + sk->AddBranch( bIt->second, bIt->first ); } // ------------------------------------------------------------------------- -- 2.45.1