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, class _TImage >
12 void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
13 SetInput( const _TPolyLine* input )
15 this->itk::ProcessObject::SetNthInput(
16 0, const_cast< _TPolyLine* >( input )
20 // -------------------------------------------------------------------------
21 template< class _TPolyLine, class _TImage >
23 cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
27 dynamic_cast< const _TPolyLine* >(
28 this->itk::ProcessObject::GetInput( 0 )
33 // -------------------------------------------------------------------------
34 template< class _TPolyLine, class _TImage >
35 void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
36 SetImage( const _TImage* image )
38 this->itk::ProcessObject::SetNthInput(
39 1, const_cast< _TImage* >( image )
43 // -------------------------------------------------------------------------
44 template< class _TPolyLine, class _TImage >
45 const _TImage* cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
49 dynamic_cast< const _TImage* >(
50 this->itk::ProcessObject::GetInput( 1 )
55 // -------------------------------------------------------------------------
56 template< class _TPolyLine, class _TImage >
57 void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
60 _TPolyLine* input = const_cast< _TPolyLine* >( this->GetInput( ) );
63 input->UpdateOutputInformation( );
64 input->UpdateOutputData( );
65 this->GenerateData( );
66 this->ReleaseInputs( );
71 // -------------------------------------------------------------------------
72 template< class _TPolyLine, class _TImage >
73 cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
74 PolyLineParametricPathWriter( )
77 m_NumberOfPoints( 100 )
79 this->SetNumberOfRequiredInputs( 1 );
82 // -------------------------------------------------------------------------
83 template< class _TPolyLine, class _TImage >
84 cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
85 ~PolyLineParametricPathWriter( )
89 // -------------------------------------------------------------------------
90 template< class _TPolyLine, class _TImage >
91 void cpExtensions::Algorithms::PolyLineParametricPathWriter< _TPolyLine, _TImage >::
94 typedef typename _TPolyLine::TContinuousIndex _TContinuousIndex;
97 const _TPolyLine* input = this->GetInput( );
98 const _TImage* image = this->GetImage( );
99 unsigned int dim = _TPolyLine::PathDimension;
100 std::stringstream buffer;
101 long step = input->GetSize( ) / this->m_NumberOfPoints;
103 for( unsigned long i = 0; i < input->GetSize( ); i += step )
105 _TContinuousIndex idx;
108 for( long j = -step; j <= step; ++j )
111 if( k >= 0 && k < input->GetSize( ) )
113 _TContinuousIndex kdx = input->GetContinuousVertex( k );
114 for( unsigned int d = 0; d < dim; ++d )
115 idx[ d ] += kdx[ d ];
122 for( unsigned int d = 0; d < dim; ++d )
126 for( unsigned int d = 1; d < dim; ++d )
127 buffer << " " << idx[ d ];
130 typename _TImage::PointType pidx;
131 typename _TImage::IndexType iidx;
132 image->TransformContinuousIndexToPhysicalPoint( idx, pidx );
133 image->TransformPhysicalPointToIndex( pidx, iidx );
134 buffer << " " << image->GetPixel( iidx );
142 std::ofstream file_stream(
143 this->m_FileName.c_str( ), std::ofstream::binary
148 << "Could not open file \"" << this->m_FileName << "\" to write a "
149 << "cpExtensions::DataStructures::PolyLineParametricPath< " << dim
155 file_stream.write( buffer.str( ).c_str( ), buffer.str( ).size( ) );
158 #endif // __cpExtensions__Algorithms__PolyLineParametricPathWriter__hxx__