1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Image__SkeletonReader__hxx__
7 #define __fpa__Image__SkeletonReader__hxx__
9 // -------------------------------------------------------------------------
10 template< class _TSkeleton >
11 _TSkeleton* fpa::Image::SkeletonReader< _TSkeleton >::
15 itkDynamicCastInDebugMode< TSkeleton* >( this->GetPrimaryOutput( ) )
19 // -------------------------------------------------------------------------
20 template< class _TSkeleton >
21 _TSkeleton* fpa::Image::SkeletonReader< _TSkeleton >::
22 GetOutput( unsigned int i )
25 itkDynamicCastInDebugMode< TSkeleton* >(
26 this->itk::ProcessObject::GetOutput( i )
31 // -------------------------------------------------------------------------
32 template< class _TSkeleton >
33 void fpa::Image::SkeletonReader< _TSkeleton >::
34 GraftOutput( itk::DataObject* out )
36 this->GraftNthOutput( 0, out );
39 // -------------------------------------------------------------------------
40 template< class _TSkeleton >
41 void fpa::Image::SkeletonReader< _TSkeleton >::
43 const typename Superclass::DataObjectIdentifierType& key,
50 << "Requested to graft output that is a NULL pointer"
54 itk::DataObject* output = this->itk::ProcessObject::GetOutput( key );
58 // -------------------------------------------------------------------------
59 template< class _TSkeleton >
60 void fpa::Image::SkeletonReader< _TSkeleton >::
61 GraftNthOutput( unsigned int i, itk::DataObject* out )
63 if( i >= this->GetNumberOfIndexedOutputs( ) )
66 << "Requested to graft output " << i
67 << " but this filter only has "
68 << this->GetNumberOfIndexedOutputs( )
69 << " indexed Outputs."
73 this->GraftOutput( this->MakeNameFromOutputIndex( i ), out );
76 // -------------------------------------------------------------------------
77 template< class _TSkeleton >
78 itk::DataObject::Pointer
79 fpa::Image::SkeletonReader< _TSkeleton >::
80 MakeOutput( itk::ProcessObject::DataObjectPointerArraySizeType i )
82 return( TSkeleton::New( ).GetPointer( ) );
85 // -------------------------------------------------------------------------
86 template< class _TSkeleton >
87 fpa::Image::SkeletonReader< _TSkeleton >::
91 typename TSkeleton::Pointer out =
92 static_cast< TSkeleton* >( this->MakeOutput( 0 ).GetPointer( ) );
93 this->itk::ProcessObject::SetNumberOfRequiredInputs( 0 );
94 this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 );
95 this->itk::ProcessObject::SetNthOutput( 0, out.GetPointer( ) );
98 // -------------------------------------------------------------------------
99 template< class _TSkeleton >
100 fpa::Image::SkeletonReader< _TSkeleton >::
105 // -------------------------------------------------------------------------
106 template< class _TSkeleton >
107 void fpa::Image::SkeletonReader< _TSkeleton >::
110 typedef typename TSkeleton::TPath _TPath;
111 typedef typename _TPath::TIndex _TIndex;
112 typedef typename _TPath::TSpacing _TSpacing;
113 typedef typename _TPath::TPoint _TPoint;
114 typedef typename _TPath::TDirection _TDirection;
117 std::ifstream file_stream( this->m_FileName.c_str( ) );
121 << "Error reading skeleton from \"" << this->m_FileName << "\""
126 file_stream.seekg( 0, std::ios::end );
127 buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) );
128 file_stream.seekg( 0, std::ios::beg );
130 ( std::istreambuf_iterator< char >( file_stream ) ),
131 std::istreambuf_iterator< char >( )
133 file_stream.close( );
135 std::istringstream in( buffer );
138 if( dim != TSkeleton::Dimension )
141 << "Mismatched skeletons dimension: " << dim
142 << " != " << TSkeleton::Dimension
148 // Read spatial parameters
152 for( unsigned int d = 0; d < dim; ++d )
154 for( unsigned int d = 0; d < dim; ++d )
155 for( unsigned int e = 0; e < dim; ++e )
157 for( unsigned int d = 0; d < dim; ++d )
160 // Read end-points, just to ignore
163 for( unsigned int i = 0; i < n; ++i )
166 for( unsigned int d = 0; d < dim; ++d )
171 // Read bifurcations, just to ignore
173 for( unsigned int i = 0; i < n; ++i )
176 for( unsigned int d = 0; d < dim; ++d )
182 TSkeleton* out = this->GetOutput( );
185 for( unsigned int p = 0; p < nPaths; ++p )
187 typename _TPath::Pointer path = _TPath::New( );
188 path->SetSpacing( spa );
189 path->SetOrigin( ori );
190 path->SetDirection( dir );
192 unsigned long pathSize;
194 for( unsigned long id = 0; id < pathSize; ++id )
197 for( unsigned int d = 0; d < dim; ++d )
199 path->AddVertex( idx );
202 out->AddBranch( path );
207 #endif // __fpa__Image__SkeletonReader__hxx__