From f9c2f567f2566525db48dff4a6abbdb753a483cf Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@cnes.fr> Date: Tue, 10 Nov 2015 17:33:32 +0100 Subject: [PATCH] PERF: Apply same scheme to FastICA image filter (separate statistics from image processing) --- .../include/otbFastICAImageFilter.h | 2 + .../include/otbFastICAImageFilter.txx | 76 +++++++++++++------ 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/Modules/Filtering/DimensionalityReduction/include/otbFastICAImageFilter.h b/Modules/Filtering/DimensionalityReduction/include/otbFastICAImageFilter.h index 65b44b163a..c7c02acc61 100644 --- a/Modules/Filtering/DimensionalityReduction/include/otbFastICAImageFilter.h +++ b/Modules/Filtering/DimensionalityReduction/include/otbFastICAImageFilter.h @@ -164,6 +164,8 @@ protected: virtual void GenerateData (); /** Internal methods */ + void ForwardGenerateOutputInformation(); + void ReverseGenerateOutputInformation(); virtual void ForwardGenerateData(); virtual void ReverseGenerateData(); diff --git a/Modules/Filtering/DimensionalityReduction/include/otbFastICAImageFilter.txx b/Modules/Filtering/DimensionalityReduction/include/otbFastICAImageFilter.txx index 2a42c3c428..6aab3f19c5 100644 --- a/Modules/Filtering/DimensionalityReduction/include/otbFastICAImageFilter.txx +++ b/Modules/Filtering/DimensionalityReduction/include/otbFastICAImageFilter.txx @@ -103,24 +103,19 @@ FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > "Class should be templeted with FORWARD or INVERSE only...", ITK_LOCATION ); } -} -template < class TInputImage, class TOutputImage, - Transform::TransformDirection TDirectionOfTransformation > -void -FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > -::GenerateData () -{ switch ( static_cast<int>(DirectionOfTransformation) ) { case static_cast<int>(Transform::FORWARD): - return ForwardGenerateData(); + { + ForwardGenerateOutputInformation(); + break; + } case static_cast<int>(Transform::INVERSE): - return ReverseGenerateData(); - default: - throw itk::ExceptionObject(__FILE__, __LINE__, - "Class should be templated with FORWARD or INVERSE only...", - ITK_LOCATION ); + { + ReverseGenerateOutputInformation(); + break; + } } } @@ -128,13 +123,13 @@ template < class TInputImage, class TOutputImage, Transform::TransformDirection TDirectionOfTransformation > void FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > -::ForwardGenerateData () +::ForwardGenerateOutputInformation() { typename InputImageType::Pointer inputImgPtr = const_cast<InputImageType*>( this->GetInput() ); m_PCAFilter->SetInput( inputImgPtr ); - m_PCAFilter->Update(); + m_PCAFilter->GetOutput()->UpdateOutputInformation(); if ( !m_GivenTransformationMatrix ) { @@ -157,19 +152,15 @@ FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > m_TransformFilter->SetInput( m_PCAFilter->GetOutput() ); m_TransformFilter->SetMatrix( m_TransformationMatrix.GetVnlMatrix() ); - m_TransformFilter->GraftOutput( this->GetOutput() ); - m_TransformFilter->Update(); - - this->GraftOutput( m_TransformFilter->GetOutput() ); } template < class TInputImage, class TOutputImage, Transform::TransformDirection TDirectionOfTransformation > void FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > -::ReverseGenerateData () +::ReverseGenerateOutputInformation() { - if ( !m_GivenTransformationMatrix ) + if ( !m_GivenTransformationMatrix ) { throw itk::ExceptionObject( __FILE__, __LINE__, "No Transformation matrix given", @@ -200,9 +191,48 @@ FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > * have not been given at this point */ m_PCAFilter->SetInput( m_TransformFilter->GetOutput() ); +} + + +template < class TInputImage, class TOutputImage, + Transform::TransformDirection TDirectionOfTransformation > +void +FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > +::GenerateData () +{ + switch ( static_cast<int>(DirectionOfTransformation) ) + { + case static_cast<int>(Transform::FORWARD): + return ForwardGenerateData(); + case static_cast<int>(Transform::INVERSE): + return ReverseGenerateData(); + default: + throw itk::ExceptionObject(__FILE__, __LINE__, + "Class should be templated with FORWARD or INVERSE only...", + ITK_LOCATION ); + } +} + +template < class TInputImage, class TOutputImage, + Transform::TransformDirection TDirectionOfTransformation > +void +FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > +::ForwardGenerateData () +{ + m_TransformFilter->GraftOutput( this->GetOutput() ); + m_TransformFilter->Update(); + + this->GraftOutput( m_TransformFilter->GetOutput() ); +} + +template < class TInputImage, class TOutputImage, + Transform::TransformDirection TDirectionOfTransformation > +void +FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > +::ReverseGenerateData () +{ m_PCAFilter->GraftOutput( this->GetOutput() ); m_PCAFilter->Update(); - this->GraftOutput( m_PCAFilter->GetOutput() ); } @@ -285,7 +315,7 @@ FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > if ( size != this->GetNumberOfPrincipalComponentsRequired() ) { - this->m_TransformationMatrix = W.get_n_rows( 0, this->GetNumberOfPrincipalComponentsRequired() ); + this->m_TransformationMatrix = W.get_n_columns( 0, this->GetNumberOfPrincipalComponentsRequired() ); } else { -- GitLab