From f2227de9eaa0f46d4bee84f8ef6efb2effa97f35 Mon Sep 17 00:00:00 2001
From: Ludovic Hussonnois <ludovic.hussonnois@c-s.fr>
Date: Tue, 18 Apr 2017 18:12:42 +0200
Subject: [PATCH] BUG: Apply missing BUG correction from develop merge.

BUG: maximum train and validation sizes were not correctly handled
(ac57432192c56a03d4cceb92c1f154910675e258)

BUG: fix TrainImagesClassifier when bm=0.
(2a3cce865a1efe1d89df3fc4318ba87fe671dc0e)
---
 .../include/otbTrainImagesBase.txx            | 21 ++++++++++++-------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/Modules/Applications/AppClassification/include/otbTrainImagesBase.txx b/Modules/Applications/AppClassification/include/otbTrainImagesBase.txx
index 243086d2de..deb34bfc73 100644
--- a/Modules/Applications/AppClassification/include/otbTrainImagesBase.txx
+++ b/Modules/Applications/AppClassification/include/otbTrainImagesBase.txx
@@ -196,17 +196,20 @@ TrainImagesBase::SamplingRates TrainImagesBase::ComputeFinalMaximumSamplingRates
       // only fmt will be used for both training and validation samples
       // So we try to compute the total number of samples given input
       // parameters mt, mv and vtr.
-      if( mt > -1 && mv > -1 )
-        {
-        rates.fmt = mt + mv;
-        }
-      if( mt > -1 && mv <= -1 && vtr < 0.99999 )
+      if( mt > -1 && vtr < 0.99999 )
         {
         rates.fmt = static_cast<long>(( double ) mt / ( 1.0 - vtr ));
         }
-      if( mt <= -1 && mv > -1 && vtr > 0.00001 )
+      if( mv > -1 && vtr > 0.00001 )
         {
-        rates.fmt = static_cast<long>(( double ) mv / vtr);
+        if( rates.fmt > -1 )
+          {
+          rates.fmt = std::min( rates.fmt, static_cast<long>(( double ) mv / vtr) );
+          }
+        else
+          {
+          rates.fmt = static_cast<long>(( double ) mv / vtr);
+          }
         }
       }
     }
@@ -228,8 +231,10 @@ void TrainImagesBase::ComputeSamplingRate(const std::vector<std::string> &statis
     {
     if( maximum > -1 )
       {
+      std::ostringstream oss;
+      oss << maximum;
       GetInternalApplication( "rates" )->SetParameterString( "strategy", "constant", false );
-      GetInternalApplication( "rates" )->SetParameterInt( "strategy.constant.nb", static_cast<int>(maximum), false );
+      GetInternalApplication( "rates" )->SetParameterString( "strategy.constant.nb", oss.str(), false );
       }
     else
       {
-- 
GitLab