From 467cf304a0e24abcfa8d703a8a85482653f25a05 Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Thu, 21 May 2009 15:04:15 +0800 Subject: [PATCH] ENH: integration of ossim plugins (TerraSar only now) --- Testing/Utilities/ossimRadarSatSupport.cxx | 2 +- Utilities/otbossim/CMakeLists.txt | 1 + .../ossim/projection/ossimEnvisatAsarModel.h | 2 + .../ossim/projection/ossimErsSarModel.h | 2 + .../projection/ossimGeometricSarSensorModel.h | 295 ++-- .../ossim/projection/ossimRadarSat2Model.h | 2 + .../ossim/projection/ossimRadarSatModel.h | 2 + .../ossim/projection/otb/PlatformPosition.h | 2 +- .../include/ossim/projection/otb/SarSensor.h | 2 +- .../include/ossim/projection/otb/Sensor.h | 2 +- .../ossim/projection/otb/SensorParams.h | 2 +- Utilities/otbossim/src/ossim/CMakeLists.txt | 6 + .../imaging/ossimImageHandlerFactory.cpp | 74 +- .../ossimGeometricSarSensorModel.cpp | 733 +++++++--- .../projection/ossimSensorModelFactory.cpp | 12 +- .../ossim/ossimCosmoSkymedModel.cpp | 387 ----- .../ossim/ossimCosmoSkymedModel.h | 91 -- .../ossim/ossimEnvisatAsarModel.cpp | 366 ----- .../ossim/ossimEnvisatAsarModel.h | 85 -- .../ossim/ossimErsSarModel.cpp | 408 ------ .../otbossimplugins/ossim/ossimErsSarModel.h | 78 - .../ossim/ossimPluginProjectionFactory.cpp | 84 +- .../ossim/ossimRadarSat2Model.cpp | 1259 ----------------- .../ossim/ossimRadarSat2Model.h | 181 --- .../ossim/ossimRadarSat2ProductDoc.cpp | 844 ----------- .../ossim/ossimRadarSat2ProductDoc.h | 179 --- .../ossim/ossimRadarSatModel.cpp | 578 -------- .../ossim/ossimRadarSatModel.h | 88 -- .../ossim/ossimTerraSarModel.cpp | 8 +- .../ossim/ossimTerraSarModel.h | 3 - otbIncludeDirectories.cmake | 1 + 31 files changed, 802 insertions(+), 4977 deletions(-) delete mode 100644 Utilities/otbossimplugins/ossim/ossimCosmoSkymedModel.cpp delete mode 100644 Utilities/otbossimplugins/ossim/ossimCosmoSkymedModel.h delete mode 100644 Utilities/otbossimplugins/ossim/ossimEnvisatAsarModel.cpp delete mode 100644 Utilities/otbossimplugins/ossim/ossimEnvisatAsarModel.h delete mode 100644 Utilities/otbossimplugins/ossim/ossimErsSarModel.cpp delete mode 100644 Utilities/otbossimplugins/ossim/ossimErsSarModel.h delete mode 100644 Utilities/otbossimplugins/ossim/ossimRadarSat2Model.cpp delete mode 100644 Utilities/otbossimplugins/ossim/ossimRadarSat2Model.h delete mode 100644 Utilities/otbossimplugins/ossim/ossimRadarSat2ProductDoc.cpp delete mode 100644 Utilities/otbossimplugins/ossim/ossimRadarSat2ProductDoc.h delete mode 100644 Utilities/otbossimplugins/ossim/ossimRadarSatModel.cpp delete mode 100644 Utilities/otbossimplugins/ossim/ossimRadarSatModel.h diff --git a/Testing/Utilities/ossimRadarSatSupport.cxx b/Testing/Utilities/ossimRadarSatSupport.cxx index 43b8c6ab70..7000fd693e 100644 --- a/Testing/Utilities/ossimRadarSatSupport.cxx +++ b/Testing/Utilities/ossimRadarSatSupport.cxx @@ -40,7 +40,7 @@ #include "ossim/projection/ossimProjectionFactoryRegistry.h" #include "ossim/imaging/ossimImageHandlerRegistry.h" #include "ossim/imaging/ossimImageHandlerSarFactory.h" -#include "ossim/projection/ossimTerraSarModel.h" +// #include "ossim/projection/ossimTerraSarModel.h" #include "ossim/projection/ossimRadarSatModel.h" diff --git a/Utilities/otbossim/CMakeLists.txt b/Utilities/otbossim/CMakeLists.txt index 37c6f2a250..db24d6a73a 100644 --- a/Utilities/otbossim/CMakeLists.txt +++ b/Utilities/otbossim/CMakeLists.txt @@ -20,6 +20,7 @@ INCLUDE_DIRECTORIES(${OTB_BINARY_DIR}/Utilities/otbossim/include) #Temporary until the SAR plugins are fully integrated INCLUDE_DIRECTORIES(${OTB_SOURCE_DIR}/Utilities/otbossim/include/ossim/projection/otb) +INCLUDE_DIRECTORIES(${OTB_SOURCE_DIR}/Utilities/otbossim/include/ossim/projection) CONFIGURE_FILE(${OTB_SOURCE_DIR}/Utilities/otbossim/include/ossim/ossimConfig.h.in ${OTB_BINARY_DIR}/Utilities/otbossim/include/ossim/ossimConfig.h) diff --git a/Utilities/otbossim/include/ossim/projection/ossimEnvisatAsarModel.h b/Utilities/otbossim/include/ossim/projection/ossimEnvisatAsarModel.h index 6dc78cd016..b238ab0ae4 100644 --- a/Utilities/otbossim/include/ossim/projection/ossimEnvisatAsarModel.h +++ b/Utilities/otbossim/include/ossim/projection/ossimEnvisatAsarModel.h @@ -39,6 +39,8 @@ public: */ virtual double getSlantRangeFromGeoreferenced(double col) const; + virtual ossimObject* dup() const {}; //FIXME just while ossimplupgins are integrated + protected: /** diff --git a/Utilities/otbossim/include/ossim/projection/ossimErsSarModel.h b/Utilities/otbossim/include/ossim/projection/ossimErsSarModel.h index 357d8aa3e5..c0e576933a 100644 --- a/Utilities/otbossim/include/ossim/projection/ossimErsSarModel.h +++ b/Utilities/otbossim/include/ossim/projection/ossimErsSarModel.h @@ -40,6 +40,8 @@ public: */ virtual double getSlantRangeFromGeoreferenced(double col) const; + virtual ossimObject* dup() const {}; //FIXME just while ossimplupgins are integrated + protected: /** * @brief Slant Range for each Ground Range (SRGR) number of coefficients sets diff --git a/Utilities/otbossim/include/ossim/projection/ossimGeometricSarSensorModel.h b/Utilities/otbossim/include/ossim/projection/ossimGeometricSarSensorModel.h index af30e2e143..1df9662eb0 100644 --- a/Utilities/otbossim/include/ossim/projection/ossimGeometricSarSensorModel.h +++ b/Utilities/otbossim/include/ossim/projection/ossimGeometricSarSensorModel.h @@ -1,3 +1,14 @@ +//---------------------------------------------------------------------------- +// +// "Copyright Centre National d'Etudes Spatiales" +// +// License: LGPL +// +// See LICENSE.txt file in the top level directory for more details. +// +//---------------------------------------------------------------------------- +// $Id$ + #ifndef ossimGeometricSarSensorModel_H #define ossimGeometricSarSensorModel_H @@ -10,166 +21,188 @@ #include <ossim/base/ossimEcefRay.h> #include <ossim/base/ossimEcefPoint.h> #include <ossim/base/ossimMatrix3x3.h> +#include <ossim/base/ossimRtti.h> #include <iostream> #include <list> #include <cstdlib> -#include <ossim/projection/otb/CivilDateTime.h> +#include <otb/CivilDateTime.h> class PlatformPosition; class SensorParams; class RefPoint; /** - * @brief This class allows for direct localisation and indirect localisation using the geometric model of SAR sensors. - * This class must be specified for each sensor. - * @author Magellium, Vincent Martin - * @version 1.0 - * @date 03-18-08 + * @brief This class allows for direct localisation and indirect localisation + * using the geometric model of SAR sensors. + * This class must be specified for each sensor. */ -class OSSIMDLLEXPORT ossimGeometricSarSensorModel : public ossimSensorModel +class ossimGeometricSarSensorModel : public ossimSensorModel { public: - /** - * @brief Constructor - */ - ossimGeometricSarSensorModel(); - - /** - * @brief Destructor - */ - ~ossimGeometricSarSensorModel(); - - /** - * @brief This function associates an image column number to a slant range when the image is georeferenced (ground projected) - * @param col Column coordinate of the image point - */ - virtual double getSlantRangeFromGeoreferenced(double col) const=0; - - /** - * @brief This function associates an image column number to a slant range - * @param col Column coordinate of the image point - */ - virtual double getSlantRange(double col) const; - - /** - * @brief This function associates an image line number to an azimuth time - * @param line Line coordinate of the image point - */ - virtual JSDDateTime getTime(double line) const; - - /** - * @brief This function is able to convert image coordinates into world coordinates the geometric model of SAR sensors. - * @param image_point Coordinates of the image point - * @param heightEllipsoid Altitude of the world point - * @param worldPoint Coordinates of the world point (OUT) - */ - virtual void lineSampleHeightToWorld(const ossimDpt& image_point, + + /** @brief default constructor */ + ossimGeometricSarSensorModel(); + + /** @brief copy constructor */ + ossimGeometricSarSensorModel(const ossimGeometricSarSensorModel& rhs); + + /** @brief Destructor */ + virtual ~ossimGeometricSarSensorModel(); + + /** + * @brief This function associates an image column number to a slant range when the image is georeferenced (ground projected) + * @param col Column coordinate of the image point + */ + virtual double getSlantRangeFromGeoreferenced(double col) const=0; + + /** + * @brief This function associates an image column number to a slant range + * @param col Column coordinate of the image point + */ + virtual double getSlantRange(double col) const; + + /** + * @brief This function associates an image line number to an azimuth time + * @param line Line coordinate of the image point + */ + virtual JSDDateTime getTime(double line) const; + + /** + * @brief This function is able to convert image coordinates into world + * coordinates the geometric model of SAR sensors. + * @param image_point Coordinates of the image point + * @param heightEllipsoid Altitude of the world point + * @param worldPoint Coordinates of the world point (OUT) + */ + virtual void lineSampleHeightToWorld(const ossimDpt& image_point, const double& heightEllipsoid, ossimGpt& worldPoint) const; - /** - * @brief This function optimizes the model according to a list of Ground Control Points. - * The input list of GCPs is appended to the one present in memory. - * An inverse localization of each ground GCP is performed. - * The error between localized GCPs and actual image coordinates is then computed and - * modeled by a linear model on each dimension. - * The time and range estimations are updated accordingly. - * - * @param groundCoordinates : input GCP ground coordinates - * @param imageCoordinates : actual image coordinates corresponding to input groundCoordinates - * - */ - virtual bool optimizeModel(const std::list<ossimGpt> & groundCoordinates, const std::list<ossimDpt> & imageCoordinates) ; - - /** - * @brief Clears _optimizationGCPsGroundCoordinates and _optimizationGCPsImageCoordinates attributes - * Updates the optimisation factors and bias - */ - virtual void clearGCPlist() ; - - /** - * @brief Returns _optimizationGCPsGroundCoordinates and _optimizationGCPsImageCoordinates attributes - * - * @retval groundCoordinates : GCP ground coordinates - * @retval imageCoordinates : actual image coordinates corresponding to groundCoordinates - */ - virtual void getGCPlist(std::list<ossimGpt> &groundCoordinates, std::list<ossimDpt> & imageCoordinates) ; - - /** - * @brief Returns pointer to a new instance, copy of this. - * @remark This function always return NULL; - */ - virtual ossimObject* dup() const { return 0; }; + /** + * @brief This function optimizes the model according to a list of Ground + * Control Points. + * + * The input list of GCPs is appended to the one present in memory. + * An inverse localization of each ground GCP is performed. + * The error between localized GCPs and actual image coordinates is then + * computed and modeled by a linear model on each dimension. + * The time and range estimations are updated accordingly. + * + * @param groundCoordinates : input GCP ground coordinates + * @param imageCoordinates : actual image coordinates corresponding to + * input groundCoordinates + * + */ + virtual bool optimizeModel(const std::list<ossimGpt> & groundCoordinates, + const std::list<ossimDpt> & imageCoordinates) ; + + /** + * @brief Clears _optimizationGCPsGroundCoordinates and + * _optimizationGCPsImageCoordinates attributes + * Updates the optimisation factors and bias + */ + virtual void clearGCPlist() ; + + /** + * @brief Returns _optimizationGCPsGroundCoordinates and + * _optimizationGCPsImageCoordinates attributes + * + * @retval groundCoordinates : GCP ground coordinates + * @retval imageCoordinates : actual image coordinates corresponding to + * groundCoordinates + */ + virtual void getGCPlist(std::list<ossimGpt> &groundCoordinates, + std::list<ossimDpt> & imageCoordinates) ; + + /** * @brief - * @return true when it's better (more accurate / fast) to use forward (from ground to image) than inverse(from image to ground) - * @remark This function always return false - */ - inline virtual bool useForward()const {return false;}; + * @return true when it's better (more accurate / fast) to use forward + * (from ground to image) than inverse(from image to ground) + * @remark This function always return false + */ + inline virtual bool useForward() const {return false;} /** - * @brief Method to the load (recreate) the state of the object from a keyword list. Return true if ok or false on error. - * @return true if load OK, false on error - */ + * @brief Method to save object state to a keyword list. + * @param kwl Keyword list to save to. + * @param prefix added to keys when saved. + * @return true on success, false on error. + */ + virtual bool saveState(ossimKeywordlist& kwl, + const char* prefix=0) const; + + /** + * @brief Method to the load (recreate) the state of the object from a + * keyword list. Return true if ok or false on error. + * @return true if load OK, false on error + */ virtual bool loadState (const ossimKeywordlist &kwl, const char *prefix=0); - /** + /*! + * METHOD: print() + * Fulfills base-class pure virtual. Dumps contents of object to ostream. + */ + virtual std::ostream& print(std::ostream& out) const; + + /** * @brief Accessors to the optimization parameters. - */ - double get_optimizationFactorX() { return _optimizationFactorX; }; - double get_optimizationFactorY() { return _optimizationFactorY; } ; - double get_optimizationBiasX() { return _optimizationBiasX; } ; - double get_optimizationBiasY() { return _optimizationBiasY; } ; + */ + double get_optimizationFactorX() const { return _optimizationFactorX; } + double get_optimizationFactorY() const { return _optimizationFactorY; } + double get_optimizationBiasX() const { return _optimizationBiasX; } + double get_optimizationBiasY() const { return _optimizationBiasY; } protected: - /** - * @brief Handle the position of the platform - */ - PlatformPosition *_platformPosition; - SensorParams * _sensor; - RefPoint * _refPoint; - - /** - * @brief True iff the product is ground range - */ - bool _isProductGeoreferenced ; - - /** - * @brief List Ground Control Points used by the optimization - */ - std::list<ossimGpt> _optimizationGCPsGroundCoordinates ; - std::list<ossimDpt> _optimizationGCPsImageCoordinates ; - - /** - * @brief Optimization result : linear error correction in both dimensions - */ - double _optimizationFactorX ; - double _optimizationFactorY ; - double _optimizationBiasX ; - double _optimizationBiasY ; + /** + * @brief Handle the position of the platform + */ + PlatformPosition *_platformPosition; + SensorParams * _sensor; + RefPoint * _refPoint; + + /** + * @brief True iff the product is ground range + */ + bool _isProductGeoreferenced ; + + /** + * @brief List Ground Control Points used by the optimization + */ + std::list<ossimGpt> _optimizationGCPsGroundCoordinates ; + std::list<ossimDpt> _optimizationGCPsImageCoordinates ; + + /** + * @brief Optimization result : linear error correction in both dimensions + */ + double _optimizationFactorX ; + double _optimizationFactorY ; + double _optimizationBiasX ; + double _optimizationBiasY ; private: - /** - * @brief Initializes the Platform Position from a projection keywordlist - */ - virtual bool InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix)=0; - /** - * @brief Initializes the Sensor Params from a projection keywordlist - */ - virtual bool InitSensorParams(const ossimKeywordlist &kwl, const char *prefix)=0; - /** - * @brief Initializes the Reference Point from a projection keywordlist - */ - virtual bool InitRefPoint(const ossimKeywordlist &kwl, const char *prefix)=0; - /** - * @brief Initializes the Slant Range to/for each Ground Range data sets from a projection keywordlist - */ - virtual bool InitSRGR(const ossimKeywordlist &kwl, const char *prefix)=0; - - TYPE_DATA + /** + * @brief Initializes the Platform Position from a projection keywordlist + */ + virtual bool InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix)=0; + /** + * @brief Initializes the Sensor Params from a projection keywordlist + */ + virtual bool InitSensorParams(const ossimKeywordlist &kwl, const char *prefix)=0; + /** + * @brief Initializes the Reference Point from a projection keywordlist + */ + virtual bool InitRefPoint(const ossimKeywordlist &kwl, const char *prefix)=0; + /** + * @brief Initializes the Slant Range to/for each Ground Range data sets from a projection keywordlist + */ + virtual bool InitSRGR(const ossimKeywordlist &kwl, const char *prefix)=0; + +TYPE_DATA + }; #endif diff --git a/Utilities/otbossim/include/ossim/projection/ossimRadarSat2Model.h b/Utilities/otbossim/include/ossim/projection/ossimRadarSat2Model.h index dd05d264ee..f426f0fd9d 100644 --- a/Utilities/otbossim/include/ossim/projection/ossimRadarSat2Model.h +++ b/Utilities/otbossim/include/ossim/projection/ossimRadarSat2Model.h @@ -40,6 +40,8 @@ public: */ virtual double getSlantRangeFromGeoreferenced(double col) const; + virtual ossimObject* dup() const {}; //FIXME just while ossimplupgins are integrated + protected: /** diff --git a/Utilities/otbossim/include/ossim/projection/ossimRadarSatModel.h b/Utilities/otbossim/include/ossim/projection/ossimRadarSatModel.h index b214c8b3d3..815633f064 100644 --- a/Utilities/otbossim/include/ossim/projection/ossimRadarSatModel.h +++ b/Utilities/otbossim/include/ossim/projection/ossimRadarSatModel.h @@ -40,6 +40,8 @@ public: */ virtual double getSlantRangeFromGeoreferenced(double col) const; + virtual ossimObject* dup() const {}; //FIXME just while ossimplupgins are integrated + protected: /** diff --git a/Utilities/otbossim/include/ossim/projection/otb/PlatformPosition.h b/Utilities/otbossim/include/ossim/projection/otb/PlatformPosition.h index 9bafb48a96..94df9759e6 100644 --- a/Utilities/otbossim/include/ossim/projection/otb/PlatformPosition.h +++ b/Utilities/otbossim/include/ossim/projection/otb/PlatformPosition.h @@ -18,7 +18,7 @@ class Ephemeris; class ossimKeywordlist; /** - * @ingroup otb + * @ingroup SARModel * @brief This class handles the platform position */ class PlatformPosition diff --git a/Utilities/otbossim/include/ossim/projection/otb/SarSensor.h b/Utilities/otbossim/include/ossim/projection/otb/SarSensor.h index daa96cb529..7854dd46f9 100644 --- a/Utilities/otbossim/include/ossim/projection/otb/SarSensor.h +++ b/Utilities/otbossim/include/ossim/projection/otb/SarSensor.h @@ -20,7 +20,7 @@ class GeographicEphemeris; class RectangularCoordinate; class JSDDateTime; /** - * @ingroup otb + * @ingroup SARModel * @brief This class provides basic location services for SAR sensors */ class SarSensor : Sensor diff --git a/Utilities/otbossim/include/ossim/projection/otb/Sensor.h b/Utilities/otbossim/include/ossim/projection/otb/Sensor.h index 0b4e4cab53..fa135a6fa9 100644 --- a/Utilities/otbossim/include/ossim/projection/otb/Sensor.h +++ b/Utilities/otbossim/include/ossim/projection/otb/Sensor.h @@ -19,7 +19,7 @@ class PlatformPosition; class JSDDateTime; /** - * @ingroup otb + * @ingroup SARModel * @brief This class provides basic location services */ class Sensor diff --git a/Utilities/otbossim/include/ossim/projection/otb/SensorParams.h b/Utilities/otbossim/include/ossim/projection/otb/SensorParams.h index 416938728f..64033a6187 100644 --- a/Utilities/otbossim/include/ossim/projection/otb/SensorParams.h +++ b/Utilities/otbossim/include/ossim/projection/otb/SensorParams.h @@ -15,7 +15,7 @@ class ossimKeywordlist; /** - * @ingroup otb + * @ingroup SARModel * @brief This class handles the sensor parameters */ diff --git a/Utilities/otbossim/src/ossim/CMakeLists.txt b/Utilities/otbossim/src/ossim/CMakeLists.txt index 237aff4ed4..2c4acfee87 100644 --- a/Utilities/otbossim/src/ossim/CMakeLists.txt +++ b/Utilities/otbossim/src/ossim/CMakeLists.txt @@ -19,6 +19,12 @@ REMOVE(ossim_plugin_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/plugin/ossimSharedObjectBr REMOVE(ossim_base_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/base/ossimGzStream.cpp") REMOVE(ossim_base_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/base/ossimFactoryBaseTemplate.cpp") +# Remove compilation of sensor models moved to plugins +REMOVE(ossim_imaging_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/imaging/TerraSar/TsxAnnotation.cpp") +REMOVE(ossim_imaging_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/imaging/ossimTerraSarTileSource.cpp") +REMOVE(ossim_projection_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/projection/ossimTerraSarModel.cpp") + + # Adjust the compiler flags to avoid problems with ossim code. IF(CMAKE_COMPILER_IS_GNUCXX) FOREACH(f ${ossim_base_SRCS} ${ossim_elevation_SRCS} ${ossim_font_SRCS} ${ossim_imaging_SRCS} ${ossim_matrix_SRCS} diff --git a/Utilities/otbossim/src/ossim/imaging/ossimImageHandlerFactory.cpp b/Utilities/otbossim/src/ossim/imaging/ossimImageHandlerFactory.cpp index 38f5f9cdeb..1f9fac536b 100644 --- a/Utilities/otbossim/src/ossim/imaging/ossimImageHandlerFactory.cpp +++ b/Utilities/otbossim/src/ossim/imaging/ossimImageHandlerFactory.cpp @@ -25,7 +25,7 @@ #include <ossim/base/ossimKeywordNames.h> #include <ossim/imaging/ossimJpegTileSource.h> #include <ossim/imaging/ossimRadarSatTileSource.h> -#include <ossim/imaging/ossimTerraSarTileSource.h> +// #include <ossim/imaging/ossimTerraSarTileSource.h> static const ossimTrace traceDebug("ossimImageHandlerFactory:debug"); @@ -53,9 +53,9 @@ ossimImageHandlerFactory* ossimImageHandlerFactory::instance() ossimImageHandler* ossimImageHandlerFactory::open(const ossimFilename& fileName)const { - + ossimFilename copyFilename = fileName; - + if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) @@ -76,7 +76,7 @@ ossimImageHandler* ossimImageHandlerFactory::open(const ossimFilename& fileName) // if we have any imagehandlers that require an encoded string and is contrlled in this factory then // we need to move this. if(!copyFilename.exists()) return 0; - + if(copyFilename.ext() == "gz") { copyFilename = copyFilename.setExtension(""); @@ -92,7 +92,7 @@ ossimImageHandler* ossimImageHandlerFactory::open(const ossimFilename& fileName) return result; } delete result; - + // test if TileMap if(traceDebug()) @@ -123,18 +123,18 @@ ossimImageHandler* ossimImageHandlerFactory::open(const ossimFilename& fileName) delete result; // test if TerraSAR - if(traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "trying TerraSAR" - << std::endl; - } - result = new ossimTerraSarTileSource; - if(result->open(copyFilename)) - { - return result; - } - delete result; +// if(traceDebug()) +// { +// ossimNotify(ossimNotifyLevel_DEBUG) +// << "trying TerraSAR" +// << std::endl; +// } +// result = new ossimTerraSarTileSource; +// if(result->open(copyFilename)) +// { +// return result; +// } +// delete result; // this must be checked first before the TIFF handler if(traceDebug()) @@ -310,16 +310,16 @@ ossimImageHandler* ossimImageHandlerFactory::open(const ossimFilename& fileName) ossimNotify(ossimNotifyLevel_DEBUG) << "trying adrg" << std::endl; } - + // test if ADRG result = new ossimAdrgTileSource(); - + if(result->open(copyFilename)) { return result; } delete result; - + if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) @@ -331,7 +331,7 @@ ossimImageHandler* ossimImageHandlerFactory::open(const ossimFilename& fileName) { return result; } - + delete result; if(traceDebug()) { @@ -484,19 +484,19 @@ ossimImageHandler* ossimImageHandlerFactory::open(const ossimKeywordlist& kwl, delete result; // TerraSAR - if(traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "trying TerraSAR" - << std::endl; - } - result = new ossimTerraSarTileSource; - if(result->loadState(kwl, prefix)) - { - return result; - } - - delete result; +// if(traceDebug()) +// { +// ossimNotify(ossimNotifyLevel_DEBUG) +// << "trying TerraSAR" +// << std::endl; +// } +// result = new ossimTerraSarTileSource; +// if(result->loadState(kwl, prefix)) +// { +// return result; +// } +// +// delete result; // Must be before tiff... if(traceDebug()) @@ -510,9 +510,9 @@ ossimImageHandler* ossimImageHandlerFactory::open(const ossimKeywordlist& kwl, { return result; } - + delete result; - + if(traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) @@ -675,7 +675,7 @@ ossimObject* ossimImageHandlerFactory::createObject(const ossimString& typeName) void ossimImageHandlerFactory::getSupportedExtensions(ossimImageHandlerFactoryBase::UniqueStringList& extensionList)const { extensionList.push_back("img"); - extensionList.push_back("ccf"); + extensionList.push_back("ccf"); extensionList.push_back("toc"); extensionList.push_back("tif"); extensionList.push_back("tiff"); diff --git a/Utilities/otbossim/src/ossim/projection/ossimGeometricSarSensorModel.cpp b/Utilities/otbossim/src/ossim/projection/ossimGeometricSarSensorModel.cpp index 5bc0a76c5f..b2ba838ea6 100644 --- a/Utilities/otbossim/src/ossim/projection/ossimGeometricSarSensorModel.cpp +++ b/Utilities/otbossim/src/ossim/projection/ossimGeometricSarSensorModel.cpp @@ -1,248 +1,569 @@ -#include <ossim/projection/ossimGeometricSarSensorModel.h> +//---------------------------------------------------------------------------- +// +// "Copyright Centre National d'Etudes Spatiales" +// +// License: LGPL +// +// See LICENSE.txt file in the top level directory for more details. +// +//---------------------------------------------------------------------------- +// $Id$ + +#include <ossimGeometricSarSensorModel.h> + +#include <otb/GalileanEphemeris.h> +#include <otb/GeographicEphemeris.h> +#include <otb/GMSTDateTime.h> + +#include <otb/PlatformPosition.h> +#include <otb/SensorParams.h> +#include <otb/RefPoint.h> +#include <otb/SarSensor.h> -#include <ossim/projection/otb/GalileanEphemeris.h> -#include <ossim/projection/otb/GeographicEphemeris.h> -#include <ossim/projection/otb/GMSTDateTime.h> +#include <ossim/base/ossimTrace.h> -#include <ossim/projection/otb/PlatformPosition.h> -#include <ossim/projection/otb/SensorParams.h> -#include <ossim/projection/otb/RefPoint.h> -#include <ossim/projection/otb/SarSensor.h> +#include <cmath> +#include <string> -#include <ossim/base/ossimTrace.h> +static const char PRODUCT_GEOREFERENCED_FLAG_KW[] = + "product_georeferenced_flag"; +static const char OPTIMIZATION_FACTOR_X_KW[] = "optimization_factor_x"; +static const char OPTIMIZATION_FACTOR_Y_KW[] = "optimization_factor_y"; +static const char OPTIMIZATION_BIAS_X_KW[] = "optimization_bias_x"; +static const char OPTIMIZATION_BIAS_Y_KW[] = "optimization_bias_y"; -#include <math.h> RTTI_DEF1(ossimGeometricSarSensorModel, "ossimGeometricSarSensorModel", ossimSensorModel); static ossimTrace traceDebug("ossimGeometricSarSensorModel:debug"); -ossimGeometricSarSensorModel::ossimGeometricSarSensorModel(): - _platformPosition(NULL), - _sensor(NULL), - _refPoint(NULL), - _isProductGeoreferenced(false), - _optimizationFactorX(0.0), - _optimizationFactorY(0.0), - _optimizationBiasX(0.0), - _optimizationBiasY(0.0) +ossimGeometricSarSensorModel::ossimGeometricSarSensorModel() + : + ossimSensorModel(), + _platformPosition(0), + _sensor(0), + _refPoint(0), + _isProductGeoreferenced(false), + _optimizationFactorX(0.0), + _optimizationFactorY(0.0), + _optimizationBiasX(0.0), + _optimizationBiasY(0.0) +{ +} + +ossimGeometricSarSensorModel::ossimGeometricSarSensorModel( + const ossimGeometricSarSensorModel& rhs) + : + ossimSensorModel(rhs), + _platformPosition(rhs._platformPosition), + _sensor(rhs._sensor), + _refPoint(rhs._refPoint), + _isProductGeoreferenced(rhs._isProductGeoreferenced), + _optimizationFactorX(rhs._optimizationFactorX), + _optimizationFactorY(rhs._optimizationFactorY), + _optimizationBiasX(rhs._optimizationBiasX), + _optimizationBiasY(rhs._optimizationBiasY) { } ossimGeometricSarSensorModel::~ossimGeometricSarSensorModel() { - if (_platformPosition != NULL) - { - delete _platformPosition; - } - - if(_sensor != NULL) - { - delete _sensor; - } - - if(_refPoint != NULL) - { - delete _refPoint; - } + if (_platformPosition != 0) + { + delete _platformPosition; + } + + if(_sensor != 0) + { + delete _sensor; + } + + if(_refPoint != 0) + { + delete _refPoint; + } } double ossimGeometricSarSensorModel::getSlantRange(double col) const { - const double CLUM = 2.99792458e+8 ; + const double CLUM = 2.99792458e+8 ; - double dist = _refPoint->get_distance() - + _sensor->get_col_direction() * (col - (_refPoint->get_pix_col())) * ((CLUM / 2.0) * _sensor->get_nRangeLook() / _sensor->get_sf()) ; + double dist = _refPoint->get_distance() + + _sensor->get_col_direction() * (col - (_refPoint->get_pix_col())) * ((CLUM / 2.0) * _sensor->get_nRangeLook() / _sensor->get_sf()) ; - return dist; + return dist; } -JSDDateTime ossimGeometricSarSensorModel::getTime(double line) const +JSDDateTime ossimGeometricSarSensorModel::getTime(double line) const { - double dt = _sensor->get_lin_direction() * (line - _refPoint->get_pix_line()) * _sensor->get_nAzimuthLook() / _sensor->get_prf() ; - JSDDateTime time = _refPoint->get_ephemeris()->get_date(); - time.set_second(time.get_second() + dt); - time.NormDate(); + double dt = _sensor->get_lin_direction() * (line - _refPoint->get_pix_line()) * _sensor->get_nAzimuthLook() / _sensor->get_prf() ; + JSDDateTime time = _refPoint->get_ephemeris()->get_date(); + time.set_second(time.get_second() + dt); + time.NormDate(); - return time; + return time; } -void ossimGeometricSarSensorModel::lineSampleHeightToWorld(const ossimDpt& image_point, const double& heightEllipsoid, ossimGpt& worldPoint) const +void ossimGeometricSarSensorModel::lineSampleHeightToWorld( + const ossimDpt& image_point, + const double& heightEllipsoid, + ossimGpt& worldPoint) const { - SarSensor sensor(_sensor,_platformPosition); - double lon, lat; - const double CLUM = 2.99792458e+8 ; - - // optimization - double col = image_point.x - (image_point.x * _optimizationFactorX + _optimizationBiasX) ; - double line = image_point.y - (image_point.y * _optimizationFactorY + _optimizationBiasY) ; - - // Slant range computation, depending on the product type - double slantRange; - if (_isProductGeoreferenced) { - slantRange = getSlantRangeFromGeoreferenced(col) ; - } - else { - slantRange = getSlantRange(col) ; - } - - JSDDateTime azimuthTime = getTime(line) ; - int etatLoc = sensor.ImageToWorld(slantRange, azimuthTime, heightEllipsoid, lon, lat); - - if(traceDebug()) - { - switch (etatLoc) - { - case 0: - ossimNotify(ossimNotifyLevel_DEBUG) << "successful call to lineSampleHeightToWorld" << std::endl; - break; - case 1: - ossimNotify(ossimNotifyLevel_DEBUG) << "lineSampleHeightToWorld : no real root to the equation belongs to the imaging ray" << std::endl; - break; - case 2: - ossimNotify(ossimNotifyLevel_DEBUG) << "lineSampleHeightToWorld : no real root to the equation" << std::endl; - break; - default : - ossimNotify(ossimNotifyLevel_DEBUG) << "lineSampleHeightToWorld : unknown error case" << std::endl; - break; - } - } - - worldPoint.lat = lat; - worldPoint.lon = lon; - worldPoint.hgt = heightEllipsoid ; + SarSensor sensor(_sensor,_platformPosition); + double lon, lat; + // const double CLUM = 2.99792458e+8 ; + + // optimization + double col = image_point.x - (image_point.x * _optimizationFactorX + _optimizationBiasX) ; + double line = image_point.y - (image_point.y * _optimizationFactorY + _optimizationBiasY) ; + + // Slant range computation, depending on the product type + double slantRange; + if (_isProductGeoreferenced) { + slantRange = getSlantRangeFromGeoreferenced(col) ; + } + else { + slantRange = getSlantRange(col) ; + } + + JSDDateTime azimuthTime = getTime(line) ; + int etatLoc = sensor.ImageToWorld(slantRange, azimuthTime, heightEllipsoid, lon, lat); + + if(traceDebug()) + { + switch (etatLoc) + { + case 0: + ossimNotify(ossimNotifyLevel_DEBUG) << "successful call to lineSampleHeightToWorld" << std::endl; + break; + case 1: + ossimNotify(ossimNotifyLevel_DEBUG) << "lineSampleHeightToWorld : no real root to the equation belongs to the imaging ray" << std::endl; + break; + case 2: + ossimNotify(ossimNotifyLevel_DEBUG) << "lineSampleHeightToWorld : no real root to the equation" << std::endl; + break; + default : + ossimNotify(ossimNotifyLevel_DEBUG) << "lineSampleHeightToWorld : unknown error case" << std::endl; + break; + } + } + + worldPoint.lat = lat; + worldPoint.lon = lon; + worldPoint.hgt = heightEllipsoid ; } void ossimGeometricSarSensorModel::clearGCPlist() { - _optimizationGCPsGroundCoordinates.clear(); - _optimizationGCPsImageCoordinates.clear(); + _optimizationGCPsGroundCoordinates.clear(); + _optimizationGCPsImageCoordinates.clear(); - // optimization model update - optimizeModel(_optimizationGCPsGroundCoordinates, _optimizationGCPsImageCoordinates) ; + // optimization model update + optimizeModel(_optimizationGCPsGroundCoordinates, _optimizationGCPsImageCoordinates) ; } void ossimGeometricSarSensorModel::getGCPlist(std::list<ossimGpt> & groundCoordinates, std::list<ossimDpt> & imageCoordinates) { - groundCoordinates = _optimizationGCPsGroundCoordinates ; - imageCoordinates = _optimizationGCPsImageCoordinates ; + groundCoordinates = _optimizationGCPsGroundCoordinates ; + imageCoordinates = _optimizationGCPsImageCoordinates ; } -bool ossimGeometricSarSensorModel::optimizeModel(const std::list<ossimGpt> & groundCoordinates, const std::list<ossimDpt> & imageCoordinates) { - - if (groundCoordinates.size() != imageCoordinates.size()) return false ; - - // no optimization is used during the GCP localization error computation - _optimizationFactorX = 0.0 ; - _optimizationFactorY = 0.0 ; - _optimizationBiasX = 0.0 ; - _optimizationBiasY = 0.0 ; - - // appends the user input GCPs to the GCPs already present - _optimizationGCPsGroundCoordinates.insert(_optimizationGCPsGroundCoordinates.end(), groundCoordinates.begin(), groundCoordinates.end()) ; - _optimizationGCPsImageCoordinates.insert(_optimizationGCPsImageCoordinates.end(), imageCoordinates.begin(), imageCoordinates.end()) ; - - // no GCP : no optimization - if (groundCoordinates.size() == 0) return true ; - - // Inverse projection of each Ground Control Point - std::list<ossimGpt>::iterator itGround = _optimizationGCPsGroundCoordinates.begin() ; - std::list<ossimDpt> inverseLocResults ; - while (itGround != _optimizationGCPsGroundCoordinates.end()) { - ossimDpt itLoc ; - this->worldToLineSample(*itGround,itLoc); - inverseLocResults.push_back(itLoc) ; - itGround++; - } - - // error computation - int nbPoints = _optimizationGCPsGroundCoordinates.size() ; - double xErrorMean = 0.0, yErrorMean = 0.0, xActualPow = 0.0, yActualPow = 0.0, xActualMean = 0.0, yActualMean = 0.0, - xErrorByActualMean = 0.0, yErrorByActualMean = 0.0 ; - double xLocalError, yLocalError ; - - std::list<ossimDpt>::iterator itActualCoords = _optimizationGCPsImageCoordinates.begin() ; - std::list<ossimDpt>::iterator itEstimatedCoords = inverseLocResults.begin() ; - while ((itActualCoords != _optimizationGCPsImageCoordinates.end())&&(itEstimatedCoords != inverseLocResults.end())) { - xLocalError = itActualCoords->x - itEstimatedCoords->x ; - yLocalError = itActualCoords->y - itEstimatedCoords->y ; - - xErrorMean += xLocalError ; - yErrorMean += yLocalError ; - xActualMean += itActualCoords->x ; - yActualMean += itActualCoords->y ; - xActualPow += itActualCoords->x * itActualCoords->x ; - yActualPow += itActualCoords->y * itActualCoords->y ; - xErrorByActualMean += xLocalError * itActualCoords->x ; - yErrorByActualMean += yLocalError * itActualCoords->y ; - - ++itActualCoords; - ++itEstimatedCoords; - } - - xErrorMean /= nbPoints ; - yErrorMean /= nbPoints ; - xActualMean /= nbPoints ; - yActualMean /= nbPoints ; - xActualPow /= nbPoints ; - yActualPow /= nbPoints ; - xErrorByActualMean /= nbPoints ; - yErrorByActualMean /= nbPoints ; - - // linear regression - if (fabs(xActualPow - xActualMean*xActualMean) > FLT_EPSILON) - _optimizationFactorX = (xErrorByActualMean - xErrorMean * xActualMean) / (xActualPow - xActualMean*xActualMean) ; - if (fabs(yActualPow - yActualMean*yActualMean) > FLT_EPSILON) - _optimizationFactorY = (yErrorByActualMean - yErrorMean * yActualMean) / (yActualPow - yActualMean*yActualMean) ; - _optimizationBiasX = xErrorMean - _optimizationFactorX * xActualMean ; - _optimizationBiasY = yErrorMean - _optimizationFactorY * yActualMean ; - - //// Comparison between the estimated image coordinates of each GCP and its actual image coordinates - //double lineBias = 0.0, columnBias = 0.0 ; - //int nbPtsUsed = 0; - - //std::list<ossimDpt>::iterator itActualCoords = imageCoordinates.begin() ; - //std::list<ossimDpt>::iterator itEstimatedCoords = inverseLocResults.begin() ; - //while ((itActualCoords != imageCoordinates.end())&&(itEstimatedCoords != inverseLocResults.end())) { - // - // columnBias += (itActualCoords->x - itEstimatedCoords->x ) ; - // lineBias += (itActualCoords->y - itEstimatedCoords->y ) ; - // - // nbPtsUsed++; - // itActualCoords++; - // itEstimatedCoords++; - //} - - //// Computation of bias in line and column : mean deviations - //lineBias /= nbPtsUsed ; - //columnBias /= nbPtsUsed ; - - //// Update of the model Reference Point - //_refPoint->set_pix_col(_refPoint->get_pix_col() - columnBias); - //_refPoint->set_pix_line(_refPoint->get_pix_line() - lineBias); - - return true ; +bool ossimGeometricSarSensorModel::optimizeModel(const std::list<ossimGpt> & groundCoordinates, const std::list<ossimDpt> & imageCoordinates) +{ + if (groundCoordinates.size() != imageCoordinates.size()) return false ; + + // no optimization is used during the GCP localization error computation + _optimizationFactorX = 0.0 ; + _optimizationFactorY = 0.0 ; + _optimizationBiasX = 0.0 ; + _optimizationBiasY = 0.0 ; + + // appends the user input GCPs to the GCPs already present + _optimizationGCPsGroundCoordinates.insert(_optimizationGCPsGroundCoordinates.end(), groundCoordinates.begin(), groundCoordinates.end()) ; + _optimizationGCPsImageCoordinates.insert(_optimizationGCPsImageCoordinates.end(), imageCoordinates.begin(), imageCoordinates.end()) ; + + // no GCP : no optimization + if (groundCoordinates.size() == 0) return true ; + + // Inverse projection of each Ground Control Point + std::list<ossimGpt>::iterator itGround = _optimizationGCPsGroundCoordinates.begin() ; + std::list<ossimDpt> inverseLocResults ; + while (itGround != _optimizationGCPsGroundCoordinates.end()) + { + ossimDpt itLoc ; + this->worldToLineSample(*itGround,itLoc); + inverseLocResults.push_back(itLoc) ; + itGround++; + } + + // error computation + int nbPoints = _optimizationGCPsGroundCoordinates.size() ; + double xErrorMean = 0.0, yErrorMean = 0.0, xActualPow = 0.0, yActualPow = 0.0, xActualMean = 0.0, yActualMean = 0.0, + xErrorByActualMean = 0.0, yErrorByActualMean = 0.0 ; + double xLocalError, yLocalError ; + + std::list<ossimDpt>::iterator itActualCoords = _optimizationGCPsImageCoordinates.begin() ; + std::list<ossimDpt>::iterator itEstimatedCoords = inverseLocResults.begin() ; + while ((itActualCoords != _optimizationGCPsImageCoordinates.end())&&(itEstimatedCoords != inverseLocResults.end())) { + xLocalError = itActualCoords->x - itEstimatedCoords->x ; + yLocalError = itActualCoords->y - itEstimatedCoords->y ; + + xErrorMean += xLocalError ; + yErrorMean += yLocalError ; + xActualMean += itActualCoords->x ; + yActualMean += itActualCoords->y ; + xActualPow += itActualCoords->x * itActualCoords->x ; + yActualPow += itActualCoords->y * itActualCoords->y ; + xErrorByActualMean += xLocalError * itActualCoords->x ; + yErrorByActualMean += yLocalError * itActualCoords->y ; + + ++itActualCoords; + ++itEstimatedCoords; + } + + xErrorMean /= nbPoints ; + yErrorMean /= nbPoints ; + xActualMean /= nbPoints ; + yActualMean /= nbPoints ; + xActualPow /= nbPoints ; + yActualPow /= nbPoints ; + xErrorByActualMean /= nbPoints ; + yErrorByActualMean /= nbPoints ; + + // linear regression + if (fabs(xActualPow - xActualMean*xActualMean) > FLT_EPSILON) + _optimizationFactorX = (xErrorByActualMean - xErrorMean * xActualMean) / (xActualPow - xActualMean*xActualMean) ; + if (fabs(yActualPow - yActualMean*yActualMean) > FLT_EPSILON) + _optimizationFactorY = (yErrorByActualMean - yErrorMean * yActualMean) / (yActualPow - yActualMean*yActualMean) ; + _optimizationBiasX = xErrorMean - _optimizationFactorX * xActualMean ; + _optimizationBiasY = yErrorMean - _optimizationFactorY * yActualMean ; + + //// Comparison between the estimated image coordinates of each GCP and its actual image coordinates + //double lineBias = 0.0, columnBias = 0.0 ; + //int nbPtsUsed = 0; + + //std::list<ossimDpt>::iterator itActualCoords = imageCoordinates.begin() ; + //std::list<ossimDpt>::iterator itEstimatedCoords = inverseLocResults.begin() ; + //while ((itActualCoords != imageCoordinates.end())&&(itEstimatedCoords != inverseLocResults.end())) { + // + // columnBias += (itActualCoords->x - itEstimatedCoords->x ) ; + // lineBias += (itActualCoords->y - itEstimatedCoords->y ) ; + // + // nbPtsUsed++; + // itActualCoords++; + // itEstimatedCoords++; + //} + + //// Computation of bias in line and column : mean deviations + //lineBias /= nbPtsUsed ; + //columnBias /= nbPtsUsed ; + + //// Update of the model Reference Point + //_refPoint->set_pix_col(_refPoint->get_pix_col() - columnBias); + //_refPoint->set_pix_line(_refPoint->get_pix_line() - lineBias); + + return true ; } -bool ossimGeometricSarSensorModel::loadState(const ossimKeywordlist &kwl, const char *prefix) +bool ossimGeometricSarSensorModel::saveState(ossimKeywordlist& kwl, + const char* prefix) const + { - if(!InitSRGR(kwl, prefix)) - { - return false; - } - if(!InitPlatformPosition(kwl, prefix)) - { - return false; - } - if(!InitSensorParams(kwl, prefix)) - { - return false; - } - if(!InitRefPoint(kwl, prefix)) - { - return false; - } - return true; + static const char MODULE[] = "ossimGeometricSarSensorModel::saveState"; + + bool result = false; + + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n"; + } + + if (_platformPosition && _sensor && _refPoint) + { + if ( _platformPosition->saveState(kwl, prefix) ) + { + if ( _sensor->saveState(kwl, prefix) ) + { + result = _refPoint->saveState(kwl, prefix); + + if (result) + { + kwl.add(prefix, + PRODUCT_GEOREFERENCED_FLAG_KW, + (_isProductGeoreferenced?"true":"false")); + kwl.add(prefix, + OPTIMIZATION_FACTOR_X_KW, + _optimizationFactorX); + kwl.add(prefix, + OPTIMIZATION_FACTOR_Y_KW, + _optimizationFactorY); + kwl.add(prefix, + OPTIMIZATION_BIAS_X_KW, + _optimizationBiasX); + kwl.add(prefix, + OPTIMIZATION_BIAS_Y_KW, + _optimizationBiasY); + + result = ossimSensorModel::saveState(kwl, prefix); + } + } + } + } + + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_DEBUG) + << MODULE << " exit status = " << (result?"true":"false\n") + << std::endl; + } + + return result; } +bool ossimGeometricSarSensorModel::loadState(const ossimKeywordlist &kwl, + const char *prefix) +{ + static const char MODULE[] = "ossimGeometricSarSensorModel::loadState"; + + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n"; + } + + bool result = true; + + // Load the base class; + if ( ossimSensorModel::loadState(kwl, prefix) == false ) + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_WARN) + << MODULE + << "\nossimSensorModel::loadState failed!\n"; + } + result = false; + } + + // Load the platform position state. + if ( !_platformPosition) + { + _platformPosition = new PlatformPosition(); + } + if ( _platformPosition->loadState(kwl, prefix) == false ) + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_WARN) + << MODULE + << "\n_platformPosition->loadState failed!\n"; + } + result = false; + } + + // Load the sensor position state. + if ( !_sensor) + { + _sensor = new SensorParams(); + } + if ( _sensor->loadState(kwl, prefix) == false ) + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_WARN) + << MODULE + << "\n_sensor->loadState failed!\n"; + } + result = false; + } + + // Load the ref point. + if ( !_refPoint) + { + _refPoint = new RefPoint(); + } + if ( _refPoint->loadState(kwl, prefix) == false ) + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_WARN) + << MODULE + << "\n_refPoint->loadState failed!\n"; + } + result = false; + } + + const char* lookup = 0; + ossimString s; + + lookup = kwl.find(prefix, PRODUCT_GEOREFERENCED_FLAG_KW); + if (lookup) + { + s = lookup; + _isProductGeoreferenced = s.toBool(); + } + else + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_WARN) + << MODULE + << "\nRequired keyword not found: " + << PRODUCT_GEOREFERENCED_FLAG_KW << "\n"; + } + result = false; + } + + lookup = kwl.find(prefix, OPTIMIZATION_FACTOR_X_KW); + if (lookup) + { + s = lookup; + _optimizationFactorX = s.toDouble(); + } + else + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_WARN) + << MODULE + << "\nRequired keyword not found: " + << OPTIMIZATION_FACTOR_X_KW << "\n"; + } + result = false; + } + + lookup = kwl.find(prefix, OPTIMIZATION_FACTOR_Y_KW); + if (lookup) + { + s = lookup; + _optimizationFactorY = s.toDouble(); + } + else + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_WARN) + << MODULE + << "\nRequired keyword not found: " + << OPTIMIZATION_FACTOR_Y_KW << "\n"; + } + result = false; + } + + lookup = kwl.find(prefix,OPTIMIZATION_BIAS_X_KW); + if (lookup) + { + s = lookup; + _optimizationBiasX= s.toDouble(); + } + else + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_WARN) + << MODULE + << "\nRequired keyword not found: " + << OPTIMIZATION_BIAS_X_KW << "\n"; + } + result = false; + } + + lookup = kwl.find(prefix,OPTIMIZATION_BIAS_Y_KW); + if (lookup) + { + s = lookup; + _optimizationBiasY = s.toDouble(); + } + else + { + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_WARN) + << MODULE + << "\nRequired keyword not found: " + << OPTIMIZATION_BIAS_X_KW << "\n"; + } + result = false; + } + + // if (result && traceDebug()) +// if (result) +// { +// ossimNotify(ossimNotifyLevel_DEBUG) +// << "calling saveState to verify loadState..." << endl; + +// ossimKeywordlist kwl2; +// saveState(kwl2, 0); + +// ossimNotify(ossimNotifyLevel_DEBUG) +// << "saveState result after loadState:" << kwl2 << endl; +// } + + if (traceDebug()) + { + ossimNotify(ossimNotifyLevel_DEBUG) + << MODULE << " exit status = " << (result?"true":"false\n") + << std::endl; + } + + return result; +} - - +#if 0 + if(!InitSRGR(kwl, prefix)) + { + return false; + } + if(!InitPlatformPosition(kwl, prefix)) + { + return false; + } + if(!InitSensorParams(kwl, prefix)) + { + return false; + } + if(!InitRefPoint(kwl, prefix)) + { + return false; + } + return true; +} +#endif + +std::ostream& ossimGeometricSarSensorModel::print(std::ostream& out) const +{ + out << setprecision(15) << setiosflags(ios::fixed) + << "\nossimGeometricSarSensorModel class data members:\n"; + + const char* prefix = 0; + ossimKeywordlist kwl; + if (_platformPosition) + { + _platformPosition->saveState(kwl, prefix); + } + if (_sensor) + { + _sensor->saveState(kwl, prefix); + } + if (_refPoint) + { + _refPoint->saveState(kwl, prefix); + } + + kwl.add(prefix, + PRODUCT_GEOREFERENCED_FLAG_KW, + (_isProductGeoreferenced?"true":"false")); + kwl.add(prefix, + OPTIMIZATION_FACTOR_X_KW, + _optimizationFactorX); + kwl.add(prefix, + OPTIMIZATION_FACTOR_Y_KW, + _optimizationFactorY); + kwl.add(prefix, + OPTIMIZATION_BIAS_X_KW, + _optimizationBiasX); + kwl.add(prefix, + OPTIMIZATION_BIAS_Y_KW, + _optimizationBiasY); + + out << kwl; + + return ossimSensorModel::print(out); +} diff --git a/Utilities/otbossim/src/ossim/projection/ossimSensorModelFactory.cpp b/Utilities/otbossim/src/ossim/projection/ossimSensorModelFactory.cpp index 7bfabb4000..11d074ea39 100644 --- a/Utilities/otbossim/src/ossim/projection/ossimSensorModelFactory.cpp +++ b/Utilities/otbossim/src/ossim/projection/ossimSensorModelFactory.cpp @@ -48,7 +48,7 @@ static ossimTrace traceDebug = ossimTrace("ossimSensorModelFactory:debug"); #include <ossim/support_data/ossimFfL5.h> #include <ossim/projection/ossimRadarSatModel.h> #include <ossim/projection/ossimEnvisatAsarModel.h> -#include <ossim/projection/ossimTerraSarModel.h> +// #include <ossim/projection/ossimTerraSarModel.h>//in plugins //#include <ossim/projection/ossimCosmoSkymedModel.h> #include <ossim/projection/ossimRadarSat2Model.h> #include <ossim/projection/ossimErsSarModel.h> @@ -200,10 +200,10 @@ ossimSensorModelFactory::createProjection(const ossimString &name) const { return new ossimEnvisatAsarModel; } - if (name == STATIC_TYPE_NAME(ossimTerraSarModel)) - { - return new ossimTerraSarModel; - } +// if (name == STATIC_TYPE_NAME(ossimTerraSarModel)) +// { +// return new ossimTerraSarModel;//in plugins +// } // if (name == STATIC_TYPE_NAME(ossimCosmoSkymedModel)) // { // return new ossimCosmoSkymedModel; @@ -265,7 +265,7 @@ ossimSensorModelFactory::getTypeNameList(std::vector<ossimString>& typeList) typeList.push_back(STATIC_TYPE_NAME(ossimSarModel)); typeList.push_back(STATIC_TYPE_NAME(ossimRadarSatModel)); typeList.push_back(STATIC_TYPE_NAME(ossimRadarSat2Model)); - typeList.push_back(STATIC_TYPE_NAME(ossimTerraSarModel)); +// typeList.push_back(STATIC_TYPE_NAME(ossimTerraSarModel)); // typeList.push_back(STATIC_TYPE_NAME(ossimCosmoSkymedModel)); typeList.push_back(STATIC_TYPE_NAME(ossimEnvisatAsarModel)); typeList.push_back(STATIC_TYPE_NAME(ossimErsSarModel)); diff --git a/Utilities/otbossimplugins/ossim/ossimCosmoSkymedModel.cpp b/Utilities/otbossimplugins/ossim/ossimCosmoSkymedModel.cpp deleted file mode 100644 index a9fe414324..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimCosmoSkymedModel.cpp +++ /dev/null @@ -1,387 +0,0 @@ -//---------------------------------------------------------------------------- -// -// "Copyright Centre National d'Etudes Spatiales" -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -//---------------------------------------------------------------------------- -// $Id$ - -#include <ossimCosmoSkymedModel.h> - -#include <otb/GalileanEphemeris.h> -#include <otb/GeographicEphemeris.h> -#include <otb/GMSTDateTime.h> - -#include <otb/PlatformPosition.h> -#include <otb/SensorParams.h> -#include <otb/RefPoint.h> -#include <otb/SarSensor.h> - -#include <cmath> - -RTTI_DEF1(ossimCosmoSkymedModel, "ossimCosmoSkymedModel", ossimGeometricSarSensorModel); - -ossimCosmoSkymedModel::ossimCosmoSkymedModel(): - _nbCol(0), - _SrGr_R0(0), - _sceneCenterRangeTime(0), - _pixel_spacing(0) -{ -} - -ossimCosmoSkymedModel::~ossimCosmoSkymedModel() -{ -} - -double ossimCosmoSkymedModel::getSlantRangeFromGeoreferenced(double col) const -{ - // in the case of Georeferenced images, _refPoint->get_distance() contains the ground range - double relativeGroundRange = _refPoint->get_distance() + _sensor->get_col_direction() * (col-_refPoint->get_pix_col())* _pixel_spacing ; - - double slantRange = _SrGr_coeffs[0] - + _SrGr_coeffs[1]*(relativeGroundRange-_SrGr_R0) - + _SrGr_coeffs[2]*(pow(relativeGroundRange,2)-_SrGr_R0) - + _SrGr_coeffs[3]*(pow(relativeGroundRange,3)-_SrGr_R0) - + _SrGr_coeffs[4]*(pow(relativeGroundRange,4)-_SrGr_R0) - + _SrGr_coeffs[5]*(pow(relativeGroundRange,5)-_SrGr_R0); - - return slantRange ; -} - -bool ossimCosmoSkymedModel::InitSensorParams(const ossimKeywordlist &kwl, const char *prefix) -{ - const char* central_freq_str = kwl.find(prefix,"central_freq"); - double central_freq = atof(central_freq_str); - const char* fr_str = kwl.find(prefix,"fr"); - double fr = atof(fr_str); - const char* fa_str = kwl.find(prefix,"fa"); - double fa = atof(fa_str); - - //number of different looks - const char* n_azilok_str = kwl.find(prefix,"n_azilok"); - double n_azilok = atof(n_azilok_str); - const char* n_rnglok_str = kwl.find(prefix,"n_rnglok"); - double n_rnglok = atof(n_rnglok_str); - - //ellipsoid parameters - const char* ellip_maj_str = kwl.find(prefix,"ellip_maj"); - double ellip_maj = atof(ellip_maj_str) * 1000.0; // km -> m - const char* ellip_min_str = kwl.find(prefix,"ellip_min"); - double ellip_min = atof(ellip_min_str) * 1000.0; // km -> m - - if(_sensor != NULL) - { - delete _sensor; - } - - _sensor = new SensorParams(); - - - /** - * @todo : � voir sur de vrais produits (exemples de DESCENDING et ASCENDING) - */ - const char* orbitDirection_str = kwl.find(prefix,"orbitDirection"); - std::string orbitDirection(orbitDirection_str) ; - int orbitDirectionSign ; - if (orbitDirection=="DESCENDING") orbitDirectionSign = 1 ; - else orbitDirectionSign = - 1 ; - - const char* lookDirection_str = kwl.find(prefix,"lookDirection"); - std::string lookDirection(lookDirection_str) ; - if ((lookDirection == "Right")||(lookDirection == "RIGHT")) _sensor->set_sightDirection(SensorParams::Right) ; - else _sensor->set_sightDirection(SensorParams::Left) ; - - const char* colsOrder_str = kwl.find(prefix,"colsOrder"); - std::string colsOrder(colsOrder_str) ; - const char* linsOrder_str = kwl.find(prefix,"linsOrder"); - std::string linsOrder(linsOrder_str) ; - if (colsOrder=="NEAR-FAR") - _sensor->set_col_direction(orbitDirectionSign); - else _sensor->set_col_direction(-orbitDirectionSign); - if (linsOrder=="NEAR-FAR") - _sensor->set_lin_direction(orbitDirectionSign); - else _sensor->set_lin_direction(-orbitDirectionSign); - - _sensor->set_sf(fr); - const double CLUM = 2.99792458e+8 ; - double wave_length = CLUM / central_freq ; - _sensor->set_rwl(wave_length); - _sensor->set_nAzimuthLook(n_azilok); - _sensor->set_nRangeLook(n_rnglok); - - // fa is the processing PRF - _sensor->set_prf(fa * n_azilok); - - _sensor->set_semiMajorAxis(ellip_maj) ; - _sensor->set_semiMinorAxis(ellip_min) ; - - return true; -} - -bool ossimCosmoSkymedModel::InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix) -{ - /* - * Retrieval of ephemerisis number - */ - const char* neph_str = kwl.find(prefix,"neph"); - int neph = atoi(neph_str); - - Ephemeris** ephemeris = new Ephemeris*[neph]; - - /* - * Retrieval of reference date - */ - const char* referenceUTC_str = kwl.find(prefix,"referenceUTC"); - std::string referenceUTC(referenceUTC_str) ; - CivilDateTime ref_civil_date; - if (! UtcDateTimeStringToCivilDate(referenceUTC, ref_civil_date)) return false; - - /* - * Retrieval of ephemerisis - */ - for (int i=0;i<neph;i++) - { - double pos[3]; - double vit[3]; - char name[64]; - - sprintf(name,"eph%i_date",i); - const char* date_str = kwl.find(prefix,name); - float relative_date = atof(date_str); - - sprintf(name,"eph%i_posX",i); - const char* px_str = kwl.find(prefix,name); - pos[0] = atof(px_str); - - sprintf(name,"eph%i_posY",i); - const char* py_str = kwl.find(prefix,name); - pos[1] = atof(py_str); - - sprintf(name,"eph%i_posZ",i); - const char* pz_str = kwl.find(prefix,name); - pos[2] = atof(pz_str); - - sprintf(name,"eph%i_velX",i); - const char* vx_str = kwl.find(prefix,name); - vit[0] = atof(vx_str) ; - - sprintf(name,"eph%i_velY",i); - const char* vy_str = kwl.find(prefix,name); - vit[1] = atof(vy_str) ; - - sprintf(name,"eph%i_velZ",i); - const char* vz_str = kwl.find(prefix,name); - vit[2] = atof(vz_str) ; - /* - * Conversion to JSD Date - */ - int second = (int) relative_date ; - double decimal = relative_date - second ; - CivilDateTime eph_civil_date(ref_civil_date.get_year(), ref_civil_date.get_month(), ref_civil_date.get_day(), second, decimal); - JSDDateTime eph_jsd_date(eph_civil_date); - - GeographicEphemeris* eph = new GeographicEphemeris(eph_jsd_date,pos,vit); - - ephemeris[i] = eph; - } - - /* - * Creation of the platform position interpolator - */ - if (_platformPosition != NULL) - { - delete _platformPosition; - } - _platformPosition = new PlatformPosition(ephemeris,neph); - - /* - * Free of memory used by ephemerisis list : the constructor copies the ephemerisis - */ - for (int i=0;i<neph;i++) - { - delete ephemeris[i]; - } - delete[] ephemeris; - - return true; -} - -bool ossimCosmoSkymedModel::InitRefPoint(const ossimKeywordlist &kwl, const char *prefix) -{ - const char* sc_lin_str = kwl.find(prefix,"sc_lin"); - double sc_lin = atof(sc_lin_str); - - const char* sc_pix_str = kwl.find(prefix,"sc_pix"); - double sc_pix = atof(sc_pix_str); - - // const char* pixel_spacing_str = kwl.find(prefix,"pixel_spacing"); - // double pixel_spacing = atof(pixel_spacing_str); - - const char* azimuthStartTime_str = kwl.find(prefix,"azimuthStartTime"); - double azimuthStartTime = atof(azimuthStartTime_str); - - const char* rng_gate_str = kwl.find(prefix,"rng_gate"); - double rng_gate = atof(rng_gate_str); - - const char* referenceUTC_str = kwl.find(prefix,"referenceUTC"); - std::string referenceUTC(referenceUTC_str) ; - CivilDateTime ref_civil_date; - if (! UtcDateTimeStringToCivilDate(referenceUTC, ref_civil_date)) return false; - - if(_refPoint == NULL) - { - _refPoint = new RefPoint(); - } - - _refPoint->set_pix_col(sc_pix); - _refPoint->set_pix_line(sc_lin); - - double relative_date = (azimuthStartTime + sc_lin/_sensor->get_prf()); - int second = (int) relative_date ; - double decimal = relative_date - second ; - CivilDateTime * date = new CivilDateTime(ref_civil_date.get_year(), ref_civil_date.get_month(), ref_civil_date.get_day(), second, decimal); - - if(_platformPosition != NULL) - { - Ephemeris * ephemeris = _platformPosition->Interpolate((JSDDateTime)*date); - if (ephemeris == NULL) return false ; - - _refPoint->set_ephemeris(ephemeris); - - delete ephemeris; - } - else - { - return false; - } - - double c = 2.99792458e+8; - double distance = (rng_gate + sc_pix*_sensor->get_nRangeLook()/_sensor->get_sf()) * (c/2.0); - - // in the case of Georeferenced images, the "relative" ground range is stored in place of the slant range - // (used for SlantRange computation relative to reference point, necessary for optimization) - // here, the pixelDirection is ignored since the CSKS reference point is always at the scene centre - if (_isProductGeoreferenced) { - distance = _refPoint->get_pix_col() * _pixel_spacing ; - } - - _refPoint->set_distance(distance); - - - // in order to use ossimSensorModel::lineSampleToWorld - const char* nbCol_str = kwl.find(prefix,"nbCol"); - const char* nbLin_str = kwl.find(prefix,"nbLin"); - theImageSize.x = atoi(nbCol_str); - theImageSize.y = atoi(nbLin_str); - theImageClipRect = ossimDrect(0, 0, theImageSize.x-1, theImageSize.y-1); - - - // Ground Control Points extracted from the model : scene center and corners - std::list<ossimGpt> groundGcpCoordinates ; - std::list<ossimDpt> imageGcpCoordinates ; - char name[64]; - for (int k=0 ; k<5 ; k++) { - sprintf(name,"cornersCol%i",k); - const char* i_str = kwl.find(name); - int i = atoi(i_str); - sprintf(name,"cornersLin%i",k); - const char* j_str = kwl.find(name); - int j = atoi(j_str); - sprintf(name,"cornersLon%i",k); - const char* lon_str = kwl.find(name); - double lon = atof(lon_str); - sprintf(name,"cornersLat%i",k); - const char* lat_str = kwl.find(name); - double lat = atof(lat_str); - sprintf(name,"cornersHeight%i",k); - const char* height_str = kwl.find(name); - double height = atof(height_str) ; - - ossimDpt imageGCP(i,j); - ossimGpt groundGCP(lat, lon, height); - groundGcpCoordinates.push_back(groundGCP) ; - imageGcpCoordinates.push_back(imageGCP) ; - } - - // Default optimization - optimizeModel(groundGcpCoordinates, imageGcpCoordinates) ; - - return true; -} - -bool ossimCosmoSkymedModel::InitSRGR(const ossimKeywordlist &kwl, const char *prefix) -{ - const char* rangeProjectionType_str = kwl.find(prefix,"rangeProjectionType"); - std::string rangeProjectionType(rangeProjectionType_str); - - const char* pixel_spacing_str = kwl.find(prefix,"pixel_spacing"); - _pixel_spacing= atof(pixel_spacing_str); - - _isProductGeoreferenced = (rangeProjectionType=="GROUNDRANGE") ; - - // Number of columns - const char* nbCol_str = kwl.find(prefix,"nbCol"); - _nbCol = atoi(nbCol_str); - - // SRGR polynomial reference - const char* SrGr_R0_str = kwl.find(prefix,"SrGr_R0"); - _SrGr_R0 = atof(SrGr_R0_str); - - // SRGR coefficients - char name[64]; - double coeff ; - for(int i=0;i<6;i++) - { - sprintf(name,"SrToGr_coeffs_%i",i); - const char* coeff_str = kwl.find(prefix,name); - coeff = atof(coeff_str); - _SrGr_coeffs.push_back(coeff); - } - - return true; -} - - -bool ossimCosmoSkymedModel::UtcDateTimeStringToCivilDate(const std::string &utcString, CivilDateTime &outputDate) { - // conversion : - // try with date format yyyymmdd - - if (utcString.size() < 8) return false ; - const char* stringUTCDate = utcString.c_str() ; - - char year_str[5]; - for (int i=0;i<4;i++) - { - year_str[i] = stringUTCDate[i]; - } - year_str[4] = '\0'; - - char month_str[3]; - for (int i=4;i<6;i++) - { - month_str[i-4] = stringUTCDate[i]; - } - month_str[2] = '\0'; - - char day_str[3]; - for (int i=6;i<8;i++) - { - day_str[i-6] = stringUTCDate[i]; - } - day_str[2] = '\0'; - - outputDate.set_year(atoi(year_str)); - outputDate.set_month(atoi(month_str)); - outputDate.set_day(atoi(day_str)); - outputDate.set_second(0.0); - outputDate.set_decimal(0.0); - - return true ; -} - - - - diff --git a/Utilities/otbossimplugins/ossim/ossimCosmoSkymedModel.h b/Utilities/otbossimplugins/ossim/ossimCosmoSkymedModel.h deleted file mode 100644 index 73fbd0352f..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimCosmoSkymedModel.h +++ /dev/null @@ -1,91 +0,0 @@ -//---------------------------------------------------------------------------- -// -// "Copyright Centre National d'Etudes Spatiales" -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -//---------------------------------------------------------------------------- -// $Id$ - -#ifndef ossimCosmoSkymedModel_H -#define ossimCosmoSkymedModel_H - -#include <ossimGeometricSarSensorModel.h> -#include <ossim/projection/ossimMapProjection.h> -#include <ossim/base/ossimIpt.h> -#include <ossim/base/ossimFilename.h> -#include <ossim/base/ossimGpt.h> -#include <ossim/base/ossimDpt.h> - -#include <otb/CivilDateTime.h> - -#include <iostream> -#include <list> - -class PlatformPosition; -class SensorParams; -class RefPoint; -/** - * @brief This class allows for direct localisation and indirect localisation - * using the CosmoSkymed sensor model - */ -class ossimCosmoSkymedModel : public ossimGeometricSarSensorModel -{ -public: - /** - * @brief Constructor - */ - ossimCosmoSkymedModel(); - - /** - * @brief Destructor - */ - ~ossimCosmoSkymedModel(); - - /** - * @brief This function associates an image column number to a slant range when the image is georeferenced (ground projected) - * @param col Column coordinate of the image point - */ - virtual double getSlantRangeFromGeoreferenced(double col) const; - -protected: - - /** - * @brief Number of columns - */ - double _nbCol; - /** - * @brief Slant Range for each Ground Range Projection reference point - */ - double _SrGr_R0 ; - /** - * @brief Slant Range for each Ground Range Projection coefficients - */ - std::vector<double> _SrGr_coeffs ; - /** - * @brief Scene Center range time - */ - double _sceneCenterRangeTime; - /** - * @brief Pixel spacing - */ - double _pixel_spacing ; - -private: - virtual bool InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix); - virtual bool InitSensorParams(const ossimKeywordlist &kwl, const char *prefix); - virtual bool InitRefPoint(const ossimKeywordlist &kwl, const char *prefix); - /** - * @brief Initializes the Slant Range to Ground Range data sets : - * _SrToGr_R0,_SrToGr_coeffs_number,_SrToGr_exponent,_SrToGr_coeffs,_nbCol - */ - virtual bool InitSRGR(const ossimKeywordlist &kwl, const char *prefix); - - bool UtcDateTimeStringToCivilDate(const std::string &utcString, CivilDateTime &outputDate); - - TYPE_DATA -}; - -#endif diff --git a/Utilities/otbossimplugins/ossim/ossimEnvisatAsarModel.cpp b/Utilities/otbossimplugins/ossim/ossimEnvisatAsarModel.cpp deleted file mode 100644 index 8c59e9e8c2..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimEnvisatAsarModel.cpp +++ /dev/null @@ -1,366 +0,0 @@ -//---------------------------------------------------------------------------- -// -// "Copyright Centre National d'Etudes Spatiales" -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -//---------------------------------------------------------------------------- -// $Id$ - -#include <ossimEnvisatAsarModel.h> -#include <otb/GalileanEphemeris.h> -#include <otb/GeographicEphemeris.h> - -#include <otb/GMSTDateTime.h> -#include <otb/CivilDateTime.h> -#include <otb/MJDDateTime.h> - -#include <otb/PlatformPosition.h> -#include <otb/SensorParams.h> -#include <otb/RefPoint.h> -#include <otb/SarSensor.h> - -#include <cmath> - -RTTI_DEF1(ossimEnvisatAsarModel, "ossimEnvisatAsarModel", ossimGeometricSarSensorModel); - -ossimEnvisatAsarModel::ossimEnvisatAsarModel(): - _n_srgr(0), - _pixel_spacing(0) -{ -} - -ossimEnvisatAsarModel::~ossimEnvisatAsarModel() -{ -} - -double ossimEnvisatAsarModel::getSlantRangeFromGeoreferenced(double col) const -{ - const double CLUM = 2.99792458e+8 ; - - double GR, GR0, relativeGroundRange, slantRange, slantrangetime; - - if (_n_srgr==0) return(-1) ; - - std::vector<double> coefset = FindSRGRSetNumber((_refPoint->get_ephemeris())->get_date()) ; - - GR = _sensor->get_col_direction() * (col)* _pixel_spacing ; - GR0 = coefset[0]; - relativeGroundRange = GR-GR0; - slantRange = coefset[1] - + coefset[2]*relativeGroundRange - + coefset[3]*pow(relativeGroundRange,2) - + coefset[4]*pow(relativeGroundRange,3) - + coefset[5]*pow(relativeGroundRange,4); - - slantrangetime = 2.0*slantRange / (CLUM); - return slantRange ; -} - -bool ossimEnvisatAsarModel::InitSensorParams(const ossimKeywordlist &kwl, const char *prefix) -{ - const double CLUM = 2.99792458e+8; - const char* wave_length_str = kwl.find(prefix,"wave_length"); - double wave_length = CLUM / atof(wave_length_str); - const char* fr_str = kwl.find(prefix,"range_sampling_rate"); - double fr = atof(fr_str); - - // product type : Slant Range or Ground Range - _isProductGeoreferenced = atoi(kwl.find(prefix,"is_groundrange")); - double fa; - if (!_isProductGeoreferenced) - { - const char* fa_str = kwl.find(prefix,"prf"); - fa = atof(fa_str); - } - else - { - const char* fa_str = kwl.find(prefix,"line_time_interval"); - fa = 1.0/atof(fa_str); - } - - // TODO : v�rifier que ceci est ok pour les produits IMP - const char* time_dir_pix = "INCREASE"; - const char* time_dir_lin = "INCREASE"; - - if(_sensor != NULL) - { - delete _sensor; - } - - _sensor = new SensorParams(); - - if(strcmp(time_dir_pix, "INCREASE") == 0) - { - _sensor->set_col_direction(1); - } - else - { - _sensor->set_col_direction(-1); - } - - if(strcmp(time_dir_lin, "INCREASE") == 0) - { - _sensor->set_lin_direction(1); - } - else - { - _sensor->set_lin_direction(-1); - } - - _sensor->set_prf(fa); - _sensor->set_sf(fr); - _sensor->set_rwl(wave_length); - - return true; -} - -bool ossimEnvisatAsarModel::InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix) -{ - const int neph = 5; - // long val_long; - // unsigned long val_ulong1; - // unsigned long val_ulong2; - CivilDateTime ref_civil_date; - - Ephemeris** ephemeris = new Ephemeris*[neph]; - - for (int i=1;i<=neph;i++) - { - double pos[3]; - double vel[3]; - char name[64]; - - /* - * Date de l'ephemeride - */ - sprintf(name,"state_vector_time_%i_day",i); - long day = (long) atof(kwl.find(prefix,name)); - sprintf(name,"state_vector_time_%i_sec",i); - unsigned long sec = (unsigned long) atof(kwl.find(prefix,name)); - sprintf(name,"state_vector_time_%i_microsec",i); - unsigned long microsec = (unsigned long) atof(kwl.find(prefix,name)); - MJDDateTime mjdDate(day, sec, microsec); - JSDDateTime jsd_date(mjdDate); - /* - * Position de l'ephemeride - */ - sprintf(name,"x_pos_%i",i); - pos[0] = (double) atoi(kwl.find(prefix,name)) * 1.0e-2; - sprintf(name,"y_pos_%i",i); - pos[1] = (double) atoi(kwl.find(prefix,name)) * 1.0e-2; - sprintf(name,"z_pos_%i",i); - pos[2] = (double) atoi(kwl.find(prefix,name)) * 1.0e-2; - /* - * Vitesse de l'ephemeride - */ - sprintf(name,"x_vel_%i",i); - vel[0] = (double) atoi(kwl.find(prefix,name)) * 1.0e-5; - sprintf(name,"y_vel_%i",i); - vel[1] = (double) atoi(kwl.find(prefix,name)) * 1.0e-5; - sprintf(name,"z_vel_%i",i); - vel[2] = (double) atoi(kwl.find(prefix,name)) * 1.0e-5; - - GeographicEphemeris* eph = new GeographicEphemeris(jsd_date, pos, vel); - - ephemeris[i-1] = eph; - } - - if (_platformPosition != NULL) - { - delete _platformPosition; - } - _platformPosition = new PlatformPosition(ephemeris,neph); - - /* - * Liberation de la memoire utilis�e par la liste des ephemerides - * ->Le constructeur effectue une copie des ephemerides - */ - for (int i=0;i<neph;i++) - { - delete ephemeris[i]; - } - delete[] ephemeris; - - return true; -} - - - -bool ossimEnvisatAsarModel::InitRefPoint(const ossimKeywordlist &kwl, const char *prefix) -{ - - // Reference image position - if(_refPoint == NULL) - { - _refPoint = new RefPoint(); - } - double sc_pix = atof(kwl.find(prefix,"samp_num")) - 1.0; - _refPoint->set_pix_col(sc_pix); - double sc_lin = atof(kwl.find(prefix,"line_num")) - 1.0; - _refPoint->set_pix_line(sc_lin); - - // Reference Point distance - double c = 2.99792458e+8; - double distance = atof(kwl.find(prefix,"slant_range_time")) * (c/2.0) * 1.0e-9; - _refPoint->set_distance(distance); - - - // Reference Point Ephemeris - long day_ref = (long)atof(kwl.find(prefix,"first_zero_doppler_time_day")); - unsigned long sec_ref = (unsigned long)atof(kwl.find(prefix,"first_zero_doppler_time_sec")); - unsigned long microsec_ref = (unsigned long)atof(kwl.find(prefix,"first_zero_doppler_time_microsec")); - - MJDDateTime mjdDate_ref(day_ref, sec_ref, microsec_ref); - JSDDateTime jsd_date_ref(mjdDate_ref); - - if(_platformPosition != NULL) - { - Ephemeris * ephemeris = _platformPosition->Interpolate(jsd_date_ref); - if (ephemeris == NULL) return false ; - _refPoint->set_ephemeris(ephemeris); - delete ephemeris; - } - else return false; - - // Adjustement of the model using the four corner points - // in order to use ossimSensorModel::lineSampleToWorld - const char* nbCol_str = kwl.find(prefix,"num_pix"); - const char* nbLin_str = kwl.find(prefix,"num_lines"); - theImageSize.x = atoi(nbCol_str); - theImageSize.y = atoi(nbLin_str); - theImageClipRect = ossimDrect(0, 0, theImageSize.x-1, theImageSize.y-1); - - // Ground Control Points extracted from the model : corner points - std::list<ossimGpt> groundGcpCoordinates ; - std::list<ossimDpt> imageGcpCoordinates ; - double h = atof(kwl.find("avg_scene_height")); - - // first line first pix - double line = atof(kwl.find("UL_line")) - 1; - double col = atof(kwl.find("UL_col")) - 1; - double lon = atof(kwl.find("UL_lon")) * 1e-6; - double lat = atof(kwl.find("UL_lat")) * 1e-6; - if (lon > 180.0) lon -= 360.0; - ossimDpt imageGCP1(col,line); - ossimGpt groundGCP1(lat, lon, h); - groundGcpCoordinates.push_back(groundGCP1) ; - imageGcpCoordinates.push_back(imageGCP1) ; - // first line last pix - line = atof(kwl.find("UR_line")) - 1; - col = atof(kwl.find("UR_col")) - 1; - lon = atof(kwl.find("UR_lon")) * 1e-6; - lat = atof(kwl.find("UR_lat")) * 1e-6; - if (lon > 180.0) lon -= 360.0; - ossimDpt imageGCP2(col,line); - ossimGpt groundGCP2(lat, lon, h); - groundGcpCoordinates.push_back(groundGCP2) ; - imageGcpCoordinates.push_back(imageGCP2) ; - // last line last pix - line = atof(kwl.find("LR_line")) - 1; - col = atof(kwl.find("LR_col")) - 1; - lon = atof(kwl.find("LR_lon")) * 1e-6; - lat = atof(kwl.find("LR_lat")) * 1e-6; - if (lon > 180.0) lon -= 360.0; - ossimDpt imageGCP3(col,line); - ossimGpt groundGCP3(lat, lon, h); - groundGcpCoordinates.push_back(groundGCP3) ; - imageGcpCoordinates.push_back(imageGCP3) ; - // last line first pix - line = atof(kwl.find("LL_line")) - 1; - col = atof(kwl.find("LL_col")) - 1; - lon = atof(kwl.find("LL_lon")) * 1e-6; - lat = atof(kwl.find("LL_lat")) * 1e-6; - if (lon > 180.0) lon -= 360.0; - ossimDpt imageGCP4(col,line); - ossimGpt groundGCP4(lat, lon, h); - groundGcpCoordinates.push_back(groundGCP4) ; - imageGcpCoordinates.push_back(imageGCP4) ; - - // Default optimization - optimizeModel(groundGcpCoordinates, imageGcpCoordinates) ; - - return true; -} -bool ossimEnvisatAsarModel::InitSRGR(const ossimKeywordlist &kwl, const char *prefix) -{ - // product type : Slant Range or Ground Range - _isProductGeoreferenced = atoi(kwl.find(prefix,"is_groundrange")); - - // pixel spacing - _pixel_spacing = atof(kwl.find(prefix,"pixel_spacing")); - - // number of SRGR sets - _n_srgr = atoi(kwl.find(prefix,"n_srgr")); - - - char name[64]; - for (int i=0;i<_n_srgr;i++) - { - // SRGR update time - sprintf(name,"srgr_update_day%i",i); - long day_ref = (long)atof(kwl.find(prefix,name)); - sprintf(name,"srgr_update_sec%i",i); - unsigned long sec_ref = (unsigned long)atof(kwl.find(prefix,name)); - sprintf(name,"srgr_update_microsec%i",i); - unsigned long microsec_ref = (unsigned long)atof(kwl.find(prefix,name)); - MJDDateTime mjdDate_ref(day_ref, sec_ref, microsec_ref); - JSDDateTime jsd_date_ref(mjdDate_ref); - _srgr_update.push_back(jsd_date_ref); - - std::vector<double> srgr_set; - // SRGR coefficients - sprintf(name,"srgr_coef%iA",i); - const char* srgr_coef_strA = kwl.find(prefix,name); - srgr_set.push_back(atof(srgr_coef_strA)); - sprintf(name,"srgr_coef%iB",i); - const char* srgr_coef_strB = kwl.find(prefix,name); - srgr_set.push_back(atof(srgr_coef_strB)); - sprintf(name,"srgr_coef%iC",i); - const char* srgr_coef_strC = kwl.find(prefix,name); - srgr_set.push_back(atof(srgr_coef_strC)); - sprintf(name,"srgr_coef%iD",i); - const char* srgr_coef_strD = kwl.find(prefix,name); - srgr_set.push_back(atof(srgr_coef_strD)); - sprintf(name,"srgr_coef%iE",i); - const char* srgr_coef_strE = kwl.find(prefix,name); - srgr_set.push_back(atof(srgr_coef_strE)*1e-10); - sprintf(name,"srgr_coef%iF",i); - const char* srgr_coef_strF = kwl.find(prefix,name); - srgr_set.push_back(atof(srgr_coef_strF)*1e-10); - - _srgr_coefset.push_back(srgr_set); - } - - - return true; -} - - -std::vector<double> ossimEnvisatAsarModel::FindSRGRSetNumber(JSDDateTime date) const -{ - //if (_n_srgr==0) return NULL ; - - std::vector<double> delays; - double delay; - for (int i=0;i<_n_srgr;i++) - { - JSDDateTime datetmp(_srgr_update.at(i)); - delay = date.get_second()+date.get_decimal() - (datetmp.get_second() + datetmp.get_decimal()); - delays.push_back( fabs(delay) ); - } - - int setNumber = 0 ; - double min_delay = delays[0] ; - for (int i=1;i<_n_srgr;i++) - { - if (delays[i]<min_delay) { - setNumber = i ; - min_delay = delays[i] ; - } - } - - return _srgr_coefset[setNumber]; -} diff --git a/Utilities/otbossimplugins/ossim/ossimEnvisatAsarModel.h b/Utilities/otbossimplugins/ossim/ossimEnvisatAsarModel.h deleted file mode 100644 index 57bad507aa..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimEnvisatAsarModel.h +++ /dev/null @@ -1,85 +0,0 @@ -//---------------------------------------------------------------------------- -// -// "Copyright Centre National d'Etudes Spatiales" -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -//---------------------------------------------------------------------------- -// $Id$ - -#ifndef ossimEnvisatAsarModel_H -#define ossimEnvisatAsarModel_H - -#include <otb/JSDDateTime.h> -#include <ossimGeometricSarSensorModel.h> -#include <ossim/projection/ossimMapProjection.h> -#include <ossim/base/ossimIpt.h> -#include <ossim/base/ossimFilename.h> -#include <ossim/base/ossimGpt.h> -#include <ossim/base/ossimDpt.h> - -#include <iostream> - -class PlatformPosition; -class SensorParams; -class RefPoint; -/** - * @brief This class is able to direct localisation and indirect localisation - * using the EnvisatAsar sensor model - */ -class ossimEnvisatAsarModel : public ossimGeometricSarSensorModel -{ -public: - /** - * @brief Constructor - */ - ossimEnvisatAsarModel(); - - /** - * @brief Destructor - */ - ~ossimEnvisatAsarModel(); - - /** - * @brief This function associates an image column number to a slant range when the image is georeferenced (ground projected) - * @param col Column coordinate of the image point - */ - virtual double getSlantRangeFromGeoreferenced(double col) const; - -protected: - - /** - * @brief Slant Range to Ground Range (SRGR) number of coefficients sets - */ - int _n_srgr; - /** - * @brief SRGR coefficient sets - */ - std::vector< std::vector<double> > _srgr_coefset; - /** - * @brief SRGR coefficient sets update times - */ - std::vector<JSDDateTime> _srgr_update; - /** - * @brief Pixel spacing - */ - double _pixel_spacing; - -private: - virtual bool InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix); - virtual bool InitSensorParams(const ossimKeywordlist &kwl, const char *prefix); - virtual bool InitRefPoint(const ossimKeywordlist &kwl, const char *prefix); - /** - * @brief Initializes the Slant Range for each Ground Range data sets : _n_srgr,_srgr_coefset,_srgr_update,_pixel_spacing,_isProductGeoreferenced - */ - virtual bool InitSRGR(const ossimKeywordlist &kwl, const char *prefix); - /** - * @brief Finds the SRGR data set which update time is the closest to the center scene time - */ - std::vector<double> FindSRGRSetNumber(JSDDateTime date) const; - TYPE_DATA -}; - -#endif diff --git a/Utilities/otbossimplugins/ossim/ossimErsSarModel.cpp b/Utilities/otbossimplugins/ossim/ossimErsSarModel.cpp deleted file mode 100644 index c71da43663..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimErsSarModel.cpp +++ /dev/null @@ -1,408 +0,0 @@ -//---------------------------------------------------------------------------- -// -// "Copyright Centre National d'Etudes Spatiales" -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -//---------------------------------------------------------------------------- -// $Id$ - -#include <ossimErsSarModel.h> -#include <otb/GalileanEphemeris.h> -#include <otb/GeographicEphemeris.h> - -#include <otb/JSDDateTime.h> -#include <otb/GMSTDateTime.h> -#include <otb/CivilDateTime.h> - -#include <otb/PlatformPosition.h> -#include <otb/SensorParams.h> -#include <otb/RefPoint.h> -#include <otb/SarSensor.h> -#include <ossim/base/ossimString.h> - -#include <cmath> -#include <cctype> // for toupper -#include <string> -#include <algorithm> - -RTTI_DEF1(ossimErsSarModel, "ossimErsSarModel", ossimGeometricSarSensorModel); - -ossimErsSarModel::ossimErsSarModel(): - _n_srgr(0), - _pixel_spacing(0) -{ -} - -ossimErsSarModel::~ossimErsSarModel() -{ -} - -double ossimErsSarModel::getSlantRangeFromGeoreferenced(double col) const -{ - const double c = 2.99792458e+8; - double tn = _srgr_coefset[0][0] + _srgr_coefset[0][1] * col + _srgr_coefset[0][2] * col*col ; - return tn * (c/2.0); -} - -bool ossimErsSarModel::InitSensorParams(const ossimKeywordlist &kwl, const char *prefix) -{ - const char* wave_length_str = kwl.find(prefix,"wave_length"); - double wave_length = atof(wave_length_str); - const char* fr_str = kwl.find(prefix,"fr"); - double fr = atof(fr_str)*1e6; - const char* fa_str = kwl.find(prefix,"fa"); - double fa = atof(fa_str); - - ossimString time_dir_pix = kwl.find(prefix,"time_dir_pix"); - time_dir_pix.upcase(); - //std::transform(time_dir_pix.begin(), time_dir_pix.end(), time_dir_pix.begin(), toupper); - ossimString time_dir_lin = kwl.find(prefix,"time_dir_lin"); - time_dir_lin.upcase(); - //std::transform(time_dir_lin.begin(), time_dir_lin.end(), time_dir_lin.begin(), toupper); - - //ellipsoid parameters - const char* ellip_maj_str = kwl.find(prefix,"ellip_maj"); - double ellip_maj = atof(ellip_maj_str) * 1000.0; // km -> m - const char* ellip_min_str = kwl.find(prefix,"ellip_min"); - double ellip_min = atof(ellip_min_str) * 1000.0; // km -> m - - if(_sensor != NULL) - { - delete _sensor; - } - - _sensor = new SensorParams(); - - if(strcmp(time_dir_pix.c_str(), "INCREASE") == 0) - { - _sensor->set_col_direction(1); - } - else - { - _sensor->set_col_direction(-1); - } - - if(strcmp(time_dir_lin.c_str(), "INCREASE") == 0) - { - _sensor->set_lin_direction(1); - } - else - { - _sensor->set_lin_direction(-1); - } - - _sensor->set_sightDirection(SensorParams::Right) ; - - double nlooks_az = atof(kwl.find(prefix,"nlooks_az")); - _sensor->set_nAzimuthLook(nlooks_az); - double n_rnglok = atof(kwl.find(prefix,"n_rnglok")); - _sensor->set_nRangeLook(n_rnglok); - - _sensor->set_prf(fa); - _sensor->set_sf(fr); - _sensor->set_rwl(wave_length); - - _sensor->set_semiMajorAxis(ellip_maj) ; - _sensor->set_semiMinorAxis(ellip_min) ; - - return true; -} - -bool ossimErsSarModel::InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix) -{ - // const double PI = 3.14159265358979323846 ; - CivilDateTime ref_civil_date; - /* - * Ephemerisis reference date retrieval - */ - const char* eph_year_str = kwl.find(prefix,"eph_year"); - int eph_year = atoi(eph_year_str); - const char* eph_month_str = kwl.find(prefix,"eph_month"); - int eph_month = atoi(eph_month_str); - const char* eph_day_str = kwl.find(prefix,"eph_day"); - int eph_day = atoi(eph_day_str); - const char* eph_sec_str = kwl.find(prefix,"eph_sec"); - double eph_sec = atof(eph_sec_str); - - ref_civil_date.set_year(eph_year); - ref_civil_date.set_month(eph_month); - ref_civil_date.set_day(eph_day); - ref_civil_date.set_second((int)eph_sec); - ref_civil_date.set_decimal( eph_sec-(double)((int)eph_sec)); - - JSDDateTime ref_jsd_date(ref_civil_date); - - /* - * Ephemerisis time interval retrieval - */ - const char* eph_int_str = kwl.find(prefix, "eph_int"); - double eph_int = atof(eph_int_str); - /* - * Ephemerisis number retrieval - */ - const char* neph_str = kwl.find(prefix,"neph"); - int neph = atoi(neph_str); - - Ephemeris** ephemeris = new Ephemeris*[neph]; - - /* - * Ephemerisis retrieval - */ - for (int i=0;i<neph;i++) - { - double pos[3]; - double vit[3]; - char name[64]; - - - sprintf(name,"eph%i_posX",i); - const char* px_str = kwl.find(prefix,name); - pos[0] = atof(px_str); - - sprintf(name,"eph%i_posY",i); - const char* py_str = kwl.find(prefix,name); - pos[1] = atof(py_str); - - sprintf(name,"eph%i_posZ",i); - const char* pz_str = kwl.find(prefix,name); - pos[2] = atof(pz_str); - - - sprintf(name,"eph%i_velX",i); - const char* vx_str = kwl.find(prefix,name); - vit[0] = atof(vx_str); - - sprintf(name,"eph%i_velY",i); - const char* vy_str = kwl.find(prefix,name); - vit[1] = atof(vy_str); - - sprintf(name,"eph%i_velZ",i); - const char* vz_str = kwl.find(prefix,name); - vit[2] = atof(vz_str); - - /* - * Ephemerisis date - */ - JSDDateTime date(ref_jsd_date); - date.set_second(date.get_second() + i * eph_int); - date.NormDate(); - - GeographicEphemeris* eph = new GeographicEphemeris(date, pos, vit); - - ephemeris[i] = eph; - } - - /* - * Antenna position interpolator creation - */ - if (_platformPosition != NULL) - { - delete _platformPosition; - } - _platformPosition = new PlatformPosition(ephemeris,neph); - - /* - * Free of memory used by the ephemerisis list - */ - for (int i=0;i<neph;i++) - { - delete ephemeris[i]; - } - delete[] ephemeris; - - return true; -} - -bool ossimErsSarModel::InitRefPoint(const ossimKeywordlist &kwl, const char *prefix) -{ - const char* sc_lin_str = kwl.find(prefix,"sc_lin"); - double sc_lin = atof(sc_lin_str); - - const char* sc_pix_str = kwl.find(prefix,"sc_pix"); - double sc_pix = atof(sc_pix_str); - - const char* inp_sctim_str = kwl.find(prefix,"inp_sctim"); - - const char* rng_gate_str = kwl.find(prefix,"zero_dop_range_time_f_pixel"); - double rng_gate = atof(rng_gate_str); - - if(_refPoint == NULL) - { - _refPoint = new RefPoint(); - } - - _refPoint->set_pix_col(sc_pix); - _refPoint->set_pix_line(sc_lin); - - char year_str[5]; - for (int i=0;i<4;i++) - { - year_str[i] = inp_sctim_str[i]; - } - year_str[4] = '\0'; - - char month_str[3]; - for (int i=4;i<6;i++) - { - month_str[i-4] = inp_sctim_str[i]; - } - month_str[2] = '\0'; - - char day_str[3]; - for (int i=6;i<8;i++) - { - day_str[i-6] = inp_sctim_str[i]; - } - day_str[2] = '\0'; - - char hour_str[3]; - for (int i=8;i<10;i++) - { - hour_str[i-8] = inp_sctim_str[i]; - } - hour_str[2] = '\0'; - - char min_str[3]; - for (int i=10;i<12;i++) - { - min_str[i-10] = inp_sctim_str[i]; - } - min_str[2] = '\0'; - - char sec_str[3]; - for (int i=12;i<14;i++) - { - sec_str[i-12] = inp_sctim_str[i]; - } - sec_str[2] = '\0'; - - char mili_str[4]; - for (int i=14;i<17;i++) - { - mili_str[i-14] = inp_sctim_str[i]; - } - mili_str[3] = '\0'; - - int year = atoi(year_str); - int month = atoi(month_str); - int day = atoi(day_str); - int hour = atoi(hour_str); - int min = atoi(min_str); - int sec = atoi(sec_str); - double mili = atof(mili_str); - - - CivilDateTime date(year, month, day, hour * 3600 + min * 60 + sec, mili/1000.0); - - if(_platformPosition != NULL) - { - Ephemeris * ephemeris = _platformPosition->Interpolate((JSDDateTime)date); - if (ephemeris == NULL) return false ; - _refPoint->set_ephemeris(ephemeris); - - delete ephemeris; - } - else - { - return false; - } - - double c = 2.99792458e+8; - - double distance = (rng_gate*1e-3 + ((double)sc_pix)*_sensor->get_nRangeLook()/_sensor->get_sf()) * (c/2.0); - - _refPoint->set_distance(distance); - - // in order to use ossimSensorModel::lineSampleToWorld - const char* nbCol_str = kwl.find(prefix,"num_pix"); - const char* nbLin_str = kwl.find(prefix,"num_lines"); - theImageSize.x = atoi(nbCol_str); - theImageSize.y = atoi(nbLin_str); - theImageClipRect = ossimDrect(0, 0, theImageSize.x-1, theImageSize.y-1); - - // Ground Control Points extracted from the model : corner points - std::list<ossimGpt> groundGcpCoordinates ; - std::list<ossimDpt> imageGcpCoordinates ; - // first line first pix - const char* lon_str = kwl.find("first_line_first_pixel_lon"); - double lon = atof(lon_str); - const char* lat_str = kwl.find("first_line_first_pixel_lat"); - double lat = atof(lat_str); - if (lon > 180.0) lon -= 360.0; - ossimDpt imageGCP1(0,0); - ossimGpt groundGCP1(lat, lon, 0.0); - groundGcpCoordinates.push_back(groundGCP1) ; - imageGcpCoordinates.push_back(imageGCP1) ; - // first line last pix - lon_str = kwl.find("first_line_last_pixel_lon"); - lon = atof(lon_str); - lat_str = kwl.find("first_line_last_pixel_lat"); - lat = atof(lat_str); - if (lon > 180.0) lon -= 360.0; - ossimDpt imageGCP2(theImageSize.x-1, 0); - ossimGpt groundGCP2(lat, lon, 0.0); - groundGcpCoordinates.push_back(groundGCP2) ; - imageGcpCoordinates.push_back(imageGCP2) ; - // last line last pix - lon_str = kwl.find("last_line_last_pixel_lon"); - lon = atof(lon_str); - lat_str = kwl.find("last_line_last_pixel_lat"); - lat = atof(lat_str); - if (lon > 180.0) lon -= 360.0; - ossimDpt imageGCP3(theImageSize.x-1,theImageSize.y-1); - ossimGpt groundGCP3(lat, lon, 0.0); - groundGcpCoordinates.push_back(groundGCP3) ; - imageGcpCoordinates.push_back(imageGCP3) ; - // last line first pix - lon_str = kwl.find("last_line_first_pixel_lon"); - lon = atof(lon_str); - lat_str = kwl.find("last_line_first_pixel_lat"); - lat = atof(lat_str); - if (lon > 180.0) lon -= 360.0; - ossimDpt imageGCP4(0,theImageSize.y-1); - ossimGpt groundGCP4(lat, lon, 0.0); - groundGcpCoordinates.push_back(groundGCP4) ; - imageGcpCoordinates.push_back(imageGCP4) ; - - // Default optimization - optimizeModel(groundGcpCoordinates, imageGcpCoordinates) ; - - return true; -} - -bool ossimErsSarModel::InitSRGR(const ossimKeywordlist &kwl, const char *prefix) -{ - // Product type = PRI - ossimString filename(kwl.find("filename")); - filename.upcase(); - //std::transform(filename.begin(), filename.end(), filename.begin(), toupper); - string::size_type loc = filename.find("PRI"); - if( loc != string::npos ) { - _isProductGeoreferenced = true; - } else { - _isProductGeoreferenced = false; - } - - // Number of SRGR Coef - _n_srgr = 3; - - // Range time for first mid and last pixel - double t1 = atof(kwl.find("zero_dop_range_time_f_pixel"))*1e-3; - double t2 = atof(kwl.find("zero_dop_range_time_c_pixel"))*1e-3; - double t3 = atof(kwl.find("zero_dop_range_time_l_pixel"))*1e-3; - - // Range pixels numbers corresponding - // Todo : check if it works with "DECREASING LINE TIME" - // double x1 = 0.0; - double x2 = atof(kwl.find("sc_pix")) - 1.0; - double x3 = 2.0*(x2+1.0) -1.0 ; - - _srgr_coefset[0][0] = t1; - _srgr_coefset[0][1] = ((t2-t1)/(x2*x2)+(t1-t3)/(x3*x3))/((1.0/x2)-(1.0/x3)); - _srgr_coefset[0][2] = ((t2-t1)/x2 + (t1-t3)/x3)/(x2-x3); - - return true; -} diff --git a/Utilities/otbossimplugins/ossim/ossimErsSarModel.h b/Utilities/otbossimplugins/ossim/ossimErsSarModel.h deleted file mode 100644 index 02e44cd2d6..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimErsSarModel.h +++ /dev/null @@ -1,78 +0,0 @@ -//---------------------------------------------------------------------------- -// -// "Copyright Centre National d'Etudes Spatiales" -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -//---------------------------------------------------------------------------- -// $Id$ - -#ifndef ossimErsSarModel_H -#define ossimErsSarModel_H - -#include <otb/JSDDateTime.h> -#include <ossimGeometricSarSensorModel.h> -#include <ossim/projection/ossimMapProjection.h> -#include <ossim/base/ossimIpt.h> -#include <ossim/base/ossimFilename.h> -#include <ossim/base/ossimGpt.h> -#include <ossim/base/ossimDpt.h> - -#include <iostream> - -class PlatformPosition; -class SensorParams; -class RefPoint; -/** - * @brief This class is able to direct localisation and indirect localisation - * using the ErsSar sensor model - */ -class ossimErsSarModel : public ossimGeometricSarSensorModel -{ -public: - /** - * @brief Constructor - */ - ossimErsSarModel(); - - /** - * @brief Destructor - */ - ~ossimErsSarModel(); - - /** - * @brief This function associates an image column number to a slant range when the image is georeferenced (ground projected) - * @param col Column coordinate of the image point - */ - virtual double getSlantRangeFromGeoreferenced(double col) const; - -protected: - /** - * @brief Slant Range for each Ground Range (SRGR) number of coefficients sets - */ - int _n_srgr; - /** - * @brief SRGR coefficient sets - */ - double _srgr_coefset[1][3]; - /** - * @brief Pixel spacing - */ - double _pixel_spacing; - -private: - virtual bool InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix); - virtual bool InitSensorParams(const ossimKeywordlist &kwl, const char *prefix); - virtual bool InitRefPoint(const ossimKeywordlist &kwl, const char *prefix); - /** - * @brief Initializes the Slant Range for each Ground Range data sets : _n_srgr,_srgr_coefset,_srgr_update,_pixel_spacing,_isProductGeoreferenced - */ - virtual bool InitSRGR(const ossimKeywordlist &kwl, const char *prefix); - - TYPE_DATA - -}; - -#endif diff --git a/Utilities/otbossimplugins/ossim/ossimPluginProjectionFactory.cpp b/Utilities/otbossimplugins/ossim/ossimPluginProjectionFactory.cpp index d6d853dde3..2c9010a683 100644 --- a/Utilities/otbossimplugins/ossim/ossimPluginProjectionFactory.cpp +++ b/Utilities/otbossimplugins/ossim/ossimPluginProjectionFactory.cpp @@ -3,9 +3,9 @@ // "Copyright Centre National d'Etudes Spatiales" // // License: LGPL -// +// // See LICENSE.txt file in the top level directory for more details. -// +// //---------------------------------------------------------------------------- // $Id$ @@ -13,17 +13,17 @@ #include "ossimPluginProjectionFactory.h" #include <ossim/base/ossimKeywordNames.h> #include <ossim/projection/ossimProjection.h> -#include "ossimRadarSatModel.h" -#include "ossimEnvisatAsarModel.h" +// #include "ossimRadarSatModel.h" +// #include "ossimEnvisatAsarModel.h" #include "ossimTerraSarModel.h" //#include <ossim/projection/ossimCosmoSkymedModel.h> -#include "ossimRadarSat2Model.h" -#include "ossimErsSarModel.h" +// #include "ossimRadarSat2Model.h" +// #include "ossimErsSarModel.h" ossimPluginProjectionFactory* ossimPluginProjectionFactory::instance() { static ossimPluginProjectionFactory* factoryInstance = new ossimPluginProjectionFactory(); - + return factoryInstance; } @@ -32,19 +32,19 @@ ossimProjection* ossimPluginProjectionFactory::createProjection(const ossimFilen { ossimProjection* result = 0; - if ( !result ) - { - ossimRadarSat2Model* model = new ossimRadarSat2Model(); - if ( model->open(filename) ) - { - result = model; - } - else - { - delete model; - model = 0; - } - } +// if ( !result ) +// { +// ossimRadarSat2Model* model = new ossimRadarSat2Model(); +// if ( model->open(filename) ) +// { +// result = model; +// } +// else +// { +// delete model; +// model = 0; +// } +// } if ( !result ) { @@ -59,7 +59,7 @@ ossimProjection* ossimPluginProjectionFactory::createProjection(const ossimFilen model = 0; } } - + return result; } @@ -82,11 +82,12 @@ ossimProjection* ossimPluginProjectionFactory::createProjection( // { // return new ossimCosmoSkymedModel; // } - if (name == STATIC_TYPE_NAME(ossimRadarSat2Model)) - { - return new ossimRadarSat2Model(); - } - else if (name == STATIC_TYPE_NAME(ossimTerraSarModel)) +// if (name == STATIC_TYPE_NAME(ossimRadarSat2Model)) +// { +// return new ossimRadarSat2Model(); +// } +// else if (name == STATIC_TYPE_NAME(ossimTerraSarModel)) + if (name == STATIC_TYPE_NAME(ossimTerraSarModel)) { return new ossimTerraSarModel(); } @@ -107,16 +108,17 @@ ossimProjection* ossimPluginProjectionFactory::createProjection( { ossimString type = lookup; - if (type == "ossimRadarSat2Model") - { - result = new ossimRadarSat2Model(); - if ( !result->loadState(kwl, prefix) ) - { - delete result; - result = 0; - } - } - else if (type == "ossimTerraSarModel") +// if (type == "ossimRadarSat2Model") +// { +// result = new ossimRadarSat2Model(); +// if ( !result->loadState(kwl, prefix) ) +// { +// delete result; +// result = 0; +// } +// } +// else if (type == "ossimTerraSarModel") + if (type == "ossimTerraSarModel") { result = new ossimTerraSarModel(); if ( !result->loadState(kwl, prefix) ) @@ -126,7 +128,7 @@ ossimProjection* ossimPluginProjectionFactory::createProjection( } } } - + return result; } @@ -145,10 +147,10 @@ ossimObject* ossimPluginProjectionFactory::createObject( void ossimPluginProjectionFactory::getTypeNameList(std::vector<ossimString>& typeList)const { - typeList.push_back(STATIC_TYPE_NAME(ossimRadarSatModel)); - typeList.push_back(STATIC_TYPE_NAME(ossimRadarSat2Model)); +// typeList.push_back(STATIC_TYPE_NAME(ossimRadarSatModel)); +// typeList.push_back(STATIC_TYPE_NAME(ossimRadarSat2Model)); typeList.push_back(STATIC_TYPE_NAME(ossimTerraSarModel)); // result.push_back(STATIC_TYPE_NAME(ossimCosmoSkymedModel)); - typeList.push_back(STATIC_TYPE_NAME(ossimEnvisatAsarModel)); - typeList.push_back(STATIC_TYPE_NAME(ossimErsSarModel)); +// typeList.push_back(STATIC_TYPE_NAME(ossimEnvisatAsarModel)); +// typeList.push_back(STATIC_TYPE_NAME(ossimErsSarModel)); } diff --git a/Utilities/otbossimplugins/ossim/ossimRadarSat2Model.cpp b/Utilities/otbossimplugins/ossim/ossimRadarSat2Model.cpp deleted file mode 100644 index cc0e4a2e0b..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimRadarSat2Model.cpp +++ /dev/null @@ -1,1259 +0,0 @@ -//---------------------------------------------------------------------------- -// -// "Copyright Centre National d'Etudes Spatiales" -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -//---------------------------------------------------------------------------- -// $Id$ - -#include <cmath> - -#include <ossimRadarSat2Model.h> -#include <ossimPluginCommon.h> -#include <ossimRadarSat2ProductDoc.h> -#include <ossim/base/ossimCommon.h> -#include <ossim/base/ossimFilename.h> -#include <ossim/base/ossimKeywordNames.h> -#include <ossim/base/ossimNotify.h> -#include <ossim/base/ossimRefPtr.h> -#include <ossim/base/ossimString.h> -#include <ossim/base/ossimTrace.h> -#include <ossim/base/ossimXmlDocument.h> -#include <ossim/base/ossimXmlNode.h> - -#include <otb/GalileanEphemeris.h> -#include <otb/GeographicEphemeris.h> -#include <otb/GMSTDateTime.h> - -#include <otb/PlatformPosition.h> -#include <otb/SensorParams.h> -#include <otb/RefPoint.h> -#include <otb/SarSensor.h> - -// Keyword constants: -static const char NUMBER_SRGR_COEFFICIENTS_KW[] = "sr_gr_coeffs_count"; -static const char LOAD_FROM_PRODUCT_FILE_KW[] = "load_from_product_file_flag"; -static const char PRODUCT_XML_FILE_KW[] = "product_xml_filename"; - -// Static trace for debugging -static ossimTrace traceDebug("ossimRadarSat2Model:debug"); - - - - -RTTI_DEF1(ossimRadarSat2Model, "ossimRadarSat2Model", ossimGeometricSarSensorModel); - - -ossimRadarSat2Model::ossimRadarSat2Model() - : - ossimGeometricSarSensorModel(), - _n_srgr(0), - _srgr_update(), - _SrGr_R0(), - theProductXmlFile(ossimFilename::NIL) -{ -} - -ossimRadarSat2Model::ossimRadarSat2Model(const ossimRadarSat2Model& rhs) - : - ossimGeometricSarSensorModel(rhs), - _n_srgr(rhs._n_srgr), - _srgr_update(rhs._srgr_update), - _SrGr_R0(rhs._SrGr_R0), - theProductXmlFile(rhs.theProductXmlFile) -{ -} - -ossimRadarSat2Model::~ossimRadarSat2Model() -{ -} - -ossimString ossimRadarSat2Model::getClassName() const -{ - return ossimString("ossimRadarSat2Model"); -} - -ossimObject* ossimRadarSat2Model::dup() const -{ - return new ossimRadarSat2Model(*this); -} - -double ossimRadarSat2Model::getSlantRangeFromGeoreferenced(double col) const -{ - if (_n_srgr==0) return(-1) ; - - double relativeGroundRange, slantRange = 0.0 ; - - // in the case of Georeferenced images, _refPoint->get_distance() - // contains the ground range - relativeGroundRange = _refPoint->get_distance() + _sensor->get_col_direction() * (col-_refPoint->get_pix_col())* theGSD.x; - - int numSet = FindSRGRSetNumber((_refPoint->get_ephemeris())->get_date()) ; - /** - * @todo : could be improved (date choice) - */ - - for (int i=0 ; i<static_cast<int>(_SrGr_coeffs[numSet].size()); i++) - { - slantRange += _SrGr_coeffs[numSet][i]*pow(relativeGroundRange,i) ; - } - - return slantRange ; -} - -bool ossimRadarSat2Model::open(const ossimFilename& file) -{ - static const char MODULE[] = "ossimRadarSat2Model::open"; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n"; - } - - bool result = false; - - // Get the xml file. - ossimFilename xmlFile; - - if (file.ext().downcase() == "xml") - { - xmlFile = file; - } - else if (file.isFile()) - { - xmlFile = file.expand().path().dirCat("product.xml"); - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "product xml file: " << xmlFile << "\n"; - } - - if ( xmlFile.exists() ) - { - //--- - // Instantiate the XML parser: - //--- - ossimXmlDocument* xdoc = new ossimXmlDocument(); - if ( xdoc->openFile(xmlFile) ) - { - ossimRadarSat2ProductDoc rsDoc; - - result = rsDoc.isRadarSat2(xdoc); - - if (result) - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "isRadarSat2...\n"; - } - - // Set the base class number of lines and samples - result = rsDoc.initImageSize(xdoc, theImageSize); - - if (result) - { - // Set the base class clip rect. - theImageClipRect = ossimDrect( - 0, 0, - theImageSize.x-1, theImageSize.y-1); - } - - // Set the sub image offset. tmp hard coded (drb). - theSubImageOffset.x = 0.0; - theSubImageOffset.y = 0.0; - - // Set the image id. - if (result) - { - result = rsDoc.getImageId(xdoc, theImageID); - } - - // Set the sensor ID. - if (result) - { - result = rsDoc.getSatellite(xdoc, theSensorID); - } - - // Set the base class gsd: - result = rsDoc.initGsd(xdoc, theGSD); - if (result) - { - theMeanGSD = (theGSD.x + theGSD.y)/2.0; - } - - if (result) - { - result = initSRGR(xdoc, rsDoc); - - if (result) - { - result = initPlatformPosition(xdoc, rsDoc); - - if (result) - { - result = initSensorParams(xdoc, rsDoc); - - if (result) - { - result = initRefPoint(xdoc, rsDoc); - } - } - } - } - } - - } // matches: if ( xdoc->openFile(xmlFile) ) - - delete xdoc; - xdoc = 0; - - } // matches: if ( xmlFile.exists() ) - - if (result) - { - theProductXmlFile = xmlFile; - } - else - { - theProductXmlFile = ossimFilename::NIL; - } - - if (result) - { - theProductXmlFile = xmlFile; - } - else - { - theProductXmlFile = ossimFilename::NIL; - } - - if (result) - { - // Assign the ossimSensorModel::theBoundGndPolygon - ossimGpt ul; - ossimGpt ur; - ossimGpt lr; - ossimGpt ll; - lineSampleToWorld(theImageClipRect.ul(), ul); - lineSampleToWorld(theImageClipRect.ur(), ur); - lineSampleToWorld(theImageClipRect.lr(), lr); - lineSampleToWorld(theImageClipRect.ll(), ll); - setGroundRect(ul, ur, lr, ll); // ossimSensorModel method. - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " exit status = " << (result?"true":"false\n") - << std::endl; - } - - return result; -} - -std::ostream& ossimRadarSat2Model::print(std::ostream& out) const -{ - // Capture the original flags. - std::ios_base::fmtflags f = out.flags(); - - out << setprecision(15) << setiosflags(ios::fixed) - << "\nossimRadarSat2Model class data members:\n" - << "_n_srgr: " << _n_srgr << "\n"; - - ossim_uint32 idx = 0; - std::vector<double>::const_iterator i = _srgr_update.begin(); - while ( i != _srgr_update.end() ) - { - out << "sr_gr_update_" << idx << ": " << (*i) << "\n"; - ++i; - ++idx; - } - - idx = 0; - i = _SrGr_R0.begin(); - while ( i != _SrGr_R0.end() ) - { - out << "sr_gr_r0_" << idx << ": " << (*i) << "\n"; - ++i; - ++idx; - } - - idx = 0; - std::vector< std::vector<double> >::const_iterator i2 = - _SrGr_coeffs.begin(); - while ( i2 != _SrGr_coeffs.end() ) - { - ossim_uint32 idx2 = 0; - i = (*i2).begin(); - while ( i != (*i2).end() ) - { - out << "sr_gr_coeffs_" << idx << "_" << idx2 << ": " << (*i) << "\n"; - ++i; - ++idx2; - } - ++i2; - ++idx; - } - - ossimGeometricSarSensorModel::print(out); - - // Reset flags. - out.setf(f); - - return out; -} - -bool ossimRadarSat2Model::InitSensorParams(const ossimKeywordlist &kwl, - const char *prefix) -{ - - // sensor frequencies - const char* central_freq_str = kwl.find(prefix,"central_freq"); - double central_freq = atof(central_freq_str); - const char* fr_str = kwl.find(prefix,"fr"); - double fr = atof(fr_str); - const char* fa_str = kwl.find(prefix,"fa"); - double fa = atof(fa_str); - - //number of different looks - const char* n_azilok_str = kwl.find(prefix,"n_azilok"); - double n_azilok = atof(n_azilok_str); - const char* n_rnglok_str = kwl.find(prefix,"n_rnglok"); - double n_rnglok = atof(n_rnglok_str); - - //ellipsoid parameters - const char* ellip_maj_str = kwl.find(prefix,"ellip_maj"); - double ellip_maj = atof(ellip_maj_str) * 1000.0; // km -> m - const char* ellip_min_str = kwl.find(prefix,"ellip_min"); - double ellip_min = atof(ellip_min_str) * 1000.0; // km -> m - - if(_sensor != 0) - { - delete _sensor; - } - - _sensor = new SensorParams(); - - const char* lineTimeOrdering_str = kwl.find(prefix,"lineTimeOrdering"); - std::string lineTimeOrdering(lineTimeOrdering_str) ; - const char* pixelTimeOrdering_str = kwl.find(prefix,"pixelTimeOrdering"); - std::string pixelTimeOrdering(pixelTimeOrdering_str) ; - if (pixelTimeOrdering == "Increasing") _sensor->set_col_direction(1); - else _sensor->set_col_direction(- 1); - if (lineTimeOrdering == "Increasing") _sensor->set_lin_direction(1); - else _sensor->set_lin_direction(- 1); - - const char* lookDirection_str = kwl.find(prefix,"lookDirection"); - std::string lookDirection(lookDirection_str) ; - if ((lookDirection == "Right")||(lookDirection == "RIGHT")) _sensor->set_sightDirection(SensorParams::Right) ; - else _sensor->set_sightDirection(SensorParams::Left) ; - - _sensor->set_sf(fr); - const double CLUM = 2.99792458e+8 ; - double wave_length = CLUM / central_freq ; - _sensor->set_rwl(wave_length); - _sensor->set_nAzimuthLook(n_azilok); - _sensor->set_nRangeLook(n_rnglok); - - // fa is the processing PRF - _sensor->set_prf(fa * n_azilok); - - _sensor->set_semiMajorAxis(ellip_maj) ; - _sensor->set_semiMinorAxis(ellip_min) ; - - return true; -} - -bool ossimRadarSat2Model::InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix) -{ - /* - * Retrieval of ephemerisis number - */ - const char* neph_str = kwl.find(prefix,"neph"); - int neph = atoi(neph_str); - - Ephemeris** ephemeris = new Ephemeris*[neph]; - - /* - * Retrieval of ephemerisis - */ - for (int i=0;i<neph;i++) - { - double pos[3]; - double vit[3]; - char name[64]; - - - sprintf(name,"eph%i_date",i); - const char* date_str = kwl.find(prefix,name); - - sprintf(name,"eph%i_posX",i); - const char* px_str = kwl.find(prefix,name); - pos[0] = atof(px_str); - - sprintf(name,"eph%i_posY",i); - const char* py_str = kwl.find(prefix,name); - pos[1] = atof(py_str); - - sprintf(name,"eph%i_posZ",i); - const char* pz_str = kwl.find(prefix,name); - pos[2] = atof(pz_str); - - - sprintf(name,"eph%i_velX",i); - const char* vx_str = kwl.find(prefix,name); - vit[0] = atof(vx_str) ; - - sprintf(name,"eph%i_velY",i); - const char* vy_str = kwl.find(prefix,name); - vit[1] = atof(vy_str) ; - - sprintf(name,"eph%i_velZ",i); - const char* vz_str = kwl.find(prefix,name); - vit[2] = atof(vz_str) ; - - /* - * Conversion to JSD Date - */ - std::string utcString(date_str); - CivilDateTime eph_civil_date; - - - if (! ossim::iso8601TimeStringToCivilDate(utcString, eph_civil_date)) return false; - - JSDDateTime eph_jsd_date(eph_civil_date); - - GeographicEphemeris* eph = new GeographicEphemeris(eph_jsd_date,pos,vit); - - ephemeris[i] = eph; - } - - /* - * Creation of the platform position interpolator - */ - if (_platformPosition != 0) - { - delete _platformPosition; - } - _platformPosition = new PlatformPosition(ephemeris,neph); - - /* - * Free of memory used by ephemerisis list : the constructor copies the ephemerisis - */ - for (int i=0;i<neph;i++) - { - delete ephemeris[i]; - } - delete[] ephemeris; - - return true; -} - -bool ossimRadarSat2Model::InitRefPoint(const ossimKeywordlist &kwl, - const char *prefix) -{ - // in order to use ossimSensorModel::lineSampleToWorld - const char* nbCol_str = kwl.find(prefix,"nbCol"); - const char* nbLin_str = kwl.find(prefix,"nbLin"); - theImageSize.x = atoi(nbCol_str); - theImageSize.y = atoi(nbLin_str); - theImageClipRect = ossimDrect(0, 0, theImageSize.x-1, theImageSize.y-1); - - // no reference point (e.g. scene center) is given in the annotation file - // we choose to use the upper left corner as reference point - if(_refPoint == 0) - { - _refPoint = new RefPoint(); - } - - _refPoint->set_pix_col(0); // upper left corner - _refPoint->set_pix_line(0); // upper left corner - - const char* zeroDopplerTimeFirstLine_str = kwl.find(prefix,"zeroDopplerTimeFirstLine"); - std::string zeroDopplerTimeFirstLine(zeroDopplerTimeFirstLine_str); - - CivilDateTime * date = new CivilDateTime() ; - if (! ossim::iso8601TimeStringToCivilDate(zeroDopplerTimeFirstLine, *date)) return false ; - - if (_sensor->get_lin_direction() == -1) { - double time = (double) date->get_second() + date->get_decimal() ; // upper left corner - time += theImageSize.y / _sensor->get_prf() ; - date->set_second((int) floor(time)) ; - date->set_decimal(time - floor(time)) ; - } - - if(_platformPosition != 0) - { - Ephemeris * ephemeris = _platformPosition->Interpolate((JSDDateTime)*date); - if (ephemeris == 0) return false ; - _refPoint->set_ephemeris(ephemeris); - - delete ephemeris; - } - else - { - return false; - } - - const char* slantRangeNearEdge_str = kwl.find(prefix,"slantRangeNearEdge"); - double distance = atof(slantRangeNearEdge_str); - - //--- - // NOTE: initSRGR method must be called before this method. - // in the case of Georeferenced images, the ground range is stored in - // place of the slant range - // (used for SlantRange computation relative to reference point, necessary - // for optimization) - //--- - if (_isProductGeoreferenced) - { - if (_sensor->get_col_direction() == 1) - { - distance += 0.0; // upper left corner - } - else - { - distance += theImageSize.x * theGSD.x; - } - } - - _refPoint->set_distance(distance); - - // Ground Control Points extracted from the model - std::list<ossimGpt> groundGcpCoordinates ; - std::list<ossimDpt> imageGcpCoordinates ; - const char* nTiePoints_str = kwl.find(prefix,"nTiePoints"); - int nTiePoints = atoi(nTiePoints_str); - char name[64]; - for (int k=0 ; k<nTiePoints ; k++) { - sprintf(name,"cornersCol%i",k); - const char* i_str = kwl.find(name); - int i = atoi(i_str); - sprintf(name,"cornersLin%i",k); - const char* j_str = kwl.find(name); - int j = atoi(j_str); - sprintf(name,"cornersLon%i",k); - const char* lon_str = kwl.find(name); - double lon = atof(lon_str); - sprintf(name,"cornersLat%i",k); - const char* lat_str = kwl.find(name); - double lat = atof(lat_str); - sprintf(name,"cornersHeight%i",k); - const char* height_str = kwl.find(name); - double height = atof(height_str); - - ossimDpt imageGCP(i,j); - ossimGpt groundGCP(lat ,lon , height); - groundGcpCoordinates.push_back(groundGCP) ; - imageGcpCoordinates.push_back(imageGCP) ; - } - - // Default optimization - optimizeModel(groundGcpCoordinates, imageGcpCoordinates) ; - - return true; -} - -bool ossimRadarSat2Model::InitSRGR(const ossimKeywordlist &kwl, - const char *prefix) -{ - const char* productType_str = kwl.find(prefix,"productType"); - ossimString productType(productType_str); - - _isProductGeoreferenced = (productType != "SLC") ; - -// // Pixel spacing -// const char* pixel_spacing_str = kwl.find(prefix,"pixel_spacing_mean"); -// _pixel_spacing = atof(pixel_spacing_str); - -// // Number of columns -// const char* nbCol_str = kwl.find(prefix,"nbCol"); -// _nbCol = atoi(nbCol_str); - - // number of SRGR coefficient sets - const char* SrGr_coeffs_number_str = kwl.find(prefix,"SrGr_coeffs_number"); - _n_srgr = atoi(SrGr_coeffs_number_str); - - // SRGR coefficients and exponents - char name[64]; - for(int i=0;i<_n_srgr;i++) - { - std::vector<double> srgr_set ; - for(int j=0;j<4;j++) - { - sprintf(name,"SrGr_coeffs_%i_%i",i,j); - const char* coeff_str = kwl.find(prefix,name); - double coeff = atof(coeff_str); - srgr_set.push_back(coeff); - } - _SrGr_coeffs.push_back(srgr_set); - // SRGR polynomial reference - sprintf(name,"SrGr_R0_%i",i); - const char* SrGr_R0_str = kwl.find(prefix,name); - _SrGr_R0.push_back(atof(SrGr_R0_str)); - // SRGR update time - sprintf(name,"SrGr_update_%i",i); - const char* SrGr_update_str = kwl.find(prefix,name); - CivilDateTime SrGr_update_date ; - ossim::iso8601TimeStringToCivilDate(std::string(SrGr_update_str), SrGr_update_date) ; - _srgr_update.push_back((double) SrGr_update_date.get_second()+ SrGr_update_date.get_decimal()); - } - - return true; -} - -int ossimRadarSat2Model::FindSRGRSetNumber(JSDDateTime date) const -{ - if (_n_srgr==0) return(-1) ; - - double delays[20]; - for (int i=0;i<_n_srgr;i++) - { - delays[i] = fabs(date.get_second()+date.get_decimal()-_srgr_update[i]) ; - } - - int setNumber = 0 ; - double min_delay = delays[0] ; - for (int i=1;i<_n_srgr;i++) - { - if (delays[i]<min_delay) { - setNumber = i ; - min_delay = delays[i] ; - } - } - return setNumber ; -} - -bool ossimRadarSat2Model::initSRGR(const ossimXmlDocument* xdoc, - const ossimRadarSat2ProductDoc& rsDoc) -{ - static const char MODULE[] = "ossimRadarSat2Model::initSRGR"; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n"; - } - - bool result = true; - - ossimString s; - - // Get the product type. - if ( rsDoc.getProductType(xdoc, s) ) - { - _isProductGeoreferenced = (s != "SLC"); - } - else - { - result = false; - } - - ossimString path = - "/product/imageGenerationParameters/slantRangeToGroundRange"; - std::vector<ossimRefPtr<ossimXmlNode> > xnodes; - xdoc->findNodes(path, xnodes); - if ( xnodes.size() ) - { - //--- - // Set the number of slant range for each ground range (srgs) - // coefficients. - //--- - _n_srgr = static_cast<int>(xnodes.size()); - - for (ossim_uint32 i = 0; i < xnodes.size(); ++i) - { - if (xnodes[i].valid()) - { - ossimRefPtr<ossimXmlNode> node = 0; - node = xnodes[i]->findFirstNode( - ossimString("zeroDopplerAzimuthTime")); - if (node.valid()) - { - CivilDateTime date; - ossim::iso8601TimeStringToCivilDate(node->getText(), date); - _srgr_update.push_back((double) date.get_second()+ - date.get_decimal()); - } - - node = xnodes[i]->findFirstNode( - ossimString("groundRangeOrigin")); - if (node.valid()) - { - _SrGr_R0.push_back(node->getText().toDouble()); - } - - node = xnodes[i]->findFirstNode( - ossimString("groundToSlantRangeCoefficients")); - if (node.valid()) - { - std::vector<ossimString> vs; - node->getText().split(vs, ' '); - std::vector<double> vd; - for (ossim_uint32 idx = 0; idx < vs.size(); ++idx) - { - vd.push_back(vs[idx].toDouble()); - } - _SrGr_coeffs.push_back(vd); - } - } - } - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " exit status = " << (result?"true":"false\n") - << std::endl; - } - - return result; -} - -bool ossimRadarSat2Model::initPlatformPosition( - const ossimXmlDocument* xdoc, const ossimRadarSat2ProductDoc& rsDoc) -{ - static const char MODULE[] = "ossimRadarSat2Model::initPlatformPosition"; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n"; - } - - // Initialize the platform position interpolator. - if (_platformPosition) - { - delete _platformPosition; - } - - _platformPosition = new PlatformPosition(); - - bool result = rsDoc.initPlatformPosition(xdoc, _platformPosition); - - if (!result) - { - delete _platformPosition; - _platformPosition = 0; - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " exit status = " << (result?"true":"false\n") - << std::endl; - } - - return result; -} - -bool ossimRadarSat2Model::initSensorParams( - const ossimXmlDocument* xdoc, const ossimRadarSat2ProductDoc& rsDoc) -{ - static const char MODULE[] = "ossimRadarSat2Model::initSensorParams"; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n"; - } - - if (_sensor ) - { - delete _sensor; - } - _sensor = new SensorParams(); - - bool result = rsDoc.initSensorParams(xdoc, _sensor); - - if (!result) - { - delete _sensor; - _sensor = 0; - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " exit status = " << (result?"true":"false\n") - << std::endl; - } - - return result; -} - -bool ossimRadarSat2Model::initRefPoint(const ossimXmlDocument* xdoc, - const ossimRadarSat2ProductDoc& rsDoc) -{ - static const char MODULE[] = "ossimRadarSat2Model::initRefPoint"; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n"; - } - - if ( !_sensor || !_platformPosition ) - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << "null pointer error! exiting\n"; - } - return false; - } - - // Reference point. - if (_refPoint) - { - delete _refPoint; - } - _refPoint = new RefPoint(); - - // Ground Control Points extracted from the model. - std::list<ossimGpt> groundGcpCoordinates; - std::list<ossimDpt> imageGcpCoordinates; - if ( rsDoc.initTiePoints(xdoc, - groundGcpCoordinates, - imageGcpCoordinates) == false ) - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << "initTiePoint error! exiting\n"; - } - return false; - } - - if ( setModelRefPoint(groundGcpCoordinates, imageGcpCoordinates) ) - { - _refPoint->set_pix_col(theRefImgPt.x); - _refPoint->set_pix_line(theRefImgPt.y); - } - else - { - // no reference point (e.g. scene center) is given in the annotation file - // we choose to use the upper left corner as reference point - _refPoint->set_pix_col(0); // upper left corner - _refPoint->set_pix_line(0); // upper left corner - } - - ossimString s; - CivilDateTime date; - if ( rsDoc.getZeroDopplerTimeFirstLine(xdoc, s) ) - { - if (! ossim::iso8601TimeStringToCivilDate(s, date)) - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << "getZeroDopplerTimeFirstLine error! exiting\n"; - } - return false; - } - } - - if (_sensor->get_lin_direction() == -1) - { - // upper left corner - double time = (double) date.get_second() + date.get_decimal(); - time += theImageSize.y / _sensor->get_prf() ; - date.set_second((int) floor(time)) ; - date.set_decimal(time - floor(time)) ; - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "date:\n" - << date - << "\n"; - } - - JSDDateTime jsdate(date); - - // Ephemeris * ephemeris = _platformPosition->Interpolate((JSDDateTime)date); - Ephemeris * ephemeris = _platformPosition->Interpolate(jsdate); - if (ephemeris == 0) - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " Interpolate error! exiting\n"; - } - return false; - } - _refPoint->set_ephemeris(ephemeris); - delete ephemeris; - ephemeris = 0; - - if ( !rsDoc.getSlantRangeNearEdge(xdoc, s) ) - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << "getSlantRangeNearEdge error! exiting\n"; - } - return false; - } - double distance = s.toDouble(); - - //--- - // in the case of Georeferenced images, the ground range is stored in - // place of the slant range - // (used for SlantRange computation relative to reference point, - // necessary for optimization) - //--- - if (_isProductGeoreferenced) - { - if (_sensor->get_col_direction() == 1) - { - distance += 0 ; // upper left corner - } - else - { - distance += theImageSize.x * theGSD.x; - } - } - - _refPoint->set_distance(distance); - - // Default optimization - optimizeModel(groundGcpCoordinates, imageGcpCoordinates) ; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " exit status = true\n"; - } - - return true; -} - -bool ossimRadarSat2Model::saveState(ossimKeywordlist& kwl, - const char* prefix) const -{ - static const char MODULE[] = "ossimRadarSat2Model::saveState"; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n"; - } - - bool result = true; - - // Save our state: - kwl.add(prefix, PRODUCT_XML_FILE_KW, theProductXmlFile.c_str()); - kwl.add(prefix, NUMBER_SRGR_COEFFICIENTS_KW, _n_srgr); - - // Make sure all the arrays are equal in size. - const ossim_uint32 COUNT = static_cast<ossim_uint32>(_n_srgr); - - if ( (_srgr_update.size() == COUNT) && - (_SrGr_R0.size() == COUNT) && - (_SrGr_coeffs.size() == COUNT) ) - { - ossimString kw1 = "sr_gr_update_"; - ossimString kw2 = "sr_gr_r0_"; - ossimString kw3 = "sr_gr_coeffs_"; - - for(ossim_uint32 i = 0; i < COUNT; ++i) - { - ossimString iStr = ossimString::toString(i); - - ossimString kw = kw1; - kw += iStr; - kwl.add(prefix, kw, _srgr_update[i]); - - kw = kw2; - kw += iStr; - kwl.add(prefix, kw, _SrGr_R0[i]); - - for (ossim_uint32 j = 0; j < _SrGr_coeffs[i].size(); ++j) - { - ossimString jStr = ossimString::toString(j); - kw = kw3; - kw += iStr; - kw += "_"; - kw += jStr; - kwl.add(prefix, kw,_SrGr_coeffs[i][j]); - } - } - } - else - { - result = false; - } - - if (result) - { - // Call base save state: - result = ossimGeometricSarSensorModel::saveState(kwl, prefix); - } - - //--- - // Uncomment to force load from product file instead of loadState. - //--- - //if (result) - //{ - // kwl.add(prefix, LOAD_FROM_PRODUCT_FILE_KW, "true"); - //} - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " exit status = " << (result?"true":"false\n") - << std::endl; - } - - return result; -} - -bool ossimRadarSat2Model::loadState (const ossimKeywordlist &kwl, - const char *prefix) -{ - static const char MODULE[] = "ossimRadarSat2Model::loadState"; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n"; - } - - const char* lookup = 0; - ossimString s; - - // Check the type first. - lookup = kwl.find(prefix, ossimKeywordNames::TYPE_KW); - if (lookup) - { - s = lookup; - if (s != getClassName()) - { - return false; - } - } - - // Get the product.xml file name. - lookup = kwl.find(prefix, PRODUCT_XML_FILE_KW); - if (lookup) - { - theProductXmlFile = lookup; - - // See if caller wants to load from xml vice keyword list. - lookup = kwl.find(prefix, LOAD_FROM_PRODUCT_FILE_KW); - if (lookup) - { - s = lookup; - if ( s.toBool() ) - { - // Loading from product.xml file. - return open(theProductXmlFile); - } - } - } - - // Load the base class. - bool result = ossimGeometricSarSensorModel::loadState(kwl, prefix); - - //--- - // Temp: This must be cleared or you end up with a bounding rect of all - // zero's. - //--- - theBoundGndPolygon.clear(); - - if (result) - { - lookup = kwl.find(prefix, NUMBER_SRGR_COEFFICIENTS_KW); - if (lookup) - { - s = lookup; - _n_srgr = s.toInt(); - } - else - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_WARN) - << MODULE - << "\nRequired keyword not found: " - << NUMBER_SRGR_COEFFICIENTS_KW << "\n"; - } - result = false; - } - - if (result && _n_srgr) - { - const ossim_uint32 COUNT = static_cast<ossim_uint32>(_n_srgr); - - _srgr_update.resize(COUNT); - _SrGr_R0.resize(COUNT); - _SrGr_coeffs.resize(COUNT); - - ossimString kw1 = "sr_gr_update_"; - ossimString kw2 = "sr_gr_r0_"; - ossimString kw3 = "sr_gr_coeffs_"; - - for(ossim_uint32 i = 0; i < COUNT; ++i) - { - ossimString kw; - ossimString iStr = ossimString::toString(i); - - // Get the _srgr_update's. - kw = kw1; - kw += iStr; - - lookup = kwl.find(prefix, kw); - if (lookup) - { - s = lookup; - _srgr_update[i] = s.toDouble(); - } - else - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_WARN) - << MODULE - << "\nRequired keyword not found: " - << kw << "\n"; - } - result = false; - } - - // Get the sr_gr_r0_'s. - kw = kw2; - kw += iStr; - lookup = kwl.find(prefix, kw); - if (lookup) - { - s = lookup; - _SrGr_R0[i] = s.toDouble(); - } - else - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_WARN) - << MODULE - << "\nRequired keyword not found: " - << kw << "\n"; - } - result = false; - } - - //--- - // Get the _SrGr_coeffs. - // Note we are assuming a count of 6. - //--- - const ossim_uint32 COEFFS_COUNT = 6; - _SrGr_coeffs[i].resize(COEFFS_COUNT); - - for (ossim_uint32 j = 0; j < COEFFS_COUNT; ++j) - { - ossimString jStr = ossimString::toString(j); - kw = kw3; - kw += iStr; - kw += "_"; - kw += jStr; - lookup = kwl.find(prefix, kw); - if (lookup) - { - s = lookup; - _SrGr_coeffs[i][j] = s.toDouble(); - } - else - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_WARN) - << MODULE - << "\nRequired keyword not found: " - << kw << "\n"; - } - result = false; - } - } - - } // matches: for(ossim_uint32 i = 0; i < COUNT; ++i) - - } // matches: if (_n_srgr) - else - { - result = false; - } - - } // matches: if (result) - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " exit status = " << (result?"true":"false\n") - << std::endl; - } - - return result; -} - -bool ossimRadarSat2Model::setModelRefPoint( - const std::list<ossimGpt>& groundGcpCoordinates, - const std::list<ossimDpt>& imageGcpCoordinates) -{ - static const char MODULE[] = "ossimRadarSat2Model::setModelRefPoint"; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n"; - } - - bool result = false; - - if ( !theImageSize.hasNans() && - (groundGcpCoordinates.size() == imageGcpCoordinates.size()) ) - { - const ossim_float64 THRESHOLD = 1.0; - ossimDpt center; - center.x = theImageSize.x / 2.0; - center.y = theImageSize.y / 2.0; - std::list<ossimGpt>::const_iterator gi = groundGcpCoordinates.begin(); - std::list<ossimDpt>::const_iterator di = imageGcpCoordinates.begin(); - - while( gi != groundGcpCoordinates.end() ) - { - // Find the image point within one pixel of center. - ossim_float64 deltaX = std::fabs( (*di).x - center.x); - ossim_float64 deltaY = std::fabs( (*di).y - center.y); - - if ( (deltaX <= THRESHOLD) && (deltaY <= THRESHOLD) ) - { - theRefImgPt = (*di); - theRefGndPt = (*gi); - result = true; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "image reference point: " << theRefImgPt - << "\nground reference point: " << theRefGndPt - << "\n"; - } - - break; - } - - ++gi; - ++di; - - } // matches: while( gi != groundGcpCoordinates.end() ) - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " exit status = " << (result?"true":"false\n") - << std::endl; - } - - return result; -} diff --git a/Utilities/otbossimplugins/ossim/ossimRadarSat2Model.h b/Utilities/otbossimplugins/ossim/ossimRadarSat2Model.h deleted file mode 100644 index 9c8c714631..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimRadarSat2Model.h +++ /dev/null @@ -1,181 +0,0 @@ -//---------------------------------------------------------------------------- -// -// "Copyright Centre National d'Etudes Spatiales" -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -//---------------------------------------------------------------------------- -// $Id$ - -#ifndef ossimRadarSat2Model_H -#define ossimRadarSat2Model_H - -#include <ossimGeometricSarSensorModel.h> -#include <ossim/projection/ossimMapProjection.h> -#include <ossim/base/ossimIpt.h> -#include <ossim/base/ossimFilename.h> -#include <ossim/base/ossimGpt.h> -#include <ossim/base/ossimDpt.h> -#include <iostream> -#include <list> - -#include <otb/CivilDateTime.h> - -class ossimFilename; -class ossimRadarSat2ProductDoc; -class ossimString; -class ossimXmlDocument; -class PlatformPosition; -class SensorParams; -class RefPoint; - -/** - * @brief This class allows for direct localisation and indirect localisation - * using the RadarSat2 sensor model - */ -class ossimRadarSat2Model : public ossimGeometricSarSensorModel -{ -public: - /** @brief default constructor */ - ossimRadarSat2Model(); - - /** @brief copy constructor */ - ossimRadarSat2Model(const ossimRadarSat2Model& rhs); - - /** @brief Destructor */ - virtual ~ossimRadarSat2Model(); - - /** - * @brief Method to return the class name. - * @return The name of this class. - */ - virtual ossimString getClassName() const; - - /** - * @brief Returns pointer to a new instance, copy of this. - */ - virtual ossimObject* dup() const; - - /** - * @brief This function associates an image column number to a slant range - * when the image is georeferenced (ground projected) - * @param col Column coordinate of the image point - */ - virtual double getSlantRangeFromGeoreferenced(double col) const; - - /** - * @brief Method to intantial model from a file. Attempts to find the - * required xml file. - * - * @param file - * - * @return true on success, false on error. - */ - bool open(const ossimFilename& file); - - /** - * @brief Method to save object state to a keyword list. - * @param kwl Keyword list to save to. - * @param prefix added to keys when saved. - * @return true on success, false on error. - */ - virtual bool saveState(ossimKeywordlist& kwl, - const char* prefix=0) const; - - /** - * @brief Method to the load (recreate) the state of the object from a - * keyword list. Return true if ok or false on error. - * @return true if load OK, false on error - */ - virtual bool loadState (const ossimKeywordlist &kwl, const char *prefix=0); - - /*! - * METHOD: print() - * Fulfills base-class pure virtual. Dumps contents of object to ostream. - */ - virtual std::ostream& print(std::ostream& out) const; - -private: - - virtual bool InitPlatformPosition(const ossimKeywordlist &kwl, - const char *prefix); - - virtual bool InitSensorParams(const ossimKeywordlist &kwl, - const char *prefix); - - virtual bool InitRefPoint(const ossimKeywordlist &kwl, - const char *prefix); - - /** - * @brief Initializes the Slant Range to Ground Range data sets : - * _srgr_update,_SrGr_R0,_SrGr_coeffs_number,_SrGr_coeffs,_nbCol, - * _pixel_spacing - */ - virtual bool InitSRGR(const ossimKeywordlist &kwl, const char *prefix); - - /** - * @brief Finds the SRGR data set which update time is the closest - * to the center scene time - */ - int FindSRGRSetNumber(JSDDateTime date) const; - - /** - * @note This method must be called before initRefPoint. - */ - bool initSRGR(const ossimXmlDocument* xdoc, - const ossimRadarSat2ProductDoc& rsDoc); - - bool initPlatformPosition(const ossimXmlDocument* xdoc, - const ossimRadarSat2ProductDoc& rsDoc); - - bool initSensorParams(const ossimXmlDocument* xdoc, - const ossimRadarSat2ProductDoc& rsDoc); - - /** - * @brief Method to initialize RefPoint object from - * RadarSat "product.xml" file. - * @param xdoc Opened product.xml file. - * @return true on success, false on error. - */ - bool initRefPoint(const ossimXmlDocument* xdoc, - const ossimRadarSat2ProductDoc& rsDoc); - - /** - * @brief Sets ossimSensorModel members theRefImgPt and theRefGndPt from - * tie points. - * @param groundGcpCoordinates Ground tie points. - * @param imageGcpCoordinates Image tie points. - * @return true on success, false on error. - */ - bool setModelRefPoint(const std::list<ossimGpt>& groundGcpCoordinates, - const std::list<ossimDpt>& imageGcpCoordinates); - - /** - * @brief Slant Range FOR EACH Ground Range (SRGR) number of coefficients - * sets - */ - int _n_srgr; - - /** - * @brief Slant Range FOR EACH Ground Range coefficient sets update times - */ - - std::vector<double> _srgr_update; - /** - * @brief Slant Range FOR EACH Ground Range Projection reference point - */ - std::vector<double> _SrGr_R0 ; - - /** - * @brief Slant Range FOR EACH Ground Range Projection coefficients - */ - std::vector< std::vector<double> > _SrGr_coeffs ; - - ossimFilename theProductXmlFile; - -TYPE_DATA - -}; -#endif diff --git a/Utilities/otbossimplugins/ossim/ossimRadarSat2ProductDoc.cpp b/Utilities/otbossimplugins/ossim/ossimRadarSat2ProductDoc.cpp deleted file mode 100644 index 91b729788b..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimRadarSat2ProductDoc.cpp +++ /dev/null @@ -1,844 +0,0 @@ -//---------------------------------------------------------------------------- -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -// Author: David Burken -// -// Description: Utility class to encapsulate parsing RadarSat2 product.xml -// file. -// -//---------------------------------------------------------------------------- -// $Id$ - -#include <ossimRadarSat2ProductDoc.h> -#include <ossimPluginCommon.h> -#include <otb/CivilDateTime.h> -#include <otb/Ephemeris.h> -#include <otb/GeographicEphemeris.h> -#include <otb/JSDDateTime.h> -#include <otb/PlatformPosition.h> -#include <otb/SarSensor.h> -#include <otb/SensorParams.h> -#include <otb/RefPoint.h> -#include <ossim/base/ossimDpt.h> -#include <ossim/base/ossimFilename.h> -#include <ossim/base/ossimGpt.h> -#include <ossim/base/ossimIpt.h> -#include <ossim/base/ossimNotify.h> -#include <ossim/base/ossimRefPtr.h> -#include <ossim/base/ossimString.h> -#include <ossim/base/ossimTrace.h> -#include <ossim/base/ossimXmlDocument.h> -#include <ossim/base/ossimXmlNode.h> - -// Static trace for debugging -static ossimTrace traceDebug("ossimRadarSat2ProductDoc:debug"); - - -ossimRadarSat2ProductDoc::ossimRadarSat2ProductDoc() -{ -} - -ossimRadarSat2ProductDoc::~ossimRadarSat2ProductDoc() -{ -} - -bool ossimRadarSat2ProductDoc::isRadarSat2(const ossimXmlDocument* xdoc) const -{ - bool result = false; - if (xdoc) - { - ossimString s; - getSatellite(xdoc, s); - if (s.upcase() == "RADARSAT-2") - { - result = true; - } - } - return result; -} - -bool ossimRadarSat2ProductDoc::initPlatformPosition( - const ossimXmlDocument* xdoc, PlatformPosition* pos) const -{ - static const char MODULE[] = - "ossimRadarSat2ProductDoc::initPlatformPosition"; - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG)<< MODULE << " entered...\n"; - } - - bool result = true; - - if ( xdoc && pos ) - { - // Get all the stateVector nodes. - ossimString path = - "/product/sourceAttributes/orbitAndAttitude/orbitInformation/stateVector"; - std::vector<ossimRefPtr<ossimXmlNode> > xnodes; - xdoc->findNodes(path, xnodes); - if ( xnodes.size() ) - { - const std::vector<ossimRefPtr<ossimXmlNode> >::size_type COUNT = - xnodes.size(); - Ephemeris** ephemeris = new Ephemeris*[COUNT]; - - int nbrData = 0; // to keep track of good stateVector count. - - ossimRefPtr<ossimXmlNode> svNode = 0; // stateVector node - - for (ossim_uint32 i = 0 ; i < COUNT; ++i) - { - svNode = xnodes[i]; - if ( !svNode ) - { - result = false; - break; - } - - double pos[3]; - double vit[3]; - CivilDateTime eph_civil_date; - ossimString s; - - path = "timeStamp"; - result = ossim::findFirstNode(path, svNode, s); - if (result) - { - ossim::iso8601TimeStringToCivilDate(s, eph_civil_date); - } - else - { - result = false; - ossimNotify(ossimNotifyLevel_WARN) - << MODULE << " ERROR:\nNode not found: " << path - << std::endl; - break; - } - - path = "xPosition"; - result = ossim::findFirstNode(path, svNode, s); - if (result) - { - pos[0] = s.toDouble(); - } - else - { - result = false; - ossimNotify(ossimNotifyLevel_WARN) - << MODULE << " ERROR:\nNode not found: " << path - << std::endl; - break; - } - - path = "yPosition"; - result = ossim::findFirstNode(path, svNode, s); - if (result) - { - pos[1] = s.toDouble(); - } - else - { - result = false; - ossimNotify(ossimNotifyLevel_WARN) - << MODULE << " ERROR:\nNode not found: " << path - << std::endl; - break; - } - - path = "zPosition"; - result = ossim::findFirstNode(path, svNode, s); - if (result) - { - pos[2] = s.toDouble(); - } - else - { - result = false; - ossimNotify(ossimNotifyLevel_WARN) - << MODULE << " ERROR:\nNode not found: " << path - << std::endl; - break; - } - - path = "xVelocity"; - result = ossim::findFirstNode(path, svNode, s); - if (result) - { - vit[0] = s.toDouble(); - } - else - { - result = false; - ossimNotify(ossimNotifyLevel_WARN) - << MODULE << " ERROR:\nNode not found: " << path - << std::endl; - break; - } - - path = "yVelocity"; - result = ossim::findFirstNode(path, svNode, s); - if (result) - { - vit[1] = s.toDouble(); - } - else - { - result = false; - ossimNotify(ossimNotifyLevel_WARN) - << MODULE << " ERROR:\nNode not found: " << path - << std::endl; - break; - } - - path = "zVelocity"; - result = ossim::findFirstNode(path, svNode, s); - if (result) - { - vit[2] = s.toDouble(); - } - else - { - result = false; - ossimNotify(ossimNotifyLevel_WARN) - << MODULE << " ERROR:\nNode not found: " << path - << std::endl; - break; - } - - JSDDateTime eph_jsd_date(eph_civil_date); - GeographicEphemeris* eph = - new GeographicEphemeris(eph_jsd_date, pos, vit); - ephemeris[i] = eph; - ++nbrData; - - } // matches: for (int i = 0 ; i < nbrData; ++i) - - if (result) - { - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << " DEBUG\nnbrData: " << nbrData << "\n"; - } - pos->setData(ephemeris, nbrData); - } - else - { - for (int idx = 0; idx < nbrData; ++idx) - { - delete ephemeris[idx]; - } - delete [] ephemeris; - ephemeris = 0; - } - - } // matches: if ( xnodes.size() ) - else - { - result = false; - ossimNotify(ossimNotifyLevel_WARN) - << MODULE << " ERROR:\nNodes not found: " << path << std::endl; - } - - } // matches: if (xdoc && pos) - else - { - result = false; - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " exit status = " << (result?"true\n":"false\n"); - } - - return result; -} - -bool ossimRadarSat2ProductDoc::initSensorParams(const ossimXmlDocument* xdoc, - SensorParams* sp) const -{ - bool result = true; - - if (xdoc && sp) - { - ossimString s; - - // Get the number of azimuth looks. - if ( getNumberOfAzimuthLooks(xdoc, s) ) - { - sp->set_nAzimuthLook(s.toDouble()); - } - else - { - result = false; - } - - //--- - // drb ??? - // Get the nominal PRF - //--- - double prf; - if ( getNominalPrf(xdoc, prf) ) - { - sp->set_prf(prf * sp->get_nAzimuthLook() ); - // sp->set_prf(prf); - } - else - { - result = false; - } - - // Get the Sampling frequency. - if ( getAdcSamplingRate(xdoc, s) ) - { - sp->set_sf(s.toDouble()); - } - else - { - result = false; - } - - // Get the radar wave length. - if ( getRadarCenterFrequency(xdoc, s) ) - { - const double CLUM = 2.99792458e+8 ; - double waveLength = CLUM / s.toDouble(); - sp->set_rwl(waveLength); - } - else - { - result = false; - } - - // Get columns direction (1=increasing, -1=decreasing). - if ( getPixelTimeOrdering(xdoc, s) ) - { - if (s.downcase() == "increasing") - { - sp->set_col_direction(1); - } - else - { - sp->set_col_direction(-1); - } - } - else - { - result = false; - } - - // Get lines direction (1=increasing, -1=decreasing). - if ( getLineTimeOrdering(xdoc, s) ) - { - if (s.downcase() == "increasing") - { - sp->set_lin_direction(1); - } - else - { - sp->set_lin_direction(-1); - } - } - else - { - result = false; - } - - // Get the antenna pointing direction. - if ( getAntennaPointing(xdoc, s) ) - { - if ( s.downcase() == "right") - { - sp->set_sightDirection(SensorParams::Right); - } - else - { - sp->set_sightDirection(SensorParams::Left); - } - } - else - { - result = false; - } - - // Get the ellipsoid semi_major axis, m, Default : WGS84 - if ( getSemiMajorAxis(xdoc, s) ) - { - sp->set_semiMajorAxis(s.toDouble()); - } - else - { - result = false; - } - - // Get the ellipsoid semi_minor axis, m, Default : WGS84 - if ( getSemiMinorAxis(xdoc, s) ) - { - sp->set_semiMinorAxis(s.toDouble()); - } - else - { - result = false; - } - - - // Get the number of range looks. - if ( getNumberOfRangeLooks(xdoc, s) ) - { - sp->set_nRangeLook(s.toDouble()); - } - else - { - result = false; - } - - } // matches: if (xdoc && sp) - else - { - result = false; - } - - return result; -} - -bool ossimRadarSat2ProductDoc::initImageSize(const ossimXmlDocument* xdoc, - ossimIpt& imageSize) const -{ - bool result = true; - - if (xdoc) - { - ossimString s; - if ( getNumberOfSamplesPerLine(xdoc, s) ) - { - imageSize.x = s.toFloat64(); - } - else - { - result = false; - } - if ( getNumberOfLines(xdoc, s) ) - { - imageSize.y = s.toFloat64(); - } - else - { - result = false; - } - } - else - { - result = false; - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "ossimRadarSat2ProductDoc::initImageSize DEBUG:\nimage size: " - << imageSize - << "\nexit status = " << (result?"true":"false") - << std::endl; - } - - return result; -} - -bool ossimRadarSat2ProductDoc::initGsd(const ossimXmlDocument* xdoc, - ossimDpt& gsd) const -{ - bool result = true; - - if (xdoc) - { - ossimString s; - if ( getSampledPixelSpacing(xdoc, s) ) - { - gsd.x = s.toFloat64(); - } - else - { - result = false; - } - if ( getSampledLineSpacing(xdoc, s) ) - { - gsd.y = s.toFloat64(s); - } - else - { - result = false; - } - } - else - { - result = false; - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "ossimRadarSat2ProductDoc::initGsd DEBUG:\ngsd: " << gsd - << "\nexit status = " << (result?"true":"false") - << std::endl; - } - - return result; -} - -bool ossimRadarSat2ProductDoc::initTiePoints(const ossimXmlDocument* xdoc, - std::list<ossimGpt>& gcp, - std::list<ossimDpt>& icp) const -{ - static const char MODULE[] = "ossimRadarSat2ProductDoc::initTiePoints"; - - bool result = true; - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " DEBUG:\n"; - } - - if (xdoc) - { - ossimString path = "/product/imageAttributes/geographicInformation/geolocationGrid/imageTiePoint"; - std::vector<ossimRefPtr<ossimXmlNode> > xnodes; - xdoc->findNodes(path, xnodes); - if ( xnodes.size() ) - { - for (ossim_uint32 i = 0; i < xnodes.size(); ++i) - { - if (xnodes[i].valid()) - { - ossimRefPtr<ossimXmlNode> icNode = 0; // imageCoordinate - icNode = - xnodes[i]->findFirstNode(ossimString("imageCoordinate")); - if (icNode.valid()) - { - ossimString s; - ossimDpt dpt; - result = ossim::findFirstNode(ossimString("line"), - icNode, s); - if (result) - { - dpt.y = s.toDouble(); - } - result = ossim::findFirstNode(ossimString("pixel"), - icNode, s); - if (result) - { - dpt.x = s.toDouble(); - } - icp.push_back(dpt); - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "dpt" << i << ": " << dpt - << "\n"; - } - } - else - { - result = false; - } - - ossimRefPtr<ossimXmlNode> gcNode = 0; // geodeticCoordinate - gcNode = xnodes[i]->findFirstNode( - ossimString("geodeticCoordinate")); - if (gcNode.valid()) - { - ossimString s; - ossimGpt gpt; - result = ossim::findFirstNode(ossimString("latitude"), - gcNode, s); - if (result) - { - gpt.lat = s.toDouble(); - } - result = ossim::findFirstNode(ossimString("longitude"), - gcNode, s); - if (result) - { - gpt.lon = s.toDouble(); - } - result = ossim::findFirstNode(ossimString("height"), - gcNode, s); - if (result) - { - gpt.hgt = s.toDouble(); - } - gcp.push_back(gpt); - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "gpt" << i << ": " << gpt - << "\n"; - } - - } // matches: if (gcNode.valid()) - else - { - result = false; - } - - } // if (xnodes[i].valid()) - - } // mathches: for (ossim_uint32 i = 0; i < xnodes.size(); ++i) - - } // matches: if ( xnodes.size() ) - else - { - result = false; // No nodes found. - } - } // matches: if (xdoc) - else - { - result = false; // Null pointer passed in. - } - - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << MODULE << " DEBUG: exit status = " << (result?"true":"false") - << std::endl; - } - - return result; -} - -bool ossimRadarSat2ProductDoc::getSatellite(const ossimXmlDocument* xdoc, - ossimString& s) const -{ - ossimString path = "/product/sourceAttributes/satellite"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getSensor(const ossimXmlDocument* xdoc, - ossimString& s) const -{ - ossimString path = "/product/sourceAttributes/sensor"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getImageId(const ossimXmlDocument* xdoc, - ossimString& s) const -{ - ossimString path = "/product/sourceAttributes/imageId"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getRadarCenterFrequency( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/sourceAttributes/radarParameters/radarCenterFrequency"; - return ossim::getPath(path, xdoc, s); -} - -//--- -// drb ??? -// -// Temporary until we decide how to get nominal prf from multiple nodes. -// drb - 15 April 2009 -//--- -bool ossimRadarSat2ProductDoc::getNominalPrf(const ossimXmlDocument* xdoc, - double& prf) const -{ - bool result = false; - std::vector<ossimString> v; - if ( getPulseRepetitionFrequency(xdoc, v) ) - { - if (v.size()) - { - double d = 0; - std::vector<ossimString>::const_iterator i = v.begin(); - while (i < v.end()) - { - d += (*i).toDouble(); - ++i; - } - prf = d / v.size(); - result = true; - } - } - if (traceDebug()) - { - ossimNotify(ossimNotifyLevel_DEBUG) - << "ossimRadarSat2ProductDoc::getNominalPrf DEBUG:\nprf = " - << prf << "\nexit status = " << (result?"true":"false") - << std::endl; - } - return result; -} - -bool ossimRadarSat2ProductDoc::getPulseRepetitionFrequency( - const ossimXmlDocument* xdoc, std::vector<ossimString>& v) const -{ - ossimString path = - "/product/sourceAttributes/radarParameters/pulseRepetitionFrequency"; - return ossim::getPath(path, xdoc, v); -} - -bool ossimRadarSat2ProductDoc::getAntennaPointing( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/sourceAttributes/radarParameters/antennaPointing"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getAdcSamplingRate( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/sourceAttributes/radarParameters/adcSamplingRate"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getPassDirection( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/sourceAttributes/orbitAndAttitude/orbitInformation/passDirection"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getProductType( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageGenerationParameters/generalProcessingInformation/productType"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getZeroDopplerTimeFirstLine( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageGenerationParameters/sarProcessingInformation/zeroDopplerTimeFirstLine"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getNumberOfRangeLooks( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageGenerationParameters/sarProcessingInformation/numberOfRangeLooks"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getNumberOfAzimuthLooks( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageGenerationParameters/sarProcessingInformation/numberOfAzimuthLooks"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getSlantRangeNearEdge( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageGenerationParameters/sarProcessingInformation/slantRangeNearEdge"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getZeroDopplerAzimuthTime( - const ossimXmlDocument* xdoc, std::vector<ossimString>& v) const -{ - ossimString path = - "/product/imageGenerationParameters/slantRangeToGroundRange/zeroDopplerAzimuthTime"; - return ossim::getPath(path, xdoc, v); -} - -bool ossimRadarSat2ProductDoc::getGroundRangeOrigin( - const ossimXmlDocument* xdoc, std::vector<ossimString>& v) const -{ - ossimString path = - "/product/imageGenerationParameters/slantRangeToGroundRange/groundRangeOrigin"; - return ossim::getPath(path, xdoc, v); -} - -bool ossimRadarSat2ProductDoc::getGroundToSlantRangeCoefficients( - const ossimXmlDocument* xdoc, std::vector<ossimString>& v) const -{ - ossimString path = - "/product/imageGenerationParameters/slantRangeToGroundRange/groundToSlantRangeCoefficients"; - return ossim::getPath(path, xdoc, v); -} - -bool ossimRadarSat2ProductDoc::getSemiMajorAxis( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageAttributes/geographicInformation/referenceEllipsoidParameters/semiMajorAxis"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getSemiMinorAxis( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageAttributes/geographicInformation/referenceEllipsoidParameters/semiMinorAxis"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getNumberOfSamplesPerLine( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageAttributes/rasterAttributes/numberOfSamplesPerLine"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getNumberOfLines( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageAttributes/rasterAttributes/numberOfLines"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getSampledPixelSpacing( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageAttributes/rasterAttributes/sampledPixelSpacing"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getSampledLineSpacing( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageAttributes/rasterAttributes/sampledLineSpacing"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getLineTimeOrdering( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageAttributes/rasterAttributes/lineTimeOrdering"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getPixelTimeOrdering( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageAttributes/rasterAttributes/pixelTimeOrdering"; - return ossim::getPath(path, xdoc, s); -} - -bool ossimRadarSat2ProductDoc::getGeodeticTerrainHeight( - const ossimXmlDocument* xdoc, ossimString& s) const -{ - ossimString path = - "/product/imageAttributes/geographicInformation/referenceEllipsoidParameters/geodeticTerrainHeight"; - return ossim::getPath(path, xdoc, s); -} diff --git a/Utilities/otbossimplugins/ossim/ossimRadarSat2ProductDoc.h b/Utilities/otbossimplugins/ossim/ossimRadarSat2ProductDoc.h deleted file mode 100644 index e73ff9d315..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimRadarSat2ProductDoc.h +++ /dev/null @@ -1,179 +0,0 @@ -//---------------------------------------------------------------------------- -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -// Author: David Burken -// -// Description: Utility class to encapsulate parsing RadarSat2 product.xml -// file. -// -//---------------------------------------------------------------------------- -// $Id$ -#ifndef ossimRadarSat2ProductDoc_HEADER -#define ossimRadarSat2ProductDoc_HEADER 1 - -#include <list> -#include <vector> -#include <ossim/base/ossimConstants.h> -#include <ossim/base/ossimRefPtr.h> - -class ossimDpt; -class ossimGpt; -class ossimIpt; -class ossimXmlDocument; -class ossimXmlNode; -class ossimString; -class PlatformPosition; -class RefPoint; -class SensorParams; - -/** @brief Class to encapsulate parsing RadarSat2 product.xml file. */ -class ossimRadarSat2ProductDoc -{ -public: - /** @brief default constructor */ - ossimRadarSat2ProductDoc(); - - /** @brief destructor */ - ~ossimRadarSat2ProductDoc(); - - /** - * @brief Checks for node /product/sourceAttributes/satellite containing - * RADARSAT-2. - * - * @return true if present, false if not. - */ - bool isRadarSat2(const ossimXmlDocument* xdoc) const; - - /** - * @brief Method to initialize PlatformPosition object from - * RadarSat "product.xml" file. - * @param xdoc Opened product.xml file. - * @param pos Pointer to PlatformPosition object. - * @return true on success, false on error. - */ - bool initPlatformPosition(const ossimXmlDocument* xdoc, - PlatformPosition* pos) const; - - /** - * @brief Method to initialize SensorParams object from - * RadarSat "product.xml" file. - * @param xdoc Opened product.xml file. - * @param sp Pointer to SensorParams object. - * @return true on success, false on error. - */ - bool initSensorParams(const ossimXmlDocument* xdoc, - SensorParams* sp) const; - - /** - * @brief Method to initialize image size from - * RadarSat "product.xml" file. - * @param xdoc Opened product.xml file. - * @param imageSize The point to initialize. - * @return true on success, false on error. - */ - bool initImageSize(const ossimXmlDocument* xdoc, - ossimIpt& imageSize) const; - - /** - * @brief Method to initialize gsd from - * RadarSat "product.xml" file. - * @param xdoc Opened product.xml file. - * @param gsd The point to initialize. - * @return true on success, false on error. - */ - bool initGsd(const ossimXmlDocument* xdoc, - ossimDpt& gsd) const; - - /** - * @brief Method to initialize image tie points from - * RadarSat "product.xml" file. - * @param xdoc Opened product.xml file. - * @param imageSize The point to initialize. - * @return true on success, false on error. - */ - bool initTiePoints(const ossimXmlDocument* xdoc, - std::list<ossimGpt>& gcp, - std::list<ossimDpt>& icp) const; - bool getSatellite(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getSensor(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getImageId(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getRadarCenterFrequency(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getNominalPrf(const ossimXmlDocument* xdoc, double& prf) const; - - bool getPulseRepetitionFrequency(const ossimXmlDocument* xdoc, - std::vector<ossimString>& v) const; - - bool getAntennaPointing(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getAdcSamplingRate(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getPassDirection(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getProductType(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getZeroDopplerTimeFirstLine(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getNumberOfRangeLooks(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getNumberOfAzimuthLooks(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getSlantRangeNearEdge(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getZeroDopplerAzimuthTime(const ossimXmlDocument* xdoc, - std::vector<ossimString>& v) const; - - bool getGroundRangeOrigin(const ossimXmlDocument* xdoc, - std::vector<ossimString>& v) const; - - bool getGroundToSlantRangeCoefficients(const ossimXmlDocument* xdoc, - std::vector<ossimString>& v) const; - - bool getSemiMajorAxis(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getSemiMinorAxis(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getNumberOfSamplesPerLine(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getNumberOfLines(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getSampledPixelSpacing(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getSampledLineSpacing(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getLineTimeOrdering(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getPixelTimeOrdering(const ossimXmlDocument* xdoc, - ossimString& s) const; - - bool getGeodeticTerrainHeight(const ossimXmlDocument* xdoc, - ossimString& s) const; - -}; - -#endif /* matches: #ifndef ossimRadarSat2ProductDoc_HEADER */ diff --git a/Utilities/otbossimplugins/ossim/ossimRadarSatModel.cpp b/Utilities/otbossimplugins/ossim/ossimRadarSatModel.cpp deleted file mode 100644 index 5aabc4fab5..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimRadarSatModel.cpp +++ /dev/null @@ -1,578 +0,0 @@ -//---------------------------------------------------------------------------- -// -// "Copyright Centre National d'Etudes Spatiales" -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -//---------------------------------------------------------------------------- -// $Id$ - -#include <cmath> - -#include <ossimRadarSatModel.h> -#include <otb/GalileanEphemeris.h> -#include <otb/GeographicEphemeris.h> - -#include <otb/JSDDateTime.h> -#include <otb/GMSTDateTime.h> -#include <otb/CivilDateTime.h> - -#include <otb/PlatformPosition.h> -#include <otb/SensorParams.h> -#include <otb/RefPoint.h> -#include <otb/SarSensor.h> - - - -RTTI_DEF1(ossimRadarSatModel, "ossimRadarSatModel", ossimGeometricSarSensorModel); - -ossimRadarSatModel::ossimRadarSatModel(): - _n_srgr(0), - _pixel_spacing(0) -{ -} - -ossimRadarSatModel::~ossimRadarSatModel() -{ -} - -ossimString ossimRadarSatModel::getClassName() const -{ - return ossimString("ossimRadarSatModel"); -} - -double ossimRadarSatModel::getSlantRangeFromGeoreferenced(double col) const -{ - if (_n_srgr==0) return(-1) ; - - double relativeGroundRange ; - - // in the case of Georeferenced images, _refPoint->get_distance() contains the ground range - relativeGroundRange = _refPoint->get_distance() + _sensor->get_col_direction() * (col-_refPoint->get_pix_col())* _pixel_spacing ; - - int numSet = FindSRGRSetNumber((_refPoint->get_ephemeris())->get_date()) ; - /** - * @todo : could be improved (date choice) - */ - - double slantRange = _srgr_coefset[numSet][0] - + _srgr_coefset[numSet][1]*relativeGroundRange - + _srgr_coefset[numSet][2]*pow(relativeGroundRange,2) - + _srgr_coefset[numSet][3]*pow(relativeGroundRange,3) - + _srgr_coefset[numSet][4]*pow(relativeGroundRange,4) - + _srgr_coefset[numSet][5]*pow(relativeGroundRange,5); - - return slantRange ; -} - -bool ossimRadarSatModel::InitSensorParams(const ossimKeywordlist &kwl, const char *prefix) -{ - const char* wave_length_str = kwl.find(prefix,"wave_length"); - double wave_length = atof(wave_length_str); - const char* fr_str = kwl.find(prefix,"fr"); - double fr = atof(fr_str); - const char* fa_str = kwl.find(prefix,"fa"); - double fa = atof(fa_str); - - /* //number of different looks - const char* n_azilok_str = kwl.find(prefix,"n_azilok"); - double n_azilok = atof(n_azilok_str); - const char* n_rnglok_str = kwl.find(prefix,"n_rnglok"); - double n_rnglok = atof(n_rnglok_str); - */ - - // look bandwidth rate (for localisation purpose) - const char* bnd_azilok_str = kwl.find(prefix,"bnd_azilok"); - double bnd_azilok = atof(bnd_azilok_str); - const char* bnd_rnglok_str = kwl.find(prefix,"bnd_rnglok"); - double bnd_rnglok = atof(bnd_rnglok_str); - const char* bnd_azi_str = kwl.find(prefix,"bnd_azi"); - double bnd_azi = atof(bnd_azi_str); - const char* bnd_rng_str = kwl.find(prefix,"bnd_rng"); - double bnd_rng = atof(bnd_rng_str); - - double n_azilok = bnd_azi/bnd_azilok; - double n_rnglok = bnd_rng/bnd_rnglok; - - const char* time_dir_pix = kwl.find(prefix,"time_dir_pix"); - const char* time_dir_lin = kwl.find(prefix,"time_dir_lin"); - - //ellipsoid parameters - const char* ellip_maj_str = kwl.find(prefix,"ellip_maj"); - double ellip_maj = atof(ellip_maj_str) * 1000.0; // km -> m - const char* ellip_min_str = kwl.find(prefix,"ellip_min"); - double ellip_min = atof(ellip_min_str) * 1000.0; // km -> m - - if(_sensor != NULL) - { - delete _sensor; - } - - _sensor = new SensorParams(); - - if(strcmp(time_dir_pix, "INCREASE") == 0) - { - _sensor->set_col_direction(1); - } - else - { - _sensor->set_col_direction(-1); - } - - if(strcmp(time_dir_lin, "INCREASE") == 0) - { - _sensor->set_lin_direction(1); - } - else - { - _sensor->set_lin_direction(-1); - } - - const char* lookDirection_str = kwl.find(prefix,"lookDirection"); - ossimString lookDirection(lookDirection_str) ; - lookDirection.trim(" ") ; // eliminates trailing blanks - if (lookDirection == "NORMAL") _sensor->set_sightDirection(SensorParams::Right) ; - else _sensor->set_sightDirection(SensorParams::Left) ; - - _sensor->set_prf(fa); - _sensor->set_sf(fr); - _sensor->set_rwl(wave_length); - _sensor->set_nAzimuthLook(n_azilok); - _sensor->set_nRangeLook(n_rnglok); - - _sensor->set_semiMajorAxis(ellip_maj) ; - _sensor->set_semiMinorAxis(ellip_min) ; - - return true; -} - -bool ossimRadarSatModel::InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix) -{ - const double _PI = 3.14159265358979323846 ; - CivilDateTime ref_civil_date; - /* - * Ephemerisis reference date retrieval - */ - const char* eph_year_str = kwl.find(prefix,"eph_year"); - int eph_year = atoi(eph_year_str); - const char* eph_month_str = kwl.find(prefix,"eph_month"); - int eph_month = atoi(eph_month_str); - const char* eph_day_str = kwl.find(prefix,"eph_day"); - int eph_day = atoi(eph_day_str); - const char* eph_sec_str = kwl.find(prefix,"eph_sec"); - double eph_sec = atof(eph_sec_str); - - ref_civil_date.set_year(eph_year); - ref_civil_date.set_month(eph_month); - ref_civil_date.set_day(eph_day); - ref_civil_date.set_second((int)eph_sec); - ref_civil_date.set_decimal( eph_sec-(double)((int)eph_sec)); - - - JSDDateTime ref_jsd_date(ref_civil_date); - - const char* eph_int_str = kwl.find(prefix, "eph_int"); - double eph_int = atof(eph_int_str); - /* - * Ephemerisis number retrieval - */ - const char* neph_str = kwl.find(prefix,"neph"); - int neph = atoi(neph_str); - - Ephemeris** ephemeris = new Ephemeris*[neph]; - - const char* hr_angle_str = kwl.find(prefix,"hr_angle"); - double greenwich_mha_ref = atof(hr_angle_str); - - GMSTDateTime * greenwich_mha_ref2000 = new GMSTDateTime(); - greenwich_mha_ref2000->set_origine(GMSTDateTime::AN2000); - ref_civil_date.AsGMSTDateTime(greenwich_mha_ref2000); - - /* - * Ephemerisis retrieval - */ - for (int i=0;i<neph;i++) - { - double pos[3]; - double vit[3]; - char name[64]; - - - sprintf(name,"eph%i_posX",i); - const char* px_str = kwl.find(prefix,name); - pos[0] = atof(px_str); - - sprintf(name,"eph%i_posY",i); - const char* py_str = kwl.find(prefix,name); - pos[1] = atof(py_str); - - sprintf(name,"eph%i_posZ",i); - const char* pz_str = kwl.find(prefix,name); - pos[2] = atof(pz_str); - - - sprintf(name,"eph%i_velX",i); - const char* vx_str = kwl.find(prefix,name); - vit[0] = atof(vx_str) * 1.0e-3;; - - sprintf(name,"eph%i_velY",i); - const char* vy_str = kwl.find(prefix,name); - vit[1] = atof(vy_str) * 1.0e-3;; - - sprintf(name,"eph%i_velZ",i); - const char* vz_str = kwl.find(prefix,name); - vit[2] = atof(vz_str) * 1.0e-3;; - - /* - * Ephemerisis date - */ - JSDDateTime date(ref_jsd_date); - date.set_second(date.get_second() + i * eph_int); - date.NormDate(); - - /* - * Date creation for referential change - */ - GMSTDateTime * greenwich_mha = new GMSTDateTime(); - greenwich_mha->set_origine(GMSTDateTime::AN2000); - date.AsGMSTDateTime(greenwich_mha); - - double angle = greenwich_mha_ref+(greenwich_mha->get_tms()-greenwich_mha_ref2000->get_tms())*180.0/_PI; - angle = fmod(angle,360.0); - - /* - * Referential change - */ - GalileanEphemeris * tmpEphemeris = new GalileanEphemeris(date,pos,vit); - GeographicEphemeris* eph = new GeographicEphemeris(); - - tmpEphemeris->ToGeographic(angle,eph); - ephemeris[i] = eph; - - delete tmpEphemeris; - - } - - /* - * Antenna position interpolator creation - */ - if (_platformPosition != NULL) - { - delete _platformPosition; - } - _platformPosition = new PlatformPosition(ephemeris,neph); - - /* - * Free of memory used by the ephemerisis list - */ - for (int i=0;i<neph;i++) - { - delete ephemeris[i]; - } - delete[] ephemeris; - - return true; -} - -bool ossimRadarSatModel::InitRefPoint(const ossimKeywordlist &kwl, const char *prefix) -{ - const char* sc_lin_str = kwl.find(prefix,"sc_lin"); - double sc_lin = atof(sc_lin_str); - - const char* sc_pix_str = kwl.find(prefix,"sc_pix"); - double sc_pix = atof(sc_pix_str); - - const char* inp_sctim_str = kwl.find(prefix,"inp_sctim"); - - const char* rng_gate_str = kwl.find(prefix,"rng_gate"); - double rng_gate = atof(rng_gate_str); - - if(_refPoint == NULL) - { - _refPoint = new RefPoint(); - } - - _refPoint->set_pix_col(sc_pix); - _refPoint->set_pix_line(sc_lin); - - char year_str[5]; - for (int i=0;i<4;i++) - { - year_str[i] = inp_sctim_str[i]; - } - year_str[4] = '\0'; - - char month_str[3]; - for (int i=4;i<6;i++) - { - month_str[i-4] = inp_sctim_str[i]; - } - month_str[2] = '\0'; - - char day_str[3]; - for (int i=6;i<8;i++) - { - day_str[i-6] = inp_sctim_str[i]; - } - day_str[2] = '\0'; - - char hour_str[3]; - for (int i=8;i<10;i++) - { - hour_str[i-8] = inp_sctim_str[i]; - } - hour_str[2] = '\0'; - - char min_str[3]; - for (int i=10;i<12;i++) - { - min_str[i-10] = inp_sctim_str[i]; - } - min_str[2] = '\0'; - - char sec_str[3]; - for (int i=12;i<14;i++) - { - sec_str[i-12] = inp_sctim_str[i]; - } - sec_str[2] = '\0'; - - char mili_str[4]; - for (int i=14;i<17;i++) - { - mili_str[i-14] = inp_sctim_str[i]; - } - mili_str[3] = '\0'; - - int year = atoi(year_str); - int month = atoi(month_str); - int day = atoi(day_str); - int hour = atoi(hour_str); - int min = atoi(min_str); - int sec = atoi(sec_str); - double mili = atof(mili_str); - - - CivilDateTime date(year, month, day, hour * 3600 + min * 60 + sec, mili/1000.0); - - if(_platformPosition != NULL) - { - Ephemeris * ephemeris = _platformPosition->Interpolate((JSDDateTime)date); - if (ephemeris == NULL) return false ; - - _refPoint->set_ephemeris(ephemeris); - - delete ephemeris; - } - else - { - return false; - } - - double c = 2.99792458e+8; - - double distance = (rng_gate + ((double)sc_pix)*_sensor->get_nRangeLook()/_sensor->get_sf()) * (c/2.0); - - // in the case of Georeferenced images, the "relative" ground range is stored in place of the slant range - // (used for SlantRange computation relative to reference point, necessary for optimization) - // here, the pixelDirection is ignored since the RDS reference point is always at the scene centre - if (_isProductGeoreferenced) { - distance = _refPoint->get_pix_col() * _pixel_spacing ; - } - - _refPoint->set_distance(distance); - - -//// essai : line spacing et vitesse satellite -// const char* line_spacing_str = kwl.find(prefix,"line_spacing"); -// double line_spacing = atof(line_spacing_str); -// Ephemeris * ephemeris = _refPoint->get_ephemeris() ; -// double velSat = sqrt(pow(ephemeris->get_vitesse()[0], 2)+ pow(ephemeris->get_vitesse()[1], 2)+ pow(ephemeris->get_vitesse()[2], 2)); -// double prfeq = velSat / line_spacing ; -// _sensor->set_prf(prfeq); -// _sensor->set_nAzimuthLook(1.0); -///** -// * @todo : effacer -// */ - - // in order to use ossimSensorModel::lineSampleToWorld - const char* nbCol_str = kwl.find(prefix,"nbCol"); - const char* nbLin_str = kwl.find(prefix,"nbLin"); - theImageSize.x = atoi(nbCol_str); - theImageSize.y = atoi(nbLin_str); - theImageClipRect = ossimDrect(0, 0, theImageSize.x-1, theImageSize.y-1); - - // sensor PRF update in the case of ground projected products - if (_isProductGeoreferenced) { - const char* acq_msec_first_str = kwl.find("acq_msec_first"); - double acq_msec_first = atof(acq_msec_first_str); - const char* acq_msec_last_str = kwl.find("acq_msec_last"); - double acq_msec_last = atof(acq_msec_last_str); - - double actualPRF = 1000.0*theImageSize.y/(acq_msec_last-acq_msec_first) ; - _sensor->set_nAzimuthLook(_sensor->get_prf()/actualPRF); - } - - // Ground Control Points extracted from the model : scene center - std::list<ossimGpt> groundGcpCoordinates ; - std::list<ossimDpt> imageGcpCoordinates ; - const char* lon_str = kwl.find("pro_long"); - double lon = atof(lon_str); - const char* lat_str = kwl.find("pro_lat"); - double lat = atof(lat_str); - //const char* height_str = kwl.find("terrain_height"); - double height = 0 ; //atof(height_str) ; - - ossimDpt imageGCP(sc_pix,sc_lin); - ossimGpt groundGCP(lat, lon, height); - groundGcpCoordinates.push_back(groundGCP) ; - imageGcpCoordinates.push_back(imageGCP) ; - - // Ground Control Points extracted from the model : scene corners - // upper left corner - lon = atof(kwl.find("cornersLon0")); - lat = atof(kwl.find("cornersLat0")); - ossimDpt imageGCP0(0,0); - ossimGpt groundGCP0(lat, lon, height); - groundGcpCoordinates.push_back(groundGCP0) ; - imageGcpCoordinates.push_back(imageGCP0) ; - // upper right corner - lon = atof(kwl.find("cornersLon1")); - lat = atof(kwl.find("cornersLat1")); - ossimDpt imageGCP1(theImageSize.x-1,0); - ossimGpt groundGCP1(lat, lon, height); - groundGcpCoordinates.push_back(groundGCP1) ; - imageGcpCoordinates.push_back(imageGCP1) ; - // lower left corner - lon = atof(kwl.find("cornersLon2")); - lat = atof(kwl.find("cornersLat2")); - ossimDpt imageGCP2(0,theImageSize.y-1); - ossimGpt groundGCP2(lat, lon, height); - groundGcpCoordinates.push_back(groundGCP2) ; - imageGcpCoordinates.push_back(imageGCP2) ; - // lower right corner - lon = atof(kwl.find("cornersLon3")); - lat = atof(kwl.find("cornersLat3")); - ossimDpt imageGCP3(theImageSize.x-1,theImageSize.y-1); - ossimGpt groundGCP3(lat, lon, height); - groundGcpCoordinates.push_back(groundGCP3) ; - imageGcpCoordinates.push_back(imageGCP3) ; - - // Default optimization - optimizeModel(groundGcpCoordinates, imageGcpCoordinates) ; - - return true; -} - -bool ossimRadarSatModel::InitSRGR(const ossimKeywordlist &kwl, const char *prefix) -{ - // product type : format "RSAT-1-SAR-{SLC,SGG,SGC,...}-..." - const char* file_name_str = kwl.find(prefix,"file_name"); - char format[4] ; - // product type (SLC,SGG,SGC,...) extraction - for (int j=11;j<14;j++) - { - format[j-11] = file_name_str[j]; - } - format[3] = '\0'; - std::string format_str(format); - - _isProductGeoreferenced = (format_str=="SGX") || (format_str=="SGF"); - - // pixel spacing - const char* pixel_spacing_str = kwl.find(prefix,"pixel_spacing"); - _pixel_spacing = atof(pixel_spacing_str); - - // number of SRGR sets - const char* n_srgr_str = kwl.find(prefix,"n_srgr"); - _n_srgr = atoi(n_srgr_str); - - char name[64]; - for (int i=0;i<_n_srgr;i++) - { - // SRGR update time, format : YYYY-DDD-HH:MM:SS.SSS - sprintf(name,"srgr_update%i",i); - const char* srgr_update_str = kwl.find(prefix,name); - - // years and days are ignored in the following (conversion from CivilDate to JSDDate requires a YYYY-MM-DD format) - // could be improved - char hour_str[3]; - for (int j=9;j<11;j++) - { - hour_str[j-9] = srgr_update_str[j]; - } - hour_str[2] = '\0'; - - char min_str[3]; - for (int j=12;j<14;j++) - { - min_str[j-12] = srgr_update_str[j]; - } - min_str[2] = '\0'; - - char sec_str[3]; - for (int j=15;j<17;j++) - { - sec_str[j-15] = srgr_update_str[j]; - } - sec_str[2] = '\0'; - - char mili_str[4]; - for (int j=18;j<21;j++) - { - mili_str[j-18] = srgr_update_str[j]; - } - mili_str[3] = '\0'; - - int hour = atoi(hour_str); - int min = atoi(min_str); - int sec = atoi(sec_str); - double mili = atof(mili_str); - _srgr_update[i] = hour * 3600 + min * 60 + sec + mili/1000.0 ; - - // SRGR coefficients - sprintf(name,"srgr_coef%iA",i); - const char* srgr_coef_strA = kwl.find(prefix,name); - _srgr_coefset[i][0] = atof(srgr_coef_strA); - sprintf(name,"srgr_coef%iB",i); - const char* srgr_coef_strB = kwl.find(prefix,name); - _srgr_coefset[i][1] = atof(srgr_coef_strB); - sprintf(name,"srgr_coef%iC",i); - const char* srgr_coef_strC = kwl.find(prefix,name); - _srgr_coefset[i][2] = atof(srgr_coef_strC); - sprintf(name,"srgr_coef%iD",i); - const char* srgr_coef_strD = kwl.find(prefix,name); - _srgr_coefset[i][3] = atof(srgr_coef_strD); - sprintf(name,"srgr_coef%iE",i); - const char* srgr_coef_strE = kwl.find(prefix,name); - _srgr_coefset[i][4] = atof(srgr_coef_strE); - sprintf(name,"srgr_coef%iF",i); - const char* srgr_coef_strF = kwl.find(prefix,name); - _srgr_coefset[i][5] = atof(srgr_coef_strF); - } - return true; -} - -int ossimRadarSatModel::FindSRGRSetNumber(JSDDateTime date) const -{ - if (_n_srgr==0) return(-1) ; - - double delays[20]; - for (int i=0;i<_n_srgr;i++) - { - delays[i] = fabs(date.get_second()+date.get_decimal()-_srgr_update[i]) ; - } - - int setNumber = 0 ; - double min_delay = delays[0] ; - for (int i=1;i<_n_srgr;i++) - { - if (delays[i]<min_delay) { - setNumber = i ; - min_delay = delays[i] ; - } - } - return setNumber ; -} diff --git a/Utilities/otbossimplugins/ossim/ossimRadarSatModel.h b/Utilities/otbossimplugins/ossim/ossimRadarSatModel.h deleted file mode 100644 index 78af4e138e..0000000000 --- a/Utilities/otbossimplugins/ossim/ossimRadarSatModel.h +++ /dev/null @@ -1,88 +0,0 @@ -//---------------------------------------------------------------------------- -// -// "Copyright Centre National d'Etudes Spatiales" -// -// License: LGPL -// -// See LICENSE.txt file in the top level directory for more details. -// -//---------------------------------------------------------------------------- -// $Id$ - -#ifndef ossimRadarSatModel_H -#define ossimRadarSatModel_H - -#include <otb/JSDDateTime.h> - -#include <ossimGeometricSarSensorModel.h> -#include <ossim/projection/ossimMapProjection.h> -#include <ossim/base/ossimIpt.h> -#include <ossim/base/ossimFilename.h> -#include <ossim/base/ossimGpt.h> -#include <ossim/base/ossimDpt.h> - -#include <iostream> - -class PlatformPosition; -class SensorParams; -class RefPoint; -/** - * @brief This class is able to direct localisation and indirect localisation using the RadarSat sensor model - */ -class ossimRadarSatModel : public ossimGeometricSarSensorModel -{ -public: - /** @brief Constructor */ - ossimRadarSatModel(); - - /** @brief Destructor */ - virtual ~ossimRadarSatModel(); - - /** - * @brief Method to return the class name. - * @return The name of this class. - */ - virtual ossimString getClassName() const; - - /** - * @brief This function associates an image column number to a slant range when the image is georeferenced (ground projected) - * @param col Column coordinate of the image point - */ - virtual double getSlantRangeFromGeoreferenced(double col) const; - -protected: - - /** - * @brief Slant Range for each Ground Range (SRGR) number of coefficients sets - */ - int _n_srgr; - /** - * @brief SRGR coefficient sets - */ - double _srgr_coefset[20][6]; - /** - * @brief SRGR coefficient sets update times - */ - double _srgr_update[20]; - /** - * @brief Pixel spacing - */ - double _pixel_spacing; - -private: - virtual bool InitPlatformPosition(const ossimKeywordlist &kwl, const char *prefix); - virtual bool InitSensorParams(const ossimKeywordlist &kwl, const char *prefix); - virtual bool InitRefPoint(const ossimKeywordlist &kwl, const char *prefix); - /** - * @brief Initializes the Slant Range for each Ground Range data sets : _n_srgr,_srgr_coefset,_srgr_update,_pixel_spacing,_isProductGeoreferenced - */ - virtual bool InitSRGR(const ossimKeywordlist &kwl, const char *prefix); - /** - * @brief Finds the SRGR data set which update time is the closest to the center scene time - */ - int FindSRGRSetNumber(JSDDateTime date) const; - TYPE_DATA - -}; - -#endif diff --git a/Utilities/otbossimplugins/ossim/ossimTerraSarModel.cpp b/Utilities/otbossimplugins/ossim/ossimTerraSarModel.cpp index d0ec83f5be..8d34df01a0 100644 --- a/Utilities/otbossimplugins/ossim/ossimTerraSarModel.cpp +++ b/Utilities/otbossimplugins/ossim/ossimTerraSarModel.cpp @@ -781,7 +781,7 @@ bool ossimTerraSarModel::InitPlatformPosition(const ossimKeywordlist &kwl, const */ std::string utcString(date_str); CivilDateTime eph_civil_date; - if (! UtcDateTimeStringToCivilDate(utcString, eph_civil_date)) return false; + if (! ossim::iso8601TimeStringToCivilDate(utcString, eph_civil_date)) return false; JSDDateTime eph_jsd_date(eph_civil_date); @@ -834,7 +834,7 @@ bool ossimTerraSarModel::InitRefPoint(const ossimKeywordlist &kwl, const char *p _refPoint->set_pix_line(sc_lin); CivilDateTime * date = new CivilDateTime() ; - if (! UtcDateTimeStringToCivilDate(inp_sctim_string, *date)) return false ; + if (! ossim::iso8601TimeStringToCivilDate(inp_sctim_string, *date)) return false ; if(_platformPosition != NULL) { @@ -879,9 +879,9 @@ bool ossimTerraSarModel::InitRefPoint(const ossimKeywordlist &kwl, const char *p std::string azimuthStartTime(kwl.find("azimuthStartTime")); std::string azimuthStopTime(kwl.find("azimuthStopTime")); CivilDateTime * dateStart = new CivilDateTime() ; - if (! UtcDateTimeStringToCivilDate(azimuthStartTime, *dateStart)) return false ; + if (! ossim::iso8601TimeStringToCivilDate(azimuthStartTime, *dateStart)) return false ; CivilDateTime * dateStop = new CivilDateTime() ; - if (! UtcDateTimeStringToCivilDate(azimuthStopTime, *dateStop)) return false ; + if (! ossim::iso8601TimeStringToCivilDate(azimuthStopTime, *dateStop)) return false ; double acq_msec_first = (double) dateStart->get_second()+dateStart->get_decimal(); double acq_msec_last = (double) dateStop->get_second()+dateStop->get_decimal(); diff --git a/Utilities/otbossimplugins/ossim/ossimTerraSarModel.h b/Utilities/otbossimplugins/ossim/ossimTerraSarModel.h index 761c21dcf3..db41225d79 100644 --- a/Utilities/otbossimplugins/ossim/ossimTerraSarModel.h +++ b/Utilities/otbossimplugins/ossim/ossimTerraSarModel.h @@ -110,9 +110,6 @@ private: */ virtual bool InitSRGR(const ossimKeywordlist &kwl, const char *prefix); - bool UtcDateTimeStringToCivilDate(const std::string &utcString, CivilDateTime &outputDate); - - /** * @note This method must be called before initRefPoint. */ diff --git a/otbIncludeDirectories.cmake b/otbIncludeDirectories.cmake index 5f9e76690c..596434d539 100644 --- a/otbIncludeDirectories.cmake +++ b/otbIncludeDirectories.cmake @@ -47,6 +47,7 @@ SET(OTB_INCLUDE_DIRS_BUILD_TREE ${OTB_INCLUDE_DIRS_BUILD_TREE} ${OTB_SOURCE_DIR}/Utilities/otbossimplugins #Temporary until the SAR plugins are fully integrated: ${OTB_SOURCE_DIR}/Utilities/otbossim/include/ossim/projection/otb + ${OTB_SOURCE_DIR}/Utilities/otbossim/include/ossim/projection # Add otbossimplugins/ossim/otb into the include directories path ${OTB_SOURCE_DIR}/Utilities/otbossimplugins/ossim/otb ${OTB_SOURCE_DIR}/Utilities/dxflib -- GitLab