Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL context issues when observing the VR camera #37

Open
cpinter opened this issue Jun 18, 2018 · 0 comments
Open

OpenGL context issues when observing the VR camera #37

cpinter opened this issue Jun 18, 2018 · 0 comments
Labels

Comments

@cpinter
Copy link
Collaborator

cpinter commented Jun 18, 2018

If the VR camera is observed, and the callback makes changes in the MRML scene, then the OpenGL context produces strange symptoms, such as showing nothing, or even a previously shown scene in one VR view while the other is showing the proper scene.

To reproduce:

  • Add observation to VR camera
    vrViewWidget = slicer.modules.virtualreality.viewWidget()
    rendererCollection = vrViewWidget.renderWindow().GetRenderers()
    vrRenderer = rendererCollection.GetItemAsObject(0)
    self.vrCamera = vrRenderer.GetActiveCamera()
    self.addObserver(self.vrCamera, vtk.vtkCommand.ModifiedEvent, self.onVrCameraModified)
  • Set a matrix
  def onVrCameraModified(self,caller,event):
    avatarTransformNode = self.headAvatarModelNode.GetParentTransformNode()

    # Move and orient avatar model to VR camera
    import numpy as np
    position = self.vrCamera.GetPosition()
    positionVector = np.array(position)
    focalPointVector = np.array(self.vrCamera.GetFocalPoint())
    viewUpVector = np.array(self.vrCamera.GetViewUp())
    # Z
    zAxis = focalPointVector - positionVector
    zAxisLength = np.linalg.norm(zAxis)
    zAxis = zAxis / zAxisLength
    # X
    xAxis = np.array(viewUpVector)
    # Y
    yAxis = np.cross(zAxis, xAxis)
    # Matrix
    avatarTransformMatrix = vtk.vtkMatrix4x4()
    for z in xrange(3):
      avatarTransformMatrix.SetElement(z,2,zAxis[z])
    for y in xrange(3):
      avatarTransformMatrix.SetElement(y,1,yAxis[y])
    for x in xrange(3):
      avatarTransformMatrix.SetElement(x,0,xAxis[x])
    for p in xrange(3):
      avatarTransformMatrix.SetElement(p,3,position[p])
    avatarTransformNode.SetMatrixTransformToParent(avatarTransformMatrix)

If a QTimer.singleShot triggers a function that does this calculation and SetMatrixTransformToParent, then everything works well.

Maybe if the VR camera is modified with a different timing, then this issue wouldn't come up. For example it could be done as the first step and not while doing the rendering, or an event could be invoked that sets the camera.

@cpinter cpinter added the bug label Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant