6 * Enum used to load native library more easily. If you don't want to set the
7 * specific environment variable you can provide the path of the directory that
8 * contains the VTK library through a Java Property. Like in the following
11 * > java -cp vtk.jar -Dvtk.lib.dir=.../vtk-libs vtk.sample.SimpleVTK
13 * The directory .../vtk-libs must contain the so/dll/dylib + the jnilib files
15 * @author sebastien jourdain - sebastien.jourdain@kitware.com
17 public enum vtkNativeLibrary {
19 COMMON("vtkCommonJava"), //
20 FILTERING("vtkFilteringJava"), //
21 GEOVIS("vtkGeovisJava"), //
22 GRAPHICS("vtkGraphicsJava"), //
23 HYBRID("vtkHybridJava"), //
24 IMAGING("vtkImagingJava"), //
25 INFOVIS("vtkInfovisJava"), //
27 RENDERING("vtkRenderingJava"), //
28 VIEWS("vtkViewsJava"), //
29 VOLUME_RENDERING("vtkVolumeRenderingJava"), //
30 WIDGETS("vtkWidgetsJava"), //
31 CHARTS("vtkChartsJava");
34 * Try to load all library
36 * @return true if all library have been successfully loaded
38 public static boolean LoadAllNativeLibraries() {
39 boolean isEveryThingLoaded = true;
40 for (vtkNativeLibrary lib : values()) {
43 } catch (UnsatisfiedLinkError e) {
44 isEveryThingLoaded = false;
48 return isEveryThingLoaded;
52 * Load the set of given library and trows runtime exception if any given
53 * library failed in the loading process
55 * @param nativeLibraries
57 public static void LoadNativeLibraries(vtkNativeLibrary... nativeLibraries) {
58 for (vtkNativeLibrary lib : nativeLibraries) {
64 * Disable the pop-in vtkErrorWindow by writing the error to a log file.
65 * If the provided logFile is null the default "vtkError.txt" file will be
70 public static void DisableOutputWindow(File logFile) {
72 logFile = new File("vtkError.txt");
74 vtkFileOutputWindow outputError = new vtkFileOutputWindow();
75 outputError.SetFileName(logFile.getAbsolutePath());
76 outputError.SetInstance(outputError);
79 private vtkNativeLibrary(String nativeLibraryName) {
80 this.nativeLibraryName = nativeLibraryName;
85 * Load the library and throws runtime exception if the library failed in
88 public void LoadLibrary() throws UnsatisfiedLinkError {
90 if (System.getProperty("vtk.lib.dir") != null) {
91 File dir = new File(System.getProperty("vtk.lib.dir"));
92 patchJavaLibraryPath(dir.getAbsolutePath());
93 File libPath = new File(dir, System.mapLibraryName(nativeLibraryName));
94 if (libPath.exists()) {
96 Runtime.getRuntime().load(libPath.getAbsolutePath());
99 } catch (UnsatisfiedLinkError e) {
103 System.loadLibrary(nativeLibraryName);
109 * @return true if the library has already been succefuly loaded
111 public boolean IsLoaded() {
116 * @return the library name
118 public String GetLibraryName() {
119 return nativeLibraryName;
122 private static void patchJavaLibraryPath(String vtkLibDir) {
123 if (vtkLibDir != null) {
124 String path_separator = System.getProperty("path.separator");
125 String s = System.getProperty("java.library.path");
126 if (!s.contains(vtkLibDir)) {
127 s = s + path_separator + vtkLibDir;
128 System.setProperty("java.library.path", s);
133 private String nativeLibraryName;
134 private boolean loaded;