X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ffpa%2FIO%2FUniqueValuesContainerReader.hxx;fp=lib%2Ffpa%2FIO%2FUniqueValuesContainerReader.hxx;h=16719f2df3191f8065e703e833a8f3c0ffa08f7e;hb=dba0f8d24a98fabeb461b337ed78efaf06cb057c;hp=0000000000000000000000000000000000000000;hpb=b4ed6ddfa7e90e892f07cad9a760961bd4e84e6b;p=FrontAlgorithms.git diff --git a/lib/fpa/IO/UniqueValuesContainerReader.hxx b/lib/fpa/IO/UniqueValuesContainerReader.hxx new file mode 100644 index 0000000..16719f2 --- /dev/null +++ b/lib/fpa/IO/UniqueValuesContainerReader.hxx @@ -0,0 +1,82 @@ +#ifndef __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__ +#define __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__ + +#include + +// ------------------------------------------------------------------------- +template< class T > +T* fpa::IO::UniqueValuesContainerReader< T >:: +GetOutput( ) +{ + return( itkDynamicCastInDebugMode< T* >( this->GetPrimaryOutput( ) ) ); +} + +// ------------------------------------------------------------------------- +template< class T > +void fpa::IO::UniqueValuesContainerReader< T >:: +Update( ) +{ + this->GenerateData( ); +} + +// ------------------------------------------------------------------------- +template< class T > +fpa::IO::UniqueValuesContainerReader< T >:: +UniqueValuesContainerReader( ) + : Superclass( ), + m_FileName( "" ) +{ + this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 ); + this->itk::ProcessObject::SetNthOutput( 0, T::New( ) ); +} + +// ------------------------------------------------------------------------- +template< class T > +fpa::IO::UniqueValuesContainerReader< T >:: +~UniqueValuesContainerReader( ) +{ +} + +// ------------------------------------------------------------------------- +template< class T > +void fpa::IO::UniqueValuesContainerReader< T >:: +GenerateData( ) +{ + T* output = this->GetOutput( ); + output->Clear( ); + + std::ifstream in( this->m_FileName.c_str( ) ); + if( !in ) + { + itkExceptionMacro( + << "Error opening file to read a minimum spanning tree: \"" + << this->m_FileName + << "\"" + ); + return; + + } // fi + + unsigned int dim; + unsigned long nVertices; + in >> dim >> nVertices; + for( unsigned long vId = 0; vId < nVertices; ++vId ) + { + typename T::TValue v; + for( unsigned int d = 0; d < dim; ++d ) + { + long val; + in >> val; + if( d < T::TValue::Dimension ) + v[ d ] = val; + + } // rof + output->Insert( v ); + + } // rof + in.close( ); +} + +#endif // __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__ + +// eof - $RCSfile$