From 1fcbde84aae8e32894709757c2eba594c999d867 Mon Sep 17 00:00:00 2001
From: Christophe Palmann <christophe.palmann@c-s.fr>
Date: Thu, 19 Mar 2015 11:14:23 +0100
Subject: [PATCH] COMP: fixed comp. of other tests when OTB_USE_LIBSVM and
 OTB_USE_OPENCV are turned off

---
 .../test/otbMachineLearningModelCanRead.cxx   | 34 +++++++++++++++++++
 .../test/otbSupervisedTestDriver.cxx          | 13 +++++++
 .../test/otbTrainMachineLearningModel.cxx     | 11 ++++++
 3 files changed, 58 insertions(+)

diff --git a/Modules/Learning/Supervised/test/otbMachineLearningModelCanRead.cxx b/Modules/Learning/Supervised/test/otbMachineLearningModelCanRead.cxx
index 752f5895d5..4749acfa32 100644
--- a/Modules/Learning/Supervised/test/otbMachineLearningModelCanRead.cxx
+++ b/Modules/Learning/Supervised/test/otbMachineLearningModelCanRead.cxx
@@ -17,7 +17,13 @@
 =========================================================================*/
 
 #include <iostream>
+
+#include <otbMachineLearningModel.h>
+
+#ifdef OTB_USE_LIBSVM
 #include "otbLibSVMMachineLearningModel.h"
+#endif
+#ifdef OTB_USE_OPENCV
 #include "otbSVMMachineLearningModel.h"
 #include "otbRandomForestsMachineLearningModel.h"
 #include "otbBoostMachineLearningModel.h"
@@ -26,6 +32,7 @@
 #include "otbDecisionTreeMachineLearningModel.h"
 #include "otbGradientBoostedTreeMachineLearningModel.h"
 #include "otbKNearestNeighborsMachineLearningModel.h"
+#endif
 
 typedef otb::MachineLearningModel<float,short>         MachineLearningModelType;
 typedef MachineLearningModelType::InputValueType       InputValueType;
@@ -49,6 +56,8 @@ int otbLibSVMMachineLearningModelCanRead(int argc, char* argv[])
     return EXIT_FAILURE;
     }
   std::string filename(argv[1]);
+  
+  #ifdef OTB_USE_LIBSVM
   typedef otb::LibSVMMachineLearningModel<InputValueType, TargetValueType> SVMType;
   SVMType::Pointer classifier = SVMType::New();
   bool lCanRead = classifier->CanReadFile(filename);
@@ -57,6 +66,7 @@ int otbLibSVMMachineLearningModelCanRead(int argc, char* argv[])
     std::cerr << "Erreur otb::LibSVMMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
     return EXIT_FAILURE;
     }
+  #endif
 
   return EXIT_SUCCESS;
 }
@@ -75,6 +85,8 @@ int otbSVMMachineLearningModelCanRead(int argc, char* argv[])
     return EXIT_FAILURE;
     }
   std::string filename(argv[1]);
+  
+  #ifdef OTB_USE_OPENCV
   typedef otb::SVMMachineLearningModel<InputValueType, TargetValueType> SVMType;
   SVMType::Pointer classifier = SVMType::New();
   bool lCanRead = classifier->CanReadFile(filename);
@@ -83,6 +95,7 @@ int otbSVMMachineLearningModelCanRead(int argc, char* argv[])
     std::cerr << "Erreur otb::SVMMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
     return EXIT_FAILURE;
     }
+  #endif
 
   return EXIT_SUCCESS;
 }
@@ -101,6 +114,8 @@ int otbRandomForestsMachineLearningModelCanRead(int argc, char* argv[])
     return EXIT_FAILURE;
     }
   std::string filename(argv[1]);
+  
+  #ifdef OTB_USE_OPENCV
   typedef otb::RandomForestsMachineLearningModel<InputValueType, TargetValueType> RFType;
   RFType::Pointer classifier = RFType::New();
   bool lCanRead = classifier->CanReadFile(filename);
@@ -109,6 +124,7 @@ int otbRandomForestsMachineLearningModelCanRead(int argc, char* argv[])
     std::cerr << "Erreur otb::RandomForestsMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
     return EXIT_FAILURE;
     }
+  #endif
 
   return EXIT_SUCCESS;
 }
@@ -127,6 +143,8 @@ int otbBoostMachineLearningModelCanRead(int argc, char* argv[])
     return EXIT_FAILURE;
     }
   std::string filename(argv[1]);
+  
+  #ifdef OTB_USE_OPENCV
   typedef otb::BoostMachineLearningModel<InputValueType, TargetValueType> BoostType;
   BoostType::Pointer classifier = BoostType::New();
   bool lCanRead = classifier->CanReadFile(filename);
@@ -135,6 +153,7 @@ int otbBoostMachineLearningModelCanRead(int argc, char* argv[])
     std::cerr << "Erreur otb::BoostMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
     return EXIT_FAILURE;
     }
+  #endif
 
   return EXIT_SUCCESS;
 }
@@ -153,6 +172,8 @@ int otbNeuralNetworkMachineLearningModelCanRead(int argc, char* argv[])
     return EXIT_FAILURE;
     }
   std::string filename(argv[1]);
+  
+  #ifdef OTB_USE_OPENCV
   typedef otb::NeuralNetworkMachineLearningModel<InputValueType, TargetValueType> ANNType;
   ANNType::Pointer classifier = ANNType::New();
   bool lCanRead = classifier->CanReadFile(filename);
@@ -161,6 +182,7 @@ int otbNeuralNetworkMachineLearningModelCanRead(int argc, char* argv[])
     std::cerr << "Erreur otb::NeuralNetworkMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
     return EXIT_FAILURE;
     }
+  #endif
 
   return EXIT_SUCCESS;
 }
@@ -179,6 +201,8 @@ int otbNormalBayesMachineLearningModelCanRead(int argc, char* argv[])
     return EXIT_FAILURE;
     }
   std::string filename(argv[1]);
+  
+  #ifdef OTB_USE_OPENCV
   typedef otb::NormalBayesMachineLearningModel<InputValueType, TargetValueType> NormalBayesType;
   NormalBayesType::Pointer classifier = NormalBayesType::New();
   bool lCanRead = classifier->CanReadFile(filename);
@@ -187,6 +211,7 @@ int otbNormalBayesMachineLearningModelCanRead(int argc, char* argv[])
     std::cerr << "Erreur otb::NormalBayesMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
     return EXIT_FAILURE;
     }
+  #endif
 
   return EXIT_SUCCESS;
 }
@@ -205,6 +230,8 @@ int otbDecisionTreeMachineLearningModelCanRead(int argc, char* argv[])
     return EXIT_FAILURE;
     }
   std::string filename(argv[1]);
+  
+  #ifdef OTB_USE_OPENCV
   typedef otb::DecisionTreeMachineLearningModel<InputValueType, TargetValueType> DecisionTreeType;
   DecisionTreeType::Pointer classifier = DecisionTreeType::New();
   bool lCanRead = classifier->CanReadFile(filename);
@@ -213,6 +240,7 @@ int otbDecisionTreeMachineLearningModelCanRead(int argc, char* argv[])
     std::cerr << "Erreur otb::DecisionTreeMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
     return EXIT_FAILURE;
     }
+  #endif
 
   return EXIT_SUCCESS;
 }
@@ -231,6 +259,8 @@ int otbGradientBoostedTreeMachineLearningModelCanRead(int argc, char* argv[])
     return EXIT_FAILURE;
     }
   std::string filename(argv[1]);
+  
+  #ifdef OTB_USE_OPENCV
   typedef otb::GradientBoostedTreeMachineLearningModel<InputValueType, TargetValueType> GBTreeType;
   GBTreeType::Pointer classifier = GBTreeType::New();
   bool lCanRead = classifier->CanReadFile(filename);
@@ -239,6 +269,7 @@ int otbGradientBoostedTreeMachineLearningModelCanRead(int argc, char* argv[])
     std::cerr << "Erreur otb::GradientBoostedTreeMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
     return EXIT_FAILURE;
     }
+  #endif
 
   return EXIT_SUCCESS;
 }
@@ -257,6 +288,8 @@ int otbKNNMachineLearningModelCanRead(int argc, char* argv[])
     return EXIT_FAILURE;
     }
   std::string filename(argv[1]);
+  
+  #ifdef OTB_USE_OPENCV
   typedef otb::KNearestNeighborsMachineLearningModel<InputValueType, TargetValueType> KNNType;
   KNNType::Pointer classifier = KNNType::New();
   bool lCanRead = classifier->CanReadFile(filename);
@@ -265,6 +298,7 @@ int otbKNNMachineLearningModelCanRead(int argc, char* argv[])
     std::cerr << "Erreur otb::KNearestNeighborsMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
     return EXIT_FAILURE;
     }
+  #endif
 
   return EXIT_SUCCESS;
 }
diff --git a/Modules/Learning/Supervised/test/otbSupervisedTestDriver.cxx b/Modules/Learning/Supervised/test/otbSupervisedTestDriver.cxx
index b9de86d89b..e498bd082e 100644
--- a/Modules/Learning/Supervised/test/otbSupervisedTestDriver.cxx
+++ b/Modules/Learning/Supervised/test/otbSupervisedTestDriver.cxx
@@ -9,7 +9,12 @@ void RegisterTests()
   REGISTER_TEST(otbConfusionMatrixMeasurementsNew);
   REGISTER_TEST(otbConfusionMatrixMeasurementsTest);
   REGISTER_TEST(otbConfusionMatrixConcatenateTest);
+  
+  #ifdef OTB_USE_LIBSVM
   REGISTER_TEST(otbLibSVMMachineLearningModelCanRead);
+  #endif
+  
+  #ifdef OTB_USE_OPENCV
   REGISTER_TEST(otbSVMMachineLearningModelCanRead);
   REGISTER_TEST(otbRandomForestsMachineLearningModelCanRead);
   REGISTER_TEST(otbBoostMachineLearningModelCanRead);
@@ -18,8 +23,14 @@ void RegisterTests()
   REGISTER_TEST(otbDecisionTreeMachineLearningModelCanRead);
   REGISTER_TEST(otbGradientBoostedTreeMachineLearningModelCanRead);
   REGISTER_TEST(otbKNNMachineLearningModelCanRead);
+  #endif
+  
+  #ifdef OTB_USE_LIBSVM
   REGISTER_TEST(otbLibSVMMachineLearningModelNew);
   REGISTER_TEST(otbLibSVMMachineLearningModel);
+  #endif
+  
+  #ifdef OTB_USE_OPENCV
   REGISTER_TEST(otbSVMMachineLearningModelNew);
   REGISTER_TEST(otbSVMMachineLearningModel);
   REGISTER_TEST(otbSVMMachineLearningRegressionModel);
@@ -37,6 +48,8 @@ void RegisterTests()
   REGISTER_TEST(otbDecisionTreeMachineLearningModel);
   REGISTER_TEST(otbGradientBoostedTreeMachineLearningModelNew);
   REGISTER_TEST(otbGradientBoostedTreeMachineLearningModel);
+  #endif
+  
   REGISTER_TEST(otbImageClassificationFilterNew);
   REGISTER_TEST(otbImageClassificationFilter);
 }
diff --git a/Modules/Learning/Supervised/test/otbTrainMachineLearningModel.cxx b/Modules/Learning/Supervised/test/otbTrainMachineLearningModel.cxx
index 24d984b096..f824e00981 100644
--- a/Modules/Learning/Supervised/test/otbTrainMachineLearningModel.cxx
+++ b/Modules/Learning/Supervised/test/otbTrainMachineLearningModel.cxx
@@ -20,7 +20,13 @@
 #include <string>
 #include <algorithm>
 
+#include <otbMachineLearningModel.h>
+
+#ifdef OTB_USE_LIBSVM
 #include "otbLibSVMMachineLearningModel.h"
+#endif
+
+#ifdef OTB_USE_OPENCV
 #include "otbSVMMachineLearningModel.h"
 #include "otbKNearestNeighborsMachineLearningModel.h"
 #include "otbRandomForestsMachineLearningModel.h"
@@ -30,6 +36,7 @@
 #include "otbDecisionTreeMachineLearningModel.h"
 #include "otbGradientBoostedTreeMachineLearningModel.h"
 #include "otbKNearestNeighborsMachineLearningModel.h"
+#endif
 
 #include "otbConfusionMatrixCalculator.h"
 
@@ -188,6 +195,7 @@ bool ReadDataRegressionFile(const std::string & infname, InputListSampleRegressi
   return true;
 }
 
+#ifdef OTB_USE_LIBSVM
 int otbLibSVMMachineLearningModelNew(int itkNotUsed(argc), char * itkNotUsed(argv) [])
 {
   typedef otb::LibSVMMachineLearningModel<InputValueType, TargetValueType> SVMType;
@@ -276,7 +284,9 @@ int otbSVMMachineLearningModelNew(int itkNotUsed(argc), char * itkNotUsed(argv)
   SVMType::Pointer svmclassifier = SVMType::New();
   return EXIT_SUCCESS;
 }
+#endif
 
+#ifdef OTB_USE_OPENCV
 int otbSVMMachineLearningModel(int argc, char * argv[])
 {
   if (argc != 3 )
@@ -1036,3 +1046,4 @@ int otbGradientBoostedTreeMachineLearningModel(int argc, char * argv[])
     return EXIT_FAILURE;
     }
 }
+#endif
-- 
GitLab