[vtkusers] vtkPanel and JAVA 1.4

Jeff Lee jeff at cdnorthamerica.com
Mon Apr 22 07:15:47 EDT 2002


Hi All,
I recently packaged up vtkPanel.java.  You can put the source on the 
toplevel in your project (vtk/vtkPanel.java).  Please let me know if 
there are any problems.
-Jeff

JL wrote:

>Hi Jason,
>
>I am enclosing a modified version of vtkPanel (and the
>corresponding) native routines.  These two files are
>taken from VTK 4.0.  I made some minor modifications,
>which include making vtkPanel part of the vtk package.
>
>Although, I compiled with JDK 1.3., it should work with
>JDK 1.4 if the only requirements are the ones you
>mentioned in your previous mail.
>
>I ran a small test program against vtk3.2 on windows and
>it works.  However, I'm not sure whether it would work
>on other platforms.  I haven't played with VTK 4.0,
>mainly 'cause I haven't taken the time to see how CMake
>works.  That said, it means I have not built this version
>of vtkPanel against VTK 4.0.  It was confusing why
>vtkJavaAwt was a header file (.h) and not a C++ file
>(.cxx) and where it was included from, etc.
>
>I think changes are required in the configuration in
>order to build this version of vtkPanel with vtk 4.0.
>Anyway, I build a separate vtkPanel library that
>contains only the native methods for vtkPanel.
>
>You are welcome to try it and maybe someone might
>volunteer to test the changes on different platforms
>and integrate them in the main source tree.
>
>So, here's how I go around building the support for
>vtkPanel.  Essentially, I build it separately from vtk.
>
>I build a separate shared library for vtkPanel
>(i.e. vtkPanel.dll or libvtkPanel.so) from vtkJavaAwt.cxx.
>I've included a pseudo-makefile, that probably won't work
>if used directly, but illustrates what it is required to
>build the vktPanel library.
>
>vtkPanel.dll is linked against:
> - vtkJava.lib
> - vtkCommon.lib
> - vtkGraphics0.lib
> - $(JDKDIR)/lib/jawt.lib where JDKDIR is the topmost
>   directory of the JDK installation.
>
>And vtkPanel is compiled as usual, "linking" against vtk.jar.
>
>javac -classpath directory_where_your_vtk_jar_is/vtk.jar:. \
>	vtk/vtkPanel.java
>
>And to execute, make sure that the appropriate CLASSPATH is set
>and that the libraries can be found by the dynamic loader, that
>is the path to the directory where your libraries are is in the
>PATH variable for Windows or in LD_LIBRARY_PATH for Unix.
>
>By now, I have confused everyone.  I apologize I cannot make
>things easier/clearer, but I'm sure there are many people out
>there that can do a better job making the build process easier
>and integrating the changes into VTK.
>
>I hope this helps,
>
>-- Julio
>
>------------ pseudo-makefile begin ------------
>
>ALL : vtkPanel.dll
>
>JDKDIR    = your_jdk_dir_here
>VTKSRCDIR = your_vtk_dir_here
>VTKBINDIR = your_vtk_build_dir_here
>PLATFORM  = win32
>
>INCLUDES  = -I "$(VTKSRCDIR)/common" -I "$(VTKSRCDIR)/graphics" \
>	    -I "$(JDKDIR)/include" -I "$(JDKDIR)/include/$(PLATFORM)" \
>	    -I "$(VTKBINDIR)"
>
>CXX_FLAGS = -nologo -G6 -MT -W3 -GX- -Od -DWIN32 -DDEBUG -D_WINDOWS -D_MBCS
>\
>	    -D_USRDLL -FD -c
>
>LINK32	     = link.exe
>LIBS 	     = vtkJava.lib vtkCommon.lib vtkGraphics0.lib
>$(JDKDIR)/lib/jawt.lib
>LINK32_FLAGS = -nologo -dll -incremental:no -machine:I386 -out:vtkPanel.dll
>\
>	     = -implib:vtkPanel.lib -libpath:$(VTKBINDIR)/lib
>
>vtkPanel.dll: $(LIBS) vtkJavaAwt.obj
>	$(LINK32) @<<
>  $(LINK32_FLAGS) $(LIBS) vtkJavaAwt.obj
><<
>
>vtkJavaAwt.obj: vtkJavaAwt.cxx # And other dependencies
>	$(CPP) $(CPP_PROJ) $(SOURCE)
>
>------------ pseudo-makefile end ------------
>
>
>
>
>>-----Original Message-----
>>From: vtkusers-admin at public.kitware.com
>>[mailto:vtkusers-admin at public.kitware.com]On Behalf Of
>>jason_donmoyer at chiinc.com
>>Sent: Tuesday, April 16, 2002 9:46 AM
>>To: vtkusers at public.kitware.com
>>Subject: [vtkusers] vtkPanel and JAVA 1.4
>>
>>
>>The class vtkPanel distributed with the vtk examples will not
>>compile using
>>J2SDK 1.4.  The following excerpt from the release notes explains why:
>>
>>------
>>
>>The compiler now rejects import statements that import a type from the
>>unnamed namespace. Previous versions of the compiler would accept such
>>import declarations, even though they were arguably not allowed by the
>>language (because the type name appearing in the import clause is not in
>>scope). The specification is being clarified to state clearly that you
>>cannot have a simple name in an import statement, nor can you import from
>>the unnamed namespace.
>>To summarize, the syntax
>>
>>import SimpleName;
>>
>>is no longer legal. Nor is the syntax
>>import ClassInUnnamedNamespace.Nested;
>>
>>which would import a nested class from the unnamed namespace. To fix such
>>problems in your code, move all of the classes from the unnamed namespace
>>into a named namespace.
>>
>>-----------
>>
>>
>>You can temporarily get around this problem by compiling vtkPanel with an
>>older version of the JDK while continuing to use J2SDK 1.4 for the rest of
>>your classes.  Steps should be taken to fix this problem so that
>>it complies
>>with the latest version of the JDK.  This is important so that
>>users of vtk
>>can take advantage of the performance benefits of 1.4 without resorting to
>>recreating the JNI calls.
>>
>>Thank you,
>>
>>Jason Donmoyer
>>_______________________________________________
>>This is the private VTK discussion list.
>>Please keep messages on-topic. Check the FAQ at:
>><http://public.kitware.com/cgi-bin/vtkfaq>
>>Follow this link to subscribe/unsubscribe:
>>http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
>>------------------------------------------------------------------------
>>
>>/* vtkPanel.java
>> * $Id$
>> */
>>package vtk;
>>
>>import java.awt.*;
>>import java.awt.event.*;
>>import java.lang.Math;
>>import sun.awt.*;
>>import java.beans.*;
>>
>>import vtk.vtkActor;
>>import vtk.vtkActorCollection;
>>import vtk.vtkCamera;
>>import vtk.vtkLight;
>>import vtk.vtkPicker;
>>import vtk.vtkRenderer;
>>import vtk.vtkRenderWindow;
>>
>>public class vtkPanel
>>    extends Canvas
>>    implements MouseListener, MouseMotionListener, KeyListener
>>{
>>  protected vtkRenderWindow rw = new vtkRenderWindow();
>>  protected vtkRenderer ren    = new vtkRenderer();
>>  protected vtkLight light     = new vtkLight();
>>  protected vtkCamera cam;
>>  protected int lastX;
>>  protected int lastY;
>>  protected int windowset 	  	= 0;
>>  protected int InteractionMode   	= 1;
>>  protected boolean lightFollowsCamera	= true;
>>  protected boolean rendering 	  	= false;
>>
>>  static {
>>    System.err.println( "loading vtkPanel native library" );
>>    System.loadLibrary( "vtkPanel" );
>>  }
>>
>>  public vtkPanel()
>>  {
>>    this.rw.AddRenderer(ren);
>>    this.addMouseListener(this);
>>    this.addMouseMotionListener(this);
>>    this.addKeyListener(this);
>>  }
>>
>>  public vtkRenderer GetRenderer()
>>  {
>>    return ren;
>>  }
>>
>>  public vtkRenderWindow GetRenderWindow()
>>  {
>>    return rw;
>>  }
>>
>>  private native void RenderCreate(vtkRenderWindow rw);
>>  private native void SetSizeInternal(vtkRenderWindow rw,int width,int height);
>>  private native void RenderInternal(vtkRenderWindow rw);
>>
>>  public void setSize(int width, int height)
>>  {
>>//    System.err.println( "vtkPanel.setSize(x=" + x + ", y=" + y + ")" );
>>    super.setSize(width, height);
>>    SetSizeInternal(this.rw, width, height);
>>  }
>>
>>  public void setBounds(int x, int y, int width, int height)
>>  {
>>//    System.err.println( "vtkPanel.setBounds(x=" + x + ", y=" + y + ", width="
>>//    			+ width + ", height=" + height + ")" );
>>    super.setBounds(x, y, width, height);
>>
>>    /* @todo: check whether the native window has been created already before
>>     * calling SetSizeInternal, to avoid SetSizeInternal from failing when the
>>     * native window has not been created
>>     */
>>    this.SetSizeInternal(this.rw, width, height);
>>  }
>>
>>  public void addNotify()
>>  {
>>    super.addNotify();
>>//    System.err.println("vtkPanel.addNotify()");
>>    this.RenderCreate(this.rw);
>>  }
>>
>>  public synchronized void Render()
>>  {
>>    if (!this.rendering) {
>>      this.rendering = true;
>>
>>      if (this.rw != null && this.ren.VisibleActorCount() != 0) {
>>        if (this.windowset == 0) {
>>          // set the window id and the active camera
>>          this.RenderCreate(this.rw);
>>          this.cam = this.ren.GetActiveCamera();
>>          this.ren.AddLight(this.light);
>>          this.light.SetPosition(this.cam.GetPosition());
>>          this.light.SetFocalPoint(this.cam.GetFocalPoint());
>>          this.windowset = 1;
>>        }
>>        this.RenderInternal(this.rw);
>>      }
>>
>>      this.rendering = false;
>>    }
>>  }
>>
>>  public void update(Graphics g)
>>  {
>>    /* avoid the background being cleared by the default implementation */
>>    this.paint(g);
>>  }
>>
>>  public void paint(Graphics g)
>>  {
>>    this.Render();
>>  }
>>
>>  public void LightFollowCameraOn()
>>  {
>>    this.lightFollowsCamera = true;
>>  }
>>
>>  public void LightFollowCameraOff()
>>  {
>>    this.lightFollowsCamera = false;
>>  }
>>
>>  public void InteractionModeRotate()
>>  {
>>    this.InteractionMode = 1;
>>  }
>>
>>  public void InteractionModeTranslate()
>>  {
>>    this.InteractionMode = 2;
>>  }
>>
>>  public void InteractionModeZoom()
>>  {
>>    this.InteractionMode = 3;
>>  }
>>
>>  public void UpdateLight()
>>  {
>>    light.SetPosition(cam.GetPosition());
>>    light.SetFocalPoint(cam.GetFocalPoint());
>>  }
>>
>>  public void mouseClicked(MouseEvent e) {}
>>
>>  public void mousePressed(MouseEvent e)
>>  {
>>    if (ren.VisibleActorCount() == 0) return;
>>    rw.SetDesiredUpdateRate(5.0);
>>    lastX = e.getX();
>>    lastY = e.getY();
>>
>>    if ((e.getModifiers() == InputEvent.BUTTON2_MASK)
>>        || e.getModifiers() == (InputEvent.BUTTON1_MASK|InputEvent.SHIFT_MASK))
>>    {
>>      InteractionModeTranslate();
>>    }
>>    else if (e.getModifiers()==InputEvent.BUTTON3_MASK)
>>    {
>>      InteractionModeZoom();
>>    }
>>    else
>>    {
>>      InteractionModeRotate();
>>    }
>>  }
>>
>>  public void mouseReleased(MouseEvent e)
>>  {
>>    rw.SetDesiredUpdateRate(0.01);
>>  }
>>
>>  public void mouseEntered(MouseEvent e)
>>  {
>>    this.requestFocus();
>>  }
>>
>>  public void mouseExited(MouseEvent e) {}
>>
>>  public void mouseMoved(MouseEvent e)
>>  {
>>    lastX = e.getX();
>>    lastY = e.getY();
>>  }
>>
>>
>>  public void mouseDragged(MouseEvent e)
>>  {
>>    if (ren.VisibleActorCount() == 0)
>>      return;
>>
>>    int x = e.getX();
>>    int y = e.getY();
>>
>>    // rotate
>>    if (this.InteractionMode == 1)
>>    {
>>      cam.Azimuth(lastX - x);
>>      cam.Elevation(y - lastY);
>>      cam.OrthogonalizeViewUp();
>>
>>      // ren.ResetCameraClippingRange();
>>      if (this.lightFollowsCamera)
>>      {
>>        light.SetPosition(cam.GetPosition());
>>        light.SetFocalPoint(cam.GetFocalPoint());
>>      }
>>    }
>>
>>    // translate
>>    if (this.InteractionMode == 2)
>>    {
>>      double  FPoint[];
>>      double  PPoint[];
>>      double  APoint[] = new double[3];
>>      double  RPoint[];
>>      double focalDepth;
>>
>>      // get the current focal point and position
>>      FPoint = cam.GetFocalPoint();
>>      PPoint = cam.GetPosition();
>>
>>      // calculate the focal depth since we'll be using it a lot
>>      ren.SetWorldPoint(FPoint[0],FPoint[1],FPoint[2],1.0);
>>      ren.WorldToDisplay();
>>      focalDepth = ren.GetDisplayPoint()[2];
>>
>>      APoint[0] = rw.GetSize()[0]/2.0 + (x - lastX);
>>      APoint[1] = rw.GetSize()[1]/2.0 - (y - lastY);
>>      APoint[2] = focalDepth;
>>      ren.SetDisplayPoint(APoint);
>>      ren.DisplayToWorld();
>>      RPoint = ren.GetWorldPoint();
>>      if (RPoint[3] != 0.0)
>>      {
>>        RPoint[0] = RPoint[0]/RPoint[3];
>>        RPoint[1] = RPoint[1]/RPoint[3];
>>        RPoint[2] = RPoint[2]/RPoint[3];
>>      }
>>
>>      /*
>>       * Compute a translation vector, moving everything 1/2
>>       * the distance to the cursor. (Arbitrary scale factor)
>>       */
>>      cam.SetFocalPoint(
>>        (FPoint[0]-RPoint[0])/2.0 + FPoint[0],
>>        (FPoint[1]-RPoint[1])/2.0 + FPoint[1],
>>        (FPoint[2]-RPoint[2])/2.0 + FPoint[2]);
>>      cam.SetPosition(
>>        (FPoint[0]-RPoint[0])/2.0 + PPoint[0],
>>        (FPoint[1]-RPoint[1])/2.0 + PPoint[1],
>>        (FPoint[2]-RPoint[2])/2.0 + PPoint[2]);
>>      // ren.ResetCameraClippingRange();
>>      }
>>    // zoom
>>    if (this.InteractionMode == 3)
>>    {
>>      double zoomFactor;
>>      double clippingRange[];
>>
>>      zoomFactor = Math.pow(1.02,(y - lastY));
>>
>>      if (cam.GetParallelProjection() == 1)
>>      {
>>        cam.SetParallelScale(cam.GetParallelScale()/zoomFactor);
>>      }
>>      else
>>      {
>>        cam.Dolly(zoomFactor);
>>        // ren.ResetCameraClippingRange();
>>      }
>>    }
>>
>>    lastX = x;
>>    lastY = y;
>>    this.repaint();
>>  }
>>
>>  public void keyTyped(KeyEvent e) {}
>>
>>  public void keyPressed(KeyEvent e)
>>  {
>>    if (ren.VisibleActorCount() == 0)
>>      return;
>>
>>    char keyChar = e.getKeyChar();
>>
>>    if ('r' == keyChar)
>>    {
>>      ren.ResetCamera();
>>      this.repaint();
>>    }
>>    
>>    if ('u' == keyChar)
>>    {
>>      vtkPicker picker = new vtkPicker();
>>      picker.Pick(lastX,700 - lastY,0.0,ren);
>>
>>    }
>>    
>>    if ('w' == keyChar)
>>    {
>>      vtkActorCollection ac;
>>      vtkActor anActor;
>>      vtkActor aPart;
>>      int i, j;
>>
>>      ac = ren.GetActors();
>>      ac.InitTraversal();
>>    
>>      for (i = 0; i < ac.GetNumberOfItems(); i++)
>>      {
>>        anActor = ac.GetNextActor();
>>        anActor.InitPartTraversal();
>>        for (j = 0; j < anActor.GetNumberOfParts(); j++)
>>        {
>>          aPart = anActor.GetNextPart();
>>          aPart.GetProperty().SetRepresentationToWireframe();
>>        }
>>      }
>>      /* schedule a paint in the 'refresh' thread rather than calling Render
>>       * here */
>>      this.repaint();
>>    }
>>    
>>    if ('s' == keyChar)
>>    {
>>      vtkActorCollection ac;
>>      vtkActor anActor;
>>      vtkActor aPart;
>>      int i, j;
>>
>>      ac = ren.GetActors();
>>      ac.InitTraversal();
>>      for (i = 0; i < ac.GetNumberOfItems(); i++)
>>      {
>>        anActor = ac.GetNextActor();
>>        anActor.InitPartTraversal();
>>        for (j = 0; j < anActor.GetNumberOfParts(); j++)
>>        {
>>          aPart = anActor.GetNextPart();
>>          aPart.GetProperty().SetRepresentationToSurface();
>>        }
>>      }
>>      this.repaint();
>>    }
>>  }
>>
>>  public void keyReleased(KeyEvent e) {}
>>
>>  public void addPropertyChangeListener(PropertyChangeListener l)
>>  {
>>    changes.addPropertyChangeListener(l);
>>  }
>>
>>  public void removePropertyChangeListener(PropertyChangeListener l)
>>  {
>>    changes.removePropertyChangeListener(l);
>>  }
>>
>>  protected PropertyChangeSupport changes = new PropertyChangeSupport(this);
>>}
>>





More information about the vtkusers mailing list