[vtkusers] Still can't get vtkInteractorStyle to work!

Nikhil Sharma pingnikhil at yahoo.com
Fri Oct 13 09:31:22 EDT 2006


Folks,

1. I'm still stuck!  Even vtkInteractorStyleImage gets unnoticed. (VTK
version: latest from CVS)

2. Secondly, (and no one addressed this second point of mine in my
original message, which is...)  how would I dynamically use / ignore
base class event handling services?   For example, some entity inside
my renderWindowInteractor is 'helpfully' providing image window-level /
 window-width functionality during mouse drag... something, which I'd
like to turn off and replace with my own.

3. Would someone be kind enough to take a quick look at the Java code
below and point out what is it that I'm missing here?  I still believe
I'm going exactly by the book (and by the API documentation)... seem to
truly have run out of ideas at this point!

4. General advice sought:  My application needs to only support 2D MPR,
Volume Rendering, and Surface Rendering.  Given such a rough start with
VTK on such a simple thing as custom mouse/kb interaction, I'm
thinking... Do I even need to pull in such a large and general purpose
visualization package as VTK in my Java app?  Couldn't I simply
implement from scratch the above 3 features, algorithms for which have
been amply discussed on the Net and in Graphics text books. 
Essentially, I have a premonition that using VTK in more-than-casual
scenarious, customizing it, etc will not go smoothly and will be far
from easy... so whether investing time learning it would be worth it! 
My assumption here is implementing and debugging one's code will be far
more easier than trying to understand (and fit into) someone else's.
	Can someone (politely) advise on this point as well?

Regards,
-Nikhil.


////////////////////////////
// vtkTestApp.java : 
//   Requires vtk.jar in classpath
//   Requires the vtk DLLs to be in PATH.

import java.io.IOException;
import vtk.*;
import java.awt.*;


class MouseKBController extends vtkInteractorStyleImage {
// class Controller extends vtkInteractorStyle {
	public void OnLeftButtonDown() {
		System.out.println("left button down");
	}
	public void OnLeftButtonUp() {
		System.out.println("left button up");
	}

	public void LeftButtonPressEvent() {
		OnLeftButtonDown();
	}
	public void LeftButtonReleaseEvent() {
		OnLeftButtonUp();
	}
}


class VtkStuff {
	
	private vtkDICOMImageReader i_reader;
	private vtkTransform i_txform;
	private vtkImageReslice i_reslice;
	private vtkRenderWindowInteractor i_rwi;
	
	private vtkImageData i_imageData; 
	private vtkImageMapper i_imageMapper;
	private vtkActor2D i_actor2D;
	private vtkRenderWindow i_renWindow;
	private vtkRenderer i_renderer;
	private MouseKBController i_controller; 

	public void init() {
		i_reader = new vtkDICOMImageReader();
		i_reader.ReleaseDataFlagOn(); // for opt
		
		i_reader.SetDirectoryName("C:\\image-dir");
		i_reader.Update();
	
		i_txform = new vtkTransform();
		i_txform.RotateZ(45);
		double s = 4; // 1.414;
		i_txform.Scale(new double[] { s, s, s });
		
		i_reslice = new vtkImageReslice();
		i_reslice.SetInput(i_reader.GetOutput());
		i_reslice.SetResliceTransform(i_txform);
		i_reslice.InterpolateOn();
		i_reslice.SetInterpolationModeToCubic();
		i_reslice.WrapOff(); // reslice.WrapOn();
		i_reslice.AutoCropOutputOn();
		double dc = Math.cos(45);
		i_reslice.SetResliceAxesDirectionCosines(dc,0,0, 0,dc,0, 0,0,dc);

		i_imageData = i_reslice.GetOutput();
		i_imageMapper = new vtkImageMapper();
		i_imageMapper.SetInput(i_imageData);
		
		i_actor2D = new vtkActor2D();
		i_actor2D.SetMapper(i_imageMapper);
		
		i_renderer = new vtkRenderer();
		i_renderer.AddActor(i_actor2D);
		
		i_renWindow = new vtkRenderWindow();
		i_renWindow.AddRenderer(i_renderer);
		
		i_rwi = new vtkRenderWindowInteractor();
		i_controller = new MouseKBController();
		i_rwi.SetInteractorStyle(i_controller);
		i_rwi.SetRenderWindow(i_renWindow);
		
		i_renWindow.Render();
		i_rwi.Start();
	}
}


public class vtkTestApp {

	static {
		try {
			// System.out.println("java.library.path = " +
System.getProperty("java.library.path"));
			System.loadLibrary("vtkCommon");
			System.loadLibrary("vtkCommonJava");
			System.loadLibrary("vtkDICOMParser");
			System.loadLibrary("vtkexoIIc");
			System.loadLibrary("vtkexpat");
			System.loadLibrary("vtkFiltering");
			System.loadLibrary("vtkFilteringJava");
			System.loadLibrary("vtkfreetype");
			System.loadLibrary("vtkftgl");
			System.loadLibrary("vtkGenericFiltering");
			System.loadLibrary("vtkGenericFilteringJava");
			System.loadLibrary("vtkGraphics");
			System.loadLibrary("vtkGraphicsJava");
			System.loadLibrary("vtkHybrid");
			System.loadLibrary("vtkHybridJava");
			System.loadLibrary("vtkImaging");
			System.loadLibrary("vtkImagingJava");
			System.loadLibrary("vtkIO");
			System.loadLibrary("vtkIOJava");
			System.loadLibrary("vtkjpeg");
			System.loadLibrary("vtkMPEG2Encode");
			System.loadLibrary("vtkNetCDF");
			System.loadLibrary("vtkpng");
			System.loadLibrary("vtkRendering");
			System.loadLibrary("vtkRenderingJava");
			System.loadLibrary("vtksys");
			System.loadLibrary("vtktiff");
			System.loadLibrary("vtkVolumeRendering");
			System.loadLibrary("vtkVolumeRenderingJava");
			System.loadLibrary("vtkWidgets");
			System.loadLibrary("vtkWidgetsJava");
			System.loadLibrary("vtkzlib");
		} catch(Exception e) {
			System.err.println("FAILED to load libraries, aborting!");
			System.exit(1);
		}
	}
	
	public static void main(String[] args) {
		VtkStuff vs = new VtkStuff();
		vs.init();
	}
}


===================
-----Original Message-----

I did the same in C++ but I inherited from vtkInteractorStyleImage.
Worked
without a problem. Try inheriting from it and override the members.

You probably will need to override all the mouse and keyboard events as
all
have some functionality associated that you might not want, but it
should
work..

I am not sure why this should not work though... could be a problem
with how
it is being cast internally, not sure. Should work despite that. I have
never used the JAVA side of it, so do not know.

Good luck,
Anja

===================
-----Original Message-----

Good to know that I'm not alone, then!
 
Now, I gave the problem some more thought since I my earlier post. 
Looks to me a class design flaw in VTK.  Here's why.
 
Though the user is free to override vtkInteractorStyle and pass it
polymorphically to vtkRenderWindowInteractor::SetInteractorStyle(), the
argument would most likely be internally cached as
vtkInteractorObserver (the base class). Which means, the callback
mechanism cannot and will not know about vtkInteractorStyle (or, the
derived class') members (and their overrides). 
 
It's quite possible that VTK may have a workaround for this, making it
not so much of a flaw!  In which case, would any of the VTK veterans /
power-users please suggest a better/alternate (set of) class(es) to
accomplish what I'm trying to... ?
 
I'm trying to:
  1. plug in my own event handlers into VTK, and
  2. have the ability to conditionally use (or not use) base class' (or
the default) version of the event handlers.
 
Regards,
-Nikhil.
 
-----Original Message-----
From: vtkusers-bounces+pingnikhil= yahoo.com at vtk.org
<http://www.vtk.org/mailman/listinfo/vtkusers>
[mailto:vtkusers-bounces+pingnikhil= yahoo.com at vtk.org
<http://www.vtk.org/mailman/listinfo/vtkusers>]On Behalf Of Harry
Simons
Sent: Wednesday, October 04, 2006 9:01 a
To:  vtkusers at vtk.org <http://www.vtk.org/mailman/listinfo/vtkusers>
Subject: RE: [vtkusers] vtkInteractorStyle overrides fail to fire!


Yep, me too.  Frustrated, gave up on this one   eventually.

> 
> Hello,
> 
> I'm trying to   implement custom mouse event handling for my 2D
(image
> actor) as   follows. The image slice shows up fine but my event
override 
> fails to   fire! Anything I'm missing?
> 
> Regards,
> A VTK   Newbie.
> 
> 
> class MyInteractorStyle extends   vtkInteractorStyle {
>     public void   OnLeftButtonDown() {
>           System.out.println("left button pressed");
>       }
> }
> 
> // ...
> myIS = new   MyInteractorStyle();
> rwi = new vtkRenderWindowInteractor();
>   rwi.SetInteractorStyle (myIS);
> 
> // ...
>   rwi.SetRenderWindow(renderWindow);
> renderWindow.Render();
>   rwi.Start();
> 




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the vtkusers mailing list