[vtkusers] Coordinates of the point clicked with the mouse

Naim naim at electromagneticworks.com
Thu Nov 30 14:49:11 EST 2006


Hi Florent,

 

Juste call OnLeftClick ( or YourOnLeftClickFunctionName) function using
vtkCallbackCommand class (subject/observer design pattern) :

 

void Init()

{

      vtkCallbackCommand* cbc = vtkCallbackCommand::New();

      cbc->SetCallback(OnLeftClick);

      cbc->SetClientData((void*) renderer->GetActiveCamera());

      iren->AddObserver(vtkCommand::LeftButtonPressEvent, cbc); // left
button clicked

      cbc->Delete();

}

 

void OnLeftClick(vtkObject* caller, unsigned long eid, void* clientdata,
void* calldata)

{

      vtkPointPicker *pointpicker = vtkPointPicker::New();

      pointpicker->SetTolerance(0.001);

      iren->SetPicker(pointpicker);

 

//get the picker handle from the interactor

      vtkPointPicker  *pointpicker = (vtkPointPicker *)(iren->GetPicker());

            

      //get the mouse position

      int * pos = iren->GetEventPosition();

 

      //start the picking process

      if ( pointpicker->Pick((double)pos[0], (double)pos[1], 0.0,
m_prenderer) != 0)

      {

            //get the list of picked point

            vtkPoints* thePointList = pointpicker->GetPickedPositions();

 

            //get the number of picked points

            int nbrpoints = thePointList->GetNumberOfPoints();

                        

            if (nbrpoints<=0)

                  return;     

}

...

}

 

PS: YourOnLeftClickFunctionName function must be static.

 

Naim Himrane

Electromagneticworks Inc.

 

  _____  

From: Florent Chandelier [mailto:Florent.Chandelier at USherbrooke.ca] 
Sent: November 30, 2006 11:02 AM
To: Naim
Cc: cyros at tiscali.it; vtkusers at vtk.org
Subject: Re: [vtkusers] Coordinates of the point clicked with the mouse

 

Hi, 

When you say, "on left click", do you mean you have created an instance (a
class) performing a special task on a left click or do you simply paste the
code like that ?

regards,
Florent.

Naim wrote: 

I’m using this to get the coordinates (OnLeftClick):

 

 

vtkPointPicker  *pointpicker = (vtkPointPicker *)(iren->GetPicker());

            

//get the mouse position

int * pos = iren->GetEventPosition();

 

pointpicker->SetTolerance(0.001);

 

//start the picking process

if ( pointpicker->Pick((double)pos[0], (double)pos[1], 0.0, m_prenderer) !=
0)

{

      //get the list of picked point

      vtkPoints* thePointList = pointpicker->GetPickedPositions();

 

      //get the number of picked points

      int nbrpoints = thePointList->GetNumberOfPoints();

}

 

Naim Himrane

Electromagneticworks Inc.

 

  _____  

From: vtkusers-bounces+naim=electromagneticworks.com at vtk.org
[mailto:vtkusers-bounces+naim=electromagneticworks.com at vtk.org] On Behalf Of
cyros at tiscali.it
Sent: November 29, 2006 7:06 PM
To: vtkusers at vtk.org
Subject: [vtkusers] Coordinates of the point clicked with the mouse 

 

 

Which it is the alternative way to vtkRenderWindow.GetEventPosition () for
having the coordinates of the point clicked with the mouse on the
vtkRenderWindow?

 





  _____  



 
_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
  

 

-- 



Florent Chandelier, PhD candidate

Master's in Medical Imaging (Medicine Faculty, Paris, France), 

French Engineer in Signal treatment and theory (ESME SUDRIA, Paris, France)

 

Local C1-4123  

 

Département de génie mécanique

Université de Sherbrooke

2500, boul. Université

Sherbrooke, QC, J1K 2R1

CANADA

 

Tel      : +1 (819) 821-8000 ext: 63160

Fax      : +1 (819) 821-7163

E-mail   : Florent.Chandelier at USherbrooke.ca

 


Avis : Ce message est confidentiel et est à l'usage exclusif de son
destinataire.  Il est strictement interdit à toute autre personne de le
diffuser, le distribuer ou le reproduire.  Si le destinataire ne peut être
joint ou vous est inconnu, veuillez informer l'expéditeur par courrier
électronique immédiatement et effacer ce message et en détruire toute copie.
Les communications par Internet sont exposées au risque d'altération des
données, à d'autres erreurs de transmission et à la perte de
confidentialité. Si vous désirez que nous communiquions avec vous par un
autre moyen, veuillez nous en aviser.

Notice: This message is confidential and is intended for the exclusive use
of the addressee.  Any other person is strictly prohibited from disclosing,
distributing or reproducing it.  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.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061130/0eec44da/attachment.htm>


More information about the vtkusers mailing list