[vtkusers] Screen coordinates to world coordinates, different results by using different methods
Bill Q
bill.q.hdp at gmail.com
Sun May 21 05:49:34 EDT 2017
Hi VTK Experts,
Sorry for previous email that was sent by mistake.
I have been trying to figure out how the coordinate system works in VTK for
quite some time. I would like to convert screen coordinates into world
coordinates, so I can mark the DICOM images properly using RTSTRUCT.
So far, I have found two ways to do it, in python:
Method 1:
*def *display_to_world(self, pt):
self.world_picker.Pick(pt[0], pt[1], 0, self.renderer)
picker_pt = self.world_picker.GetPickPosition()
*return *picker_pt
Mehtod 2:
*def *display_to_world(self, pt):
worldPt = [0, 0, 0, 0]
vtk.vtkInteractorObserver.ComputeDisplayToWorld(self.renderer,
pt[0], pt[1], 0,
worldPt)
*return *worldPt[0] / worldPt[3], worldPt[1] / worldPt[3], worldPt[2] /
worldPt[3]
However, the result is different between these two methods. So far, using
the vtkWorldPicker is returning the correct coordinates in most cases,
while using ComputeDisplayToWorld is not. What's more confusing is that, if
I just converted both results back to screen coordinates, only the result
from ComputeDisplayToWorld is correct at all times. I used the following
way to convert it from world back to screen:
*def *world_to_display(self, pt):
displayPt = [0, 0, 0]
vtk.vtkInteractorObserver.ComputeWorldToDisplay(self.renderer,
pt[0], pt[1], pt[2],
displayPt)
*return *displayPt[:2]
What I have observed is that, ComputeDisplayToWorld always returns with a z
value, but vtkWorldPicker method does not.
Please let let me know if can help or you need more details.
Many thanks.
Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170521/3f52e32b/attachment.html>
More information about the vtkusers
mailing list