File: vtkVRInteractorStyle.h

package info (click to toggle)
paraview 5.11.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 497,236 kB
  • sloc: cpp: 3,171,290; ansic: 1,315,072; python: 134,290; xml: 103,324; sql: 65,887; sh: 5,286; javascript: 4,901; yacc: 4,383; java: 3,977; perl: 2,363; lex: 1,909; f90: 1,255; objc: 143; makefile: 119; tcl: 59; pascal: 50; fortran: 29
file content (296 lines) | stat: -rw-r--r-- 8,271 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*=========================================================================

Program:   Visualization Toolkit
Module:    vtkVRInteractorStyle.h

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/**
 * @class   vtkVRInteractorStyle
 * @brief   Extended from vtkInteractorStyle3D to override command methods.
 *
 * This abstract class defines an interactor style in a virtual reality context.
 */

#ifndef vtkVRInteractorStyle_h
#define vtkVRInteractorStyle_h

#include "vtkEventData.h" // for enums
#include "vtkInteractorStyle3D.h"
#include "vtkNew.h"               // for vtkNew
#include "vtkRenderingVRModule.h" // For export macro
#include "vtkSmartPointer.h"      // for vtkSmartPointer

#include <map>    // for std::map
#include <vector> // for std::vector

VTK_ABI_NAMESPACE_BEGIN
class vtkCallbackCommand;
class vtkCell;
class vtkPlane;
class vtkRenderWindowInteractor;
class vtkSelection;
class vtkSphereSource;
class vtkTextActor3D;
class vtkVRControlsHelper;
class vtkVRHardwarePicker;
class vtkVRMenuRepresentation;
class vtkVRMenuWidget;

class VTKRENDERINGVR_EXPORT vtkVRInteractorStyle : public vtkInteractorStyle3D
{
public:
  vtkTypeMacro(vtkVRInteractorStyle, vtkInteractorStyle3D);
  void PrintSelf(ostream& os, vtkIndent indent) override;

  ///@{
  /**
   * Override generic event bindings to call the corresponding action.
   */
  void OnSelect3D(vtkEventData* edata) override;
  void OnNextPose3D(vtkEventData* edata) override;
  void OnViewerMovement3D(vtkEventData* edata) override;
  void OnMove3D(vtkEventData* edata) override;
  void OnMenu3D(vtkEventData* edata) override;
  void OnElevation3D(vtkEventData* edata) override;
  ///@}

  ///@{
  /**
   * Interaction mode entry points.
   */
  void StartPick(vtkEventDataDevice3D*);
  void EndPick(vtkEventDataDevice3D*);
  void StartLoadCamPose(vtkEventDataDevice3D*);
  void EndLoadCamPose(vtkEventDataDevice3D*);
  void StartPositionProp(vtkEventDataDevice3D*);
  void EndPositionProp(vtkEventDataDevice3D*);
  void StartClip(vtkEventDataDevice3D*);
  void EndClip(vtkEventDataDevice3D*);
  void StartMovement3D(int interactionState, vtkEventDataDevice3D*);
  void EndMovement3D(vtkEventDataDevice3D*);
  ///@}

  ///@{
  /**
   * Multitouch events binding.
   */
  void OnPan() override;
  void OnPinch() override;
  void OnRotate() override;
  ///@}

  ///@{
  /**
   * Methods for interaction.
   */
  void ProbeData(vtkEventDataDevice controller);
  void PositionProp(vtkEventData*, double* lwpos = nullptr, double* lwori = nullptr) override;
  void Clip(vtkEventDataDevice3D*);
  virtual void LoadNextCameraPose() = 0;
  ///@}

  /**
   * Move the camera on the "XY" plan (ground) using the thumbstick/trackpad position
   * (up/down and left/right), according to the headset view direction.
   */
  void GroundMovement3D(vtkEventDataDevice3D*);

  /**
   * Move the camera following the "Z" axis (elevation) using the thumbstick/trackpad
   * position (up/down).
   */
  void Elevation3D(vtkEventDataDevice3D*);

  ///@{
  /**
   * Map controller inputs to actions.
   * Actions are defined by a VTKIS_*STATE*, interaction entry points,
   * and the corresponding method for interaction.
   */
  void MapInputToAction(vtkCommand::EventIds eid, int state);
  void MapInputToAction(vtkCommand::EventIds eid, vtkEventDataAction action, int state);
  ///@}

  /**
   * Define the helper text that goes with an input.
   */
  void AddTooltipForInput(
    vtkEventDataDevice device, vtkEventDataDeviceInput input, const std::string& text = {});

  /**
   * Creates a new ControlsHelper suitable for use with the child class.
   */
  virtual vtkVRControlsHelper* MakeControlsHelper() = 0;

  ///@{
  /**
   * Indicates if picking should be updated every frame. If so, the interaction
   * picker will try to pick a prop and rays will be updated accordingly.
   * Default is set to off.
   */
  vtkSetMacro(HoverPick, bool);
  vtkGetMacro(HoverPick, bool);
  vtkBooleanMacro(HoverPick, bool);
  ///@}

  ///@{
  /**
   * Specify if the grab mode uses the ray to grab distant objects.
   * Default is set to on.
   */
  vtkSetMacro(GrabWithRay, bool);
  vtkGetMacro(GrabWithRay, bool);
  vtkBooleanMacro(GrabWithRay, bool);
  ///@}

  enum MovementStyle
  {
    FLY_STYLE,
    GROUNDED_STYLE
  };

  ///@{
  /**
   * Specify the movement style between 'Flying" and "Grounded".
   * Default is Flying.
   */
  vtkSetMacro(Style, MovementStyle);
  vtkGetMacro(Style, MovementStyle);
  ///@}

  /**
   * Return interaction state for the specified device (dolly, pick, none, etc...).
   */
  int GetInteractionState(vtkEventDataDevice device)
  {
    return this->InteractionState[static_cast<int>(device)];
  }

  ///@{
  /**
   * Show/hide the ray for the specified controller.
   */
  void ShowRay(vtkEventDataDevice controller);
  void HideRay(vtkEventDataDevice controller);
  ///@}

  ///@{
  /**
   * Show/hide billboard with given text string.
   */
  void ShowBillboard(const std::string& text);
  void HideBillboard();
  ///@}

  /**
   * Make the pick actor a sphere of given radius centered at given position,
   * and show it.
   */
  void ShowPickSphere(double* pos, double radius, vtkProp3D*);

  /**
   * Make the pick actor a polydata built from the points and edges of the
   * given cell, and show it.
   */

  void ShowPickCell(vtkCell* cell, vtkProp3D*);

  /**
   * Hide the pick actor (sphere or polydata).
   */
  void HidePickActor();

  ///@{
  /**
   * Control visibility of descriptive tooltips for controller/HMD models.
   */
  void ToggleDrawControls();
  void SetDrawControls(bool);
  ///@}

  /**
   * Set the Interactor wrapper being controlled by this object.
   */
  void SetInteractor(vtkRenderWindowInteractor* iren) override;

  /**
   * Setup default actions defined with an action path and a corresponding command.
   */
  virtual void SetupActions(vtkRenderWindowInteractor* iren) = 0;

  /**
   * Return the menu to allow the user to add options to it.
   */
  vtkVRMenuWidget* GetMenu() { return this->Menu.Get(); }

protected:
  vtkVRInteractorStyle();
  ~vtkVRInteractorStyle() override;

  /**
   * Update and draw the ray.
   */
  void UpdateRay(vtkEventDataDevice controller);

  void EndPickCallback(vtkSelection* sel);
  static void MenuCallback(
    vtkObject* object, unsigned long event, void* clientdata, void* calldata);

  /**
   * Utility routines.
   */
  void StartAction(int VTKIS_STATE, vtkEventDataDevice3D* edata);
  void EndAction(int VTKIS_STATE, vtkEventDataDevice3D* edata);

  /**
   * Pick using hardware selector.
   */
  bool HardwareSelect(vtkEventDataDevice controller, bool actorPassOnly);

  /**
   * Update the 3D movement according to the given interaction state.
   */
  void Movement3D(int interactionState, vtkEventData* edata);

  bool HoverPick = false;
  bool GrabWithRay = true;

  vtkNew<vtkVRMenuWidget> Menu;
  vtkNew<vtkVRMenuRepresentation> MenuRepresentation;
  vtkNew<vtkCallbackCommand> MenuCommand;

  vtkNew<vtkTextActor3D> TextActor3D;
  vtkNew<vtkActor> PickActor;
  vtkNew<vtkSphereSource> Sphere;
  vtkNew<vtkVRHardwarePicker> HardwarePicker;

  // Device input to interaction state mapping
  std::map<std::tuple<vtkCommand::EventIds, vtkEventDataAction>, int> InputMap;
  vtkVRControlsHelper* ControlsHelpers[vtkEventDataNumberOfDevices][vtkEventDataNumberOfInputs];

  // Store required controllers information when performing action
  int InteractionState[vtkEventDataNumberOfDevices];
  std::vector<vtkSmartPointer<vtkProp3D>> InteractionProps;
  std::vector<vtkSmartPointer<vtkPlane>> ClippingPlanes;

  // Store headset world orientation
  double HeadsetDir[3] = { 0, 0, 0 };

  // Store movement style
  MovementStyle Style = vtkVRInteractorStyle::FLY_STYLE;

private:
  vtkVRInteractorStyle(const vtkVRInteractorStyle&) = delete;
  void operator=(const vtkVRInteractorStyle&) = delete;
};

VTK_ABI_NAMESPACE_END
#endif