1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __cpExtensions__Algorithms__SkeletonReader__hxx__
6 #define __cpExtensions__Algorithms__SkeletonReader__hxx__
8 // -------------------------------------------------------------------------
9 template< class _TSkeleton >
10 _TSkeleton* cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
14 itkDynamicCastInDebugMode< TSkeleton* >( this->GetPrimaryOutput( ) )
18 // -------------------------------------------------------------------------
19 template< class _TSkeleton >
20 _TSkeleton* cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
21 GetOutput( unsigned int i )
24 itkDynamicCastInDebugMode< TSkeleton* >(
25 this->itk::ProcessObject::GetOutput( i )
30 // -------------------------------------------------------------------------
31 template< class _TSkeleton >
32 void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
33 GraftOutput( itk::DataObject* out )
35 this->GraftNthOutput( 0, out );
38 // -------------------------------------------------------------------------
39 template< class _TSkeleton >
40 void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
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 _TSkeleton >
59 void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
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 _TSkeleton >
77 itk::DataObject::Pointer
78 cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
79 MakeOutput( itk::ProcessObject::DataObjectPointerArraySizeType i )
81 return( TSkeleton::New( ).GetPointer( ) );
84 // -------------------------------------------------------------------------
85 template< class _TSkeleton >
86 cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
90 typename TSkeleton::Pointer out =
91 static_cast< TSkeleton* >( 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 _TSkeleton >
99 cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
104 // -------------------------------------------------------------------------
105 template< class _TSkeleton >
106 void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
109 typedef typename TSkeleton::TPath _TPath;
110 typedef typename _TPath::TSpacing _TSpacing;
111 typedef typename _TPath::TPoint _TPoint;
112 typedef typename _TPath::TDirection _TDirection;
113 typedef typename _TPath::TContinuousIndex _TContinuousIndex;
117 if( !( cpExtensions::Read( buffer, this->m_FileName ) ) )
120 << "Error reading skeleton from \"" << this->m_FileName << "\""
127 std::istringstream in( buffer );
130 if( dim != TSkeleton::Dimension )
133 << "Mismatched skeletons dimension: " << dim
134 << " != " << TSkeleton::Dimension
140 TSkeleton* out = this->GetOutput( );
148 for( unsigned int d = 0; d < dim; ++d )
150 for( unsigned int d = 0; d < dim; ++d )
152 for( unsigned int d = 0; d < dim; ++d )
153 for( unsigned int e = 0; e < dim; ++e )
156 typename _TPath::Pointer path = _TPath::New( );
157 path->SetSpacing( spa );
158 path->SetOrigin( ori );
159 path->SetDirection( dir );
160 for( unsigned long s = 0; s < size; ++s )
162 _TContinuousIndex idx;
163 for( unsigned int d = 0; d < dim; ++d )
165 path->AddVertex( idx );
168 out->AddBranch( path );
174 #endif // __cpExtensions__Algorithms__SkeletonReader__hxx__