From ca4aec9f6f745d780d05a59950a050c1eefb2c87 Mon Sep 17 00:00:00 2001
From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Date: Thu, 12 Nov 2009 11:14:19 +0800
Subject: [PATCH] ENH: adding fun info on the viewer

---
 Code/Projections/otbCoordinateToName.cxx |  2 ++
 Code/Projections/otbCoordinateToName.h   | 28 ++++++++++++++++++++++++
 Code/Visualization/otbImageLayer.h       |  3 +++
 Code/Visualization/otbImageLayer.txx     | 23 ++++++++++---------
 4 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/Code/Projections/otbCoordinateToName.cxx b/Code/Projections/otbCoordinateToName.cxx
index 669f018277..48fa198ec4 100644
--- a/Code/Projections/otbCoordinateToName.cxx
+++ b/Code/Projections/otbCoordinateToName.cxx
@@ -37,6 +37,8 @@ CoordinateToName::CoordinateToName():
 
   m_Threader = itk::MultiThreader::New();
 
+  m_UpdateDistance = 0.01;//about 1km at equator
+
 }
 
 /**
diff --git a/Code/Projections/otbCoordinateToName.h b/Code/Projections/otbCoordinateToName.h
index d55718cfbf..c1835def41 100644
--- a/Code/Projections/otbCoordinateToName.h
+++ b/Code/Projections/otbCoordinateToName.h
@@ -20,6 +20,7 @@
 
 #include "itkObject.h"
 #include "itkObjectFactory.h"
+#include "itkPoint.h"
 #include "itkMultiThreader.h"
 
 namespace otb
@@ -50,12 +51,36 @@ public:
   /** Method for creation through the object factory. */
   itkNewMacro(Self);
 
+  typedef itk::Point<double,2>              PointType;
+
   itkGetMacro( Lon, double );
   itkGetMacro( Lat, double );
 
   itkSetMacro( Lon, double );
   itkSetMacro( Lat, double );
 
+  /**
+   * Set the lon/lat only if they are far enough from the current point to
+   * avoid triggering too many updates
+   */
+  bool SetLonLat(PointType point)
+  {
+    if ((vcl_abs(point[0] - m_Lon) > m_UpdateDistance) || (vcl_abs(point[1] - m_Lat) > m_UpdateDistance))
+    {
+      std::cout << "Update lon/lat " << m_Lon << ", " << m_Lat << " -> " << point << std::endl;
+      m_Lon = point[0];
+      m_Lat = point[1];
+      //TODO Check whether it is better to have something imprecise or nothing at all
+      m_IsValid = false;
+      return true;
+    }
+    else
+    {
+      std::cout << "Keeping lon/lat" << std::endl;
+      return false;
+    }
+  }
+
   std::string GetPlaceName() const
   {
     if (m_IsValid)
@@ -105,6 +130,9 @@ private:
   double m_Lat;
   bool m_Multithread;
   bool m_IsValid;
+  //Minimum distance to trigger an update of the coordinates
+  //specified in degrees
+  double m_UpdateDistance;
 
   std::string m_PlaceName;
   std::string m_CountryName;
diff --git a/Code/Visualization/otbImageLayer.h b/Code/Visualization/otbImageLayer.h
index 5c87ff1f5b..88cfff086a 100644
--- a/Code/Visualization/otbImageLayer.h
+++ b/Code/Visualization/otbImageLayer.h
@@ -29,6 +29,8 @@
 #include "otbRenderingImageFilter.h"
 #include "otbGenericRSTransform.h"
 
+#include "otbCoordinateToName.h"
+
 namespace otb
 {
 /** \class ImageLayer
@@ -246,6 +248,7 @@ private:
 
   /** Coordinate transform */
   TransformType::Pointer m_Transform;
+  CoordinateToName::Pointer m_CoordinateToName;
 
   /** General info about the image*/
   std::string m_PlaceName;//FIXME the call should be done by a more general method outside of the layer
diff --git a/Code/Visualization/otbImageLayer.txx b/Code/Visualization/otbImageLayer.txx
index a75e08af3a..7329ad3a83 100644
--- a/Code/Visualization/otbImageLayer.txx
+++ b/Code/Visualization/otbImageLayer.txx
@@ -59,6 +59,7 @@ ImageLayer<TImage,TOutputImage>
   m_ScaledExtractRenderingFilter->SetInput(m_ScaledExtractFilter->GetOutput());
 
   m_Transform = TransformType::New();
+  m_CoordinateToName = CoordinateToName::New();
 
   m_PlaceName = "";
   m_CountryName = "";
@@ -273,18 +274,16 @@ ImageLayer<TImage,TOutputImage>
       if (m_Transform->GetTransformAccuracy() == Projection::PRECISE) oss<< "(precise location)" << std::endl;
       if (m_Transform->GetTransformAccuracy() == Projection::ESTIMATE) oss<< "(estimated location)" << std::endl;
 
-//       if ((m_PlaceName == "") && (m_CountryName == ""))
-//       {
-//         CoordinateToName::Pointer conv = CoordinateToName::New();
-//         conv->SetLon(point[0]);
-//         conv->SetLat(point[1]);
-//         conv->Evaluate();
-//
-//         m_PlaceName = conv->GetPlaceName();
-//         m_CountryName = conv->GetCountryName();
-//       }
-//       if (m_PlaceName != "") oss << "Near " << m_PlaceName;
-//       if (m_CountryName != "") oss << " in " << m_CountryName;
+      if (m_CoordinateToName->SetLonLat(point))
+      {
+         m_CoordinateToName->Evaluate();
+      }
+
+      m_PlaceName = m_CoordinateToName->GetPlaceName();
+      m_CountryName = m_CoordinateToName->GetCountryName();
+
+      if (m_PlaceName != "") oss << "Near " << m_PlaceName;
+      if (m_CountryName != "") oss << " in " << m_CountryName;
     }
     else
     {
-- 
GitLab