diff --git a/Code/UtilitiesAdapters/OssimAdapters/otbGeometricSarSensorModelAdapter.cxx b/Code/UtilitiesAdapters/OssimAdapters/otbGeometricSarSensorModelAdapter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..232d2614e397a2620cc1d2e377de368ee6e6970c --- /dev/null +++ b/Code/UtilitiesAdapters/OssimAdapters/otbGeometricSarSensorModelAdapter.cxx @@ -0,0 +1,75 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "otbGeometricSarSensorModelAdapter.h" + +#include "otbMacro.h" +#include "otbImageKeywordlist.h" + +#include "ossimGeometricSarSensorModel.h" +#include "projection/ossimProjection.h" +#include "ossim/ossimPluginProjectionFactory.h" +#include "otb/JSDDateTime.h" + + +namespace otb { + +GeometricSarSensorModelAdapter::GeometricSarSensorModelAdapter(): + m_SensorModel(NULL) +{ +} + +GeometricSarSensorModelAdapter::~GeometricSarSensorModelAdapter() +{ + if (m_SensorModel != NULL) + { + delete m_SensorModel; + m_SensorModel = NULL; + } +} + + +void GeometricSarSensorModelAdapter::CreateSensorModel(const ImageKeywordlist& image_kwl) +{ + ossimKeywordlist geom; + + image_kwl.convertToOSSIMKeywordlist(geom); + otbMsgDevMacro(<< "CreateSensorModel()"); + otbMsgDevMacro(<< "* type: " << geom.find("type")); + + ossimProjection* sensor = ossimplugins::ossimPluginProjectionFactory::instance()->createProjection(geom); + + m_SensorModel = dynamic_cast<ossimplugins::ossimGeometricSarSensorModel*>(sensor); + if (!m_SensorModel) + { + otbMsgDevMacro(<< "CreateSensorModel() failed"); + } +} + +ossimplugins::JSDDateTime GeometricSarSensorModelAdapter::getTime(double line) +{ + return m_SensorModel->getTime(line); +} + +void GeometricSarSensorModelAdapter::GetPlatformPositionAtLine( + double line, std::vector<double>& position, std::vector<double>& speed) +{ + m_SensorModel->getPlatformPositionAtLine(line, position, speed); +} + +} // namespace otb diff --git a/Code/UtilitiesAdapters/OssimAdapters/otbGeometricSarSensorModelAdapter.h b/Code/UtilitiesAdapters/OssimAdapters/otbGeometricSarSensorModelAdapter.h new file mode 100644 index 0000000000000000000000000000000000000000..89cc4f32070f4aebe0befc1bb41c88206951e324 --- /dev/null +++ b/Code/UtilitiesAdapters/OssimAdapters/otbGeometricSarSensorModelAdapter.h @@ -0,0 +1,86 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __otbGeometricSarSensorModelAdapter_h +#define __otbGeometricSarSensorModelAdapter_h + +#include <vector> + +#include "itkObject.h" +#include "itkObjectFactory.h" + +namespace ossimplugins +{ +class ossimGeometricSarSensorModel; +class JSDDateTime; +} + +namespace otb +{ + +class ImageKeywordlist; + +/** + * \class GeometricSarSensorModelAdapter + * \brief Wrapper class to access the platform Geometric Sar + * Sensor Modelposition from ossim. + * + * This class is intended to be used in an InSAR setting to get + * information relative to the baseline. If necessary, it could be + * extended to non SAR models, but the optical ossim classes would + * need to be modified. + **/ + +class GeometricSarSensorModelAdapter: public itk::Object +{ +public: + /** Standard class typedefs. */ + typedef GeometricSarSensorModelAdapter Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(GeometricSarSensorModelAdapter, itk::Object); + + void CreateSensorModel(const ImageKeywordlist& image_kwl); + + /** Get the platform position and speed for a given line. */ + void GetPlatformPositionAtLine( + double line, std::vector<double>& position, std::vector<double>& speed); + + /** Get the platform time for a given line. */ + ossimplugins::JSDDateTime getTime(double line); + +protected: + GeometricSarSensorModelAdapter(); + virtual ~GeometricSarSensorModelAdapter(); + +private: + GeometricSarSensorModelAdapter(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + ossimplugins::ossimGeometricSarSensorModel* m_SensorModel; + +}; + +} // namespace otb + +#endif diff --git a/Testing/Code/UtilitiesAdapters/CMakeLists.txt b/Testing/Code/UtilitiesAdapters/CMakeLists.txt index d62d7fd11742e4e971590db5d447138a6643a37b..c7f5b52f08e22209bbc01d409d664659ff3b5707 100644 --- a/Testing/Code/UtilitiesAdapters/CMakeLists.txt +++ b/Testing/Code/UtilitiesAdapters/CMakeLists.txt @@ -20,9 +20,26 @@ ADD_TEST(uaTvPlatformPositionComputeBaselineTest ${TEMP}/uaTvPlatformPositionComputeBaselineTest.txt) ENDIF(OTB_DATA_USE_LARGEINPUT) +ADD_TEST(uaTvGeometricSarSenorModelAdapterNew + ${UtilitiesAdapters_TESTS1} + otbGeometricSarSenorModelAdapterNewTest) + +IF(OTB_DATA_USE_LARGEINPUT) +ADD_TEST(uaTvGeometricSarSenorModelAdapterTest + ${UtilitiesAdapters_TESTS1} + --compare-ascii ${EPSILON_9} + ${BASELINE_FILES}/uaTvGeometricSarSenorModelAdapterTest.txt + ${TEMP}/uaTvGeometricSarSenorModelAdapterTest.txt + otbGeometricSarSenorModelAdapterTest + ${LARGEINPUT}/TERRASARX/ULURU/TSX1_SAR__SSC______HS_S_SRA_20090212T204239_20090212T204240/TSX1_SAR__SSC______HS_S_SRA_20090212T204239_20090212T204240.xml + ${LARGEINPUT}/TERRASARX/ULURU/TSX1_SAR__SSC______HS_S_SRA_20090223T204240_20090223T204241/TSX1_SAR__SSC______HS_S_SRA_20090223T204240_20090223T204241.xml + ${TEMP}/uaTvGeometricSarSenorModelAdapter.txt) +ENDIF(OTB_DATA_USE_LARGEINPUT) + SET(UtilitiesAdapters_SRCS1 otbUtilitiesAdaptersTests1.cxx otbPlatformPositionAdapter.cxx +otbGeometricSarSensorModelAdapter.cxx ) diff --git a/Testing/Code/UtilitiesAdapters/otbGeometricSarSensorModelAdapter.cxx b/Testing/Code/UtilitiesAdapters/otbGeometricSarSensorModelAdapter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..8e8d19dd5f28f0660d6a5efc9676ef113ac11a5a --- /dev/null +++ b/Testing/Code/UtilitiesAdapters/otbGeometricSarSensorModelAdapter.cxx @@ -0,0 +1,102 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include <iomanip> + +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbGeometricSarSensorModelAdapter.h" + +int otbGeometricSarSenorModelAdapterNewTest(int argc, char* argv[]) +{ + typedef otb::GeometricSarSenorModelAdapter SarSensorModelType; + SarSensorModelType::Pointer masterPlatform = SarSensorModelType::New(); + return EXIT_SUCCESS; +} + +int otbGeometricSarSenorModelAdapterTest(int argc, char* argv[]) +{ + if (argc != 4) + { + std::cerr << "Usage: " << argv[0] << " masterImageFile slaveImageFile output" << std::endl; + return EXIT_FAILURE; + } + + typedef std::complex<double> PixelType; + typedef otb::Image<PixelType,2> ImageType; + + typedef otb::ImageFileReader<ImageType> ReaderType; + + ReaderType::Pointer master = ReaderType::New(); + ReaderType::Pointer slave = ReaderType::New(); + + master->SetFileName(argv[1]); + slave->SetFileName(argv[2]); + + master->UpdateOutputInformation(); + slave->UpdateOutputInformation(); + + typedef otb::GeometricSarSenorModelAdapter SarSensorModelType; + SarSensorModelType::Pointer masterSarModel = SarSensorModelType::New(); + SarSensorModelType::Pointer slaveSarModel = SarSensorModelType::New(); + + masterSarModel->CreateSensorModel(master->GetOutput()->GetImageKeywordlist()); + slaveSarModel->CreateSensorModel(slave->GetOutput()->GetImageKeywordlist()); + + std::vector<double> masterPosition; + std::vector<double> masterSpeed; + masterPosition.resize(3); + masterSpeed.resize(3); + + std::vector<double> slavePosition; + std::vector<double> slaveSpeed; + slavePosition.resize(3); + slaveSpeed.resize(3); + + masterSarModel->GetPlatformPositionAtLine(0, masterPosition, masterSpeed); + slaveSarModel->GetPlatformPositionAtLine(0, slavePosition, slaveSpeed); + + std::ofstream file; + file.open(argv[3]); + + file << std::setprecision(15); + + file << "Master image:\n"; + file << "Start Time: " << masterSarModel->getTime(0)<< " m\n"; + file << "Pos X: " << masterPosition[0] << " m\n"; + file << "Pos Y: " << masterPosition[1] << " m\n"; + file << "Pos Z: " << masterPosition[2] << " m\n"; + file << "Spd X: " << masterSpeed[0] << " m/s\n"; + file << "Spd Y: " << masterSpeed[1] << " m/s\n"; + file << "Spd Z: " << masterSpeed[2] << " m/s\n"; + + file << "Slave image:\n"; + file << "Start Time: " << slaveSarModel->getTime(0)<< " m\n"; + file << "Pos X: " << slavePosition[0] << " m\n"; + file << "Pos Y: " << slavePosition[1] << " m\n"; + file << "Pos Z: " << slavePosition[2] << " m\n"; + file << "Spd X: " << slaveSpeed[0] << " m/s\n"; + file << "Spd Y: " << slaveSpeed[1] << " m/s\n"; + file << "Spd Z: " << slaveSpeed[2] << " m/s\n"; + + file << "\nBaseline length:\n"; + file << baselineLength << " m \n"; + + file.close(); + return EXIT_SUCCESS; +} diff --git a/Testing/Code/UtilitiesAdapters/otbUtilitiesAdaptersTests1.cxx b/Testing/Code/UtilitiesAdapters/otbUtilitiesAdaptersTests1.cxx index d3d42cb7b39b3c47e4ab744568190f9f8049c81f..e4c62ceb387b5c82344691de12ee762d0fbcf81a 100644 --- a/Testing/Code/UtilitiesAdapters/otbUtilitiesAdaptersTests1.cxx +++ b/Testing/Code/UtilitiesAdapters/otbUtilitiesAdaptersTests1.cxx @@ -25,4 +25,6 @@ void RegisterTests() { REGISTER_TEST(otbPlatformPositionComputeBaselineNewTest); REGISTER_TEST(otbPlatformPositionComputeBaselineTest); + REGISTER_TEST(otbGeometricSarSenorModelAdapterNewTest); + REGISTER_TEST(otbGeometricSarSenorModelAdapterTest); } diff --git a/Utilities/otbossimplugins/ossim/ossimGeometricSarSensorModel.cpp b/Utilities/otbossimplugins/ossim/ossimGeometricSarSensorModel.cpp index 1bb635849e9398e7d10064e395753ac8bb1dc0a0..6e865f33097678ddc225066379c08f2f73e649fd 100644 --- a/Utilities/otbossimplugins/ossim/ossimGeometricSarSensorModel.cpp +++ b/Utilities/otbossimplugins/ossim/ossimGeometricSarSensorModel.cpp @@ -122,18 +122,7 @@ JSDDateTime ossimGeometricSarSensorModel::getTime(double line) const bool ossimGeometricSarSensorModel::getPlatformPositionAtLine(double line, vector<double>& position, vector<double>& speed) { JSDDateTime time = getTime(line); - Ephemeris* ephemeris = _platformPosition->Interpolate(time); - double* position_ptr = ephemeris->get_position(); - double* speed_ptr = ephemeris->get_speed(); - if (position.size() != 3) position.resize(3); - if (speed.size() != 3) speed.resize(3); - position[0] = position_ptr[0]; - position[1] = position_ptr[1]; - position[2] = position_ptr[2]; - speed[0] = speed_ptr[0]; - speed[1] = speed_ptr[1]; - speed[2] = speed_ptr[2]; - return true; + return _platformPosition->getPlatformPositionAtTime(time,position,speed); } void ossimGeometricSarSensorModel::lineSampleHeightToWorld(