]> Creatis software - FrontAlgorithms.git/blobdiff - appli/TempAirwaysAppli/TempAirwaysAppli.cxx
...
[FrontAlgorithms.git] / appli / TempAirwaysAppli / TempAirwaysAppli.cxx
index 1bb55735d144ab6ce9bbc7155f41c7ab3180d083..9e3692d23b6d5548a0c48983ca68555725f29074 100644 (file)
@@ -464,6 +464,7 @@ void DrawVTKLinesFromTree(AirwaysTree& tree, const std::string filepath, bool co
 #include <fpa/Image/MinimumSpanningTree.h>
 #include <cpExtensions/DataStructures/ImageIndexesContainer.h>
 #include <itkImage.h>
+#include <queue>
 
 template< class TImage, class TVertex >
 Node* FAVertexToNode( TVertex vertex, TImage* image )
@@ -498,33 +499,62 @@ AirwaysTree& ConvertFilterToAirwaysTree( TInputImage* input_image, cpPlugins::Wo
   auto distance_map =
     ws.GetFilter( "dmap" )->GetOutputData( "Output" )->
     GetITK< itk::Image< float, 3 > >( );
-  auto branches =
+  auto sk =
     w_filter->GetOutputData( "Skeleton" )->GetITK< TFASkeleton >( );
-  auto sIt = branches->Get( ).begin( );
-  for( ; sIt!=branches->Get( ).end( ); ++sIt )
+  const auto& branches = sk->Get( );
+  auto seed0 =
+    ws.GetFilter( "seed" )->GetOutputData( "Output" )->
+    GetITK< TVerticesFA >( )->Get( )[ 0 ];
+
+  std::queue< TVertexFA > q;
+  // TODO: std::set< TVertexFA, TVertexCompareFA > marks;
+  q.push( seed0 );
+  while( !q.empty( ) )
   {
-    auto srcIt = vertexMap.find( sIt->first );
+    auto sVertex = q.front( );
+    q.pop( );
+    auto sIt = branches.find( sVertex );
+    /* TODO
+       if( marks.find( sVertex ) != marks.end( ) )
+       {
+       std::cout << "MARK!!!!! : " << sVertex << std::endl;
+       }
+       marks.insert( sVertex );
+    */
+
+    // End node... do nothing
+    if( sIt == branches.end( ) )
+      continue;
+
+    // Create source node
+    auto srcIt = vertexMap.find( sVertex );
     if( srcIt == vertexMap.end( ) )
       srcIt = vertexMap.insert(
         VertexMap::value_type(
-          sIt->first, FAVertexToNode( sIt->first, input_image )
+          sVertex, FAVertexToNode( sVertex, input_image )
           )
         ).first;
-    auto eIt = sIt->second.begin( );
-    for( ; eIt != sIt->second.end( ); ++eIt )
+
+    // TODO: std::cout << sVertex << " " << " " << sLevel << " " << seed0 << std::endl;
+    // Create destination nodes
+    for( auto eIt = sIt->second.begin( ); eIt != sIt->second.end( ); ++eIt )
     {
       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;
-
+      if( dstIt == vertexMap.end( ) )
+        dstIt = vertexMap.insert(
+          VertexMap::value_type(
+            eIt->first, FAVertexToNode( eIt->first, input_image )
+            )
+          ).first;
+
+      // Connect in the acyclic graph
       dstIt->second->SetFather( srcIt->second );
       srcIt->second->AddChild( dstIt->second );
+
+      // Create detailed edge
       TEdgeAirways* edge = new Edge( );
+      edge->SetSource( srcIt->second );
+      edge->SetTarget( dstIt->second );
       auto path = eIt->second->GetVertexList( );
       for( unsigned int pIt = 0; pIt < path->Size( ); ++pIt )
       {
@@ -539,12 +569,16 @@ AirwaysTree& ConvertFilterToAirwaysTree( TInputImage* input_image, cpPlugins::Wo
 
       } // rof
 
+      // Finish association
+      dstIt->second->SetEdge( edge );
+
+      // Put it as next candidate
+      q.push( eIt->first );
+
     } // rof
 
-  } // rof
-  auto seed0 =
-    ws.GetFilter( "seed" )->GetOutputData( "Output" )->
-    GetITK< TVerticesFA >( )->Get( )[ 0 ];
+  } // elihw
+
   AirwaysTree* tree =
     new AirwaysTree( input_image, NULL, vertexMap[ seed0 ], false );
   std::time(&end);