Orfeo Toolbox  3.16
otbHistogramActionHandler.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 __otbHistogramActionHandler_h
19 #define __otbHistogramActionHandler_h
20 
21 #include "otbCurves2DWidget.h"
23 #include "itkNumericTraits.h"
24 
25 namespace otb
26 {
35 template <class TModel, class TView, class TRenderingFunction>
38 {
39 public:
45 
47  itkNewMacro(Self);
48 
51 
53  typedef TModel ModelType;
54  typedef typename ModelType::Pointer ModelPointerType;
55  typedef typename ModelType::RegionType RegionType;
56 
58  typedef TView ViewType;
59  typedef typename ViewType::Pointer ViewPointerType;
60  typedef typename ViewType::ImageWidgetType::PointType PointType;
61 
65 
67  typedef TRenderingFunction RenderingFunctionType;
68  typedef typename RenderingFunctionType::Pointer RenderingFunctionPointerType;
69  typedef typename RenderingFunctionType::ParametersType ParametersType;
70 
74 
79  virtual bool HandleWidgetEvent(const std::string& widgetId, int event)
80  {
81  // Variable declaration
82  PointType spacePoint;
83  spacePoint.Fill(0);
84 
85  // Left screen abcisse
86  spacePoint[0] = m_LeftAsymptote->GetAbcisse();
87  double abcisseL = m_Curve->TransformPoint(spacePoint)[0];
88 
89  // Right screen abcisse
90  spacePoint[0] = m_RightAsymptote->GetAbcisse();
91  double abcisseR = m_Curve->TransformPoint(spacePoint)[0];
92 
93  spacePoint[0] = m_MinimumAbcisse;
94  double minScreenAbs = m_Curve->TransformPoint(spacePoint)[0];
95 
96  spacePoint[0] = m_MaximumAbcisse;
97  double maxScreenAbs = m_Curve->TransformPoint(spacePoint)[0];
98 
99 
100  if (widgetId == m_Curve->GetIdentifier() && this->GetIsActive())
101  {
102  switch (event)
103  {
104  case FL_PUSH:
105  {
106  // Position Clicked
107  double x = Fl::event_x();
108 
109  if ((vcl_abs(x - abcisseL) < 50) || (vcl_abs(x - abcisseR) < 50))
110  {
111  if (vcl_abs(x - abcisseL) < vcl_abs(x - abcisseR))
112  {
113  m_ModifyLeft = true;
114  }
115  else
116  {
117  m_ModifyRight = true;
118  }
119  }
120  return true;
121  }
122  case FL_RELEASE:
123  {
124  if (m_ModifyLeft || m_ModifyRight)
125  {
126  m_Model->Update();
127  }
128 
129  m_ModifyLeft = false;
130  m_ModifyRight = false;
131  return true;
132  }
133  case FL_DRAG:
134  {
135  double x = Fl::event_x();
136 
137  if (m_ModifyLeft)
138  {
139  double newLeftAbcisse = m_MinimumAbcisse
140  + (m_MaximumAbcisse - m_MinimumAbcisse) / (maxScreenAbs - minScreenAbs) * (x - minScreenAbs);
141  if ( newLeftAbcisse < m_RightAsymptote->GetAbcisse()
142  && newLeftAbcisse >= m_MinimumAbcisse)
143  {
144  m_LeftAsymptote->SetAbcisse(newLeftAbcisse);
145  m_Curve->redraw();
146 
147  // Update The Rendering Function min and max
148  ParametersType param = m_RenderingFunction->GetParameters();
149  param.SetElement(2 * m_Channel, newLeftAbcisse);
150  param.SetElement(2 * m_Channel + 1, m_RightAsymptote->GetAbcisse());
151  m_RenderingFunction->SetParameters(param);
152  }
153  }
154 
155  if (m_ModifyRight)
156  {
157  double newRightAbcisse = m_MinimumAbcisse
158  + (m_MaximumAbcisse - m_MinimumAbcisse) / (maxScreenAbs - minScreenAbs) * (x - minScreenAbs);
159  if (newRightAbcisse > m_LeftAsymptote->GetAbcisse()
160  && newRightAbcisse < m_MaximumAbcisse)
161  {
162  m_RightAsymptote->SetAbcisse(newRightAbcisse);
163  m_Curve->redraw();
164 
165  // Update The Rendering Function min and max
166  ParametersType param = m_RenderingFunction->GetParameters();
167  param.SetElement(2 * m_Channel, m_LeftAsymptote->GetAbcisse());
168  param.SetElement(2 * m_Channel + 1, newRightAbcisse);
169  m_RenderingFunction->SetParameters(param);
170  }
171  }
172  return true;
173  }
174  }
175  }
176  return false;
177  }
178 
180  itkSetObjectMacro(View, ViewType);
181  itkGetObjectMacro(View, ViewType);
182 
184  itkSetObjectMacro(Model, ModelType);
185  itkGetObjectMacro(Model, ModelType);
186 
188  itkSetObjectMacro(Curve, CurveWidgetType);
189 
191  itkSetObjectMacro(LeftAsymptote, VerticalAsymptoteType);
192  itkSetObjectMacro(RightAsymptote, VerticalAsymptoteType);
193 
195  itkSetObjectMacro(RenderingFunction, RenderingFunctionType);
196 
200  itkSetMacro(MaximumAbcisse, double);
201  itkSetMacro(MinimumAbcisse, double);
202 
204  itkSetMacro(Channel, unsigned int);
205 
206 protected:
208  HistogramActionHandler() : m_View(), m_Model(), m_RenderingFunction()
209  {
210  m_Channel = 0;
211  m_ModifyLeft = false;
212  m_ModifyRight = false;
213  m_MaximumAbcisse = itk::NumericTraits<double>::max();
214  m_MinimumAbcisse = itk::NumericTraits<double>::NonpositiveMin();
215  }
216 
220  void PrintSelf(std::ostream& os, itk::Indent indent) const
221  {
222  Superclass::PrintSelf(os, indent);
223  }
224 
225 private:
226  HistogramActionHandler(const Self &); // purposely not implemented
227  void operator =(const Self&); // purposely not implemented
228 
229  // Pointer to the view
231 
232  // Pointer to the model
234 
235  // Curve Widget To Handle Events on
237 
238  // StandardRenderingFunction
240 
241  // Left And Rigth Asymptote
244 
245  // Flags
248 
249  //Channel we're dealing handling
250  unsigned int m_Channel;
251 
252  // extremum of the histogram used as limit for the abcisse
255 
256 }; // end class
257 } // end namespace otb
258 #endif

Generated at Sun Feb 3 2013 00:25:20 for Orfeo Toolbox with doxygen 1.8.1.1