1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__Common__Image__PathReader__hxx__
6 #define __fpa__Common__Image__PathReader__hxx__
8 // -------------------------------------------------------------------------
9 template< class _TPath >
10 _TPath* fpa::Common::Image::PathReader< _TPath >::
14 itkDynamicCastInDebugMode< TPath* >( this->GetPrimaryOutput( ) )
18 // -------------------------------------------------------------------------
19 template< class _TPath >
20 _TPath* fpa::Common::Image::PathReader< _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::PathReader< _TPath >::
33 GraftOutput( itk::DataObject* out )
35 this->GraftNthOutput( 0, out );
38 // -------------------------------------------------------------------------
39 template< class _TPath >
40 void fpa::Common::Image::PathReader< _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::PathReader< _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 fpa::Common::Image::PathReader< _TPath >::
78 MakeOutput( itk::ProcessObject::DataObjectPointerArraySizeType i )
80 return( TPath::New( ).GetPointer( ) );
83 // -------------------------------------------------------------------------
84 template< class _TPath >
85 fpa::Common::Image::PathReader< _TPath >::
89 typename TPath::Pointer out =
90 static_cast< TPath* >( this->MakeOutput( 0 ).GetPointer( ) );
91 this->itk::ProcessObject::SetNumberOfRequiredInputs( 0 );
92 this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 );
93 this->itk::ProcessObject::SetNthOutput( 0, out.GetPointer( ) );
96 // -------------------------------------------------------------------------
97 template< class _TPath >
98 fpa::Common::Image::PathReader< _TPath >::
103 // -------------------------------------------------------------------------
104 template< class _TPath >
105 void fpa::Common::Image::PathReader< _TPath >::
109 std::ifstream file_stream( this->m_FileName.c_str( ) );
113 << "Error reading skeleton from \"" << this->m_FileName << "\""
118 file_stream.seekg( 0, std::ios::end );
119 buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
120 file_stream.seekg( 0, std::ios::beg );
122 ( std::istreambuf_iterator< char >( file_stream ) ),
123 std::istreambuf_iterator< char >( )
125 file_stream.close( );
127 std::istringstream in( buffer );
130 if( dim != TPath::Dimension )
133 << "Mismatched path dimension: " << dim
134 << " != " << TPath::Dimension
140 // Read spatial parameters
141 typename TPath::TSpacing spa;
142 typename TPath::TDirection dir;
143 typename TPath::TPoint ori;
144 for( unsigned int d = 0; d < dim; ++d )
146 for( unsigned int d = 0; d < dim; ++d )
147 for( unsigned int e = 0; e < dim; ++e )
149 for( unsigned int d = 0; d < dim; ++d )
153 TPath* path = this->GetOutput( );
154 path->SetSpacing( spa );
155 path->SetOrigin( ori );
156 path->SetDirection( dir );
158 unsigned long pathSize;
160 for( unsigned long id = 0; id < pathSize; ++id )
162 typename TPath::TIndex idx;
163 for( unsigned int d = 0; d < dim; ++d )
165 path->AddVertex( idx );
170 #endif // __fpa__Common__Image__PathReader__hxx__