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