]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 7 Dec 2017 21:57:56 +0000 (16:57 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 7 Dec 2017 21:57:56 +0000 (16:57 -0500)
lib/ivq/ITK/ImageSkeletonWriter.hxx

index 3541bcd22f26da0a3fde00c9ac75a61b98c6fc1d..d70f40cac3b7613c7b98195f8aa3d68fc9b39315 100644 (file)
@@ -45,83 +45,119 @@ template< class _TSkeleton >
 void ivq::ITK::ImageSkeletonWriter< _TSkeleton >::
 GenerateData( )
 {
-  const TSkeleton* sk = this->GetInput( );
-  typename TMatrix::const_iterator mIt = sk->BeginEdgesRows( );
-  typename TMatrixRow::const_iterator rIt = mIt->second.begin( );
-  typename TEdges::const_iterator eIt = rIt->second.begin( );
-  const TPath* path = *eIt;
-
   // Write base information
   std::stringstream out1, out2;
   out1 << TSkeleton::Dimension << std::endl;
-  typename TPath::TSpacing spa = path->GetSpacing( );
-  for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
-    out1 << spa[ d ] << " ";
-  out1 << std::endl;
-  typename TPath::TDirection dir = path->GetDirection( );
-  for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
-    for( unsigned int e = 0; e < TSkeleton::Dimension; ++e )
-      out1 << dir[ d ][ e ] << " ";
-  out1 << std::endl;
-  typename TPath::TPoint ori = path->GetOrigin( );
-  for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
-    out1 << ori[ d ] << " ";
-  out1 << std::endl;
-
-  // End points
-  std::vector< TVertex > end_points = sk->GetEndPoints( );
-  out1 << end_points.size( ) << std::endl;
-  typename std::vector< TVertex >::const_iterator epIt = end_points.begin( );
-  for( ; epIt != end_points.end( ); ++epIt )
-  {
-    for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
-      out1 << ( *epIt )[ d ] << " ";
-    out1 << std::endl;
-
-  } // rof
 
-  // Bifurcations
-  std::vector< TVertex > bifurcations = sk->GetBifurcations( );
-  out1 << bifurcations.size( ) << std::endl;
-  typename std::vector< TVertex >::const_iterator bIt = bifurcations.begin( );
-  for( ; bIt != bifurcations.end( ); ++bIt )
-  {
-    for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
-      out1 << ( *bIt )[ d ] << " ";
-    out1 << std::endl;
-
-  } // rof
-
-  // Write paths
-  unsigned long pathCount = 0;
-  mIt = sk->BeginEdgesRows( );
-  for( ; mIt != sk->EndEdgesRows( ); ++mIt )
+  // Skeleton data
+  bool ok = false;
+  const TSkeleton* sk = this->GetInput( );
+  typename TMatrix::const_iterator mIt = sk->BeginEdgesRows( );
+  if( mIt != sk->EndEdgesRows( ) )
   {
     typename TMatrixRow::const_iterator rIt = mIt->second.begin( );
-    for( ; rIt != mIt->second.end( ); ++rIt )
+    if( rIt != mIt->second.end( ) )
     {
       typename TEdges::const_iterator eIt = rIt->second.begin( );
-      for( ; eIt != rIt->second.end( ); ++eIt )
+      if( eIt != rIt->second.end( ) )
       {
-        TPath* path = *eIt;
-        pathCount++;
-        unsigned int size = path->GetSize( );
-        out2 << size << std::endl;
-        for( unsigned int i = 0; i < path->GetSize( ); ++i )
+        const TPath* path = *eIt;
+        if( path != NULL )
         {
-          TVertex v = path->GetVertex( i );
+          ok = true;
+          typename TPath::TSpacing spa = path->GetSpacing( );
           for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
-            out2 << v[ d ] << " ";
-
-        } // rof
-        out2 << std::endl;
+            out1 << spa[ d ] << " ";
+          out1 << std::endl;
+          typename TPath::TDirection dir = path->GetDirection( );
+          for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+            for( unsigned int e = 0; e < TSkeleton::Dimension; ++e )
+              out1 << dir[ d ][ e ] << " ";
+          out1 << std::endl;
+          typename TPath::TPoint ori = path->GetOrigin( );
+          for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+            out1 << ori[ d ] << " ";
+          out1 << std::endl;
+
+          // End points
+          std::vector< TVertex > end_points = sk->GetEndPoints( );
+          out1 << end_points.size( ) << std::endl;
+          typename std::vector< TVertex >::const_iterator epIt = end_points.begin( );
+          for( ; epIt != end_points.end( ); ++epIt )
+          {
+            for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+              out1 << ( *epIt )[ d ] << " ";
+            out1 << std::endl;
+
+          } // rof
+
+          // Bifurcations
+          std::vector< TVertex > bifurcations = sk->GetBifurcations( );
+          out1 << bifurcations.size( ) << std::endl;
+          typename std::vector< TVertex >::const_iterator bIt = bifurcations.begin( );
+          for( ; bIt != bifurcations.end( ); ++bIt )
+          {
+            for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+              out1 << ( *bIt )[ d ] << " ";
+            out1 << std::endl;
+
+          } // rof
+
+          // Write paths
+          unsigned long pathCount = 0;
+          mIt = sk->BeginEdgesRows( );
+          for( ; mIt != sk->EndEdgesRows( ); ++mIt )
+          {
+            typename TMatrixRow::const_iterator rIt = mIt->second.begin( );
+            for( ; rIt != mIt->second.end( ); ++rIt )
+            {
+              typename TEdges::const_iterator eIt = rIt->second.begin( );
+              for( ; eIt != rIt->second.end( ); ++eIt )
+              {
+                TPath* path = *eIt;
+                pathCount++;
+                unsigned int size = path->GetSize( );
+                out2 << size << std::endl;
+                for( unsigned int i = 0; i < path->GetSize( ); ++i )
+                {
+                  TVertex v = path->GetVertex( i );
+                  for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+                    out2 << v[ d ] << " ";
+
+                } // rof
+                out2 << std::endl;
+
+              } // rof
+
+            } // rof
+
+          } // rof
+          out1 << pathCount << std::endl << out2.str( );
+
+        } // fi
+
+      } // fi
+
+    } // fi
 
-      } // rof
+  } // fi
 
-    } // rof
+  if( !ok )
+  {
+    for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+      out1 << "0 ";
+    out1 << std::endl;
+    for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+      for( unsigned int e = 0; e < TSkeleton::Dimension; ++e )
+        out1 << "0 ";
+    out1 << std::endl;
+    for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+      out1 << "0 ";
+    out1 << std::endl;
+    out1 << "0" << std::endl;
+    out1 << "0" << std::endl;
 
-  } // rof
-  out1 << pathCount << std::endl << out2.str( );
+  } // fi
 
   // Real write
   std::ofstream file_stream( this->m_FileName.c_str( ), std::ofstream::binary );