VTK
vtkOpenVROverlayInternal.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4 
5  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 
15 #include "vtkVectorOperators.h"
16 
18 {
19 public:
20  double Position[3];
21  double PhysicalViewUp[3];
23  double ViewDirection[3];
24  double Translation[3];
25  double Distance;
26  double MotionFactor = 1.0;
27  bool Loaded = false;
28 
29  // return a vector based on in that is orthogonal to normal
31  vtkVector3d result;
32  if (fabs(in.Dot(normal)) > 0.999) // some epsilon
33  {
34  if (fabs(normal[0]) < 0.1)
35  {
36  result.Set(1.0,0.0,0.0);
37  }
38  else
39  {
40  result.Set(0.0,1.0,0.0);
41  }
42  }
43  else
44  {
45  result = in - (in.Dot(normal))*normal;
46  result.Normalize();
47  }
48  return result;
49  };
50 
52  win->GetPhysicalTranslation(this->Translation);
53  win->GetPhysicalViewUp(this->PhysicalViewUp);
54  this->Distance = win->GetPhysicalScale();
56  static_cast<vtkInteractorStyle3D *>(win->GetInteractor()->GetInteractorStyle());
57  this->MotionFactor = is->GetDollyPhysicalSpeed();
58 
59  cam->GetPosition(this->Position);
60 
61  win->GetPhysicalViewDirection(this->PhysicalViewDirection);
62  cam->GetDirectionOfProjection(this->ViewDirection);
63 
64  this->Loaded = true;
65  };
66 
68 
69  // s = saved values
70  vtkVector3d svup(this->PhysicalViewUp);
71  vtkVector3d svdir(this->ViewDirection);
72  vtkVector3d strans(this->Translation);
73  vtkVector3d spos(this->Position);
74  double sdistance = this->Distance;
75 
76  // c = current values
77  vtkVector3d cvup;
78  win->GetPhysicalViewUp(cvup.GetData());
79  vtkVector3d cpos;
80  cam->GetPosition(cpos.GetData());
81  vtkVector3d ctrans;
82  win->GetPhysicalTranslation(ctrans.GetData());
83  vtkVector3d cvdir;
84  cam->GetDirectionOfProjection(cvdir.GetData());
85  vtkVector3d civdir;
86  win->GetPhysicalViewDirection(civdir.GetData());
87  double cdistance = win->GetPhysicalScale();
88 
89  // n = new values
90  vtkVector3d nvup = svup;
91  win->SetPhysicalViewUp(nvup.GetData());
92 
93  // sanitize the svdir, must be orthogonal to nvup
94  svdir = this->SanitizeVector(svdir, nvup);
95 
96  // make sure cvdir and civdir are orthogonal to our nvup
97  cvdir = this->SanitizeVector(cvdir, nvup);
98  civdir = this->SanitizeVector(civdir, nvup);
99  vtkVector3d civright = civdir.Cross(nvup);
100 
101  // find the new initialvdir
102  vtkVector3d nivdir;
103  double theta = acos(svdir.Dot(cvdir));
104  if (nvup.Dot(cvdir.Cross(svdir)) < 0.0)
105  {
106  theta = -theta;
107  }
108  // rotate civdir by theta
109  nivdir = civdir*cos(theta) - civright*sin(theta);
110  win->SetPhysicalViewDirection(nivdir.GetData());
111  vtkVector3d nivright = nivdir.Cross(nvup);
112 
113  // adjust translation so that we are in the same spot
114  // as when the camera was saved
115  vtkVector3d ntrans;
116  vtkVector3d cppwc;
117  cppwc = cpos + ctrans;
118  double x = cppwc.Dot(civdir)/cdistance;
119  double y = cppwc.Dot(civright)/cdistance;
120 
121  ntrans =
122  strans*nvup +
123  nivdir*(x*sdistance - spos.Dot(nivdir)) +
124  nivright*(y*sdistance - spos.Dot(nivright));
125 
126  win->SetPhysicalTranslation(ntrans.GetData());
127  cam->SetPosition(cpos.GetData());
128 
129  // this really only sets the distance as the render loop
130  // sets focal point and position every frame
131  vtkVector3d nfp;
132  nfp = cpos + nivdir*sdistance;
133  cam->SetFocalPoint(nfp.GetData());
134  win->SetPhysicalScale(sdistance);
135 
136 #if 0
137  win->SetPhysicalViewDirection(this->PhysicalViewDirection);
138  cam->SetTranslation(this->Translation);
139  cam->SetFocalPoint(this->FocalPoint);
140  cam->SetPosition(
141  this->FocalPoint[0] - this->PhysicalViewDirection[0]*this->Distance,
142  this->FocalPoint[1] - this->PhysicalViewDirection[1]*this->Distance,
143  this->FocalPoint[2] - this->PhysicalViewDirection[2]*this->Distance);
144 #endif
145 
146  win->SetPhysicalViewUp(this->PhysicalViewUp);
148  static_cast<vtkInteractorStyle3D *>(win->GetInteractor()->GetInteractorStyle());
149  is->SetDollyPhysicalSpeed(this->MotionFactor);
150  }
151 };
152 
154 {
155 public:
156  vtkOpenVROverlaySpot(int x1, int x2, int y1, int y2, vtkCommand *cb) {
157  this->xmin = x1;
158  this->xmax = x2;
159  this->ymin = y1;
160  this->ymax = y2;
161  this->Callback = cb;
162  cb->Register(nullptr);
163  this->Active = false;
164  }
166  if (this->Callback)
167  {
168  this->Callback->Delete();
169  this->Callback = nullptr;
170  }
171  }
172  bool Active;
173  int xmin;
174  int xmax;
175  int ymin;
176  int ymax;
179  int GroupId;
180 
182  this->xmin = in.xmin;
183  this->xmax = in.xmax;
184  this->ymin = in.ymin;
185  this->ymax = in.ymax;
186  this->Callback = in.Callback;
187  this->Callback->Register(0);
188  this->Active = in.Active;
189  this->Group = in.Group;
190  this->GroupId = in.GroupId;
191  }
192  vtkOpenVROverlaySpot& operator=(const vtkOpenVROverlaySpot&) = delete;
193 };
194 
195 //****************************************************************************
196 // VTK-HeaderTest-Exclude: vtkOpenVROverlayInternal.h
virtual void SetPhysicalTranslation(double, double, double)
Set/get physical coordinate system in world coordinate system.
OpenVR camera.
double Normalize()
Normalize the vector in place.
Definition: vtkVector.h:91
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
virtual void SetPhysicalViewUp(double, double, double)
Set/get physical coordinate system in world coordinate system.
vtkVector3d SanitizeVector(vtkVector3d &in, vtkVector3d &normal)
virtual void SetDollyPhysicalSpeed(double)
Set/Get the maximum dolly speed used when flying in 3D, in meters per second.
virtual double * GetPhysicalTranslation()
Set/get physical coordinate system in world coordinate system.
virtual double * GetDirectionOfProjection()
Get the vector in the direction from the camera position to the focal point.
extends interaction to support 3D input
virtual double * GetPhysicalViewUp()
Set/get physical coordinate system in world coordinate system.
void SetPosition(double x, double y, double z)
Set/Get the position of the camera in world coordinates.
vtkOpenVROverlaySpot(int x1, int x2, int y1, int y2, vtkCommand *cb)
virtual double GetDollyPhysicalSpeed()
Set/Get the maximum dolly speed used when flying in 3D, in meters per second.
T Dot(const vtkVector< T, Size > &other) const
The dot product of this and the supplied vector.
Definition: vtkVector.h:120
virtual double * GetPosition()
Set/Get the position of the camera in world coordinates.
superclass for callback/observer methods
Definition: vtkCommand.h:370
virtual double * GetPhysicalViewDirection()
Set/get physical coordinate system in world coordinate system.
virtual void SetPhysicalViewDirection(double, double, double)
Set/get physical coordinate system in world coordinate system.
virtual double GetPhysicalScale()
Set/get physical coordinate system in world coordinate system.
void Set(const T &x, const T &y, const T &z)
Set the x, y and z components of the vector.
Definition: vtkVector.h:243
vtkOpenVROverlaySpot(const vtkOpenVROverlaySpot &in)
void Apply(vtkOpenVRCamera *cam, vtkOpenVRRenderWindow *win)
void SetFocalPoint(double x, double y, double z)
Set/Get the focal of the camera in world coordinates.
virtual vtkRenderWindowInteractor * GetInteractor()
Get the interactor associated with this render window.
vtkVector3< T > Cross(const vtkVector3< T > &other) const
Return the cross product of this X other.
Definition: vtkVector.h:285
void Set(vtkOpenVRCamera *cam, vtkOpenVRRenderWindow *win)
OpenVR rendering window.
T * GetData()
Get a pointer to the underlying data of the tuple.
Definition: vtkTuple.h:79
virtual void SetPhysicalScale(double)
Set/get physical coordinate system in world coordinate system.
virtual vtkInteractorObserver * GetInteractorStyle()
External switching between joystick/trackball/new? modes.