#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$