Sadly, yes, this is the way to do it.  If you want, there is a class that offers static convenience methods:<br><br>static void vtkInteractorObserver::ComputeDisplayToWorld (vtkRenderer *ren, double x, double y, double z, double worldPt[4])<br>
static void vtkInteractorObserver::ComputeWorldToDisplay (vtkRenderer *ren, double x, double y, double z, double displayPt[3])<br><br>But if you look at the implementation...<br><br>void vtkInteractorObserver::ComputeWorldToDisplay(vtkRenderer *ren,<br>
                                                  double x, <br>                                                  double y,<br>                                                  double z, <br>                                                  double displayPt[3])<br>
{<br>  ren->SetWorldPoint(x, y, z, 1.0);<br>  ren->WorldToDisplay();<br>  ren->GetDisplayPoint(displayPt);<br>}<br><br>One comment about your code... I'd be careful returning a double* like that.  You don't own that memory, it could change at any time.<br>
<br>Pat<br><br><div class="gmail_quote">On Wed, Sep 8, 2010 at 1:42 PM, Daniel Haehn <span dir="ltr"><<a href="mailto:haehn@bwh.harvard.edu">haehn@bwh.harvard.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi VTK experts,<br>
<br>
I use the following functions to convert between World and Display coordinates and vice versa. I found the method on the mailing list or in some other code.<br>
<br>
Isn't there an easier way to do that? Is it correct at all and is it robust?<br>
<br>
this->GetRenderer is a vtkRenderer.<br>
<br>
//---------------------------------------------------------------------------<br>
/// Convert display to world coordinates<br>
double* vtkMRMLAnnotationThreeDViewDisplayableManager::GetDisplayToWorldCoordinates(double x, double y)<br>
{<br>
  double coordinates[3];<br>
  coordinates[0]=(double)x;<br>
  coordinates[1]=(double)y;<br>
  coordinates[2]=0;<br>
<br>
  this->GetRenderer()->SetDisplayPoint(coordinates);<br>
  this->GetRenderer()->DisplayToView();<br>
  this->GetRenderer()->GetViewPoint(coordinates);<br>
  this->GetRenderer()->ViewToWorld();<br>
  return this->GetRenderer()->GetWorldPoint();<br>
<br>
}<br>
<br>
//---------------------------------------------------------------------------<br>
/// Convert world to display coordinates<br>
double* vtkMRMLAnnotationThreeDViewDisplayableManager::GetWorldToDisplayCoordinates(double * worldPoints)<br>
{<br>
<br>
  vtkDebugMacro("GetWorldToDisplayCoordinates: RAS " << worldPoints[0] << ", " << worldPoints[1] << ", " << worldPoints[2])<br>
<br>
  double * displayCoordinates;<br>
<br>
  this->GetRenderer()->SetWorldPoint(worldPoints);<br>
  this->GetRenderer()->WorldToView();<br>
  displayCoordinates = this->GetRenderer()->GetViewPoint();<br>
  this->GetRenderer()->ViewToDisplay();<br>
<br>
  double * output = this->GetRenderer()->GetDisplayPoint();<br>
<br>
  vtkDebugMacro("GetWorldToDisplayCoordinates: Display " << output[0] << ", " << output[1])<br>
<br>
  return output;<br>
<br>
}<br>
<br>
Thank you,<br>
Daniel<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br>