[vtkusers] RE: Win32, Intercepting a interactor messages. (Custom interactor)

BURRELL Benjamin Benjamin.Burrell at Tenix.com
Fri Apr 2 03:49:20 EST 2004


Just an update.

I have got it to work using the OLD SetLeftButtonPressMethod(...) but BUT a vtk warning comes up saying that the SetLeftButtonPressMethod(...) is obsolete and will not be supported after vtk4.2. So how are you meant to do it now?????????

This is how I got it to work using SetLeftButtonPressMethod(...):

  this->mp_ren = vtkRenderer::New();
  this->mp_renWin = vtkWin32OpenGLRenderWindow::New();
  this->mp_iren = vtkWin32RenderWindowInteractor::New();

  vtkInteractorStyleTrackballCamera *mp_iafl = vtkInteractorStyleTrackballCamera::New();
  mp_iafl->SetLeftButtonPressMethod(myRotate, (void*)this->mp_iafl);


where the myRotate routine is:

void myRotate(void* arg)
{
	 vtkInteractorStyleTrackballCamera  *irst = ( vtkInteractorStyleTrackballCamera *)arg;;
	irst->StartPan();
}

and I have just the standard WindowProc function overwritten eg:

	LRESULT CVtkMDIView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
	{
		switch ( message )
		{
			//case WM_PAINT: 
			case WM_CLOSE: 
			case WM_LBUTTONDOWN:
			case WM_LBUTTONUP: 
			case WM_MBUTTONDOWN: 
			case WM_MBUTTONUP: 
			case WM_RBUTTONDOWN: 
			case WM_RBUTTONUP: 
			case WM_MOUSEMOVE:
			case WM_CHAR:
			case WM_TIMER:
				if ( this->mp_iren->GetInitialized() )
				{
					return vtkHandleMessage2(this->m_hWnd, message, wParam, lParam, this->mp_iren);
				}
				break;
		}
		return CView::WindowProc(message, wParam, lParam);
}


You run this and the vtk warning comes up saying that the SetLeftButtonPressMethod(...) is obsolete and will not be supported after vtk4.2.
######################################################################################################################################


I have also tried deriving my own class from vtkInteractorStyleTrackballCamera (derived from this class because I want exactly the same interaction except for adding a fake 2D mode feature).


#include "vtkInteractorStyleTrackballCamera.h"

class vtkCDNInteractor : public vtkInteractorStyleTrackballCamera
{

public:

/////////////////////////////////////////////////////
//Custom Overidden Routines///////////
/////////////////////////////////////////////////////
	void OnLeftButtonDown();

protected:

private:

};

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

#include "stdafx.h"
#include "vtkMDI.h"

#include "vtkCDNInteractor.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

void  vtkCDNInteractor::OnLeftButtonDown()
{
	StartPan();
}

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

Now in my code I do:

CVtkMDIView::CVtkMDIView()
{
  // Create the the renderer, window and interactor objects.
  this->mp_ren = vtkRenderer::New();
  this->mp_renWin = vtkWin32OpenGLRenderWindow::New();
  this->mp_iren = vtkWin32RenderWindowInteractor::New();

  this->mp_iafl = (vtkCDNInteractor*)vtkCDNInteractor::New();
  this->mp_iren->SetInteractorStyle(mp_iafl);
...
}

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

But this results in a window that just interacts like a normal vtkInteractorStyleTrackballCamera.

I have found that if I call    this->mp_iafl->OnLeftButtonDown()   it seems to call the base function    vtkInteractorStyleTrackballCamera::OnLeftButtonDown()   not the overwritten function I wrote.
If you call     this->mp_iafl->vtkCDNInteractor::OnLeftButtonDown()    then it does call my function.


How do I go about solving this problem?????????????????????????????????????//



>  -----Original Message-----
> From: 	BURRELL Benjamin  
> Sent:	Friday, April 02, 2004 9:35 AM
> To:	'vtkusers at vtk.org'
> Subject:	Win32, Intercepting a interactor messages. (Custom interactor)
> 
> I have an application that has a 3D scene and I want to add a feature to be able to go to a 2D type view. How I want to implement it is to move the camera to directing 'overhead' of the scene and I would 'intercept' left mouse button movements and redirect them from calling Rotate() to Pan(). This would give the impression of only giving a 2D perspective even though it is still a 3D scene. I still would like to keep the rest of the standard interactor functionality.
> 
> Now I though this WAS going to be easy, that I just insert code show below but it seems like the program never enters any of the case statements other than WM_CHAR and WM_TIMER, and it only enters these when a key on the keyboard is pressed.
> 
> Does anyone have any ideas how to do this and how I go about doing a Pan() call?
> 
> Is this problem arising from vtkWin32RenderWindowInteractor by default installing a MessageProc callback like mentioned in the class description?
> If I stop it from installing a MessageProc callback by calling iren->InstallMessageProcOff() the application still never enters the WM_LBUTTONDOWN case.
> 
> 
> LRESULT CVtkMDIView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
> {
> 	switch ( message )
> 	{
> 		//case WM_PAINT: 
> 		case WM_CLOSE: 
> 		case WM_LBUTTONDOWN:  // ENTER CODE HERE TO INTERCEPT A LEFT MOUSE BUTTON ACTION AND MOVEMENT.
> 					       // eg.   if (this->in2Dmode())  { iren->Pan(); }    ???????????
> 		case WM_LBUTTONUP: 
> 		case WM_MBUTTONDOWN: 
> 		case WM_MBUTTONUP: 
> 		case WM_RBUTTONDOWN: 
> 		case WM_RBUTTONUP: 
> 		case WM_MOUSEMOVE:
> 		case WM_CHAR:
> 		case WM_TIMER:
> 			if ( this->mp_iren->GetInitialized() )
> 			{
> 				return vtkHandleMessage2(this->m_hWnd, message, wParam, lParam, this->mp_iren);
> 			}
> 			break;
> 	}
> 	return CView::WindowProc(message, wParam, lParam);
> }
> 
> 
> 
> Thanks for any help,
> 
> Benjamin Burrell



More information about the vtkusers mailing list