<div dir="ltr"><div>Hi VTK Experts,</div><div>Sorry for previous email that was sent by mistake.</div><div><br></div><div>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.</div><div><br></div><div>So far, I have found two ways to do it, in python:</div><div>
<p class="gmail-p1"><span class="gmail-s1">Method 1:</span></p><p class="gmail-p1"><span class="gmail-s1"><b>def </b></span>display_to_world(<span class="gmail-s2">self</span>, pt):<br>
<span class="gmail-s2">self</span>.world_picker.Pick(pt[<span class="gmail-s3">0</span>], pt[<span class="gmail-s3">1</span>], <span class="gmail-s3">0</span>, <span class="gmail-s2">self</span>.renderer)<br>
picker_pt = <span class="gmail-s2">self</span>.world_picker.GetPickPosition()<br>
<span class="gmail-s1"><b>return </b></span>picker_pt<br>
<br>Mehtod 2:<br>
<span class="gmail-s1"><b>def </b></span>display_to_world(<span class="gmail-s2">self</span>, pt):<br>
worldPt = [<span class="gmail-s3">0</span>, <span class="gmail-s3">0</span>, <span class="gmail-s3">0</span>, <span class="gmail-s3">0</span>]<br>
vtk.vtkInteractorObserver.ComputeDisplayToWorld(<span class="gmail-s2">self</span>.renderer,<br>
pt[<span class="gmail-s3">0</span>], pt[<span class="gmail-s3">1</span>], <span class="gmail-s3">0</span>,<br>
worldPt)<br>
<span class="gmail-s1"><b>return </b></span>worldPt[<span class="gmail-s3">0</span>] / worldPt[<span class="gmail-s3">3</span>], worldPt[<span class="gmail-s3">1</span>] / worldPt[<span class="gmail-s3">3</span>], worldPt[<span class="gmail-s3">2</span>] / worldPt[<span class="gmail-s3">3</span>]</p></div><div>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: </div><div>
<p class="gmail-p1"><span class="gmail-s1"><b>def </b></span>world_to_display(<span class="gmail-s2">self</span>, pt):<br>
displayPt = [<span class="gmail-s3">0</span>, <span class="gmail-s3">0</span>, <span class="gmail-s3">0</span>]<br>
vtk.vtkInteractorObserver.ComputeWorldToDisplay(<span class="gmail-s2">self</span>.renderer,<br>
pt[<span class="gmail-s3">0</span>], pt[<span class="gmail-s3">1</span>], pt[<span class="gmail-s3">2</span>],<br>
displayPt)<br>
<span class="gmail-s1"><b>return </b></span>displayPt[:<span class="gmail-s3">2</span>]</p><p class="gmail-p1">What I have observed is that, ComputeDisplayToWorld always returns with a z value, but vtkWorldPicker method does not.</p><p class="gmail-p1">Please let let me know if can help or you need more details.</p></div><div><br></div><div><div class="gmail_signature"><div dir="ltr"><div>Many thanks.<br><br><br></div>Bill<br></div></div></div>
</div>