1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __cpExtensions__Algorithms__SkeletonWriter__hxx__
6 #define __cpExtensions__Algorithms__SkeletonWriter__hxx__
8 #include <cpPlugins/Utility.h>
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 std::stringstream out;
72 out << TSkeleton::Dimension << std::endl;
75 auto mIt = sk->BeginEdgesRows( );
76 for( ; mIt != sk->EndEdgesRows( ); ++mIt )
78 auto rIt = mIt->second.begin( );
79 for( ; rIt != mIt->second.end( ); ++rIt )
81 auto eIt = rIt->second.begin( );
82 for( ; eIt != rIt->second.end( ); ++eIt )
85 unsigned int size = path->GetSize( );
86 auto spa = path->GetSpacing( );
87 auto ori = path->GetOrigin( );
88 auto dir = path->GetDirection( );
89 out << size << std::endl;
90 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
91 out << spa[ d ] << " ";
93 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
94 out << ori[ d ] << " ";
96 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
97 for( unsigned int e = 0; e < TSkeleton::Dimension; ++e )
98 out << dir[ d ][ e ] << " ";
101 for( unsigned int i = 0; i < path->GetSize( ); ++i )
103 auto v = path->GetVertex( i );
104 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
105 out << v[ d ] << " ";
108 std::cout << std::endl;
115 out << "0" << std::endl;
117 if( !( cpPlugins::Write( out.str( ), this->m_FileName ) ) )
119 << "Unable to write skeleton to \""
125 #endif // __cpExtensions__Algorithms__SkeletonWriter__hxx__