[vtkusers] Which interactor style to use..??

Allan James ar.james at qut.edu.au
Tue Mar 9 20:43:50 EST 2010


Hi Rakesh,


There are numerous ways to capture double-clicks... The (simple and incomplete) example below essentially counts the number of clicks that have occurred when mouse is not moving. When the has moved more pixels than resetPixelDistance, number of clicks is reset.

Attach the callback to your interactor style to capture these events: "LeftButtonPressEvent", "LeftButtonReleaseEvent" and "MouseMoveEvent" 

This should give you an idea for one way to approach this, another way would be to instead include a timer so that double-click needs to occur within a specified time interval.

--------------

void MyCallback::Execute(vtkObject *caller, unsigned long eventId, void* data)
{
	if(eventId == vtkCommand::LeftButtonPressEvent)
	{
		// propogate event
		if(sceneRenderWindowInteractorStyle)
			sceneRenderWindowInteractorStyle->OnLeftButtonDown();

	}
	else if(eventId == vtkCommand::LeftButtonReleaseEvent)
	{
		numClicks++;

		if(numClicks >= 2)
		{
			// this block is executed on double-click
			
			numClicks = 0;

			int pickPosition[2];
			sceneRenderWindowInteractor->GetEventPosition(pickPosition);
		}

		// propogate event
		if(sceneRenderWindowInteractorStyle)
			sceneRenderWindowInteractorStyle->OnLeftButtonUp();
	}
	else if(eventId == vtkCommand::MouseMoveEvent)
	{
		if(numClicks > 0)
		{
			int pickPosition[2];
			sceneRenderWindowInteractor->GetEventPosition(pickPosition);

			int xdist = pickPosition[0]-prevPosition[0];
			int ydist = pickPosition[1]-prevPosition[1];

			prevPosition[0] = pickPosition[0];
			prevPosition[1] = pickPosition[1];

			int moveDistance = (int)sqrt((double)(xdist*xdist + ydist*ydist));

			// Reset numClicks - If mouse moved further than resetPixelDistance
			if(moveDistance > resetPixelDistance)
				numClicks = 0;
		}

		// propogate event
		if(sceneRenderWindowInteractorStyle)
			sceneRenderWindowInteractorStyle->OnMouseMove();
	}
}

MyCallback::MyCallback()
{
	numClicks = 0;
	resetPixelDistance = 10;
	prevPosition[0] = prevPosition[1] = 0;
}

---------------
 
Allan James
High Performance Computing & Research Support
Queensland University of Technology
(07) 3138 9264
ar.james at qut.edu.au
http://www.qut.edu.au/its/hpc

><(((º>  ._.·´¯`·..  >++(((º>  ._.·´¯`·..  >++(((º>


> You can catch keys like this:
> http://vtk.org/Wiki/VTK/Examples/Interaction/KeypressEvents
>
> Double click is a good question - anyone have any ideas?
>
> Thanks,
>
> David
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <http://www.vtk.org/pipermail/vtkusers/attachments/20100309/c1
> 74cdfc/attachment-0001.htm>
>
> ------------------------------
>
> Message: 12
> Date: Tue, 9 Mar 2010 09:53:47 -0500
> From: David Doria <daviddoria+vtk at gmail.com>
> Subject: Re: [vtkusers] Which interactor style to use..??
> To: Rakesh Patil <rakeshthp at in.com>
> Cc: vtkusers <vtkusers at vtk.org>
> Message-ID:
>       <c19fcadc1003090653odcbd660xb233091f6f7d2b22 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> On Tue, Mar 9, 2010 at 7:52 AM, Rakesh Patil <rakeshthp at in.com> wrote:
>
> > Hello,
> >
> > I need to catch double click event,.. Is there any
> interactor style that
> > has this facility..?? Also, i need catch keypress events,
> like deleting
> > objects by pressing delete button..
> >
> > How do i do this..??
> >
> > Thanks in advance
> >
> > Regards
> > Rakesh Patil
> >
> >






More information about the vtkusers mailing list