]> Creatis software - FrontAlgorithms.git/blobdiff - appli/TempAirwaysAppli/TempAirwaysAppli.cxx
On my way... it does not work yet, but I think I'm on the good track.
[FrontAlgorithms.git] / appli / TempAirwaysAppli / TempAirwaysAppli.cxx
index d5cc42f602600ac9fab927a262f3d404bcea5170..1bb55735d144ab6ce9bbc7155f41c7ab3180d083 100644 (file)
@@ -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 : "<<leoTreeWeigth << " nodes "<<std::endl;
-
-  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 );
-  //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: "<<tree->GetWeight()<<". Takes "<<(end-start)<<" s." << std::endl;
   return *tree;
 }