From: Leonardo Flórez-Valencia Date: Wed, 15 Feb 2017 03:09:42 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~10 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=cpPlugins.git;a=commitdiff_plain;h=8503ed517290328e3770807b09ff27bf55d66571 ... --- diff --git a/lib/cpExtensions/Algorithms/SkeletonWriter.hxx b/lib/cpExtensions/Algorithms/SkeletonWriter.hxx index 76e05c1..15093f6 100644 --- a/lib/cpExtensions/Algorithms/SkeletonWriter.hxx +++ b/lib/cpExtensions/Algorithms/SkeletonWriter.hxx @@ -5,6 +5,8 @@ #ifndef __cpExtensions__Algorithms__SkeletonWriter__hxx__ #define __cpExtensions__Algorithms__SkeletonWriter__hxx__ +#include + // ------------------------------------------------------------------------- template< class _TSkeleton > const _TSkeleton* cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >:: @@ -66,11 +68,53 @@ void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >:: GenerateData( ) { const TSkeleton* sk = this->GetInput( ); - std::stringstream out; - out << TSkeleton::Dimension << std::endl; - - // Write auto mIt = sk->BeginEdgesRows( ); + auto rIt = mIt->second.begin( ); + auto eIt = rIt->second.begin( ); + auto path = *eIt; + + // Write base information + std::stringstream out1, out2; + out1 << TSkeleton::Dimension << std::endl; + auto spa = path->GetSpacing( ); + for( unsigned int d = 0; d < TSkeleton::Dimension; ++d ) + out1 << spa[ d ] << " "; + out1 << std::endl; + auto 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; + auto ori = path->GetOrigin( ); + for( unsigned int d = 0; d < TSkeleton::Dimension; ++d ) + out1 << ori[ d ] << " "; + out1 << std::endl; + + // End points + auto end_points = sk->GetEndPoints( ); + out1 << end_points.size( ) << std::endl; + for( auto point : end_points ) + { + for( unsigned int d = 0; d < TSkeleton::Dimension; ++d ) + out1 << point[ d ] << " "; + out1 << std::endl; + + } // rof + + // Bifurcations + auto bifurcations = sk->GetBifurcations( ); + out1 << bifurcations.size( ) << std::endl; + for( auto point : bifurcations ) + { + for( unsigned int d = 0; d < TSkeleton::Dimension; ++d ) + out1 << point[ d ] << " "; + out1 << std::endl; + + } // rof + + // Write paths + unsigned long pathCount = 0; + mIt = sk->BeginEdgesRows( ); for( ; mIt != sk->EndEdgesRows( ); ++mIt ) { auto rIt = mIt->second.begin( ); @@ -80,46 +124,34 @@ GenerateData( ) for( ; eIt != rIt->second.end( ); ++eIt ) { auto path = *eIt; + pathCount++; unsigned int size = path->GetSize( ); - auto spa = path->GetSpacing( ); - auto ori = path->GetOrigin( ); - auto dir = path->GetDirection( ); - out << size << std::endl; - for( unsigned int d = 0; d < TSkeleton::Dimension; ++d ) - out << spa[ d ] << " "; - out << std::endl; - for( unsigned int d = 0; d < TSkeleton::Dimension; ++d ) - out << ori[ d ] << " "; - out << std::endl; - for( unsigned int d = 0; d < TSkeleton::Dimension; ++d ) - for( unsigned int e = 0; e < TSkeleton::Dimension; ++e ) - out << dir[ d ][ e ] << " "; - out << std::endl; - + out2 << size << std::endl; for( unsigned int i = 0; i < path->GetSize( ); ++i ) { auto v = path->GetVertex( i ); for( unsigned int d = 0; d < TSkeleton::Dimension; ++d ) - out << v[ d ] << " "; + out2 << v[ d ] << " "; } // rof - out << std::endl; + out2 << std::endl; } // rof } // rof } // rof - out << "0" << std::endl; - - /* TODO - if( !( cpExtensions::Write( out.str( ), this->m_FileName ) ) ) - itkExceptionMacro( - << "Unable to write skeleton to \"" - << this->m_FileName - << "\"" - ); - */ + out1 << pathCount << std::endl << out2.str( ); + + // Real write + std::ofstream file_stream( this->m_FileName.c_str( ), std::ofstream::binary ); + if( !file_stream ) + itkExceptionMacro( + << "Unable to write skeleton to \"" + << this->m_FileName + << "\"" + ); + file_stream.write( out1.str( ).c_str( ), out1.str( ).size( ) ); } #endif // __cpExtensions__Algorithms__SkeletonWriter__hxx__ diff --git a/lib/cpExtensions/DataStructures/Skeleton.hxx b/lib/cpExtensions/DataStructures/Skeleton.hxx index 579f425..12f463f 100644 --- a/lib/cpExtensions/DataStructures/Skeleton.hxx +++ b/lib/cpExtensions/DataStructures/Skeleton.hxx @@ -45,6 +45,14 @@ cpExtensions::DataStructures::Skeleton< _VDim >:: GetEndPoints( ) const { std::vector< TIndex > res; + auto mIt = this->BeginEdgesRows( ); + for( ; mIt != this->EndEdgesRows( ); ++mIt ) + { + unsigned long count = mIt->second.size( ); + if( count == 1 ) + res.push_back( mIt->first ); + + } // rof return( res ); } @@ -55,6 +63,14 @@ cpExtensions::DataStructures::Skeleton< _VDim >:: GetBifurcations( ) const { std::vector< TIndex > res; + auto mIt = this->BeginEdgesRows( ); + for( ; mIt != this->EndEdgesRows( ); ++mIt ) + { + unsigned long count = mIt->second.size( ); + if( count > 1 ) + res.push_back( mIt->first ); + + } // rof return( res ); }