1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
package vtk.sample.rendering.annotation;
import javax.swing.JFrame;
import vtk.vtkActor;
import vtk.vtkCubeAxesActor;
import vtk.vtkDelaunay2D;
import vtk.vtkNativeLibrary;
import vtk.vtkPanel;
import vtk.vtkPoints;
import vtk.vtkPolyData;
import vtk.vtkPolyDataMapper;
import vtk.vtkRenderer;
import vtk.vtkStringArray;
public class LabeledCubeAxesActor {
// Load VTK library and print which library was not properly loaded
static {
if(!vtkNativeLibrary.LoadAllNativeLibraries()) {
for(vtkNativeLibrary lib : vtkNativeLibrary.values()) {
if(!lib.IsLoaded()) {
System.out.println(lib.GetLibraryName() + " not loaded");
}
}
}
vtkNativeLibrary.DisableOutputWindow(null);
}
public static void main(String args[]) {
try {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
createVtkPanel();
}
});
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* @param panel
*/
static void createVtkPanel() {
JFrame mainFrame = new JFrame();
vtkPanel panel = new vtkPanel();
vtkRenderer renderer = panel.GetRenderer();
vtkPoints points = getPoints();
vtkPolyData polyData = new vtkPolyData();
polyData.SetPoints(points);
vtkDelaunay2D delaunay = new vtkDelaunay2D();
delaunay.SetInputData(polyData);
vtkPolyDataMapper mapper = new vtkPolyDataMapper();
mapper.SetInputConnection(delaunay.GetOutputPort());
vtkActor surfaceActor = new vtkActor();
surfaceActor.SetMapper(mapper);
renderer.AddActor(surfaceActor);
vtkCubeAxesActor cubeAxesActor = new vtkCubeAxesActor();
cubeAxesActor.SetCamera(renderer.GetActiveCamera());
cubeAxesActor.SetBounds(points.GetBounds());
cubeAxesActor.SetXTitle("Date");
cubeAxesActor.SetXAxisMinorTickVisibility(0);
cubeAxesActor.SetAxisLabels(0, getXLabels());
cubeAxesActor.SetYTitle("Place");
cubeAxesActor.SetYAxisMinorTickVisibility(0);
cubeAxesActor.SetAxisLabels(1, getYLabels());
cubeAxesActor.SetZTitle("Value");
renderer.AddActor(cubeAxesActor);
renderer.ResetCamera();
mainFrame.add(panel);
mainFrame.setSize(600, 600);
panel.Render();
mainFrame.setVisible(true);
panel.Render();
}
/**
* @return a list of places ordered the same as the y point values.
*/
static vtkStringArray getYLabels() {
vtkStringArray yLabel = new vtkStringArray();
yLabel.InsertNextValue("A");
yLabel.InsertNextValue("B");
yLabel.InsertNextValue("C");
return yLabel;
}
/**
* @return a list of dates ordered the same as the x point values.
* We have 4 X-values, from 0.5 to 3, that we will label with 6 dates
* that will be linearly distributed along the axis.
*/
static vtkStringArray getXLabels() {
vtkStringArray xLabel = new vtkStringArray();
xLabel.InsertNextValue("Jan");
xLabel.InsertNextValue("Feb");
xLabel.InsertNextValue("Mar");
xLabel.InsertNextValue("Apr");
xLabel.InsertNextValue("May");
xLabel.InsertNextValue("June");
return xLabel;
}
/**
* @return data to plot.
*/
static vtkPoints getPoints() {
vtkPoints points = new vtkPoints();
points.InsertNextPoint(0.5, 0, 0.);
points.InsertNextPoint(1, 0, 1.);
points.InsertNextPoint(2, 0, 0.4);
points.InsertNextPoint(3, 0, 0.5);
points.InsertNextPoint(0.5, 1, 0.3);
points.InsertNextPoint(1, 1, 0.3);
points.InsertNextPoint(2, 1, 0.8);
points.InsertNextPoint(3, 1, 0.6);
points.InsertNextPoint(0.5, 2, 0.5);
points.InsertNextPoint(1, 2, 0.8);
points.InsertNextPoint(2, 2, 0.3);
points.InsertNextPoint(3, 2, 0.4);
return points;
}
}
|