[vtkusers] Question on the usage of vtkPanel with Java

TINGAUD Frederic Frederic.TINGAUD at murex.com
Mon Oct 15 09:00:13 EDT 2012


Hi all,

 

I am trying to use the vtkPanel for Java on Windows, to create a simple
test. I use the code you can see thereafter. You can notice a commented
out panel.Render(). While it is commented out, the code works well, but
the resulting graph will have ugly aliasing. If I uncomment the
panel.Render() that is just before setting my JFrame to visible, two
differences will be visible:

-          The graph is way nicer, with smooth edges and faster drawings
(I see it when doing time consuming operations like multiple AAFrames).

-          One time out of 10, I will have a "ChoosePixelFormat failed"
error and the application will crash.

 

I assume that calling CreateWindow from vtkWin32OpenGLRenderWindow.cxx
achieves way better results than letting Java do it, but I am wondering
whether it is possible to obtain the same nice rendering while letting
the JFrame do the win32 call and if I can protect myself in any way
against the choosePixelFormat error?

 

Regards,

 

Frederic

 

package murex.gui.component.chart3d;

 

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;

 

public class minimalTest {

    // 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());

        renderer.AddActor(cubeAxesActor);

 

        renderer.ResetCamera();

        mainFrame.add(panel);

        mainFrame.setSize(600, 600);

//        panel.Render();

        mainFrame.setVisible(true);

        panel.Render();

    }

 

    /**

     * @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;

    }

}

 

*******************************

This e-mail contains information for the intended recipient only. It may contain proprietary material or confidential information. If you are not the intended recipient you are not authorised to distribute, copy or use this e-mail or any attachment to it. Murex cannot guarantee that it is virus free and accepts no responsibility for any loss or damage arising from its use. If you have received this e-mail in error please notify immediately the sender and delete the original email received, any attachments and all copies from your system.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121015/6f61d0ef/attachment.htm>


More information about the vtkusers mailing list