VTK  9.0.20200704
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 #ifndef vtkPVOpenVROverlayInternal_h
16 #define vtkPVOpenVROverlayInternal_h
17 
18 #include "vtkInteractorStyle3D.h"
19 #include "vtkOpenVRCamera.h"
20 #include "vtkOpenVRRenderWindow.h"
22 #include "vtkVectorOperators.h"
23 
25 {
26 public:
27  double Position[3];
28  double PhysicalViewUp[3];
30  double ViewDirection[3];
31  double Translation[3];
32  double Distance;
33  double MotionFactor = 1.0;
34  bool Loaded = false;
35 
36  // return a vector based on in that is orthogonal to normal
38  {
39  vtkVector3d result;
40  if (fabs(in.Dot(normal)) > 0.999) // some epsilon
41  {
42  if (fabs(normal[0]) < 0.1)
43  {
44  result.Set(1.0, 0.0, 0.0);
45  }
46  else
47  {
48  result.Set(0.0, 1.0, 0.0);
49  }
50  }
51  else
52  {
53  result = in - (in.Dot(normal)) * normal;
54  result.Normalize();
55  }
56  return result;
57  }
58 
60  {
61  win->GetPhysicalTranslation(this->Translation);
62  win->GetPhysicalViewUp(this->PhysicalViewUp);
63  this->Distance = win->GetPhysicalScale();
65  static_cast<vtkInteractorStyle3D*>(win->GetInteractor()->GetInteractorStyle());
66  this->MotionFactor = is->GetDollyPhysicalSpeed();
67 
68  cam->GetPosition(this->Position);
69 
70  win->GetPhysicalViewDirection(this->PhysicalViewDirection);
71  cam->GetDirectionOfProjection(this->ViewDirection);
72 
73  this->Loaded = true;
74  }
75 
77  {
78 
79  // s = saved values
80  vtkVector3d svup(this->PhysicalViewUp);
81  vtkVector3d svdir(this->ViewDirection);
82  vtkVector3d strans(this->Translation);
83  vtkVector3d spos(this->Position);
84  double sdistance = this->Distance;
85 
86  // c = current values
87  vtkVector3d cvup;
88  win->GetPhysicalViewUp(cvup.GetData());
89  vtkVector3d cpos;
90  cam->GetPosition(cpos.GetData());
91  vtkVector3d ctrans;
92  win->GetPhysicalTranslation(ctrans.GetData());
93  vtkVector3d cvdir;
94  cam->GetDirectionOfProjection(cvdir.GetData());
95  vtkVector3d civdir;
96  win->GetPhysicalViewDirection(civdir.GetData());
97  double cdistance = win->GetPhysicalScale();
98 
99  // n = new values
100  vtkVector3d nvup = svup;
101  win->SetPhysicalViewUp(nvup.GetData());
102 
103  // sanitize the svdir, must be orthogonal to nvup
104  svdir = this->SanitizeVector(svdir, nvup);
105 
106  // make sure cvdir and civdir are orthogonal to our nvup
107  cvdir = this->SanitizeVector(cvdir, nvup);
108  civdir = this->SanitizeVector(civdir, nvup);
109  vtkVector3d civright = civdir.Cross(nvup);
110 
111  // find the new initialvdir
112  vtkVector3d nivdir;
113  double theta = acos(svdir.Dot(cvdir));
114  if (nvup.Dot(cvdir.Cross(svdir)) < 0.0)
115  {
116  theta = -theta;
117  }
118  // rotate civdir by theta
119  nivdir = civdir * cos(theta) - civright * sin(theta);
120  win->SetPhysicalViewDirection(nivdir.GetData());
121  vtkVector3d nivright = nivdir.Cross(nvup);
122 
123  // adjust translation so that we are in the same spot
124  // as when the camera was saved
125  vtkVector3d ntrans;
126  vtkVector3d cppwc;
127  cppwc = cpos + ctrans;
128  double x = cppwc.Dot(civdir) / cdistance;
129  double y = cppwc.Dot(civright) / cdistance;
130 
131  ntrans = strans * nvup + nivdir * (x * sdistance - spos.Dot(nivdir)) +
132  nivright * (y * sdistance - spos.Dot(nivright));
133 
134  win->SetPhysicalTranslation(ntrans.GetData());
135  cam->SetPosition(cpos.GetData());
136 
137  // this really only sets the distance as the render loop
138  // sets focal point and position every frame
139  vtkVector3d nfp;
140  nfp = cpos + nivdir * sdistance;
141  cam->SetFocalPoint(nfp.GetData());
142  win->SetPhysicalScale(sdistance);
143 
144 #if 0
145  win->SetPhysicalViewDirection(this->PhysicalViewDirection);
146  cam->SetTranslation(this->Translation);
147  cam->SetFocalPoint(this->FocalPoint);
148  cam->SetPosition(
149  this->FocalPoint[0] - this->PhysicalViewDirection[0]*this->Distance,
150  this->FocalPoint[1] - this->PhysicalViewDirection[1]*this->Distance,
151  this->FocalPoint[2] - this->PhysicalViewDirection[2]*this->Distance);
152 #endif
153 
154  win->SetPhysicalViewUp(this->PhysicalViewUp);
156  static_cast<vtkInteractorStyle3D*>(win->GetInteractor()->GetInteractorStyle());
157  is->SetDollyPhysicalSpeed(this->MotionFactor);
158  }
159 };
160 
162 {
163 public:
164  vtkOpenVROverlaySpot(int x1, int x2, int y1, int y2, vtkCommand* cb)
165  {
166  this->xmin = x1;
167  this->xmax = x2;
168  this->ymin = y1;
169  this->ymax = y2;
170  this->Callback = cb;
171  cb->Register(nullptr);
172  this->Active = false;
173  }
175  {
176  if (this->Callback)
177  {
178  this->Callback->Delete();
179  this->Callback = nullptr;
180  }
181  }
182  bool Active;
183  int xmin;
184  int xmax;
185  int ymin;
186  int ymax;
189  int GroupId;
190 
192  {
193  this->xmin = in.xmin;
194  this->xmax = in.xmax;
195  this->ymin = in.ymin;
196  this->ymax = in.ymax;
197  this->Callback = in.Callback;
198  this->Callback->Register(0);
199  this->Active = in.Active;
200  this->Group = in.Group;
201  this->GroupId = in.GroupId;
202  }
204 };
205 
206 #endif // vtkPVOpenVROverlayInternal_h
207 
208 //****************************************************************************
209 // VTK-HeaderTest-Exclude: vtkOpenVROverlayInternal.h
vtkOpenVRRenderWindow::GetPhysicalScale
virtual double GetPhysicalScale()
vtkOpenVROverlaySpot::xmax
int xmax
Definition: vtkOpenVROverlayInternal.h:184
vtkCommand
superclass for callback/observer methods
Definition: vtkCommand.h:377
vtkOpenVRRenderWindow::SetPhysicalViewUp
virtual void SetPhysicalViewUp(double, double, double)
Set/get physical coordinate system in world coordinate system.
vtkOpenVRRenderWindow.h
vtkOpenVRCameraPose::Position
double Position[3]
Definition: vtkOpenVROverlayInternal.h:27
vtkInteractorStyle3D.h
vtkInteractorStyle3D::SetDollyPhysicalSpeed
virtual void SetDollyPhysicalSpeed(double)
Set/Get the maximum dolly speed used when flying in 3D, in meters per second.
vtkVector::Normalize
double Normalize()
Normalize the vector in place.
Definition: vtkVector.h:85
vtkObjectBase::Register
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
vtkOpenVROverlaySpot::ymin
int ymin
Definition: vtkOpenVROverlayInternal.h:185
vtkOpenVRCameraPose::PhysicalViewUp
double PhysicalViewUp[3]
Definition: vtkOpenVROverlayInternal.h:28
vtkOpenVROverlaySpot::Active
bool Active
Definition: vtkOpenVROverlayInternal.h:182
vtkOpenVRCameraPose::PhysicalViewDirection
double PhysicalViewDirection[3]
Definition: vtkOpenVROverlayInternal.h:29
vtkOpenVROverlaySpot::vtkOpenVROverlaySpot
vtkOpenVROverlaySpot(const vtkOpenVROverlaySpot &in)
Definition: vtkOpenVROverlayInternal.h:191
vtkOpenVRRenderWindow::SetPhysicalScale
virtual void SetPhysicalScale(double)
Set/get physical coordinate system in world coordinate system.
vtkObjectBase::Delete
virtual void Delete()
Delete a VTK object.
vtkOpenVROverlaySpot::Callback
vtkCommand * Callback
Definition: vtkOpenVROverlayInternal.h:187
vtkOpenVROverlaySpot::GroupId
int GroupId
Definition: vtkOpenVROverlayInternal.h:189
vtkOpenVRCameraPose::Loaded
bool Loaded
Definition: vtkOpenVROverlayInternal.h:34
vtkCamera::SetFocalPoint
void SetFocalPoint(double x, double y, double z)
Set/Get the focal of the camera in world coordinates.
vtkOpenVRCameraPose::Apply
void Apply(vtkOpenVRCamera *cam, vtkOpenVRRenderWindow *win)
Definition: vtkOpenVROverlayInternal.h:76
vtkOpenVRCameraPose::Set
void Set(vtkOpenVRCamera *cam, vtkOpenVRRenderWindow *win)
Definition: vtkOpenVROverlayInternal.h:59
vtkOpenVRCameraPose::Translation
double Translation[3]
Definition: vtkOpenVROverlayInternal.h:31
vtkRenderWindowInteractor::GetInteractorStyle
virtual vtkInteractorObserver * GetInteractorStyle()
vtkRenderWindow::GetInteractor
virtual vtkRenderWindowInteractor * GetInteractor()
Get the interactor associated with this render window.
vtkInteractorStyle3D::GetDollyPhysicalSpeed
virtual double GetDollyPhysicalSpeed()
vtkOpenVROverlaySpot::ymax
int ymax
Definition: vtkOpenVROverlayInternal.h:186
vtkOpenVROverlaySpot::xmin
int xmin
Definition: vtkOpenVROverlayInternal.h:183
vtkOpenVROverlaySpot::Group
std::string Group
Definition: vtkOpenVROverlayInternal.h:188
vtkOpenVRRenderWindow::SetPhysicalTranslation
virtual void SetPhysicalTranslation(double, double, double)
Set/get physical coordinate system in world coordinate system.
vtkOpenVRCameraPose::Distance
double Distance
Definition: vtkOpenVROverlayInternal.h:32
vtkOpenVRRenderWindow
OpenVR rendering window.
Definition: vtkOpenVRRenderWindow.h:70
vtkTuple::GetData
T * GetData()
Get a pointer to the underlying data of the tuple.
Definition: vtkTuple.h:77
vtkCamera::SetPosition
void SetPosition(double x, double y, double z)
Set/Get the position of the camera in world coordinates.
vtkOpenVRCameraPose
Definition: vtkOpenVROverlayInternal.h:24
vtkVector3::Cross
vtkVector3< T > Cross(const vtkVector3< T > &other) const
Return the cross product of this X other.
Definition: vtkVector.h:283
vtkOpenVROverlaySpot::vtkOpenVROverlaySpot
vtkOpenVROverlaySpot(int x1, int x2, int y1, int y2, vtkCommand *cb)
Definition: vtkOpenVROverlayInternal.h:164
vtkCamera::GetDirectionOfProjection
virtual double * GetDirectionOfProjection()
Get the vector in the direction from the camera position to the focal point.
vtkOpenVROverlaySpot::operator=
vtkOpenVROverlaySpot & operator=(const vtkOpenVROverlaySpot &)=delete
vtkInteractorStyle3D
extends interaction to support 3D input
Definition: vtkInteractorStyle3D.h:66
vtkX3D::string
Definition: vtkX3D.h:496
vtkOpenVRCameraPose::MotionFactor
double MotionFactor
Definition: vtkOpenVROverlayInternal.h:33
vtkOpenVRCameraPose::ViewDirection
double ViewDirection[3]
Definition: vtkOpenVROverlayInternal.h:30
vtkCamera::GetPosition
virtual double * GetPosition()
vtkOpenVRRenderWindow::GetPhysicalViewUp
virtual double * GetPhysicalViewUp()
vtkVector3::Set
void Set(const T &x, const T &y, const T &z)
Set the x, y and z components of the vector.
Definition: vtkVector.h:241
vtkVectorOperators.h
vtkOpenVRCameraPose::SanitizeVector
vtkVector3d SanitizeVector(vtkVector3d &in, vtkVector3d &normal)
Definition: vtkOpenVROverlayInternal.h:37
vtkOpenVRCamera
OpenVR camera.
Definition: vtkOpenVRCamera.h:35
vtkOpenVROverlaySpot::~vtkOpenVROverlaySpot
~vtkOpenVROverlaySpot()
Definition: vtkOpenVROverlayInternal.h:174
vtkVector::Dot
T Dot(const vtkVector< T, Size > &other) const
The dot product of this and the supplied vector.
Definition: vtkVector.h:118
vtkRenderWindowInteractor.h
vtkOpenVROverlaySpot
Definition: vtkOpenVROverlayInternal.h:161
vtkOpenVRRenderWindow::GetPhysicalTranslation
virtual double * GetPhysicalTranslation()
vtkVector3d
Definition: vtkVector.h:488
vtkOpenVRCamera.h
vtkOpenVRRenderWindow::GetPhysicalViewDirection
virtual double * GetPhysicalViewDirection()
vtkOpenVRRenderWindow::SetPhysicalViewDirection
virtual void SetPhysicalViewDirection(double, double, double)
Set/get physical coordinate system in world coordinate system.