From 61b672dd64310d182bb5872aee0fdf13540f223d Mon Sep 17 00:00:00 2001
From: Sebastien Harasse <sebastien.harasse@c-s.fr>
Date: Mon, 30 Apr 2012 18:15:45 +0200
Subject: [PATCH] BUG: Mean shift. fixed wrong output image types. Also
 replaced * by smart pointers when possible.

---
 Code/BasicFilters/otbMeanShiftImageFilter2.h  |  1 +
 .../BasicFilters/otbMeanShiftImageFilter2.txx | 22 ++++++++-----------
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/Code/BasicFilters/otbMeanShiftImageFilter2.h b/Code/BasicFilters/otbMeanShiftImageFilter2.h
index 49b3a79357..37ed0f2440 100644
--- a/Code/BasicFilters/otbMeanShiftImageFilter2.h
+++ b/Code/BasicFilters/otbMeanShiftImageFilter2.h
@@ -192,6 +192,7 @@ public:
   typedef TOutputIterationImage                       OutputIterationImageType;
 
   typedef otb::VectorImage<RealType, InputImageType::ImageDimension> OutputSpatialImageType;
+  typedef typename OutputSpatialImageType::Pointer                   OutputSpatialImagePointerType;
   typedef typename OutputSpatialImageType::PixelType                 OutputSpatialPixelType;
 
   typedef TKernel                                     KernelType;
diff --git a/Code/BasicFilters/otbMeanShiftImageFilter2.txx b/Code/BasicFilters/otbMeanShiftImageFilter2.txx
index 17c1abb6dd..175ac0c961 100644
--- a/Code/BasicFilters/otbMeanShiftImageFilter2.txx
+++ b/Code/BasicFilters/otbMeanShiftImageFilter2.txx
@@ -41,7 +41,7 @@ MeanShiftImageFilter2<TInputImage, TOutputImage, TKernel, TNorm, TOutputMetricIm
   m_ModeSearchOptimization = true;
 
   this->SetNumberOfOutputs(4);
-  this->SetNthOutput(0, OutputImageType::New());
+  this->SetNthOutput(0, OutputSpatialImageType::New());
   this->SetNthOutput(1, OutputImageType::New());
   this->SetNthOutput(2, OutputMetricImageType::New());
   this->SetNthOutput(3, OutputIterationImageType::New());
@@ -214,15 +214,11 @@ MeanShiftImageFilter2<TInputImage, TOutputImage, TKernel, TNorm, TOutputMetricIm
   Superclass::GenerateInputRequestedRegion();
 
   // Retrieve input pointers
-  TInputImage * inPtr  = const_cast<TInputImage *>(this->GetInput());
-
-  TOutputMetricImage    * outMetricPtr = this->GetMetricOutput();
-  OutputSpatialImageType * outSpatialPtr = this->GetSpatialOutput();
-  TOutputImage * outRangePtr = this->GetRangeOutput();
-  OutputIterationImageType * outIterationPtr = this->GetIterationOutput();
+  InputImagePointerType inPtr  = const_cast<TInputImage *>(this->GetInput());
+  OutputImagePointerType outRangePtr = this->GetRangeOutput();
 
   // Check pointers before using them
-  if(!inPtr || !outMetricPtr || !outSpatialPtr || !outRangePtr || !outIterationPtr)
+  if ( !inPtr || !outRangePtr )
     {
     return;
     }
@@ -230,7 +226,7 @@ MeanShiftImageFilter2<TInputImage, TOutputImage, TKernel, TNorm, TOutputMetricIm
 
   // Retrieve requested region (TODO: check if we need to handle
   // region for outHDispPtr)
-  RegionType outputRequestedRegion = outMetricPtr->GetRequestedRegion();
+  RegionType outputRequestedRegion = outRangePtr->GetRequestedRegion();
 
   // spatial and range radius may differ, padding must be done with the largest.
   //unsigned int largestRadius= this->GetLargestRadius();
@@ -278,10 +274,10 @@ MeanShiftImageFilter2<TInputImage, TOutputImage, TKernel, TNorm, TOutputMetricIm
   typedef itk::ImageRegionConstIteratorWithIndex<InputImageType> InputIteratorWithIndexType;
   typedef itk::ImageRegionIterator<RealVectorImageType> JointImageIteratorType;
 
-  TOutputMetricImage    * outMetricPtr = this->GetMetricOutput();
-  OutputSpatialImageType * outSpatialPtr   = this->GetSpatialOutput();
-  TOutputImage * outRangePtr   = this->GetRangeOutput();
-  typename InputImageType::ConstPointer inputPtr = this->GetInput();
+  OutputMetricImagePointerType          outMetricPtr  = this->GetMetricOutput();
+  OutputSpatialImagePointerType         outSpatialPtr = this->GetSpatialOutput();
+  OutputImagePointerType                outRangePtr   = this->GetRangeOutput();
+  typename InputImageType::ConstPointer inputPtr      = this->GetInput();
 
   InputIndexType index;
 
-- 
GitLab