From 3e5d461496dd560b6f9acd17cc467f79972c9b45 Mon Sep 17 00:00:00 2001
From: Manuel Grizonnet <manuel.grizonnet@gmail.com>
Date: Tue, 19 Jan 2010 16:09:41 +0100
Subject: [PATCH] ENH:add pixel descriptionin viewer in progress

---
 Code/IO/otbImageMetadataInterfaceBase.cxx | 29 +++++++++++++++++++++++
 Code/IO/otbImageMetadataInterfaceBase.h   |  8 +++++++
 Code/Visualization/otbImageLayer.txx      | 25 +++++++++++++++++++
 Examples/OBIA/otbOBIAExamplesTests.cxx    |  1 -
 4 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/Code/IO/otbImageMetadataInterfaceBase.cxx b/Code/IO/otbImageMetadataInterfaceBase.cxx
index 00e53f7259..4682ed67b3 100755
--- a/Code/IO/otbImageMetadataInterfaceBase.cxx
+++ b/Code/IO/otbImageMetadataInterfaceBase.cxx
@@ -420,6 +420,35 @@ ImageMetadataInterfaceBase::GetBandName( const MetaDataDictionaryType & dict ) c
   return outputValues;
 }
 
+double ImageMetadataInterfaceBase::GetXPixelSpacing( const MetaDataDictionaryType & dict ) const
+{
+  ImageKeywordlistType ImageKeywordlist;
+
+  if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
+  {
+    itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist);
+  }
+  ossimKeywordlist kwl;
+  ImageKeywordlist.convertToOSSIMKeywordlist(kwl);
+  std::string key= "support_data.x_pixel_spacing";
+  ossimString keywordString = kwl.find(key.c_str());
+  return keywordString.toDouble();
+}
+
+double ImageMetadataInterfaceBase::GetYPixelSpacing( const MetaDataDictionaryType & dict ) const
+{
+  ImageKeywordlistType ImageKeywordlist;
+
+  if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey))
+  {
+    itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist);
+  }
+  ossimKeywordlist kwl;
+  ImageKeywordlist.convertToOSSIMKeywordlist(kwl);
+  std::string key= "support_data.y_pixel_spacing";
+  ossimString keywordString = kwl.find(key.c_str());
+  return keywordString.toDouble();
+}
 
 void
 ImageMetadataInterfaceBase::PrintSelf(std::ostream& os, itk::Indent indent, const MetaDataDictionaryType & dict) const
diff --git a/Code/IO/otbImageMetadataInterfaceBase.h b/Code/IO/otbImageMetadataInterfaceBase.h
index 664a4aa06f..147e4c5347 100755
--- a/Code/IO/otbImageMetadataInterfaceBase.h
+++ b/Code/IO/otbImageMetadataInterfaceBase.h
@@ -202,6 +202,14 @@ public:
   virtual VariableLengthVectorType GetLastWavelengths( const MetaDataDictionaryType & dict ) const =0;
   otbMetadataGetMacro(LastWavelengths, VariableLengthVectorType);
 
+  /** Get the x resolution  */
+  double GetXPixelSpacing( const MetaDataDictionaryType & dict ) const;
+  otbMetadataGetMacro(XPixelSpacing, double);
+  
+  /** Get the y resolution  */
+  double GetYPixelSpacing( const MetaDataDictionaryType & dict ) const;
+  otbMetadataGetMacro(YPixelSpacing, double);
+  
   virtual bool CanRead( const MetaDataDictionaryType & dict ) const =0;
 
   virtual void PrintSelf(std::ostream& os, itk::Indent indent, const MetaDataDictionaryType & dict) const;
diff --git a/Code/Visualization/otbImageLayer.txx b/Code/Visualization/otbImageLayer.txx
index dd48a7ad48..b91c5b3f79 100755
--- a/Code/Visualization/otbImageLayer.txx
+++ b/Code/Visualization/otbImageLayer.txx
@@ -26,6 +26,7 @@
 
 #include "otbImageKeywordlist.h"
 // #include "otbCoordinateToName.h"
+#include "otbImageMetadataInterfaceBase.h"
 
 namespace otb
 {
@@ -300,6 +301,30 @@ ImageLayer<TImage,TOutputImage>
       oss << otbGetTextMacro("Location unknown") << std::endl;
     }
   }
+  
+  /** Metadatas typedef */
+  typedef typename ImageMetadataInterfaceBase          ImageMetadataInterfaceType;
+  typedef typename ImageMetadataInterfaceBase::Pointer ImageMetadataInterfacePointerType;
+  // Build the metadata interface
+  ImageMetadataInterfacePointerType lImageMetadata = ImageMetadataInterfaceType::New();
+
+  // Check availability
+  bool mdIsAvailable = lImageMetadata->CanRead(m_Image->GetMetaDataDictionary());
+  
+  if (mdIsAvailable)
+  {
+    double x_spacing = lImageMetadata->GetXPixelSpacing(m_Image->GetMetaDataDictionary());
+    double y_spacing = lImageMetadata->GetYPixelSpacing(m_Image->GetMetaDataDictionary());
+    oss<< "x res: " <<  x_spacing << std::endl;
+    oss<< "y res: " <<  y_spacing << std::endl;
+  }
+  else 
+  {
+    oss << otbGetTextMacro("Resolution unknown") << std::endl;
+  }
+  
+  
+  
   return oss.str();
 }
 
diff --git a/Examples/OBIA/otbOBIAExamplesTests.cxx b/Examples/OBIA/otbOBIAExamplesTests.cxx
index b767454463..08728cc154 100755
--- a/Examples/OBIA/otbOBIAExamplesTests.cxx
+++ b/Examples/OBIA/otbOBIAExamplesTests.cxx
@@ -14,7 +14,6 @@
     PURPOSE.  See the above copyright notices for more information.
 
 =========================================================================*/
-
 // this file defines the otbMultiScaleTest for the test driver
 // and all it expects is that you have a function called RegisterTests
 #if defined(_MSC_VER)
-- 
GitLab