gt:     vtkRenderer ren3 = new vtkRenderer();
context: /*=========================================================================
  
    Program: GDCM (Grassroots DICOM). A DICOM library
  
    Copyright (c) 2006-2011 Mathieu Malaterre
    All rights reserved.
    See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
  
       This software is distributed WITHOUT ANY WARRANTY; without even
       the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
       PURPOSE.  See the above copyright notice for more information.
  
  =========================================================================*/
  import vtk.*;
  import gdcm.*;
  import java.io.File;
  
  /*
   * Compilation:
   * CLASSPATH=vtkgdcm.jar:/usr/share/java/vtk.jar javac MPRViewer2.java
   *
   * Usage:
   * LD_LIBRARY_PATH=/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/xawt:/usr/lib/jni:. CLASSPATH=/usr/share/java/vtk.jar:vtkgdcm.jar:gdcm.jar:. java MPRViewer2 BRAINX
   *
   */
  public class MPRViewer2
  {
    static {
      // VTK
      System.loadLibrary("vtkCommonJava");
      System.loadLibrary("vtkFilteringJava");
      System.loadLibrary("vtkIOJava");
      System.loadLibrary("vtkImagingJava");
      System.loadLibrary("vtkGraphicsJava");
      System.loadLibrary("vtkRenderingJava");
      System.loadLibrary("vtkHybridJava");
      System.loadLibrary("vtkWidgetsJava");
      // VTK-GDCM
      System.loadLibrary("vtkgdcmJava");
    }
  
    static FilenamesType fns = new FilenamesType();
  
    public static void process(String path)
      {
      fns.add( path );
      }
  
    // Process only files under dir
    public static void visitAllFiles(File dir)
      {
      if (dir.isDirectory())
        {
        String[] children = dir.list();
        for (int i=0; i<children.length; i++)
          {
          visitAllFiles(new File(dir, children[i]));
          }
        }
      else
        {
        process(dir.getPath());
        }
      }
  
    public void dointer(vtkImagePlaneWidget  current_widget)
      {
      int cstat = current_widget.GetCursorDataStatus();
      double[] v = current_widget.GetCurrentCursorPosition();
      //System.out.println( cstat );
      //System.out.println( v[0] );
      //System.out.println( v[1] );
      //System.out.println( v[2] );
      planeWidgetX.SetSliceIndex( (int)v[0] );
      planeWidgetY.SetSliceIndex( (int)v[1] );
      planeWidgetZ.SetSliceIndex( (int)v[2] );
      planeWidgetX.GetCurrentRenderer().ResetCameraClippingRange();
      planeWidgetY.GetCurrentRenderer().ResetCameraClippingRange();
      planeWidgetZ.GetCurrentRenderer().ResetCameraClippingRange();
      }
    public void startinterX()
      {
      dointer( planeWidgetX );
      }
    public void interX()
      {
      dointer( planeWidgetX );
      }
    public void endinterX()
      {
      }
    public void startinterY()
      {
      dointer( planeWidgetY );
      }
    public void interY()
      {
      dointer( planeWidgetY );
      }
    public void endinterY()
      {
      }
    public void startinterZ()
      {
      dointer( planeWidgetZ );
      }
    public void interZ()
      {
      dointer( planeWidgetZ );
      }
    public void endinterZ()
      {
      //System.out.println( "endinter" );
      }
  
    public static void AlignCamera(int slice_number, vtkImagePlaneWidget current_widget)
      {
      vtkImageData image = (vtkImageData)current_widget.GetInput();
      vtkRenderer ren = current_widget.GetCurrentRenderer();
      double[] origin = image.GetOrigin();
      double ox = origin[0];
      double oy = origin[1];
      double oz = origin[2];
  
      int dims[] = image.GetDimensions();
      int xMin = 0;
      int xMax = 1;
      int yMin = 2;
      int yMax = dims[0]-1;
      int zMin = dims[1]-1;
      int zMax = dims[2]-1;
  
      double[] spacing = image.GetSpacing();
      double sx = spacing[0];
      double sy = spacing[1];
      double sz = spacing[2];
  
      double cx = ox+(0.5*(xMax-xMin))*sx;
      double cy = oy+(0.5*(yMax-yMin))*sy;
      double cz = oy+(0.5*(zMax-zMin))*sz;
      double vx = 0, vy = 0, vz = 0;
      double nx = 0, ny = 0, nz = 0;
      int iaxis = current_widget.GetPlaneOrientation();
      if ( iaxis == 0 ) {
        vz = -1;
        nx = ox + xMax*sx;
        cx = ox + slice_number*sx;
        }
      else if ( iaxis == 1 ) {
        vz = -1;
        ny = oy+yMax*sy;
        cy = oy+slice_number*sy;
        }
      else {
        vy = 1;
        nz = oz+zMax*sz;
        cz = oz+slice_number*sz;
      }
      double px = cx+nx*2;
      double py = cy+ny*2;
      double pz = cz+nz*3;
  
      vtkCamera camera = ren.GetActiveCamera();
      camera.SetViewUp(vx, vy, vz);
      camera.SetFocalPoint(cx, cy, cz);
      camera.SetPosition(px, py, pz);
      camera.OrthogonalizeViewUp();
      ren.ResetCameraClippingRange();
      }
  
    private vtkImagePlaneWidget planeWidgetX = new vtkImagePlaneWidget();
    private vtkImagePlaneWidget planeWidgetY = new vtkImagePlaneWidget();
    private vtkImagePlaneWidget planeWidgetZ = new vtkImagePlaneWidget();
  
    public void config()
      {
      //System.out.println( "config" );
      planeWidgetX.GetCurrentRenderer().ResetCamera();
      planeWidgetY.GetCurrentRenderer().ResetCamera();
      planeWidgetZ.GetCurrentRenderer().ResetCamera();
      }
  
    public void Run(String dirname)
      {
      File dir = new File(dirname);
      visitAllFiles(dir);
  
      IPPSorter ipp = new IPPSorter();
      ipp.SetComputeZSpacing( true );
      ipp.SetZSpacingTolerance( 1e-3 );
      boolean b = ipp.Sort( fns );
      if(!b)
        {
        //throw new Exception("Could not scan");
        }
      double ippzspacing = ipp.GetZSpacing();
  
      FilenamesType sorted = ipp.GetFilenames();
      vtkStringArray files = new vtkStringArray();
      long nfiles = sorted.size();
      //for( String f : sorted )
      for (int i = 0; i < nfiles; i++) {
        String f = sorted.get(i);
        files.InsertNextValue( f );
        }
      vtkGDCMImageReader reader = new vtkGDCMImageReader();
      reader.SetFileNames( files );
      reader.Update(); // get spacing value
  
      double[] spacing = reader.GetOutput().GetSpacing();
  
      vtkImageChangeInformation change = new vtkImageChangeInformation();
      change.SetInputConnection( reader.GetOutputPort() );
      change.SetOutputSpacing( spacing[0], spacing[1], ippzspacing );
      change.Update();
  
      System.out.println( change.GetOutput().toString() );
  
      vtkRenderer ren1 = new vtkRenderer();
      ren1.SetViewport(0., 0., 0.333, 1);
      ren1.SetBackground(0.1,0.2,0.4);
      vtkRenderer ren2 = new vtkRenderer();
      ren2.SetViewport(0.333, 0., 0.667, 1);
      ren2.SetBackground(0.1,0.2,0.4);
  