From 7e6ebfd934218de1c9f35df9ca4592446b5deadc Mon Sep 17 00:00:00 2001 From: Otmane Lahlou <otmane.lahlou@c-s.fr> Date: Mon, 12 Dec 2011 17:05:42 +0100 Subject: [PATCH] ENH: add handler class to manage elevation parameters --- .../otbWrapperElevationParametersHandler.cxx | 130 ++++++++++++++++++ .../otbWrapperElevationParametersHandler.h | 71 ++++++++++ 2 files changed, 201 insertions(+) create mode 100644 Code/ApplicationEngine/otbWrapperElevationParametersHandler.cxx create mode 100644 Code/ApplicationEngine/otbWrapperElevationParametersHandler.h diff --git a/Code/ApplicationEngine/otbWrapperElevationParametersHandler.cxx b/Code/ApplicationEngine/otbWrapperElevationParametersHandler.cxx new file mode 100644 index 0000000000..ee9f09b621 --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperElevationParametersHandler.cxx @@ -0,0 +1,130 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "otbWrapperElevationParametersHandler.h" + +namespace otb +{ +namespace Wrapper +{ + +void ElevationParametersHandler::AddElevationParameters(Application::Pointer app, + const std::string & key) +{ + app->AddParameter(ParameterType_Choice, key, "Elevation management"); + app->SetParameterDescription(key, + "This group of parameters allows to manage elevation values. Supported formats are SRTM, DTED or any geotiff processed by the DEM import application"); + + // DEM directory + std::ostringstream oss; + oss << key<<".dem"; + app->AddChoice(oss.str(),"DEM directory"); + oss << ".value"; + app->AddParameter(ParameterType_Directory, oss.str(), "DEM directory"); + app->SetParameterDescription(oss.str(), + "This parameter allows to select a directory containing Digital Elevation Model tiles"); + app->MandatoryOff(oss.str()); + + // Average elevation + oss.str(""); + oss << key <<".average"; + app->AddChoice(oss.str(), "Average Elevation"); + oss << ".value"; + app->AddParameter(ParameterType_Float, oss.str(), "Average Elevation"); + app->SetParameterDescription(oss.str(),"This parameter allows to pick up an average elevation for all the points of the image."); + +// // TODO : not implemented yet +// // // Tiff image +// // oss << ".tiff"; +// // app->AddChoice(oss.str(), "Tiff file"); +// // app->AddParameter(ParameterType_InputImage, oss.str(), "Tiff file"); +// // app->SetParameterDescription(oss.str(),"Tiff file used to get elevation for each location in the image"); + + // Geoid file + oss.str(""); + oss << key<<".geoid"; + app->AddChoice(oss.str(), "Geoid file"); + oss << ".value"; + app->AddParameter(ParameterType_Filename, oss.str(), "Geoid File"); + app->SetParameterDescription(oss.str(),"Use a geoid grid to get the height above the ellipsoid used"); + + // Set the default value + app->SetParameterString(key, "dem"); +} + + +/** + * + * Get the Average elevation value + **/ +const std::string +ElevationParametersHandler::GetDEMDirectory(const Application::Pointer app, const std::string& key) +{ + std::ostringstream oss; + oss << key <<".dem.value"; + return app->GetParameterString(oss.str()); +} + +/** + * + * Get the Average elevation value + */ +float +ElevationParametersHandler::GetAverageElevation(const Application::Pointer app, const std::string& key) +{ + std::ostringstream oss; + oss << key <<".average.value"; + return app->GetParameterFloat(oss.str()); +} + +/** + * Get the Geoid file + */ +const std::string +ElevationParametersHandler::GetGeoidFile(const Application::Pointer app, const std::string& key) +{ + std::ostringstream oss; + oss << key <<".geoid.value"; + return app->GetParameterString(oss.str()); +} + +/** + * + * Get the Elevation mode choosen by the user + */ +const ElevationType +ElevationParametersHandler::GetElevationType(const Application::Pointer app, const std::string& key) +{ + switch(app->GetParameterInt(key)) + { + case Elevation_DEM: + return Elevation_DEM; + break; + case Elevation_Average: + return Elevation_Average; + break; + // case Elevation_Tiff: + // return Eleavation_Tiff; + // break; + case Elevation_Geoid: + return Elevation_Geoid; + break; + } +} + +}// End namespace Wrapper +}// End namespace otb diff --git a/Code/ApplicationEngine/otbWrapperElevationParametersHandler.h b/Code/ApplicationEngine/otbWrapperElevationParametersHandler.h new file mode 100644 index 0000000000..ef52df311c --- /dev/null +++ b/Code/ApplicationEngine/otbWrapperElevationParametersHandler.h @@ -0,0 +1,71 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ +#ifndef __otbWrapperElevationParametersHandler_h +#define __otbWrapperElevationParametersHandler_h + +#include "otbWrapperApplication.h" + +namespace otb +{ +namespace Wrapper +{ + +/** \class ElevationParametersHandler + * \brief This class represent a helper class for elevation modes. It + * add the parameters automatically to the application where it is + * used, provide method to get the value needed. + * + * This class allow creating a Choice list with several Elevation + * modes to be used, supported modes are DEM, Geoid file, average + * elevation. The user can get the value relative to each mode + * using one the following methods Get{AverageElevation, DEMDirectory, GeoidFile}. + * + * + */ + +class ElevationParametersHandler +{ +public: + /** + * Add a Group containing several choices for map projections + * + */ + static void AddElevationParameters(Application::Pointer app, const std::string & key); + + /** + * Helper method : Get the elevation type selected by the user + * projection picked up by the user + * + */ + static const ElevationType GetElevationType(const Application::Pointer app, const std::string& key); + + /** Method for getting the value of the elevation mode selected */ + static const std::string GetDEMDirectory(const Application::Pointer app, const std::string& key); + static float GetAverageElevation(const Application::Pointer app, const std::string& key); + static const std::string GetGeoidFile(const Application::Pointer app, const std::string& key); + +protected: + ElevationParametersHandler(); // not implemented + virtual ~ElevationParametersHandler(); // not implemented +}; + +} +} + + +#endif // __otbWrapperElevationParametersHandler_h_ -- GitLab