From d911771cc1999ea22a2d4c1cf9184cec319bb548 Mon Sep 17 00:00:00 2001
From: Cyrille Valladeau <cyrille.valladeau@c-s.fr>
Date: Fri, 4 Nov 2011 16:01:28 +0100
Subject: [PATCH] ENH: add Minimum/MximumParameterValue

---
 .../otbRadiometricVegetationIndices.cxx       |  8 +--
 Applications/Util/otbExtractROI.cxx           | 16 +++---
 .../otbWrapperApplication.cxx                 | 55 +++++++++++++++++++
 .../ApplicationEngine/otbWrapperApplication.h | 35 ++++++++++++
 4 files changed, 102 insertions(+), 12 deletions(-)

diff --git a/Applications/RadiometricIndices/otbRadiometricVegetationIndices.cxx b/Applications/RadiometricIndices/otbRadiometricVegetationIndices.cxx
index b4a71765f9..c52fd45f57 100644
--- a/Applications/RadiometricIndices/otbRadiometricVegetationIndices.cxx
+++ b/Applications/RadiometricIndices/otbRadiometricVegetationIndices.cxx
@@ -177,10 +177,10 @@ private:
     if ( HasValue("in") )
       {
        // Put the limit of the channel indices
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("channels.red"))->SetMinimumValue(1);
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("channels.red"))->SetMaximumValue(GetParameterImage("in")->GetNumberOfComponentsPerPixel());
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("channels.nir"))->SetMinimumValue(1);
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("channels.nir"))->SetMaximumValue(GetParameterImage("in")->GetNumberOfComponentsPerPixel());
+      SetMinimumValue("channels.red", 1);
+      SetMaximumValue("channels.red", GetParameterImage("in")->GetNumberOfComponentsPerPixel());
+      SetMinimumValue("channels.nir", 1);
+      SetMaximumValue("channels.nir", GetParameterImage("in")->GetNumberOfComponentsPerPixel());
       }
   }
 
diff --git a/Applications/Util/otbExtractROI.cxx b/Applications/Util/otbExtractROI.cxx
index ac73260f00..73bfc1dd4f 100644
--- a/Applications/Util/otbExtractROI.cxx
+++ b/Applications/Util/otbExtractROI.cxx
@@ -123,17 +123,17 @@ private:
         }
       
       // Put the limit of the index and the size relative the image
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizex"))->SetMinimumValue(0);
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizex"))->SetMaximumValue(largestRegion.GetSize(0));
+      SetMinimumValue("sizex", 0);
+      SetMaximumValue("sizex", largestRegion.GetSize(0));
 
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizey"))->SetMinimumValue(0);
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("sizey"))->SetMaximumValue(largestRegion.GetSize(1));
+      SetMinimumValue("sizey", 0);
+      SetMaximumValue("sizey", largestRegion.GetSize(1));
 
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("startx"))->SetMinimumValue(0);
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("startx"))->SetMaximumValue(largestRegion.GetSize(0));
+      SetMinimumValue("startx", 0);
+      SetMaximumValue("startx", largestRegion.GetSize(0));
         
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("starty"))->SetMinimumValue(0);
-      dynamic_cast< NumericalParameter<int> * >(GetParameterByKey("starty"))->SetMaximumValue(largestRegion.GetSize(1));
+      SetMinimumValue("starty", 0);
+      SetMaximumValue("starty", largestRegion.GetSize(1));
     
       // Crop the roi region to be included in the largest possible
       // region
diff --git a/Code/ApplicationEngine/otbWrapperApplication.cxx b/Code/ApplicationEngine/otbWrapperApplication.cxx
index afacb4c9e0..26fabf2307 100644
--- a/Code/ApplicationEngine/otbWrapperApplication.cxx
+++ b/Code/ApplicationEngine/otbWrapperApplication.cxx
@@ -512,6 +512,61 @@ void Application::SetDefaultParameterFloat(std::string parameter, float value)
     }
 }
 
+void Application::SetMinimumParameterValue(std::string parameter, int value)
+{
+  Parameter* param = GetParameterByKey(parameter);
+
+  if (dynamic_cast<IntParameter*>(param))
+    {
+    IntParameter* paramInt = dynamic_cast<IntParameter*>(param);
+    paramInt->SetMinimumValue(value);
+    }
+ else
+    itkExceptionMacro(<<parameter << "parameter can't be casted to int");
+}
+
+void Application::SetMaximumParameterValue(std::string parameter, int value)
+{
+  Parameter* param = GetParameterByKey(parameter);
+
+  if (dynamic_cast<IntParameter*>(param))
+    {
+    IntParameter* paramInt = dynamic_cast<IntParameter*>(param);
+    paramInt->SetMaximumValue(value);
+    }
+  else
+    itkExceptionMacro(<<parameter << "parameter can't be casted to int");
+  
+}
+
+void Application::SetMinimumParameterValue(std::string parameter, float value)
+{
+  Parameter* param = GetParameterByKey(parameter);
+
+  if (dynamic_cast<FloatParameter*>(param))
+    {
+    FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param);
+    paramFloat->SetMinimumValue(value);
+    }
+ else
+    itkExceptionMacro(<<parameter << "parameter can't be casted to float");
+}
+
+void Application::SetMaximumParameterValue(std::string parameter, float value)
+{
+  Parameter* param = GetParameterByKey(parameter);
+
+  if (dynamic_cast<FloatParameter*>(param))
+    {
+    FloatParameter* paramFloat = dynamic_cast<FloatParameter*>(param);
+    paramFloat->SetMaximumValue(value);
+    }
+  else
+    itkExceptionMacro(<<parameter << "parameter can't be casted to float");
+  
+}
+
+
 void Application::SetParameterString(std::string parameter, std::string value)
 {
   Parameter* param = GetParameterByKey(parameter);
diff --git a/Code/ApplicationEngine/otbWrapperApplication.h b/Code/ApplicationEngine/otbWrapperApplication.h
index ba2e91959c..d8bc71bf32 100644
--- a/Code/ApplicationEngine/otbWrapperApplication.h
+++ b/Code/ApplicationEngine/otbWrapperApplication.h
@@ -209,6 +209,41 @@ public:
    */
   void SetDefaultParameterFloat(std::string parameter, float value);
 
+ /* Set a minimum int value, must used in the
+   * DoCreateParameters when setting a value by default
+   * for the parameter
+   *
+   * Can be called for types :
+   * \li ParameterType_Int
+   */
+  void SetMinimumParameterValue(std::string parameter, int value);
+
+ /* Set a maximum int value, must used in the
+   * DoCreateParameters when setting a value by default
+   * for the parameter
+   *
+   * Can be called for types :
+   * \li ParameterType_Int
+   */
+  void SetMaximumParameterValue(std::string parameter, int value);
+
+ /* Set a minimum int value, must used in the
+   * DoCreateParameters when setting a value by default
+   * for the parameter
+   *
+   * Can be called for types :
+   * \li ParameterType_Float
+   */
+  void SetMinimumParameterValue(std::string parameter, float value);
+
+ /* Set a maximum int value, must used in the
+   * DoCreateParameters when setting a value by default
+   * for the parameter
+   *
+   * Can be called for types :
+   * \li ParameterType_Float
+   */
+  void SetMaximumParameterValue(std::string parameter, float value);
 
   /* Set a string value
    *
-- 
GitLab