File: ImagePlaneWidget.java

package info (click to toggle)
vtk 5.0.2-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 51,080 kB
  • ctags: 67,442
  • sloc: cpp: 522,627; ansic: 221,292; tcl: 43,377; python: 14,072; perl: 3,102; java: 1,436; yacc: 1,033; sh: 469; lex: 248; makefile: 181; asm: 154
file content (162 lines) | stat: -rw-r--r-- 4,919 bytes parent folder | download | duplicates (6)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import vtk.*;

// Example of complex 3D widget in use.
public class ImagePlaneWidget extends vtkCanvas {

  private int width = 512;
  private int height = 512;

  public ImagePlaneWidget(String path) {
    super();

    // attach observer to set the render window size after
    // the render window is created...
    addWindowSetObserver(new Observer() {
        public void update(Observable o, Object arg) {
          setSize(width, height);
        }
      });

    //Start by loading some data.
    vtkVolume16Reader v16 = new vtkVolume16Reader();
    v16.SetDataDimensions(64, 64);
    v16.SetDataByteOrderToLittleEndian();
    v16.SetFilePrefix(path);
    v16.SetImageRange (1, 93);
    v16.SetDataSpacing(3.2, 3.2, 1.5);
    v16.Update();

    setImageData(v16.GetOutput());

    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add(this, BorderLayout.CENTER);

    JFrame frame = new JFrame("ImagePlaneWidget Test");
    frame.setBounds(10, 10, width, height);
    frame.getContentPane().add(p, BorderLayout.CENTER);
    frame.setVisible(true);
    frame.pack();

    frame.addWindowListener(new WindowAdapter() 
      {
        public void windowClosing(WindowEvent e) {System.exit(0);}
      });
  }

  public void setImageData(vtkImageData id) {

    //The shared picker enables us to use 3 planes at one time
    //and gets the picking order right
    vtkCellPicker picker = new vtkCellPicker();
    picker.SetTolerance(0.005);

    //The 3 image plane widgets are used to probe the dataset.
    vtkImagePlaneWidget planeWidgetX = new vtkImagePlaneWidget();
    planeWidgetX.DisplayTextOn();
    planeWidgetX.SetInput(id);
    planeWidgetX.SetInteractor(getIren());
    planeWidgetX.SetPlaneOrientationToXAxes();
    planeWidgetX.SetSliceIndex(32);
    planeWidgetX.SetPicker(picker);
    planeWidgetX.SetKeyPressActivationValue('x');
    planeWidgetX.GetPlaneProperty().SetColor(1, 0, 0);
    planeWidgetX.On();

    vtkImagePlaneWidget planeWidgetY = new vtkImagePlaneWidget();
    planeWidgetY.DisplayTextOn();
    planeWidgetY.SetInput(id);
    planeWidgetY.SetInteractor(getIren());
    planeWidgetY.SetPlaneOrientationToYAxes();
    planeWidgetY.SetSliceIndex(32);
    planeWidgetY.SetPicker(picker);
    planeWidgetY.SetKeyPressActivationValue('y');
    planeWidgetY.GetPlaneProperty().SetColor(1, 1, 0);
    planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable());
    planeWidgetY.On();
     
    //for the z-slice, turn off texture interpolation:
    //interpolation is now nearest neighbour, to demonstrate
    //cross-hair cursor snapping to pixel centers
    vtkImagePlaneWidget planeWidgetZ = new vtkImagePlaneWidget();
    planeWidgetZ.DisplayTextOn();
    planeWidgetZ.SetInput(id);
    planeWidgetZ.TextureInterpolateOff();
    planeWidgetZ.SetInteractor(getIren());
    planeWidgetZ.SetPlaneOrientationToZAxes();
    planeWidgetZ.SetSliceIndex(46);
    planeWidgetZ.SetPicker(picker);
    planeWidgetZ.SetKeyPressActivationValue('z');
    planeWidgetZ.GetPlaneProperty().SetColor (0, 0, 1);
    planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable());
    planeWidgetZ.On();

    //An outline is shown for context.
    vtkOutlineFilter outline = new vtkOutlineFilter();
    outline.SetInput (id);
      
    vtkPolyDataMapper outlineMapper = new vtkPolyDataMapper();
    outlineMapper.SetInput ( outline.GetOutput()  );
      
    vtkActor outlineActor = new vtkActor();
    outlineActor.SetMapper(outlineMapper);
      
    GetRenderer().AddActor(outlineActor);
      
    //Add the outline actor to the renderer, set the background and size
    GetRenderer().GetCullers().RemoveAllItems();
      
    GetRenderer().SetBackground(0.1, 0.1, 0.2);
      
  }

  static public void printUsage(String err) {
    if (!err.equals("")) {
      System.err.println("Error: " + err);
    }
    System.err.println("Usage: java ImagePlaneWidget [-D path]");
    System.err.println("Where:");
    System.err.println("      path is location of your VTKData directory");
    System.exit(-1);
  }


  public static void main(String[] argv) {
    int argSize = argv.length;

    String pathToVTKData = "";

    int argCurrent = 0;

    try {
      while (argSize > argCurrent) {
	if (argv[argCurrent].equals("-D")) {
	  ++argCurrent;
	  pathToVTKData = argv[argCurrent];
	  ++argCurrent;
	}
	else {
	  ImagePlaneWidget.printUsage("");
	} 
      }
    }
    catch (Exception e) {
      ImagePlaneWidget.printUsage("");
    }

    if (pathToVTKData.equals(""))
      ImagePlaneWidget.printUsage("");

    File f = new File(pathToVTKData + "/Data/headsq");
    if (!f.exists() || !f.canRead() || !f.isDirectory())
      ImagePlaneWidget.printUsage(f.getAbsolutePath() + " does not exist or cannot be read.");

    new ImagePlaneWidget(f.getAbsolutePath() + "/quarter");

  }
}