1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__CPRFILTER__HXX__
6 #define __CPEXTENSIONS__ALGORITHMS__CPRFILTER__HXX__
9 #include <itkMinimumMaximumImageCalculator.h>
10 #include <itkNearestNeighborInterpolateImageFunction.h>
11 #include <cpExtensions/Algorithms/BezierCurveFunction.h>
13 // -------------------------------------------------------------------------
14 template< class I, class S >
15 const typename cpExtensions::Algorithms::CPRFilter< I, S >::
16 TAxis* cpExtensions::Algorithms::CPRFilter< I, S >::
22 // -------------------------------------------------------------------------
23 template< class I, class S >
24 void cpExtensions::Algorithms::CPRFilter< I, S >::
25 SetAxis( const TAxis* axis )
29 // -------------------------------------------------------------------------
30 template< class I, class S >
31 cpExtensions::Algorithms::CPRFilter< I, S >::
35 this->m_Interpolator =
36 itk::NearestNeighborInterpolateImageFunction< I, S >::New( );
39 // -------------------------------------------------------------------------
40 template< class I, class S >
41 cpExtensions::Algorithms::CPRFilter< I, S >::
46 // -------------------------------------------------------------------------
47 template< class I, class S >
48 void cpExtensions::Algorithms::CPRFilter< I, S >::
51 typedef itk::Point< S, VDimension > _P;
52 typedef typename _P::VectorType _V;
53 typedef cpExtensions::Algorithms::BezierCurveFunction< _V > _Bezier;
54 typedef typename _Bezier::TFrame _M;
55 typedef itk::MinimumMaximumImageCalculator< I > _MinMax;
57 auto image = this->GetInput( );
58 auto axis = this->GetAxis( );
60 // 0. Get image properties
61 typename _MinMax::Pointer minmax = _MinMax::New( );
62 minmax->SetImage( image );
64 auto background = minmax->GetMinimum( );
66 // 1. Construct Bezier curve
67 typename _Bezier::Pointer bezier = _Bezier::New( );
68 auto vertices = axis->GetVertexList( );
69 for( unsigned int i = 0; i < vertices->Size( ); ++i )
71 auto index = vertices->GetElement( i );
73 image->TransformContinuousIndexToPhysicalPoint( index, point );
74 bezier->AddPoint( point.GetVectorFromOrigin( ) );
78 // 2. Slice image and prepare join filter
79 this->m_Join = TJoin::New( );
80 unsigned int nSlices = this->m_NumberOfSlices;
82 nSlices = bezier->GetNumberOfPoints( );
86 for( unsigned int i = 0; i <= nSlices; ++i )
88 // Get geometrical data and correct Frenet frame
89 S u = S( i ) / S( nSlices );
90 _V vnex = bezier->Evaluate( u );
91 _M mnex = bezier->EvaluateFrenetFrame( u );
94 len += ( vpre - vnex ).GetNorm( );
96 // TODO: Update Frenet frame orientation
101 typename TSlicer::Pointer slicer = TSlicer::New( );
102 slicer->SetInput( image );
103 slicer->SetRotation( mnex );
104 slicer->SetTranslation( vnex );
105 slicer->SetSize( S( this->m_SliceRadius ) );
106 slicer->SpacingFromMinimumOn( );
107 slicer->SetDefaultValue( background );
108 slicer->SetInterpolator( this->m_Interpolator );
110 // Add output to join filter and keep track of the current slicer
111 this->m_Join->SetInput( i, slicer->GetOutput( ) );
112 this->m_Slices.push_back( slicer );
120 // 3. Finish join filter configuration
121 this->m_Join->SetSpacing( double( len / S( nSlices + 1 ) ) );
122 this->m_Join->SetOrigin( double( 0 ) );
125 this->m_Join->GraftOutput( this->GetOutput( ) );
126 this->m_Join->UpdateLargestPossibleRegion( );
127 this->GraftOutput( this->m_Join->GetOutput( ) );
130 #endif // __CPEXTENSIONS__ALGORITHMS__CPRFILTER__HXX__