// ========================================================================= // @author Leonardo Florez Valencia // @email florez-l@javeriana.edu.co // ========================================================================= #ifndef __fpa__Common__Image__PolyLineParametricPathReader__hxx__ #define __fpa__Common__Image__PolyLineParametricPathReader__hxx__ // ------------------------------------------------------------------------- template< class _TPath > _TPath* fpa::Common::Image::PolyLineParametricPathReader< _TPath >:: GetOutput( ) { return( itkDynamicCastInDebugMode< TPath* >( this->GetPrimaryOutput( ) ) ); } // ------------------------------------------------------------------------- template< class _TPath > _TPath* fpa::Common::Image::PolyLineParametricPathReader< _TPath >:: GetOutput( unsigned int i ) { return( itkDynamicCastInDebugMode< TPath* >( this->itk::ProcessObject::GetOutput( i ) ) ); } // ------------------------------------------------------------------------- template< class _TPath > void fpa::Common::Image::PolyLineParametricPathReader< _TPath >:: GraftOutput( itk::DataObject* out ) { this->GraftNthOutput( 0, out ); } // ------------------------------------------------------------------------- template< class _TPath > void fpa::Common::Image::PolyLineParametricPathReader< _TPath >:: GraftOutput( const typename Superclass::DataObjectIdentifierType& key, itk::DataObject* out ) { if( out == NULL ) { itkExceptionMacro( << "Requested to graft output that is a NULL pointer" ); } // fi itk::DataObject* output = this->itk::ProcessObject::GetOutput( key ); output->Graft( out ); } // ------------------------------------------------------------------------- template< class _TPath > void fpa::Common::Image::PolyLineParametricPathReader< _TPath >:: GraftNthOutput( unsigned int i, itk::DataObject* out ) { if( i >= this->GetNumberOfIndexedOutputs( ) ) { itkExceptionMacro( << "Requested to graft output " << i << " but this filter only has " << this->GetNumberOfIndexedOutputs( ) << " indexed Outputs." ); } // fi this->GraftOutput( this->MakeNameFromOutputIndex( i ), out ); } // ------------------------------------------------------------------------- template< class _TPath > itk::DataObject::Pointer fpa::Common::Image::PolyLineParametricPathReader< _TPath >:: MakeOutput( itk::ProcessObject::DataObjectPointerArraySizeType i ) { return( TPath::New( ).GetPointer( ) ); } // ------------------------------------------------------------------------- template< class _TPath > fpa::Common::Image::PolyLineParametricPathReader< _TPath >:: PolyLineParametricPathReader( ) : Superclass( ) { typename TPath::Pointer out = static_cast< TPath* >( this->MakeOutput( 0 ).GetPointer( ) ); this->itk::ProcessObject::SetNumberOfRequiredInputs( 0 ); this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 ); this->itk::ProcessObject::SetNthOutput( 0, out.GetPointer( ) ); } // ------------------------------------------------------------------------- template< class _TPath > fpa::Common::Image::PolyLineParametricPathReader< _TPath >:: ~PolyLineParametricPathReader( ) { } // ------------------------------------------------------------------------- template< class _TPath > void fpa::Common::Image::PolyLineParametricPathReader< _TPath >:: GenerateData( ) { std::string buffer; std::ifstream file_stream( this->m_FileName.c_str( ) ); if( !file_stream ) { itkExceptionMacro( << "Error reading skeleton from \"" << this->m_FileName << "\"" ); return; } // fi file_stream.seekg( 0, std::ios::end ); buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) ); file_stream.seekg( 0, std::ios::beg ); buffer.assign( ( std::istreambuf_iterator< char >( file_stream ) ), std::istreambuf_iterator< char >( ) ); file_stream.close( ); std::istringstream in( buffer ); unsigned int dim; in >> dim; if( dim != TPath::Dimension ) { itkExceptionMacro( << "Mismatched path dimension: " << dim << " != " << TPath::Dimension ); return; } // fi // Read spatial parameters typename TPath::TSpacing spa; typename TPath::TDirection dir; typename TPath::TPoint ori; for( unsigned int d = 0; d < dim; ++d ) in >> spa[ d ]; for( unsigned int d = 0; d < dim; ++d ) for( unsigned int e = 0; e < dim; ++e ) in >> dir[ d ][ e ]; for( unsigned int d = 0; d < dim; ++d ) in >> ori[ d ]; // Read path TPath* path = this->GetOutput( ); path->SetSpacing( spa ); path->SetOrigin( ori ); path->SetDirection( dir ); unsigned long pathSize; in >> pathSize; for( unsigned long id = 0; id < pathSize; ++id ) { typename TPath::TIndex idx; for( unsigned int d = 0; d < dim; ++d ) in >> idx[ d ]; path->AddVertex( idx ); } // rof } #endif // __fpa__Common__Image__PolyLineParametricPathReader__hxx__ // eof - $RCSfile$