I hacked one of the vtk examples to demonstrate the bug. Attached and copied below. With the bug, it will only print "Pick success" when the x coordinate of the mouse press is 150.<br><br># CMakeLists.txt<br>cmake_minimum_required(VERSION 2.6)<br>
project(test)<br>find_package(VTK REQUIRED)<br>include(${VTK_USE_FILE})<br>add_executable(test test.cxx)<br>target_link_libraries(test vtkRendering)<br><br>// test.cxx<br>/*=========================================================================<br>
<br> Program: Visualization Toolkit<br> Module: $RCSfile: line5.cxx,v $<br><br> Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen<br> All rights reserved.<br> See Copyright.txt or <a href="http://www.kitware.com/Copyright.htm">http://www.kitware.com/Copyright.htm</a> for details.<br>
<br> This software is distributed WITHOUT ANY WARRANTY; without even<br> the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR<br> PURPOSE. See the above copyright notice for more information.<br>
<br>=========================================================================*/<br>//<br>// This example introduces the concepts of interaction into the<br>// C++ environment. A different interaction style (than<br>// the default) is defined. <br>
// <br><br>// First include the required header files for the VTK classes we are using.<br>#include "vtkPolyDataMapper.h"<br>#include "vtkRenderWindow.h"<br>#include "vtkRenderWindowInteractor.h"<br>
#include "vtkCamera.h"<br>#include "vtkActor.h"<br>#include "vtkRenderer.h"<br>#include "vtkInteractorStyleTrackballCamera.h"<br><br>#include "vtkCallbackCommand.h"<br>#include "vtkLineSource.h"<br>
#include "vtkProperty.h"<br>#include "vtkPropPicker.h"<br>#include "vtkSmartPointer.h"<br><br>//-----------------------------------------------------------------------------<br>class PickHelper {<br>
public:<br> PickHelper();<br> vtkSmartPointer<vtkCallbackCommand> Command;<br> vtkSmartPointer<vtkPropPicker> Picker;<br> vtkActor* Actor;<br> vtkRenderer* Renderer;<br> vtkRenderWindowInteractor* Interactor;<br>
};<br><br>//-----------------------------------------------------------------------------<br>void ProcessEvents(vtkObject* object, unsigned long event,<br> void* clientData, void* callData)<br>{<br> PickHelper* h = reinterpret_cast<PickHelper*>(clientData);<br>
if (event == vtkCommand::LeftButtonPressEvent)<br> {<br> int x = 150;<br> int y = 150;<br> h->Interactor->GetEventPosition(x, y);<br> printf("Mouse press: %d %d\n", x, y);<br> if (h->Picker->PickProp(x, y, h->Renderer)<br>
&& h->Picker->GetViewProp() == h->Actor)<br> {<br> printf("Pick success.\n");<br> }<br> }<br>}<br><br>//-----------------------------------------------------------------------------<br>
PickHelper::PickHelper()<br>{<br> this->Picker = vtkSmartPointer<vtkPropPicker>::New();<br> this->Command = vtkSmartPointer<vtkCallbackCommand>::New();<br> this->Command->SetCallback(ProcessEvents);<br>
this->Command->SetClientData(this);<br> this->Picker->AddObserver(vtkCommand::EndPickEvent, Command);<br>}<br><br><br>int main()<br>{<br> // <br> // Next we create an instance of vtkLineSource and set some of its<br>
// properties. The instance of vtkLineSource "line" is part of a<br> // visualization pipeline (it is a source process object); it produces data<br> // (output type is vtkPolyData) which other filters may process.<br>
//<br> vtkLineSource *line = vtkLineSource::New();<br> line->SetPoint1( 0, 0, 0);<br> line->SetPoint2( 0, 1, 0);<br> <br> // <br> // In this example we terminate the pipeline with a mapper process object.<br>
// (Intermediate filters such as vtkShrinkPolyData could be inserted in<br> // between the source and the mapper.) We create an instance of<br> // vtkPolyDataMapper to map the polygonal data into graphics primitives. We<br>
// connect the output of the line souece to the input of this mapper.<br> //<br> vtkPolyDataMapper *lineMapper = vtkPolyDataMapper::New();<br> lineMapper->SetInputConnection( line->GetOutputPort() );<br><br> // <br>
// Create an actor to represent the line. The actor orchestrates rendering<br> // of the mapper's graphics primitives. An actor also refers to properties<br> // via a vtkProperty instance, and includes an internal transformation<br>
// matrix. We set this actor's mapper to be lineMapper which we created<br> // above.<br> //<br> vtkActor *lineActor = vtkActor::New();<br> lineActor->SetMapper( lineMapper );<br> lineActor->GetProperty()->SetLineWidth(10);<br>
<br> //<br> // Create the Renderer and assign actors to it. A renderer is like a<br> // viewport. It is part or all of a window on the screen and it is<br> // responsible for drawing the actors it has. We also set the background<br>
// color here.<br> //<br> vtkRenderer *ren1= vtkRenderer::New();<br> ren1->AddActor( lineActor );<br> ren1->SetBackground( 0.5, 0.5, 0.5 );<br><br> //<br> // Finally we create the render window which will show up on the screen.<br>
// We put our renderer into the render window using AddRenderer. We also<br> // set the size to be 300 pixels by 300.<br> //<br> vtkRenderWindow *renWin = vtkRenderWindow::New();<br> renWin->AddRenderer( ren1 );<br>
renWin->SetSize( 300, 300 );<br><br> // <br> // The vtkRenderWindowInteractor class watches for events (e.g., keypress,<br> // mouse) in the vtkRenderWindow. These events are translated into<br> // event invocations that VTK understands (see VTK/Common/vtkCommand.h<br>
// for all events that VTK processes). Then observers of these VTK<br> // events can process them as appropriate.<br> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();<br> iren->SetRenderWindow(renWin);<br>
<br> //<br> // By default the vtkRenderWindowInteractor instantiates an instance<br> // of vtkInteractorStyle. vtkInteractorStyle translates a set of events<br> // it observes into operations on the camera, actors, and/or properties<br>
// in the vtkRenderWindow associated with the vtkRenderWinodwInteractor. <br> // Here we specify a particular interactor style.<br> vtkInteractorStyleTrackballCamera *style = <br> vtkInteractorStyleTrackballCamera::New();<br>
iren->SetInteractorStyle(style);<br><br> // Initialize the picker<br> PickHelper helper;<br> helper.Actor = lineActor;<br> helper.Renderer = ren1;<br> helper.Interactor = iren;<br> iren->AddObserver(vtkCommand::LeftButtonPressEvent, helper.Command);<br>
<br> //<br> // Unlike the previous scripts where we performed some operations and then<br> // exited, here we leave an event loop running. The user can use the mouse<br> // and keyboard to perform the operations on the scene according to the<br>
// current interaction style. When the user presses the "e" key, by default<br> // an ExitEvent is invoked by the vtkRenderWindowInteractor which is caught<br> // and drops out of the event loop (triggered by the Start() method that<br>
// follows.<br> //<br> iren->Initialize();<br> iren->Start();<br> <br> // <br> // Final note: recall that an observers can watch for particular events and<br> // take appropriate action. Pressing "u" in the render window causes the<br>
// vtkRenderWindowInteractor to invoke a UserEvent. This can be caught to<br> // popup a GUI, etc. So the Tcl line5.tcl example for an idea of how this<br> // works.<br><br> //<br> // Free up any objects we created. All instances in VTK are deleted by<br>
// using the Delete() method.<br> //<br> line->Delete();<br> lineMapper->Delete();<br> lineActor->Delete();<br> ren1->Delete();<br> renWin->Delete();<br> iren->Delete();<br> style->Delete();<br>
<br> return 0;<br>}<br><br><br><div class="gmail_quote">On Fri, Jan 22, 2010 at 1:18 PM, pat marion <span dir="ltr"><<a href="mailto:pat.marion@kitware.com">pat.marion@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Using vtkPropPicker::PickProp it is difficult to pick lines (using a vtkLineSource with a vtkPolyDataMapper for example). Even if I set the line width to 10 pixels, the pick is only successful if I click exactly in the center of the 10 pixel band, as if the hardware picker was not respecting the 10 pixel width. Can someone that is familiar with this part of vtk verify the bug, or point me in the right direction?<br>
<font color="#888888">
<br>Pat<br>
</font></blockquote></div><br>