From d55a229416be7cbd3b1777d556ea8bc0d6b9a7c5 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@c-s.fr>
Date: Wed, 10 Sep 2008 08:47:12 +0000
Subject: [PATCH] COMP: Fixed some warnings on gcc using the -Wall option.

---
 Code/BasicFilters/otbMeanShiftImageFilter.h   |  11 +-
 Code/BasicFilters/otbMeanShiftImageFilter.txx |  18 ++
 .../otbMeanShiftImageFilterBase.h             | 216 ++++++++++--------
 .../otbMeanShiftImageFilterBase.txx           |  12 +-
 .../otbMeanShiftVectorImageFilter.h           |  10 +-
 .../otbMeanShiftVectorImageFilter.txx         |  20 ++
 6 files changed, 179 insertions(+), 108 deletions(-)

diff --git a/Code/BasicFilters/otbMeanShiftImageFilter.h b/Code/BasicFilters/otbMeanShiftImageFilter.h
index 5bd5119726..4de9423255 100644
--- a/Code/BasicFilters/otbMeanShiftImageFilter.h
+++ b/Code/BasicFilters/otbMeanShiftImageFilter.h
@@ -46,7 +46,10 @@ class ITK_EXPORT MeanShiftImageFilter
     typedef itk::SmartPointer<const Self>                     ConstPointer;
    
     // Precision pixel type 
+    typedef typename Superclass::InputPixelType     InputPixelType;
     typedef typename Superclass::PrecisionPixelType PrecisionPixelType;
+    typedef typename Superclass::OutputPixelType    OutputPixelType;
+    
 
     /** New and Type macros */
     itkNewMacro(Self);
@@ -72,7 +75,13 @@ class ITK_EXPORT MeanShiftImageFilter
     
     /** Redefinition of the SquaredNorm() method adapted for Image */
     virtual double SquaredNorm(const PrecisionPixelType& value);
-    
+
+    /** Redefinition of CastInputPixelToPrecisionPixel() method adapted form Image */
+    virtual const PrecisionPixelType CastInputPixelToPrecisionPixel(const InputPixelType & pixel);
+
+    /** Redefinition of CastPrecisionPixelToOutputPixel() method adapted form Image */
+    virtual const OutputPixelType CastPrecisionPixelToOutputPixel(const PrecisionPixelType & pixel);
+
     private:
     MeanShiftImageFilter(const Self&); //purposely not implemented
     void operator=(const Self&);             //purposely not implemented
diff --git a/Code/BasicFilters/otbMeanShiftImageFilter.txx b/Code/BasicFilters/otbMeanShiftImageFilter.txx
index 7a6acfbfef..f91b892ca5 100644
--- a/Code/BasicFilters/otbMeanShiftImageFilter.txx
+++ b/Code/BasicFilters/otbMeanShiftImageFilter.txx
@@ -47,6 +47,24 @@ namespace otb
     return value * value;
   }
 
+  template <class TInputImage,class TOutputImage,class TPrecision>
+  const typename  MeanShiftImageFilter<TInputImage,TOutputImage,TPrecision>
+  ::PrecisionPixelType
+  MeanShiftImageFilter<TInputImage,TOutputImage,TPrecision>
+  ::CastInputPixelToPrecisionPixel(const InputPixelType & pixel)
+  {   
+    return static_cast<PrecisionPixelType>(pixel);
+  }
+
+  template <class TInputImage,class TOutputImage,class TPrecision>
+  const typename  MeanShiftImageFilter<TInputImage,TOutputImage,TPrecision>
+  ::OutputPixelType
+  MeanShiftImageFilter<TInputImage,TOutputImage,TPrecision>
+  ::CastPrecisionPixelToOutputPixel(const PrecisionPixelType & pixel)
+  {   
+    return static_cast<OutputPixelType>(pixel);
+  }
+
   template <class TInputImage,class TOutputImage,class TPrecision>
   void
   MeanShiftImageFilter<TInputImage,TOutputImage,TPrecision>
diff --git a/Code/BasicFilters/otbMeanShiftImageFilterBase.h b/Code/BasicFilters/otbMeanShiftImageFilterBase.h
index e4c27baabe..8de616ceb4 100644
--- a/Code/BasicFilters/otbMeanShiftImageFilterBase.h
+++ b/Code/BasicFilters/otbMeanShiftImageFilterBase.h
@@ -57,108 +57,124 @@ namespace otb
    * \ingroup Threaded
    */
 
-template <class TInputImage, class TOutputImage, class TPrecision = double>
-class ITK_EXPORT MeanShiftImageFilterBase
-  : public itk::InPlaceImageFilter<TInputImage,TOutputImage>
-  {
-  public:
-    /** Standard class typedef */
-    typedef MeanShiftImageFilterBase                          Self;
-    typedef itk::InPlaceImageFilter<TInputImage,TOutputImage> Superclass;
-    typedef itk::SmartPointer<Self>                           Pointer;
-    typedef itk::SmartPointer<const Self>                     ConstPointer;
-
-    /** Type macro */
-    itkTypeMacro(MeanShiftImageFilterBase,InPlaceImageFilter);
+  template <class TInputImage, class TOutputImage, class TPrecision = double>
+    class ITK_EXPORT MeanShiftImageFilterBase
+    : public itk::InPlaceImageFilter<TInputImage,TOutputImage>
+    {
+      public:
+      /** Standard class typedef */
+      typedef MeanShiftImageFilterBase                          Self;
+      typedef itk::InPlaceImageFilter<TInputImage,TOutputImage> Superclass;
+      typedef itk::SmartPointer<Self>                           Pointer;
+      typedef itk::SmartPointer<const Self>                     ConstPointer;
+
+      /** Type macro */
+      itkTypeMacro(MeanShiftImageFilterBase,InPlaceImageFilter);
     
-    /** Template parameters typedefs */
-    typedef TInputImage                                  InputImageType;
-    typedef typename InputImageType::Pointer             InputImagePointerType;
-    typedef typename InputImageType::PixelType           InputPixelType;
-    typedef typename InputImageType::PointType           PointType;
-    typedef TOutputImage                                 OutputImageType;
-    typedef typename OutputImageType::Pointer            OutputImagePointerType;
-    typedef typename OutputImageType::PixelType          OutputPixelType;
-    typedef typename OutputImageType::RegionType         RegionType;
-    typedef typename RegionType::SizeType                SizeType;
-    typedef typename RegionType::IndexType               IndexType;
-    typedef typename InputImageType::SpacingType         SpacingType;
-    typedef TPrecision                                   PrecisionPixelType;
-
-    /** Setters / Getters */
-    itkSetMacro(SpatialRadius,double);
-    itkGetMacro(SpatialRadius,double);
-    itkSetMacro(RangeRadius,double);
-    itkGetMacro(RangeRadius,double);
-    itkSetMacro(MaxNumberOfIterations,unsigned int);
-    itkGetMacro(MaxNumberOfIterations,unsigned int);
-    itkGetMacro(ConvergenceDistanceThreshold,double);
-    itkSetMacro(ConvergenceDistanceThreshold,double);
-    itkSetMacro(UseImageSpacing,bool);
-    itkGetMacro(UseImageSpacing,bool);
-    itkBooleanMacro(UseImageSpacing);
-
-  protected:
-    /** This filters use a neighborhood around the pixel, so it needs to redfine the 
-     * input requested region */
-    virtual void GenerateInputRequestedRegion();
-
-    /** Threaded generate data */
-    virtual void ThreadedGenerateData(const RegionType & outputRegionForThread,int threadId);
-
-    /** Constructor */
-    MeanShiftImageFilterBase();
-
-    /** destructor */
-    ~MeanShiftImageFilterBase(){};
-
-   /**PrintSelf method */
-    virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
-
-    /** 
-     * This method must be defined in order to handle VectorImage or Image.
-     * \return the number of components per pixel of the input image.
-     */
-    virtual unsigned int GetNumberOfComponentsPerPixel() = 0;
-
-   /** 
-     * This method must be defined in order to handle VectorImage or Image.
-     * \param value The value to intialize (please note that the reference will be modified)
-     * \param nbComponents the number of components of the value to intialize.
-     */
-    virtual void InitValue(PrecisionPixelType & value, const unsigned int& nbComponents) = 0;
-
-    /**
-     * This method must be defined in order to handle VectorImage or Image.
-     * \return The sqaured norm of the given value 
-     */
-    virtual double SquaredNorm(const PrecisionPixelType& value) = 0;
-
-  private:
-    MeanShiftImageFilterBase(const Self&); //purposely not implemented
-    void operator=(const Self&);             //purposely not implemented
+      /** Template parameters typedefs */
+      typedef TInputImage                                  InputImageType;
+      typedef typename InputImageType::Pointer             InputImagePointerType;
+      typedef typename InputImageType::PixelType           InputPixelType;
+      typedef typename InputImageType::PointType           PointType;
+      typedef TOutputImage                                 OutputImageType;
+      typedef typename OutputImageType::Pointer            OutputImagePointerType;
+      typedef typename OutputImageType::PixelType          OutputPixelType;
+      typedef typename OutputImageType::RegionType         RegionType;
+      typedef typename RegionType::SizeType                SizeType;
+      typedef typename RegionType::IndexType               IndexType;
+      typedef typename InputImageType::SpacingType         SpacingType;
+      typedef TPrecision                                   PrecisionPixelType;
+
+      /** Setters / Getters */
+      itkSetMacro(SpatialRadius,double);
+      itkGetMacro(SpatialRadius,double);
+      itkSetMacro(RangeRadius,double);
+      itkGetMacro(RangeRadius,double);
+      itkSetMacro(MaxNumberOfIterations,unsigned int);
+      itkGetMacro(MaxNumberOfIterations,unsigned int);
+      itkGetMacro(ConvergenceDistanceThreshold,double);
+      itkSetMacro(ConvergenceDistanceThreshold,double);
+      itkSetMacro(UseImageSpacing,bool);
+      itkGetMacro(UseImageSpacing,bool);
+      itkBooleanMacro(UseImageSpacing);
+
+      protected:
+      /** This filters use a neighborhood around the pixel, so it needs to redfine the 
+       * input requested region */
+      virtual void GenerateInputRequestedRegion();
+
+      /** Threaded generate data */
+      virtual void ThreadedGenerateData(const RegionType & outputRegionForThread,int threadId);
+
+      /** Constructor */
+      MeanShiftImageFilterBase();
+
+      /** destructor */
+      ~MeanShiftImageFilterBase(){};
+
+      /**PrintSelf method */
+      virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
+
+      /** 
+       * This method must be defined in order to handle VectorImage or Image.
+       * \return the number of components per pixel of the input image.
+       */
+      virtual unsigned int GetNumberOfComponentsPerPixel() = 0;
+
+      /** 
+       * This method must be defined in order to handle VectorImage or Image.
+       * \param value The value to intialize (please note that the reference will be modified)
+       * \param nbComponents the number of components of the value to intialize.
+       */
+      virtual void InitValue(PrecisionPixelType & value, const unsigned int& nbComponents) = 0;
+
+      /**
+       * This method must be defined in order to handle VectorImage or Image.
+       * \return The sqaured norm of the given value 
+       */
+      virtual double SquaredNorm(const PrecisionPixelType& value) = 0;
+
+      /**
+       * This method must be defined in order to handle VectorImage or Image.
+       * It casts a pixel of type InputPixelType to a pixel of type PrecisionPixelType.
+       * \param inputPixel the pixel to cast
+       * \return the casted pixel.
+       */
+      virtual const PrecisionPixelType CastInputPixelToPrecisionPixel(const InputPixelType & pixel) = 0;
+
+      /**
+       * This method must be defined in order to handle VectorImage or Image.
+       * It casts a pixel of type PrecisionPixelType to a pixel of type OutputPixelType.
+       * \param pixel the pixel to cast
+       * \return the casted pixel.
+       */
+      virtual const OutputPixelType CastPrecisionPixelToOutputPixel(const PrecisionPixelType & pixel) = 0;
+
+      private:
+      MeanShiftImageFilterBase(const Self&); //purposely not implemented
+      void operator=(const Self&);             //purposely not implemented
  
-    /** Spatial radius for mean shift convergence */
-    double m_SpatialRadius;
-    /** Range radius for mean shift convergence */
-    double m_RangeRadius;
-    /** Max number of iterations for convergence */
-    unsigned int m_MaxNumberOfIterations;
-
-    /** Internal radius used by the iterator. The value depends on the spatial radius
-     *  and the maximum number of iterations. This value is not intended to be accessed
-     *  by users, thus no getter or setter is provided */
-    SizeType m_InternalRadius;
-
-    /** use image spacing */
-    bool m_UseImageSpacing;
-
-    /** Internal spacing is [1.,1.] if UseImageSpacing is off */
-    SpacingType m_InternalSpacing;
-
-    /** Distance threshold for convergence in the spatial domain */
-    double m_ConvergenceDistanceThreshold;
-  };
+      /** Spatial radius for mean shift convergence */
+      double m_SpatialRadius;
+      /** Range radius for mean shift convergence */
+      double m_RangeRadius;
+      /** Max number of iterations for convergence */
+      unsigned int m_MaxNumberOfIterations;
+
+      /** Internal radius used by the iterator. The value depends on the spatial radius
+       *  and the maximum number of iterations. This value is not intended to be accessed
+       *  by users, thus no getter or setter is provided */
+      SizeType m_InternalRadius;
+
+      /** use image spacing */
+      bool m_UseImageSpacing;
+
+      /** Internal spacing is [1.,1.] if UseImageSpacing is off */
+      SpacingType m_InternalSpacing;
+
+      /** Distance threshold for convergence in the spatial domain */
+      double m_ConvergenceDistanceThreshold;
+    };
 }// end namespace otb
 
 #ifndef OTB_MANUAL_INSTANTIATION
diff --git a/Code/BasicFilters/otbMeanShiftImageFilterBase.txx b/Code/BasicFilters/otbMeanShiftImageFilterBase.txx
index 7bee359db1..04bd4e8032 100644
--- a/Code/BasicFilters/otbMeanShiftImageFilterBase.txx
+++ b/Code/BasicFilters/otbMeanShiftImageFilterBase.txx
@@ -159,7 +159,7 @@ namespace otb
 	goesOn = true;
 	convergencePoint[0]=static_cast<double>(inputIt.GetIndex()[0])*m_InternalSpacing[0];
 	convergencePoint[1]=static_cast<double>(inputIt.GetIndex()[1])*m_InternalSpacing[1];
-	convergenceValue = inputIt.Get();
+	convergenceValue = this->CastInputPixelToPrecisionPixel(inputIt.Get());
 	// While the max number of iterations has not been reached and the convergence index is still moving
 	while(nbIterations < m_MaxNumberOfIterations && goesOn)
 	  {
@@ -167,10 +167,10 @@ namespace otb
 	    this->InitValue(maxDensityValue,nbComponentsPerPixel);
 	    nbPixelsIntoAccount = 0;
 
-	    startx = vcl_floor((convergencePoint[0]-m_SpatialRadius)/m_InternalSpacing[0]);
-	    stopx  = vcl_ceil ((convergencePoint[0]+m_SpatialRadius)/m_InternalSpacing[0]);
-	    starty = vcl_floor((convergencePoint[1]-m_SpatialRadius)/m_InternalSpacing[1]);
-	    stopy  = vcl_ceil ((convergencePoint[1]+m_SpatialRadius)/m_InternalSpacing[1]);
+	    startx = static_cast<long>(vcl_floor((convergencePoint[0]-m_SpatialRadius)/m_InternalSpacing[0]));
+	    stopx  = static_cast<long>(vcl_ceil ((convergencePoint[0]+m_SpatialRadius)/m_InternalSpacing[0]));
+	    starty = static_cast<long>(vcl_floor((convergencePoint[1]-m_SpatialRadius)/m_InternalSpacing[1]));
+	    stopy  = static_cast<long>(vcl_ceil ((convergencePoint[1]+m_SpatialRadius)/m_InternalSpacing[1]));
 
 	    // loop on the neighborhood
 	    for(i = startx;i<=stopx;++i)
@@ -229,7 +229,7 @@ namespace otb
 	    ++nbIterations;
 	  }
 	// Set the output value
-	outputIt.Set(convergenceValue);
+	outputIt.Set(this->CastPrecisionPixelToOutputPixel(convergenceValue));
 	// Update progress
 	progress.CompletedPixel();
 	// Increment iterators
diff --git a/Code/BasicFilters/otbMeanShiftVectorImageFilter.h b/Code/BasicFilters/otbMeanShiftVectorImageFilter.h
index 1cbfaba35e..150398974b 100644
--- a/Code/BasicFilters/otbMeanShiftVectorImageFilter.h
+++ b/Code/BasicFilters/otbMeanShiftVectorImageFilter.h
@@ -51,8 +51,10 @@ namespace otb
       itkTypeMacro(MeanShiftVectorImageFilter,MeanShiftImageFilterBase);
     
       /** Template parameters typedefs */
+      typedef typename Superclass::InputPixelType     InputPixelType;
       typedef typename Superclass::PrecisionPixelType PrecisionPixelType;
-
+      typedef typename Superclass::OutputPixelType    OutputPixelType;
+      
       protected:
       /** Constructor */
       MeanShiftVectorImageFilter(){};
@@ -74,6 +76,12 @@ namespace otb
       /** Redefinition of the SquaredNorm() method adapted for vector images */
       virtual double SquaredNorm(const PrecisionPixelType & value);
 
+      /** Redefinition of CastInputPixelToPrecisionPixel() method adapted form Image */
+      virtual const PrecisionPixelType CastInputPixelToPrecisionPixel(const InputPixelType & pixel);
+      
+      /** Redefinition of CastPrecisionPixelToOutputPixel() method adapted form Image */
+      virtual const OutputPixelType CastPrecisionPixelToOutputPixel(const PrecisionPixelType & pixel);
+      
       private:
       MeanShiftVectorImageFilter(const Self&); //purposely not implemented
       void operator=(const Self&);             //purposely not implemented
diff --git a/Code/BasicFilters/otbMeanShiftVectorImageFilter.txx b/Code/BasicFilters/otbMeanShiftVectorImageFilter.txx
index 30f7a40626..4786260d9d 100644
--- a/Code/BasicFilters/otbMeanShiftVectorImageFilter.txx
+++ b/Code/BasicFilters/otbMeanShiftVectorImageFilter.txx
@@ -54,6 +54,26 @@ namespace otb
     return value.GetSquaredNorm();
   }
 
+  template <class TInputImage,class TOutputImage,class TPrecision>
+  const typename  MeanShiftVectorImageFilter<TInputImage,TOutputImage,TPrecision>
+  ::PrecisionPixelType 
+  MeanShiftVectorImageFilter<TInputImage,TOutputImage,TPrecision>
+  ::CastInputPixelToPrecisionPixel(const InputPixelType & pixel)
+  {
+    // Inplicit cast in construction by copy, nothing to do here
+    return pixel;
+  }
+
+  template <class TInputImage,class TOutputImage,class TPrecision>
+  const typename  MeanShiftVectorImageFilter<TInputImage,TOutputImage,TPrecision>
+  ::OutputPixelType 
+  MeanShiftVectorImageFilter<TInputImage,TOutputImage,TPrecision>
+  ::CastPrecisionPixelToOutputPixel(const PrecisionPixelType & pixel)
+  {   
+    // Inplicit cast in construction by copy, nothing to do here
+    return pixel;
+  }
+
   template <class TInputImage,class TOutputImage,class TPrecision>
   void
   MeanShiftVectorImageFilter<TInputImage,TOutputImage,TPrecision>
-- 
GitLab