X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FAlgorithms%2FCPRImageFilter.hxx;h=b2b8d969b1a6e69a8bfcbd7060f8c270c1e892e4;hb=9d315ac836e5fe246a8c987681085ee19898affc;hp=a29c6565f0fb8a79bf4653f7c621d6e417936bb3;hpb=0ddc14324268de8d6af08eaa89163a60ce1d16ce;p=cpPlugins.git diff --git a/lib/cpExtensions/Algorithms/CPRImageFilter.hxx b/lib/cpExtensions/Algorithms/CPRImageFilter.hxx index a29c656..b2b8d96 100644 --- a/lib/cpExtensions/Algorithms/CPRImageFilter.hxx +++ b/lib/cpExtensions/Algorithms/CPRImageFilter.hxx @@ -1,6 +1,10 @@ #ifndef __cpExtensions__Algorithms__CPRImageFilter__hxx__ #define __cpExtensions__Algorithms__CPRImageFilter__hxx__ +#include +#include +#include + // ------------------------------------------------------------------------- template< class _TImage, class _TCurve > _TCurve* cpExtensions::Algorithms::CPRImageFilter< _TImage, _TCurve >:: @@ -26,7 +30,7 @@ template< class _TImage, class _TCurve > void cpExtensions::Algorithms::CPRImageFilter< _TImage, _TCurve >:: SetCurve( _TCurve* curve ) { - this->itk::ProcessObject::SetInput( 1, curve ); + this->itk::ProcessObject::SetNthInput( 1, curve ); } // ------------------------------------------------------------------------- @@ -68,10 +72,63 @@ template< class _TImage, class _TCurve > void cpExtensions::Algorithms::CPRImageFilter< _TImage, _TCurve >:: GenerateData( ) { - /* TODO - double m_SliceRadius - typename TInterpolateFunction::Pointer m_Interpolator - */ + typedef itk::MinimumMaximumImageCalculator< _TImage > _TMinMax; + typedef itk::ImageSliceIteratorWithIndex< _TImage > _T3DIt; + typedef itk::ImageRegionIterator< typename TSlicer::TSliceImage > _T2DIt; + + auto input = this->GetInput( ); + auto curve = this->GetCurve( ); + auto output = this->GetOutput( ); + + // Compute image intensity range + typename _TMinMax::Pointer minmax = _TMinMax::New( ); + minmax->SetImage( input ); + minmax->Compute( ); + + // Prepare slicer + typename TSlicer::Pointer slicer = TSlicer::New( ); + slicer->SetInput( input ); + slicer->SetDefaultValue( minmax->GetMinimum( ) ); + slicer->SpacingFromMinimumOn( ); + if( this->m_Interpolator.IsNotNull( ) ) + slicer->SetInterpolator( this->m_Interpolator ); + slicer->SizeFromMaximumOff( ); + if( this->m_SliceRadius > double( 0 ) ) + { + slicer->SizeFromMinimumOff( ); + slicer->SetSize( this->m_SliceRadius ); + } + else + slicer->SizeFromMinimumOn( ); + + // Slice image + _T3DIt oIt( output, output->GetRequestedRegion( ) ); + oIt.SetFirstDirection( 1 ); + oIt.SetSecondDirection( 2 ); + oIt.GoToBegin( ); + unsigned long N = curve->GetNumberOfPoints( ); + for( unsigned long n = 0; n < N; ++n ) + { + slicer->SetTranslation( curve->GetPoint( n ) ); + slicer->SetRotation( curve->GetFrame( n ) ); + slicer->Update( ); + + // Fill output image + _T2DIt sIt( + slicer->GetOutput( ), slicer->GetOutput( )->GetRequestedRegion( ) + ); + for( sIt.GoToBegin( ); !sIt.IsAtEnd( ); ++sIt ) + { + oIt.Set( sIt.Get( ) ); + ++oIt; + if( oIt.IsAtEndOfLine( ) ) + oIt.NextLine( ); + if( oIt.IsAtEndOfSlice( ) ) + oIt.NextSlice( ); + + } // rof + + } // rof } #endif // __cpExtensions__Algorithms__CPRImageFilter__hxx__