+++ /dev/null
-// -------------------------------------------------------------------------
-// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
-// -------------------------------------------------------------------------
-
-#ifndef __cpExtensions__Algorithms__PolyLineParametricPathWriter__hxx__
-#define __cpExtensions__Algorithms__PolyLineParametricPathWriter__hxx__
-
-#include <sstream>
-
-// -------------------------------------------------------------------------
-template< class _TPolyLine, class _TImage >
-void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
-SetInput( const _TPolyLine* input )
-{
- this->itk::ProcessObject::SetNthInput(
- 0, const_cast< _TPolyLine* >( input )
- );
-}
-
-// -------------------------------------------------------------------------
-template< class _TPolyLine, class _TImage >
-const _TPolyLine*
-cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
-GetInput( )
-{
- return(
- dynamic_cast< const _TPolyLine* >(
- this->itk::ProcessObject::GetInput( 0 )
- )
- );
-}
-
-// -------------------------------------------------------------------------
-template< class _TPolyLine, class _TImage >
-void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
-SetImage( const _TImage* image )
-{
- this->itk::ProcessObject::SetNthInput(
- 1, const_cast< _TImage* >( image )
- );
-}
-
-// -------------------------------------------------------------------------
-template< class _TPolyLine, class _TImage >
-const _TImage* cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
-GetImage( )
-{
- return(
- dynamic_cast< const _TImage* >(
- this->itk::ProcessObject::GetInput( 1 )
- )
- );
-}
-
-// -------------------------------------------------------------------------
-template< class _TPolyLine, class _TImage >
-void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
-Update( )
-{
- _TPolyLine* input = const_cast< _TPolyLine* >( this->GetInput( ) );
- if( input != NULL )
- {
- input->UpdateOutputInformation( );
- input->UpdateOutputData( );
- this->GenerateData( );
- this->ReleaseInputs( );
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-template< class _TPolyLine, class _TImage >
-cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
-PolyLineParametricPathWriter( )
- : Superclass( ),
- m_FileName( "" ),
- m_NumberOfPoints( 100 )
-{
- this->SetNumberOfRequiredInputs( 1 );
-}
-
-// -------------------------------------------------------------------------
-template< class _TPolyLine, class _TImage >
-cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
-~PolyLineParametricPathWriter( )
-{
-}
-
-// -------------------------------------------------------------------------
-template< class _TPolyLine, class _TImage >
-void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
-GenerateData( )
-{
- typedef typename _TPolyLine::TContinuousIndex _TContinuousIndex;
-
- // "Serialize" data
- const _TPolyLine* input = this->GetInput( );
- const _TImage* image = this->GetImage( );
- unsigned int dim = _TPolyLine::PathDimension;
- std::stringstream buffer;
- long step = input->GetSize( ) / this->m_NumberOfPoints;
-
- for( unsigned long i = 0; i < input->GetSize( ); i += step )
- {
- _TContinuousIndex idx;
- idx.Fill( 0 );
- int c = 0;
- for( long j = -step; j <= step; ++j )
- {
- long k = i + j;
- if( k >= 0 && k < input->GetSize( ) )
- {
- _TContinuousIndex kdx = input->GetContinuousVertex( k );
- for( unsigned int d = 0; d < dim; ++d )
- idx[ d ] += kdx[ d ];
- c++;
-
- } // fi
-
- } // rof
- if( c != 0 )
- for( unsigned int d = 0; d < dim; ++d )
- idx[ d ] /= c;
-
- buffer << idx[ 0 ];
- for( unsigned int d = 1; d < dim; ++d )
- buffer << " " << idx[ d ];
- if( image != NULL )
- {
- typename _TImage::PointType pidx;
- typename _TImage::IndexType iidx;
- image->TransformContinuousIndexToPhysicalPoint( idx, pidx );
- image->TransformPhysicalPointToIndex( pidx, iidx );
- buffer << " " << image->GetPixel( iidx );
-
- } // fi
- buffer << std::endl;
-
- } // rof
-
- // Real write
- std::ofstream file_stream(
- this->m_FileName.c_str( ), std::ofstream::binary
- );
- if( !file_stream )
- {
- itkExceptionMacro(
- << "Could not open file \"" << this->m_FileName << "\" to write a "
- << "cpExtensions::DataStructures::PolyLineParametricPath< " << dim
- << " > object."
- );
- return;
-
- } // fi
- file_stream.write( buffer.str( ).c_str( ), buffer.str( ).size( ) );
-}
-
-#endif // __cpExtensions__Algorithms__PolyLineParametricPathWriter__hxx__
-
-// eof - $RCSfile$