From 125e3c100954f598657284ba793fb3cfbfb73e92 Mon Sep 17 00:00:00 2001
From: Guillaume Borrut <guillaume.borrut@c-s.fr>
Date: Tue, 17 Mar 2009 16:38:26 +0100
Subject: [PATCH] ENH: Adding clearBuffer method for the otbImageWidgets

---
 Code/Visualization/otbImageLayer.txx  |  1 +
 Code/Visualization/otbImageView.h     |  3 +++
 Code/Visualization/otbImageWidget.h   |  3 +++
 Code/Visualization/otbImageWidget.txx | 39 +++++++++++++++++++--------
 4 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/Code/Visualization/otbImageLayer.txx b/Code/Visualization/otbImageLayer.txx
index 2e2da6b22f..6b906fe09d 100644
--- a/Code/Visualization/otbImageLayer.txx
+++ b/Code/Visualization/otbImageLayer.txx
@@ -104,6 +104,7 @@ ImageLayer<TImage,TOutputImage>
     {
     itk::TimeProbe probe;
     probe.Start();
+    std::cout<<"Extent: "<<this->GetExtent()<<" Largest: "<<m_Image->GetLargestPossibleRegion()<<" ExtractRegion: "<<this->GetExtractRegion()<<std::endl;
     m_ExtractRenderingFilter->GetOutput()->SetRequestedRegion(this->GetExtractRegion());
     m_ExtractRenderingFilter->Update();
     this->SetRenderedExtract(m_ExtractRenderingFilter->GetOutput());
diff --git a/Code/Visualization/otbImageView.h b/Code/Visualization/otbImageView.h
index abec552586..582536e9fc 100644
--- a/Code/Visualization/otbImageView.h
+++ b/Code/Visualization/otbImageView.h
@@ -93,6 +93,9 @@ public:
   itkGetObjectMacro(FullWidget,ImageWidgetType);
   itkGetObjectMacro(ZoomWidget,ImageWidgetType);
 
+  /** Clear the widgets buffers  */
+  void ClearBuffer();
+
  protected:
   /** Constructor */
   ImageView();
diff --git a/Code/Visualization/otbImageWidget.h b/Code/Visualization/otbImageWidget.h
index 46c1a59b34..b77ba1b4d6 100644
--- a/Code/Visualization/otbImageWidget.h
+++ b/Code/Visualization/otbImageWidget.h
@@ -84,6 +84,9 @@ public:
    */
   virtual void ReadBuffer(const InputImageType * image, const RegionType & region);
 
+  /** Clear the OpenGl buffer */
+  void ClearBuffer();
+
   /** Set/Get the Isotropic zoom */
   itkSetMacro(IsotropicZoom,double);
   itkGetMacro(IsotropicZoom,double);
diff --git a/Code/Visualization/otbImageWidget.txx b/Code/Visualization/otbImageWidget.txx
index 86337e5d07..a75816b1e0 100644
--- a/Code/Visualization/otbImageWidget.txx
+++ b/Code/Visualization/otbImageWidget.txx
@@ -41,12 +41,7 @@ template <class TInputImage>
 ImageWidget<TInputImage>
 ::~ImageWidget()
 {
-  // Delete OpenGl buffer if needed
-  if(m_OpenGlBuffer!=NULL)
-    {
-    delete [] m_OpenGlBuffer;
-    m_OpenGlBuffer = NULL;
-    }
+  this->ClearBuffer();
 }
 
 template <class TInputImage>
@@ -82,11 +77,8 @@ ImageWidget<TInputImage>
     itkExceptionMacro(<<"Region to read is oustside of the buffered region.");
     }
   // Delete previous buffer if needed
-  if(m_OpenGlBuffer != NULL)
-    {
-    delete [] m_OpenGlBuffer;
-    m_OpenGlBuffer = NULL;
-    }
+  this->ClearBuffer();
+
   // Allocate new memory
   m_OpenGlBuffer = new unsigned char[3*region.GetNumberOfPixels()];
 
@@ -122,6 +114,31 @@ ImageWidget<TInputImage>
   m_OpenGlBufferedRegion = region;
 }
 
+template <class TInputImage>
+void
+ImageWidget<TInputImage>
+::ClearBuffer()
+{
+  // Delete previous buffer if needed
+  if(m_OpenGlBuffer != NULL)
+    {
+    delete [] m_OpenGlBuffer;
+    m_OpenGlBuffer = NULL;
+    }
+
+  RegionType region;
+  typename RegionType::IndexType index;
+  typename RegionType::SizeType  size;
+  size.Fill(0);
+  index.Fill(0);
+  region.SetIndex(index);
+  region.SetSize(size);
+
+  // Last, updating buffer size
+  m_OpenGlBufferedRegion = region;
+
+}
+
 template <class TInputImage>
 void
 ImageWidget<TInputImage>
-- 
GitLab