From 861be1a3bde2775d9c2e98ad92e55ba087118a95 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@c-s.fr>
Date: Thu, 6 Dec 2007 16:58:53 +0000
Subject: [PATCH] =?UTF-8?q?Mise=20en=20=C3=A9vidence=20du=20pb=20ossim?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Testing/Code/IO/CMakeLists.txt              | 17 ++++
 Testing/Code/IO/otbDEMHandlerTest.cxx       |  4 +-
 Testing/Code/IO/otbIOTests.cxx              |  1 +
 Testing/Code/IO/otbOssimElevManagerTest.cxx | 98 +++++++++++++++++++++
 4 files changed, 118 insertions(+), 2 deletions(-)
 create mode 100644 Testing/Code/IO/otbOssimElevManagerTest.cxx

diff --git a/Testing/Code/IO/CMakeLists.txt b/Testing/Code/IO/CMakeLists.txt
index ea43f4d9f0..96a18e0b41 100755
--- a/Testing/Code/IO/CMakeLists.txt
+++ b/Testing/Code/IO/CMakeLists.txt
@@ -1120,6 +1120,7 @@ ADD_TEST(ioTvDEMHandler ${IO_TESTS}
         otbDEMHandlerTest
         ${INPUTDATA}/DEM/srtm_directory
         ${TEMP}/ioDEMGetHeightAboveMSL.txt
+	3.6999 44.08
         )
 
 # ---  otb::ImageGeometryHandler ---
@@ -1143,6 +1144,21 @@ ADD_TEST(ioTvDEMToImageGeneratorTest ${IO_TESTS}
          )
  
 
+
+ADD_TEST(ioTvossimElevManagerTest ${IO_TESTS}
+--compare-image ${TOL}  ${BASELINE}/ioTvossimElevManagerTest.tif
+                        ${TEMP}/ioTvossimElevManagerTest.tif
+        otbOssimElevManagerTest
+         ${INPUTDATA}/DEM/srtm_directory
+         ${TEMP}/ioTvossimElevManagerTest.tif
+				 6.5
+         44.5
+				 0.002
+				 0.002
+				  500
+				  500
+         )
+
 #----------------------------------------------------------------------------------
 # Exemples de tests sur les grosses images
 # Tests non lanc�s pour raison taille des fichiers produits
@@ -1211,6 +1227,7 @@ otbDEMToImageGeneratorNew.cxx
 otbDEMToImageGeneratorTest.cxx
 otbImageGeometryHandlerNew.cxx
 otbPipeline.cxx
+otbOssimElevManagerTest.cxx
 )
 
 INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
diff --git a/Testing/Code/IO/otbDEMHandlerTest.cxx b/Testing/Code/IO/otbDEMHandlerTest.cxx
index 4be1556990..c5482dca83 100644
--- a/Testing/Code/IO/otbDEMHandlerTest.cxx
+++ b/Testing/Code/IO/otbDEMHandlerTest.cxx
@@ -42,8 +42,8 @@ int otbDEMHandlerTest(int argc, char * argv[])
         typedef otb::UtmInverseProjection                      utmProjection;
         typedef utmProjection::InputPointType	        InputPoint;
         InputPoint                                      geoPoint;
-        geoPoint[0] = 3.6999;
-        geoPoint[1] = 44.08;
+        geoPoint[0] = atof(argv[3]);//3.6999;
+        geoPoint[1] = atof(argv[4]);//44.08;
 
         height=demHandler->GetHeightAboveMSL(geoPoint); 
 
diff --git a/Testing/Code/IO/otbIOTests.cxx b/Testing/Code/IO/otbIOTests.cxx
index 4b912add80..6f7a90edff 100755
--- a/Testing/Code/IO/otbIOTests.cxx
+++ b/Testing/Code/IO/otbIOTests.cxx
@@ -79,5 +79,6 @@ REGISTER_TEST(otbDEMHandlerTest);
 REGISTER_TEST(otbImageGeometryHandlerNew);
 REGISTER_TEST(otbDEMToImageGeneratorNew);
 REGISTER_TEST(otbDEMToImageGeneratorTest);
+REGISTER_TEST(otbOssimElevManagerTest); 
 REGISTER_TEST(otbPipeline);
 }
diff --git a/Testing/Code/IO/otbOssimElevManagerTest.cxx b/Testing/Code/IO/otbOssimElevManagerTest.cxx
new file mode 100644
index 0000000000..a8897a9a82
--- /dev/null
+++ b/Testing/Code/IO/otbOssimElevManagerTest.cxx
@@ -0,0 +1,98 @@
+#include "otbImage.h"
+#include "otbImageFileWriter.h"
+#include "elevation/ossimElevManager.h"
+#include "base/ossimFilename.h"
+#include "itkImageRegionIteratorWithIndex.h"
+
+
+int otbOssimElevManagerTest(int argc,char* argv[])
+{
+
+  if(argc!=9)
+    {
+      std::cout<<"Usage: "<<std::endl;
+      std::cout<<argv[0]<<" srtmDir outfname originX originY spacingX spacingY sizeX sizeY"<<std::endl;
+      return EXIT_FAILURE;
+    }
+
+  const ossimFilename srtmDir(argv[1]);
+  const char * outfname = argv[2];  
+
+  typedef double PixelType;
+  const unsigned int Dimension = 2;
+  
+  typedef otb::Image<PixelType,Dimension> ImageType;
+  typedef otb::ImageFileWriter<ImageType> WriterType;
+  typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;
+
+  typedef ImageType::PointType PoinType;
+  typedef ImageType::RegionType RegionType;
+  typedef ImageType::SpacingType SpacingType;
+  typedef RegionType::IndexType IndexType;
+  typedef RegionType::SizeType SizeType;
+  typedef ImageType::PointType PointType;
+
+  PointType origin;
+  SpacingType spacing;
+  SizeType size;
+
+  origin[0]= atof(argv[3]);
+  origin[1]= atof(argv[4]);
+  spacing[0]=atof(argv[5]);
+  spacing[1]=atof(argv[6]);
+  size[0]=   atoi(argv[7]);
+  size[1]=   atoi(argv[8]);
+
+  IndexType index;
+  index.Fill(0);
+
+  RegionType region;
+  region.SetIndex(index);
+  region.SetSize(size);
+
+  ImageType::Pointer image = ImageType::New();
+  image->SetRegions(region);
+  image->Allocate();
+  image->FillBuffer(0);
+
+  image->SetOrigin(origin);
+  image->SetSpacing(spacing);
+
+  ossimElevManager * elevManager = ossimElevManager::instance();
+
+  int error = elevManager->openDirectory(srtmDir);
+
+  std::cout<<"Opening srtmDir : "<<error<<std::endl;
+
+
+  IteratorType it(image,image->GetLargestPossibleRegion());
+
+  for(it.GoToBegin();!it.IsAtEnd();++it)
+    {
+      PointType point;
+      image->TransformIndexToPhysicalPoint(it.GetIndex(),point);
+      ossimGpt ossimWorldPoint;
+      ossimWorldPoint.lon=point[0];
+      ossimWorldPoint.lat=point[1];
+      double height = elevManager->getHeightAboveMSL(ossimWorldPoint);
+      if (height!=static_cast<double>(OSSIM_DBL_NAN))
+	  {
+	    // Fill the image
+	    it.Set(height);
+	  } 
+	else 
+	  {
+	    // Back to the MNT default value
+	    it.Set(0);
+	  }
+    }
+
+  WriterType::Pointer writer = WriterType::New();
+  writer->SetInput(image);
+  writer->SetFileName(outfname);
+  writer->Update();
+  
+
+
+  return EXIT_SUCCESS;
+}
-- 
GitLab