<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Hi All,<br><br>I meet some difficulty with VTK while trying 
to draw a 3D line vertical to the screen passing through the mouse clicked 
point. My source code is as follows. After I run the code, I couldn't 
get a 3D line vertical to the screen, but get a 3D line drawn away from 
the mouse clicked point and not vertical to the screen. Would like to 
know how to solve the problem. Many thanks.<br><br>void MousepressCallbackFunction2 ( vtkObject* caller, long unsigned int vtkNotUsed(eventId), <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void* vtkNotUsed(clientData), void* vtkNotUsed(callData) )<br>{<br>&nbsp; std::cout &lt;&lt; "Mousepress2 callback" &lt;&lt; std::endl;<br>&nbsp;<br>&nbsp; vtkRenderWindowInteractor *iren = <br>&nbsp;&nbsp;&nbsp; static_cast&lt;vtkRenderWindowInteractor*&gt;(caller);<br><br>&nbsp; std::cout &lt;&lt; "Picking pixel: " &lt;&lt; iren-&gt;GetEventPosition()[0] <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;&lt; " " &lt;&lt; iren-&gt;GetEventPosition()[1] &lt;&lt; std::endl;<br><br>&nbsp; // First point:<br>&nbsp; double display1[3];<br>&nbsp; display1[0] = iren-&gt;GetEventPosition()[0];<br>&nbsp; display1[1] = iren-&gt;GetEventPosition()[1];<br>&nbsp; display1[2] = -1;<br><br>&nbsp; iren-&gt;GetRenderWindow()-&gt;GetRenderers()-&gt;GetFirstRenderer()-&gt;SetDisplayPoint(display1);<br>&nbsp; iren-&gt;GetRenderWindow()-&gt;GetRenderers()-&gt;GetFirstRenderer()-&gt;DisplayToWorld();<br>&nbsp; double* world1 = iren-&gt;GetRenderWindow()-&gt;GetRenderers()-&gt;GetFirstRenderer()-&gt;GetWorldPoint();<br>&nbsp; double world_coordinate1[3];<br>&nbsp; for (int i=0; i&lt;3; i++)<br>&nbsp;&nbsp;&nbsp; &nbsp; world_coordinate1[i] = world1[i];<br><br>&nbsp; // Second point:<br>&nbsp; double display2[3];<br>&nbsp; display2[0] = display1[0];<br>&nbsp; display2[1] = display1[1];<br>&nbsp; display2[2] = 1;<br><br>&nbsp; iren-&gt;GetRenderWindow()-&gt;GetRenderers()-&gt;GetFirstRenderer()-&gt;SetDisplayPoint(display2);<br>&nbsp; iren-&gt;GetRenderWindow()-&gt;GetRenderers()-&gt;GetFirstRenderer()-&gt;DisplayToWorld();<br>&nbsp; double* world2 = iren-&gt;GetRenderWindow()-&gt;GetRenderers()-&gt;GetFirstRenderer()-&gt;GetWorldPoint();<br>&nbsp; double world_coordinate2[3];<br>&nbsp; for (int i=0; i&lt;3; i++)<br>&nbsp;&nbsp;&nbsp; &nbsp; world_coordinate2[i] = world2[i];<br><br>&nbsp; // 3D line from first point to second point:<br>&nbsp; vtkLineSource* line = vtkLineSource::New();<br>&nbsp; vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();<br>&nbsp; vtkActor* actor = vtkActor::New();<br><br>&nbsp; line-&gt;SetPoint1(world_coordinate1[0],<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; world_coordinate1[1],<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; world_coordinate1[2]);<br>&nbsp; line-&gt;SetPoint2(world_coordinate2[0],<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; world_coordinate2[1],<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; world_coordinate2[2]);<br><br>&nbsp; mapper-&gt;SetInput(line-&gt;GetOutput());<br>&nbsp; actor-&gt;SetMapper(mapper);<br><br>&nbsp; iren-&gt;GetRenderWindow()-&gt;GetRenderers()-&gt;GetFirstRenderer()-&gt;AddActor(actor);<br>}<br>                                               </div></body>
</html>