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 #include <cpExtensions/Utility.h>
10 // -------------------------------------------------------------------------
11 template< class _TSkeleton >
12 _TSkeleton* cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
16 itkDynamicCastInDebugMode< TSkeleton* >( this->GetPrimaryOutput( ) )
20 // -------------------------------------------------------------------------
21 template< class _TSkeleton >
22 _TSkeleton* cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
23 GetOutput( unsigned int i )
26 itkDynamicCastInDebugMode< TSkeleton* >(
27 this->itk::ProcessObject::GetOutput( i )
32 // -------------------------------------------------------------------------
33 template< class _TSkeleton >
34 void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
35 GraftOutput( itk::DataObject* out )
37 this->GraftNthOutput( 0, out );
40 // -------------------------------------------------------------------------
41 template< class _TSkeleton >
42 void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
44 const typename Superclass::DataObjectIdentifierType& key,
51 << "Requested to graft output that is a NULL pointer"
55 itk::DataObject* output = this->itk::ProcessObject::GetOutput( key );
59 // -------------------------------------------------------------------------
60 template< class _TSkeleton >
61 void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
62 GraftNthOutput( unsigned int i, itk::DataObject* out )
64 if( i >= this->GetNumberOfIndexedOutputs( ) )
67 << "Requested to graft output " << i
68 << " but this filter only has "
69 << this->GetNumberOfIndexedOutputs( )
70 << " indexed Outputs."
74 this->GraftOutput( this->MakeNameFromOutputIndex( i ), out );
77 // -------------------------------------------------------------------------
78 template< class _TSkeleton >
79 itk::DataObject::Pointer
80 cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
81 MakeOutput( itk::ProcessObject::DataObjectPointerArraySizeType i )
83 return( TSkeleton::New( ).GetPointer( ) );
86 // -------------------------------------------------------------------------
87 template< class _TSkeleton >
88 cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
92 typename TSkeleton::Pointer out =
93 static_cast< TSkeleton* >( this->MakeOutput( 0 ).GetPointer( ) );
94 this->itk::ProcessObject::SetNumberOfRequiredInputs( 0 );
95 this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 );
96 this->itk::ProcessObject::SetNthOutput( 0, out.GetPointer( ) );
99 // -------------------------------------------------------------------------
100 template< class _TSkeleton >
101 cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
106 // -------------------------------------------------------------------------
107 template< class _TSkeleton >
108 void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
111 typedef typename TSkeleton::TPath _TPath;
112 typedef typename _TPath::TSpacing _TSpacing;
113 typedef typename _TPath::TPoint _TPoint;
114 typedef typename _TPath::TDirection _TDirection;
115 typedef typename _TPath::TContinuousIndex _TContinuousIndex;
118 if( !( cpExtensions::Read( buffer, this->m_FileName ) ) )
121 << "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__