JLink / VTK problem
- To: mathgroup at smc.vnet.net
- Subject: [mg63825] JLink / VTK problem
- From: "Andy Somogyi" <andy_somogyi at hotmail.com>
- Date: Mon, 16 Jan 2006 02:16:52 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hello All I'm trying to get Mathematica to call some VTK (visulization toolkit) classes using the java VTK wrapper. I've tried the same example using plain java and it works fine. Here is the original java code: import vtk.*; public class Cone { public static void main (String []args) { System.loadLibrary("vtkCommonJava"); System.loadLibrary("vtkFilteringJava"); System.loadLibrary("vtkIOJava"); System.loadLibrary("vtkImagingJava"); System.loadLibrary("vtkGraphicsJava"); System.loadLibrary("vtkRenderingJava"); vtkConeSource cone = new vtkConeSource() ... And here is the Mathematica code: Needs["JLink`"] (* use the correct version of java, this is the version I build VTK with *) In[23]:= InstallJava[CommandLine->"C:\\Program Files\\Java\\jdk1.5.0_05\\jre\\bin\\javaw.exe"] Out[23]=LinkObject[C:\Program Files\Java\jdk1.5.0_05\jre\bin\javaw.exe,6,2] (* add the location of the vtk jar *) In[24]:=AddToClassPath["D:/src/vtk_build/bin"]; (* load System to create the context *) In[25]:=LoadJavaClass["java.lang.System"] Out[25]=JavaClass[java.lang.System,0] (* load the VTK native libraries, all works fine *) In[26]:=System`loadLibrary["vtkCommonJava"] In[27]:=System`loadLibrary["vtkFilteringJava"] In[28]:=System`loadLibrary["vtkIOJava"] In[29]:=System`loadLibrary["vtkImagingJava"] In[30]:=System`loadLibrary["vtkGraphicsJava"] In[31]:=System`loadLibrary["vtkRenderingJava"] (* create a new vtk object, this is where I get into trouble *) In[32]:=cone = JavaNew["vtk.vtkConeSource"] From In[32]:=Java::excptn: A Java exception occurred: java.lang.UnsatisfiedLinkError: \ VTKInit at vtk.vtkConeSource.VTKInit(Native Method) at vtk.vtkObject.<init>(vtkObject.java:98) at vtk.vtkProcessObject.<init>(vtkProcessObject.java:78) at vtk.vtkSource.<init>(vtkSource.java:82) at vtk.vtkPolyDataSource.<init>(vtkPolyDataSource.java:30) at vtk.vtkConeSource.<init>(vtkConeSource.java:114) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(\ NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(\ DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:494). From In[32]:= JavaNew::fail: Error calling constructor for class vtk.vtkConeSource. Out[32]=$Failed As you can see, the Mathematica code is doing the exact same thing as the java code, and the java code works fine. BTW, I run the java example like: javaw -classpath ../../../../bin/vtk.jar;. Cone Has anyone here had much experience with JLink, how reliable / stable is it? Reason that I ask is that I'm starting to work on a binding from Mathematica to VTK and I'm debating writting my own MathLink interface directly or using java with the VTK java wrapper. thanks