[vtkusers] vtkChartXYZ Java example

James Labiak jim at jslengineeringsoftware.com
Mon Dec 8 10:46:33 EST 2014


Hello,
I am a new user of vtk and relatively new to Java. I am trying to use 
vtkChartXYZ in Java, but having a lot of problems. I adapted the 
TestSurfacePlot.cxx from Charts\Core\Testing\Cxx to Java, but it just 
shows a 2D surface which appears to be a plane. Does anyone have any 
Java examples of vtkChartXYZ? I included the converted Java code below.
Thanks,
Jim


import java.io.File;

// We import the vtk wrapped classes first.
import vtk.*;

// Then we define our class.
public class CP_plot_test {

   // In the static contructor we load in the native code.
   // The libraries must be in your path to work.

     static
     {
         if (!vtkNativeLibrary.LoadAllNativeLibraries()) {
            for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
                     if (!lib.IsLoaded())
                 System.out.println(lib.GetLibraryName() + " not loaded");
            }
         System.out.println("Make sure the search path is correct: ");
         System.out.println(System.getProperty("java.library.path"));
         }
         vtkNativeLibrary.DisableOutputWindow(null);
     }

   // now the main program
   public static void main (String []args) {

       vtkChartXYZ chart = new vtkChartXYZ();
       vtkPlotSurface plot = new vtkPlotSurface();
       vtkContextView view = new vtkContextView();
       view.GetRenderWindow().SetSize(400, 300);
       view.GetScene().AddItem(chart); //.GetPointer();

       //create a surface
       vtkTable table = new vtkTable();
       int numPoints = 70;
       float inc = 9.424778F / (numPoints - 1);
       for (float x = 0; x < numPoints; ++x)
       {
         vtkDoubleArray arr = new vtkDoubleArray();
         for (float y = 0; y < numPoints; ++y)
                 {
                     double z = Math.sin(Math.sqrt(x * x + y * y));
                     arr.InsertNextValue(z);
                     System.out.println("x = " + x + " y = " + y + " z 
=" + z);
                 }
         table.AddColumn(arr);
       }

       //set up the surface plot to be visualized and add it to the chart

       System.out.println("Table has " + table.GetNumberOfColumns() + " 
columns");
       System.out.println("Table has " + table.GetNumberOfRows() + " rows");

       plot.SetYRange(0, 9.424778);
       plot.SetXRange(0, 9.424778);
       plot.SetInputData(table);
       chart.AddPlot(plot);

       view.GetRenderWindow().SetMultiSamples(0);
       view.GetInteractor().Initialize();
       view.GetRenderWindow().Render();

       view.GetInteractor().Start();

  }
}


More information about the vtkusers mailing list