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 >::
21 // -------------------------------------------------------------------------
22 template< class I, class S >
23 void cpExtensions::Algorithms::CPRFilter< I, S >::
24 SetAxis( const TAxis* axis )
28 // -------------------------------------------------------------------------
29 template< class I, class S >
30 cpExtensions::Algorithms::CPRFilter< I, S >::
34 this->m_Interpolator =
35 itk::NearestNeighborInterpolateImageFunction< I, S >::New( );
38 // -------------------------------------------------------------------------
39 template< class I, class S >
40 cpExtensions::Algorithms::CPRFilter< I, S >::
45 // -------------------------------------------------------------------------
46 template< class I, class S >
47 void cpExtensions::Algorithms::CPRFilter< I, S >::
50 typedef itk::Point< S, VDimension > _P;
51 typedef typename _P::VectorType _V;
52 typedef cpExtensions::Algorithms::BezierCurveFunction< _V > _Bezier;
53 typedef typename _Bezier::TFrame _M;
54 typedef itk::MinimumMaximumImageCalculator< I > _MinMax;
56 auto image = this->GetInput( );
57 auto axis = this->GetAxis( );
59 // 0. Get image properties
60 typename _MinMax::Pointer minmax = _MinMax::New( );
61 minmax->SetImage( image );
63 auto background = minmax->GetMinimum( );
65 // 1. Construct Bezier curve
66 typename _Bezier::Pointer bezier = _Bezier::New( );
67 auto vertices = axis->GetVertexList( );
68 for( unsigned int i = 0; i < vertices->Size( ); ++i )
70 auto index = vertices->GetElement( i );
72 image->TransformContinuousIndexToPhysicalPoint( index, point );
73 bezier->AddPoint( point.GetVectorFromOrigin( ) );
77 // 2. Slice image and prepare join filter
78 this->m_Join = TJoin::New( );
79 unsigned int nSlices = this->m_NumberOfSlices;
81 nSlices = bezier->GetNumberOfPoints( );
85 for( unsigned int i = 0; i <= nSlices; ++i )
87 // Get geometrical data and correct Frenet frame
88 S u = S( i ) / S( nSlices );
89 _V vnex = bezier->Evaluate( u );
90 _M mnex = bezier->EvaluateFrenetFrame( u );
93 len += ( vpre - vnex ).GetNorm( );
95 // TODO: Update Frenet frame orientation
100 typename TSlicer::Pointer slicer = TSlicer::New( );
101 slicer->SetInput( image );
102 slicer->SetRotation( mnex );
103 slicer->SetTranslation( vnex );
104 slicer->SetSize( S( this->m_SliceRadius ) );
105 slicer->SpacingFromMinimumOn( );
106 slicer->SetDefaultValue( background );
107 slicer->SetInterpolator( this->m_Interpolator );
109 // Add output to join filter and keep track of the current slicer
110 this->m_Join->SetInput( i, slicer->GetOutput( ) );
111 this->m_Slices.push_back( slicer );
119 // 3. Finish join filter configuration
120 this->m_Join->SetSpacing( double( len / S( nSlices + 1 ) ) );
121 this->m_Join->SetOrigin( double( 0 ) );
124 this->m_Join->GraftOutput( this->GetOutput( ) );
125 this->m_Join->UpdateLargestPossibleRegion( );
126 this->GraftOutput( this->m_Join->GetOutput( ) );
129 #endif // __CPEXTENSIONS__ALGORITHMS__CPRFILTER__HXX__