<div dir="ltr"><div><div>HI Georges,<br><br></div>you should see if the left mouse button actually clicked on your image actor,<br></div><div>something like this:<br><br></div><div>  picker->PickFromListOn();<br></div><div>  picker->AddPickList(imageActor);<br></div><div>  picker->Pick( X, Y, 0.0, this->CurrentRenderer );<br>  vtkAssemblyPath* path = this->Picker->GetPath();<br><br>  vtkProp* pickedProp = 0;<br>  if( path  )<br>  {<br>    // Deal with the possibility that we may be using a shared picker<br>    vtkCollectionSimpleIterator sit;<br>    path->InitTraversal( sit );<br>    vtkAssemblyNode *node;<br>    for( int i = 0; i < path->GetNumberOfItems(); ++i )<br>    {   <br>      node = path->GetNextNode( sit );<br>      pickedProp = node->GetViewProp();<br>      if( imageActor == pickedProp ) <br>      {   <br>        break;<br>      }   <br>    }<br>  }<br><br>  if( !pickedProp ) return;<br>  double q[3];<br></div><div>  picker->GetPickPosition(q);<br>  <br></div><div>  What I do with picking on a vtkImageActor is to clamp the picked position<br></div><div>  to the bounds of the actor, then convert the clamped position<br></div><div>  from world coordinates back into image data voxel/pixel coordinate using<br></div><div> the origin, spacing and extent of the vtkImageData that is being<br></div><div> displayed by the actor.  You probably will need to NOT set the actor<br>  position: ImageActor->SetPosition(0,0,0);<br><br></div><div></div><div>  - Dean<br></div><div><br>  <br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 22, 2016 at 2:58 PM, Georges <span dir="ltr"><<a href="mailto:Siqueiros.jorge@outlook.com" target="_blank">Siqueiros.jorge@outlook.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everybody, I'm new in vtk, this is my first vtk project. I'm working over<br>
C++ in VisualStudio with vtk 5.10.1 version. I'm making a SDI-MFC aplication<br>
and I'm trying to obtain the coordinates (image coordinates) of the left<br>
mouse click event when this click is over an image. I've reviewed the<br>
examples pickpixel, pickpixel2 and picking, but pickpixel2 gave me the<br>
coordiantes in int type variable and I need the coordinates in double type<br>
variable. I've implemented the picking example (link:<br>
<a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/Picking" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/Picking</a>) but when I run<br>
the app over my program I get an Assertion and I can´t find the error. I now<br>
attach my programm. I appreciate your help in explaining  how could I make<br>
the picking detection event or find the program mistake.<br>
<br>
*//<br>
*************************************************************************<br>
// FUNCTION TO LOAD AN IMAGE IN FORMATS *,jpg. *.bmp, *.tiff, *.png<br>
//<br>
**************************************************************************<br>
void COSSysView::OssysLoadImagevtk(CString m_ImagePath)<br>
{<br>
  //Create an image reader<br>
  vtkImageFileReader *ImageReader = vtkImageFileReader::New();<br>
  ImageReader->SetFileName(m_ImagePath);<br>
  ImageReader->Update();<br>
<br>
  // ###Create an image mapper<br>
  vtkImageMapper3D *imageMapper;<br>
  vtkImageSliceMapper *imageSMapper = vtkImageSliceMapper::New();<br>
  imageMapper = imageSMapper;<br>
  imageMapper->SetInputConnection(ImageReader->GetOutputPort());<br>
<br>
  // Create an actor<br>
  vtkImageActor *ImageActor = vtkImageActor::New();<br>
  ImageActor->SetInput(ImageReader->GetOutput());<br>
  ImageActor->SetPosition(0,0,0);<br>
  ImageActor->SetMapper(imageMapper);<br>
<br>
  GetRenderer()->RemoveAllViewProps(); // Remove all the actors<br>
<br>
  // Setup renderer<br>
  GetRenderer()->AddActor(ImageActor);<br>
  GetRenderer()->ResetCamera();<br>
<br>
  // Setup render window<br>
  GetRenderer()->GetRenderWindow()->Render();<br>
<br>
  // Setup render window interactor<br>
  vtkRenderWindowInteractor *renderWindowInteractor =<br>
vtkRenderWindowInteractor::New();<br>
  MouseInteractorStyle2        *style                      = MouseInteractorStyle2::New();<br>
<br>
  renderWindowInteractor->SetInteractorStyle(style);<br>
<br>
  // Render and start interaction<br>
  renderWindowInteractor->SetRenderWindow(GetRenderer()->GetRenderWindow());<br>
  renderWindowInteractor->Initialize();<br>
  renderWindowInteractor->Start();<br>
<br>
}<br>
*//<br>
**************************************************************************<br>
<br>
*//<br>
*************************************************************************<br>
// CLASS TO HANDLE MOUSE EVENT<br>
//<br>
**************************************************************************<br>
<br>
class MouseInteractorStyle2 : public vtkInteractorStyleTrackballCamera<br>
{<br>
  public:<br>
    static MouseInteractorStyle2* New();<br>
    vtkTypeMacro(MouseInteractorStyle2, vtkInteractorStyleTrackballCamera);<br>
<br>
    virtual void OnLeftButtonDown()<br>
    {<br>
      int* clickPos = this->GetInteractor()->GetEventPosition();<br>
<br>
      // Pick from this location.<br>
      vtkSmartPointer<vtkPropPicker>  picker =<br>
vtkSmartPointer<vtkPropPicker>::New();<br>
      picker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());<br>
// IN THIS PART THE ASSERTION APPEARS<br>
<br>
      double* pos = picker->GetPickPosition();<br>
      std::cout << "Pick position (world coordinates) is: "<br>
                << pos[0] << " " << pos[1]<br>
                << " " << pos[2] << std::endl;<br>
<br>
      std::cout << "Picked actor: " << picker->GetActor() << std::endl;<br>
<br>
//Create a sphere<br>
      vtkSmartPointer<vtkSphereSource> sphereSource =<br>
vtkSmartPointer<vtkSphereSource>::New();<br>
      sphereSource->SetCenter(pos[0], pos[1], pos[2]);<br>
      sphereSource->SetRadius(0.1);<br>
<br>
      //Create a mapper and actor<br>
      vtkSmartPointer<vtkPolyDataMapper> mapper =<br>
vtkSmartPointer<vtkPolyDataMapper>::New();<br>
      mapper->SetInputConnection(sphereSource->GetOutputPort());<br>
<br>
      vtkSmartPointer<vtkActor> actorsphere =<br>
vtkSmartPointer<vtkActor>::New();<br>
      actorsphere->SetMapper(mapper);<br>
      this->GetDefaultRenderer()->AddActor(actorsphere);<br>
      // Forward events<br>
      vtkInteractorStyleTrackballCamera::OnLeftButtonDown();<br>
    }<br>
<br>
};<br>
<br>
vtkStandardNewMacro(MouseInteractorStyle2);<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/How-to-obtain-the-coordinates-double-and-not-int-type-mouse-picking-over-an-image-tp5737850.html" rel="noreferrer" target="_blank">http://vtk.1045678.n5.nabble.com/How-to-obtain-the-coordinates-double-and-not-int-type-mouse-picking-over-an-image-tp5737850.html</a><br>
Sent from the VTK - Users mailing list archive at Nabble.com.<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br></div>