1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Common__Image__SkeletonWriter__hxx__
6 #define __fpa__Common__Image__SkeletonWriter__hxx__
10 // -------------------------------------------------------------------------
11 template< class _TSkeleton >
12 const _TSkeleton* fpa::Common::Image::SkeletonWriter< _TSkeleton >::
16 dynamic_cast< const TSkeleton* >(
17 this->itk::ProcessObject::GetInput( 0 )
22 // -------------------------------------------------------------------------
23 template< class _TSkeleton >
24 void fpa::Common::Image::SkeletonWriter< _TSkeleton >::
25 SetInput( const _TSkeleton* skeleton )
27 this->itk::ProcessObject::SetNthInput(
28 0, const_cast< TSkeleton* >( skeleton )
32 // -------------------------------------------------------------------------
33 template< class _TSkeleton >
34 void fpa::Common::Image::SkeletonWriter< _TSkeleton >::
37 TSkeleton* input = const_cast< TSkeleton* >( this->GetInput( ) );
40 input->UpdateOutputInformation( );
41 input->UpdateOutputData( );
42 this->GenerateData( );
43 this->ReleaseInputs( );
48 // -------------------------------------------------------------------------
49 template< class _TSkeleton >
50 fpa::Common::Image::SkeletonWriter< _TSkeleton >::
55 this->SetNumberOfRequiredInputs( 1 );
58 // -------------------------------------------------------------------------
59 template< class _TSkeleton >
60 fpa::Common::Image::SkeletonWriter< _TSkeleton >::
65 // -------------------------------------------------------------------------
66 template< class _TSkeleton >
67 void fpa::Common::Image::SkeletonWriter< _TSkeleton >::
70 const TSkeleton* sk = this->GetInput( );
71 typename TMatrix::const_iterator mIt = sk->BeginEdgesRows( );
72 typename TMatrixRow::const_iterator rIt = mIt->second.begin( );
73 typename TEdges::const_iterator eIt = rIt->second.begin( );
74 const TPath* path = *eIt;
76 // Write base information
77 std::stringstream out1, out2;
78 out1 << TSkeleton::Dimension << std::endl;
79 typename TPath::TSpacing spa = path->GetSpacing( );
80 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
81 out1 << spa[ d ] << " ";
83 typename TPath::TDirection dir = path->GetDirection( );
84 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
85 for( unsigned int e = 0; e < TSkeleton::Dimension; ++e )
86 out1 << dir[ d ][ e ] << " ";
88 typename TPath::TPoint ori = path->GetOrigin( );
89 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
90 out1 << ori[ d ] << " ";
94 std::vector< TVertex > end_points = sk->GetEndPoints( );
95 out1 << end_points.size( ) << std::endl;
96 typename std::vector< TVertex >::const_iterator epIt = end_points.begin( );
97 for( ; epIt != end_points.end( ); ++epIt )
99 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
100 out1 << ( *epIt )[ d ] << " ";
106 std::vector< TVertex > bifurcations = sk->GetBifurcations( );
107 out1 << bifurcations.size( ) << std::endl;
108 typename std::vector< TVertex >::const_iterator bIt = bifurcations.begin( );
109 for( ; bIt != bifurcations.end( ); ++bIt )
111 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
112 out1 << ( *bIt )[ d ] << " ";
118 unsigned long pathCount = 0;
119 mIt = sk->BeginEdgesRows( );
120 for( ; mIt != sk->EndEdgesRows( ); ++mIt )
122 typename TMatrixRow::const_iterator rIt = mIt->second.begin( );
123 for( ; rIt != mIt->second.end( ); ++rIt )
125 typename TEdges::const_iterator eIt = rIt->second.begin( );
126 for( ; eIt != rIt->second.end( ); ++eIt )
130 unsigned int size = path->GetSize( );
131 out2 << size << std::endl;
132 for( unsigned int i = 0; i < path->GetSize( ); ++i )
134 TVertex v = path->GetVertex( i );
135 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
136 out2 << v[ d ] << " ";
146 out1 << pathCount << std::endl << out2.str( );
149 std::ofstream file_stream( this->m_FileName.c_str( ), std::ofstream::binary );
152 << "Unable to write skeleton to \""
156 file_stream.write( out1.str( ).c_str( ), out1.str( ).size( ) );
159 #endif // __fpa__Common__Image__SkeletonWriter__hxx__