IVT
OpenGLVisualizerControl.cpp
Go to the documentation of this file.
1 // ****************************************************************************
2 // This file is part of the Integrating Vision Toolkit (IVT).
3 //
4 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6 //
7 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8 // All rights reserved.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // 3. Neither the name of the KIT nor the names of its contributors may be
21 // used to endorse or promote products derived from this software
22 // without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // ****************************************************************************
35 // ****************************************************************************
36 // Filename: OpenGLVisualizerControl.cpp
37 // Author: Florian Hecht
38 // Date: 2009
39 // ****************************************************************************
40 
41 
42 // ****************************************************************************
43 // Includes
44 // ****************************************************************************
45 
47 
49 #include "OpenGLVisualizer.h"
50 
51 
52 
53 // ****************************************************************************
54 // Constructor
55 // ****************************************************************************
56 
58 : m_widget(widget), m_visualizer(visualizer), m_main_window(main_window), m_event_callback(event_callback), m_width(width), m_height(height), m_mouse_mode(0)
59 {
61 }
62 
63 
64 // ****************************************************************************
65 // Methods
66 // ****************************************************************************
67 
69 {
70  m_ViewMatrix = transformation;
71 
72  if (m_visualizer)
73  m_visualizer->SetViewMatrix(m_ViewMatrix);
74 }
75 
77 {
78  return m_ViewMatrix;
79 }
80 
82 {
83  m_ViewMatrix.rotation = Math3d::unit_mat;
84  m_ViewMatrix.translation = Math3d::zero_vec;
85 
86  if (m_visualizer)
87  m_visualizer->SetViewMatrix(m_ViewMatrix);
88 }
89 
90 // this two events are specific for the image widget
91 void COpenGLVisualizerControl::RectSelected(WIDGET_HANDLE widget, int x0, int y0, int x1, int y1)
92 {
93  if (m_event_callback)
94  m_event_callback->RectSelected(widget, x0, y0, x1, y1);
95 }
96 
98 {
99  if (m_event_callback)
100  m_event_callback->PointClicked(widget, x, y);
101 }
102 
103 // the following events are only generated for image and GL widgets
104 void COpenGLVisualizerControl::MouseDown(WIDGET_HANDLE widget, int button, int x, int y)
105 {
106  if (widget == m_widget)
107  {
108  int mod = 0;
109  if (m_main_window)
110  mod = m_main_window->GetModifierKeyState();
111 
112  if (button == IVT_LEFT_BUTTON)
113  {
114  if (mod == 0)
115  m_mouse_mode = 1;
116  else if (mod & IVT_SHIFT_KEY)
117  m_mouse_mode = 3;
118  else if (mod & IVT_CONTROL_KEY || mod & IVT_ALT_KEY)
119  m_mouse_mode = 4;
120  }
121  else if (button == IVT_RIGHT_BUTTON)
122  {
123  m_mouse_mode = 2;
124  }
125  else if (button == IVT_MIDDLE_BUTTON)
126  {
127  m_mouse_mode = 3;
128  }
129 
130  m_mouse_old_x = x;
131  m_mouse_old_y = y;
132 
133  return;
134  }
135 
136  if (m_event_callback)
137  m_event_callback->MouseDown(widget, button, x, y);
138 }
139 
140 void COpenGLVisualizerControl::MouseUp(WIDGET_HANDLE widget, int button, int x, int y)
141 {
142  if (widget == m_widget)
143  {
144  m_mouse_mode = 0;
145 
146  m_mouse_old_x = x;
147  m_mouse_old_y = y;
148 
149  return;
150  }
151 
152  if (m_event_callback)
153  m_event_callback->MouseUp(widget, button, x, y);
154 }
155 
157 {
158  if (widget == m_widget && m_mouse_mode != 0)
159  {
160  m_mouse_old_x = x;
161  m_mouse_old_y = y;
162 
163  return;
164  }
165 
166  if (m_event_callback)
167  m_event_callback->MouseMove(widget, x, y);
168 }
169 
171 {
172  if (m_event_callback)
173  m_event_callback->KeyDown(widget, key);
174 }
175 
177 {
178  if (m_event_callback)
179  m_event_callback->KeyUp(widget, key);
180 }
181 
182 // this event is only emitted for buttons
184 {
185  if (m_event_callback)
186  m_event_callback->ButtonPushed(widget);
187 }
188 
189 // this event is generated by check boxes, sliders, text edits (value = -1)
190 // and combo boxes
192 {
193  if (m_event_callback)
194  m_event_callback->ValueChanged(widget, value);
195 }
196 
197 #define ROT_SPEED 0.1f
198 #define TRANS_SPEED 100.0f
199 
201 {
202  float fx = (float)(m_mouse_old_x - (m_width / 2)) / (float)(m_width / 2);
203  float fy = (float)(m_mouse_old_y - (m_height / 2)) / (float)(m_height / 2);
204 
205  if (m_mouse_mode == 1)
206  {
207  Mat3d m1, m2;
208 
211 
212  Math3d::MulMatMat(m1, m2, m1);
213  Math3d::MulMatMat(m1, m_ViewMatrix.rotation, m_ViewMatrix.rotation);
214 
215  if (m_visualizer)
216  m_visualizer->SetViewMatrix(m_ViewMatrix);
217  }
218  else if (m_mouse_mode == 2)
219  {
220  m_ViewMatrix.translation.z += TRANS_SPEED * fy;
221 
222  if (m_visualizer)
223  m_visualizer->SetViewMatrix(m_ViewMatrix);
224  }
225  else if (m_mouse_mode == 3)
226  {
227  m_ViewMatrix.translation.x += TRANS_SPEED * fx;
228  m_ViewMatrix.translation.y += TRANS_SPEED * fy;
229 
230  if (m_visualizer)
231  m_visualizer->SetViewMatrix(m_ViewMatrix);
232  }
233  else if (m_mouse_mode == 4)
234  {
235  Mat3d m1;
236 
238 
239  Math3d::MulMatMat(m1, m_ViewMatrix.rotation, m_ViewMatrix.rotation);
240 
241  if (m_visualizer)
242  m_visualizer->SetViewMatrix(m_ViewMatrix);
243  }
244 }
245 
246 #undef ROT_SPEED
247 #undef TRANS_SPEED
#define IVT_ALT_KEY
virtual void RectSelected(WIDGET_HANDLE widget, int x0, int y0, int x1, int y1)
float y
Definition: Math3d.h:75
void SetRotationMatZ(Mat3d &matrix, float theta)
Definition: Math3d.cpp:358
void * WIDGET_HANDLE
virtual void MouseUp(WIDGET_HANDLE widget, int button, int x, int y)
virtual void KeyDown(WIDGET_HANDLE widget, int key)
void MouseDown(WIDGET_HANDLE widget, int button, int x, int y)
#define IVT_CONTROL_KEY
COpenGLVisualizerControl(WIDGET_HANDLE widget, int width, int height, COpenGLVisualizer *visualizer, CMainWindowInterface *main_window, CMainWindowEventInterface *event_callback)
void RectSelected(WIDGET_HANDLE widget, int x0, int y0, int x1, int y1)
#define ROT_SPEED
virtual void MouseMove(WIDGET_HANDLE widget, int x, int y)
float x
Definition: Math3d.h:75
const Mat3d unit_mat
Definition: Math3d.cpp:60
void KeyUp(WIDGET_HANDLE widget, int key)
Vec3d translation
Definition: Math3d.h:108
#define TRANS_SPEED
virtual void ButtonPushed(WIDGET_HANDLE widget)
const Transformation3d & GetViewMatrix()
void PointClicked(WIDGET_HANDLE widget, int x, int y)
void ButtonPushed(WIDGET_HANDLE widget)
void MulMatMat(const Mat3d &matrix1, const Mat3d &matrix2, Mat3d &result)
Definition: Math3d.cpp:444
void SetViewMatrix(const Transformation3d &transformation)
#define IVT_MIDDLE_BUTTON
Mat3d rotation
Definition: Math3d.h:107
const Vec3d zero_vec
Definition: Math3d.cpp:59
void SetRotationMatY(Mat3d &matrix, float theta)
Definition: Math3d.cpp:349
virtual void PointClicked(WIDGET_HANDLE widget, int x, int y)
void SetViewMatrix(const Transformation3d &transformation)
#define IVT_RIGHT_BUTTON
void KeyDown(WIDGET_HANDLE widget, int key)
void ValueChanged(WIDGET_HANDLE widget, int value)
virtual void KeyUp(WIDGET_HANDLE widget, int key)
float z
Definition: Math3d.h:75
#define IVT_LEFT_BUTTON
Interface for the creation of GUIs with the GUI toolkit of the IVT.
virtual void MouseDown(WIDGET_HANDLE widget, int button, int x, int y)
Interface for the event mechanism of GUIs using the GUI toolkit of the IVT.
virtual void ValueChanged(WIDGET_HANDLE widget, int value)
Data structure for the representation of a 3x3 matrix.
Definition: Math3d.h:93
void MouseMove(WIDGET_HANDLE widget, int x, int y)
void SetRotationMatX(Mat3d &matrix, float theta)
Definition: Math3d.cpp:340
Data structure for the representation of a 3D rigid body transformation.
Definition: Math3d.h:105
virtual int GetModifierKeyState()=0
#define IVT_SHIFT_KEY
void MouseUp(WIDGET_HANDLE widget, int button, int x, int y)