From 704d879b9fd12af572932d2aab981dbfb45e6ac8 Mon Sep 17 00:00:00 2001
From: Patrick Imbo <patrick.imbo@c-s.fr>
Date: Wed, 3 Nov 2010 10:06:34 +0100
Subject: [PATCH] ENH: template ElevDatabaseHeightAboveMSLFunction class with
 OutputPixelType instead of OutputImageType

---
 Code/IO/otbDEMToImageGenerator.h              |  5 ++-
 .../otbElevDatabaseHeightAboveMSLFunction.h   | 42 ++++++++-----------
 .../otbElevDatabaseHeightAboveMSLFunction.txx | 22 +++++-----
 .../otbElevDatabaseHeightAboveMSLFunction.cxx |  3 +-
 4 files changed, 32 insertions(+), 40 deletions(-)

diff --git a/Code/IO/otbDEMToImageGenerator.h b/Code/IO/otbDEMToImageGenerator.h
index e064699bef..b3b8c70304 100644
--- a/Code/IO/otbDEMToImageGenerator.h
+++ b/Code/IO/otbDEMToImageGenerator.h
@@ -78,7 +78,8 @@ public:
 
   typedef itk::FunctionBase< PointType, PixelType>         DEMFunctionBaseType;
   typedef typename DEMFunctionBaseType::Pointer            DEMFunctionBasePointer;
-  typedef otb::ElevDatabaseHeightAboveMSLFunction<DEMImageType,typename PointType::ValueType>    SRTMFunctionType;
+  typedef otb::ElevDatabaseHeightAboveMSLFunction<PixelType,
+                        typename PointType::ValueType>     SRTMFunctionType;
 
   /** Method for creation through the object factory. */
   itkNewMacro(Self);
@@ -193,7 +194,7 @@ protected:
   SizeType                m_OutputSize;
   PixelType               m_DefaultUnknownValue;
 
-  typename DEMFunctionBaseType::Pointer m_DEMFunction;
+  DEMFunctionBasePointer  m_DEMFunction;
 
 private:
   DEMToImageGenerator(const Self &); //purposely not implemented
diff --git a/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.h b/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.h
index 6f511874d6..ccd5053eb5 100644
--- a/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.h
+++ b/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.h
@@ -39,25 +39,22 @@ namespace otb
  * \ingroup ImageFunctions
  */
 template <
-class TOutput,
-class TCoordRep = float
+class TOutputPixel,
+class TCoordRep = float,
+unsigned int NPointDimension=2
 >
 class ElevDatabaseHeightAboveMSLFunction :
-    public itk::FunctionBase< itk::Point<TCoordRep,
-                               ::itk::GetImageDimension<TOutput>::ImageDimension>,
-                       typename TOutput::PixelType >
+    public itk::FunctionBase< itk::Point<TCoordRep, NPointDimension>,
+                              TOutputPixel >
 {
 public:
-    /** Dimension underlying input image. */
-    itkStaticConstMacro(ImageDimension, unsigned int,
-                        TOutput::ImageDimension);
-
+    /** Dimension of the Space */
+    itkStaticConstMacro(PointDimension, unsigned int, NPointDimension);
 
     /** Standard class typedefs. */
-  typedef ElevDatabaseHeightAboveMSLFunction                            Self;
+  typedef ElevDatabaseHeightAboveMSLFunction                    Self;
   typedef itk::FunctionBase<
-    itk::Point<TCoordRep, itkGetStaticConstMacro(ImageDimension)>,
-    TOutput >                                                   Superclass;
+      itk::Point<TCoordRep, NPointDimension>, TOutputPixel >    Superclass;
   typedef itk::SmartPointer<Self>                               Pointer;
   typedef itk::SmartPointer<const Self>                         ConstPointer;
 
@@ -67,24 +64,19 @@ public:
   /** Method for creation through the object factory. */
   itkNewMacro(Self);
 
-  /** OutputType typedef support. */
-  typedef TOutput OutputImageType;
-
-  /** InputPixel typedef support */
-  typedef typename OutputImageType::PixelType PixelType;
-
-  /** InputImagePointer typedef support */
-  typedef typename OutputImageType::ConstPointer ImageConstPointer;
+  /** Output Pixel typedef support */
+  typedef TOutputPixel   PixelType;
 
   /** CoordRepType typedef support. */
   typedef TCoordRep CoordRepType;
 
-  /** Index Type. */
-  typedef typename OutputImageType::IndexType      IndexType;
-  typedef typename OutputImageType::IndexValueType IndexValueType;
-
   /** Point Type. */
-  typedef itk::Point<TCoordRep,itkGetStaticConstMacro(ImageDimension)> PointType;
+  typedef itk::Point<TCoordRep,NPointDimension>    PointType;
+
+  /** Get the dimension (size) of the point. */
+  static unsigned int GetPointDimension()
+    { return NPointDimension; }
+
 
   /** Set the Elev Manager to the function. */
   virtual void SetElevManager(ossimElevManager * ptr )
diff --git a/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.txx b/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.txx
index 884463aa81..e4340233b7 100644
--- a/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.txx
+++ b/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.txx
@@ -37,8 +37,8 @@ namespace otb
 /**
  * Constructor
  */
-template <class TOutput, class TCoordRep>
-ElevDatabaseHeightAboveMSLFunction<TOutput, TCoordRep>
+template <class TOutputPixel, class TCoordRep, unsigned int NPointDimension>
+ElevDatabaseHeightAboveMSLFunction<TOutputPixel, TCoordRep, NPointDimension>
 ::ElevDatabaseHeightAboveMSLFunction() :
      m_ElevManager(ossimElevManager::instance())
 {
@@ -51,9 +51,9 @@ ElevDatabaseHeightAboveMSLFunction<TOutput, TCoordRep>
 /**
  * Standard "PrintSelf" method
  */
-template <class TOutput, class TCoordRep>
+template <class TOutputPixel, class TCoordRep, unsigned int NPointDimension>
 void
-ElevDatabaseHeightAboveMSLFunction<TOutput, TCoordRep>
+ElevDatabaseHeightAboveMSLFunction<TOutputPixel, TCoordRep, NPointDimension>
 ::PrintSelf(
   std::ostream& os,
   itk::Indent indent) const
@@ -65,9 +65,9 @@ ElevDatabaseHeightAboveMSLFunction<TOutput, TCoordRep>
 /**
  *
  */
-template <class TOutput, class TCoordRep>
-typename ElevDatabaseHeightAboveMSLFunction<TOutput, TCoordRep>::PixelType
-ElevDatabaseHeightAboveMSLFunction<TOutput, TCoordRep>
+template <class TOutputPixel, class TCoordRep, unsigned int NPointDimension>
+typename ElevDatabaseHeightAboveMSLFunction<TOutputPixel, TCoordRep, NPointDimension>::PixelType
+ElevDatabaseHeightAboveMSLFunction<TOutputPixel, TCoordRep, NPointDimension>
 ::Evaluate(const PointType& point) const
 {
   double   height;
@@ -88,9 +88,9 @@ ElevDatabaseHeightAboveMSLFunction<TOutput, TCoordRep>
 
 }
 
-template <class TOutput, class TCoordRep>
+template <class TOutputPixel, class TCoordRep, unsigned int NPointDimension>
 void
-ElevDatabaseHeightAboveMSLFunction<TOutput, TCoordRep>
+ElevDatabaseHeightAboveMSLFunction<TOutputPixel, TCoordRep, NPointDimension>
 ::OpenDEMDirectory(const char* DEMDirectory)
 {
   ossimFilename ossimDEMDir;
@@ -102,9 +102,9 @@ ElevDatabaseHeightAboveMSLFunction<TOutput, TCoordRep>
     }
 }
 
-template <class TOutput, class TCoordRep>
+template <class TOutputPixel, class TCoordRep, unsigned int NPointDimension>
 void
-ElevDatabaseHeightAboveMSLFunction<TOutput, TCoordRep>
+ElevDatabaseHeightAboveMSLFunction<TOutputPixel, TCoordRep, NPointDimension>
 ::SetDefaultHeightAboveEllipsoid(double h)
 {
   m_ElevManager->setDefaultHeightAboveEllipsoid(h);
diff --git a/Testing/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.cxx b/Testing/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.cxx
index b22d9f1b90..840e53abc2 100644
--- a/Testing/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.cxx
+++ b/Testing/Code/Projections/otbElevDatabaseHeightAboveMSLFunction.cxx
@@ -22,8 +22,7 @@
 
 int otbElevDatabaseHeightAboveMSLFunction(int argc, char* argv[])
 {
-  typedef otb::Image<float,2>                          ImageType;
-  typedef otb::ElevDatabaseHeightAboveMSLFunction<ImageType>   SrtmFunctionType;
+  typedef otb::ElevDatabaseHeightAboveMSLFunction<float>   SrtmFunctionType;
 
   SrtmFunctionType::Pointer srtmDem;
 
-- 
GitLab