1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Image__SkeletonWriter__hxx__
7 #define __fpa__Image__SkeletonWriter__hxx__
11 // -------------------------------------------------------------------------
12 template< class _TSkeleton >
13 const _TSkeleton* fpa::Image::SkeletonWriter< _TSkeleton >::
17 dynamic_cast< const TSkeleton* >(
18 this->itk::ProcessObject::GetInput( 0 )
23 // -------------------------------------------------------------------------
24 template< class _TSkeleton >
25 void fpa::Image::SkeletonWriter< _TSkeleton >::
26 SetInput( const _TSkeleton* skeleton )
28 this->itk::ProcessObject::SetNthInput(
29 0, const_cast< TSkeleton* >( skeleton )
33 // -------------------------------------------------------------------------
34 template< class _TSkeleton >
35 void fpa::Image::SkeletonWriter< _TSkeleton >::
38 TSkeleton* input = const_cast< TSkeleton* >( this->GetInput( ) );
41 input->UpdateOutputInformation( );
42 input->UpdateOutputData( );
43 this->GenerateData( );
44 this->ReleaseInputs( );
49 // -------------------------------------------------------------------------
50 template< class _TSkeleton >
51 fpa::Image::SkeletonWriter< _TSkeleton >::
56 this->SetNumberOfRequiredInputs( 1 );
59 // -------------------------------------------------------------------------
60 template< class _TSkeleton >
61 fpa::Image::SkeletonWriter< _TSkeleton >::
66 // -------------------------------------------------------------------------
67 template< class _TSkeleton >
68 void fpa::Image::SkeletonWriter< _TSkeleton >::
71 const TSkeleton* sk = this->GetInput( );
72 typename TMatrix::const_iterator mIt = sk->BeginEdgesRows( );
73 typename TMatrixRow::const_iterator rIt = mIt->second.begin( );
74 typename TEdges::const_iterator eIt = rIt->second.begin( );
75 const TPath* path = *eIt;
77 // Write base information
78 std::stringstream out1, out2;
79 out1 << TSkeleton::Dimension << std::endl;
80 typename TPath::TSpacing spa = path->GetSpacing( );
81 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
82 out1 << spa[ d ] << " ";
84 typename TPath::TDirection dir = path->GetDirection( );
85 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
86 for( unsigned int e = 0; e < TSkeleton::Dimension; ++e )
87 out1 << dir[ d ][ e ] << " ";
89 typename TPath::TPoint ori = path->GetOrigin( );
90 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
91 out1 << ori[ d ] << " ";
95 std::vector< TVertex > end_points = sk->GetEndPoints( );
96 out1 << end_points.size( ) << std::endl;
97 typename std::vector< TVertex >::const_iterator epIt = end_points.begin( );
98 for( ; epIt != end_points.end( ); ++epIt )
100 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
101 out1 << ( *epIt )[ d ] << " ";
107 std::vector< TVertex > bifurcations = sk->GetBifurcations( );
108 out1 << bifurcations.size( ) << std::endl;
109 typename std::vector< TVertex >::const_iterator bIt = bifurcations.begin( );
110 for( ; bIt != bifurcations.end( ); ++bIt )
112 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
113 out1 << ( *bIt )[ d ] << " ";
119 unsigned long pathCount = 0;
120 mIt = sk->BeginEdgesRows( );
121 for( ; mIt != sk->EndEdgesRows( ); ++mIt )
123 typename TMatrixRow::const_iterator rIt = mIt->second.begin( );
124 for( ; rIt != mIt->second.end( ); ++rIt )
126 typename TEdges::const_iterator eIt = rIt->second.begin( );
127 for( ; eIt != rIt->second.end( ); ++eIt )
131 unsigned int size = path->GetSize( );
132 out2 << size << std::endl;
133 for( unsigned int i = 0; i < path->GetSize( ); ++i )
135 TVertex v = path->GetVertex( i );
136 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
137 out2 << v[ d ] << " ";
147 out1 << pathCount << std::endl << out2.str( );
150 std::ofstream file_stream( this->m_FileName.c_str( ), std::ofstream::binary );
153 << "Unable to write skeleton to \""
157 file_stream.write( out1.str( ).c_str( ), out1.str( ).size( ) );
160 #endif // __fpa__Image__SkeletonWriter__hxx__