1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __cpExtensions__Algorithms__PolyLineParametricPathWriter__hxx__
6 #define __cpExtensions__Algorithms__PolyLineParametricPathWriter__hxx__
10 // -------------------------------------------------------------------------
11 template< class _TPolyLine >
12 void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >::
13 SetInput( const _TPolyLine* input )
15 this->itk::ProcessObject::SetNthInput(
16 0, const_cast< _TPolyLine* >( input )
20 // -------------------------------------------------------------------------
21 template< class _TPolyLine >
23 cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >::
27 dynamic_cast< const _TPolyLine* >(
28 this->itk::ProcessObject::GetInput( 0 )
33 // -------------------------------------------------------------------------
34 template< class _TPolyLine >
35 void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >::
38 _TPolyLine* input = const_cast< _TPolyLine* >( this->GetInput( ) );
41 input->UpdateOutputInformation( );
42 input->UpdateOutputData( );
43 this->GenerateData( );
44 this->ReleaseInputs( );
49 // -------------------------------------------------------------------------
50 template< class _TPolyLine >
51 cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >::
52 PolyLineParametricPathWriter( )
55 m_NumberOfPoints( 100 )
57 this->SetNumberOfRequiredInputs( 1 );
60 // -------------------------------------------------------------------------
61 template< class _TPolyLine >
62 cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >::
63 ~PolyLineParametricPathWriter( )
67 // -------------------------------------------------------------------------
68 template< class _TPolyLine >
69 void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine >::
72 typedef typename _TPolyLine::TContinuousIndex _TContinuousIndex;
75 const _TPolyLine* input = this->GetInput( );
76 unsigned int dim = _TPolyLine::PathDimension;
77 std::stringstream buffer;
78 long step = input->GetSize( ) / this->m_NumberOfPoints;
80 for( unsigned long i = 0; i < input->GetSize( ); i += step )
82 _TContinuousIndex idx;
85 for( long j = -step; j <= step; ++j )
88 if( k >= 0 && k < input->GetSize( ) )
90 _TContinuousIndex kdx = input->GetContinuousVertex( k );
91 for( unsigned int d = 0; d < dim; ++d )
99 for( unsigned int d = 0; d < dim; ++d )
103 for( unsigned int d = 1; d < dim; ++d )
104 buffer << " " << idx[ d ];
110 std::ofstream file_stream(
111 this->m_FileName.c_str( ), std::ofstream::binary
116 << "Could not open file \"" << this->m_FileName << "\" to write a "
117 << "cpExtensions::DataStructures::PolyLineParametricPath< " << dim
123 file_stream.write( buffer.str( ).c_str( ), buffer.str( ).size( ) );
126 #endif // __cpExtensions__Algorithms__PolyLineParametricPathWriter__hxx__