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 // -------------------------------------------------------------------------
9 template< class _TSkeleton >
10 const _TSkeleton* cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
14 dynamic_cast< const TSkeleton* >(
15 this->itk::ProcessObject::GetInput( 0 )
20 // -------------------------------------------------------------------------
21 template< class _TSkeleton >
22 void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
23 SetInput( const _TSkeleton* skeleton )
25 this->itk::ProcessObject::SetNthInput(
26 0, const_cast< TSkeleton* >( skeleton )
30 // -------------------------------------------------------------------------
31 template< class _TSkeleton >
32 void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
35 TSkeleton* input = const_cast< TSkeleton* >( this->GetInput( ) );
38 input->UpdateOutputInformation( );
39 input->UpdateOutputData( );
40 this->GenerateData( );
41 this->ReleaseInputs( );
46 // -------------------------------------------------------------------------
47 template< class _TSkeleton >
48 cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
53 this->SetNumberOfRequiredInputs( 1 );
56 // -------------------------------------------------------------------------
57 template< class _TSkeleton >
58 cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
63 // -------------------------------------------------------------------------
64 template< class _TSkeleton >
65 void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
68 const TSkeleton* sk = this->GetInput( );
69 std::stringstream out;
70 out << TSkeleton::Dimension << std::endl;
73 auto mIt = sk->BeginEdgesRows( );
74 for( ; mIt != sk->EndEdgesRows( ); ++mIt )
76 auto rIt = mIt->second.begin( );
77 for( ; rIt != mIt->second.end( ); ++rIt )
79 auto eIt = rIt->second.begin( );
80 for( ; eIt != rIt->second.end( ); ++eIt )
83 unsigned int size = path->GetSize( );
84 auto spa = path->GetSpacing( );
85 auto ori = path->GetOrigin( );
86 auto dir = path->GetDirection( );
87 out << size << std::endl;
88 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
89 out << spa[ d ] << " ";
91 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
92 out << ori[ d ] << " ";
94 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
95 for( unsigned int e = 0; e < TSkeleton::Dimension; ++e )
96 out << dir[ d ][ e ] << " ";
99 for( unsigned int i = 0; i < path->GetSize( ); ++i )
101 auto v = path->GetVertex( i );
102 for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
103 out << v[ d ] << " ";
113 out << "0" << std::endl;
116 if( !( cpExtensions::Write( out.str( ), this->m_FileName ) ) )
118 << "Unable to write skeleton to \""
125 #endif // __cpExtensions__Algorithms__SkeletonWriter__hxx__