Réf:[vtkusers] Picking a pixel coordinate with vtkPointPicke

Hummel, Jerome Jerome.Hummel at fr.michelin.com
Mon Nov 20 02:19:59 EST 2006


Hi Florent,

I think you forgot to associate your point picker with your render window
interactor (iren->SetPicker(picker)).

-Jerome

____________________Séparateur de messages____________________
Objet : [vtkusers] Picking a pixel coordinate with vtkPointPicker or
Auteur :    Florent.Chandelier at USherbrooke.ca
Date :  17/11/2006 18:48

-- see attachments --
  
-------------- next part --------------
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
Dear VTK users, <br>
<br>
I'm not new to VTK but I'm new to dealing with mouse events.<br>
I try to write a simple code loading a BMP and determining on a mouse
left click, the coordinate of the pixel picked.<br>
<br>
Whether I use vtkPointPicker or vtkWorldPointPicker I'm not able to
interact with the image and extract some coordiante with the following
code.<br>
<br>
Can someone point me out to where is my mistake (I did check the
vtkusers archives but did not find any answers).<br>
regards,<br>
<br>
Florent Chandelier<br>
<br>
Pasted below is my code:<br>
<br>
#include "vtkRenderer.h"<br>
#include "vtkRenderWindow.h"<br>
#include "vtkRenderWindowInteractor.h"<br>
#include "vtkBMPReader.h"<br>
#include "vtkPolyDataMapper.h"<br>
#include "vtkActor.h"<br>
#include "vtkActor2D.h"<br>
#include "vtkImageMapper.h"<br>
<br>
<br>
#include "vtkObject.h"<br>
#include "vtkWorldPointPicker.h"<br>
#include "vtkCoordinate.h"<br>
#include "vtkPointPicker.h"<br>
#include "vtkPropPicker.h"<br>
#include "vtkProp.h"<br>
<br>
int main( int argc, char *argv[] )<br>
{<br>
<br>
&nbsp; // Image Size<br>
&nbsp; int size_x = 374;<br>
&nbsp; int size_y = 328;<br>
<br>
&nbsp; // load and show image<br>
&nbsp; vtkBMPReader *m_singleImage = vtkBMPReader::New();<br>
&nbsp; m_singleImage-&gt;SetFileName("Img_Test.bmp");<br>
&nbsp; m_singleImage-&gt;SetDataExtent(0,size_x, 0, size_y, 0, 0);<br>
&nbsp; m_singleImage-&gt;SetDataSpacing(1, 1, 0);<br>
&nbsp; m_singleImage-&gt;Update();<br>
<br>
&nbsp; // map it!<br>
&nbsp; vtkImageMapper *mapIm = vtkImageMapper::New();<br>
&nbsp; mapIm-&gt;SetInput(m_singleImage-&gt;GetOutput());<br>
&nbsp; mapIm-&gt;SetColorLevel(128);<br>
&nbsp; mapIm-&gt;SetColorWindow(256);<br>
<br>
&nbsp; // hook it up to an actor<br>
&nbsp; vtkActor2D *actorIm = vtkActor2D::New();<br>
&nbsp; actorIm-&gt;SetMapper(mapIm);<br>
<br>
&nbsp; // render the actor<br>
&nbsp; vtkRenderer *renderer = vtkRenderer::New();<br>
&nbsp; renderer-&gt;SetViewport(0, 0, 1, 1);<br>
&nbsp; renderer-&gt;AddActor(actorIm);<br>
&nbsp; renderer-&gt;SetBackground(1.0, 1.0, 1.0);<br>
<br>
&nbsp; vtkRenderWindow *renWin = vtkRenderWindow::New();<br>
&nbsp;&nbsp;&nbsp; renWin-&gt;AddRenderer(renderer);<br>
&nbsp;&nbsp;&nbsp; renWin-&gt;SetSize(size_x,size_y);<br>
<br>
&nbsp;&nbsp;&nbsp; vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br>
&nbsp;&nbsp;&nbsp; iren-&gt;SetRenderWindow(renWin);&nbsp;&nbsp;&nbsp; <br>
<br>
&nbsp;&nbsp;&nbsp; renWin-&gt;Render();<br>
&nbsp; iren-&gt;Start();<br>
<br>
&nbsp;&nbsp;&nbsp; int x, y;<br>
<br>
&nbsp;&nbsp;&nbsp; vtkPointPicker *picker = vtkPointPicker::New();<br>
&nbsp;&nbsp;&nbsp; int X,Y;<br>
&nbsp;&nbsp;&nbsp; int result = picker-&gt;Pick((float)X,(float)Y,0.0,renderer);<br>
&nbsp;&nbsp;&nbsp; float *pos; float Point[3];&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; if (result != -1)<br>
&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /*pos = picker-&gt;GetPickPosition();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i=0;i&lt;3;i++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Point[i] = pos[i];&nbsp;&nbsp;&nbsp;&nbsp; */<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; printf("pick, pick\n");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; /*vtkWorldPointPicker * picker = vtkWorldPointPicker::New();<br>
&nbsp;&nbsp;&nbsp; int picked = picker-&gt;Pick(x, y, 0, renderer);<br>
&nbsp;&nbsp;&nbsp; if (picked != -1)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; picker-&gt;GetPickPosition()[0] &lt;&lt; ":
" &lt;&lt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; picker-&gt;GetPickPosition()[1] &lt;&lt; std::endl;&nbsp; &nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vtkCoordinate* c = vtkCoordinate::New();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c-&gt;SetViewport(renderer);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c-&gt;SetCoordinateSystemToWorld();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c-&gt;SetValue(picker-&gt;GetPickPosition()[0],<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; picker-&gt;GetPickPosition()[1]);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; int *p = c-&gt;GetComputedDisplayValue(renderer);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; p[0] &lt;&lt; ": " &lt;&lt; p[1] &lt;&lt;
std::endl;<br>
<br>
&nbsp;&nbsp;&nbsp; }*/<br>
<br>
&nbsp;return 0;<br>
<br>
}<br>
<br>
<br>
<br>
<br>
<div class="moz-signature">-- <br>
<meta http-equiv="Content-Type" content="text/html; ">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.41">
<style type="text/css">
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
    p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Helvetica}
    p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
    p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
    p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 10.0px Helvetica}
    p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; text-align: justify; font: 12.0px Helvetica; min-height: 14.0px}
    span.s1 {font: 12.0px Helvetica}
    span.Apple-tab-span {white-space:pre}
  </style>
<p class="p1"><b><i>Florent Chandelier</i></b><span class="s1">, PhD
candidate</span></p>
<p class="p2"><span class="s1">Master's in Medical Imaging</span>
(Medicine Faculty, Paris, France),<span class="Apple-converted-space">&nbsp;</span></p>
<p class="p2"><span class="s1">French Engineer</span> in Signal
treatment and theory (ESME SUDRIA, Paris, France)</p>
<p class="p3"><br>
</p>
<p class="p4">Local C1-4123 <span class="Apple-converted-space">&nbsp;</span></p>
<p class="p3"><br>
</p>
<p class="p4">D&eacute;partement de g&eacute;nie m&eacute;canique</p>
<p class="p4">Universit&eacute; de Sherbrooke</p>
<p class="p4">2500, boul. Universit&eacute;</p>
<p class="p4">Sherbrooke, QC, J1K 2R1</p>
<p class="p4">CANADA</p>
<p class="p3"><br>
</p>
<p class="p4">Tel<span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; </span>: +1
(819) 821-8000 ext: 63160</p>
<p class="p4">Fax<span class="Apple-converted-space">&nbsp; &nbsp; &nbsp; </span>: +1
(819) 821-7163</p>
<p class="p4">E-mail <span class="Apple-converted-space">&nbsp; </span>: <b><i><a class="moz-txt-link-abbreviated" href="mailto:Florent.Chandelier at USherbrooke.ca">Florent.Chandelier at USherbrooke.ca</a></i></b></p>
<p class="p3"><br>
</p>
<table>
  <tbody>
    <tr>
      <td>
      <p class="p5"><span class="s1"><b>Avis :</b></span> Ce message
est confidentiel et est &agrave; l'usage exclusif de son destinataire.<span
 class="Apple-converted-space">&nbsp; </span>Il est strictement interdit &agrave;
toute autre personne de le diffuser, le distribuer ou le reproduire.<span
 class="Apple-converted-space">&nbsp; </span>Si le destinataire ne peut
&ecirc;tre joint ou vous est inconnu, veuillez informer l'exp&eacute;diteur par
courrier &eacute;lectronique imm&eacute;diatement et effacer ce message et en
d&eacute;truire toute copie. Les communications par Internet sont expos&eacute;es au
risque d'alt&eacute;ration des donn&eacute;es, &agrave; d'autres erreurs de transmission et
&agrave; la perte de confidentialit&eacute;. Si vous d&eacute;sirez que nous communiquions
avec vous par un autre moyen, veuillez nous en aviser.</p>
      </td>
      <td>
      <p class="p5"><span class="s1"><b>Notice:</b> </span>This
message is confidential and is intended for the exclusive use of the
addressee.<span class="Apple-converted-space">&nbsp; </span>Any other
person is strictly prohibited from disclosing, distributing or
reproducing it.<span class="Apple-converted-space">&nbsp; </span>If the
addressee cannot be reached or is unknown to you, please inform the
sender by return e-mail immediately and delete this message and destroy
all copies. Internet communications are subject to the risk of data
corruption, other transmission errors and loss of confidentiality.
Please advise if you wish us to use a different method when
communicating with you.</p>
      </td>
    </tr>
  </tbody>
</table>
</div>
</body>
</html>
-------------- next part --------------
begin:vcard
fn:Florent Chandelier
n:Chandelier;Florent
org;quoted-printable:Universit=C3=A9 de Sherbrooke;Bio-Engineering
adr;quoted-printable:;;1580 rue Prunier;Sherbrooke;Qu=C3=A9bec;J1K2K3;Canada
email;internet:Florent.Chandelier at free.fr
title:PhD Student - Master's in Engineering - Master's in Medical Imaging
tel;work:001 819 821 8000 ext:63160
tel;home:001 819 348 2209
url:http://flochandelier.ovh.org/
version:2.1
end:vcard



More information about the vtkusers mailing list