]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/IO/MatrixValuesContainerWriter.hxx
I/O classes added
[FrontAlgorithms.git] / lib / fpa / IO / MatrixValuesContainerWriter.hxx
1 #ifndef __FPA__IO__MATRIXVALUESCONTAINERWRITER__HXX__
2 #define __FPA__IO__MATRIXVALUESCONTAINERWRITER__HXX__
3
4 #include <fstream>
5 #include <itkMacro.h>
6
7 // -------------------------------------------------------------------------
8 template< class T >
9 void fpa::IO::MatrixValuesContainerWriter< T >::
10 SetInput( const T* input )
11 {
12   this->itk::ProcessObject::SetNthInput( 0, const_cast< T* >( input ) );
13 }
14
15 // -------------------------------------------------------------------------
16 template< class T >
17 T* fpa::IO::MatrixValuesContainerWriter< T >::
18 GetInput( )
19 {
20   return( dynamic_cast< T* >( this->itk::ProcessObject::GetInput( 0 ) ) );
21 }
22
23 // -------------------------------------------------------------------------
24 template< class T >
25 const T* fpa::IO::MatrixValuesContainerWriter< T >::
26 GetInput( ) const
27 {
28   return(
29     dynamic_cast< const T* >( this->itk::ProcessObject::GetInput( 0 ) )
30     );
31 }
32
33 // -------------------------------------------------------------------------
34 template< class T >
35 void fpa::IO::MatrixValuesContainerWriter< T >::
36 Update( )
37 {
38   T* input = this->GetInput( );
39   if( input != NULL )
40   {
41     input->UpdateOutputInformation( );
42     input->UpdateOutputData( );
43     this->GenerateData( );
44     this->ReleaseInputs( );
45
46   } // fi
47 }
48
49 // -------------------------------------------------------------------------
50 template< class T >
51 fpa::IO::MatrixValuesContainerWriter< T >::
52 MatrixValuesContainerWriter( )
53   : Superclass( ),
54     m_FileName( "" )
55 {
56   this->SetNumberOfRequiredInputs( 1 );
57 }
58
59 // -------------------------------------------------------------------------
60 template< class T >
61 fpa::IO::MatrixValuesContainerWriter< T >::
62 ~MatrixValuesContainerWriter( )
63 {
64 }
65
66 // -------------------------------------------------------------------------
67 template< class T >
68 void fpa::IO::MatrixValuesContainerWriter< T >::
69 GenerateData( )
70 {
71   const T* input = this->GetInput( );
72
73   std::ofstream out( this->m_FileName.c_str( ) );
74   if( !out )
75   {
76     itkExceptionMacro(
77       << "Error opening file to write a minimum spanning tree: \""
78       << this->m_FileName
79       << "\""
80       );
81     return;
82
83   } // fi
84
85   out << T::TIndex::Dimension << std::endl;
86
87   const typename T::TDecorated& real_input = input->Get( );
88   out << real_input.size( ) << std::endl;
89   typename T::TDecorated::const_iterator cIt = real_input.begin( );
90   for( ; cIt != real_input.end( ); ++cIt )
91   {
92     out << cIt->second.size( ) << " ";
93     for( unsigned int d = 0; d < T::TIndex::Dimension; ++d )
94       out << ( cIt->first )[ d ] << " ";
95
96     typename T::TDecorated::value_type::second_type::const_iterator rIt =
97       cIt->second.begin( );
98     for( ; rIt != cIt->second.end( ); ++rIt )
99     {
100       for( unsigned int d = 0; d < T::TIndex::Dimension; ++d )
101         out << ( rIt->first )[ d ] << " ";
102       out << rIt->second << std::endl;
103
104     } // rof
105
106   } // rof
107   out.close( );
108 }
109
110 #endif // __FPA__IO__MATRIXVALUESCONTAINERWRITER__HXX__
111
112 // eof - $RCSfile$