From 92ba553e8d5823ebf7be7bf4fee1cf5180a30f3e Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@cnes.fr>
Date: Mon, 10 Oct 2016 17:03:20 +0200
Subject: [PATCH] BUG: Prevent UpdateResolution to read back geometry at each
 call (fix 1287)

---
 .../Visualization/Ice/src/otbGlImageActor.cxx | 39 +++++++++++--------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/Modules/Visualization/Ice/src/otbGlImageActor.cxx b/Modules/Visualization/Ice/src/otbGlImageActor.cxx
index 6298db6920..cbe8fc6b06 100644
--- a/Modules/Visualization/Ice/src/otbGlImageActor.cxx
+++ b/Modules/Visualization/Ice/src/otbGlImageActor.cxx
@@ -139,7 +139,8 @@ void GlImageActor::Initialize(const std::string & filename)
 
   m_FileReader = ReaderType::New();
   m_FileReader->SetFileName(m_FileName);
-  m_FileReader->UpdateOutputInformation();
+  m_FileReader->GetOutput()->UpdateOutputInformation();
+  std::cout<<"GlImageActor::Initialize"<<std::endl;
 
   m_LargestRegion = m_FileReader->GetOutput()->GetLargestPossibleRegion();
 
@@ -983,7 +984,7 @@ void GlImageActor::UpdateResolution()
 
   // Arbitrary higher than any distance we will compute here
   double minDist = 50000.;
-  m_CurrentResolution = 0;
+  unsigned int newResolution = 0;
 
   // OTB always include full resolution level in available resolutions.
   assert( !m_AvailableResolutions.empty() );
@@ -1015,9 +1016,9 @@ void GlImageActor::UpdateResolution()
 	isFound = true;
 
 	minDist = vcl_abs(diff);
-	m_CurrentResolution = std::distance(m_AvailableResolutions.begin(),it);
+	newResolution = std::distance(m_AvailableResolutions.begin(),it);
 
-	// std::cout << "found: " << m_CurrentResolution << std::endl;
+	// std::cout << "found: " << newResolution << std::endl;
 	}
       }
 
@@ -1026,23 +1027,29 @@ void GlImageActor::UpdateResolution()
       {
       assert( m_AvailableResolutions.size() > 0 );
 
-      m_CurrentResolution = m_AvailableResolutions.size() - 1;
+      newResolution = m_AvailableResolutions.size() - 1;
 
       // std::cout << "not found: " << m_CurrentResolution << std::endl;
       }
     }
 
-  std::ostringstream extFilename;
-  extFilename<<m_FileName<<"?&resol="<<m_CurrentResolution;
-
-  // ReaderType::New() is forced because of warning message
-  // 'Duplicated option detected: <option>. Using value <value>.'
-  // output by otb::ExtendedFilenameHelper.
-  m_FileReader = ReaderType::New();
-  m_FileReader->SetFileName(extFilename.str());
-  m_FileReader->UpdateOutputInformation();
-
-  // std::cout << "Switched to resolution: " << m_CurrentResolution << std::endl;
+  if(newResolution != m_CurrentResolution)
+    {
+    m_CurrentResolution = newResolution;
+    
+    std::ostringstream extFilename;
+    extFilename<<m_FileName<<"?&resol="<<m_CurrentResolution;
+
+    // ReaderType::New() is forced because of warning message
+    // 'Duplicated option detected: <option>. Using value <value>.'
+    // output by otb::ExtendedFilenameHelper.
+    m_FileReader = ReaderType::New();
+    m_FileReader->SetFileName(extFilename.str());
+    m_FileReader->GetOutput()->UpdateOutputInformation();
+    std::cout<<"GlImageActor::UpdateResolution"<<std::endl;
+  // std::cout << "Switched to resolution: " << m_CurrentResolution <<
+  // std::endl;
+    }
 }
 
 void GlImageActor::UpdateTransforms()
-- 
GitLab