1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Common__Image__PolyLineParametricPathReader__hxx__
6 #define __fpa__Common__Image__PolyLineParametricPathReader__hxx__
8 // -------------------------------------------------------------------------
9 template< class _TPath >
10 _TPath* fpa::Common::Image::PolyLineParametricPathReader< _TPath >::
14 itkDynamicCastInDebugMode< TPath* >( this->GetPrimaryOutput( ) )
18 // -------------------------------------------------------------------------
19 template< class _TPath >
20 _TPath* fpa::Common::Image::PolyLineParametricPathReader< _TPath >::
21 GetOutput( unsigned int i )
24 itkDynamicCastInDebugMode< TPath* >(
25 this->itk::ProcessObject::GetOutput( i )
30 // -------------------------------------------------------------------------
31 template< class _TPath >
32 void fpa::Common::Image::PolyLineParametricPathReader< _TPath >::
33 GraftOutput( itk::DataObject* out )
35 this->GraftNthOutput( 0, out );
38 // -------------------------------------------------------------------------
39 template< class _TPath >
40 void fpa::Common::Image::PolyLineParametricPathReader< _TPath >::
42 const typename Superclass::DataObjectIdentifierType& key,
49 << "Requested to graft output that is a NULL pointer"
53 itk::DataObject* output = this->itk::ProcessObject::GetOutput( key );
57 // -------------------------------------------------------------------------
58 template< class _TPath >
59 void fpa::Common::Image::PolyLineParametricPathReader< _TPath >::
60 GraftNthOutput( unsigned int i, itk::DataObject* out )
62 if( i >= this->GetNumberOfIndexedOutputs( ) )
65 << "Requested to graft output " << i
66 << " but this filter only has "
67 << this->GetNumberOfIndexedOutputs( )
68 << " indexed Outputs."
72 this->GraftOutput( this->MakeNameFromOutputIndex( i ), out );
75 // -------------------------------------------------------------------------
76 template< class _TPath >
77 itk::DataObject::Pointer
78 fpa::Common::Image::PolyLineParametricPathReader< _TPath >::
79 MakeOutput( itk::ProcessObject::DataObjectPointerArraySizeType i )
81 return( TPath::New( ).GetPointer( ) );
84 // -------------------------------------------------------------------------
85 template< class _TPath >
86 fpa::Common::Image::PolyLineParametricPathReader< _TPath >::
87 PolyLineParametricPathReader( )
90 typename TPath::Pointer out =
91 static_cast< TPath* >( this->MakeOutput( 0 ).GetPointer( ) );
92 this->itk::ProcessObject::SetNumberOfRequiredInputs( 0 );
93 this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 );
94 this->itk::ProcessObject::SetNthOutput( 0, out.GetPointer( ) );
97 // -------------------------------------------------------------------------
98 template< class _TPath >
99 fpa::Common::Image::PolyLineParametricPathReader< _TPath >::
100 ~PolyLineParametricPathReader( )
104 // -------------------------------------------------------------------------
105 template< class _TPath >
106 void fpa::Common::Image::PolyLineParametricPathReader< _TPath >::
110 std::ifstream file_stream( this->m_FileName.c_str( ) );
114 << "Error reading skeleton from \"" << this->m_FileName << "\""
119 file_stream.seekg( 0, std::ios::end );
120 buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
121 file_stream.seekg( 0, std::ios::beg );
123 ( std::istreambuf_iterator< char >( file_stream ) ),
124 std::istreambuf_iterator< char >( )
126 file_stream.close( );
128 std::istringstream in( buffer );
131 if( dim != TPath::Dimension )
134 << "Mismatched path dimension: " << dim
135 << " != " << TPath::Dimension
141 // Read spatial parameters
142 typename TPath::TSpacing spa;
143 typename TPath::TDirection dir;
144 typename TPath::TPoint ori;
145 for( unsigned int d = 0; d < dim; ++d )
147 for( unsigned int d = 0; d < dim; ++d )
148 for( unsigned int e = 0; e < dim; ++e )
150 for( unsigned int d = 0; d < dim; ++d )
154 TPath* path = this->GetOutput( );
155 path->SetSpacing( spa );
156 path->SetOrigin( ori );
157 path->SetDirection( dir );
159 unsigned long pathSize;
161 for( unsigned long id = 0; id < pathSize; ++id )
163 typename TPath::TIndex idx;
164 for( unsigned int d = 0; d < dim; ++d )
166 path->AddVertex( idx );
171 #endif // __fpa__Common__Image__PolyLineParametricPathReader__hxx__