Commit 99288da8 authored by Antoine Regimbeau's avatar Antoine Regimbeau
Browse files

BUG: restore multithreading in computehisto filter

No related merge requests found
Showing with 20 additions and 20 deletions
+20 -20
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "itkImageRegionIterator.h" #include "itkImageRegionIterator.h"
#include "itkImageRegionConstIteratorWithIndex.h" #include "itkImageRegionConstIteratorWithIndex.h"
#include <limits> #include <limits>
namespace otb namespace otb
...@@ -37,6 +38,7 @@ ApplyGainFilter < TInputImage , TLut , TOutputImage > ...@@ -37,6 +38,7 @@ ApplyGainFilter < TInputImage , TLut , TOutputImage >
m_Min = std::numeric_limits< InputPixelType >::quiet_NaN(); m_Min = std::numeric_limits< InputPixelType >::quiet_NaN();
m_Max = std::numeric_limits< InputPixelType >::quiet_NaN(); m_Max = std::numeric_limits< InputPixelType >::quiet_NaN();
m_NoData = std::numeric_limits< InputPixelType >::quiet_NaN(); m_NoData = std::numeric_limits< InputPixelType >::quiet_NaN();
m_Step = -1; m_Step = -1;
} }
......
...@@ -234,7 +234,9 @@ void ComputeHistoFilter < TInputImage , TOutputImage > ...@@ -234,7 +234,9 @@ void ComputeHistoFilter < TInputImage , TOutputImage >
// Initializing shared variable with thread number parameter // Initializing shared variable with thread number parameter
SizeType outSize ( output->GetRequestedRegion().GetSize() ); SizeType outSize ( output->GetRequestedRegion().GetSize() );
m_HistoThread.resize( m_ValidThreads * outSize[0] * outSize[1] , zeroPixel ); m_HistoThread.resize( m_ValidThreads * outSize[0] * outSize[1] );
m_HistoThread.shrink_to_fit();
std::fill( m_HistoThread.begin() , m_HistoThread.end() , zeroPixel );
m_Step = static_cast<double>( m_Max - m_Min ) \ m_Step = static_cast<double>( m_Max - m_Min ) \
/ static_cast<double>( m_NbBin -1 ); / static_cast<double>( m_NbBin -1 );
...@@ -242,8 +244,7 @@ void ComputeHistoFilter < TInputImage , TOutputImage > ...@@ -242,8 +244,7 @@ void ComputeHistoFilter < TInputImage , TOutputImage >
template <class TInputImage, class TOutputImage > template <class TInputImage, class TOutputImage >
void ComputeHistoFilter < TInputImage , TOutputImage > void ComputeHistoFilter < TInputImage , TOutputImage >
::ThreadedGenerateData(const OutputImageRegionType & ::ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread ,
itkNotUsed(outputRegionForThread) ,
itk::ThreadIdType threadId ) itk::ThreadIdType threadId )
{ {
assert(m_Step>0); assert(m_Step>0);
...@@ -253,13 +254,14 @@ void ComputeHistoFilter < TInputImage , TOutputImage > ...@@ -253,13 +254,14 @@ void ComputeHistoFilter < TInputImage , TOutputImage >
// outputRegionForThread.GetNumberOfPixels() ); // outputRegionForThread.GetNumberOfPixels() );
typename InputImageType::ConstPointer input ( this->GetInput() ); typename InputImageType::ConstPointer input ( this->GetInput() );
typename OutputImageType::Pointer output ( this->GetHistoOutput() );
OutputImageRegionType histoRegion ( OutputImageRegionType histoRegion (
GetHistoOutput()->GetRequestedRegion() ); GetHistoOutput()->GetRequestedRegion() );
SizeType outSize ( histoRegion.GetSize() ); SizeType outSize ( histoRegion.GetSize() );
IndexType outIndex ( histoRegion.GetIndex() ); IndexType outIndex ( histoRegion.GetIndex() );
typename InputImageType::RegionType region; typename InputImageType::RegionType region;
region.SetSize( m_ThumbSize );
unsigned int threadIndex ( threadId * outSize[0] * outSize[1] ) , pixel(0) ; unsigned int threadIndex ( threadId * outSize[0] * outSize[1] ) , pixel(0) ;
...@@ -267,24 +269,18 @@ void ComputeHistoFilter < TInputImage , TOutputImage > ...@@ -267,24 +269,18 @@ void ComputeHistoFilter < TInputImage , TOutputImage >
nthHisto < outSize[0] * outSize[1] ; nthHisto++ ) nthHisto < outSize[0] * outSize[1] ; nthHisto++ )
{ {
IndexType start; IndexType start;
start[0] = (outIndex[0] + nthHisto % outSize[0] ) * m_ThumbSize[0]; start[0] = ( outIndex[0] + nthHisto % outSize[0] ) * m_ThumbSize[0];
start[1] = (outIndex[1] + nthHisto / outSize[0] ) * m_ThumbSize[1]; start[1] = ( outIndex[1] + nthHisto / outSize[0] ) * m_ThumbSize[1];
region.SetSize( m_ThumbSize );
region.SetIndex(start); region.SetIndex(start);
if ( !region.Crop( input->GetRequestedRegion() ) )
{ if ( !region.Crop( outputRegionForThread ) )
// Couldn't crop the region (region is outside the requested continue;
// region). Throw an exception.
// build an exception
itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
e.SetLocation(ITK_LOCATION);
e.SetDescription("Asked region is outside requested region");
// e.SetDataObject( input );
throw e;
}
typename itk::ImageRegionConstIterator < InputImageType > typename itk::ImageRegionConstIterator < InputImageType >
it( input , region ); it( input , region );
InputPixelType currentPixel(0); InputPixelType currentPixel(0);
int i (0);
for ( it.GoToBegin() ; !it.IsAtEnd() ; ++it ) for ( it.GoToBegin() ; !it.IsAtEnd() ; ++it )
{ {
currentPixel = it.Get(); currentPixel = it.Get();
...@@ -295,7 +291,9 @@ void ComputeHistoFilter < TInputImage , TOutputImage > ...@@ -295,7 +291,9 @@ void ComputeHistoFilter < TInputImage , TOutputImage >
pixel = static_cast< unsigned int >( pixel = static_cast< unsigned int >(
std::round( ( currentPixel - m_Min ) / m_Step ) ); std::round( ( currentPixel - m_Min ) / m_Step ) );
++m_HistoThread[threadIndex + nthHisto][pixel]; ++m_HistoThread[threadIndex + nthHisto][pixel];
++i;
} }
} }
} }
...@@ -324,8 +322,8 @@ void ComputeHistoFilter < TInputImage , TOutputImage > ...@@ -324,8 +322,8 @@ void ComputeHistoFilter < TInputImage , TOutputImage >
for ( unsigned int threadId = 0 ; threadId < m_ValidThreads ; threadId++ ) for ( unsigned int threadId = 0 ; threadId < m_ValidThreads ; threadId++ )
{ {
agreg += m_HistoThread[ threadId * outSize[0] * outSize[1] agreg += m_HistoThread[ threadId * outSize[0] * outSize[1]
+ ( ( oit.GetIndex()[0] - outIndex[0] ) ) + ( oit.GetIndex()[1] - outIndex[1] ) * outSize[0]
+ ( oit.GetIndex()[1] - outIndex[1] ) * outSize[0] ][i] ; + ( ( oit.GetIndex()[0] - outIndex[0] ) ) ][i] ;
} }
oit.Get()[i] = agreg; oit.Get()[i] = agreg;
total += agreg; total += agreg;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment