// ========================================================================= // @author Leonardo Florez Valencia // @email florez-l@javeriana.edu.co // ========================================================================= #ifndef __fpa__Common__Image__PolyLineParametricPathWriter__hxx__ #define __fpa__Common__Image__PolyLineParametricPathWriter__hxx__ #include // ------------------------------------------------------------------------- template< class _TPath > const _TPath* fpa::Common::Image::PolyLineParametricPathWriter< _TPath >:: GetInput( ) const { return( dynamic_cast< const TPath* >( this->itk::ProcessObject::GetInput( 0 ) ) ); } // ------------------------------------------------------------------------- template< class _TPath > void fpa::Common::Image::PolyLineParametricPathWriter< _TPath >:: SetInput( const _TPath* path ) { this->itk::ProcessObject::SetNthInput( 0, const_cast< TPath* >( path ) ); } // ------------------------------------------------------------------------- template< class _TPath > void fpa::Common::Image::PolyLineParametricPathWriter< _TPath >:: Update( ) { TPath* input = const_cast< TPath* >( this->GetInput( ) ); if( input != NULL ) { input->UpdateOutputInformation( ); input->UpdateOutputData( ); this->GenerateData( ); this->ReleaseInputs( ); } // fi } // ------------------------------------------------------------------------- template< class _TPath > fpa::Common::Image::PolyLineParametricPathWriter< _TPath >:: PolyLineParametricPathWriter( ) : Superclass( ), m_FileName( "" ) { this->SetNumberOfRequiredInputs( 1 ); } // ------------------------------------------------------------------------- template< class _TPath > fpa::Common::Image::PolyLineParametricPathWriter< _TPath >:: ~PolyLineParametricPathWriter( ) { } // ------------------------------------------------------------------------- template< class _TPath > void fpa::Common::Image::PolyLineParametricPathWriter< _TPath >:: GenerateData( ) { const TPath* path = this->GetInput( ); // Write base information std::stringstream out1, out2; out1 << TPath::Dimension << std::endl; typename TPath::TSpacing spa = path->GetSpacing( ); for( unsigned int d = 0; d < TPath::Dimension; ++d ) out1 << spa[ d ] << " "; out1 << std::endl; typename TPath::TDirection dir = path->GetDirection( ); for( unsigned int d = 0; d < TPath::Dimension; ++d ) for( unsigned int e = 0; e < TPath::Dimension; ++e ) out1 << dir[ d ][ e ] << " "; out1 << std::endl; typename TPath::TPoint ori = path->GetOrigin( ); for( unsigned int d = 0; d < TPath::Dimension; ++d ) out1 << ori[ d ] << " "; out1 << std::endl; // Write path unsigned int size = path->GetSize( ); out2 << size << std::endl; for( unsigned int i = 0; i < path->GetSize( ); ++i ) { typename TPath::TIndex v = path->GetVertex( i ); for( unsigned int d = 0; d < TPath::Dimension; ++d ) out2 << v[ d ] << " "; } // rof // Real write std::ofstream file_stream( this->m_FileName.c_str( ), std::ofstream::binary ); if( !file_stream ) itkExceptionMacro( << "Unable to write skeleton to \"" << this->m_FileName << "\"" ); file_stream.write( out1.str( ).c_str( ), out1.str( ).size( ) ); } #endif // __fpa__Common__Image__PolyLineParametricPathWriter__hxx__ // eof - $RCSfile$