[vtkusers] Interaction using vtkRenderWindowInteractor

stoptv stoptv at gmail.com
Tue Apr 18 04:30:33 EDT 2006


On 4/18/06, Ashley Sher <tany0029 at ntu.edu.sg> wrote:
>
> I'm implementing exactly what you're trying to do.
>
> I was thinking maybe it's more suitable to use vtkPropPicker as the
> default
> picker?
>
> Something like that,
>
> vtkPropPicker *pPropPicker = vtkPropPicker::New();
> vtkCallbackCommand *PickCallBackCommand = vtkCallbackCommand::New();
> PickCallBackCommand->SetCallback(MyVtkView::PickCallBack);
> pPropPicker->AddObserver(vtkCommand::EndPickEvent, PickCallBackCommand);
> MyVtkInteractor->SetPicker(pPropPicker);
>
> I have not finish implementing it so not too sure if it works well too.
> Keep me update once you've tried it?
>
> Thx!


Ashley, Marc - nice talking to you!

OK.. unfortunately I did not see Marc's message yesterday so I hacked up
smthng that works..
I wasn't aware you could tell the callback about the renderer, so I used a
class as a namespace
to hold a few important pointers for me. I did realize I need a picker, and
vtkPropPicker was my first
pick :-) unfortunately no luck.. I will be trying Marc's approach as it's
clean and simple.

Ashley, this is what I have for now and it's working:

renderer is a vtkRenderer;
renderWindow has a renderer;
interactor has a renderWindow;
....

vtkInteractorStyle* style = vtkInteractorStyle::New();

// i had no luck with other styles, except this one and
vtkInteractorStyleUser

LeftClickCallback* callback = LeftClickCallback::New(); // per Marc's
instructions

style->AddObserver( vtkCommand::LeftButtonPressEvent, callback );

global.interactor->SetInteractorStyle( style );

callback->Delete();
style->Delete();

//  ... then later  inside LeftClickCallback::Execute

void LeftClickCallback::Execute( vtkObject* caller, unsigned long eventId,
void* callData )
   {
      vtkInteractorStyle* style = vtkInteractorStyle::SafeDownCast(caller);

      if( style ) // is this necessary?
      {
        vtkPicker* p = vtkPicker::New(); // didn't work with vtkPropPicker

        // i've got only one renderer, renderWindow, interactor pipeline so
i don't have to ask style where the event occured
        // i know it ocured in my global.interactor.

        p->Pick( (global.interactor->GetEventPosition())[0], (
global.interactor->GetEventPosition())[1], 0, global.renderer );
        vtkActor* a = p->GetActors()->GetLastActor();

        // here i do something to my actor.. adjust it's color, blah blah..
        // my next problem is adjusting size.. hm... i don't see any size
properties..

        p->Delete();
        g.renderWindow->Render(); // update screen
      }
   }
...

Ashley, Marc, Kjeld - thank you all for your time and generous help.
Hopefully I'll be able to reciprocate someday.

Cheers!!
--
stoptv at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060418/16800546/attachment.htm>


More information about the vtkusers mailing list