Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OverviewCameraTool.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
23 #ifdef _WIN32
24 #include "wx/msw/wrapwin.h"
25 #endif
26 #include "OverviewCameraTool.h"
27 #include "GLViewer.h"
28 
31 
33 {
38  down = false;
39 }
40 
41 
42 
43 void PanosphereOverviewCameraTool::MouseMoveEvent(double x, double y, wxMouseEvent & e)
44 {
45  if (down)
46  {
47  if (e.ButtonIsDown(wxMOUSE_BTN_ANY))
48  {
51  //FIXME: include a scale factor for the panosphere
52  double scale = (state->getR() - state->getSphereRadius()) / 40000.0;
53  if (state->isInsideView())
54  {
55  if (e.ButtonIsDown(wxMOUSE_BTN_MIDDLE))
56  {
57  // invert mouse for middle button panning in inside view
58  state->setAngX(start_angx - (pos.x - start_x) * scale);
59  double ey = (pos.y - start_y) * scale + start_angy;
60  if (ey >= M_PI / 2.0) { ey = M_PI / 2.0 - 0.0001; }
61  if (ey <= -M_PI / 2.0) { ey = -M_PI / 2.0 + 0.0001; }
62  state->setAngY(ey);
63  }
64  else
65  {
66  state->setAngX((pos.x - start_x) * scale + start_angx);
67  double ey = start_angy - (pos.y - start_y) * scale;
68  if (ey >= M_PI / 2.0) { ey = M_PI / 2.0 - 0.0001; }
69  if (ey <= -M_PI / 2.0) { ey = -M_PI / 2.0 + 0.0001; }
70  state->setAngY(ey);
71  };
72  }
73  else
74  {
75  // outside view
76  state->setAngX((pos.x - start_x) * scale + start_angx);
77  double ey = (pos.y - start_y) * scale + start_angy;
78  if (ey >= M_PI / 2.0) { ey = M_PI / 2.0 - 0.0001; }
79  if (ey <= -M_PI / 2.0) { ey = -M_PI / 2.0 + 0.0001; }
80  state->setAngY(ey);
81  };
82  state->Redraw();
83  }
84  else
85  {
86  // no button pressed any more, reset flag
87  down = false;
88  };
89  };
90 }
91 
93 {
94 // DEBUG_DEBUG("mouse ov drag button");
95  if (e.ButtonDown())
96  {
98  if (state->isInsideView() || (!helper->IsMouseOverPano() || e.CmdDown() || e.AltDown() || e.MiddleDown()))
99  {
100  down = true;
102  start_x = pos.x;
103  start_y = pos.y;
104  start_angx = state->getAngX();
105  start_angy = state->getAngY();
106  };
107  };
108  if (e.ButtonUp())
109  {
110  if (down)
111  {
112  down = false;
113  };
114  };
115 }
116 
117 
118 void PanosphereOverviewCameraTool::ChangeZoomLevel(bool zoomIn, double scale) {
120  double radius = state->getSphereRadius();
121  if (zoomIn) {
122  if (state->getR() > limit_low * radius) {
123  state->setR((state->getR() - radius) / scale + radius);
124  state->SetDirtyViewport();
125  state->ForceRequireRedraw();
126  state->Redraw();
127  }
128  } else {
129  if (state->getR() < limit_high * radius) {
130  state->setR((state->getR() - radius) * scale + radius);
131  state->SetDirtyViewport();
132  state->ForceRequireRedraw();
133  state->Redraw();
134  }
135  }
136 }
137 
139 {
141  if (zoomIn)
142  {
143  state->setFOV(state->getFOV() / 1.1);
144  state->SetDirtyViewport();
145  state->ForceRequireRedraw();
146  state->Redraw();
147  }
148  else
149  {
150  state->setFOV(state->getFOV() * 1.1);
151  state->SetDirtyViewport();
152  state->ForceRequireRedraw();
153  state->Redraw();
154  };
155 }
157 {
158  if (e.GetWheelRotation() != 0)
159  {
160  if (static_cast<PanosphereOverviewVisualizationState*>(helper->GetVisualizationStatePtr())->isInsideView())
161  {
162  ChangeFOV(e.GetWheelRotation() > 0);
163  }
164  else
165  {
166  ChangeZoomLevel(e.GetWheelRotation() > 0);
167  };
168  }
169 }
170 
171 void PanosphereOverviewCameraTool::KeypressEvent(int keycode, int modifiers, bool pressed) {
172 // std::cout << "kc: " << keycode << " " << modifiers << std::endl;
173 // std::cout << "cmd: " << wxMOD_CMD << " " << wxMOD_CONTROL << " " << WXK_ADD << " " << WXK_SUBTRACT << std::endl;
174 // std::cout << "cmd: " << wxMOD_CMD << " " << wxMOD_CONTROL << " " << WXK_NUMPAD_ADD << " " << WXK_NUMPAD_SUBTRACT << std::endl;
175  if (pressed)
176  if (modifiers == wxMOD_CMD) {
177  if (keycode == WXK_ADD) {
178  ChangeZoomLevel(true);
179  } else if (keycode == WXK_SUBTRACT) {
180  ChangeZoomLevel(false);
181  }
182  }
183 }
184 
186 {
190  down = false;
191 }
192 
193 void PlaneOverviewCameraTool::MouseMoveEvent(double x, double y, wxMouseEvent & e)
194 {
195  if (down) {
197 //
198  //same code as in tool helper to get position on the z-plane but with initial position
199  double d = state->getR();
200 
201  int tcanv_w, tcanv_h;
202  state->GetViewer()->GetClientSize(&tcanv_w,&tcanv_h);
203 
204  double canv_w, canv_h;
205  canv_w = tcanv_w;
206  canv_h = tcanv_h;
207 
208  double fov = state->getFOV();
209 
210  double fovy, fovx;
211  if (canv_w > canv_h) {
212  fovy = DEG_TO_RAD(fov);
213  fovx = 2 * atan( tan(fovy / 2.0) * canv_w / canv_h);
214  } else {
215  fovx = DEG_TO_RAD(fov);
216  fovy = 2 * atan( tan(fovx / 2.0) * canv_h / canv_w);
217  }
218 
219  double vis_w, vis_h;
220  vis_w = 2.0 * tan ( fovx / 2.0 ) * d;
221  vis_h = 2.0 * tan ( fovy / 2.0 ) * d;
222 
223  //position of the mouse on the z=0 plane
224  double prim_x, prim_y;
225  prim_x = (double) x / canv_w * vis_w - vis_w / 2.0 + start_pos_x;
226  prim_y = ((double) y / canv_h * vis_h - vis_h / 2.0 - start_pos_y);
227 
228 // DEBUG_DEBUG("mouse ov tool 1 " << state->getX() << " " << state->getY());
229  state->setX((-prim_x + start_x) + start_pos_x);
230  state->setY((prim_y - start_y) + start_pos_y);
231 // DEBUG_DEBUG("mouse ov tool 2 " << state->getX() << " " << state->getY());
232  state->ForceRequireRedraw();
233  state->Redraw();
234  }
235 }
236 
238 {
239  PlaneOverviewToolHelper * thelper = static_cast<PlaneOverviewToolHelper*>(helper);
241 // DEBUG_DEBUG("mouse ov drag button");
242  if (((e.CmdDown() || e.AltDown()) && e.LeftDown()) || e.MiddleDown()) {
243  down = true;
244  start_x = thelper->getPlaneX();
245  start_y = thelper->getPlaneY();
246  start_pos_x = state->getX();
247  start_pos_y = state->getY();
248  }
249  if (e.LeftUp() || e.MiddleUp()) {
250  if (down) {
251  down = false;
252  }
253  }
254 }
255 
256 void PlaneOverviewCameraTool::ChangeZoomLevel(bool zoomIn, double scale) {
258  if (zoomIn) {
259  state->setR(state->getR() / scale);
260  } else {
261  state->setR(state->getR() * scale);
262  }
263  state->SetDirtyViewport();
264  state->ForceRequireRedraw();
265  state->Redraw();
266 }
267 
269 {
270  if (e.GetWheelRotation() != 0) {
271  ChangeZoomLevel(e.GetWheelRotation() > 0);
272  }
273 }
274 
275 void PlaneOverviewCameraTool::KeypressEvent(int keycode, int modifiers, bool pressed) {
276  if (pressed)
277  if (modifiers == wxMOD_CMD) {
278  if (keycode == WXK_ADD) {
279  ChangeZoomLevel(true);
280  } else if (keycode == WXK_SUBTRACT) {
281  ChangeZoomLevel(false);
282  }
283  }
284 }
285 
286 
void MouseMoveEvent(double x, double y, wxMouseEvent &e)
Notify when the mouse pointer has moved over the panorama preview.
void ForceRequireRedraw()
Definition: ViewState.cpp:439
void NotifyMe(Event event, Tool *tool)
Definition: ToolHelper.cpp:315
VisualizationState * GetVisualizationStatePtr()
Definition: ToolHelper.cpp:300
hugin_utils::FDiff2D GetMouseScreenPosition()
Definition: ToolHelper.cpp:290
void Activate()
Switch on a tool.
void ChangeZoomLevel(bool zoomIn, double scale=1.1)
ToolHelper * helper
The PreviewToolHelper that uses the same preview window and panorama as the tool should.
Definition: Tool.h:102
void Activate()
Switch on a tool.
bool IsMouseOverPano()
Definition: ToolHelper.h:136
void ChangeZoomLevel(bool zoomIn, double scale=1.1)
void MouseWheelEvent(wxMouseEvent &)
Notify of a mouse wheel event on the panorama preview.
void MouseWheelEvent(wxMouseEvent &)
Notify of a mouse wheel event on the panorama preview.
static const double limit_high
GLViewer * GetViewer()
Definition: ViewState.h:251
#define DEG_TO_RAD(x)
Definition: hugin_math.h:44
void KeypressEvent(int keycode, int modifiers, bool pressed)
Notify of a Keypress event.
void MouseButtonEvent(wxMouseEvent &e)
Notify of a mouse button press on the panorama preview.
void SetDirtyViewport()
Definition: ViewState.h:249
#define M_PI
Definition: GaborFilter.cpp:34
void MouseButtonEvent(wxMouseEvent &e)
Notify of a mouse button press on the panorama preview.
void MouseMoveEvent(double x, double y, wxMouseEvent &e)
Notify when the mouse pointer has moved over the panorama preview.
void KeypressEvent(int keycode, int modifiers, bool pressed)
Notify of a Keypress event.