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 <itkLinearInterpolateImageFunction.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 >::
20 dynamic_cast< const TAxis* >( this->itk::ProcessObject::GetInput( 1 ) )
24 // -------------------------------------------------------------------------
25 template< class I, class S >
26 void cpExtensions::Algorithms::CPRFilter< I, S >::
27 SetAxis( const TAxis* axis )
29 this->itk::ProcessObject::SetNthInput( 1, const_cast< TAxis* >( axis ) );
32 // -------------------------------------------------------------------------
33 template< class I, class S >
34 cpExtensions::Algorithms::CPRFilter< I, S >::
38 this->m_Interpolator =
39 itk::LinearInterpolateImageFunction< I, S >::New( );
42 // -------------------------------------------------------------------------
43 template< class I, class S >
44 cpExtensions::Algorithms::CPRFilter< I, S >::
49 // -------------------------------------------------------------------------
50 template< class I, class S >
51 void cpExtensions::Algorithms::CPRFilter< I, S >::
52 GenerateOutputInformation( )
54 // Do nothing since the output has different geometry and topology.
57 // -------------------------------------------------------------------------
58 template< class I, class S >
59 void cpExtensions::Algorithms::CPRFilter< I, S >::
62 typedef itk::Point< S, VDimension > _P;
63 typedef typename _P::VectorType _V;
64 typedef cpExtensions::Algorithms::BezierCurveFunction< _V > _Bezier;
65 typedef typename _Bezier::TFrame _M;
66 typedef itk::MinimumMaximumImageCalculator< I > _MinMax;
68 auto image = this->GetInput( );
69 auto axis = this->GetAxis( );
71 // 0. Get image properties
72 typename _MinMax::Pointer minmax = _MinMax::New( );
73 minmax->SetImage( image );
75 auto background = minmax->GetMinimum( );
77 // 1. Construct Bezier curve
78 typename _Bezier::Pointer bezier = _Bezier::New( );
79 auto vertices = axis->GetVertexList( );
80 for( unsigned int i = 0; i < vertices->Size( ); ++i )
82 auto index = vertices->GetElement( i );
84 image->TransformContinuousIndexToPhysicalPoint( index, point );
85 bezier->AddPoint( point.GetVectorFromOrigin( ) );
89 // 2. Slice image and prepare join filter
90 this->m_Join = TJoin::New( );
91 unsigned int nSlices = this->m_NumberOfSlices;
93 nSlices = bezier->GetNumberOfPoints( );
97 for( unsigned int i = 0; i <= nSlices; ++i )
99 // Get geometrical data and correct Frenet frame
100 S u = S( i ) / S( nSlices );
101 std::cout << u << std::endl;
102 _V vnex = bezier->Evaluate( u );
103 _M mnex = bezier->EvaluateFrenetFrame( u );
106 len += ( vpre - vnex ).GetNorm( );
108 // TODO: Update Frenet frame orientation
113 typename TSlicer::Pointer slicer = TSlicer::New( );
114 slicer->SetInput( image );
115 slicer->SetRotation( mnex );
116 slicer->SetTranslation( vnex );
117 slicer->SetSize( S( this->m_SliceRadius ) );
118 slicer->SpacingFromMinimumOn( );
119 slicer->SetDefaultValue( background );
120 slicer->SetInterpolator( this->m_Interpolator );
123 std::cout << slicer->GetOutput( )->GetLargestPossibleRegion( ).GetSize( ) << std::endl;
125 // Add output to join filter and keep track of the current slicer
126 this->m_Join->SetInput( i, slicer->GetOutput( ) );
127 this->m_Slices.push_back( slicer );
135 // 3. Finish join filter configuration
136 this->m_Join->SetSpacing( double( len / S( nSlices + 1 ) ) );
137 std::cout << this->m_Join->GetSpacing( ) << std::endl;
138 this->m_Join->SetOrigin( double( 0 ) );
141 this->m_Join->GraftOutput( this->GetOutput( ) );
142 this->m_Join->Update( );//LargestPossibleRegion( );
143 this->GraftOutput( this->m_Join->GetOutput( ) );
146 #endif // __CPEXTENSIONS__ALGORITHMS__CPRFILTER__HXX__