Orfeo Toolbox  3.16
otbChangeScaleActionHandler.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbChangeScaleActionHandler_h
19 #define __otbChangeScaleActionHandler_h
20 
22 
23 namespace otb
24 {
38 template <class TModel, class TView, class TViewToUpdate=TView>
41 {
42 public:
48 
50  itkNewMacro(Self);
51 
54 
56  typedef TModel ModelType;
57  typedef typename ModelType::Pointer ModelPointerType;
58  typedef typename ModelType::RegionType RegionType;
59 
61  typedef TView ViewType;
62  typedef typename ViewType::Pointer ViewPointerType;
63 
64  typedef TViewToUpdate ViewToUpdateType;
65  typedef typename ViewToUpdateType::Pointer ViewToUpdatePointerType;
66 
72  virtual bool HandleWidgetEvent(const std::string& widgetId, int event)
73  {
74  if (m_View.IsNotNull() && m_Model.IsNotNull() && this->GetIsActive())
75  {
76  if (widgetId == m_View->GetZoomWidget()->GetIdentifier()
77  && event == FL_MOUSEWHEEL)
78  {
80  << "ChangeScaleActionHandler::HandleWidgetEvent(): handling (" << widgetId << ", " << event << ")");
81  // Get the mousewhell offset
82  int dy = Fl::event_dy();
83 
84  // Compute new scale
85  double newScale = m_View->GetZoomWidget()->GetIsotropicZoom() * vcl_pow(m_ScaleRatio, -dy);
86 
87  if (newScale >= 1.0 )
88  {
89  // compute the new size of the extracted region, if less than
90  // 1 pixel dont allow the zoom
91  double sizex = m_View->GetZoomWidget()->w() / newScale;
92  double sizey = m_View->GetZoomWidget()->h() / newScale;
93 
94  if (sizex > 1. && sizey >1.)
95  {
96  m_View->GetZoomWidget()->SetIsotropicZoom(newScale);
97 
98  // If set, update the IsotropicZoom of the second view
99  if(m_ViewToUpdate.IsNotNull())
100  {
101  m_ViewToUpdate->GetZoomWidget()->SetIsotropicZoom(newScale);
102  }
103 
104  RegionType region = m_Model->GetScaledExtractRegion();
105 
106  typename RegionType::IndexType index = region.GetIndex();
107  typename RegionType::SizeType size = region.GetSize();
108  index[0] += size[0] / 2;
109  index[1] += size[1] / 2;
110  size[0] = static_cast<unsigned int>(m_View->GetZoomWidget()->w() / m_View->GetZoomWidget()->GetIsotropicZoom());
111  size[1] = static_cast<unsigned int>(m_View->GetZoomWidget()->h() / m_View->GetZoomWidget()->GetIsotropicZoom());
112  region.SetSize(size);
113  m_Model->SetScaledExtractRegion(region);
114  m_Model->SetScaledExtractRegionCenter(index);
115  // Update the model
116  m_Model->Update();
117  }
118  }
119  return true;
120  }
121  }
122  return false;
123  }
124 
126  itkSetObjectMacro(View, ViewType);
127  itkGetObjectMacro(View, ViewType);
128 
129  itkSetObjectMacro(ViewToUpdate, ViewToUpdateType);
130  itkGetObjectMacro(ViewToUpdate, ViewToUpdateType);
131 
133  itkSetObjectMacro(Model, ModelType);
134  itkGetObjectMacro(Model, ModelType);
135 
137  itkSetMacro(ScaleRatio, double);
138  itkGetMacro(ScaleRatio, double);
139 
140 protected:
143  {
145  }
146 
150  void PrintSelf(std::ostream& os, itk::Indent indent) const
151  {
152  Superclass::PrintSelf(os, indent);
153  }
154 
155 private:
156  ChangeScaleActionHandler(const Self&); // purposely not implemented
157  void operator =(const Self&); // purposely not implemented
158 
159  // Pointer to the view
162 
163  // Pointer to the model
165 
167  double m_ScaleRatio;
168 
169 }; // end class
170 } // end namespace otb
171 #endif

Generated at Sun Feb 3 2013 00:18:59 for Orfeo Toolbox with doxygen 1.8.1.1