]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/SkeletonWriter.hxx
76e05c117bdba8e356660d74c04ad7d37656d76a
[cpPlugins.git] / lib / cpExtensions / Algorithms / SkeletonWriter.hxx
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __cpExtensions__Algorithms__SkeletonWriter__hxx__
6 #define __cpExtensions__Algorithms__SkeletonWriter__hxx__
7
8 // -------------------------------------------------------------------------
9 template< class _TSkeleton >
10 const _TSkeleton* cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
11 GetInput( ) const
12 {
13   return(
14     dynamic_cast< const TSkeleton* >(
15       this->itk::ProcessObject::GetInput( 0 )
16       )
17     );
18 }
19
20 // -------------------------------------------------------------------------
21 template< class _TSkeleton >
22 void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
23 SetInput( const _TSkeleton* skeleton )
24 {
25   this->itk::ProcessObject::SetNthInput(
26     0, const_cast< TSkeleton* >( skeleton )
27     );
28 }
29
30 // -------------------------------------------------------------------------
31 template< class _TSkeleton >
32 void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
33 Update( )
34 {
35   TSkeleton* input = const_cast< TSkeleton* >( this->GetInput( ) );
36   if( input != NULL )
37   {
38     input->UpdateOutputInformation( );
39     input->UpdateOutputData( );
40     this->GenerateData( );
41     this->ReleaseInputs( );
42
43   } // fi
44 }
45
46 // -------------------------------------------------------------------------
47 template< class _TSkeleton >
48 cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
49 SkeletonWriter( )
50   : Superclass( ),
51     m_FileName( "" )
52 {
53   this->SetNumberOfRequiredInputs( 1 );
54 }
55
56 // -------------------------------------------------------------------------
57 template< class _TSkeleton >
58 cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
59 ~SkeletonWriter( )
60 {
61 }
62
63 // -------------------------------------------------------------------------
64 template< class _TSkeleton >
65 void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
66 GenerateData( )
67 {
68   const TSkeleton* sk = this->GetInput( );
69   std::stringstream out;
70   out << TSkeleton::Dimension << std::endl;
71
72   // Write
73   auto mIt = sk->BeginEdgesRows( );
74   for( ; mIt != sk->EndEdgesRows( ); ++mIt )
75   {
76     auto rIt = mIt->second.begin( );
77     for( ; rIt != mIt->second.end( ); ++rIt )
78     {
79       auto eIt = rIt->second.begin( );
80       for( ; eIt != rIt->second.end( ); ++eIt )
81       {
82         auto path = *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 ] << " ";
90         out << std::endl;
91         for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
92           out << ori[ d ] << " ";
93         out << std::endl;
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 ] << " ";
97         out << std::endl;
98
99         for( unsigned int i = 0; i < path->GetSize( ); ++i )
100         {
101           auto v = path->GetVertex( i );
102           for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
103             out << v[ d ] << " ";
104
105         } // rof
106         out << std::endl;
107
108       } // rof
109
110     } // rof
111
112   } // rof
113   out << "0" << std::endl;
114
115   /* TODO
116      if( !( cpExtensions::Write( out.str( ), this->m_FileName ) ) )
117      itkExceptionMacro(
118      << "Unable to write skeleton to \""
119      << this->m_FileName
120      << "\""
121      );
122   */
123 }
124
125 #endif // __cpExtensions__Algorithms__SkeletonWriter__hxx__
126
127 // eof - $RCSfile$