From f588055f27d92c541ff40b1f146aecffedb45386 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@orfeo-toolbox.org>
Date: Tue, 16 Oct 2012 17:35:19 +0200
Subject: [PATCH] ENH: Adding read/write of geom file in sensor model ossim
 adapter

---
 .../OssimAdapters/otbSensorModelAdapter.cxx   | 37 +++++++++++++++++++
 .../OssimAdapters/otbSensorModelAdapter.h     |  6 +++
 2 files changed, 43 insertions(+)

diff --git a/Code/UtilitiesAdapters/OssimAdapters/otbSensorModelAdapter.cxx b/Code/UtilitiesAdapters/OssimAdapters/otbSensorModelAdapter.cxx
index a8df4fbbb7..401f5eb131 100644
--- a/Code/UtilitiesAdapters/OssimAdapters/otbSensorModelAdapter.cxx
+++ b/Code/UtilitiesAdapters/OssimAdapters/otbSensorModelAdapter.cxx
@@ -245,4 +245,41 @@ double SensorModelAdapter::Optimize()
   return precision;
 }
 
+bool SensorModelAdapter::ReadGeomFile(const std::string & infile)
+{
+  ossimKeywordlist geom;
+
+  geom.add(infile.c_str());
+  
+  m_SensorModel = ossimSensorModelFactory::instance()->createProjection(geom);
+  
+  if (m_SensorModel == NULL)
+    {
+    m_SensorModel = ossimplugins::ossimPluginProjectionFactory::instance()->createProjection(geom);
+    }
+  
+  return (m_SensorModel != NULL);
+}
+
+bool SensorModelAdapter::WriteGeomFile(const std::string & outfile)
+{
+  // If tie points and model are allocated
+  if(m_SensorModel != NULL)
+    {
+    // try to retrieve a sensor model
+    ossimSensorModel * sensorModel = NULL;
+    sensorModel = dynamic_cast<ossimSensorModel *>(m_SensorModel);
+
+    ossimKeywordlist geom;
+
+    bool success = sensorModel->saveState(geom);
+
+    if(success)
+      {
+      return geom.write(outfile.c_str());
+      }
+    }
+  return false;
+}
+
 } // namespace otb
diff --git a/Code/UtilitiesAdapters/OssimAdapters/otbSensorModelAdapter.h b/Code/UtilitiesAdapters/OssimAdapters/otbSensorModelAdapter.h
index c5f67ee978..150feab485 100644
--- a/Code/UtilitiesAdapters/OssimAdapters/otbSensorModelAdapter.h
+++ b/Code/UtilitiesAdapters/OssimAdapters/otbSensorModelAdapter.h
@@ -86,6 +86,12 @@ public:
   /** Is sensor model valid method. return false if the m_SensorModel is null*/
   bool IsValidSensorModel();
 
+  /** Read geom file and instanciate sensor model */
+  bool ReadGeomFile(const std::string & infile);
+  
+  /** Write geom file corresponding to sensor model */
+  bool WriteGeomFile(const std::string& outfile);
+
 protected:
   SensorModelAdapter();
   virtual ~SensorModelAdapter();
-- 
GitLab