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