Skip to content
Snippets Groups Projects
Commit 4ce22afb authored by Julien Michel's avatar Julien Michel
Browse files

BUG: The SurfaceAdjancecyEffect6SCorrectionSchemeFilter bug with small shiny...

BUG: The SurfaceAdjancecyEffect6SCorrectionSchemeFilter bug with small shiny strips appearing when using multithreading is fixed.
parent ec5e0811
Branches
Tags
No related merge requests found
......@@ -18,7 +18,7 @@
#ifndef __otbUnaryFunctorNeighborhoodImageFilter_h
#define __otbUnaryFunctorNeighborhoodImageFilter_h
#include "itkInPlaceImageFilter.h"
#include "itkImageToImageFilter.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkConstNeighborhoodIterator.h"
#include "itkProcessObject.h"
......@@ -35,12 +35,12 @@ namespace otb {
*/
template <class TInputImage, class TOutputImage, class TFunction >
class ITK_EXPORT UnaryFunctorNeighborhoodImageFilter
: public itk::InPlaceImageFilter<TInputImage,TOutputImage>
: public itk::ImageToImageFilter<TInputImage,TOutputImage>
{
public:
/** Standard class typedefs. */
typedef UnaryFunctorNeighborhoodImageFilter Self;
typedef itk::InPlaceImageFilter<TInputImage,TOutputImage > Superclass;
typedef itk::ImageToImageFilter<TInputImage,TOutputImage > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
......@@ -48,7 +48,7 @@ public:
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(UnaryFunctorNeighborhoodImageFilter,InPlaceImageFilter);
itkTypeMacro(UnaryFunctorNeighborhoodImageFilter,ImageToImageFilter);
/** Some convenient typedefs. */
......@@ -128,11 +128,6 @@ protected:
*/
virtual void GenerateInputRequestedRegion(void);
/**
* Allocate the output buffer before calling the ThreadedGenerateData.
*/
/* virtual void BeforeThreadedGenerateData(void); */
private:
UnaryFunctorNeighborhoodImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
......
......@@ -25,6 +25,7 @@
#include "itkProgressReporter.h"
#include "otbMirrorBoundaryCondition.h"
#include "itkZeroFluxNeumannBoundaryCondition.h"
#include "itkNeighborhoodAlgorithm.h"
namespace otb
{
......@@ -36,7 +37,6 @@ UnaryFunctorNeighborhoodImageFilter<TInputImage,TOutputImage,TFunction>
::UnaryFunctorNeighborhoodImageFilter()
{
this->SetNumberOfRequiredInputs( 1 );
this->InPlaceOff();
m_Radius = 1;
}
template <class TInputImage, class TOutputImage, class TFunction >
......@@ -98,36 +98,56 @@ void
UnaryFunctorNeighborhoodImageFilter<TInputImage, TOutputImage, TFunction>
::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread, int threadId)
{
std::cout<<threadId<<" "<<outputRegionForThread<<std::endl;
//unsigned int i;
itk::ZeroFluxNeumannBoundaryCondition<TInputImage> nbc;
TInputImage * inputPtr = static_cast<TInputImage *>( ProcessObjectType::GetInput(0) );
// We use dynamic_cast since inputs are stored as DataObjects. The
// ImageToImageFilter::GetInput(int) always returns a pointer to a
// TInputImage so it cannot be used for the second input.
InputImagePointer inputPtr
= dynamic_cast<const TInputImage*>(ProcessObjectType::GetInput(0));
OutputImagePointer outputPtr = this->GetOutput(0);
RadiusType r;
r.Fill(m_Radius);
NeighborhoodIteratorType neighInputIt;
itk::ImageRegionIterator<TOutputImage> outputIt;
OutputImagePointer outputPtr = this->GetOutput();
itk::ImageRegionIterator<TOutputImage> outputIt;
// Find the data-set boundary "faces"
typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType faceList;
typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage> bC;
faceList = bC(inputPtr, outputRegionForThread, r);
typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<TInputImage>::FaceListType::iterator fit;
// support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
NeighborhoodIteratorType neighInputIt( r, inputPtr, outputRegionForThread );
neighInputIt.OverrideBoundaryCondition( &nbc );
neighInputIt.GoToBegin();
outputIt = itk::ImageRegionIterator<TOutputImage> ( outputPtr,outputRegionForThread );
outputIt.GoToBegin();
while ( !outputIt.IsAtEnd() )
{
outputIt.Set( m_Functor( neighInputIt ) );
// Process each of the boundary faces. These are N-d regions which border
// the edge of the buffer.
for (fit=faceList.begin(); fit != faceList.end(); ++fit)
{
neighInputIt = itk::ConstNeighborhoodIterator<TInputImage>(r, inputPtr, *fit);
outputIt = itk::ImageRegionIterator<TOutputImage>(outputPtr, *fit);
neighInputIt.OverrideBoundaryCondition(&nbc);
neighInputIt.GoToBegin();
while ( ! outputIt.IsAtEnd() )
{
outputIt.Set( m_Functor( neighInputIt) );
++neighInputIt;
++outputIt;
progress.CompletedPixel();
}
}
}
}
}
} // end namespace otb
......
......@@ -62,8 +62,8 @@ namespace otb
{
unsigned int neighborhoodSize = it.Size();
double contribution = 0.;
double temp = 0.;
TOutput outPixel = it.GetPixel(0);
TOutput outPixel;
outPixel.SetSize(it.GetCenterPixel().Size());
// Loop over each component
for (unsigned int j=0; j<outPixel.GetSize(); j++)
......@@ -94,9 +94,7 @@ namespace otb
contribution += static_cast<double>( tempPix[j] )*idVal;
}
temp = 0.;
temp = static_cast<double>(it.GetCenterPixel()[j])*m_UpwardTransmittanceRatio[j] + contribution*m_DiffuseRatio[j];
outPixel[j] = static_cast<RealValueType>(temp);
outPixel[j] = static_cast<RealValueType>(it.GetCenterPixel()[j])*m_UpwardTransmittanceRatio[j] + contribution*m_DiffuseRatio[j];
}
return outPixel;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment