]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Common/Image/PolyLineParametricPathWriter.hxx
94b6a0414f13fde78ae9b84f8d004281f2f8929f
[FrontAlgorithms.git] / lib / fpa / Common / Image / PolyLineParametricPathWriter.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Common__Image__PolyLineParametricPathWriter__hxx__
6 #define __fpa__Common__Image__PolyLineParametricPathWriter__hxx__
7
8 #include <fstream>
9
10 // -------------------------------------------------------------------------
11 template< class _TPath >
12 const _TPath* fpa::Common::Image::PolyLineParametricPathWriter< _TPath >::
13 GetInput( ) const
14 {
15   return(
16     dynamic_cast< const TPath* >(
17       this->itk::ProcessObject::GetInput( 0 )
18       )
19     );
20 }
21
22 // -------------------------------------------------------------------------
23 template< class _TPath >
24 void fpa::Common::Image::PolyLineParametricPathWriter< _TPath >::
25 SetInput( const _TPath* path )
26 {
27   this->itk::ProcessObject::SetNthInput( 0, const_cast< TPath* >( path ) );
28 }
29
30 // -------------------------------------------------------------------------
31 template< class _TPath >
32 void fpa::Common::Image::PolyLineParametricPathWriter< _TPath >::
33 Update( )
34 {
35   TPath* input = const_cast< TPath* >( 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 _TPath >
48 fpa::Common::Image::PolyLineParametricPathWriter< _TPath >::
49 PolyLineParametricPathWriter( )
50   : Superclass( ),
51     m_FileName( "" )
52 {
53   this->SetNumberOfRequiredInputs( 1 );
54 }
55
56 // -------------------------------------------------------------------------
57 template< class _TPath >
58 fpa::Common::Image::PolyLineParametricPathWriter< _TPath >::
59 ~PolyLineParametricPathWriter( )
60 {
61 }
62
63 // -------------------------------------------------------------------------
64 template< class _TPath >
65 void fpa::Common::Image::PolyLineParametricPathWriter< _TPath >::
66 GenerateData( )
67 {
68   const TPath* path = this->GetInput( );
69
70   // Write base information
71   std::stringstream out1, out2;
72   out1 << TPath::Dimension << std::endl;
73   typename TPath::TSpacing spa = path->GetSpacing( );
74   for( unsigned int d = 0; d < TPath::Dimension; ++d )
75     out1 << spa[ d ] << " ";
76   out1 << std::endl;
77   typename TPath::TDirection dir = path->GetDirection( );
78   for( unsigned int d = 0; d < TPath::Dimension; ++d )
79     for( unsigned int e = 0; e < TPath::Dimension; ++e )
80       out1 << dir[ d ][ e ] << " ";
81   out1 << std::endl;
82   typename TPath::TPoint ori = path->GetOrigin( );
83   for( unsigned int d = 0; d < TPath::Dimension; ++d )
84     out1 << ori[ d ] << " ";
85   out1 << std::endl;
86
87   // Write path
88   unsigned int size = path->GetSize( );
89   out2 << size << std::endl;
90   for( unsigned int i = 0; i < path->GetSize( ); ++i )
91   {
92     typename TPath::TIndex v = path->GetVertex( i );
93     for( unsigned int d = 0; d < TPath::Dimension; ++d )
94       out2 << v[ d ] << " ";
95
96   } // rof
97
98   // Real write
99   std::ofstream file_stream( this->m_FileName.c_str( ), std::ofstream::binary );
100   if( !file_stream )
101     itkExceptionMacro(
102       << "Unable to write skeleton to \""
103       << this->m_FileName
104       << "\""
105       );
106   file_stream.write( out1.str( ).c_str( ), out1.str( ).size( ) );
107 }
108
109 #endif // __fpa__Common__Image__PolyLineParametricPathWriter__hxx__
110
111 // eof - $RCSfile$