]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/IO/UniqueValuesContainerReader.hxx
16719f2df3191f8065e703e833a8f3c0ffa08f7e
[FrontAlgorithms.git] / lib / fpa / IO / UniqueValuesContainerReader.hxx
1 #ifndef __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__
2 #define __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__
3
4 #include <fstream>
5
6 // -------------------------------------------------------------------------
7 template< class T >
8 T* fpa::IO::UniqueValuesContainerReader< T >::
9 GetOutput( )
10 {
11   return( itkDynamicCastInDebugMode< T* >( this->GetPrimaryOutput( ) ) );
12 }
13
14 // -------------------------------------------------------------------------
15 template< class T >
16 void fpa::IO::UniqueValuesContainerReader< T >::
17 Update( )
18 {
19   this->GenerateData( );
20 }
21
22 // -------------------------------------------------------------------------
23 template< class T >
24 fpa::IO::UniqueValuesContainerReader< T >::
25 UniqueValuesContainerReader( )
26   : Superclass( ),
27     m_FileName( "" )
28 {
29   this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 );
30   this->itk::ProcessObject::SetNthOutput( 0, T::New( ) );
31 }
32
33 // -------------------------------------------------------------------------
34 template< class T >
35 fpa::IO::UniqueValuesContainerReader< T >::
36 ~UniqueValuesContainerReader( )
37 {
38 }
39
40 // -------------------------------------------------------------------------
41 template< class T >
42 void fpa::IO::UniqueValuesContainerReader< T >::
43 GenerateData( )
44 {
45   T* output = this->GetOutput( );
46   output->Clear( );
47
48   std::ifstream in( this->m_FileName.c_str( ) );
49   if( !in )
50   {
51     itkExceptionMacro(
52       << "Error opening file to read a minimum spanning tree: \""
53       << this->m_FileName
54       << "\""
55       );
56     return;
57
58   } // fi
59
60   unsigned int dim;
61   unsigned long nVertices;
62   in >> dim >> nVertices;
63   for( unsigned long vId = 0; vId < nVertices; ++vId )
64   {
65     typename T::TValue v;
66     for( unsigned int d = 0; d < dim; ++d )
67     {
68       long val;
69       in >> val;
70       if( d < T::TValue::Dimension )
71         v[ d ] = val;
72
73     } // rof
74     output->Insert( v );
75
76   } // rof
77   in.close( );
78 }
79
80 #endif // __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__
81
82 // eof - $RCSfile$