X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FIO%2FMinimumSpanningTreeWriter.hxx;fp=lib%2Ffpa%2FIO%2FMinimumSpanningTreeWriter.hxx;h=f9b8533b264691b3808dd598c7e848ea169513b2;hb=b4ed6ddfa7e90e892f07cad9a760961bd4e84e6b;hp=0000000000000000000000000000000000000000;hpb=5e326afe442245572b6c3ec98ebeec8b45f9012f;p=FrontAlgorithms.git diff --git a/lib/fpa/IO/MinimumSpanningTreeWriter.hxx b/lib/fpa/IO/MinimumSpanningTreeWriter.hxx new file mode 100644 index 0000000..f9b8533 --- /dev/null +++ b/lib/fpa/IO/MinimumSpanningTreeWriter.hxx @@ -0,0 +1,118 @@ +#ifndef __FPA__IO__MINIMUMSPANNINGTREEWRITER__HXX__ +#define __FPA__IO__MINIMUMSPANNINGTREEWRITER__HXX__ + +#include +#include + +// ------------------------------------------------------------------------- +template< class T > +void fpa::IO::MinimumSpanningTreeWriter< T >:: +SetInput( const T* input ) +{ + this->itk::ProcessObject::SetNthInput( 0, const_cast< T* >( input ) ); +} + +// ------------------------------------------------------------------------- +template< class T > +T* fpa::IO::MinimumSpanningTreeWriter< T >:: +GetInput( ) +{ + return( dynamic_cast< T* >( this->itk::ProcessObject::GetInput( 0 ) ) ); +} + +// ------------------------------------------------------------------------- +template< class T > +const T* fpa::IO::MinimumSpanningTreeWriter< T >:: +GetInput( ) const +{ + return( + dynamic_cast< const T* >( this->itk::ProcessObject::GetInput( 0 ) ) + ); +} + +// ------------------------------------------------------------------------- +template< class T > +void fpa::IO::MinimumSpanningTreeWriter< T >:: +Update( ) +{ + T* input = this->GetInput( ); + if( input != NULL ) + { + input->UpdateOutputInformation( ); + input->UpdateOutputData( ); + this->GenerateData( ); + this->ReleaseInputs( ); + + } // fi +} + +// ------------------------------------------------------------------------- +template< class T > +fpa::IO::MinimumSpanningTreeWriter< T >:: +MinimumSpanningTreeWriter( ) + : Superclass( ), + m_FileName( "" ) +{ + this->SetNumberOfRequiredInputs( 1 ); +} + +// ------------------------------------------------------------------------- +template< class T > +fpa::IO::MinimumSpanningTreeWriter< T >:: +~MinimumSpanningTreeWriter( ) +{ +} + +// ------------------------------------------------------------------------- +template< class T > +void fpa::IO::MinimumSpanningTreeWriter< 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::TVertex::Dimension << std::endl; + + const typename T::TCollisions& collisions = input->GetCollisions( ); + unsigned long nSeeds = collisions.size( ); + out << nSeeds << std::endl; + for( unsigned long i = 0; i < nSeeds; ++i ) + { + for( unsigned long j = 0; j < nSeeds; ++j ) + out << collisions[ i ][ j ].second << " "; + out << std::endl; + + } // rof + + 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::TVertex::Dimension; ++d ) + out << iIt->first[ d ] << " "; + for( unsigned int d = 0; d < T::TVertex::Dimension; ++d ) + out << iIt->second.first[ d ] << " "; + out << iIt->second.second << std::endl; + + } // rof + out.close( ); +} + +#endif // __FPA__IO__MINIMUMSPANNINGTREEWRITER__HXX__ + +// eof - $RCSfile$