X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FCommon%2FImage%2FPathWriter.hxx;fp=lib%2Ffpa%2FCommon%2FImage%2FPathWriter.hxx;h=fc3d840a82f5381fc6d55d056e87cd1ecdae4261;hb=bd89a1af0c14ed2ac0afeca923103de54283cbaf;hp=0000000000000000000000000000000000000000;hpb=a8ac405fe1422bc0792a810f7f0693096a22c20e;p=FrontAlgorithms.git diff --git a/lib/fpa/Common/Image/PathWriter.hxx b/lib/fpa/Common/Image/PathWriter.hxx new file mode 100644 index 0000000..fc3d840 --- /dev/null +++ b/lib/fpa/Common/Image/PathWriter.hxx @@ -0,0 +1,111 @@ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= +#ifndef __fpa__Common__Image__PathWriter__hxx__ +#define __fpa__Common__Image__PathWriter__hxx__ + +#include + +// ------------------------------------------------------------------------- +template< class _TPath > +const _TPath* fpa::Common::Image::PathWriter< _TPath >:: +GetInput( ) const +{ + return( + dynamic_cast< const TPath* >( + this->itk::ProcessObject::GetInput( 0 ) + ) + ); +} + +// ------------------------------------------------------------------------- +template< class _TPath > +void fpa::Common::Image::PathWriter< _TPath >:: +SetInput( const _TPath* path ) +{ + this->itk::ProcessObject::SetNthInput( 0, const_cast< TPath* >( path ) ); +} + +// ------------------------------------------------------------------------- +template< class _TPath > +void fpa::Common::Image::PathWriter< _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::PathWriter< _TPath >:: +PathWriter( ) + : Superclass( ), + m_FileName( "" ) +{ + this->SetNumberOfRequiredInputs( 1 ); +} + +// ------------------------------------------------------------------------- +template< class _TPath > +fpa::Common::Image::PathWriter< _TPath >:: +~PathWriter( ) +{ +} + +// ------------------------------------------------------------------------- +template< class _TPath > +void fpa::Common::Image::PathWriter< _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__PathWriter__hxx__ + +// eof - $RCSfile$