[vtkusers] creating custom events for interactorStyle classes
Fatih Ergüner
f.erguner at gmail.com
Mon May 20 13:03:50 EDT 2013
Firstly thank you very much for reply.
To be more concrete: im in front of a camera and im getting the both hand
coordinates ready to use in interactorStyle class via a device mediator
class.
There is a DeviceVolumeInteractor class which is derived from
vtkInteractorStyleJoystickCamera. This class has the hand coordinates(x,y
values are same as in GetEventPosition() ) as stated above. The problem is
that even i know the hand coordinates i cannot inject the hand.x,hand.y
values into GetEventPosition().
I created custom events in another thread to overcome, but in this case i
got "failed in MakeCurrent(), error: The requested *resource is in use*." i
give call the callback from another thread but i couldnt figure out where
should i trigger it every time.
here is the code summary:
//-------------------------------
//------DeviceVolumeInteractor is derived from
vtkInteractorStyleJoystickCamera
//-------------------------------
//ctor
DeviceVolumeInteractor::DeviceVolumeInteractor()
{
// Use timers to handle continous interaction
this->UseTimers = 1;
// user defined event number starts from vtkCommand::UserEvent
this->DeviceControlEvent = vtkCommand::UserEvent + 1;
this->UCDeviceCallbackCommand = vtkCallbackCommand::New();
this->UCDeviceCallbackCommand->SetClientData(this);
*this->UCDeviceCallbackCommand->SetCallback(ProcessEvents);*
//this->SetEnabled(1);
*//adding User Control Device Callback as an observer to user-defined
Interactor*
* this->AddObserver(DeviceControlEvent,UCDeviceCallbackCommand);*
DeviceCS = DeviceControlState::CS_NONE;
initialize();
}
/// Thread to handle Device controls
DWORD WINAPI DeviceVolumeInteractor::DeviceEventLoop( )
{
while(true)
{
//if hand is active
if(mKm->m_ActiveHand != DeviceMediator::ActiveHand::AH_NOT_ACTIVE)
{
//InvokeEvent(DeviceControlEvent,NULL);
setDeviceControlState(DeviceControlState::CS_ZOOM);
}
else
{
setDeviceControlState(DeviceControlState::CS_NONE);
}
}
return 0;
}
*// The Callback method*
void DeviceVolumeInteractor::ProcessEvents(vtkObject*
vtkNotUsed(object),
unsigned long event,
void* clientdata,
void* calldata )
{
DeviceVolumeInteractor* self
= reinterpret_cast<DeviceVolumeInteractor *>( clientdata );
*//CAN BE WRONG*
*self->OnHandActive();*
}
//----------------------------------------------------------------------------
void DeviceVolumeInteractor::OnHandActive()
{
if ( mKm->m_ActiveHand == DeviceMediator::ActiveHand::AH_LEFT ||
mKm->m_ActiveHand == DeviceMediator::ActiveHand::AH_BOTH)
{
this->SetCurrentRenderer(this->Interactor->FindPokedRenderer(mKm->mpHandLeft.x,
mKm->mpHandLeft.y));
}
else if ( mKm->m_ActiveHand == DeviceMediator::ActiveHand::AH_RIGHT )
{
this->SetCurrentRenderer(this->Interactor->FindPokedRenderer(mKm->mpHandRight.x,
mKm->mpHandRight.y));
}
*//CAN BE WRONG*
*this->GrabFocus(this->UCDeviceCallbackCommand);*
* //setDeviceControlState(DeviceControlState::CS_ZOOM);*
Dolly();
if ( this->Interactor )
{
this->ReleaseFocus();
}
}
//----------------------------------------------------------------------------
void DeviceVolumeInteractor::Dolly()
{
if (this->CurrentRenderer == NULL)
{
return;
}
vtkRenderWindowInteractor *rwi = this->Interactor;
double *center = this->CurrentRenderer->GetCenter();
//double dy = rwi->GetEventPosition()[1] - center[1];
*double dy = (mKm->mpHandLeft.depth - mKm->mpHandRight.depth);// -
center[1];*
double dyf = 0.5 * dy;// / center[1];
this->Dolly(pow(1.1, dyf));
}
On Mon, May 20, 2013 at 4:44 PM, David Doria <daviddoria at gmail.com> wrote:
> On Fri, May 17, 2013 at 5:33 PM, Fatih Ergüner <f.erguner at gmail.com>
> wrote:
> > Hello all,
> >
> > i want to create custom event for manipuating the rendered 3d volumes.
> For
> > example when i say "hello" then this event is invoked and i move the
> objects
> > etc. I created a custom interactorstyle which is a subclass of
> > vtkInteractorStyle.
> >
> > http://www.vtk.org/Wiki/VTK/Examples/Cxx/Interaction/UserEvent
> > in above example, a test class which is inherited from
> vtkPolyDataAlgorithm
> > has a user defined RefreshEvent which is invoked in RequestData.
> >
> > But vtkInteractorStyle class has no RequestData method. is there a way of
> > overriding the ProgressEvent Method. Or how can i accomplish this task?
> >
> > thanks in advance...
> >
> > --
> > Best Regards;
> > Fatih Ergüner
>
>
> Perhaps you can be a bit more concrete. What do you mean by "say hello"?
>
> You should be able to invoke an event from anywhere as long as the
> class is derived from vtkObject. It would probably be easier if you
> could show us a minimal, compilable example of what you've tried so
> far, and explain exactly where it is not working for you.
>
> David
>
--
Saygılarımla;
Fatih Ergüner
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130520/f00a5faa/attachment.htm>
More information about the vtkusers
mailing list