diff --git a/Examples/ChangeDetection/KullbackLeiblerSupervizedDistanceChDet.cxx b/Examples/ChangeDetection/KullbackLeiblerSupervizedDistanceChDet.cxx index 8e2b1129658efdea2616f7567cdac0455d64d787..fb327afb05e9d12a9e54d71520ca6fc441abccc9 100644 --- a/Examples/ChangeDetection/KullbackLeiblerSupervizedDistanceChDet.cxx +++ b/Examples/ChangeDetection/KullbackLeiblerSupervizedDistanceChDet.cxx @@ -26,7 +26,6 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" #include "otbKullbackLeiblerSupervizedDistanceImageFilter.h" @@ -34,36 +33,13 @@ int main(int argc, char * argv[]) { try { - - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - parser->AddOption("--InputImage1", "Give Before image", "-1", 1, true); - parser->AddOption("--InputImage2", "Give After image", "-2", 1, true); - parser->AddOption("--Roi", "Give ROI image", "-r", 1, true); - parser->AddOption("--winSize", - "Sliding window size (def. 35)", - "-w", - 1, - false); - parser->AddOutputImage(); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine(argc, argv, parseResult); - } - catch (itk::ExceptionObject& err) + if( argc < 5 ) { - std::string descriptionException = err.GetDescription(); - if (descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos) return EXIT_SUCCESS; - if (descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos) return EXIT_SUCCESS; + std::cerr << "Usage: " << argv[0]; + std::cerr << "inputNameImage1 inputNameImage2 ROIImageName outputName "; + std::cerr << "[winSize=35]"; return EXIT_FAILURE; } - /* * Types declaration */ @@ -83,18 +59,14 @@ int main(int argc, char * argv[]) * Extract command line parameters */ - std::string inputImageFileName1 = parseResult->GetParameterString( - "--InputImage1"); - std::string inputImageFileName2 = parseResult->GetParameterString( - "--InputImage2"); - std::string inputTrainingImageFileName = parseResult->GetParameterString( - "--Roi"); - std::string outputImageFileName = parseResult->GetOutputImage(); + std::string inputImageFileName1 = argv[1]; + std::string inputImageFileName2 = argv[2]; + std::string inputTrainingImageFileName = argv[3]; + std::string outputImageFileName = argv[4]; int winSize = 35; - if (parseResult->IsOptionPresent("--winSize")) - winSize = - parseResult->GetParameterInt("--winSize"); + if ( argc == 6 ) + winSize = std::stoi(argv[5]); /* * JustDoIt diff --git a/Examples/DisparityMap/NCCRegistrationFilterExample.cxx b/Examples/DisparityMap/NCCRegistrationFilterExample.cxx index ea80a671d47eecafd2fd81c212c6e2364bfeceab..1b604564c791d8d4139f5c0dd2bd4336d1bc471a 100644 --- a/Examples/DisparityMap/NCCRegistrationFilterExample.cxx +++ b/Examples/DisparityMap/NCCRegistrationFilterExample.cxx @@ -37,7 +37,6 @@ #include "otbImageFileWriter.h" #include "otbImageFileReader.h" -#include "otbCommandLineArgumentParser.h" // Software Guide : BeginCodeSnippet #include "otbNCCRegistrationFilter.h" @@ -111,14 +110,14 @@ int main(int argc, char** argv) FixedBlurType::Pointer fBlur = FixedBlurType::New(); fBlur->SetInput(fReader->GetOutput()); - fBlur->SetSigma(atof(argv[7])); + fBlur->SetSigma(std::stof(argv[7])); typedef itk::RecursiveGaussianImageFilter<MovingImageType, MovingImageType> MovingBlurType; MovingBlurType::Pointer mBlur = MovingBlurType::New(); mBlur->SetInput(mReader->GetOutput()); - mBlur->SetSigma(atof(argv[7])); + mBlur->SetSigma(std::stof(argv[7])); // Software Guide : EndCodeSnippet // Software Guide : BeginLatex @@ -153,8 +152,8 @@ int main(int argc, char** argv) RadiusType radius; - radius[0] = atoi(argv[6]); - radius[1] = atoi(argv[6]); + radius[0] = std::stoi(argv[6]); + radius[1] = std::stoi(argv[6]); registrator->SetNCCRadius(radius); // Software Guide : EndCodeSnippet @@ -168,7 +167,7 @@ int main(int argc, char** argv) // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - registrator->SetNumberOfIterations(atoi(argv[8])); + registrator->SetNumberOfIterations(std::stoi(argv[8])); // Software Guide : EndCodeSnippet // registrator->GetDisplacementField(); diff --git a/Examples/Simulation/LAIFromNDVIImageTransform.cxx b/Examples/Simulation/LAIFromNDVIImageTransform.cxx index 8156b3f2398c1fd592ea509f1b33cc2f4cfaa875..e5f583f45b4c5b760aebb41d4fb04d3c707d045d 100644 --- a/Examples/Simulation/LAIFromNDVIImageTransform.cxx +++ b/Examples/Simulation/LAIFromNDVIImageTransform.cxx @@ -40,7 +40,6 @@ #include "otbMultiChannelRAndNIRIndexImageFilter.h" // Software Guide : EndCodeSnippet -#include "otbCommandLineArgumentParser.h" #include "otbImage.h" #include "otbImageFileWriter.h" diff --git a/Examples/Tutorials/SmarterFilteringPipeline.cxx b/Examples/Tutorials/SmarterFilteringPipeline.cxx index 582f304fc1321b4a876abad2fd3ba6e281e11f4e..c118a560f50f133e36bad1f5899e5ca3b8d09618 100644 --- a/Examples/Tutorials/SmarterFilteringPipeline.cxx +++ b/Examples/Tutorials/SmarterFilteringPipeline.cxx @@ -59,7 +59,7 @@ // Software Guide : BeginCodeSnippet #include "itkMacro.h" -#include "otbCommandLineArgumentParser.h" + // Software Guide : EndCodeSnippet // Software Guide : BeginLatex @@ -95,96 +95,59 @@ int main(int argc, char * argv[]) // Software Guide : BeginCodeSnippet try { - // Software Guide : EndCodeSnippet + // Software Guide : EndCodeSnippet // Software Guide : BeginLatex - // - // Now, we can declare the \doxygen{otb}{CommandLineArgumentParser} which is - // going to parse the command line, select the proper variables, handle the - // missing compulsory arguments and print an error message if necessary. - // - // Let's declare the parser: + // + // First we document the usage of the program, and get the different + // variables $\sigma_D$ (d=), $\sigma_I$ (i=) and $\alpha$ (a=) in + // c++ variables : // // Software Guide : EndLatex - // Software Guide : BeginCodeSnippet - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // - // It's now time to tell the parser what are the options we want. Special - //options are available for input and output images with the - // \code{AddInputImage()} and \code{AddOutputImage()} methods. - // - // For the other options, we need to use the \code{AddOption()} method. - // This method allows us to specify - // \begin{itemize} - // \item the name of the option - // \item a message to explain the meaning of this option - // \item a shortcut for this option - // \item the number of expected parameters for this option - // \item whether or not this option is compulsory - // \end{itemize} - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - parser->SetProgramDescription( - "This program applies a Harris detector on the input image"); - parser->AddInputImage(); - parser->AddOutputImage(); - parser->AddOption("--SigmaD", - "Set the sigmaD parameter. Default is 1.0.", - "-d", - 1, - false); - parser->AddOption("--SigmaI", - "Set the sigmaI parameter. Default is 1.0.", - "-i", - 1, - false); - parser->AddOption("--Alpha", - "Set the alpha parameter. Default is 1.0.", - "-a", - 1, - false); - // Software Guide : EndCodeSnippet - - // Software Guide : BeginLatex - // - // Now that the parser has all this information, it can actually look at - // the command line to parse it. We have to do this within a \code{try} - - // \code{catch} loop to handle exceptions nicely. - // - // Software Guide : EndLatex - - // Software Guide : BeginCodeSnippet - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try + // Software Guide : BeginCodeSnippet + if ( argc < 3 ) { - parser->ParseCommandLine(argc, argv, parseResult); + std::cerr << "This program applies the Harris detector on the input " + << "image\n"; + std::cerr << "Usage : " << argv[0] ; + std::cerr << " input_filename output_filename [d=1.0] [i=1.0] [a=1.0]\n"; + std::cerr << "\"d=\" is for the sigmaD parameter, default value is 1.0\n"; + std::cerr << "\"i=\" is for the sigmaI parameter, default value is 1.0\n"; + std::cerr << "\"a=\" is for the alpha parameter, default value is 1.0\n"; + return EXIT_FAILURE; } - - catch (itk::ExceptionObject& err) + std::string input_filename = argv[1]; + std::string output_filename = argv[2]; + bool is_there_sigma_d(false), is_there_sigma_i(false), + is_there_alpha(false); + double sigma_d(1.0), sigma_i(1.0), alpha(1.0); + for (auto i = 3 ; i < argc ; i++ ) { - std::string descriptionException = err.GetDescription(); - if (descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos) + std::string temp_arg = argv[i]; + auto pos_sigma_d = temp_arg.find("d="); + auto pos_sigma_i = temp_arg.find("i="); + auto pos_alpha = temp_arg.find("a="); + if ( pos_sigma_d != std::string::npos ) { - return EXIT_SUCCESS; + is_there_sigma_d = true; + sigma_d = std::stod( temp_arg.substr( pos_sigma_d + 2 ) ); + continue; } - if (descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos) + if ( pos_sigma_i != std::string::npos ) { - return EXIT_SUCCESS; + is_there_sigma_i = true; + sigma_i = std::stod( temp_arg.substr( pos_sigma_i + 2 ) ); + continue; + } + if ( pos_alpha != std::string::npos ) + { + is_there_alpha = true; + alpha = std::stod( temp_arg.substr( pos_alpha + 2 ) ); + continue; } - return EXIT_FAILURE; } - // Software Guide : EndCodeSnippet + // Software Guide : EndCodeSnippet // Software Guide : BeginLatex // @@ -209,14 +172,14 @@ int main(int argc, char * argv[]) // Software Guide : BeginLatex // - // We are getting the filenames for the input and the output - // images directly from the parser: + // We are setting the filenames of the input and the output and the + // reader and writer respectively: // // Software Guide : BeginLatex // Software Guide : BeginCodeSnippet - reader->SetFileName(parseResult->GetInputImage()); - writer->SetFileName(parseResult->GetOutputImage()); + reader->SetFileName( input_filename ); + writer->SetFileName( output_filename ); // Software Guide : EndCodeSnippet // Software Guide : BeginLatex @@ -236,24 +199,20 @@ int main(int argc, char * argv[]) // Software Guide : BeginLatex // - // We set the filter parameters from the parser. The method - // \code{IsOptionPresent()} let us know if an optional option - // was provided in the command line. + // We set the filter parameters from the variables we created from the + // commandline. // // Software Guide : EndLatex // Software Guide : BeginCodeSnippet - if (parseResult->IsOptionPresent("--SigmaD")) - filter->SetSigmaD( - parseResult->GetParameterDouble("--SigmaD")); + if ( is_there_sigma_d ) + filter->SetSigmaD( sigma_d ); - if (parseResult->IsOptionPresent("--SigmaI")) - filter->SetSigmaI( - parseResult->GetParameterDouble("--SigmaI")); + if ( is_there_sigma_i ) + filter->SetSigmaI( sigma_i ); - if (parseResult->IsOptionPresent("--Alpha")) - filter->SetAlpha( - parseResult->GetParameterDouble("--Alpha")); + if ( is_there_alpha ) + filter->SetAlpha( alpha ); // Software Guide : EndCodeSnippet // Software Guide : BeginLatex diff --git a/Examples/Tutorials/test/CMakeLists.txt b/Examples/Tutorials/test/CMakeLists.txt index 6a752efad8f5542ba6d47760eb58851c90b7f60c..48864ba9e52d721bb0a22762347fffc370589a25 100644 --- a/Examples/Tutorials/test/CMakeLists.txt +++ b/Examples/Tutorials/test/CMakeLists.txt @@ -70,11 +70,11 @@ otb_add_test(NAME trTeTutorialsSmarterFilteringPipelineTest COMMAND ${OTB_TEST_ ${BASELINE}/TutorialsSmarterFilteringPipelineOutput.png ${TEMP}/TutorialsSmarterFilteringPipelineOutput.png Execute $<TARGET_FILE:SmarterFilteringPipeline> - -in ${INPUTDATA}/QB_Suburb.png - -out ${TEMP}/TutorialsSmarterFilteringPipelineOutput.png - -d 1.5 - -i 2 - -a 0.1 + ${INPUTDATA}/QB_Suburb.png + ${TEMP}/TutorialsSmarterFilteringPipelineOutput.png + d=1.5 + i=2 + a=0.1 ) otb_add_test(NAME trTeTutorialsOrthoFusionTest COMMAND ${OTB_TEST_DRIVER} diff --git a/Modules/Core/CommandLineParser/CMakeLists.txt b/Modules/Core/CommandLineParser/CMakeLists.txt deleted file mode 100644 index e76557a6d4e66c3b3a310d90b4581e2d7b18b370..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# -# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) -# -# This file is part of Orfeo Toolbox -# -# https://www.orfeo-toolbox.org/ -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -project(OTBCommandLineParser) - -set(OTBCommandLineParser_LIBRARIES OTBCommandLineParser) - -otb_module_impl() diff --git a/Modules/Core/CommandLineParser/include/otbCommandLineArgumentParser.h b/Modules/Core/CommandLineParser/include/otbCommandLineArgumentParser.h deleted file mode 100644 index 65dd076fbe46955f1b390fa6a7a43a383b9da87c..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/include/otbCommandLineArgumentParser.h +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbCommandLineArgumentParser_h -#define otbCommandLineArgumentParser_h - -#include <vector> -#include <string> -#include <map> - -#include "itkProcessObject.h" - -/** \class CommandLineArgumentParserHelpException - * \brief This exception is thrown when the help menu is displayed. - * - * \ingroup OTBCommandLineParser - */ -class ITK_EXPORT CommandLineArgumentParserHelpException - : public itk::ExceptionObject -{ -public: - /** Run-time information. */ - itkTypeMacro(CommandLineArgumentParserHelpException, ExceptionObject); - - /** Constructor. */ - CommandLineArgumentParserHelpException(const char *file, unsigned int line, - const char* message = "Help:", - const char* loc = "Unknown") : - ExceptionObject(file, line, message, loc) {} - /** Constructor. */ - CommandLineArgumentParserHelpException(const std::string & file, unsigned int line, - const char* message = "Help:", - const char* loc = "Unknown") : - ExceptionObject(file, line, message, loc) {} -}; - -/** \class CommandLineArgumentParserVersionException - * \brief This exception is thrown when the version is displayed. - * - * \ingroup OTBCommandLineParser - */ -class ITK_EXPORT CommandLineArgumentParserVersionException - : public itk::ExceptionObject -{ -public: - /** Run-time information. */ - itkTypeMacro(CommandLineArgumentParserVersionException, ExceptionObject); - - /** Constructor. */ - CommandLineArgumentParserVersionException(const char *file, unsigned int line, - const char* message = "Version:", - const char* loc = "Unknown") : - ExceptionObject(file, line, message, loc) {} - /** Constructor. */ - CommandLineArgumentParserVersionException(const std::string & file, unsigned int line, - const char* message = "Version:", - const char* loc = "Unknown") : - ExceptionObject(file, line, message, loc) {} -}; - -/** \class CommandLineArgumentParserArgumentErrorException - * \brief This exception is thrown when the version is displayed. - * - * \ingroup OTBCommandLineParser - */ -class ITK_EXPORT CommandLineArgumentParserArgumentErrorException - : public itk::ExceptionObject -{ -public: - /** Run-time information. */ - itkTypeMacro(CommandLineArgumentParserArgumentErrorException, ExceptionObject); - - /** Constructor. */ - CommandLineArgumentParserArgumentErrorException(const char *file, unsigned int line, - const char* message = "Argument error:", - const char* loc = "Unknown") : - ExceptionObject(file, line, message, loc) {} - /** Constructor. */ - CommandLineArgumentParserArgumentErrorException(const std::string & file, unsigned int line, - const char* message = "Argument error:", - const char* loc = "Unknown") : - ExceptionObject(file, line, message, loc) {} -}; - -namespace otb -{ - -//class CommandLineArgumentParser; - -/** - * \class CommandLineArgumentParseResult - * \brief Object returned by CommandLineArgumentParser - * - * \see CommandLineArgumentParser - * - * \ingroup OTBCommandLineParser - */ -class ITK_EXPORT CommandLineArgumentParseResult : public itk::ProcessObject -{ -public: - typedef CommandLineArgumentParseResult Self; - typedef itk::ProcessObject Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - itkNewMacro(Self); - itkTypeMacro(CommandLineArgumentParseResult, itk::ProcessObject); - - /** Check whether the option was passed in or not */ - bool IsOptionPresent(const std::string& option) const; - - /** Check whether the input image option was passed in or not */ - bool IsOptionInputImagePresent(void) const; - - /** Check whether the output image option was passed in or not */ - bool IsOptionOutputImagePresent(void) const; - - /** Check whether the OTBTesting option was passed in or not */ - bool IsOptionOTBTestingPresent(void) const; - - /** Get one of the parameters to the option */ -// const char *GetOptionParameter(const char *option, unsigned int number = 0); - int GetNumberOfParameters(const std::string& option); - - void PrintSelf(std::ostream& os, itk::Indent indent) const override; - -#define otbGetParameterMacro(name, type) \ - virtual type GetParameter ## name (const std::string& option, unsigned int number = 0) const \ - { \ - std::string parameter = this->GetParameterString(option, number); \ - type lValeur; \ - std::stringstream flux; \ - flux << parameter; \ - flux >> lValeur; \ - return lValeur; \ - } - - otbGetParameterMacro(Char, char); - otbGetParameterMacro(Short, short); - otbGetParameterMacro(UShort, unsigned short); - otbGetParameterMacro(Int, int); - otbGetParameterMacro(UInt, unsigned int); - otbGetParameterMacro(Long, long); - otbGetParameterMacro(ULong, unsigned long); - otbGetParameterMacro(Float, float); - otbGetParameterMacro(Double, double); - - std::string GetParameterString(const std::string& option, unsigned int number = 0) const; - - std::string GetInputImage(void) const; - std::string GetOutputImage(void) const; - -protected: - CommandLineArgumentParseResult(); - ~CommandLineArgumentParseResult() override; - -private: - template<typename TypeValeur> - TypeValeur GetParameter(const std::string& option, unsigned int number = 0) const; - - typedef std::vector<std::string> ParameterArrayType; - typedef std::map<std::string, ParameterArrayType> OptionMapType; - - void Clear(); - void AddOption(const std::string & option); - void AddParameter(const std::string & option, const std::string & parameter); - - OptionMapType m_OptionMap; - - friend class CommandLineArgumentParser; -}; - -/** - * \class CommandLineArgumentParser - * \brief Utility to Parse command line argument. - * - * Usage: - * - Initialize the parser: - * \code - * CommandLineArgumentParser parser; - * parser.SetProgramDescription("This program is an example"); - * parser.AddInputImage(); - * parser.AddOption("--DetailedName","Help explanation","-d", 1, false); - * \endcode - * - Use the parser: - * \code - * CommandLineArgumentParseResult result; - * if( parser.ParseCommandLine(argc, argv, &result) ) - * { - * if( result.IsOptionPresent("--DetailledName") ) - * { - * std::cout << "DetailedName : " << result.GetParameterString("--DetailedName") << std::endl; - * ... - * } - * } - * \endcode - * - * \ingroup OTBCommandLineParser - */ -class ITK_EXPORT CommandLineArgumentParser : public itk::ProcessObject -{ -public: - typedef CommandLineArgumentParser Self; - typedef itk::ProcessObject Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - - itkNewMacro(Self); - itkTypeMacro(CommandLineArgumentParser, itk::ProcessObject); - - /** Add an input image option */ - void AddInputImage(bool obligatory = true); - /** Add an output image option */ - void AddOutputImage(bool obligatory = true); - - /** Set the program name */ - itkSetStringMacro(ProgramDescription); - - /** Get the program name */ - itkGetStringMacro(ProgramDescription); - - /** Add a new option with fixed number of parameters */ - void AddOption(const std::string& name, - const std::string& comment, - const std::string& synonym = nullptr, - int nParameters = 1, - bool obligatory = true); - - /** Add a new option with unknown number of parameters */ - void AddOptionNParams(const std::string& name, const std::string& comment, const std::string& synonym = nullptr, bool obligatory = true); - - /** Interpret options from the command line */ - void ParseCommandLine(int argc, char *argv[], - CommandLineArgumentParseResult * outResult, - bool failOnUnknownTrailingParameters = true); - -protected: - CommandLineArgumentParser(); - ~CommandLineArgumentParser() override; - -private: - - void PrintUsage(std::ostream& os) const; - void PrintVersion(std::ostream& os) const; - bool FindOption(const std::string&, int& index); - bool IsNumber(const std::string& text); - - /** Try processing a command line. Returns false if something breaks */ - bool TryParseCommandLine(int argc, char *argv[], - CommandLineArgumentParseResult * outResult, - bool reportFailedMsg, - bool failOnUnknownTrailingParameters); - - typedef struct - { - std::string CommonName; // option name - std::string Description; // option description - std::string Synonym; // shortcut - bool NumberOfParametersFixed; // required number of values - int NumberOfParameters; // number of values - bool Obligatory; // is the option mandatory ? - bool Finded; // check if the option is present - } OptionType; - - typedef std::vector<OptionType> ListOptionType; - - ListOptionType m_OptionList; - - std::string m_ProgramName; - std::string m_ProgramDescription; -}; - -} - -#endif // otbCommandLineArgumentParser_h_ diff --git a/Modules/Core/CommandLineParser/otb-module.cmake b/Modules/Core/CommandLineParser/otb-module.cmake deleted file mode 100644 index cae9ccc0872269b2b3b59995b31b870ee085f515..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/otb-module.cmake +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) -# -# This file is part of Orfeo Toolbox -# -# https://www.orfeo-toolbox.org/ -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -set(DOCUMENTATION "TODO") - -otb_module(OTBCommandLineParser - DEPENDS - OTBCommon - OTBITK - - TEST_DEPENDS - OTBTestKernel - - DESCRIPTION - "${DOCUMENTATION}" -) diff --git a/Modules/Core/CommandLineParser/src/CMakeLists.txt b/Modules/Core/CommandLineParser/src/CMakeLists.txt deleted file mode 100644 index 075dfacd2daf8de033f38a67252a5542531925f5..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/src/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) -# -# This file is part of Orfeo Toolbox -# -# https://www.orfeo-toolbox.org/ -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -set(OTBCommandLineParser_SRC - otbCommandLineArgumentParser.cxx - ) - -add_library(OTBCommandLineParser ${OTBCommandLineParser_SRC}) -target_link_libraries(OTBCommandLineParser - ${OTBCommon_LIBRARIES} - ${OTBITK_LIBRARIES} - ) - -otb_module_target(OTBCommandLineParser) diff --git a/Modules/Core/CommandLineParser/src/otbCommandLineArgumentParser.cxx b/Modules/Core/CommandLineParser/src/otbCommandLineArgumentParser.cxx deleted file mode 100644 index 7d22767da2f55d8139f7d9c9de9fcfb39a863e75..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/src/otbCommandLineArgumentParser.cxx +++ /dev/null @@ -1,450 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <string> - -#include "otbCommandLineArgumentParser.h" - -#include <assert.h> -#include <iostream> - -#include "itkMacro.h" -#include "otbConfigure.h" // For OTB_VERSION_STRING generated by ccmake - -namespace otb -{ - -// --------- CommandLineArgumentParseResult -// --------- ---------------------------------------- -CommandLineArgumentParseResult::CommandLineArgumentParseResult() {} - -CommandLineArgumentParseResult::~CommandLineArgumentParseResult() {} - -void CommandLineArgumentParseResult -::PrintSelf(std::ostream& itkNotUsed(os), itk::Indent itkNotUsed(indent)) const -{ - -} - -bool CommandLineArgumentParseResult -::IsOptionPresent(const std::string& option) const -{ - return (m_OptionMap.find(option) != m_OptionMap.end()); -} - -bool CommandLineArgumentParseResult -::IsOptionInputImagePresent(void) const -{ - return (this->IsOptionPresent("--InputImage")); -} -bool CommandLineArgumentParseResult -::IsOptionOutputImagePresent(void) const -{ - return (this->IsOptionPresent("--OutputImage")); -} - -bool CommandLineArgumentParseResult -::IsOptionOTBTestingPresent(void) const -{ - return (this->IsOptionPresent("--OTBTesting")); -} - -std::string CommandLineArgumentParseResult -::GetParameterString(const std::string& option, unsigned int number) const -{ - if (this->IsOptionPresent(option) == false) - { - std::ostringstream msg; - msg << "GetParameterString(): The following '" << option << "' option is unknown !!"; - CommandLineArgumentParserArgumentErrorException e(__FILE__, __LINE__); - e.SetDescription(msg.str()); - throw e; - } - OptionMapType::const_iterator it = m_OptionMap.begin(); - it = m_OptionMap.find(option); - ParameterArrayType pat = (*it).second; - std::string lString = pat[number]; - return (lString); -} - -std::string CommandLineArgumentParseResult -::GetInputImage(void) const -{ - return (GetParameterString("--InputImage")); -} - -std::string CommandLineArgumentParseResult -::GetOutputImage(void) const -{ - return (GetParameterString("--OutputImage")); -} - -int CommandLineArgumentParseResult -::GetNumberOfParameters(const std::string& option) -{ - assert(IsOptionPresent(option)); - return (m_OptionMap[option].size()); -} - -void CommandLineArgumentParseResult -::Clear() -{ - m_OptionMap.clear(); -} - -void CommandLineArgumentParseResult -::AddOption(const std::string& option) -{ - ParameterArrayType pat; -// pat.reserve(nParms); - m_OptionMap[option] = pat; -} - -void CommandLineArgumentParseResult -::AddParameter(const std::string& option, const std::string& parameter) -{ - m_OptionMap[option].push_back(parameter); -} - -// --------- CommandLineArgumentParser ---------------------------------------- - -CommandLineArgumentParser -::CommandLineArgumentParser() -{ - AddOption("--help", "Help", "-h", 0, false); - AddOption("--version", "Version", "-v", 0, false); - AddOptionNParams("--OTBTesting", "Testing purposes only.", "-OTBTesting", false); - m_ProgramDescription.clear(); -} - -CommandLineArgumentParser -::~CommandLineArgumentParser() {} - - -void CommandLineArgumentParser -::AddInputImage(bool obligatory) -{ - AddOption("--InputImage", "input image file name ", "-in", 1, obligatory); -} - -void CommandLineArgumentParser -::AddOutputImage(bool obligatory) -{ - AddOption("--OutputImage", "output image file name ", "-out", 1, obligatory); -} - -void CommandLineArgumentParser -::AddOption(const std::string& name, const std::string& comment, const std::string& synonym, int nParameters, bool obligatory) -{ - // Create a structure for the command - OptionType option; - option.CommonName = name; - option.Description = comment; - option.Synonym = synonym; - option.NumberOfParameters = nParameters; - option.NumberOfParametersFixed = true; - option.Obligatory = obligatory; - option.Finded = false; - - // Add the option to the map - m_OptionList.push_back(option); - -} - -void CommandLineArgumentParser -::AddOptionNParams(const std::string& name, const std::string& comment, const std::string& synonym, bool obligatory) -{ - // Create a structure for the command - OptionType option; - option.CommonName = name; - option.Description = comment; - option.Synonym = synonym; - option.NumberOfParameters = -1; - option.NumberOfParametersFixed = false; - option.Obligatory = obligatory; - option.Finded = false; - - // Add the option to the map - m_OptionList.push_back(option); - -} - -void CommandLineArgumentParser -::ParseCommandLine(int argc, char *argv[], - CommandLineArgumentParseResult * outResult, - bool failOnUnknownTrailingParameters) -{ - bool tryParse = TryParseCommandLine(argc, argv, outResult, false, failOnUnknownTrailingParameters); - - bool IsHelp = outResult->IsOptionPresent("--help"); - if (IsHelp) - { - PrintUsage(std::cout); - CommandLineArgumentParserHelpException e(__FILE__, __LINE__); - e.SetDescription("ParseCommandLine(): Help Parser"); - throw e; - } - bool IsVersion = outResult->IsOptionPresent("--version"); - if (IsVersion) - { - PrintVersion(std::cout); - CommandLineArgumentParserHelpException e(__FILE__, __LINE__); - e.SetDescription("ParseCommandLine(): Version Parser"); - throw e; - } - tryParse = TryParseCommandLine(argc, argv, outResult, true, failOnUnknownTrailingParameters); - if (!tryParse) - { - PrintUsage(std::cerr); - CommandLineArgumentParserArgumentErrorException e(__FILE__, __LINE__); - e.SetDescription("ParseCommandLine() argument Error"); - throw e; - } -} - -bool CommandLineArgumentParser::TryParseCommandLine(int argc, char *argv[], - CommandLineArgumentParseResult * outResult, - bool reportFailedMsg, - bool failOnUnknownTrailingParameters) -{ -// Clear the result - outResult->Clear(); - - int i; - m_ProgramName = std::string(argv[0]); - int index(0); - -// Go through the arguments - for (i = 1; i < argc; ++i) - { -// Get the next argument - std::string arg(argv[i]); - - // Check if the argument is known - bool findOption = FindOption(arg, index); - if (findOption == false) - { - if (failOnUnknownTrailingParameters) - { - // Unknown argument found - if (reportFailedMsg == true) - { - std::cerr << "The following '" << arg << "' option is unknown !!" << std::endl; - } - return false; - } - else return true; - } - //Check the option - m_OptionList[index].Finded = true; - // If the number of parameters is predefined - if (m_OptionList[index].NumberOfParametersFixed == true) - { - // Check if the number of parameters is correct - int nParameters = m_OptionList[index].NumberOfParameters; - if (i + nParameters >= argc) - { - // Too few parameters - if (reportFailedMsg == true) - { - std::cerr << "Missing one (or more) parameter(s) for the following '" << arg << "' option." << std::endl; - } - return false; - } - // Tell the result that the option has been encountered - outResult->AddOption(m_OptionList[index].CommonName); - - // Pass in the parameters - for (int j = 0; j < nParameters; ++j, ++i) - { - outResult->AddParameter(m_OptionList[index].CommonName, std::string(argv[i + 1])); - } - } -// If the number of parameters is not defined, read until the next option or the end of argv - else - { -// Tell the result that the option has been encountered - outResult->AddOption(m_OptionList[index].CommonName); - bool goOnFlag(true); - while (goOnFlag == true) - { - if (argv[i + 1] != nullptr) - { - std::string strArgv = std::string(argv[i + 1]); - if (strArgv[0] == '-' ) - { - // Test if the string is an argument or a real - if(!this->IsNumber(strArgv)) - { - goOnFlag = false; - } - else // If not an argument add it to the option list - { - outResult->AddParameter(m_OptionList[index].CommonName, strArgv); - ++i; - } - } - else - { - outResult->AddParameter(m_OptionList[index].CommonName, strArgv); - ++i; - } - } - else goOnFlag = false; - // ++i; - } - } - - } - -// Check that all required arguments are specified - for (unsigned int cpt = 0; cpt < m_OptionList.size(); ++cpt) - { - if ((m_OptionList[cpt].Obligatory == true) && (m_OptionList[cpt].Finded == false)) - { - // Too few parameters - if (reportFailedMsg == true) - { - std::cerr << "'" << m_OptionList[cpt].CommonName << "' argument is required !!!" << std::endl; - } - return false; - } - } - -// Everything is correct - return true; -} - - -bool CommandLineArgumentParser::IsNumber(const std::string& text) -{ - if(text.empty()) - return false; - - // Don't test the sign (-) - unsigned int i = 1; - while (text[i]) - { - if( text[i] != '.' && text[i] != ',') - { - if(!isdigit(text[i])) - { - return false; - } - } - ++i; - } - return true; -} - -bool CommandLineArgumentParser::FindOption(const std::string& option, int& index) -{ - //Look through the option list - bool optionFoundFlag(false); - bool goOnFlag(true); - unsigned int cpt(0); - std::string strOption(option); - while (goOnFlag == true) - { - if ((m_OptionList[cpt].CommonName == strOption) || (m_OptionList[cpt].Synonym == strOption)) - { - index = cpt; - goOnFlag = false; - optionFoundFlag = true; - } - ++cpt; - if (cpt >= m_OptionList.size()) - { - goOnFlag = false; - } - } - return (optionFoundFlag); -} - -void CommandLineArgumentParser::PrintUsage(std::ostream& os) const -{ - os << std::endl; - - if (!m_ProgramDescription.empty()) - { - os << m_ProgramDescription << std::endl << std::endl; - } - - os << " Usage : " << m_ProgramName << std::endl; - // Compute the max width for option display - int largeurmax(-1); - unsigned int i; - - for (i = 0; i < m_OptionList.size(); ++i) - { - int largeur = m_OptionList[i].CommonName.size() + m_OptionList[i].Synonym.size(); - if (largeur > largeurmax) largeurmax = largeur; - } - - // Check that all required arguments are present on the command line - for (i = 0; i < m_OptionList.size(); ++i) - { - if (m_OptionList[i].CommonName != "--OTBTesting") - { - int largeur = m_OptionList[i].CommonName.size() + m_OptionList[i].Synonym.size(); - os << " "; - if (m_OptionList[i].Obligatory == false) os << "["; - else os << " "; - os << m_OptionList[i].CommonName; - if (m_OptionList[i].Synonym.empty() == false) - { - os << "|" << m_OptionList[i].Synonym; - } - if (m_OptionList[i].Obligatory == false) os << "]"; - else os << " "; -//Align the text - for (int b = largeur; b < largeurmax; b++) - os << " "; - os << " : " << m_OptionList[i].Description; - if (m_OptionList[i].NumberOfParametersFixed == true) - { - switch (m_OptionList[i].NumberOfParameters) - { - case 0: - break; - case 1: - os << " (" << m_OptionList[i].NumberOfParameters << " parameter)"; - break; - default: - os << " (" << m_OptionList[i].NumberOfParameters << " parameters)"; - break; - } - } - else - { - os << " (N parameters)"; - } - os << std::endl; - } - } - os << std::endl; -} - -void CommandLineArgumentParser::PrintVersion(std::ostream& os) const -{ - os << " OTB Version : " << OTB_VERSION_STRING << std::endl; -} - -} diff --git a/Modules/Core/CommandLineParser/test/CMakeLists.txt b/Modules/Core/CommandLineParser/test/CMakeLists.txt deleted file mode 100644 index e6e3986c55ee339c2b1dac97f9561570d95fd18b..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/test/CMakeLists.txt +++ /dev/null @@ -1,64 +0,0 @@ -# -# Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) -# -# This file is part of Orfeo Toolbox -# -# https://www.orfeo-toolbox.org/ -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -otb_module_test() -set(OTBCommandLineParserTests - otbTestCommandLineArgumentParser.cxx - otbTestCommandLineArgumentParserHelp.cxx - otbTestCommandLineArgumentParserList.cxx - otbTestCommandLineArgumentParserWithError.cxx - otbCommandLineParserTestDriver.cxx ) - -add_executable(otbCommandLineParserTestDriver ${OTBCommandLineParserTests}) -target_link_libraries(otbCommandLineParserTestDriver ${OTBCommandLineParser-Test_LIBRARIES}) -otb_module_target_label(otbCommandLineParserTestDriver) -otb_add_test(NAME coTuCmdLineArgParserDeuxEntiers_ExactNumberArg COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParser - -image image.png -entier 150 -double 12.25 -deuxentiers 78 56 ) -otb_add_test(NAME coTuCmdLineArgParserHelpWithArg COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParserHelp - --help -image image.png) -otb_add_test(NAME coTuCmdLineArgParserHelpWithoutArg COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParserHelp - --help) -otb_add_test(NAME coTuCmdLineArgParser_List2Arg COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParserList - -image image.png -entier 150 -double 12.25 -deuxentiers 78 56 -doubles 1.0 2.0) -otb_add_test(NAME coTuCmdLineArgParser_List2ArgBis COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParserList - -image image.png -entier 150 -double 12.25 -doubles 1.0 2.0 -deuxentiers 78 56 ) -otb_add_test(NAME coTuCmdLineArgParser_EmptyList COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParserList - -image image.png -entier 150 -double 12.25 -deuxentiers 78 56 -doubles) -otb_add_test(NAME coTuCmdLineArgParser_List1Arg COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParserList - -image image.png -entier 150 -double 12.25 -deuxentiers 78 56 -doubles 1.0 2.5) -otb_add_test(NAME coTuCmdLineArgParser_List3ArgWithError COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParserList - -image image.png -entier 150 -double 12.25 -deuxentiers 78 56 -doubles 1.0 2.5 -3.5) -otb_add_test(NAME coTuCmdLineArgParserDeuxEntier_LessArg COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParserWithError - -image image.png -entier 150 -double 12.25 -deuxentiers 78 ) -otb_add_test(NAME coTuCmdLineArgParser_MissingObligatoryArg COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParserWithError - -entier 150 -double 12.25 -deuxentiers 78 56 32) -otb_add_test(NAME coTuCmdLineArgParserDeuxEntier_MoreArg COMMAND otbCommandLineParserTestDriver - otbTestCommandLineArgumentParserWithError - -image image.png -entier 150 -double 12.25 -deuxentiers 78 56 32) diff --git a/Modules/Core/CommandLineParser/test/otbCommandLineParserTestDriver.cxx b/Modules/Core/CommandLineParser/test/otbCommandLineParserTestDriver.cxx deleted file mode 100644 index 326c130f1b10d09b6740b79195b5f86f8e9ae5ea..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/test/otbCommandLineParserTestDriver.cxx +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "otbTestMain.h" - -void RegisterTests() -{ - REGISTER_TEST(otbTestCommandLineArgumentParser); - REGISTER_TEST(otbTestCommandLineArgumentParserHelp); - REGISTER_TEST(otbTestCommandLineArgumentParserList); - REGISTER_TEST(otbTestCommandLineArgumentParserWithError); -} diff --git a/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParser.cxx b/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParser.cxx deleted file mode 100644 index 2a028440fbda8abd2e2239175c675c51af776942..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParser.cxx +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include <iostream> - -#include "otbCommandLineArgumentParser.h" - -int otbTestCommandLineArgumentParser(int argc, char * argv[]) -{ - // Parse command line parameters - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddOption("-image", "Nom d'une image", "-i", 1, true); - parser->AddOption("-entier", "Une Valeur entiere (obligatoire)", "-e"); - parser->AddOption("-deuxentiers", "Deux Valeurs entieres non obligatoire", "-dede", 2, false); - parser->AddOption("-double", "Valeur reelle double", "-d"); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - parser->ParseCommandLine(argc, argv, parseResult); - - std::cout << "Image : " << parseResult->GetParameterString("-image") << std::endl; - - unsigned int lEntier = parseResult->GetParameterUInt("-entier"); - std::cout << "Entier : " << lEntier << std::endl; - if (parseResult->IsOptionPresent("-deuxentiers")) - { - std::cout << "Entier : " << lEntier << std::endl; - } - double lDouble = parseResult->GetParameterDouble("-double"); - std::cout << "Double : " << lDouble << std::endl; - - return EXIT_SUCCESS; -} diff --git a/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParserHelp.cxx b/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParserHelp.cxx deleted file mode 100644 index b2d3411096a3da77d9cec4975c8390a0222e0f7a..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParserHelp.cxx +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include <iostream> - -#include "itkMacro.h" -#include "otbCommandLineArgumentParser.h" - -int otbTestCommandLineArgumentParserHelp(int argc, char * argv[]) -{ - try - { - // Parse command line parameters - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddOption("-image", "Nom d'une image", "-i", 1, true); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - parser->ParseCommandLine(argc, argv, parseResult); - - std::cout << "Image : " << parseResult->GetParameterString("-image") << std::endl; - } - catch (CommandLineArgumentParserHelpException& err) - { - std::cerr << err; - return EXIT_SUCCESS; - } - - return EXIT_FAILURE; -} diff --git a/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParserList.cxx b/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParserList.cxx deleted file mode 100644 index 62817c101f8a1402f28b2fca1e4ba1fdea5d3673..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParserList.cxx +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include <iostream> - -#include "otbCommandLineArgumentParser.h" - -int otbTestCommandLineArgumentParserList(int argc, char * argv[]) -{ - // Parse command line parameters - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddOption("-image", "Nom d'une image", "-i", 1, true); - parser->AddOption("-entier", "Une Valeur entiere (obligatoire)", "-e"); - parser->AddOption("-deuxentiers", "Deux Valeurs entieres non obligatoire", "-dede", 2, false); - parser->AddOption("-double", "Valeur reelle double", "-d"); - parser->AddOptionNParams("-doubles", "Liste de Valeurs reelles", "-ld", false); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - parser->ParseCommandLine(argc, argv, parseResult); - - std::cout << "Image : " << parseResult->GetParameterString("-image") << std::endl; - //unsigned int lEntier = otb::GetParameter<unsigned int>(parseResult,"-entier"); - unsigned int lEntier = parseResult->GetParameterUInt("-entier"); - std::cout << "Entier : " << lEntier << std::endl; - if (parseResult->IsOptionPresent("-deuxentiers")) - { - //unsigned int lEntierDeux = otb::GetParameter<unsigned int>(parseResult,"-deuxentiers", 1); - unsigned int lEntierDeux = parseResult->GetParameterUInt("-deuxentiers", 1); - std::cout << "Entier : " << lEntierDeux << std::endl; - } - //double lDouble = otb::GetParameter<double>(parseResult,"-double"); - double lDouble = parseResult->GetParameterDouble("-double"); - std::cout << "Double : " << lDouble << std::endl; - - std::cout << "List de Double : " << parseResult->GetNumberOfParameters("-doubles") << std::endl; - for (int i = 0; i < parseResult->GetNumberOfParameters("-doubles"); ++i) - { - //double value = otb::GetParameter<double>(parseResult,"-doubles", i); - double value = parseResult->GetParameterDouble("-doubles", i); - std::cout << " " << value; - } - std::cout << std::endl; - - return EXIT_SUCCESS; -} diff --git a/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParserWithError.cxx b/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParserWithError.cxx deleted file mode 100644 index 78d7cab29d2c1caa86bff4a1b046ec5e606bc0c2..0000000000000000000000000000000000000000 --- a/Modules/Core/CommandLineParser/test/otbTestCommandLineArgumentParserWithError.cxx +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include <iostream> - -#include "itkMacro.h" -#include "otbCommandLineArgumentParser.h" - -int otbTestCommandLineArgumentParserWithError(int argc, char * argv[]) -{ - // Parse command line parameters - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddOption("-image", "Nom d'une image", "-i", 1, true); - parser->AddOption("-entier", "Une Valeur entiere (obligatoire)", "-e"); - parser->AddOption("-deuxentiers", "Deux Valeurs entieres non obligatoire", "-dede", 2, false); - parser->AddOption("-double", "Valeur reelle double", "-d"); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - - parser->ParseCommandLine(argc, argv, parseResult); - - std::cout << "Image : " << parseResult->GetParameterString("-image") << std::endl; - //unsigned int lEntier = otb::GetParameter<unsigned int>(parseResult,"-entier"); - unsigned int lEntier = parseResult->GetParameterUInt("-entier"); - std::cout << "Entier : " << lEntier << std::endl; - if (parseResult->IsOptionPresent("-deuxentiers")) - { - //unsigned int lEntierDeux = otb::GetParameter<unsigned int>(parseResult,"-deuxentiers", 1); - unsigned int lEntierDeux = parseResult->GetParameterUInt("-deuxentiers", 1); - std::cout << "Entier : " << lEntierDeux << std::endl; - } - //double lDouble = otb::GetParameter<double>(parseResult,"-double"); - double lDouble = parseResult->GetParameterDouble("-double"); - std::cout << "Double : " << lDouble << std::endl; - } - catch (CommandLineArgumentParserArgumentErrorException& err) - { - std::cerr << err; - return EXIT_SUCCESS; - } - return EXIT_FAILURE; -} diff --git a/Modules/Feature/Edge/otb-module.cmake b/Modules/Feature/Edge/otb-module.cmake index 3d934d1a3c478f94878ea3db401d8dce9b36a112..3760ff5d237e3548ca74c8c6f4a4ab02c153fbcd 100644 --- a/Modules/Feature/Edge/otb-module.cmake +++ b/Modules/Feature/Edge/otb-module.cmake @@ -37,7 +37,6 @@ otb_module(OTBEdge OTBVectorDataBase TEST_DEPENDS - OTBCommandLineParser OTBImageIO OTBTestKernel OTBVectorDataIO diff --git a/Modules/Feature/Edge/test/CMakeLists.txt b/Modules/Feature/Edge/test/CMakeLists.txt index cdba184eeb03f09368c67baacc5c3581fc6b30c1..8f7e5afcb026139362b080f06f7645a299c03e1c 100644 --- a/Modules/Feature/Edge/test/CMakeLists.txt +++ b/Modules/Feature/Edge/test/CMakeLists.txt @@ -68,8 +68,8 @@ otb_add_test(NAME bfTvHorizontalSobelVectorImageFilter COMMAND otbEdgeTestDriver ${BASELINE}/bfTvHorizontalSobelVectorImageFilter.tif ${TEMP}/bfTvHorizontalSobelVectorImageFilter.tif otbHorizontalSobelVectorImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvHorizontalSobelVectorImageFilter.tif) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvHorizontalSobelVectorImageFilter.tif) otb_add_test(NAME feTvAsymmetricFusionOfLineDetector COMMAND otbEdgeTestDriver --compare-image ${EPSILON_8} ${BASELINE}/feFiltreAsymmetricFusion_amst_2_3.tif @@ -148,8 +148,8 @@ otb_add_test(NAME bfTvSobelVectorImageFilter COMMAND otbEdgeTestDriver ${BASELINE}/bfTvSobelVectorImageFilter.tif ${TEMP}/bfTvSobelVectorImageFilter.tif otbSobelVectorImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvSobelVectorImageFilter.tif) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvSobelVectorImageFilter.tif) otb_add_test(NAME feTvHoughTransform2DLinesImage COMMAND otbEdgeTestDriver --compare-image ${EPSILON_8} @@ -208,8 +208,8 @@ otb_add_test(NAME bfTvVerticalSobelVectorImageFilter COMMAND otbEdgeTestDriver ${BASELINE}/bfTvVerticalSobelVectorImageFilter.tif ${TEMP}/bfTvVerticalSobelVectorImageFilter.tif otbVerticalSobelVectorImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvVerticalSobelVectorImageFilter.tif) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvVerticalSobelVectorImageFilter.tif) otb_add_test(NAME feTvStreamingLineSegmentDetector10 COMMAND otbEdgeTestDriver --compare-ogr ${EPSILON_8} diff --git a/Modules/Feature/Edge/test/otbHorizontalSobelVectorImageFilter.cxx b/Modules/Feature/Edge/test/otbHorizontalSobelVectorImageFilter.cxx index 45fd7669281d03823573b04cd9836cc87285fda2..4576f61b845308f4f21371585a6e502dc3992a8a 100644 --- a/Modules/Feature/Edge/test/otbHorizontalSobelVectorImageFilter.cxx +++ b/Modules/Feature/Edge/test/otbHorizontalSobelVectorImageFilter.cxx @@ -24,40 +24,16 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" #include "otbHorizontalSobelVectorImageFilter.h" int otbHorizontalSobelVectorImageFilterTest ( int argc, char* argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddInputImage(); - parser->AddOutputImage(); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs horizonal sobel on a vector image\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; + if (argc != 3) + { + std::cerr << "Usage: otbHorizontalSobelVectorImageFilterTest input output\n"; return EXIT_FAILURE; - } - - std::string inputImageName = parseResult->GetInputImage(); - std::string outputImageName = parseResult->GetOutputImage(); + } // Main type definition const unsigned int Dimension = 2; @@ -67,7 +43,7 @@ int otbHorizontalSobelVectorImageFilterTest ( int argc, char* argv[] ) // Reading input images typedef otb::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImageName); + reader->SetFileName(argv[1]); // Image filtering typedef otb::HorizontalSobelVectorImageFilter< ImageType, ImageType > @@ -81,7 +57,7 @@ int otbHorizontalSobelVectorImageFilterTest ( int argc, char* argv[] ) typedef otb::ImageFileWriter< ImageType > ImageWriterType; ImageWriterType::Pointer writer = ImageWriterType::New(); - writer->SetFileName( outputImageName ); + writer->SetFileName( argv[2] ); writer->SetInput( filter->GetOutput() ); writer->Update(); diff --git a/Modules/Feature/Edge/test/otbSobelVectorImageFilter.cxx b/Modules/Feature/Edge/test/otbSobelVectorImageFilter.cxx index 5c60e8c13976da5fe22f5525577d061235ae0aed..41f775bb2d8f588720767eed9cad1be09ef5da58 100644 --- a/Modules/Feature/Edge/test/otbSobelVectorImageFilter.cxx +++ b/Modules/Feature/Edge/test/otbSobelVectorImageFilter.cxx @@ -24,40 +24,16 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" #include "otbSobelVectorImageFilter.h" int otbSobelVectorImageFilterTest ( int argc, char* argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddInputImage(); - parser->AddOutputImage(); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs sobel on a vector image\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; + if (argc != 3) + { + std::cerr << "Usage: otbSobelVectorImageFilterTest input output\n"; return EXIT_FAILURE; - } - - std::string inputImageName = parseResult->GetInputImage(); - std::string outputImageName = parseResult->GetOutputImage(); + } // Main type definition const unsigned int Dimension = 2; @@ -67,7 +43,7 @@ int otbSobelVectorImageFilterTest ( int argc, char* argv[] ) // Reading input images typedef otb::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImageName); + reader->SetFileName(argv[1]); // Image filtering typedef otb::SobelVectorImageFilter< ImageType, ImageType > FilterType; @@ -80,7 +56,7 @@ int otbSobelVectorImageFilterTest ( int argc, char* argv[] ) typedef otb::ImageFileWriter< ImageType > ImageWriterType; ImageWriterType::Pointer writer = ImageWriterType::New(); - writer->SetFileName( outputImageName ); + writer->SetFileName( argv[2] ); writer->SetInput( filter->GetOutput() ); writer->Update(); diff --git a/Modules/Feature/Edge/test/otbVerticalSobelVectorImageFilter.cxx b/Modules/Feature/Edge/test/otbVerticalSobelVectorImageFilter.cxx index 7ee2f2c04195ac9dda827233692937b7f20dbc5b..4b0464a41063606eb94bff92998fff3190edb43e 100644 --- a/Modules/Feature/Edge/test/otbVerticalSobelVectorImageFilter.cxx +++ b/Modules/Feature/Edge/test/otbVerticalSobelVectorImageFilter.cxx @@ -24,40 +24,16 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" #include "otbVerticalSobelVectorImageFilter.h" int otbVerticalSobelVectorImageFilterTest ( int argc, char* argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddInputImage(); - parser->AddOutputImage(); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs vertical sobel on a vector image\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; + if (argc != 3) + { + std::cerr << "Usage: otbVerticalSobelVectorImageFilterTest input output\n"; return EXIT_FAILURE; - } - - std::string inputImageName = parseResult->GetInputImage(); - std::string outputImageName = parseResult->GetOutputImage(); + } // Main type definition const unsigned int Dimension = 2; @@ -67,7 +43,7 @@ int otbVerticalSobelVectorImageFilterTest ( int argc, char* argv[] ) // Reading input images typedef otb::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImageName); + reader->SetFileName(argv[1]); // Image filtering typedef otb::VerticalSobelVectorImageFilter< ImageType, ImageType > @@ -81,7 +57,7 @@ int otbVerticalSobelVectorImageFilterTest ( int argc, char* argv[] ) typedef otb::ImageFileWriter< ImageType > ImageWriterType; ImageWriterType::Pointer writer = ImageWriterType::New(); - writer->SetFileName( outputImageName ); + writer->SetFileName( argv[2] ); writer->SetInput( filter->GetOutput() ); writer->Update(); diff --git a/Modules/Filtering/DimensionalityReduction/include/otbAngularProjectionBinaryImageFilter.hxx b/Modules/Filtering/DimensionalityReduction/include/otbAngularProjectionBinaryImageFilter.hxx index ed6c30890e0138c64651447640c2c7a521f5b83f..9e1a9b36388f8335d682f6fabeb38089f259017a 100644 --- a/Modules/Filtering/DimensionalityReduction/include/otbAngularProjectionBinaryImageFilter.hxx +++ b/Modules/Filtering/DimensionalityReduction/include/otbAngularProjectionBinaryImageFilter.hxx @@ -85,7 +85,7 @@ AngularProjectionBinaryImageFilter< TInputImage, TOutputImage, TPrecision > { m_AngleSet = angle; this->SetNumberOfRequiredOutputs( angle.size() ); - for ( unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i ) + for ( unsigned int i = 0; i < this->GetNumberOfRequiredOutputs(); ++i ) { this->SetNthOutput(i, OutputImageType::New()); } diff --git a/Modules/Filtering/DimensionalityReduction/otb-module.cmake b/Modules/Filtering/DimensionalityReduction/otb-module.cmake index 121a558e704e6f355700cbe29a78d142c99a60d4..678c1b43ee64734543c964db6666dec831506d58 100644 --- a/Modules/Filtering/DimensionalityReduction/otb-module.cmake +++ b/Modules/Filtering/DimensionalityReduction/otb-module.cmake @@ -35,7 +35,6 @@ otb_module(OTBDimensionalityReduction OTBStatistics TEST_DEPENDS - OTBCommandLineParser OTBImageIO OTBTestKernel OTBWavelet diff --git a/Modules/Filtering/DimensionalityReduction/test/CMakeLists.txt b/Modules/Filtering/DimensionalityReduction/test/CMakeLists.txt index f423cc12d6c0a823d8449a4a3e4422111ac330ac..f68ba0a68ff10ebbe136a4e05b10c4527fad77de 100644 --- a/Modules/Filtering/DimensionalityReduction/test/CMakeLists.txt +++ b/Modules/Filtering/DimensionalityReduction/test/CMakeLists.txt @@ -44,16 +44,48 @@ otb_module_target_label(otbDimensionalityReductionTestDriver) # Tests Declaration #otb_add_test(NAME bfTvFastICAImageFilter COMMAND otbDimensionalityReductionTestDriver - #--compare-n-images ${EPSILON_7} 2 - #${BASELINE}/hyTvFastICAImageFilter.tif - #${TEMP}/hyTvFastICAImageFilter.tif - #${BASELINE}/hyTvFastICAImageFilterInv.tif - #${TEMP}/hyTvFastICAImageFilterInv.tif - #otbFastICAImageFilterTest - #-in ${INPUTDATA}/cupriteSubHsi.tif - #-inv ${TEMP}/hyTvFastICAImageFilterInv.tif - #-out ${TEMP}/hyTvFastICAImageFilter.tif) +# --compare-n-images ${EPSILON_7} 2 +# ${BASELINE}/hyTvFastICAImageFilter.tif +# ${TEMP}/hyTvFastICAImageFilter.tif +# ${BASELINE}/hyTvFastICAImageFilterInv.tif +# ${TEMP}/hyTvFastICAImageFilterInv.tif +# otbFastICAImageFilterTest +# ${INPUTDATA}/cupriteSubHsi.tif +# ${TEMP}/hyTvFastICAImageFilter.tif +# ${TEMP}/hyTvFastICAImageFilterInv.tif +#) + +otb_add_test(NAME bfTvAngularProjectionBinaryImageFilter COMMAND otbDimensionalityReductionTestDriver + --compare-n-images ${EPSILON_12} 2 + ${BASELINE}/bfTvAngularProjectionBinaryImageFilter1.tif + ${TEMP}/bfTvAngularProjectionBinaryImageFilter1.tif + ${BASELINE}/bfTvAngularProjectionBinaryImageFilter2.tif + ${TEMP}/bfTvAngularProjectionBinaryImageFilter2.tif + otbAngularProjectionBinaryImageFilterTest + ${INPUTDATA}/cupriteSubHsi.tif + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvAngularProjectionBinaryImageFilter1.tif + ${TEMP}/bfTvAngularProjectionBinaryImageFilter2.tif +) +otb_add_test(NAME bfTvAngularProjectionImageFilter COMMAND otbDimensionalityReductionTestDriver + --compare-image ${EPSILON_12} + ${BASELINE}/bfTvAngularProjectionImageFilter.tif + ${TEMP}/bfTvAngularProjectionImageFilter.tif + otbAngularProjectionImageFilterTest + ${INPUTDATA}/cupriteSubHsi.tif + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvAngularProjectionImageFilter.tif +) + +otb_add_test(NAME bfTvAngularProjectionSetImageFilter COMMAND otbDimensionalityReductionTestDriver + --compare-image ${EPSILON_12} + ${BASELINE}/bfTvAngularProjectionSetImageFilter.tif + ${TEMP}/bfTvAngularProjectionSetImageFilter.tif + otbAngularProjectionSetImageFilterTest + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvAngularProjectionSetImageFilter.tif +) otb_add_test(NAME bfTvNormalizeInnerProductPCAImageFilter COMMAND otbDimensionalityReductionTestDriver --compare-image ${EPSILON_12} ${BASELINE}/bfNormalizeInnerProductPCAImageFilter.tif @@ -80,29 +112,33 @@ otb_add_test(NAME bfTvMNFImageFilter3 COMMAND otbDimensionalityReductionTestDriv ${BASELINE}/bfTvMNFImageFilter3Inv.tif ${TEMP}/bfTvMNFImageFilter3Inv.tif otbMNFImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvMNFImageFilter3.tif - -inv ${TEMP}/bfTvMNFImageFilter3Inv.tif - -norm) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvMNFImageFilter3.tif + ${TEMP}/bfTvMNFImageFilter3Inv.tif + true + 0) otb_add_test(NAME bfTvMNFImageFilter2 COMMAND otbDimensionalityReductionTestDriver --compare-image ${EPSILON_7} ${INPUTDATA}/cupriteSubHsi.tif ${TEMP}/bfTvMNFImageFilter2Inv.tif otbMNFImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvMNFImageFilter2.tif - -inv ${TEMP}/bfTvMNFImageFilter2Inv.tif - -norm) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvMNFImageFilter2.tif + ${TEMP}/bfTvMNFImageFilter2Inv.tif + true + 0) otb_add_test(NAME bfTvMNFImageFilter1 COMMAND otbDimensionalityReductionTestDriver --compare-image ${EPSILON_7} ${INPUTDATA}/cupriteSubHsi.tif ${TEMP}/bfTvMNFImageFilter1Inv.tif otbMNFImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvMNFImageFilter1.tif - -inv ${TEMP}/bfTvMNFImageFilter1Inv.tif) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvMNFImageFilter1.tif + ${TEMP}/bfTvMNFImageFilter1Inv.tif + false + 0) otb_add_test(NAME bfTvMNFImageFilter4 COMMAND otbDimensionalityReductionTestDriver --compare-n-images ${EPSILON_7} 2 @@ -111,11 +147,11 @@ otb_add_test(NAME bfTvMNFImageFilter4 COMMAND otbDimensionalityReductionTestDriv ${BASELINE}/bfTvMNFImageFilter4Inv.tif ${TEMP}/bfTvMNFImageFilter4Inv.tif otbMNFImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvMNFImageFilter4.tif - -inv ${TEMP}/bfTvMNFImageFilter4Inv.tif - -norm - -n 4) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvMNFImageFilter4.tif + ${TEMP}/bfTvMNFImageFilter4Inv.tif + true + 4) otb_add_test(NAME bfTvInnerProductPCAImageFilter_PC12 COMMAND otbDimensionalityReductionTestDriver --compare-image ${EPSILON_7} @@ -261,10 +297,11 @@ otb_add_test(NAME bfTvPCAImageFilter2 COMMAND otbDimensionalityReductionTestDriv ${INPUTDATA}/cupriteSubHsi.tif ${TEMP}/bfTvPCAImageFilter2Inv.tif otbPCAImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvPCAImageFilter2.tif - -inv ${TEMP}/bfTvPCAImageFilter2Inv.tif - -norm) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvPCAImageFilter2.tif + ${TEMP}/bfTvPCAImageFilter2Inv.tif + true + 0) otb_add_test(NAME bfTvPCAImageFilter4 COMMAND otbDimensionalityReductionTestDriver --compare-n-images ${EPSILON_7} 2 @@ -273,10 +310,11 @@ otb_add_test(NAME bfTvPCAImageFilter4 COMMAND otbDimensionalityReductionTestDriv ${BASELINE}/bfTvPCAImageFilter4Inv.tif ${TEMP}/bfTvPCAImageFilter4Inv.tif otbPCAImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvPCAImageFilter4.tif - -inv ${TEMP}/bfTvPCAImageFilter4Inv.tif - -n 4) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvPCAImageFilter4.tif + ${TEMP}/bfTvPCAImageFilter4Inv.tif + false + 4) otb_add_test(NAME bfTvPCAImageFilter4Norm COMMAND otbDimensionalityReductionTestDriver --compare-n-images ${EPSILON_7} 2 @@ -285,11 +323,11 @@ otb_add_test(NAME bfTvPCAImageFilter4Norm COMMAND otbDimensionalityReductionTest ${BASELINE}/bfTvPCAImageFilter4InvNorm.tif ${TEMP}/bfTvPCAImageFilter4InvNorm.tif otbPCAImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvPCAImageFilter4Norm.tif - -inv ${TEMP}/bfTvPCAImageFilter4InvNorm.tif - -norm - -n 4) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvPCAImageFilter4Norm.tif + ${TEMP}/bfTvPCAImageFilter4InvNorm.tif + true + 4) otb_add_test(NAME bfTvPCAImageFilter3 COMMAND otbDimensionalityReductionTestDriver --compare-n-images ${EPSILON_7} 2 @@ -298,19 +336,23 @@ otb_add_test(NAME bfTvPCAImageFilter3 COMMAND otbDimensionalityReductionTestDriv ${BASELINE}/bfTvPCAImageFilter3Inv.tif ${TEMP}/bfTvPCAImageFilter3Inv.tif otbPCAImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvPCAImageFilter3.tif - -inv ${TEMP}/bfTvPCAImageFilter3Inv.tif - ) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvPCAImageFilter3.tif + ${TEMP}/bfTvPCAImageFilter3Inv.tif + false + 0) otb_add_test(NAME bfTvPCAImageFilter1 COMMAND otbDimensionalityReductionTestDriver --compare-image ${EPSILON_7} ${INPUTDATA}/cupriteSubHsi.tif ${TEMP}/bfTvPCAImageFilter1Inv.tif otbPCAImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvPCAImageFilter1.tif - -inv ${TEMP}/bfTvPCAImageFilter1Inv.tif) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvPCAImageFilter1.tif + ${TEMP}/bfTvPCAImageFilter1Inv.tif + false + 0) + otb_add_test(NAME bfTvPCAImageFilter3Norm COMMAND otbDimensionalityReductionTestDriver --compare-n-images ${EPSILON_7} 2 @@ -319,19 +361,22 @@ otb_add_test(NAME bfTvPCAImageFilter3Norm COMMAND otbDimensionalityReductionTest ${BASELINE}/bfTvPCAImageFilter3InvNorm.tif ${TEMP}/bfTvPCAImageFilter3InvNorm.tif otbPCAImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvPCAImageFilter3Norm.tif - -inv ${TEMP}/bfTvPCAImageFilter3InvNorm.tif - -norm) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvPCAImageFilter3Norm.tif + ${TEMP}/bfTvPCAImageFilter3InvNorm.tif + true + 0) otb_add_test(NAME bfTvNAPCAImageFilter1 COMMAND otbDimensionalityReductionTestDriver --compare-image ${EPSILON_7} ${INPUTDATA}/cupriteSubHsi.tif ${TEMP}/bfTvNAPCAImageFilter1Inv.tif otbNAPCAImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvNAPCAImageFilter1.tif - -inv ${TEMP}/bfTvNAPCAImageFilter1Inv.tif) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvNAPCAImageFilter1.tif + ${TEMP}/bfTvNAPCAImageFilter1Inv.tif + false + 0) otb_add_test(NAME bfTvNAPCAImageFilter3 COMMAND otbDimensionalityReductionTestDriver --compare-n-images ${EPSILON_7} 2 @@ -340,20 +385,22 @@ otb_add_test(NAME bfTvNAPCAImageFilter3 COMMAND otbDimensionalityReductionTestDr ${BASELINE}/bfTvNAPCAImageFilter3Inv.tif ${TEMP}/bfTvNAPCAImageFilter3Inv.tif otbNAPCAImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvNAPCAImageFilter3.tif - -inv ${TEMP}/bfTvNAPCAImageFilter3Inv.tif - -norm) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvNAPCAImageFilter3.tif + ${TEMP}/bfTvNAPCAImageFilter3Inv.tif + true + 0) otb_add_test(NAME bfTvNAPCAImageFilter2 COMMAND otbDimensionalityReductionTestDriver --compare-image ${EPSILON_7} ${INPUTDATA}/cupriteSubHsi.tif ${TEMP}/bfTvNAPCAImageFilter2Inv.tif otbNAPCAImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvNAPCAImageFilter2.tif - -inv ${TEMP}/bfTvNAPCAImageFilter2Inv.tif - -norm) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvNAPCAImageFilter2.tif + ${TEMP}/bfTvNAPCAImageFilter2Inv.tif + true + 0) otb_add_test(NAME bfTvNAPCAImageFilter4 COMMAND otbDimensionalityReductionTestDriver --compare-n-images ${EPSILON_7} 2 @@ -362,16 +409,16 @@ otb_add_test(NAME bfTvNAPCAImageFilter4 COMMAND otbDimensionalityReductionTestDr ${BASELINE}/bfTvNAPCAImageFilter4Inv.tif ${TEMP}/bfTvNAPCAImageFilter4Inv.tif otbNAPCAImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvNAPCAImageFilter4.tif - -inv ${TEMP}/bfTvNAPCAImageFilter4Inv.tif - -norm - -n 4) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvNAPCAImageFilter4.tif + ${TEMP}/bfTvNAPCAImageFilter4Inv.tif + true + 4) otb_add_test(NAME bfTvLocalActivityVectorImageFilter COMMAND otbDimensionalityReductionTestDriver --compare-image ${EPSILON_7} ${BASELINE}/bfTvLocalActivityVectorImageFilter.tif ${TEMP}/bfTvLocalActivityVectorImageFilter.tif otbLocalActivityVectorImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvLocalActivityVectorImageFilter.tif) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvLocalActivityVectorImageFilter.tif) diff --git a/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionBinaryImageFilter.cxx b/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionBinaryImageFilter.cxx index 811522c5bd8bcf2dfee3822e76b711153cb97e0f..0921c3e31f86f09ba455d6a64cca524d94371355 100644 --- a/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionBinaryImageFilter.cxx +++ b/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionBinaryImageFilter.cxx @@ -25,41 +25,15 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" #include "otbAngularProjectionBinaryImageFilter.h" -int otbAngularProjectionBinaryImageFilterTest ( int argc, char * argv[] ) +int otbAngularProjectionBinaryImageFilterTest ( int , char * argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddOption( "--InputImages", "Input Images", "-in", 2, true ); - parser->AddOption( "--OutputImages", "Generic name for output Images (_#.hdr will be added)", "-out", 1, true ); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs angular projection on 2 images\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } - - std::string inputImageName1(parseResult->GetParameterString("--InputImages", 0)); - std::string inputImageName2(parseResult->GetParameterString("--InputImages", 1)); - std::string outputImageName(parseResult->GetParameterString("--OutputImages")); + std::string inputImageName1(argv[1]); + std::string inputImageName2(argv[2]); + std::string outputImageName1(argv[3]); + std::string outputImageName2(argv[4]); // Main type definition const unsigned int Dimension = 2; @@ -83,7 +57,7 @@ int otbAngularProjectionBinaryImageFilterTest ( int argc, char * argv[] ) std::vector< PixelType > angle; angle.push_back( otb::CONST_PI_2 ); - angle.push_back( 0. ); + angle.push_back( 0 ); filter->SetAngleSet( angle ); @@ -94,18 +68,15 @@ int otbAngularProjectionBinaryImageFilterTest ( int argc, char * argv[] ) filter->Update(); typedef otb::ImageFileWriter< ImageType > WriterType; - std::vector< WriterType::Pointer > writers; - writers.resize( filter->GetNumberOfOutputs() ); - - for ( unsigned int i = 0; i < filter->GetNumberOfOutputs(); ++i ) - { - std::stringstream title; - title << outputImageName << "_" << i << ".hdr"; + auto writer1 = WriterType::New(); + writer1->SetFileName(outputImageName1); + writer1->SetInput( filter->GetOutput(0) ); + writer1->Update(); + + auto writer2 = WriterType::New(); + writer2->SetFileName(outputImageName2); + writer2->SetInput( filter->GetOutput(1) ); + writer2->Update(); - writers[i] = WriterType::New(); - writers[i]->SetFileName( title.str() ); - writers[i]->SetInput( filter->GetOutput(i) ); - writers[i]->Update(); - } return EXIT_SUCCESS; } diff --git a/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionImageFilter.cxx b/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionImageFilter.cxx index e5cd9510e6466a6834469e941aff33fc83fcfce9..043e17e45132c8e4e432cb94c35060b78398429a 100644 --- a/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionImageFilter.cxx +++ b/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionImageFilter.cxx @@ -25,41 +25,14 @@ #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -#include "otbCommandLineArgumentParser.h" #include "otbAngularProjectionImageFilter.h" -int otbAngularProjectionImageFilterTest ( int argc, char * argv[] ) +int otbAngularProjectionImageFilterTest ( int , char * argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddOption( "--InputImages", "Input Images", "-in", 2, true ); - parser->AddOutputImage(); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs otbAngularProjectionImageFilterTest\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } - - std::string inputImageName1 = parseResult->GetParameterString("--InputImages", 0); - std::string inputImageName2 = parseResult->GetParameterString("--InputImages", 1); - std::string outputImageName = parseResult->GetOutputImage(); + std::string inputImageName1 = argv[1]; + std::string inputImageName2 = argv[2]; + std::string outputImageName = argv[3]; // Main type definition const unsigned int Dimension = 2; diff --git a/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionSetImageFilter.cxx b/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionSetImageFilter.cxx index f94c41da360076f7666425f6946cc74cbd3dab4f..e01eda92142a1a4f1652a3763cc634e9d65b5671 100644 --- a/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionSetImageFilter.cxx +++ b/Modules/Filtering/DimensionalityReduction/test/otbAngularProjectionSetImageFilter.cxx @@ -25,46 +25,20 @@ #include "otbImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -#include "otbCommandLineArgumentParser.h" #include "otbAngularProjectionSetImageFilter.h" -int otbAngularProjectionSetImageFilterTest ( int argc, char * argv[] ) +int otbAngularProjectionSetImageFilterTest ( int, char * argv[] ) { const unsigned int Dimension = 2; const unsigned int SpaceDimension = 3; const unsigned int nbInputImages = SpaceDimension+1; - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); + // Use the same input several time in this test + std::string inputImageName = argv[1]; - parser->AddOption( "--InputImages", "Input Images", "-in", nbInputImages, true ); - parser->AddOption( "--OutputImages", "Generic name for output Images (_#.hdr will be added)", "-out", 1, true ); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs otbAngularProjectionSetImageFilterTest with " << nbInputImages << " images\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } - - std::string inputImageName [ nbInputImages ]; - for ( unsigned int i = 0; i < nbInputImages; i++ ) - inputImageName[i] = parseResult->GetParameterString("--InputImages", i); - std::string outputImageName = parseResult->GetParameterString("--OutputImages"); + // We only have one output here + std::string outputImageName = argv[2]; // Main type definition typedef float PixelType; @@ -81,7 +55,7 @@ int otbAngularProjectionSetImageFilterTest ( int argc, char * argv[] ) for ( unsigned int i = 0; i < nbInputImages; i++ ) { reader->SetNthElement(i, ReaderType::New()); - reader->GetNthElement(i)->SetFileName( inputImageName[i] ); + reader->GetNthElement(i)->SetFileName( inputImageName ); reader->GetNthElement(i)->Update(); } @@ -104,21 +78,17 @@ int otbAngularProjectionSetImageFilterTest ( int argc, char * argv[] ) filter->SetInput( i, reader->GetNthElement(i)->GetOutput() ); } filter->SetAngleList( angleList ); - + filter->Update(); // Saving typedef otb::ImageFileWriter< ImageType > WriterType; typedef otb::ObjectList< WriterType > WriterListType; WriterListType::Pointer writers = WriterListType::New(); writers->Resize( filter->GetOutput()->Size() ); - - for ( unsigned int i = 0; i < writers->Size(); i++ ) + for ( unsigned int i = 0; i < filter->GetOutput()->Size(); i++ ) { - std::ostringstream title; - title << outputImageName << "_" << i << ".hdr"; - writers->SetNthElement(i, WriterType::New()); WriterType::Pointer writer = writers->GetNthElement(i); - writer->SetFileName( title.str() ); + writer->SetFileName( outputImageName); writer->SetInput( filter->GetOutput()->GetNthElement(i) ); writer->Update(); } diff --git a/Modules/Filtering/DimensionalityReduction/test/otbDimensionalityReductionTestDriver.cxx b/Modules/Filtering/DimensionalityReduction/test/otbDimensionalityReductionTestDriver.cxx index 8662c8693cf566332f101685db5c5c1709e3f784..9b855b3196de9ae697d2c820207c75a9f9a9f17b 100644 --- a/Modules/Filtering/DimensionalityReduction/test/otbDimensionalityReductionTestDriver.cxx +++ b/Modules/Filtering/DimensionalityReduction/test/otbDimensionalityReductionTestDriver.cxx @@ -34,5 +34,5 @@ void RegisterTests() REGISTER_TEST(otbAngularProjectionImageFilterTest); REGISTER_TEST(otbLocalActivityVectorImageFilterTest); REGISTER_TEST(otbAngularProjectionBinaryImageFilterTest); - REGISTER_TEST(otbSparseWvltToAngleMapperListFilterTest); + // REGISTER_TEST(otbSparseWvltToAngleMapperListFilterTest); } diff --git a/Modules/Filtering/DimensionalityReduction/test/otbFastICAImageFilter.cxx b/Modules/Filtering/DimensionalityReduction/test/otbFastICAImageFilter.cxx index ae7db7a600e2fc14327b673e7dea7aa4c171bc0a..2a892582c48646402cc8b053c4195b3606e503f6 100644 --- a/Modules/Filtering/DimensionalityReduction/test/otbFastICAImageFilter.cxx +++ b/Modules/Filtering/DimensionalityReduction/test/otbFastICAImageFilter.cxx @@ -23,51 +23,19 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" - #include "otbFastICAImageFilter.h" -int otbFastICAImageFilterTest ( int argc, char* argv[] ) +int otbFastICAImageFilterTest ( int , char* argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddInputImage(); - parser->AddOption( "--NumComponents", "Number of components to keep for output", "-n", 1, false ); - parser->AddOption( "--Inverse", "Performs also the inverse transformation (give the output name)", "-inv", 1, false ); - parser->AddOption( "--NumIterations", "number of iterations (def.20)", "-iter", 1, false ); - parser->AddOption( "--Mu", "Give the increment weight of W in [0, 1] (def. 1)", "-mu", 1, false ); - parser->AddOutputImage(); - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " applies FastICA transformations\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } + std::string inputImageName = argv[1]; + std::string outputImageName = argv[2]; + std::string outputInvImageName = argv[3]; - std::string inputImageName = parseResult->GetInputImage(); - std::string outputImageName = parseResult->GetOutputImage(); - const unsigned int nbComponents = parseResult->IsOptionPresent("--NumComponents") ? - parseResult->GetParameterUInt("--NumComponents") : 0; - const unsigned int nbIterations = parseResult->IsOptionPresent("--NumIterations") ? - parseResult->GetParameterUInt("--NumIterations") : 20; - const double mu = parseResult->IsOptionPresent("--Mu" ) ? - parseResult->GetParameterDouble("--Mu") : 1.; + const unsigned int nbComponents = 0; + const unsigned int nbIterations = 20; + const double mu = 1.; // Main type definition const unsigned int Dimension = 2; @@ -102,7 +70,7 @@ int otbFastICAImageFilterTest ( int argc, char* argv[] ) // std::cerr << filter << "\n"; - if ( parseResult->IsOptionPresent("--Inverse") ) + if ( true ) { typedef otb::FastICAImageFilter< ImageType, ImageType, otb::Transform::INVERSE > InvFilterType; InvFilterType::Pointer invFilter = InvFilterType::New(); @@ -119,7 +87,7 @@ int otbFastICAImageFilterTest ( int argc, char* argv[] ) std::cerr << "Reconstruction\n"; ImageWriterType::Pointer invWriter = ImageWriterType::New(); - invWriter->SetFileName( parseResult->GetParameterString("--Inverse") ); + invWriter->SetFileName(outputInvImageName); invWriter->SetInput( invFilter->GetOutput() ); invWriter->Update(); } diff --git a/Modules/Filtering/DimensionalityReduction/test/otbLocalActivityVectorImageFilter.cxx b/Modules/Filtering/DimensionalityReduction/test/otbLocalActivityVectorImageFilter.cxx index 9b9f4397b41682a8e05c6a1a9d6538eef9fcf2c7..ea99870413e7e893fec1e4fa8c2cc8ebf78eb745 100644 --- a/Modules/Filtering/DimensionalityReduction/test/otbLocalActivityVectorImageFilter.cxx +++ b/Modules/Filtering/DimensionalityReduction/test/otbLocalActivityVectorImageFilter.cxx @@ -19,55 +19,19 @@ * limitations under the License. */ - #include "otbVectorImage.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" #include "otbLocalActivityVectorImageFilter.h" -int otbLocalActivityVectorImageFilterTest ( int argc, char* argv[] ) +int otbLocalActivityVectorImageFilterTest ( int, char* argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddInputImage(); - parser->AddOption( "--Radius", "Set the radius of the sliding window (def.1)", "-r", 2, false ); - parser->AddOutputImage(); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs the local activity estimation on a vector image\n"; - std::cerr << "Local activity is defined here a the difference between pixel and mean of surrounding\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } - - std::string inputImageName = parseResult->GetInputImage(); - std::string outputImageName = parseResult->GetOutputImage(); unsigned int radiusX = 1; unsigned int radiusY = 1; - if ( parseResult->IsOptionPresent("--Radius") ) - { - radiusX = parseResult->GetParameterUInt("--Radius", 0); - radiusY = parseResult->GetParameterUInt("--Radius", 1); - } + // Main type definition const unsigned int Dimension = 2; @@ -77,7 +41,7 @@ int otbLocalActivityVectorImageFilterTest ( int argc, char* argv[] ) // Reading input images typedef otb::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImageName); + reader->SetFileName( argv[1] ); // Image filtering typedef otb::LocalActivityVectorImageFilter< ImageType, ImageType > FilterType; @@ -93,7 +57,7 @@ int otbLocalActivityVectorImageFilterTest ( int argc, char* argv[] ) typedef otb::ImageFileWriter< ImageType > ImageWriterType; ImageWriterType::Pointer writer = ImageWriterType::New(); - writer->SetFileName( outputImageName ); + writer->SetFileName( argv[2] ); writer->SetInput( filter->GetOutput() ); writer->Update(); diff --git a/Modules/Filtering/DimensionalityReduction/test/otbMNFImageFilter.cxx b/Modules/Filtering/DimensionalityReduction/test/otbMNFImageFilter.cxx index 2764893a2eee7d77254071fa300eec42a230fc49..f8248353a4a58d4ab8e0bbda52e1bc722986d967 100644 --- a/Modules/Filtering/DimensionalityReduction/test/otbMNFImageFilter.cxx +++ b/Modules/Filtering/DimensionalityReduction/test/otbMNFImageFilter.cxx @@ -23,56 +23,30 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" #include "otbMNFImageFilter.h" #include "otbLocalActivityVectorImageFilter.h" -int otbMNFImageFilterTest ( int argc, char* argv[] ) +int otbMNFImageFilterTest ( int , char* argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); + /* + usage : otbMNFImageFilterTest input output inv norm nbcomponent=1 + */ + unsigned int radiusX = 1; + unsigned int radiusY = 1; - parser->AddInputImage(); - parser->AddOption( "--NumComponents", "Number of components to keep for output", "-n", 1, false ); - parser->AddOption( "--Inverse", "Performs also the inverse transformation (give the output name)", "-inv", 1, false ); - parser->AddOption( "--Radius", "Set the radius of the sliding window (def.1)", "-r", 2, false ); - parser->AddOption( "--Normalize", "center and reduce data before MNF", "-norm", 0, false ); - parser->AddOutputImage(); + bool want_inv = true; + if ( std::string(argv[3]).compare("none") == 0) + { + want_inv = false; + } - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); + bool normalization = false; + if ( std::string(argv[4]).compare("true") == 0) + normalization = true; - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " applies MNF transformations\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } - - std::string inputImageName = parseResult->GetInputImage(); - std::string outputImageName = parseResult->GetOutputImage(); - const unsigned int nbComponents = parseResult->IsOptionPresent("--NumComponents") ? - parseResult->GetParameterUInt("--NumComponents") : 0; - unsigned int radiusX = 1; - unsigned int radiusY = 1; - if ( parseResult->IsOptionPresent("--Radius") ) - { - radiusX = parseResult->GetParameterUInt("--Radius", 0); - radiusY = parseResult->GetParameterUInt("--Radius", 1); - } - const bool normalization = parseResult->IsOptionPresent("--Normalize"); + int nbComponents = std::stoi(argv[5]); // Main type definition const unsigned int Dimension = 2; @@ -82,7 +56,7 @@ int otbMNFImageFilterTest ( int argc, char* argv[] ) // Reading input images typedef otb::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImageName); + reader->SetFileName(argv[1]); // Noise filtering typedef otb::LocalActivityVectorImageFilter< ImageType, ImageType > NoiseFilterType; @@ -104,12 +78,12 @@ int otbMNFImageFilterTest ( int argc, char* argv[] ) // Writing typedef otb::ImageFileWriter< ImageType > ImageWriterType; ImageWriterType::Pointer writer = ImageWriterType::New(); - writer->SetFileName( outputImageName ); + writer->SetFileName( argv[2] ); writer->SetInput( filter->GetOutput() ); writer->Update(); - if ( parseResult->IsOptionPresent("--Inverse") ) + if ( want_inv ) { typedef otb::MNFImageFilter< ImageType, ImageType, NoiseFilterType, otb::Transform::INVERSE > InvFilterType; @@ -125,7 +99,7 @@ int otbMNFImageFilterTest ( int argc, char* argv[] ) invFilter->AddObserver( itk::ProgressEvent(), invObserver ); ImageWriterType::Pointer invWriter = ImageWriterType::New(); - invWriter->SetFileName( parseResult->GetParameterString("--Inverse") ); + invWriter->SetFileName( argv[3] ); invWriter->SetInput( invFilter->GetOutput() ); invWriter->Update(); } diff --git a/Modules/Filtering/DimensionalityReduction/test/otbNAPCAImageFilter.cxx b/Modules/Filtering/DimensionalityReduction/test/otbNAPCAImageFilter.cxx index 800224f080afdc9edaecacafaeaea0852a5ff2d4..5e50f8d571717b247af096c66e37007d4bcc2679 100644 --- a/Modules/Filtering/DimensionalityReduction/test/otbNAPCAImageFilter.cxx +++ b/Modules/Filtering/DimensionalityReduction/test/otbNAPCAImageFilter.cxx @@ -23,56 +23,21 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" #include "otbNAPCAImageFilter.h" #include "otbLocalActivityVectorImageFilter.h" -int otbNAPCAImageFilterTest ( int argc, char* argv[] ) +int otbNAPCAImageFilterTest ( int , char* argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddInputImage(); - parser->AddOption( "--NumComponents", "Number of components to keep for output", "-n", 1, false ); - parser->AddOption( "--Inverse", "Performs also the inverse transformation (give the output name)", "-inv", 1, false ); - parser->AddOption( "--Radius", "Set the radius of the sliding window (def.1)", "-r", 2, false ); - parser->AddOption( "--Normalize", "center and reduce data before NAPCA", "-norm", 0, false ); - parser->AddOutputImage(); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " applies NAPCA transformations\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } - - std::string inputImageName = parseResult->GetInputImage(); - std::string outputImageName = parseResult->GetOutputImage(); - const unsigned int nbComponents = parseResult->IsOptionPresent("--NumComponents") ? - parseResult->GetParameterUInt("--NumComponents") : 0; + + const unsigned int nbComponents = atoi(argv[5]); unsigned int radiusX = 1; unsigned int radiusY = 1; - if ( parseResult->IsOptionPresent("--Radius") ) - { - radiusX = parseResult->GetParameterUInt("--Radius", 0); - radiusY = parseResult->GetParameterUInt("--Radius", 1); - } - const bool normalization = parseResult->IsOptionPresent("--Normalize"); + + bool normalization = false ; + if ( std::string( argv[4] ).compare("true") == 0 ) + normalization = true; // Main type definition const unsigned int Dimension = 2; @@ -82,7 +47,7 @@ int otbNAPCAImageFilterTest ( int argc, char* argv[] ) // Reading input images typedef otb::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImageName); + reader->SetFileName(argv[1]); // Noise filtering typedef otb::LocalActivityVectorImageFilter< ImageType, ImageType > NoiseFilterType; @@ -104,31 +69,27 @@ int otbNAPCAImageFilterTest ( int argc, char* argv[] ) // Writing typedef otb::ImageFileWriter< ImageType > ImageWriterType; ImageWriterType::Pointer writer = ImageWriterType::New(); - writer->SetFileName( outputImageName ); + writer->SetFileName( argv[2] ); writer->SetInput( filter->GetOutput() ); writer->Update(); - - if ( parseResult->IsOptionPresent("--Inverse") ) - { - typedef otb::NAPCAImageFilter< ImageType, ImageType, - NoiseFilterType, otb::Transform::INVERSE > InvFilterType; - InvFilterType::Pointer invFilter = InvFilterType::New(); - invFilter->SetInput( filter->GetOutput() ); - invFilter->SetMeanValues( filter->GetMeanValues() ); - if ( normalization ) - invFilter->SetStdDevValues( filter->GetStdDevValues() ); - invFilter->SetTransformationMatrix( filter->GetTransformationMatrix() ); - - typedef otb::CommandProgressUpdate< InvFilterType > CommandType2; - CommandType2::Pointer invObserver = CommandType2::New(); - invFilter->AddObserver( itk::ProgressEvent(), invObserver ); - - ImageWriterType::Pointer invWriter = ImageWriterType::New(); - invWriter->SetFileName( parseResult->GetParameterString("--Inverse") ); - invWriter->SetInput( invFilter->GetOutput() ); - invWriter->Update(); - } + typedef otb::NAPCAImageFilter< ImageType, ImageType, + NoiseFilterType, otb::Transform::INVERSE > InvFilterType; + InvFilterType::Pointer invFilter = InvFilterType::New(); + invFilter->SetInput( filter->GetOutput() ); + invFilter->SetMeanValues( filter->GetMeanValues() ); + if ( normalization ) + invFilter->SetStdDevValues( filter->GetStdDevValues() ); + invFilter->SetTransformationMatrix( filter->GetTransformationMatrix() ); + + typedef otb::CommandProgressUpdate< InvFilterType > CommandType2; + CommandType2::Pointer invObserver = CommandType2::New(); + invFilter->AddObserver( itk::ProgressEvent(), invObserver ); + + ImageWriterType::Pointer invWriter = ImageWriterType::New(); + invWriter->SetFileName( argv[3] ); + invWriter->SetInput( invFilter->GetOutput() ); + invWriter->Update(); return EXIT_SUCCESS; } diff --git a/Modules/Filtering/DimensionalityReduction/test/otbPCAImageFilter.cxx b/Modules/Filtering/DimensionalityReduction/test/otbPCAImageFilter.cxx index f2c92fced016617306e34f0b3afdb493e5a2a07d..25d68f4506006c5be3f10c5285e324f8d57b00c4 100644 --- a/Modules/Filtering/DimensionalityReduction/test/otbPCAImageFilter.cxx +++ b/Modules/Filtering/DimensionalityReduction/test/otbPCAImageFilter.cxx @@ -23,46 +23,16 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" #include "otbPCAImageFilter.h" -int otbPCAImageFilterTest ( int argc, char* argv[] ) +int otbPCAImageFilterTest ( int, char* argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); + const unsigned int nbComponents = atoi(argv[5]); - parser->AddInputImage(); - parser->AddOption( "--NumComponents", "Number of components to keep for output", "-n", 1, false ); - parser->AddOption( "--Inverse", "Performs also the inverse transformation (give the output name)", "-inv", 1, false ); - parser->AddOption( "--Normalize", "center AND reduce data before PCA", "-norm", 0, false ); - parser->AddOutputImage(); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " applies PCA transformations\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } - - std::string inputImageName = parseResult->GetInputImage(); - std::string outputImageName = parseResult->GetOutputImage(); - const unsigned int nbComponents = parseResult->IsOptionPresent("--NumComponents") ? - parseResult->GetParameterUInt("--NumComponents") : 0; - const bool normalization = parseResult->IsOptionPresent("--Normalize"); + bool normalization = false ; + if ( std::string( argv[4] ).compare("true") == 0 ) + normalization = true; // Main type definition const unsigned int Dimension = 2; @@ -72,7 +42,7 @@ int otbPCAImageFilterTest ( int argc, char* argv[] ) // Reading input images typedef otb::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImageName); + reader->SetFileName(argv[1]); // Image filtering typedef otb::PCAImageFilter< ImageType, ImageType, otb::Transform::FORWARD > FilterType; @@ -88,32 +58,29 @@ int otbPCAImageFilterTest ( int argc, char* argv[] ) // Writing typedef otb::ImageFileWriter< ImageType > ImageWriterType; ImageWriterType::Pointer writer = ImageWriterType::New(); - writer->SetFileName( outputImageName ); + writer->SetFileName( argv[2] ); writer->SetInput( filter->GetOutput() ); writer->Update(); - - if ( parseResult->IsOptionPresent("--Inverse") ) + typedef otb::PCAImageFilter< ImageType, ImageType, otb::Transform::INVERSE > InvFilterType; + InvFilterType::Pointer invFilter = InvFilterType::New(); + invFilter->SetInput( filter->GetOutput() ); + if ( normalization ) { - typedef otb::PCAImageFilter< ImageType, ImageType, otb::Transform::INVERSE > InvFilterType; - InvFilterType::Pointer invFilter = InvFilterType::New(); - invFilter->SetInput( filter->GetOutput() ); - if ( normalization ) - { - invFilter->SetMeanValues( filter->GetMeanValues() ); - invFilter->SetStdDevValues( filter->GetStdDevValues() ); - } - invFilter->SetTransformationMatrix( filter->GetTransformationMatrix() ); + invFilter->SetMeanValues( filter->GetMeanValues() ); + invFilter->SetStdDevValues( filter->GetStdDevValues() ); + } + invFilter->SetTransformationMatrix( filter->GetTransformationMatrix() ); - typedef otb::CommandProgressUpdate< InvFilterType > CommandType2; - CommandType2::Pointer invObserver = CommandType2::New(); - invFilter->AddObserver( itk::ProgressEvent(), invObserver ); + typedef otb::CommandProgressUpdate< InvFilterType > CommandType2; + CommandType2::Pointer invObserver = CommandType2::New(); + invFilter->AddObserver( itk::ProgressEvent(), invObserver ); + + ImageWriterType::Pointer invWriter = ImageWriterType::New(); + invWriter->SetFileName( argv[3] ); + invWriter->SetInput( invFilter->GetOutput() ); + invWriter->Update(); - ImageWriterType::Pointer invWriter = ImageWriterType::New(); - invWriter->SetFileName( parseResult->GetParameterString("--Inverse") ); - invWriter->SetInput( invFilter->GetOutput() ); - invWriter->Update(); - } return EXIT_SUCCESS; } diff --git a/Modules/Filtering/DimensionalityReduction/test/otbSparseWvltToAngleMapperListFilter.cxx b/Modules/Filtering/DimensionalityReduction/test/otbSparseWvltToAngleMapperListFilter.cxx index 8623db63ac6d034b10d25be7f427f0e7f77f341a..dbe01cd353a5d014b83a720f4e580e8273490698 100644 --- a/Modules/Filtering/DimensionalityReduction/test/otbSparseWvltToAngleMapperListFilter.cxx +++ b/Modules/Filtering/DimensionalityReduction/test/otbSparseWvltToAngleMapperListFilter.cxx @@ -25,51 +25,22 @@ #include "otbWaveletTransform.h" #include "otbImageFileReader.h" #include "otbImageFileWriter.h" -#include "otbCommandLineArgumentParser.h" #include "itkListSample.h" #include "otbSparseWvltToAngleMapperListFilter.h" -int otbSparseWvltToAngleMapperListFilterTest ( int argc, char * argv[] ) +int otbSparseWvltToAngleMapperListFilterTest ( int , char * [] ) { // number of images to consider const unsigned int Dimension = 2; const unsigned int nbInputImages = 2; - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddOption( "--InputImages", "Input Images", "-in", nbInputImages, true ); - //parser->AddOption( "--OutputImages", "Generic name for output Images (_#.hdr will be added)", "-out", 1, true ); - parser->AddOption( "--Threshold", "Lower threshold for accounting the waBinaryFunctorImageListToSampleListFiltervelet coeffs (def. 10)", "-th", 1, false ); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs otbSparseWvltToAngleMapperListFilterNewTest on " << nbInputImages << " images\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } - std::string inputImageName [ nbInputImages ]; for ( unsigned int i = 0; i < nbInputImages; i++ ) - inputImageName[i] = parseResult->GetParameterString("--InputImages", i); + inputImageName[i] = ""; // Parameter (to be changed if necessary) - const double threshold = parseResult->IsOptionPresent("--Threshold") ? - parseResult->GetParameterDouble("--Threshold") : 10.; + const double threshold = 10.; // Main type definition typedef float PixelType; diff --git a/Modules/Filtering/ImageManipulation/otb-module.cmake b/Modules/Filtering/ImageManipulation/otb-module.cmake index f67964ec0423623b158a0dd7a8139541caa63e8e..8d908064ec2b99150f2f24dff3ed21691076b348 100644 --- a/Modules/Filtering/ImageManipulation/otb-module.cmake +++ b/Modules/Filtering/ImageManipulation/otb-module.cmake @@ -38,7 +38,6 @@ otb_module(OTBImageManipulation OTBTransform TEST_DEPENDS - OTBCommandLineParser OTBDensity OTBImageIO OTBTestKernel diff --git a/Modules/Filtering/ImageManipulation/test/CMakeLists.txt b/Modules/Filtering/ImageManipulation/test/CMakeLists.txt index e86ba7b8fda735f859203a9552cc9c55c5613316..b2d6fa66d71cb7a2fc86c45f1f957e7c8230526d 100644 --- a/Modules/Filtering/ImageManipulation/test/CMakeLists.txt +++ b/Modules/Filtering/ImageManipulation/test/CMakeLists.txt @@ -448,8 +448,8 @@ otb_add_test(NAME bfTvLocalGradientVectorImageFilter COMMAND otbImageManipulatio ${BASELINE}/bfTvLocalGradientVectorImageFilter.tif ${TEMP}/bfTvLocalGradientVectorImageFilter.tif otbLocalGradientVectorImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvLocalGradientVectorImageFilter.tif) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvLocalGradientVectorImageFilter.tif) otb_add_test(NAME bfTvBoundingRegionCalculator COMMAND otbImageManipulationTestDriver --compare-ascii ${NOTOL} diff --git a/Modules/Filtering/ImageManipulation/test/otbLocalGradientVectorImageFilter.cxx b/Modules/Filtering/ImageManipulation/test/otbLocalGradientVectorImageFilter.cxx index 2adaff84fd47c4909cafaaec33022ebe5b22b59b..ddc54c3b444627d734063ddc786881e359416e08 100644 --- a/Modules/Filtering/ImageManipulation/test/otbLocalGradientVectorImageFilter.cxx +++ b/Modules/Filtering/ImageManipulation/test/otbLocalGradientVectorImageFilter.cxx @@ -24,40 +24,16 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" - #include "otbLocalGradientVectorImageFilter.h" int otbLocalGradientVectorImageFilterTest ( int argc, char* argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddInputImage(); - parser->AddOutputImage(); - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs horizonal sobel on a vector image\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; + if (argc != 3) + { + std::cerr << "Usage: otbLocalGradientVectorImageFilterTest input output\n"; return EXIT_FAILURE; - } - - std::string inputImageName = parseResult->GetInputImage(); - std::string outputImageName = parseResult->GetOutputImage(); + } // Main type definition const unsigned int Dimension = 2; @@ -67,7 +43,7 @@ int otbLocalGradientVectorImageFilterTest ( int argc, char* argv[] ) // Reading input images typedef otb::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImageName); + reader->SetFileName(argv[1]); // Image filtering typedef otb::LocalGradientVectorImageFilter< ImageType, ImageType > @@ -81,7 +57,7 @@ int otbLocalGradientVectorImageFilterTest ( int argc, char* argv[] ) typedef otb::ImageFileWriter< ImageType > ImageWriterType; ImageWriterType::Pointer writer = ImageWriterType::New(); - writer->SetFileName( outputImageName ); + writer->SetFileName( argv[2] ); writer->SetInput( filter->GetOutput() ); writer->Update(); diff --git a/Modules/Filtering/Projection/otb-module.cmake b/Modules/Filtering/Projection/otb-module.cmake index 9dbc49a3f7232ab168518a5e5db91f595d058d7a..0e8267d87763f4c86257d191daa5a38be17ed24e 100644 --- a/Modules/Filtering/Projection/otb-module.cmake +++ b/Modules/Filtering/Projection/otb-module.cmake @@ -42,7 +42,6 @@ ENABLE_SHARED OTBVectorDataManipulation TEST_DEPENDS - OTBCommandLineParser OTBImageIO OTBTestKernel OTBVectorDataIO diff --git a/Modules/Filtering/Projection/test/CMakeLists.txt b/Modules/Filtering/Projection/test/CMakeLists.txt index 36a5965e6fec9ebda2264f2e3714a789cb70a682..3fabcfe5c660b5210b59adbd12c8fed563a073ce 100644 --- a/Modules/Filtering/Projection/test/CMakeLists.txt +++ b/Modules/Filtering/Projection/test/CMakeLists.txt @@ -627,9 +627,8 @@ otb_add_test(NAME bfTvSpectralAngleDataNodeFeatureFunction_Line COMMAND otbProje otb_add_test(NAME prTvGCPsToRPCSensorModelImageCheckInputGcpPointsProjection_WithDEM COMMAND otbProjectionTestDriver otbGCPsToRPCSensorModelImageFilterCheckRpcModel - -in ${INPUTDATA}/QB_TOULOUSE_MUL_Extract_500_500.tif - -dem ${INPUTDATA}/DEM/srtm_directory - -gcp + ${INPUTDATA}/QB_TOULOUSE_MUL_Extract_500_500.tif + ${INPUTDATA}/DEM/srtm_directory 2000 2000 1.4181 43.6147 135.084 2000 2050 1.41811 43.6135 134.185 2000 2100 1.41812 43.6123 135.728 @@ -730,13 +729,13 @@ otb_add_test(NAME prTvGCPsToRPCSensorModelImageCheckInputGcpPointsProjection_Wit 2450 2350 1.43238 43.6063 144.66 2450 2400 1.43239 43.6051 144.932 2450 2450 1.43239 43.6038 136.794 - -err 10 # Tolerance in meters, the first goal of this test + err=10 # Tolerance in meters, the first goal of this test ) otb_add_test(NAME prTvGCPsToRPCSensorModelImageCheckInputGcpPointsProjection_WithoutDEM COMMAND otbProjectionTestDriver otbGCPsToRPCSensorModelImageFilterCheckRpcModel - -in ${INPUTDATA}/QB_TOULOUSE_MUL_Extract_500_500.tif - -gcp + ${INPUTDATA}/QB_TOULOUSE_MUL_Extract_500_500.tif + no_output 2000 2000 1.41809 43.6143 0 2000 2050 1.4181 43.6131 0 2000 2100 1.4181 43.6119 0 @@ -837,7 +836,7 @@ otb_add_test(NAME prTvGCPsToRPCSensorModelImageCheckInputGcpPointsProjection_Wit 2450 2350 1.43238 43.6059 0 2450 2400 1.43238 43.6047 0 2450 2450 1.43239 43.6034 0 - -err 10 # Tolerance in meters, the first goal of this test + err=10 # Tolerance in meters, the first goal of this test ) otb_add_test(NAME prTvGeographicalDistance COMMAND otbProjectionTestDriver diff --git a/Modules/Filtering/Projection/test/otbGCPsToRPCSensorModelImageFilterCheckRpcModel.cxx b/Modules/Filtering/Projection/test/otbGCPsToRPCSensorModelImageFilterCheckRpcModel.cxx index 5d67185dce34173737c6f1773b72b0b13d944d5f..7707dc7b5a2dc618befabf4aea651c528ef90b44 100644 --- a/Modules/Filtering/Projection/test/otbGCPsToRPCSensorModelImageFilterCheckRpcModel.cxx +++ b/Modules/Filtering/Projection/test/otbGCPsToRPCSensorModelImageFilterCheckRpcModel.cxx @@ -18,50 +18,27 @@ * limitations under the License. */ -#include "otbCommandLineArgumentParser.h" #include "otbVectorImage.h" #include "otbImageFileReader.h" #include "otbGCPsToRPCSensorModelImageFilter.h" #include "otbGenericRSTransform.h" #include "otbGeographicalDistance.h" +#include <string> int otbGCPsToRPCSensorModelImageFilterCheckRpcModel(int argc, char * argv[]) { - // Set command line arguments - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddInputImage(); - parser->AddOption("--DEMDirectory", "Path to the DEM directory ", "-dem", 1, false); - parser->AddOptionNParams("--GroudControlPoints", - "Ground Control Points to estimate sensor model a1x a1y b1x b1y b1z ... aNx aNy aNz bNx bNy bNz", - "-gcp", true); - parser->AddOption("--ErrorAllowed", "Error allowed to declare a point not good ", "-err", 1, false); - - // Parse the command line - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine(argc, argv, parseResult); - } - catch ( itk::ExceptionObject & err ) - { - std::string descriptionException = err.GetDescription(); - if (descriptionException.find("ParseCommandLine(): Help Parser") != std::string::npos) + // Look for tolerance value + std::string s_tol = argv[argc-1] ; // last argument + int tol = 0; + unsigned int nbPoints = argc-3; + if ( s_tol.find("err=") != std::string::npos) { - return EXIT_SUCCESS; + nbPoints--; // last argument in not a gcp pairs point + tol = stoi( s_tol.substr( s_tol.find("=") + 1 ) ); } - if (descriptionException.find("ParseCommandLine(): Version Parser") != std::string::npos) - { - return EXIT_SUCCESS; - } - return EXIT_FAILURE; - } - // Check if the number of gcp pairs point is consistent - unsigned int nbPoints = parseResult->GetNumberOfParameters("--GroudControlPoints"); + + if (nbPoints % 5 != 0) { @@ -78,7 +55,7 @@ int otbGCPsToRPCSensorModelImageFilterCheckRpcModel(int argc, char * argv[]) typedef otb::GeographicalDistance<ImageType::PointType> GeoDistanceType; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(parseResult->GetInputImage()); + reader->SetFileName(argv[1]); reader->UpdateOutputInformation(); GCPsToSensorModelFilterType::Pointer rpcEstimator = GCPsToSensorModelFilterType::New(); @@ -90,13 +67,13 @@ int otbGCPsToRPCSensorModelImageFilterCheckRpcModel(int argc, char * argv[]) for (unsigned int gcpId = 0; gcpId < nbGCPs; ++gcpId) { Point2DType sensorPoint; - sensorPoint[0] = parseResult->GetParameterFloat("--GroudControlPoints", gcpId * 5); - sensorPoint[1] = parseResult->GetParameterFloat("--GroudControlPoints", 1 + gcpId * 5); + sensorPoint[0] = std::stof(argv[ 3 + gcpId * 5]); + sensorPoint[1] = std::stof(argv[ 4 + gcpId * 5]); Point3DType geoPoint; - geoPoint[0] = parseResult->GetParameterFloat("--GroudControlPoints", 2 + gcpId * 5); - geoPoint[1] = parseResult->GetParameterFloat("--GroudControlPoints", 3 + gcpId * 5); - geoPoint[2] = parseResult->GetParameterFloat("--GroudControlPoints", 4 + gcpId * 5); + geoPoint[0] = std::stof(argv[ 5 + gcpId * 5]); + geoPoint[1] = std::stof(argv[ 6 + gcpId * 5]); + geoPoint[2] = std::stof(argv[ 7 + gcpId * 5]); std::cout << "Adding GCP sensor: " << sensorPoint << " <-> geo: " << geoPoint << std::endl; @@ -117,15 +94,9 @@ int otbGCPsToRPCSensorModelImageFilterCheckRpcModel(int argc, char * argv[]) std::cout<<rpcEstimator->GetKeywordlist()<<std::endl; grsTrasnform->SetOutputProjectionRef("4326"); - // Set the DEM Directory if any - if(parseResult->IsOptionPresent("--DEMDirectory")) - { - otb::DEMHandler::Instance()->OpenDEMDirectory(parseResult->GetParameterString("--DEMDirectory")); - } - else - { - otb::DEMHandler::Instance()->SetDefaultHeightAboveEllipsoid(0); - } + // Set the DEM Directory + if ( std::string(argv[2]).compare("no_output") != 0) + otb::DEMHandler::Instance()->OpenDEMDirectory(argv[2]); grsTrasnform->InstantiateTransform(); @@ -136,9 +107,9 @@ int otbGCPsToRPCSensorModelImageFilterCheckRpcModel(int argc, char * argv[]) for (unsigned int gcpId = 0; gcpId < nbGCPs; ++gcpId) { Point3DType point; - point[0] = parseResult->GetParameterFloat("--GroudControlPoints", gcpId * 5); - point[1] = parseResult->GetParameterFloat("--GroudControlPoints", 1 + gcpId * 5); - point[2] = parseResult->GetParameterFloat("--GroudControlPoints", 4 + gcpId * 5); + point[0] = std::stof(argv[ 3 + gcpId * 5]); + point[1] = std::stof(argv[ 4 + gcpId * 5]); + point[2] = std::stof(argv[ 7 + gcpId * 5]); Point3DType transformedPoint; transformedPoint = grsTrasnform->TransformPoint(point); @@ -149,8 +120,8 @@ int otbGCPsToRPCSensorModelImageFilterCheckRpcModel(int argc, char * argv[]) // reference point Point2DType geoPoint; - geoPoint[0] = parseResult->GetParameterFloat("--GroudControlPoints", 2 + gcpId * 5); - geoPoint[1] = parseResult->GetParameterFloat("--GroudControlPoints", 3 + gcpId * 5); + geoPoint[0] = std::stof(argv[ 5 + gcpId * 5]); + geoPoint[1] = std::stof(argv[ 6 + gcpId * 5]); // Search for nans if ( vnl_math_isnan(transformedPoint2D[0]) || vnl_math_isnan(transformedPoint2D[1]) ) @@ -165,14 +136,14 @@ int otbGCPsToRPCSensorModelImageFilterCheckRpcModel(int argc, char * argv[]) // Search for wrong projection results double residual = geoDistance->Evaluate(geoPoint, transformedPoint2D); - if( residual > parseResult->GetParameterFloat("--ErrorAllowed")) + if( residual > tol ) { std::cout << "Reference : "<< geoPoint <<" --> Result of the reprojection using the estimated RpcModel " << transformedPoint2D << std::endl << " Residual ["<< residual << "] is higher than the tolerance [" - << parseResult->GetParameterFloat("--ErrorAllowed") + << tol <<"], there is a problem with the estimated RpcModel" <<std::endl<<std::endl; isErrorDetected = true; diff --git a/Modules/Filtering/Statistics/otb-module.cmake b/Modules/Filtering/Statistics/otb-module.cmake index ab1f3e9f1bade6994223564c58c36486ae01b3cb..855eb0b37dfcba94ccdc0ecf071849612d7c16af 100644 --- a/Modules/Filtering/Statistics/otb-module.cmake +++ b/Modules/Filtering/Statistics/otb-module.cmake @@ -35,7 +35,6 @@ otb_module(OTBStatistics OTBStreaming TEST_DEPENDS - OTBCommandLineParser OTBImageIO OTBImageManipulation OTBInterpolation diff --git a/Modules/Filtering/Statistics/test/CMakeLists.txt b/Modules/Filtering/Statistics/test/CMakeLists.txt index b257c9cf46a0daa5feb775cd8d1588c50d1c13fa..66c7bc0c662722577e05c08a18e80e80ec009cfb 100644 --- a/Modules/Filtering/Statistics/test/CMakeLists.txt +++ b/Modules/Filtering/Statistics/test/CMakeLists.txt @@ -105,8 +105,8 @@ otb_add_test(NAME bfTvNormalizeVectorImageFilter COMMAND otbStatisticsTestDriver ${BASELINE}/bfTvNormalizeVectorImageFilter.tif ${TEMP}/bfTvNormalizeVectorImageFilter.tif otbNormalizeVectorImageFilterTest - -in ${INPUTDATA}/cupriteSubHsi.tif - -out ${TEMP}/bfTvNormalizeVectorImageFilter.tif) + ${INPUTDATA}/cupriteSubHsi.tif + ${TEMP}/bfTvNormalizeVectorImageFilter.tif) otb_add_test(NAME bfTvVectorImageToMatrix COMMAND otbStatisticsTestDriver otbVectorImageToMatrixTest) diff --git a/Modules/Filtering/Statistics/test/otbNormalizeVectorImageFilter.cxx b/Modules/Filtering/Statistics/test/otbNormalizeVectorImageFilter.cxx index e2ffccefbd290272bcb31faa7fc0688b44507488..b16c391d96483e1f9715f07a83e8509f3f59fd3b 100644 --- a/Modules/Filtering/Statistics/test/otbNormalizeVectorImageFilter.cxx +++ b/Modules/Filtering/Statistics/test/otbNormalizeVectorImageFilter.cxx @@ -22,41 +22,16 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" - #include "otbNormalizeVectorImageFilter.h" int otbNormalizeVectorImageFilterTest ( int argc, char* argv[] ) { - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddInputImage(); - parser->AddOutputImage(); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs horizonal sobel on a vector image\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; + if (argc != 3) + { + std::cerr << "Usage: otbNormalizeVectorImageFilterTest input output\n"; return EXIT_FAILURE; - } - - std::string inputImageName = parseResult->GetInputImage(); - std::string outputImageName = parseResult->GetOutputImage(); - + } + // Main type definition const unsigned int Dimension = 2; typedef double PixelType; @@ -65,7 +40,7 @@ int otbNormalizeVectorImageFilterTest ( int argc, char* argv[] ) // Reading input images typedef otb::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(inputImageName); + reader->SetFileName(argv[1]); // Image filtering typedef otb::NormalizeVectorImageFilter< ImageType, ImageType > @@ -79,7 +54,7 @@ int otbNormalizeVectorImageFilterTest ( int argc, char* argv[] ) typedef otb::ImageFileWriter< ImageType > ImageWriterType; ImageWriterType::Pointer writer = ImageWriterType::New(); - writer->SetFileName( outputImageName ); + writer->SetFileName( argv[2] ); writer->SetInput( filter->GetOutput() ); writer->Update(); diff --git a/Modules/Filtering/VectorDataManipulation/otb-module.cmake b/Modules/Filtering/VectorDataManipulation/otb-module.cmake index c04dfaaaf961c3845d8145a773f7e363cdf8efbf..80a8b2e7e09ee89a71b57d694c6274ba58b10c7d 100644 --- a/Modules/Filtering/VectorDataManipulation/otb-module.cmake +++ b/Modules/Filtering/VectorDataManipulation/otb-module.cmake @@ -34,7 +34,6 @@ otb_module(OTBVectorDataManipulation OTBVectorDataBase TEST_DEPENDS - OTBCommandLineParser OTBImageIO OTBProjection OTBTestKernel diff --git a/Modules/Filtering/VectorDataManipulation/test/CMakeLists.txt b/Modules/Filtering/VectorDataManipulation/test/CMakeLists.txt index 2cc1a69dfad2399db52039cc2ae65d2ceeecb280..c28c01c30de55907e0ba0556cb64d3c37a45fce8 100644 --- a/Modules/Filtering/VectorDataManipulation/test/CMakeLists.txt +++ b/Modules/Filtering/VectorDataManipulation/test/CMakeLists.txt @@ -95,9 +95,9 @@ otb_add_test(NAME bfTvConcatenateVectorDataFilter COMMAND otbVectorDataManipulat ${BASELINE_FILES}/otbConcatenateVectorDataFilter_Output.shp ${TEMP}/otbConcatenateVectorDataFilter_Output.shp otbConcatenateVectorDataFilter - -in ${INPUTDATA}/france_coastline.shp + ${INPUTDATA}/france_coastline.shp ${INPUTDATA}/waterways.shp - -out ${TEMP}/otbConcatenateVectorDataFilter_Output.shp + ${TEMP}/otbConcatenateVectorDataFilter_Output.shp ) otb_add_test(NAME bfTvRadiometryHomogenousWithNeighborhoodDataNodeFeatureFunction_Polygon COMMAND otbVectorDataManipulationTestDriver diff --git a/Modules/Filtering/VectorDataManipulation/test/otbConcatenateVectorDataFilter.cxx b/Modules/Filtering/VectorDataManipulation/test/otbConcatenateVectorDataFilter.cxx index 934bf7bdcccce7bf2b9edb0ebcfe9914061bccfc..9fa7f65b1949020e67f1b9c8980a3fc998e3bf1b 100644 --- a/Modules/Filtering/VectorDataManipulation/test/otbConcatenateVectorDataFilter.cxx +++ b/Modules/Filtering/VectorDataManipulation/test/otbConcatenateVectorDataFilter.cxx @@ -17,10 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - -#include "otbCommandLineArgumentParser.h" - // Images #include "otbVectorDataFileReader.h" #include "otbVectorDataFileWriter.h" @@ -36,29 +32,14 @@ typedef otb::ConcatenateVectorDataFilter<VectorDataType> ConcatenateFilterType; int otbConcatenateVectorDataFilter (int argc, char * argv[]) { - // Parse command line parameters - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - parser->AddOptionNParams("--InputVectorDatas","Input VectorDatas to concatenate ", "-in", true); - parser->AddOption("--OutputVectorData","Output concatenated VectorData","-out", true); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - parser->ParseCommandLine(argc, argv, parseResult); - - // Get number of input vectorDatas - unsigned int nbInputs = parseResult->GetNumberOfParameters("--InputVectorDatas"); - // Instantiate a concatenate filter - // Concatenate the vector datas + // Concatenate the vector datas ConcatenateFilterType::Pointer concatenate = ConcatenateFilterType::New(); - - for (unsigned int idx = 0; idx < nbInputs; ++idx) + for (int idx = 1; idx < argc-1 ; ++idx) { // Reader object ReaderType::Pointer reader = ReaderType::New(); - //std::cout << << std::endl; - reader->SetFileName(parseResult->GetParameterString("--InputVectorDatas", idx )); + reader->SetFileName(argv[idx]); reader->Update(); concatenate->AddInput(reader->GetOutput()); @@ -66,7 +47,7 @@ int otbConcatenateVectorDataFilter (int argc, char * argv[]) // Write the output WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(parseResult->GetParameterString("--OutputVectorData")); + writer->SetFileName(argv[argc-1]); writer->SetInput(concatenate->GetOutput()); writer->Update(); diff --git a/Modules/Hyperspectral/Unmixing/otb-module.cmake b/Modules/Hyperspectral/Unmixing/otb-module.cmake index 6e01bc8b434880c69037b47c55af28de30de17f8..a106820650315d9a8024c7ed9b15c54cec061e7b 100644 --- a/Modules/Hyperspectral/Unmixing/otb-module.cmake +++ b/Modules/Hyperspectral/Unmixing/otb-module.cmake @@ -36,7 +36,6 @@ otb_module(OTBUnmixing OTBWavelet TEST_DEPENDS - OTBCommandLineParser OTBImageIO OTBTestKernel diff --git a/Modules/Hyperspectral/Unmixing/test/otbSparseUnmixingImageFilter.cxx b/Modules/Hyperspectral/Unmixing/test/otbSparseUnmixingImageFilter.cxx index 0f0f6350f7c9eb0453a949bd33c8599491fd27f6..c853517d4e86c479ca623fd68f43b346ae00ff54 100644 --- a/Modules/Hyperspectral/Unmixing/test/otbSparseUnmixingImageFilter.cxx +++ b/Modules/Hyperspectral/Unmixing/test/otbSparseUnmixingImageFilter.cxx @@ -23,48 +23,18 @@ #include "otbImageFileReader.h" #include "otbImageFileWriter.h" #include "otbCommandProgressUpdate.h" -#include "otbCommandLineArgumentParser.h" #include "otbSparseUnmixingImageFilter.h" -int otbSparseUnmixingImageFilterTest ( int argc, char * argv[] ) +int otbSparseUnmixingImageFilterTest ( int , char * [] ) { // number of images to consider const unsigned int nbInputImages = 2; - - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->AddOption( "--InputImages", "Input Images", "-in", nbInputImages, true ); - parser->AddOption( "--OutputImages", "Generic name for output Images (_#.hdr will be added)", "-out", 1, true ); - parser->AddOption( "--Threshold", "Lower threshold for accounting the waBinaryFunctorImageListToSampleListFiltervelet coeffs (def. 10)", "-th", 1, false ); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine( argc, argv, parseResult ); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << argv[0] << " performs Wvlt unmixing on " << nbInputImages << " images\n"; - std::string descriptionException = err.GetDescription(); - if ( descriptionException.find("ParseCommandLine(): Help Parser") - != std::string::npos ) - return EXIT_SUCCESS; - if(descriptionException.find("ParseCommandLine(): Version Parser") - != std::string::npos ) - return EXIT_SUCCESS; - return EXIT_FAILURE; - } - std::string inputImageName [ nbInputImages ]; for ( unsigned int i = 0; i < nbInputImages; i++ ) - inputImageName[i] = parseResult->GetParameterString("--InputImages", i); - std::string outputImageName = parseResult->GetParameterString("--OutputImages"); - const double threshold = parseResult->IsOptionPresent("--Threshold") ? - parseResult->GetParameterDouble("--Threshold") : 10.; + inputImageName[i] = ""; + std::string outputImageName = ""; + const double threshold = 10.; // Main type definition const unsigned int Dimension = 2; diff --git a/Modules/IO/Carto/otb-module.cmake b/Modules/IO/Carto/otb-module.cmake index 96856ac4b7850c4f693c3586cb28ed35ef553f16..bf20c841ea995e566a7e7dff6a48c19c18f7ab12 100644 --- a/Modules/IO/Carto/otb-module.cmake +++ b/Modules/IO/Carto/otb-module.cmake @@ -42,7 +42,6 @@ ENABLE_SHARED OTBVectorDataIO TEST_DEPENDS - OTBCommandLineParser OTBTestKernel DESCRIPTION diff --git a/Modules/IO/Carto/test/CMakeLists.txt b/Modules/IO/Carto/test/CMakeLists.txt index 93eeec0f0ab8d80fc0fd74eaf821d4e747d7e1d5..ca67be3db3845ae87223df3d227d7ebb4e6a921c 100644 --- a/Modules/IO/Carto/test/CMakeLists.txt +++ b/Modules/IO/Carto/test/CMakeLists.txt @@ -41,10 +41,10 @@ otb_add_test(NAME ioTvImageToOSMVectorDataGenerator COMMAND otbCartoTestDriver ${BASELINE_FILES}/ioTvImageToOSMVectorDataGenerator_highway_motorway.shp ${TEMP}/ioTvImageToOSMVectorDataGenerator_highway_motorway.shp otbImageToOSMVectorDataGenerator - -in ${EXAMPLEDATA}/qb_RoadExtract.tif - -osm ${INPUTDATA}/qb_road.osm - -out ${TEMP}/ioTvImageToOSMVectorDataGenerator_highway_motorway.shp - -key highvay,motorway + ${EXAMPLEDATA}/qb_RoadExtract.tif + ${INPUTDATA}/qb_road.osm + ${TEMP}/ioTvImageToOSMVectorDataGenerator_highway_motorway.shp + highvay,motorway ) set_property(TEST ioTvImageToOSMVectorDataGenerator PROPERTY RESOURCE_LOCK web_access) @@ -63,8 +63,8 @@ otb_add_test(NAME ioTvOSMToVectorDataGeneratorByName COMMAND otbCartoTestDriver ${BASELINE_FILES}/ioTvOSMToVectorDataFilterByName_highway.shp ${TEMP}/ioTvOSMToVectorDataFilterByName_highway.shp otbOSMToVectorDataGeneratorByName - -osm ${INPUTDATA}/qb_road.osm - -vd ${TEMP}/ioTvOSMToVectorDataFilterByName_highway.shp + ${INPUTDATA}/qb_road.osm + ${TEMP}/ioTvOSMToVectorDataFilterByName_highway.shp ) set_property(TEST ioTvOSMToVectorDataGeneratorByName PROPERTY RESOURCE_LOCK web_access) diff --git a/Modules/IO/Carto/test/otbImageToOSMVectorDataGenerator.cxx b/Modules/IO/Carto/test/otbImageToOSMVectorDataGenerator.cxx index d2e1e8ab5816524319b0a2aa4807f183237d93fb..f6d838959d5e4f2f8bf29a1f71ea79b1e31efd11 100644 --- a/Modules/IO/Carto/test/otbImageToOSMVectorDataGenerator.cxx +++ b/Modules/IO/Carto/test/otbImageToOSMVectorDataGenerator.cxx @@ -18,9 +18,6 @@ * limitations under the License. */ - -#include "otbCommandLineArgumentParser.h" - #include "otbImageToOSMVectorDataGenerator.h" #include "otbVectorDataFileWriter.h" @@ -28,7 +25,6 @@ #include "otbImageFileReader.h" #include "otbVectorDataFileWriter.h" - typedef otb::VectorImage<unsigned int, 2> ImageType; typedef otb::ImageToOSMVectorDataGenerator<ImageType> FilterType; @@ -37,28 +33,12 @@ typedef FilterType::VectorDataType VectorDataType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::VectorDataFileWriter<VectorDataType> VectorDataFileWriterType; - - - int otbImageToOSMVectorDataGenerator(int argc, char * argv[]) { - // Parse command line parameters - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - parser->AddInputImage(); - parser->AddOption("--OutputVectorData","Output VectorData","-out", true); - parser->AddOption("--Key","Key to search in the XML OSM file","-key", 1, false); - parser->AddOption("--OSM","OSM XML file to be parsed","-osm", 1, false); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine(argc, argv, parseResult); - } - catch ( itk::ExceptionObject & ) + if (argc != 5) { + std::cerr << "Usage: otbImageToOSMVectorDataGenerator input osm_xml_file " + "output key_name\n"; return EXIT_FAILURE; } @@ -68,17 +48,14 @@ int otbImageToOSMVectorDataGenerator(int argc, char * argv[]) // Instantiate the image reader ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(parseResult->GetInputImage()); + reader->SetFileName(argv[1]); reader->UpdateOutputInformation(); // VectorData generator instantiation FilterType::Pointer vdgenerator = FilterType::New(); vdgenerator->SetInput(reader->GetOutput()); - if(parseResult->IsOptionPresent("--OSM")) - { - vdgenerator->SetUseUrl(false); - vdgenerator->SetFileName(parseResult->GetParameterString("--OSM")); - } + vdgenerator->SetUseUrl(false); + vdgenerator->SetFileName(argv[2]); vdgenerator->Update(); // Split the classes to get classes and values @@ -87,7 +64,7 @@ int otbImageToOSMVectorDataGenerator(int argc, char * argv[]) { std::string key; KeyValueType currentkeyvalue; - std::string str = parseResult->GetParameterString("--Key"); + std::string str = argv[4]; // find the position of the separator , size_t pos = str.find(","); @@ -106,21 +83,12 @@ int otbImageToOSMVectorDataGenerator(int argc, char * argv[]) // Write the generated vector data VectorDataFileWriterType::Pointer writer = VectorDataFileWriterType::New(); - writer->SetFileName(parseResult->GetParameterString("--OutputVectorData")); + writer->SetFileName(argv[3]); - if(parseResult->IsOptionPresent("--Key")) - { - const VectorDataType *vd = - vdgenerator->GetVectorDataByName(keyvalueList[0].first, + const VectorDataType *vd = + vdgenerator->GetVectorDataByName(keyvalueList[0].first, keyvalueList[0].second); - writer->SetInput(vd); - } - else - { - const VectorDataType *vd = - vdgenerator->GetVectorDataByName("highway"); - writer->SetInput(vd); - } + writer->SetInput(vd); // trigger the execution writer->Update(); diff --git a/Modules/IO/Carto/test/otbOSMDataToVectorDataTests.cxx b/Modules/IO/Carto/test/otbOSMDataToVectorDataTests.cxx index ce8f08c98e14911ec3da9a694035f132789f0448..82e39b3d4f287e86fd2216ecdeea02c0abac11ee 100644 --- a/Modules/IO/Carto/test/otbOSMDataToVectorDataTests.cxx +++ b/Modules/IO/Carto/test/otbOSMDataToVectorDataTests.cxx @@ -18,15 +18,12 @@ * limitations under the License. */ -#include "otbCommandLineArgumentParser.h" #include "otbOSMDataToVectorDataGenerator.h" #include "otbVectorDataFileWriter.h" - typedef otb::OSMDataToVectorDataGenerator FilterType; typedef otb::VectorDataFileWriter<FilterType::VectorDataType> VectorDataFileWriterType; - int otbOSMToVectorDataGeneratorTest (int itkNotUsed(argc), char * argv[]) { FilterType::Pointer filter = FilterType::New(); @@ -49,29 +46,14 @@ int otbOSMToVectorDataGeneratorTest (int itkNotUsed(argc), char * argv[]) int otbOSMToVectorDataGeneratorByName (int argc, char * argv[]) { - // Parse command line parameters - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - parser->AddOption("--OSMFile","The osm file containig the points to extract", - "-osm", 1, true); - - parser->AddOption("--OutputVectorData","The output vectordata", - "-vd", 1, true); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine(argc, argv, parseResult); - } - catch ( itk::ExceptionObject & ) + if (argc != 3) { + std::cerr << "Usage: otbOSMToVectorDataGeneratorByName input output\n"; return EXIT_FAILURE; } - + FilterType::Pointer filter = FilterType::New(); - filter->SetFileName(parseResult->GetParameterString("--OSMFile")); + filter->SetFileName(argv[1]); filter->SetUseUrl(false); // Set the extent of the request @@ -97,7 +79,7 @@ int otbOSMToVectorDataGeneratorByName (int argc, char * argv[]) // Write the VectorData VectorDataFileWriterType::Pointer writer = VectorDataFileWriterType::New(); - writer->SetFileName(parseResult->GetParameterString("--OutputVectorData")); + writer->SetFileName(argv[2]); writer->SetInput(v4); writer->Update(); diff --git a/Modules/IO/KMZWriter/otb-module.cmake b/Modules/IO/KMZWriter/otb-module.cmake index 2feb1967d723cac1d874149cd8706a218ec8757c..82a0d62ba989d251ca09ba63f695e48c4d5cabe0 100644 --- a/Modules/IO/KMZWriter/otb-module.cmake +++ b/Modules/IO/KMZWriter/otb-module.cmake @@ -34,7 +34,6 @@ otb_module(OTBKMZWriter OTBlibkml TEST_DEPENDS - OTBCommandLineParser OTBProjection OTBTestKernel diff --git a/Modules/IO/KMZWriter/test/CMakeLists.txt b/Modules/IO/KMZWriter/test/CMakeLists.txt index f5aa232c58b5956db09a0291761249b94f20b6f2..6f6462f74a1c425e1983e780e807c738c84cc3a5 100644 --- a/Modules/IO/KMZWriter/test/CMakeLists.txt +++ b/Modules/IO/KMZWriter/test/CMakeLists.txt @@ -66,12 +66,12 @@ otb_add_test(NAME ioTvKmzProductWriterWithGCP COMMAND otbKMZWriterTestDriver otb_add_test(NAME ioTvKmzProductWriterWithGCP_Logo_Legend COMMAND otbKMZWriterTestDriver otbKmzProductWriterWithLogoAndLegend - -in ${INPUTDATA}/Haiti1.jpeg - -lo ${INPUTDATA}/cnes.png - -le ${INPUTDATA}/otb_big.png - -dem ${INPUTDATA}/DEM/srtm_directory - -kmz ${TEMP}/ioTuHaitiKmzProductWithLogoAndLegend.kmz - -gcp 1980.000000 1986.000000 -72.351257 18.555075 0.000000 + ${INPUTDATA}/Haiti1.jpeg + ${INPUTDATA}/cnes.png + ${INPUTDATA}/otb_big.png + ${INPUTDATA}/DEM/srtm_directory + ${TEMP}/ioTuHaitiKmzProductWithLogoAndLegend.kmz + 1980.000000 1986.000000 -72.351257 18.555075 0.000000 1963.000000 1944.000000 -72.352051 18.556946 0.000000 2078.000000 1566.000000 -72.346130 18.574358 0.000000 2154.000000 1430.000000 -72.342377 18.580441 0.000000 diff --git a/Modules/IO/KMZWriter/test/otbKmzProductWriter.cxx b/Modules/IO/KMZWriter/test/otbKmzProductWriter.cxx index 3d34dcc716eb59e772594c42a4ddadb239dc70cf..65baa2c8504ef4661f01f5d2f5b380be2b390600 100644 --- a/Modules/IO/KMZWriter/test/otbKmzProductWriter.cxx +++ b/Modules/IO/KMZWriter/test/otbKmzProductWriter.cxx @@ -22,7 +22,6 @@ #include "otbImageFileReader.h" #include "otbKmzProductWriter.h" #include "otbGCPsToRPCSensorModelImageFilter.h" -#include "otbCommandLineArgumentParser.h" typedef otb::VectorImage<float, 2> ImageType; @@ -32,8 +31,6 @@ typedef otb::GCPsToRPCSensorModelImageFilter<ImageType> GCPsToSensorModelFilterT typedef GCPsToSensorModelFilterType::Point2DType Point2DType; typedef GCPsToSensorModelFilterType::Point3DType Point3DType; - - int otbKmzProductWriter(int argc, char* argv[]) { @@ -72,16 +69,16 @@ int otbKmzProductWriter(int argc, char* argv[]) for (unsigned int gcpId = 0; gcpId < nbGCPs; ++gcpId) { Point2DType sensorPoint; - sensorPoint[0] = atof(argv[4 + gcpId * 5]); - sensorPoint[1] = atof(argv[5 + gcpId * 5]); + sensorPoint[0] = std::stof(argv[4 + gcpId * 5]); + sensorPoint[1] = std::stof(argv[5 + gcpId * 5]); Point3DType geoPoint; - geoPoint[0] = atof(argv[6 + 5 * gcpId]); - geoPoint[1] = atof(argv[7 + 5 * gcpId]); - geoPoint[2] = atof(argv[8 + 5 * gcpId]); - + geoPoint[0] = std::stof(argv[6 + 5 * gcpId]); + geoPoint[1] = std::stof(argv[7 + 5 * gcpId]); + geoPoint[2] = std::stof(argv[8 + 5 * gcpId]); +#ifdef DEBUG std::cout << "Adding GCP sensor: " << sensorPoint << " <-> geo: " << geoPoint << std::endl; - +#endif rpcEstimator->AddGCP(sensorPoint, geoPoint); } @@ -103,58 +100,30 @@ int otbKmzProductWriter(int argc, char* argv[]) int otbKmzProductWriterWithLogoAndLegend(int argc, char* argv[]) { - // Parse command line parameters - typedef otb::CommandLineArgumentParser ParserType; - ParserType::Pointer parser = ParserType::New(); - - parser->SetProgramDescription("Chain that Estimate a sensor model in order to export the input image to Google Earth understandable format Kmz"); - parser->AddInputImage(); - parser->AddOption("--OutputProductName", "Output Kmz product ", "-kmz", 1, true); - parser->AddOption("--LogoImage", "Output Kmz product ", "-lo", 1, false); - parser->AddOption("--LegendImage", "Output Kmz product ", "-le", 1, false); - parser->AddOption("--DEMDirectory", "Path to the DEM directory ", "-dem", 1, true); - parser->AddOptionNParams("--GroudControlPoints", - "Ground Control Points to estimate sensor model a1x a1y b1x b1y b1z ... aNx aNy aNz bNx bNy bNz", - "-gcp", true); - - typedef otb::CommandLineArgumentParseResult ParserResultType; - ParserResultType::Pointer parseResult = ParserResultType::New(); - - try - { - parser->ParseCommandLine(argc, argv, parseResult); - } - catch ( itk::ExceptionObject & err ) - { - std::string descriptionException = err.GetDescription(); - if (descriptionException.find("ParseCommandLine(): Help Parser") != std::string::npos) + + if (argc < 3) { - return EXIT_SUCCESS; - } - if (descriptionException.find("ParseCommandLine(): Version Parser") != std::string::npos) - { - return EXIT_SUCCESS; - } + std::cerr << "Usage: " << argv[0] << " input logo_path legend_path " + <<"DEM_path output " + <<"a1x a1y b1x b1y b1z ... aNx aNy aNz bNx bNy bNz" + << std::endl; return EXIT_FAILURE; - } - - // Check if the number of gcp pairs point is consistent - unsigned int nbPoints = parseResult->GetNumberOfParameters("--GroudControlPoints"); - - if (nbPoints % 5 != 0) + } + else if ((argc - 6) % 5 != 0) { std::cout <<"argc " << argc << std::endl; std::cerr << "Inconsistent GCPs description!" << std::endl; return EXIT_FAILURE; } - + // Instantiate reader ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName(parseResult->GetInputImage()); + reader->SetFileName(argv[1]); GCPsToSensorModelFilterType::Pointer rpcEstimator = GCPsToSensorModelFilterType::New(); rpcEstimator->SetInput(reader->GetOutput()); + unsigned int nbPoints = argc-6; std::cout << "Receiving " << nbPoints << " from command line." << std::endl; unsigned int nbGCPs = nbPoints/5; @@ -162,16 +131,16 @@ int otbKmzProductWriterWithLogoAndLegend(int argc, char* argv[]) for (unsigned int gcpId = 0; gcpId < nbGCPs; ++gcpId) { Point2DType sensorPoint; - sensorPoint[0] = parseResult->GetParameterFloat("--GroudControlPoints", gcpId * 5); - sensorPoint[1] = parseResult->GetParameterFloat("--GroudControlPoints", 1 + gcpId * 5); + sensorPoint[0] = std::stof(argv[6 + 5 * gcpId]); + sensorPoint[1] = std::stof(argv[7 + 5 * gcpId]); Point3DType geoPoint; - geoPoint[0] = parseResult->GetParameterFloat("--GroudControlPoints", 2 + gcpId * 5); - geoPoint[1] = parseResult->GetParameterFloat("--GroudControlPoints", 3 + gcpId * 5); - geoPoint[2] = parseResult->GetParameterFloat("--GroudControlPoints", 4 + gcpId * 5); - + geoPoint[0] = std::stof(argv[8 + 5 * gcpId]); + geoPoint[1] = std::stof(argv[9 + 5 * gcpId]); + geoPoint[2] = std::stof(argv[10 + 5 * gcpId]); +#ifdef DEBUG std::cout << "Adding GCP sensor: " << sensorPoint << " <-> geo: " << geoPoint << std::endl; - +#endif rpcEstimator->AddGCP(sensorPoint, geoPoint); } @@ -181,30 +150,23 @@ int otbKmzProductWriterWithLogoAndLegend(int argc, char* argv[]) // Second part : Image To Kmz KmzProductWriterType::Pointer kmzWriter = KmzProductWriterType::New(); kmzWriter->SetInput(rpcEstimator->GetOutput()); - kmzWriter->SetPath(parseResult->GetParameterString("--OutputProductName")); - - // Read the logo if any - if(parseResult->IsOptionPresent("--LogoImage")) - { - ReaderType::Pointer logoReader = ReaderType::New(); - logoReader->SetFileName(parseResult->GetParameterString("--LogoImage")); - logoReader->Update(); - kmzWriter->SetLogo(logoReader->GetOutput()); - } - // Read the legend if any - if(parseResult->IsOptionPresent("--LegendImage")) - { - ReaderType::Pointer legendReader = ReaderType::New(); - legendReader->SetFileName(parseResult->GetParameterString("--LegendImage")); - legendReader->Update(); - kmzWriter->AddLegend("Input Legend", legendReader->GetOutput()); - kmzWriter->AddLegend(legendReader->GetOutput()); - } - // Set the DEM Directory if any - if(parseResult->IsOptionPresent("--DEMDirectory")) - { - otb::DEMHandler::Instance()->OpenDEMDirectory(parseResult->GetParameterString("--DEMDirectory")); - } + kmzWriter->SetPath(argv[5]); + + // Read the logo + ReaderType::Pointer logoReader = ReaderType::New(); + logoReader->SetFileName(argv[2]); + logoReader->Update(); + kmzWriter->SetLogo(logoReader->GetOutput()); + + // Read the legend + ReaderType::Pointer legendReader = ReaderType::New(); + legendReader->SetFileName(argv[3]); + legendReader->Update(); + kmzWriter->AddLegend("Input Legend", legendReader->GetOutput()); + kmzWriter->AddLegend(legendReader->GetOutput()); + + // Set the DEM Directory + otb::DEMHandler::Instance()->OpenDEMDirectory(argv[4]); // trigger the writing kmzWriter->Update();