Using VTK with java
cd java/mkdir classes/javac -d classes/ vtk/*.javacd classes/jar cvf vtk.jar vtk/jar i vtk.jarcp vtk.jar ../../bin/
The goal is to build a kick-ass 3d renderer using vtk inside java. My guess is that I'll need the vtk.jar and the .dll (shared libraries) and tuck them inside NakedRelease/libraries and NakedRelease/native. But we'll see how well that works :)
http://www.duke.edu/~iwd/howto/VTK-Linux-Java_HOWTO.html
1) Build vtk4.x with Java wrapping
2) Compile all the vtk *.java files ... look in dir x:\vtk4x\VTKbin\java\vtk
3) compile vtkPanel.java and place it in java\vtk with the other classes ... look in x:\vtk4x\VTK\Wrapping\Java for the source file.
4) Add environment variable CLASSPATH = .;x:\vtk4x\vtkbin\java (NOTE: the leading period is important). Since vtk java wrappings have been packaged, you do not need to point to the \java\vtk folder, just \java
At this point you should have a good vtk Java wrapping installed so try running VTKSimple to make sure the Java part is working okay ... look in x:\vtk4x\VTK\Wrapping\Java for the source code.
5) edit MatLab C:\MATLAB6p1\toolbox\local\classpath.txt to add drive:\path_to_the_classfiles
Don't put the name of the classes there. Just the path is sufficient for matlab to pick up all the classes that exist in that directory. Since vtk java wrappings have been packaged, you do not need to point to the \java\vtk folder, just \java. For example, this works for me...
P:\WinCVS\vtk40\VTKbin\java
6) Compile the vtkMatlab.java file (see below for code) and place the class file in the java directory (important not in java/vtk) .... try placing it in x:\vtk4x\vtkbin\java. You could place this file whereever you want if you add its path to the MatLab classpath or to the Environment variable CLASSPATH see steps 3) or 5)
7) Run the testvtk.m script (see code below) which attemps to load each class from MatLab. It should run fine and create all the zillion variables. If some are not created check that in cmake you enabled all the needed modules (patented etc). As vtk changes you may need to recomplie the list of vtk classes it loads, see the instructions for doing this in the comments of the script.
7b) Alternately you can run my script ckvtk.m (see code below) which dynamically creates the list and objects, writing log files with a.) successful creations and b.) any errors creating objects. Intenal comments tell whats going on. Note: you need to change the path in the script to point to your directory of vtk classes so it can generate the class list. (I know I could probably get this from the CLASSPATH variable but I'm too lazy)
8) Run the cone.m script from within MatLab (see code below)
I was not able to run this with the default jre in Matlab (v1.1.8) so I changed to jre 1.3.1 as follows:
Create an environment variable MATLAB_JAVA and point it to the jre folder you want, for example P:\wincvs\java13102\jre. I see some funny things happen in Matlab with 1.3.102 but this might just be me. I've seen some seg faults and the Matlab command cursor disappears sometimes. Use at your own risk. Another funny thing is that exitting the vtk scripts closes MatLab...hmmmm
Also it appears that Matlab truncates class names longer than 31 characters (35 with vtk.) so these classes can not create objects using the standard obj = vtk.vtkClass however this works obj=javaObject('vtk.vtkClass')


0 Comments:
Post a Comment
<< Home