1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Base__SkeletonWriter__hxx__
7 #define __fpa__Base__SkeletonWriter__hxx__
11 // -------------------------------------------------------------------------
12 template< class _TSkeleton >
13 const _TSkeleton* fpa::Base::SkeletonWriter< _TSkeleton >::
17 dynamic_cast< const TSkeleton* >(
18 this->itk::ProcessObject::GetInput( 0 )
23 // -------------------------------------------------------------------------
24 template< class _TSkeleton >
25 void fpa::Base::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::Base::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::Base::SkeletonWriter< _TSkeleton >::
56 this->SetNumberOfRequiredInputs( 1 );
59 // -------------------------------------------------------------------------
60 template< class _TSkeleton >
61 fpa::Base::SkeletonWriter< _TSkeleton >::
66 // -------------------------------------------------------------------------
67 template< class _TSkeleton >
68 void fpa::Base::SkeletonWriter< _TSkeleton >::
71 const TSkeleton* sk = this->GetInput( );
72 auto mIt = sk->BeginEdgesRows( );
73 auto rIt = mIt->second.begin( );
74 auto eIt = rIt->second.begin( );
77 // Write base information
78 std::stringstream out1, out2;
79 out1 << TSkeleton::Dimension << std::endl;
80 auto spa = path->GetSpacing( );
81 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
82 out1 << spa[ d ] << " ";
84 auto 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 auto ori = path->GetOrigin( );
90 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
91 out1 << ori[ d ] << " ";
95 auto end_points = sk->GetEndPoints( );
96 out1 << end_points.size( ) << std::endl;
97 for( auto point : end_points )
99 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
100 out1 << point[ d ] << " ";
106 auto bifurcations = sk->GetBifurcations( );
107 out1 << bifurcations.size( ) << std::endl;
108 for( auto point : bifurcations )
110 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
111 out1 << point[ d ] << " ";
117 unsigned long pathCount = 0;
118 mIt = sk->BeginEdgesRows( );
119 for( ; mIt != sk->EndEdgesRows( ); ++mIt )
121 auto rIt = mIt->second.begin( );
122 for( ; rIt != mIt->second.end( ); ++rIt )
124 auto eIt = rIt->second.begin( );
125 for( ; eIt != rIt->second.end( ); ++eIt )
129 unsigned int size = path->GetSize( );
130 out2 << size << std::endl;
131 for( unsigned int i = 0; i < path->GetSize( ); ++i )
133 auto v = path->GetVertex( i );
134 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
135 out2 << v[ d ] << " ";
145 out1 << pathCount << std::endl << out2.str( );
148 std::ofstream file_stream( this->m_FileName.c_str( ), std::ofstream::binary );
151 << "Unable to write skeleton to \""
155 file_stream.write( out1.str( ).c_str( ), out1.str( ).size( ) );
158 #endif // __fpa__Base__SkeletonWriter__hxx__