From d6f659c08ec227f8a42b9cc682f3385cc9e21c87 Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Tue, 13 Dec 2011 11:36:18 +0100
Subject: [PATCH] ENH: use ElevationParametersHandler to manage elevation
 params

---
 .../otbStereoSensorModelToElevationMap.cxx    |  5 ++-
 .../otbLineSegmentDetection.cxx               | 39 ++++++++++------
 .../Projections/otbBundleToPerfectSensor.cxx  |  1 +
 .../otbConnectedComponentSegmentation.cxx     | 35 +++++++++------
 .../otbVectorDataExtractROIApplication.cxx    | 45 ++++++++++---------
 5 files changed, 76 insertions(+), 49 deletions(-)

diff --git a/Applications/DisparityMap/otbStereoSensorModelToElevationMap.cxx b/Applications/DisparityMap/otbStereoSensorModelToElevationMap.cxx
index fea008022b..39fcfdf0af 100644
--- a/Applications/DisparityMap/otbStereoSensorModelToElevationMap.cxx
+++ b/Applications/DisparityMap/otbStereoSensorModelToElevationMap.cxx
@@ -158,8 +158,9 @@ private:
    SetDocExampleParameterValue("ref", "sensor_stereo_left.tif");
    SetDocExampleParameterValue("sec", "sensor_stereo_right.tif");
    SetDocExampleParameterValue("out", "StereoSensorModelToElevationMap.tif");
-   SetDocExampleParameterValue("dem", "DEM");
-   SetDocExampleParameterValue("geoid", "egm96.grd");
+   SetDocExampleParameterValue("elev", "dem");
+   SetDocExampleParameterValue("elev.dem.path", "dem");
+   SetDocExampleParameterValue("elev.dem.geoid", "egm96.grd");
   }
 
   void DoUpdateParameters()
diff --git a/Applications/FeatureExtraction/otbLineSegmentDetection.cxx b/Applications/FeatureExtraction/otbLineSegmentDetection.cxx
index 82396a495c..d43276b6fc 100644
--- a/Applications/FeatureExtraction/otbLineSegmentDetection.cxx
+++ b/Applications/FeatureExtraction/otbLineSegmentDetection.cxx
@@ -29,6 +29,8 @@
 #include "otbVectorDataTransformFilter.h"
 #include "itkAffineTransform.h"
 
+// Elevation handler
+#include "otbWrapperElevationParametersHandler.h"
 
 namespace otb
 {
@@ -68,8 +70,9 @@ private:
 
     AddParameter(ParameterType_OutputVectorData, "out", "Output Detected lines");
     SetParameterDescription("out"," Output detected line segments (vector data).");
-    AddParameter(ParameterType_Directory, "dem", "Digital Elevation Model directory");
-    MandatoryOff("dem");
+
+    // Elevation
+    ElevationParametersHandler::AddElevationParameters(this, "elev");
 
     AddParameter(ParameterType_Empty, "norescale", "No rescaling in [0, 255]");
     MandatoryOff("norescale");
@@ -163,18 +166,26 @@ private:
       vproj->SetInputOrigin(GetParameterImage("in")->GetOrigin());
       vproj->SetInputSpacing(GetParameterImage("in")->GetSpacing());
 
-      // Configure DEM directory
-      if(IsParameterEnabled("dem"))
-        {
-        vproj->SetDEMDirectory( GetParameterString("dem") );
-        }
-      else
-        {
-        if ( otb::ConfigurationFile::GetInstance()->IsValid() )
-          {
-          vproj->SetDEMDirectory(otb::ConfigurationFile::GetInstance()->GetDEMDirectory());
-          }
-        }
+    // Elevation through the elevation handler
+    switch(ElevationParametersHandler::GetElevationType(this, "elev"))
+      {
+      case Elevation_DEM:
+      {
+      vproj->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
+      vproj->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
+      }
+      break;
+      case Elevation_Average:
+      {
+      vproj->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
+      }
+      break;
+      //   Commented cause using a tiff file is not implemented yet
+      //  case Elevation_Tiff:
+      //  {
+      //  }
+      //  break;
+      }
 
       AddProcess(vproj, "Reprojecting output vector data");
       vproj->Update();
diff --git a/Applications/Projections/otbBundleToPerfectSensor.cxx b/Applications/Projections/otbBundleToPerfectSensor.cxx
index 046ee2157d..5ebc029b08 100644
--- a/Applications/Projections/otbBundleToPerfectSensor.cxx
+++ b/Applications/Projections/otbBundleToPerfectSensor.cxx
@@ -68,6 +68,7 @@ private:
 
     AddParameter(ParameterType_InputImage,   "inp",   "Input PAN Image");
     AddParameter(ParameterType_InputImage,   "inxs",  "Input XS Image");
+
     // Elevation
     ElevationParametersHandler::AddElevationParameters(this, "elev");
 
diff --git a/Applications/Segmentation/otbConnectedComponentSegmentation.cxx b/Applications/Segmentation/otbConnectedComponentSegmentation.cxx
index 36c615ce6e..2f9e151dfd 100644
--- a/Applications/Segmentation/otbConnectedComponentSegmentation.cxx
+++ b/Applications/Segmentation/otbConnectedComponentSegmentation.cxx
@@ -25,6 +25,9 @@
 
 #include "otbVectorDataProjectionFilter.h"
 
+// Elevation handler
+#include "otbWrapperElevationParametersHandler.h"
+
 namespace otb
 {
 namespace Wrapper
@@ -103,10 +106,8 @@ private:
     MandatoryOff("obia");
     DisableParameter("obia");
     
-    AddParameter(ParameterType_Directory, "dem", "DEM Directory");
-    SetParameterDescription("dem", "DEM directory (used to reproject output in WGS84 if input image is in sensor model geometry)");
-    MandatoryOff("dem");
-    DisableParameter("dem");
+    // Elevation
+    ElevationParametersHandler::AddElevationParameters(this, "elev");
 
    // Doc example parameter settings
    SetDocExampleParameterValue("in", "ROI_QB_MUL_4.tif");
@@ -166,18 +167,26 @@ private:
       m_Vproj->SetInputKeywordList(inputImage->GetImageKeywordlist());
       m_Vproj->SetInputOrigin(inputImage->GetOrigin());
       m_Vproj->SetInputSpacing(inputImage->GetSpacing());
-      
-      // Configure DEM directory
-      if(IsParameterEnabled("dem") && HasValue("dem"))
+
+      // Elevation through the elevation handler
+      switch(ElevationParametersHandler::GetElevationType(this, "elev"))
         {
-        m_Vproj->SetDEMDirectory(GetParameterString("dem"));
+        case Elevation_DEM:
+        {
+        m_Vproj->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
+        m_Vproj->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
         }
-      else
+        break;
+        case Elevation_Average:
         {
-        if ( otb::ConfigurationFile::GetInstance()->IsValid() )
-          {
-          m_Vproj->SetDEMDirectory(otb::ConfigurationFile::GetInstance()->GetDEMDirectory());
-          }
+        m_Vproj->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
+        }
+        break;
+        //   Commented cause using a tiff file is not implemented yet
+        //  case Elevation_Tiff:
+        //  {
+        //  }
+        //  break;
         }
       
       m_Vproj->Update();
diff --git a/Applications/Utils/otbVectorDataExtractROIApplication.cxx b/Applications/Utils/otbVectorDataExtractROIApplication.cxx
index 6cda0af93f..e6a93d635c 100644
--- a/Applications/Utils/otbVectorDataExtractROIApplication.cxx
+++ b/Applications/Utils/otbVectorDataExtractROIApplication.cxx
@@ -25,6 +25,9 @@
 //Misc
 #include "otbRemoteSensingRegion.h"
 
+// Elevation handler
+#include "otbWrapperElevationParametersHandler.h"
+
 #include <iostream>
 
 namespace otb
@@ -79,17 +82,9 @@ private:
     AddParameter(ParameterType_InputVectorData, "io.vd", "Input Vector data");
     AddParameter(ParameterType_InputImage,      "io.in", "Support image");
     AddParameter(ParameterType_OutputVectorData,"io.out","Output Vector data");
-    
-    AddParameter(ParameterType_Group,"elev","Elevation management");
-    SetParameterDescription("elev","This group of parameters allows to manage elevation values in the VectorData projection process");
 
-    AddParameter(ParameterType_Directory, "elev.dem",   "DEM directory");
-    std::ostringstream oss;
-    oss << "This parameter allows to select a directory containing ";
-    oss << "Digital Elevation Model tiles. Supported formats are SRTM, DTED ";
-    oss << "or any geotiff processed by the DEM import application";
-    SetParameterDescription("elev.dem", oss.str());
-    MandatoryOff("elev.dem");
+    // Elevation
+    ElevationParametersHandler::AddElevationParameters(this, "elev");
 
     // Doc example parameter settings
     SetDocExampleParameterValue("io.in", "QB_Toulouse_Ortho_XS.tif");
@@ -157,19 +152,29 @@ private:
     m_VdProj->SetOutputOrigin(inImage->GetOrigin());
     m_VdProj->SetOutputSpacing(inImage->GetSpacing());
 
-    // Set the DEM directory if used
-    if (IsParameterEnabled("elev.dem") && HasValue("elev.dem"))
+     // Elevation through the elevation handler
+    switch(ElevationParametersHandler::GetElevationType(this, "elev"))
+      {
+      case Elevation_DEM:
       {
-      m_VdExtract->SetDEMDirectory(GetParameterString("elev.dem"));
-      m_VdProj->SetDEMDirectory(GetParameterString("elev.dem"));
+      m_VdExtract->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
+      m_VdExtract->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
+
+      m_VdProj->SetDEMDirectory(ElevationParametersHandler::GetDEMDirectory(this, "elev"));
+      m_VdProj->SetGeoidFile(ElevationParametersHandler::GetGeoidFile(this, "elev"));
       }
-    else
+      break;
+      case Elevation_Average:
       {
-      if ( otb::ConfigurationFile::GetInstance()->IsValid() )
-        {
-        m_VdExtract->SetDEMDirectory(otb::ConfigurationFile::GetInstance()->GetDEMDirectory());
-        m_VdProj->SetDEMDirectory(otb::ConfigurationFile::GetInstance()->GetDEMDirectory());
-        }
+      m_VdExtract->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
+      m_VdProj->SetAverageElevation(ElevationParametersHandler::GetAverageElevation(this, "elev"));
+      }
+      break;
+      //   Commented cause using a tiff file is not implemented yet
+      //  case Elevation_Tiff:
+      //  {
+      //  }
+      //  break;
       }
     
     // Set the output vectorData
-- 
GitLab