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 InitialViewUp[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  cam->GetTranslation(this->Translation);
53  win->GetInitialViewUp(this->InitialViewUp);
54  this->Distance = cam->GetDistance();
56  static_cast<vtkInteractorStyle3D *>(win->GetInteractor()->GetInteractorStyle());
57  this->MotionFactor = is->GetDollyMotionFactor();
58 
59  cam->GetPosition(this->Position);
60 
63 
64  this->Loaded = true;
65  };
66 
68 
69  // s = saved values
70  vtkVector3d svup(this->InitialViewUp);
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->GetInitialViewUp(cvup.GetData());
79  vtkVector3d cpos;
80  cam->GetPosition(cpos.GetData());
81  vtkVector3d ctrans;
82  cam->GetTranslation(ctrans.GetData());
83  vtkVector3d cvdir;
84  cam->GetDirectionOfProjection(cvdir.GetData());
85  vtkVector3d civdir;
86  win->GetInitialViewDirection(civdir.GetData());
87  double cdistance = cam->GetDistance();
88 
89  // n = new values
90  vtkVector3d nvup = svup;
91  win->SetInitialViewUp(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->SetInitialViewDirection(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  cam->SetTranslation(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 
135 #if 0
137  cam->SetTranslation(this->Translation);
138  cam->SetFocalPoint(this->FocalPoint);
139  cam->SetPosition(
140  this->FocalPoint[0] - this->InitialViewDirection[0]*this->Distance,
141  this->FocalPoint[1] - this->InitialViewDirection[1]*this->Distance,
142  this->FocalPoint[2] - this->InitialViewDirection[2]*this->Distance);
143 #endif
144 
145  win->SetInitialViewUp(this->InitialViewUp);
147  static_cast<vtkInteractorStyle3D *>(win->GetInteractor()->GetInteractorStyle());
149  }
150 };
151 
153 {
154 public:
155  vtkOpenVROverlaySpot(int x1, int x2, int y1, int y2, vtkCommand *cb) {
156  this->xmin = x1;
157  this->xmax = x2;
158  this->ymin = y1;
159  this->ymax = y2;
160  this->Callback = cb;
161  cb->Register(NULL);
162  this->Active = false;
163  }
165  if (this->Callback)
166  {
167  this->Callback->Delete();
168  this->Callback = NULL;
169  }
170  }
171  bool Active;
172  int xmin;
173  int xmax;
174  int ymin;
175  int ymax;
178  int GroupId;
179 
181  this->xmin = in.xmin;
182  this->xmax = in.xmax;
183  this->ymin = in.ymin;
184  this->ymax = in.ymax;
185  this->Callback = in.Callback;
186  this->Callback->Register(0);
187  this->Active = in.Active;
188  this->Group = in.Group;
189  this->GroupId = in.GroupId;
190  }
191  vtkOpenVROverlaySpot& operator=(const vtkOpenVROverlaySpot&) VTK_DELETE_FUNCTION;
192 };
193 
194 //****************************************************************************
195 // VTK-HeaderTest-Exclude: vtkOpenVROverlayInternal.h
OpenVR camera.
double Normalize()
Normalize the vector in place.
Definition: vtkVector.h:88
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
vtkVector3d SanitizeVector(vtkVector3d &in, vtkVector3d &normal)
virtual double * GetDirectionOfProjection()
Get the vector in the direction from the camera position to the focal point.
extends interaction to support 3D input
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)
T Dot(const vtkVector< T, Size > &other) const
The dot product of this and the supplied vector.
Definition: vtkVector.h:117
virtual double * GetPosition()
Set/Get the position of the camera in world coordinates.
superclass for callback/observer methods
Definition: vtkCommand.h:354
virtual double * GetTranslation()
Set/Get the translation to map world coordinates into the OpenVR physical space (meters, 0,0,0).
vtkOpenVROverlaySpot & operator=(const vtkOpenVROverlaySpot &) VTK_DELETE_FUNCTION
virtual void SetTranslation(double, double, double)
Set/Get the translation to map world coordinates into the OpenVR physical space (meters, 0,0,0).
void Set(const T &x, const T &y, const T &z)
Set the x, y and z components of the vector.
Definition: vtkVector.h:240
vtkOpenVROverlaySpot(const vtkOpenVROverlaySpot &in)
void Apply(vtkOpenVRCamera *cam, vtkOpenVRRenderWindow *win)
virtual double GetDistance()
Return the distance from the camera position to the focal point.
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:282
void Set(vtkOpenVRCamera *cam, vtkOpenVRRenderWindow *win)
OpenVR rendering window.
virtual double * GetInitialViewUp()
Control the Vive to World transformations.
T * GetData()
Get a pointer to the underlying data of the tuple.
Definition: vtkTuple.h:79
virtual double GetDollyMotionFactor()
Set/Get the dolly motion factor used when flying in 3D.
virtual void SetInitialViewUp(double, double, double)
Control the Vive to World transformations.
virtual double * GetInitialViewDirection()
Control the Vive to World transformations.
virtual void SetDollyMotionFactor(double)
Set/Get the dolly motion factor used when flying in 3D.
virtual void Delete()
Delete a VTK object.
virtual vtkInteractorObserver * GetInteractorStyle()
External switching between joystick/trackball/new? modes.
virtual void SetInitialViewDirection(double, double, double)
Control the Vive to World transformations.