How to understand the depth of a display point?

I am reading the source code of VTK, and there is one concept make me confuzed.

In the operation of camera (pan, zoom in/out), there is some code like:

  vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
  camera->GetFocalPoint(viewFocus);
  this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1], viewFocus[2],
                              viewFocus);
  focalDepth = viewFocus[2];

  this->ComputeDisplayToWorld(rwi->GetEventPosition()[0],
                              rwi->GetEventPosition()[1],
                              focalDepth,
                              newPickPoint);

image

In the above figure, in my understanding, the position of object is the focal point. Am I right?

what make me confuzed is the focalDepth. How to understand the focalDepth? The world point should be [x, y, z], and the display point should be [x, y]. Now, the this->ComputeWorldToDisplay would retuen a [x, y, depth]. How to understand the depth?

Hi, Zhang,

Focal point is the point in space where the camera is looking at. Focal depth is the distance between the camera and something in the scene. This value is used, for instance, in the Z buffer (also called depth buffer) to compute occlusions.

cheers,

Paulo

Do not confuse focal depth in this context with depth of focus in photography.

Thank you very much for your kindly reply. But I still have questions about thd display coordiante.

The display coordiante and world coordinate conversion is a very important function in vtk. To convert display coordinate to world coordinate, I can find three method:

First, vtkPropPicker:

picker = vtk.vtkPropPicker()
picker.Pick(x, y, 0, self.renderer) ##### selectionZ = 0 would give the correct world coordinate
                                    ##### if so, why do not design a function as: Pick(x, y, renderer) ??
world = picker.GetPickPosition()

Second, vtkCoordinate:

        coordinate = vtk.vtkCoordinate()
        coordinate.SetCoordinateSystemToDisplay()
        coordinate.SetValue(x, y)
        world = coordinate.GetComputedWorldValue(self.renderer)  ### Actually, the world is wrong

Finally:

renderer.SetDisplayPoint(x, y, z) ### I don't know what should be the z?? Is z the depth?
                                  ### if z=0, the result is wrong. 
renderer.DisplayToWorld()
worldPoint = list(self.renderer.GetWorldPoint())

I don’t know which one is correct. Why vtk provide so manny different method? What’s the difference between vtkPropPicker, vtkCoordinate, and renderer.DisplayToWorld()?

Hi, Zhang,

There is no wrong or right method. It depends on your objective. One difference is performance. For example, picking tends to be slower but it is designed for interacting with objects in the screen with the mouse.
I’d suggest you to read the documentation of the mentioned methods to see which suits your need.

cheers,

Paulo

Dear Paulo,

import vtk

cone = vtk.vtkConeSource()
cone.SetCenter(150, 150, 0)
cone.SetHeight(100)
cone.SetRadius(50)
cone.Update()
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputData(cone.GetOutput())
coneMapper.Update()
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)

ren = vtk.vtkRenderer()
ren.AddActor(coneActor)
ren.SetBackground(0.1, 0.2, 0.4)


renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(400, 400)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

renWin.Render()
X = 100
Y = 100
picker = vtk.vtkPropPicker()
picker.Pick(X, Y, 0, ren)
pickerWorld = picker.GetPickPosition()
print('world point from vtkPropPicker: ', pickerWorld)

coordinate = vtk.vtkCoordinate()
coordinate.SetCoordinateSystemToDisplay()
coordinate.SetValue(X, Y)
coorWorld = coordinate.GetComputedWorldValue(ren)
print('world point from vtkCoordinate: ', coorWorld)

Please have a look for the above code. I print the world point from vtkPropPicker and vtkCoordinate, and the result is different:

world point from vtkPropPicker:  (108.0365506828649, 108.0365506828649, 7.141902959080343)
world point from vtkCoordinate:  (119.0534474476644, 119.0534474476644, 89.37313989502613)

Since the result is different, there must be one correct and one wrong.

Best wishes,
Qiang