X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FIO%2FUniqueValuesContainerWriter.hxx;fp=lib%2Ffpa%2FIO%2FUniqueValuesContainerWriter.hxx;h=17eb1d1b2bb541c7ea060aa845172e54f01e0965;hb=b4ed6ddfa7e90e892f07cad9a760961bd4e84e6b;hp=0000000000000000000000000000000000000000;hpb=5e326afe442245572b6c3ec98ebeec8b45f9012f;p=FrontAlgorithms.git diff --git a/lib/fpa/IO/UniqueValuesContainerWriter.hxx b/lib/fpa/IO/UniqueValuesContainerWriter.hxx new file mode 100644 index 0000000..17eb1d1 --- /dev/null +++ b/lib/fpa/IO/UniqueValuesContainerWriter.hxx @@ -0,0 +1,105 @@ +#ifndef __FPA__IO__UNIQUEVALUESCONTAINERWRITER__HXX__ +#define __FPA__IO__UNIQUEVALUESCONTAINERWRITER__HXX__ + +#include +#include + +// ------------------------------------------------------------------------- +template< class T > +void fpa::IO::UniqueValuesContainerWriter< T >:: +SetInput( const T* input ) +{ + this->itk::ProcessObject::SetNthInput( 0, const_cast< T* >( input ) ); +} + +// ------------------------------------------------------------------------- +template< class T > +T* fpa::IO::UniqueValuesContainerWriter< T >:: +GetInput( ) +{ + return( dynamic_cast< T* >( this->itk::ProcessObject::GetInput( 0 ) ) ); +} + +// ------------------------------------------------------------------------- +template< class T > +const T* fpa::IO::UniqueValuesContainerWriter< T >:: +GetInput( ) const +{ + return( + dynamic_cast< const T* >( this->itk::ProcessObject::GetInput( 0 ) ) + ); +} + +// ------------------------------------------------------------------------- +template< class T > +void fpa::IO::UniqueValuesContainerWriter< T >:: +Update( ) +{ + T* input = this->GetInput( ); + if( input != NULL ) + { + input->UpdateOutputInformation( ); + input->UpdateOutputData( ); + this->GenerateData( ); + this->ReleaseInputs( ); + + } // fi +} + +// ------------------------------------------------------------------------- +template< class T > +fpa::IO::UniqueValuesContainerWriter< T >:: +UniqueValuesContainerWriter( ) + : Superclass( ), + m_FileName( "" ) +{ + this->SetNumberOfRequiredInputs( 1 ); +} + +// ------------------------------------------------------------------------- +template< class T > +fpa::IO::UniqueValuesContainerWriter< T >:: +~UniqueValuesContainerWriter( ) +{ +} + +// ------------------------------------------------------------------------- +template< class T > +void fpa::IO::UniqueValuesContainerWriter< T >:: +GenerateData( ) +{ + const T* input = this->GetInput( ); + + std::ofstream out( this->m_FileName.c_str( ) ); + if( !out ) + { + itkExceptionMacro( + << "Error opening file to write a minimum spanning tree: \"" + << this->m_FileName + << "\"" + ); + return; + + } // fi + + out << T::TValue::Dimension << std::endl; + + const typename T::TDecorated& real_input = input->Get( ); + out << real_input.size( ) << std::endl; + for( + typename T::TDecorated::const_iterator iIt = real_input.begin( ); + iIt != real_input.end( ); + ++iIt + ) + { + for( unsigned int d = 0; d < T::TValue::Dimension; ++d ) + out << ( *iIt )[ d ] << " "; + out << std::endl; + + } // rof + out.close( ); +} + +#endif // __FPA__IO__UNIQUEVALUESCONTAINERWRITER__HXX__ + +// eof - $RCSfile$