From 5ae5a17dc7746aa382d9d6188c0c65a37b776865 Mon Sep 17 00:00:00 2001
From: Antoine Regimbeau <antoine.regimbeau@c-s.fr>
Date: Tue, 30 Jul 2019 12:56:51 +0200
Subject: [PATCH] ENH: make GlobalStatsDetected public and allow returning
 empty expression

---
 .../include/otbBandMathXImageFilter.h            | 15 ++++++++-------
 .../include/otbBandMathXImageFilter.hxx          | 16 ++++++++++++----
 2 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/Modules/Filtering/MathParserX/include/otbBandMathXImageFilter.h b/Modules/Filtering/MathParserX/include/otbBandMathXImageFilter.h
index 9822cd6ab7..ce76dd8e44 100644
--- a/Modules/Filtering/MathParserX/include/otbBandMathXImageFilter.h
+++ b/Modules/Filtering/MathParserX/include/otbBandMathXImageFilter.h
@@ -112,8 +112,8 @@ public:
   /** Set an expression to be parsed */
   void SetExpression(const std::string& expression);
 
-  /** Return the nth expression to be parsed */
-  std::string GetExpression(int) const;
+  /** Return the nth expression to be parsed*/
+  std::string GetExpression(unsigned int IDExpression) const;
 
   /** Set a matrix (or a vector) */
   void SetMatrix(const std::string& name, const std::string& definition);
@@ -127,9 +127,15 @@ public:
   /** Import constants and expressions from a given filename */
   void ImportContext(const std::string& filename);
 
+  /** Clear all previously set expression*/
+  void ClearExpression();
   /** Return the variable and constant names */
   std::vector<std::string> GetVarNames() const;
 
+  bool GlobalStatsDetected() const
+  {
+    return !m_StatsVarDetected.empty();
+  }
 
 protected :
   BandMathXImageFilter();
@@ -145,11 +151,6 @@ protected :
 
 private :
 
-  bool globalStatsDetected() const
-  {
-    return (m_StatsVarDetected.size()>0);
-  }
-
   typedef struct {
       std::string name;
       ValueType   value;
diff --git a/Modules/Filtering/MathParserX/include/otbBandMathXImageFilter.hxx b/Modules/Filtering/MathParserX/include/otbBandMathXImageFilter.hxx
index 6092926c7d..44cde5bed7 100644
--- a/Modules/Filtering/MathParserX/include/otbBandMathXImageFilter.hxx
+++ b/Modules/Filtering/MathParserX/include/otbBandMathXImageFilter.hxx
@@ -261,7 +261,13 @@ void BandMathXImageFilter<TImage>
   this->Modified();
 }
 
-
+template< typename TImage >
+void BandMathXImageFilter<TImage>
+::ClearExpression()
+{
+  m_Expression.clear();
+  this->Modified();
+}
 template< typename TImage >
 void BandMathXImageFilter<TImage>
 ::SetMatrix(const std::string& name, const std::string& definition)
@@ -517,9 +523,11 @@ void BandMathXImageFilter<TImage>
 
 template< typename TImage >
 std::string BandMathXImageFilter<TImage>
-::GetExpression(int IDExpression) const
+::GetExpression(unsigned int IDExpression) const
 {
-  return m_Expression[IDExpression];
+  if ( IDExpression < m_Expression.size() )
+    return m_Expression[IDExpression];
+  return "";
 }
 
 
@@ -913,7 +921,7 @@ void BandMathXImageFilter< TImage >
 
   CheckImageDimensions();
   PrepareParsers();
-  if (globalStatsDetected())
+  if (GlobalStatsDetected())
     PrepareParsersGlobStats();
   OutputsDimensions();
 
-- 
GitLab