1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __cpExtensions__Algorithms__SkeletonWriter__hxx__
6 #define __cpExtensions__Algorithms__SkeletonWriter__hxx__
10 // -------------------------------------------------------------------------
11 template< class _TSkeleton >
12 const _TSkeleton* cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
16 dynamic_cast< const TSkeleton* >(
17 this->itk::ProcessObject::GetInput( 0 )
22 // -------------------------------------------------------------------------
23 template< class _TSkeleton >
24 void cpExtensions::Algorithms::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 cpExtensions::Algorithms::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 cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
55 this->SetNumberOfRequiredInputs( 1 );
58 // -------------------------------------------------------------------------
59 template< class _TSkeleton >
60 cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
65 // -------------------------------------------------------------------------
66 template< class _TSkeleton >
67 void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
70 const TSkeleton* sk = this->GetInput( );
71 auto mIt = sk->BeginEdgesRows( );
72 auto rIt = mIt->second.begin( );
73 auto eIt = rIt->second.begin( );
76 // Write base information
77 std::stringstream out1, out2;
78 out1 << TSkeleton::Dimension << std::endl;
79 auto spa = path->GetSpacing( );
80 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
81 out1 << spa[ d ] << " ";
83 auto 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 auto ori = path->GetOrigin( );
89 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
90 out1 << ori[ d ] << " ";
94 auto end_points = sk->GetEndPoints( );
95 out1 << end_points.size( ) << std::endl;
96 for( auto point : end_points )
98 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
99 out1 << point[ d ] << " ";
105 auto bifurcations = sk->GetBifurcations( );
106 out1 << bifurcations.size( ) << std::endl;
107 for( auto point : bifurcations )
109 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
110 out1 << point[ d ] << " ";
116 unsigned long pathCount = 0;
117 mIt = sk->BeginEdgesRows( );
118 for( ; mIt != sk->EndEdgesRows( ); ++mIt )
120 auto rIt = mIt->second.begin( );
121 for( ; rIt != mIt->second.end( ); ++rIt )
123 auto eIt = rIt->second.begin( );
124 for( ; eIt != rIt->second.end( ); ++eIt )
128 unsigned int size = path->GetSize( );
129 out2 << size << std::endl;
130 for( unsigned int i = 0; i < path->GetSize( ); ++i )
132 auto v = path->GetVertex( i );
133 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
134 out2 << v[ d ] << " ";
144 out1 << pathCount << std::endl << out2.str( );
147 std::ofstream file_stream( this->m_FileName.c_str( ), std::ofstream::binary );
150 << "Unable to write skeleton to \""
154 file_stream.write( out1.str( ).c_str( ), out1.str( ).size( ) );
157 #endif // __cpExtensions__Algorithms__SkeletonWriter__hxx__