VTK
vtkEventData.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkEventData.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
19 #ifndef vtkEventData_h
20 #define vtkEventData_h
21 
22 #include "vtkCommand.h"
23 
24 // enumeration of possible devices
25 enum class vtkEventDataDevice {
26  Unknown = -1,
31 };
32 
34  static_cast<int>(vtkEventDataDevice::NumberOfDevices);
35 
36 // enumeration of possible device inputs
38  Unknown = -1,
39  Trigger,
40  TrackPad,
41  Joystick,
42  Grip,
45 };
46 
49 
50 // enumeration of actions that can happen
51 enum class vtkEventDataAction {
52  Unknown = -1,
53  Press,
54  Release,
55  Touch,
56  Untouch,
58 };
59 
62 
64 {
65 public:
66  vtkBaseTypeMacro(vtkEventData,vtkObjectBase);
67 
68  int GetType() const { return this->Type; }
69 
70  // are two events equivalent
71  bool operator==(const vtkEventData& a) const
72  {
73  return this->Type == a.Type && this->Equivalent(&a);
74  }
75 
76  // some convenience downcasts
77  virtual vtkEventDataForDevice *GetAsEventDataForDevice() { return nullptr; }
78  virtual vtkEventDataDevice3D *GetAsEventDataDevice3D() { return nullptr; }
79 
80 protected:
82  ~vtkEventData() override {}
83 
84  // subclasses override this to define their
85  // definition of equivalent
86  virtual bool Equivalent(const vtkEventData *ed) const = 0;
87 
88  int Type;
89 
90 private:
91  vtkEventData(const vtkEventData& c) = delete;
92 };
93 
94 // a subclass for events that may have one or more of
95 // device, input, and action
97 {
98 public:
102  ret->InitializeObjectBase();
103  return ret;
104  };
105 
106  vtkEventDataDevice GetDevice() const { return this->Device; }
107  vtkEventDataDeviceInput GetInput() const { return this->Input; }
108  vtkEventDataAction GetAction() const { return this->Action; }
109 
110  void SetDevice(vtkEventDataDevice v) { this->Device = v; }
111  void SetInput(vtkEventDataDeviceInput v) { this->Input = v; }
112  void SetAction(vtkEventDataAction v) { this->Action = v; }
113 
114  vtkEventDataForDevice *GetAsEventDataForDevice() override { return this; }
115 
116 protected:
120 
121  bool Equivalent(const vtkEventData *e) const override {
122  const vtkEventDataForDevice *edd = static_cast<const vtkEventDataForDevice *>(e);
123  return this->Device == edd->Device && this->Input == edd->Input && this->Action == edd->Action;
124  };
125 
127  this->Device = vtkEventDataDevice::Unknown;
128  this->Input = vtkEventDataDeviceInput::Unknown;
129  this->Action = vtkEventDataAction::Unknown; }
131 
132 private:
133  vtkEventDataForDevice(const vtkEventData& c) = delete;
134  void operator=(const vtkEventDataForDevice&) = delete;
135 };
136 
137 // a subclass for events that have a 3D world position
138 // direction and orientation.
140 {
141 public:
143 
144  vtkEventDataDevice3D *GetAsEventDataDevice3D() override { return this; }
145 
146  void GetWorldPosition(double v[3]) const {
147  v[0] = this->WorldPosition[0];
148  v[1] = this->WorldPosition[1];
149  v[2] = this->WorldPosition[2];
150  }
151  const double *GetWorldPosition() const {
152  return this->WorldPosition;
153  }
154  void SetWorldPosition(const double p[3])
155  {
156  this->WorldPosition[0] = p[0];
157  this->WorldPosition[1] = p[1];
158  this->WorldPosition[2] = p[2];
159  }
160 
161  void GetWorldDirection(double v[3]) const {
162  v[0] = this->WorldDirection[0];
163  v[1] = this->WorldDirection[1];
164  v[2] = this->WorldDirection[2];
165  }
166  const double *GetWorldDirection() const {
167  return this->WorldDirection;
168  }
169  void SetWorldDirection(const double p[3])
170  {
171  this->WorldDirection[0] = p[0];
172  this->WorldDirection[1] = p[1];
173  this->WorldDirection[2] = p[2];
174  }
175 
176  void GetWorldOrientation(double v[4]) const {
177  v[0] = this->WorldOrientation[0];
178  v[1] = this->WorldOrientation[1];
179  v[2] = this->WorldOrientation[2];
180  v[3] = this->WorldOrientation[3];
181  }
182  const double *GetWorldOrientation() const {
183  return this->WorldOrientation;
184  }
185  void SetWorldOrientation(const double p[4])
186  {
187  this->WorldOrientation[0] = p[0];
188  this->WorldOrientation[1] = p[1];
189  this->WorldOrientation[2] = p[2];
190  this->WorldOrientation[3] = p[3];
191  }
192 
193  void GetTrackPadPosition(double v[2]) const {
194  v[0] = this->TrackPadPosition[0];
195  v[1] = this->TrackPadPosition[1];
196  }
197  const double *GetTrackPadPosition() const {
198  return this->TrackPadPosition;
199  }
200  void SetTrackPadPosition(const double p[2])
201  {
202  this->TrackPadPosition[0] = p[0];
203  this->TrackPadPosition[1] = p[1];
204  }
205  void SetTrackPadPosition(double x, double y)
206  {
207  this->TrackPadPosition[0] = x;
208  this->TrackPadPosition[1] = y;
209  }
210 
211 protected:
212  double WorldPosition[3];
213  double WorldOrientation[4];
214  double WorldDirection[3];
215  double TrackPadPosition[2];
216 
218  ~vtkEventDataDevice3D() override {}
219 
220 private:
221  vtkEventDataDevice3D(const vtkEventDataDevice3D& c) = delete;
222  void operator=(const vtkEventDataDevice3D&) = delete;
223 };
224 
225 // subclass for button event 3d
227 {
228 public:
232  ret->InitializeObjectBase();
233  return ret;
234  };
235 
236 protected:
238  ~vtkEventDataButton3D() override {}
239 
240 private:
241  vtkEventDataButton3D(const vtkEventDataButton3D& c) = delete;
242  void operator=(const vtkEventDataButton3D&) = delete;
243 };
244 
245 // subclass for move event 3d
247 {
248 public:
252  ret->InitializeObjectBase();
253  return ret;
254  };
255 
256 protected:
258  ~vtkEventDataMove3D() override {}
259 
260 private:
261  vtkEventDataMove3D(const vtkEventDataMove3D& c) = delete;
262  void operator=(const vtkEventDataMove3D&) = delete;
263 };
264 
265 #endif
266 
267 // VTK-HeaderTest-Exclude: vtkEventData.h
static vtkEventDataButton3D * New()
Definition: vtkEventData.h:230
void InitializeObjectBase()
void SetWorldDirection(const double p[3])
Definition: vtkEventData.h:169
void GetTrackPadPosition(double v[2]) const
Definition: vtkEventData.h:193
const double * GetTrackPadPosition() const
Definition: vtkEventData.h:197
vtkEventDataDeviceInput
Definition: vtkEventData.h:37
void SetWorldOrientation(const double p[4])
Definition: vtkEventData.h:185
const double * GetWorldOrientation() const
Definition: vtkEventData.h:182
vtkEventDataDeviceInput GetInput() const
Definition: vtkEventData.h:107
virtual vtkEventDataForDevice * GetAsEventDataForDevice()
Definition: vtkEventData.h:77
vtkEventDataDevice3D * GetAsEventDataDevice3D() override
Definition: vtkEventData.h:144
vtkEventDataAction Action
Definition: vtkEventData.h:119
~vtkEventDataButton3D() override
Definition: vtkEventData.h:238
~vtkEventData() override
Definition: vtkEventData.h:82
const double * GetWorldDirection() const
Definition: vtkEventData.h:166
~vtkEventDataMove3D() override
Definition: vtkEventData.h:258
void SetTrackPadPosition(const double p[2])
Definition: vtkEventData.h:200
const int vtkEventDataNumberOfDevices
Definition: vtkEventData.h:33
vtkEventDataDevice Device
Definition: vtkEventData.h:117
const int vtkEventDataNumberOfInputs
Definition: vtkEventData.h:47
vtkEventDataAction
Definition: vtkEventData.h:51
int GetType() const
Definition: vtkEventData.h:68
void SetInput(vtkEventDataDeviceInput v)
Definition: vtkEventData.h:111
~vtkEventDataDevice3D() override
Definition: vtkEventData.h:218
vtkEventDataAction GetAction() const
Definition: vtkEventData.h:108
void GetWorldDirection(double v[3]) const
Definition: vtkEventData.h:161
void SetTrackPadPosition(double x, double y)
Definition: vtkEventData.h:205
vtkEventDataForDevice * GetAsEventDataForDevice() override
Definition: vtkEventData.h:114
abstract base class for most VTK objects
Definition: vtkObjectBase.h:65
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:25
bool Equivalent(const vtkEventData *e) const override
Definition: vtkEventData.h:121
static vtkEventDataForDevice * New()
Definition: vtkEventData.h:100
const double * GetWorldPosition() const
Definition: vtkEventData.h:151
virtual vtkEventDataDevice3D * GetAsEventDataDevice3D()
Definition: vtkEventData.h:78
~vtkEventDataForDevice() override
Definition: vtkEventData.h:130
bool operator==(const vtkEventData &a) const
Definition: vtkEventData.h:71
static vtkEventDataMove3D * New()
Definition: vtkEventData.h:250
void SetWorldPosition(const double p[3])
Definition: vtkEventData.h:154
void SetAction(vtkEventDataAction v)
Definition: vtkEventData.h:112
void GetWorldPosition(double v[3]) const
Definition: vtkEventData.h:146
vtkEventDataDeviceInput Input
Definition: vtkEventData.h:118
void GetWorldOrientation(double v[4]) const
Definition: vtkEventData.h:176
void SetDevice(vtkEventDataDevice v)
Definition: vtkEventData.h:110
vtkEventDataDevice GetDevice() const
Definition: vtkEventData.h:106