ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Mouse3DInput.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 // ##########################################################################
10 // # #
11 // # CLOUDCOMPARE #
12 // # #
13 // # This program is free software; you can redistribute it and/or modify #
14 // # it under the terms of the GNU General Public License as published by #
15 // # the Free Software Foundation; version 2 or later of the License. #
16 // # #
17 // # This program is distributed in the hope that it will be useful, #
18 // # but WITHOUT ANY WARRANTY; without even the implied warranty of #
19 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
20 // # GNU General Public License for more details. #
21 // # #
22 // # COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
23 // # #
24 // ##########################################################################
25 
26 #include "CCAppCommon.h"
27 
28 // cloudViewer
29 #include <CVConst.h>
30 
31 // qCC_db
32 #include <ecvGLMatrix.h>
33 
34 // Qt
35 #include <QObject>
36 
37 // system
38 #include <vector>
39 
40 class ccGLWindow;
41 
43 class CVAPPCOMMON_LIB_API Mouse3DInput : public QObject {
44  Q_OBJECT
45 
46 public:
48  explicit Mouse3DInput(QObject* parent);
50  virtual ~Mouse3DInput();
51 
53  bool connect(QWidget* mainWidget, QString appName);
55  void disconnectDriver();
56 
58  enum VirtualKey {
59  V3DK_INVALID = 0,
60  V3DK_MENU = 1,
90  V3DK_MINUS
91  };
92 
93  enum V3DCMD {
94  V3DCMD_NOOP = 0,
95  V3DCMD_MENU_OPTIONS = 1,
96  V3DCMD_VIEW_FIT = 2,
97  V3DCMD_VIEW_TOP = 3,
98  V3DCMD_VIEW_LEFT = 4,
99  V3DCMD_VIEW_RIGHT = 5,
100  V3DCMD_VIEW_FRONT = 6,
101  V3DCMD_VIEW_BOTTOM = 7,
102  V3DCMD_VIEW_BACK = 8,
103  V3DCMD_VIEW_ROLLCW = 9,
104  V3DCMD_VIEW_ROLLCCW = 10,
105  V3DCMD_VIEW_ISO1 = 11,
106  V3DCMD_VIEW_ISO2 = 12,
107  V3DCMD_KEY_F1 = 13,
108  V3DCMD_KEY_F2 = 14,
109  V3DCMD_KEY_F3 = 15,
110  V3DCMD_KEY_F4 = 16,
111  V3DCMD_KEY_F5 = 17,
112  V3DCMD_KEY_F6 = 18,
113  V3DCMD_KEY_F7 = 19,
114  V3DCMD_KEY_F8 = 20,
115  V3DCMD_KEY_F9 = 21,
116  V3DCMD_KEY_F10 = 22,
117  V3DCMD_KEY_F11 = 23,
118  V3DCMD_KEY_F12 = 24,
119  V3DCMD_KEY_ESC = 25,
120  V3DCMD_KEY_ALT = 26,
121  V3DCMD_KEY_SHIFT = 27,
122  V3DCMD_KEY_CTRL = 28,
123  V3DCMD_FILTER_ROTATE = 29,
124  V3DCMD_FILTER_PANZOOM = 30,
125  V3DCMD_FILTER_DOMINANT = 31,
126  V3DCMD_SCALE_PLUS = 32,
127  V3DCMD_SCALE_MINUS = 33,
128  V3DCMD_VIEW_SPINCW = 34,
129  V3DCMD_VIEW_SPINCCW = 35,
130  V3DCMD_VIEW_TILTCW = 36,
131  V3DCMD_VIEW_TILTCCW = 37,
132  V3DCMD_MENU_POPUP = 38,
133  V3DCMD_MENU_BUTTONMAPPINGEDITOR = 39,
134  V3DCMD_MENU_ADVANCEDSETTINGSEDITOR = 40,
135  V3DCMD_MOTIONMACRO_ZOOM = 41,
136  V3DCMD_MOTIONMACRO_ZOOMOUT_CURSORTOCENTER = 42,
137  V3DCMD_MOTIONMACRO_ZOOMIN_CURSORTOCENTER = 43,
138  V3DCMD_MOTIONMACRO_ZOOMOUT_CENTERTOCENTER = 44,
139  V3DCMD_MOTIONMACRO_ZOOMIN_CENTERTOCENTER = 45,
140  V3DCMD_MOTIONMACRO_ZOOMOUT_CURSORTOCURSOR = 46,
141  V3DCMD_MOTIONMACRO_ZOOMIN_CURSORTOCURSOR = 47,
142  V3DCMD_VIEW_QZ_IN = 48,
143  V3DCMD_VIEW_QZ_OUT = 49,
144  V3DCMD_KEY_ENTER = 50,
145  V3DCMD_KEY_DELETE = 51,
146  V3DCMD_KEY_F13 = 52,
147  V3DCMD_KEY_F14 = 53,
148  V3DCMD_KEY_F15 = 54,
149  V3DCMD_KEY_F16 = 55,
150  V3DCMD_KEY_F17 = 56,
151  V3DCMD_KEY_F18 = 57,
152  V3DCMD_KEY_F19 = 58,
153  V3DCMD_KEY_F20 = 59,
154  V3DCMD_KEY_F21 = 60,
155  V3DCMD_KEY_F22 = 61,
156  V3DCMD_KEY_F23 = 62,
157  V3DCMD_KEY_F24 = 63,
158  V3DCMD_KEY_F25 = 64,
159  V3DCMD_KEY_F26 = 65,
160  V3DCMD_KEY_F27 = 66,
161  V3DCMD_KEY_F28 = 67,
162  V3DCMD_KEY_F29 = 68,
163  V3DCMD_KEY_F30 = 69,
164  V3DCMD_KEY_F31 = 70,
165  V3DCMD_KEY_F32 = 71,
166  V3DCMD_KEY_F33 = 72,
167  V3DCMD_KEY_F34 = 73,
168  V3DCMD_KEY_F35 = 74,
169  V3DCMD_KEY_F36 = 75,
170  V3DCMD_VIEW_1 = 76,
171  V3DCMD_VIEW_2 = 77,
172  V3DCMD_VIEW_3 = 78,
173  V3DCMD_VIEW_4 = 79,
174  V3DCMD_VIEW_5 = 80,
175  V3DCMD_VIEW_6 = 81,
176  V3DCMD_VIEW_7 = 82,
177  V3DCMD_VIEW_8 = 83,
178  V3DCMD_VIEW_9 = 84,
179  V3DCMD_VIEW_10 = 85,
180  V3DCMD_VIEW_11 = 86,
181  V3DCMD_VIEW_12 = 87,
182  V3DCMD_VIEW_13 = 88,
183  V3DCMD_VIEW_14 = 89,
184  V3DCMD_VIEW_15 = 90,
185  V3DCMD_VIEW_16 = 91,
186  V3DCMD_VIEW_17 = 92,
187  V3DCMD_VIEW_18 = 93,
188  V3DCMD_VIEW_19 = 94,
189  V3DCMD_VIEW_20 = 95,
190  V3DCMD_VIEW_21 = 96,
191  V3DCMD_VIEW_22 = 97,
192  V3DCMD_VIEW_23 = 98,
193  V3DCMD_VIEW_24 = 99,
194  V3DCMD_VIEW_25 = 100,
195  V3DCMD_VIEW_26 = 101,
196  V3DCMD_VIEW_27 = 102,
197  V3DCMD_VIEW_28 = 103,
198  V3DCMD_VIEW_29 = 104,
199  V3DCMD_VIEW_30 = 105,
200  V3DCMD_VIEW_31 = 106,
201  V3DCMD_VIEW_32 = 107,
202  V3DCMD_VIEW_33 = 108,
203  V3DCMD_VIEW_34 = 109,
204  V3DCMD_VIEW_35 = 110,
205  V3DCMD_VIEW_36 = 111,
206  V3DCMD_SAVE_VIEW_1 = 112,
207  V3DCMD_SAVE_VIEW_2 = 113,
208  V3DCMD_SAVE_VIEW_3 = 114,
209  V3DCMD_SAVE_VIEW_4 = 115,
210  V3DCMD_SAVE_VIEW_5 = 116,
211  V3DCMD_SAVE_VIEW_6 = 117,
212  V3DCMD_SAVE_VIEW_7 = 118,
213  V3DCMD_SAVE_VIEW_8 = 119,
214  V3DCMD_SAVE_VIEW_9 = 120,
215  V3DCMD_SAVE_VIEW_10 = 121,
216  V3DCMD_SAVE_VIEW_11 = 122,
217  V3DCMD_SAVE_VIEW_12 = 123,
218  V3DCMD_SAVE_VIEW_13 = 124,
219  V3DCMD_SAVE_VIEW_14 = 125,
220  V3DCMD_SAVE_VIEW_15 = 126,
221  V3DCMD_SAVE_VIEW_16 = 127,
222  V3DCMD_SAVE_VIEW_17 = 128,
223  V3DCMD_SAVE_VIEW_18 = 129,
224  V3DCMD_SAVE_VIEW_19 = 130,
225  V3DCMD_SAVE_VIEW_20 = 131,
226  V3DCMD_SAVE_VIEW_21 = 132,
227  V3DCMD_SAVE_VIEW_22 = 133,
228  V3DCMD_SAVE_VIEW_23 = 134,
229  V3DCMD_SAVE_VIEW_24 = 135,
230  V3DCMD_SAVE_VIEW_25 = 136,
231  V3DCMD_SAVE_VIEW_26 = 137,
232  V3DCMD_SAVE_VIEW_27 = 138,
233  V3DCMD_SAVE_VIEW_28 = 139,
234  V3DCMD_SAVE_VIEW_29 = 140,
235  V3DCMD_SAVE_VIEW_30 = 141,
236  V3DCMD_SAVE_VIEW_31 = 142,
237  V3DCMD_SAVE_VIEW_32 = 143,
238  V3DCMD_SAVE_VIEW_33 = 144,
239  V3DCMD_SAVE_VIEW_34 = 145,
240  V3DCMD_SAVE_VIEW_35 = 146,
241  V3DCMD_SAVE_VIEW_36 = 147,
242  V3DCMD_KEY_TAB = 148,
243  V3DCMD_KEY_SPACE = 149,
244  V3DCMD_MENU_1 = 150,
245  V3DCMD_MENU_2 = 151,
246  V3DCMD_MENU_3 = 152,
247  V3DCMD_MENU_4 = 153,
248  V3DCMD_MENU_5 = 154,
249  V3DCMD_MENU_6 = 155,
250  V3DCMD_MENU_7 = 156,
251  V3DCMD_MENU_8 = 157,
252  V3DCMD_MENU_9 = 158,
253  V3DCMD_MENU_10 = 159,
254  V3DCMD_MENU_11 = 160,
255  V3DCMD_MENU_12 = 161,
256  V3DCMD_MENU_13 = 162,
257  V3DCMD_MENU_14 = 163,
258  V3DCMD_MENU_15 = 164,
259  V3DCMD_MENU_16 = 165,
260  /* Add here as needed. Don't change any values that may be in use */
261  };
262 
264  static void GetMatrix(const std::vector<float>& motionData,
265  ccGLMatrixd& mat);
266 
268  static void Apply(const std::vector<float>& motionData, ccGLWindow* win);
269 
271 
273  bool onSiEvent(void* siGetEventData);
274 
275 Q_SIGNALS:
276 
277  void sigMove3d(std::vector<float>& motionData);
278  void sigReleased();
279  void sigOn3dmouseKeyDown(int virtualKeyCode);
280  void sigOn3dmouseCMDKeyDown(int virtualCMDCode);
281  void sigOn3dmouseKeyUp(int virtualKeyCode);
282  void sigOn3dmouseCMDKeyUp(int virtualCMDCode);
283 
284 protected:
286 
288  virtual void move3d(std::vector<float>& motionData);
289 
291 
294  virtual void on3dmouseKeyDown(int virtualKeyCode);
295 
297 
300  virtual void on3dmouseCMDKeyDown(int virtualCMDCode);
301 
303 
306  virtual void on3dmouseKeyUp(int virtualKeyCode);
307 
309 
312  virtual void on3dmouseCMDKeyUp(int virtualCMDCode);
313 
315  void* m_siHandle;
316 };
ecvViewportParameters::computeWidthAtFocalDist
double computeWidthAtFocalDist() const
Computes the object 'width' at the 'focal' distance.
Definition: ecvViewportParameters.cpp:321
Mouse3DInput::V3DK_1
@ V3DK_1
Definition: Mouse3DInput.h:72
Mouse3DInput::V3DK_PANZOOM
@ V3DK_PANZOOM
Definition: Mouse3DInput.h:87
ccGLMatrixTpl::getColumnAsVec3D
Vector3Tpl< T > getColumnAsVec3D(unsigned index) const
Returns a copy of a given column as a CCVector3.
Definition: ecvGLMatrixTpl.h:919
Mouse3DInput::V3DK_ROTATE
@ V3DK_ROTATE
Definition: Mouse3DInput.h:86
Mouse3DInput::V3DCMD_MENU_OPTIONS
@ V3DCMD_MENU_OPTIONS
Definition: Mouse3DInput.h:95
Mouse3DInput::sigOn3dmouseCMDKeyUp
void sigOn3dmouseCMDKeyUp(int virtualCMDCode)
ccGLMatrixTpl::inverse
ccGLMatrixTpl< T > inverse() const
Returns inverse transformation.
Definition: ecvGLMatrixTpl.h:1325
Mouse3DInput::V3DK_BACK
@ V3DK_BACK
Definition: Mouse3DInput.h:67
Mouse3DInput::V3DK_9
@ V3DK_9
Definition: Mouse3DInput.h:80
CVPlatform.h
Mouse3DInput::sigOn3dmouseKeyUp
void sigOn3dmouseKeyUp(int virtualKeyCode)
ccGLMatrixTpl::getColumn
T * getColumn(unsigned index)
Returns a pointer to a given column.
Definition: ecvGLMatrixTpl.h:904
Mouse3DInput::~Mouse3DInput
virtual ~Mouse3DInput()
Destructor.
Definition: Mouse3DInput.cpp:66
CVConst.h
ccGLMatrixd
Double version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:56
Mouse3DInput::V3DK_ALT
@ V3DK_ALT
Definition: Mouse3DInput.h:83
CVLog::Print
static bool Print(const char *format,...)
Prints out a formatted message in console.
Definition: CVLog.cpp:113
ecvViewportParameters
Standard parameters for GL displays/viewports.
Definition: ecvViewportParameters.h:18
CVLog.h
ecvViewportParameters::setFocalDistance
void setFocalDistance(double distance)
Sets the 'focal' distance.
Definition: ecvViewportParameters.cpp:304
Mouse3DInput::m_siHandle
void * m_siHandle
3DxWare handle
Definition: Mouse3DInput.h:315
Mouse3DInput::sigOn3dmouseKeyDown
void sigOn3dmouseKeyDown(int virtualKeyCode)
Mouse3DInput::V3DK_CTRL
@ V3DK_CTRL
Definition: Mouse3DInput.h:85
CCVector3d
Vector3Tpl< double > CCVector3d
Double 3D Vector.
Definition: CVGeom.h:804
result
core::Tensor result
Definition: VtkUtils.cpp:76
Mouse3DInput::move3d
virtual void move3d(std::vector< float > &motionData)
Called with the processed motion data when a 3D mouse event is received.
Definition: Mouse3DInput.cpp:233
Mouse3DInput::V3DK_FRONT
@ V3DK_FRONT
Definition: Mouse3DInput.h:65
Mouse3DInput::V3DK_SHIFT
@ V3DK_SHIFT
Definition: Mouse3DInput.h:84
math.h
Mouse3DInput::V3DK_ISO1
@ V3DK_ISO1
Definition: Mouse3DInput.h:70
ecvViewportParameters::getFocalDistance
double getFocalDistance() const
Computes the 'focal' distance.
Definition: ecvViewportParameters.h:54
Mouse3DInput::V3DK_2
@ V3DK_2
Definition: Mouse3DInput.h:73
Mouse3DInput::V3DK_7
@ V3DK_7
Definition: Mouse3DInput.h:78
Mouse3DInput::V3DK_6
@ V3DK_6
Definition: Mouse3DInput.h:77
Mouse3DInput::sigOn3dmouseCMDKeyDown
void sigOn3dmouseCMDKeyDown(int virtualCMDCode)
Mouse3DInput::V3DK_5
@ V3DK_5
Definition: Mouse3DInput.h:76
Vector3Tpl< double >
Mouse3DInput::V3DK_CCW
@ V3DK_CCW
Definition: Mouse3DInput.h:69
Mouse3DInput::GetMatrix
static void GetMatrix(const std::vector< float > &motionData, ccGLMatrixd &mat)
Converts 'rotation' part of motion data to a rotation matrix.
Definition: Mouse3DInput.cpp:253
s_mouseInputInstance
static Mouse3DInput * s_mouseInputInstance
Definition: Mouse3DInput.cpp:35
cloudViewer::GreaterThanEpsilon
bool GreaterThanEpsilon(float x)
Test a floating point number against our epsilon (a very small number).
Definition: CVMath.h:37
Mouse3DInput::connect
bool connect(QWidget *mainWidget, QString appName)
Attempts to connect with the 3DxWare driver.
Definition: Mouse3DInput.cpp:73
ccGLMatrixTpl::initFromParameters
void initFromParameters(T alpha_rad, const Vector3Tpl< T > &axis3D, const Vector3Tpl< T > &t3D)
Inits transformation from a rotation axis, an angle and a translation.
Definition: ecvGLMatrixTpl.h:648
Mouse3DInput::V3DCMD
V3DCMD
Definition: Mouse3DInput.h:93
Mouse3DInput::V3DK_DOMINANT
@ V3DK_DOMINANT
Definition: Mouse3DInput.h:88
Mouse3DInput::Mouse3DInput
Mouse3DInput(QObject *parent)
Default constructor.
Definition: Mouse3DInput.cpp:59
RawInputEventFilter::nativeEventFilter
bool nativeEventFilter(const QByteArray &eventType, void *msg, long *result) override
Definition: Mouse3DInput.cpp:40
Mouse3DInput::V3DK_ESC
@ V3DK_ESC
Definition: Mouse3DInput.h:82
Mouse3DInput::V3DK_RIGHT
@ V3DK_RIGHT
Definition: Mouse3DInput.h:64
Mouse3DInput.h
Mouse3DInput::on3dmouseKeyDown
virtual void on3dmouseKeyDown(int virtualKeyCode)
Called when a 3D mouse key is pressed.
Definition: Mouse3DInput.cpp:237
Mouse3DInput::V3DK_4
@ V3DK_4
Definition: Mouse3DInput.h:75
ecvViewportParameters::objectCenteredView
bool objectCenteredView
Definition: ecvViewportParameters.h:130
Mouse3DInput::V3DK_8
@ V3DK_8
Definition: Mouse3DInput.h:79
Mouse3DInput::VirtualKey
VirtualKey
Default key codes.
Definition: Mouse3DInput.h:58
Mouse3DInput::on3dmouseCMDKeyDown
virtual void on3dmouseCMDKeyDown(int virtualCMDCode)
Called when a 3D mouse key is pressed after translation to CMD.
Definition: Mouse3DInput.cpp:241
Mouse3DInput::V3DK_TOP
@ V3DK_TOP
Definition: Mouse3DInput.h:62
Mouse3DInput::V3DK_CW
@ V3DK_CW
Definition: Mouse3DInput.h:68
ecvViewportParameters::perspectiveView
bool perspectiveView
Perspective view state.
Definition: ecvViewportParameters.h:125
Mouse3DInput::disconnectDriver
void disconnectDriver()
Disconnects from the 3DxWare driver.
Definition: Mouse3DInput.cpp:145
CVAPPCOMMON_LIB_API
#define CVAPPCOMMON_LIB_API
Definition: CVAppCommon.h:15
Mouse3DInput::Apply
static void Apply(const std::vector< float > &motionData, ccGLWindow *win)
Applies motion data to a given 3D window.
Definition: Mouse3DInput.cpp:268
CVLog::Warning
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
Mouse3DInput::V3DK_3
@ V3DK_3
Definition: Mouse3DInput.h:74
Mouse3DInput::V3DK_ISO2
@ V3DK_ISO2
Definition: Mouse3DInput.h:71
Mouse3DInput::sigMove3d
void sigMove3d(std::vector< float > &motionData)
Mouse3DInput::on3dmouseCMDKeyUp
virtual void on3dmouseCMDKeyUp(int virtualCMDCode)
Called when a 3D mouse key is released after translation to CMD.
Definition: Mouse3DInput.cpp:249
Mouse3DInput
3DxWare driver wrapper for 3D mouse handling
Definition: Mouse3DInput.h:43
Mouse3DInput::onSiEvent
bool onSiEvent(void *siGetEventData)
Called when a new system message is available.
Definition: Mouse3DInput.cpp:154
X
void * X
Definition: SmallVector.cpp:45
Mouse3DInput::sigReleased
void sigReleased()
RawInputEventFilter
Definition: Mouse3DInput.cpp:38
Mouse3DInput::V3DK_BOTTOM
@ V3DK_BOTTOM
Definition: Mouse3DInput.h:66
Mouse3DInput::V3DK_LEFT
@ V3DK_LEFT
Definition: Mouse3DInput.h:63
s_rawInputEventFilter
static RawInputEventFilter s_rawInputEventFilter
Definition: Mouse3DInput.cpp:57
Mouse3DInput::V3DK_FIT
@ V3DK_FIT
Definition: Mouse3DInput.h:61
ecvGLMatrix.h
c_3dmouseAngularVelocity
static const double c_3dmouseAngularVelocity
Object angular velocity per mouse tick (in radians per ms per count)
Definition: Mouse3DInput.cpp:32
Mouse3DInput::on3dmouseKeyUp
virtual void on3dmouseKeyUp(int virtualKeyCode)
Called when a 3D mouse key is released.
Definition: Mouse3DInput.cpp:245
Mouse3DInput::V3DK_PLUS
@ V3DK_PLUS
Definition: Mouse3DInput.h:89
name
std::string name
Definition: FileIOFactory.cpp:129
Mouse3DInput::V3DK_10
@ V3DK_10
Definition: Mouse3DInput.h:81