<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi Maarten,<br>
I would suggest creating a callback and registering it with the
interactor's *ButtonPressEvent. The callback would manage its own
picker. Something like:<br>
<br>
<tt>//================================================<br>
class PickCallback : public vtkCommand</tt><tt><br>
</tt><tt>{</tt><tt><br>
</tt><tt>public :</tt><tt><br>
</tt><tt> static PickCallback * New() { return new PickCallback; }</tt><tt><br>
</tt><tt> void SetRenderer(vtkRenderer * r) { this->ren = r; }</tt><tt><br>
</tt><tt> void Execute(vtkObject *caller, unsigned long event, void
*)</tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> if (this->ren == NULL)</tt><tt><br>
</tt><tt> return;</tt><tt><br>
</tt><tt><br>
</tt><tt> if (event == vtkCommand::LeftButtonPressEvent)</tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> vtkRenderWindowInteractor * rwi =
vtkRenderWindowInteractor::SafeDownCast(caller);</tt><tt><br>
</tt><tt> if (rwi)</tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> this->picker->Pick(x, y, this->ren);</tt><tt><br>
</tt><tt> vtkAssemblyPath * path =
this->picker->GetPath();</tt><tt><br>
</tt><tt> if (path)</tt><tt><br>
</tt><tt> {</tt><tt><br>
</tt><tt> // Something was picked for sure.</tt><tt><br>
</tt><tt> vtkProp * pickedProp =
path->GetLastNode()->GetViewProp();</tt><tt><br>
</tt><tt><br>
</tt><tt> // do something with the prop</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt><br>
</tt><tt>private :</tt><tt><br>
</tt><tt> PickCallback() { </tt><tt><br>
</tt><tt> this->picker =
vtkSmartPointer<vtkCellPicker>::New(); </tt><tt><br>
</tt><tt> this->ren = NULL;</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> vtkRenderer * ren;</tt><tt><br>
</tt><tt> vtkSmartPointer<vtkCellPicker> picker;</tt><tt><br>
</tt><tt>};</tt><tt><br>
<br>
</tt><tt>//---------------------------------------------------------------------<br>
</tt><tt>// How to use the callback:</tt><tt><br>
</tt><tt>vtkSmartPointer<PickCallback> cbk =
vtkSmartPointer<PickCallback>::New();</tt><tt><br>
cbk->SetRenderer(ren);<br>
</tt><tt>interactor->AddObserver(vtkCommand::LeftButtonPressEvent,
cbk);</tt><tt><br>
</tt><tt>//================================================<br>
<br>
</tt>Hope this helps,<br>
Miro<br>
<br>
<br>
<br>
<div class="moz-cite-prefix">On 08/13/2014 09:29 AM, Maarten Beek
via vtkusers wrote:<br>
</div>
<blockquote
cite="mid:1407947381.61312.YahooMailNeo@web121306.mail.ne1.yahoo.com"
type="cite">
<div style="color:#000; background-color:#fff;
font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial,
Lucida Grande, sans-serif;font-size:12pt">
<div style="" class="">Hi all,</div>
<div style="" class=""><br style="" class="">
</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;">I noticed
that getting the currently picked actor from the picker in the
interactor doesn't always work.</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;">Some
interactor styles and widgets (e.g.
vtkInteractorstyleTrackballActor) have their own picker which
is used for the picking but which is different from the one in
the interactor.</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><br
style="" class="">
</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;">I wrote a
class that has awareness of the interactor.</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;">I would
like to use this->Interactor->GetPicker() to get access
to the currently picked object. However this doesn't work with
observers like vtkInteractorstyleTrackballActor. Using
this->Interactor->GetInteractorStyle()->GetPicker()
is also not an option because not all observers use their own
picker (and a GetPicker() function does not exist in
vtkInteractorstyleTrackballActor).</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><br
style="" class="">
</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;">The hack I
made was to derive from vtkInteractorstyleTrackballActor and
overload the SetInteractor() function:</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><br
style="" class="">
</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;">void
MyClass::SetInteractor(vtkRenderWindowInteractor* rwi)</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;">{</div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class="">
this->Superclass::SetInteractor(rwi);</span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""> if(
this->Interactor != NULL )</span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""> {</span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""> <span style=""
class=""> vtkCellPicker* picker =
vtkCellPicker::New;</span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""> <span style="" class="">
picker->SetTolerance(0.001);</span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""> <span style="" class="">
this->Interactor->SetPicker(picker);</span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""> <span style=""
class=""> picker->Delete();</span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""> }</span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class="">}</span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><br
style="" class="">
<span style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""></span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class="">This works. But I'd
like to use MyClass with different
observers w/o having to derive from
all of them...</span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><br
style="" class="">
<span style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""></span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class="">I've also looked at
the PickingManager class since all
observers seems to register their
pickers, but firstly it is not enabled
by default and secondly to get the
current selection I have to call
GetAssemblyPath() which performs a
pick which I don't want because this
invokes a PickEvent.. I use the event
in MyClass but only when I pick an
object, not when I want the currently
picked object. Giving
vtkPickingManager a public
SelectedPicker() function (like </span></span></span></span></span></span></span></span></span></span></span></span><br
style="" class="">
<span style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class="">vtkPickingManager::Internal
has) would do the trick here..</span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><br>
<span style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""></span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class="">I guess my question
is:</span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class="">How would a write
code to get the currently picked
object that works with various
observers when I only have awareness
of the interactor?</span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><br>
<span style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""></span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class="">Maarten<br>
</span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><br
style="" class="">
<span style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""></span></span></span></span></span></span></span></span></span></span></span></span></div>
<div class="" style="color: rgb(0, 0, 0); font-size: 16px;
font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif;
background-color: transparent; font-style: normal;"><span
style="" class=""><span style="" class=""><span style=""
class=""><span style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><span style="" class=""><span
style="" class=""><br style=""
class="">
</span></span></span></span></span></span></span></span></span></span></span></span></div>
</div>
</blockquote>
<br>
</body>
</html>