From 56f8cdc732944bc5b2f52e65c37ed58d1f9e5cf8 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@c-s.fr>
Date: Mon, 1 Sep 2008 16:42:19 +0000
Subject: [PATCH] correction bugs

---
 Code/Visu/otbFullResolutionImageWidget.h      |  2 +-
 Code/Visu/otbImageViewerBase.txx              | 44 ++++++++++---------
 ...ImageViewerFullResolutionEventsInterface.h |  7 ++-
 Code/Visu/otbImageViewerFullWidget.h          | 24 ++++++++--
 .../Projections/OrthoRectificationExample.cxx |  6 +--
 5 files changed, 53 insertions(+), 30 deletions(-)

diff --git a/Code/Visu/otbFullResolutionImageWidget.h b/Code/Visu/otbFullResolutionImageWidget.h
index 02f2106fc6..e58f79fa9a 100644
--- a/Code/Visu/otbFullResolutionImageWidget.h
+++ b/Code/Visu/otbFullResolutionImageWidget.h
@@ -62,7 +62,7 @@ class FullResolutionImageWidget
    * Set upper left corner position in image.
    * \param index the upper left corner index.
    */
-  void SetUpperLeftCorner(IndexType index);
+  virtual void SetUpperLeftCorner(IndexType index);
   itkGetMacro(UpperLeftCorner,IndexType);
 
  protected:
diff --git a/Code/Visu/otbImageViewerBase.txx b/Code/Visu/otbImageViewerBase.txx
index 16fa22b4c7..18213d2436 100644
--- a/Code/Visu/otbImageViewerBase.txx
+++ b/Code/Visu/otbImageViewerBase.txx
@@ -851,31 +851,35 @@ template <class TPixel, class TLabel>
   ImageViewerBase<TPixel,TLabel>
 ::ChangeZoomViewedRegion(IndexType clickedIndex)
 { 
+
   m_Updating = true;
   //comment: std::cout<<"ChangeZoomViewedRegion: "<<m_Label<<" Updating flag on"<<std::endl;
-  RegionType region = m_ZoomWidget->GetViewedRegion();
-  IndexType newIndex;
-  newIndex[0]=clickedIndex[0]-region.GetSize()[0]/2;
-  newIndex[1]=clickedIndex[1]-region.GetSize()[1]/2;
- 
-  region.SetIndex(newIndex);
-  RegionType newRegion = ComputeConstrainedRegion(region,m_FullWidget->GetViewedRegion());
-  m_ZoomWidget->SetZoomUpperLeftCorner(newRegion.GetIndex());
- 
-  typename ViewerListType::Iterator linkedIt = m_LinkedViewerList->Begin();
-  typename OffsetListType::iterator offIt = m_LinkedViewerOffsetList.begin();
-  
-  while(linkedIt!=m_LinkedViewerList->End()&&offIt!=m_LinkedViewerOffsetList.end())
+  if(m_ShowZoomWidget)
     {
-      if(!linkedIt.Get()->GetUpdating())
+      RegionType region = m_ZoomWidget->GetViewedRegion();
+      IndexType newIndex;
+      newIndex[0]=clickedIndex[0]-region.GetSize()[0]/2;
+      newIndex[1]=clickedIndex[1]-region.GetSize()[1]/2;
+      
+      region.SetIndex(newIndex);
+      RegionType newRegion = ComputeConstrainedRegion(region,m_FullWidget->GetViewedRegion());
+      m_ZoomWidget->SetZoomUpperLeftCorner(newRegion.GetIndex());
+      
+      typename ViewerListType::Iterator linkedIt = m_LinkedViewerList->Begin();
+      typename OffsetListType::iterator offIt = m_LinkedViewerOffsetList.begin();
+      
+      while(linkedIt!=m_LinkedViewerList->End()&&offIt!=m_LinkedViewerOffsetList.end())
 	{
-	  IndexType linkedIndex;
-	  linkedIndex[0] = clickedIndex[0]+(*offIt)[0];
-	  linkedIndex[1] = clickedIndex[1]+(*offIt)[1];
-	  linkedIt.Get()->ChangeZoomViewedRegion(linkedIndex);
+	  if(!linkedIt.Get()->GetUpdating())
+	    {
+	      IndexType linkedIndex;
+	      linkedIndex[0] = clickedIndex[0]+(*offIt)[0];
+	      linkedIndex[1] = clickedIndex[1]+(*offIt)[1];
+	      linkedIt.Get()->ChangeZoomViewedRegion(linkedIndex);
+	    }
+	  ++offIt;
+	  ++linkedIt;			    
 	}
-      ++offIt;
-      ++linkedIt;			    
     }
   //comment: std::cout<<"ChangeZoomViewedRegion: "<<m_Label<<" Updating flag off"<<std::endl;
   m_Updating = false; 
diff --git a/Code/Visu/otbImageViewerFullResolutionEventsInterface.h b/Code/Visu/otbImageViewerFullResolutionEventsInterface.h
index f36f185433..f2feb9eb8b 100644
--- a/Code/Visu/otbImageViewerFullResolutionEventsInterface.h
+++ b/Code/Visu/otbImageViewerFullResolutionEventsInterface.h
@@ -38,13 +38,16 @@ class ImageViewerFullResolutionEventsInterface
   itkTypeMacro(ImageViewerFullResolutionEventsInterface,Superclass);
 
   typedef itk::ImageRegion<2> RegionType;
+  typedef RegionType::IndexType IndexType;
 
   itkSetMacro(ForwardEvents,bool);
   itkGetMacro(ForwardEvents,bool);
 
   /** Users actions */
-  virtual void RegionSelected(const RegionType & region) = 0;
-  
+  virtual void RegionSelected(const RegionType & region){};
+  virtual void ViewedRegionChanged(){};
+  virtual void PixelClicked(const IndexType& index){};
+
  protected:
   /** Constructor */
   ImageViewerFullResolutionEventsInterface()
diff --git a/Code/Visu/otbImageViewerFullWidget.h b/Code/Visu/otbImageViewerFullWidget.h
index 750306b2d8..e3a6546063 100644
--- a/Code/Visu/otbImageViewerFullWidget.h
+++ b/Code/Visu/otbImageViewerFullWidget.h
@@ -82,7 +82,17 @@ class ITK_EXPORT ImageViewerFullWidget
   itkGetMacro(Parent,ParentPointerType);
   itkGetObjectMacro(EventsInterface,EventsInterfaceType);
   itkSetObjectMacro(EventsInterface,EventsInterfaceType);
-  /** Handle method */
+ 
+ virtual void SetUpperLeftCorner(IndexType index)
+ {
+   Superclass::SetUpperLeftCorner(index);
+   if(m_EventsInterface.IsNotNull())
+     {
+       m_EventsInterface->ViewedRegionChanged();
+     }
+ }
+ 
+ /** Handle method */
   
   
   /** Default mode handling, without ROI selection */
@@ -99,8 +109,16 @@ class ITK_EXPORT ImageViewerFullWidget
 	  clickedIndex[0]=x;
 	  clickedIndex[1]=y;
           clickedIndex=this->WindowToImageCoordinates(clickedIndex);
-          m_Parent->ChangeZoomViewedRegion(clickedIndex);
-          m_Parent->Update();
+
+	  if(m_EventsInterface.IsNotNull())
+	  {
+	    m_EventsInterface->PixelClicked(clickedIndex);
+	  }
+	  if(m_EventsInterface.IsNotNull() && m_EventsInterface->GetForwardEvents())
+	  {
+	    m_Parent->ChangeZoomViewedRegion(clickedIndex);
+	    m_Parent->Update();
+	  }
           return 1;
           }
        case FL_KEYDOWN:
diff --git a/Examples/Projections/OrthoRectificationExample.cxx b/Examples/Projections/OrthoRectificationExample.cxx
index 06239c29b6..bdf9c7289b 100644
--- a/Examples/Projections/OrthoRectificationExample.cxx
+++ b/Examples/Projections/OrthoRectificationExample.cxx
@@ -81,10 +81,8 @@ int main( int argc, char* argv[] )
 
 
 
-   
-  typedef otb::Image<unsigned char, 2>    CharImageType;
-  typedef otb::Image<unsigned int, 2>     ImageType;
-  typedef otb::VectorImage<unsigned int, 2>     VectorImageType;
+  typedef otb::Image<int, 2>     ImageType;
+  typedef otb::VectorImage<int, 2>     VectorImageType;
   typedef otb::ImageFileReader<VectorImageType>  ReaderType;
   typedef otb::StreamingImageFileWriter<VectorImageType>  WriterType;
 
-- 
GitLab