[vtkusers] Getting pointer to currently picked actor

Miro Drahos mdrahos at robodoc.com
Thu Aug 14 14:29:23 EDT 2014


I am not sure I understand -- what do you mean by picking transparent 
prop? Can you elaborate a bit more? Post some code to illustrate the issue?

If you are picking an opaque actor and then making it transparent after 
the pick, there should be no issues with that.
Picking something that is not being rendered -- I have never done that 
but I would think you'd have to use a ray casting picker (such as cell 
picker).

vtkPropPicker is faster than cell picker (hw accelerated), but doesn't 
give you tolerance and the prop you are picking must be visible. If you 
can live with that, definitely go with vtkPropPicker.

Miro



On 08/13/2014 01:45 PM, Maarten Beek wrote:
> Thanks for the suggestion, Miro.
>
> I actually implemented something similar.
> However, when I pick the actor I make it transparent.
>
> When I then want to get the picked actor, I have to use 
> vtkRenderer::PickProp because that apparently also picks transparent 
> props. However, it is really slow... Any suggestion here?
>
> Thanks - Maarten
>
>
> On Wednesday, August 13, 2014 4:10:03 PM, Miro Drahos 
> <mdrahos at robodoc.com> wrote:
>
>
> Hi Maarten,
> I would suggest creating a callback and registering it with the 
> interactor's *ButtonPressEvent. The callback would manage its own 
> picker. Something like:
>
> //================================================
> class PickCallback : public vtkCommand
> {
> public :
>   static PickCallback * New() { return new PickCallback; }
>   void SetRenderer(vtkRenderer * r) { this->ren = r; }
>   void Execute(vtkObject *caller, unsigned long event, void *)
>   {
>     if (this->ren == NULL)
>       return;
>
>     if (event == vtkCommand::LeftButtonPressEvent)
>       {
>         vtkRenderWindowInteractor * rwi = 
> vtkRenderWindowInteractor::SafeDownCast(caller);
>         if (rwi)
>           {
>             this->picker->Pick(x, y, this->ren);
>             vtkAssemblyPath * path = this->picker->GetPath();
>             if (path)
>               {
>                 // Something was picked for sure.
>                 vtkProp * pickedProp = path->GetLastNode()->GetViewProp();
>
>                 // do something with the prop
>               }
>           }
>       }
>   }
>
> private :
>   PickCallback() {
>     this->picker = vtkSmartPointer<vtkCellPicker>::New();
>     this->ren    = NULL;
>   }
>
>   vtkRenderer                   * ren;
>   vtkSmartPointer<vtkCellPicker> picker;
> };
>
> //---------------------------------------------------------------------
> // How to use the callback:
> vtkSmartPointer<PickCallback> cbk = vtkSmartPointer<PickCallback>::New();
> cbk->SetRenderer(ren);
> interactor->AddObserver(vtkCommand::LeftButtonPressEvent, cbk);
> //================================================
>
> Hope this helps,
> Miro
>
>
>
> On 08/13/2014 09:29 AM, Maarten Beek via vtkusers wrote:
>> Hi all,
>>
>> I noticed that getting the currently picked actor from the picker in 
>> the interactor doesn't always work.
>> 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.
>>
>> I wrote a class that has awareness of the interactor.
>> 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).
>>
>> The hack I made was to derive from vtkInteractorstyleTrackballActor 
>> and overload the SetInteractor()  function:
>>
>> void MyClass::SetInteractor(vtkRenderWindowInteractor* rwi)
>> {
>> this->Superclass::SetInteractor(rwi);
>>     if( this->Interactor != NULL )
>>     {
>> vtkCellPicker* picker = vtkCellPicker::New;
>> picker->SetTolerance(0.001);
>> this->Interactor->SetPicker(picker);
>> picker->Delete();
>>     }
>> }
>>
>> This works. But I'd like to use MyClass with different observers w/o 
>> having to derive from all of them...
>>
>> 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
>> vtkPickingManager::Internal has) would do the trick here..
>>
>> I guess my question is:
>> How would a write code to get the currently picked object that works 
>> with various observers when I only have awareness of the interactor?
>>
>> Maarten
>>
>>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140814/08cfee29/attachment.html>


More information about the vtkusers mailing list