Hi Antonio,
> My modified version in clojure with errors:*
The errors would be interesting as well. But I found at least two
obvious glitches.
> (defn main []
> (let [cone (doto (vtkConeSource.)
> (.SetHeight 3.0)
> (.SetRadius 1.0)
> (.SetResolution 10))
> coneMapper (doto (vtkPolyDataMapper.)
> (.SetInputConnection(.GetOutputPort cone)))
> coneActor (doto (vtkActor.)
> (.SetMapper coneMapper))
> ren (doto (vtkRenderer.)
> (.AddActor coneActor)
> (.SetBackground 0.1 0.2 0.4)
> (.ResetCamera)
> (.GetActiveCamera.Azimuth 90))
This has to be: (-> (.GetActiveCamera) (.Azimuth 90))
> renWin (doto (vtkRenderWindow.)
> (.AddRenderer ren)
> (.SetSize 300 300))
> iren (doto (.vtkRenderWindowInteractor.)
> (.SetRenderWindow renWin)
> (.SetInteractorStyle vtkInteractorStyleTrackballCamera.)
This has to be: (.SetInteractorStyle (vtkInteractorStyleTrackballCamera.))
> (.Initialize)
> (.Start))
> ]))
HTH,
Tassilo
Add the path to your VTK java files to the "cp" parameter you are
invoking clojure with.
I usually just use -Djava.library.path=<whatever>. On linux you also
may have to be sure that your shared libraries are +x for your user.
--Aaron
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
This is the directory that contains: libvtkCommonJava.so,
libvtkFilteringJava.so, libvtkIOJava.so, libvtkImagingJava.so,
libvtkGraphicsJava.so, and libvtkRenderingJava.so ?
They all are executable for the user you are running your program as?
Does the Java example in your initial mail actually run for you?
--Aaron
What is happening is that the vtk java files and your clojure code are
using different classloaders (clojure uses its own classloader).
System/loadLibrary is kind of crippled in that it always loads the
library into the ClassLoader of the _invoking class's_ classLoader. I
was hoping it would use the Thread's context classloader, but it does
not.
There isn't any straightforward way to load a library using a
particular classloader either, so you have 2 options.
1) Make a java class that exposes a "loadLibrary" method. This java
class will be in the same classLoader as VTK and as a result,
loadLibrary calls from there will be visible to VTK.
public class Loader {
public static void loadLibrary(String lib) {
// Hack to load a library outside of Clojure's classloader
System.loadLibrary(lib);
}
}
2) Expose the package-private "Runtime/loadLibrary0" method and call it.
; This function is in clojure-contrib, reproduced here for convenience
(defn wall-hack-method
"Calls a private or protected method.
params is a vector of class which correspond to the arguments to the method
obj is nil for static methods, the instance object otherwise
the method name is given as a symbol or a keyword (something Named)"
[class-name method-name params obj & args]
(-> class-name (.getDeclaredMethod (name method-name) (into-array
Class params))
(doto (.setAccessible true))
(.invoke obj (into-array Object args))))
(defn load-lib [class lib]
"Loads a native library in the same classLoader as \"class\" was
loaded in. \"lib\" is a string with the OS-appropriate name of the
library. For instance, to load libvtk.so on Linux, lib should be
\"vtk\""
(wall-hack-method java.lang.Runtime "loadLibrary0" [Class String]
(Runtime/getRuntime) class lib))
; Load vtkCommonJava library in the same classLoader as vtkConeSource
(load-lib vtkConeSource "vtkCommonJava")
--------
I actually think clojure should probably add a method to its RT class
that does option 1 above, that way there's a straightforward way to
load native libraries in the correct classloader.
--Aaron
You need to replace all of these with the appropriate (load-lib
vtkConeSource "libraryName"). The vtkConeSource there is fairly
arbitrary, it's just any class that was loaded by the correct
ClassLoader.
> (defn wall-hack-method
> [class-name method-name params obj & args]
> (-> class-name (.getDeclaredMethod (name method-name) (into-array Class
> params))
> (doto (.setAccessible true))
> (.invoke obj (into-array Object args))))
> (defn load-lib [class vtk]
> (wall-hack-method java.lang.Runtime "vtkCommonJava" [Class String]
Where did this "vtkCommonJava" come from? It must be "loadLibrary0".
You're trying to call a method that doesn't exist.
To be clear, the top of your file should look like:
(defn wall-hack-method
"Calls a private or protected method.
params is a vector of class which correspond to the arguments to the method
obj is nil for static methods, the instance object otherwise
the method name is given as a symbol or a keyword (something Named)"
[class-name method-name params obj & args]
(-> class-name (.getDeclaredMethod (name method-name) (into-array
Class params))
(doto (.setAccessible true))
(.invoke obj (into-array Object args))))
(defn load-lib [class lib]
"Loads a native library in the same classLoader as class was
loaded in, lib is a string with the OS-appropriate name of the
library. For instance, to load libvtk.so on Linux, lib should be
\"vtk\""
(wall-hack-method java.lang.Runtime "loadLibrary0" [Class String]
(Runtime/getRuntime) class lib))
(load-lib vtkConeSource "vtkCommonJava")
(load-lib vtkConeSource "vtkFilteringJava")
(load-lib vtkConeSource "vtkIOJava")
(load-lib vtkConeSource "vtkImagingJava")
(load-lib vtkConeSource "vtkGraphicsJava")
(load-lib vtkConeSource "vtkRenderingJava")
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.