<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>                                   void* vtkNotUsed(clientData), void* vtkNotUsed(callData) )<br>{<br>  std::cout << "Mousepress2 callback" << std::endl;<br> <br>  vtkRenderWindowInteractor *iren = <br>    static_cast<vtkRenderWindowInteractor*>(caller);<br><br>  std::cout << "Picking pixel: " << iren->GetEventPosition()[0] <br>        << " " << iren->GetEventPosition()[1] << std::endl;<br><br>  // First point:<br>  double display1[3];<br>  display1[0] = iren->GetEventPosition()[0];<br>  display1[1] = iren->GetEventPosition()[1];<br>  display1[2] = -1;<br><br>  iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->SetDisplayPoint(display1);<br>  iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->DisplayToWorld();<br>  double* world1 = iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetWorldPoint();<br>  double world_coordinate1[3];<br>  for (int i=0; i<3; i++)<br>      world_coordinate1[i] = world1[i];<br><br>  // Second point:<br>  double display2[3];<br>  display2[0] = display1[0];<br>  display2[1] = display1[1];<br>  display2[2] = 1;<br><br>  iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->SetDisplayPoint(display2);<br>  iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->DisplayToWorld();<br>  double* world2 = iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->GetWorldPoint();<br>  double world_coordinate2[3];<br>  for (int i=0; i<3; i++)<br>      world_coordinate2[i] = world2[i];<br><br>  // 3D line from first point to second point:<br>  vtkLineSource* line = vtkLineSource::New();<br>  vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();<br>  vtkActor* actor = vtkActor::New();<br><br>  line->SetPoint1(world_coordinate1[0],<br>                  world_coordinate1[1],<br>                  world_coordinate1[2]);<br>  line->SetPoint2(world_coordinate2[0],<br>                  world_coordinate2[1],<br>                  world_coordinate2[2]);<br><br>  mapper->SetInput(line->GetOutput());<br>  actor->SetMapper(mapper);<br><br>  iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(actor);<br>}<br>                                    </div></body>
</html>