Quantcast

VTK JAVA 2D charts

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

VTK JAVA 2D charts

Jim Labiak

Hello vtk users,

I've been trying to use the JAVA VTK chart class to create 2D plots, but it is not working. The JRE crashes every time at the spot where the plot is added to the chart. During debugging, I trace the crash to the JAVA Vector.class at line 477 (method directly below), which is the return statement... I've extended vtkRenderWindowPanel and use that class to do my rendering as it seemed to be the most robust approach for my application. Only a portion of the code from that class is shown below.

The JAVA wrapper is known to be difficult to learn, but 2D charts really must work for this (vtk) to be a viable JAVA program. I could create 3D charts and make them look 2D, but it seems like I must be missing something in the 2D charts... I don't see "test" programs in the documentation for this class (vtkChart) and related ones in JAVA - was this ever tested during development, and anyone know how extensively? Or, is the wrapper just kind of generated and then exists "as-is"? Some of the statements required and shown in other language examples are difficult to translate into JAVA accurately.

Thanks for any suggestions,

Jim

Excerpt from Vector.class:

    /**
     * Returns the component at the specified index.
     *
     * <p>This method is identical in functionality to the {@link #get(int)}
     * method (which is part of the {@link List} interface).
     *
     * @param      index   an index into this vector
     * @return     the component at the specified index
     * @throws ArrayIndexOutOfBoundsException if the index is out of range
     *         ({@code index < 0 || index >= size()})
     */
    public synchronized E elementAt(int index) {
        if (index >= elementCount) {
            throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
        }

        return elementData(index);
    }

--------------------------------------------------------------------------------------------------------------------------

public class RenderWindowPanel extends vtkRenderWindowPanel {

// Only relevant part of the class is shown...

public void updateRenderWindowPanelYPosData(Object[] aObject) {
    this.xData = (vtkFloatArray) this.objectArrayXData[3];
    this.yData = (vtkFloatArray) this.objectArrayYData[4];

        this.table = new vtkTable();
        vtkDoubleArray arrX = new vtkDoubleArray();
        arrX.SetName("ArrayX");
        vtkDoubleArray arrY = new vtkDoubleArray();
        arrY.SetName("ArrayY");
       
        this.table.SetNumberOfRows(this.xData.GetNumberOfTuples());
            double tempx = 0;
            double tempy = 0;
           
            // Column 0
            for (int i = 0; i < this.xData.GetNumberOfTuples(); i++) {
                tempx = this.xData.GetValue(i);
                arrX.InsertNextTuple1(tempx);   
            }
            this.table.AddColumn(arrX);
           
            // Column 1
            for (int i = 0; i < this.yData.GetNumberOfTuples(); i++) {
                tempy = this.yData.GetValue(i);
                arrY.InsertNextTuple1(tempy);   
            }
            this.table.AddColumn(arrY);
       
        this.chart = new vtkChart();
        this.plot = new vtkPlot();
        this.chart.AddPlot(this.plot);
        // Note: also tried this.plot = this.chart.AddPlot(0);
        this.plot.SetColor(0.0, 0.0, 255.0);
        this.plot.SetWidth(1.0);
        this.plot.SetInputData(this.table, "ArrayX", "ArrayY");
       
        this.view = new vtkContextView();
        this.view.SetRenderWindow(this.GetRenderWindow());
        this.view.SetRenderer(this.renderer);
        this.view.GetRenderWindow().SetMultiSamples(0);
        this.view.GetScene().AddItem(this.chart);
                       
        this.renderer.SetActiveCamera(this.camera);
        this.renderer.AddActor(this.textActor);
        this.renderer.SetBackground(255, 255, 255); // white
        this.renderer.ResetCamera();
        this.renderWindowInteractor = this.view.GetInteractor();
        this.view.GetInteractor().Initialize();
        this.view.GetInteractor().Start();
           
        try {
            this.Render();
            System.out.println("Debug break after render");
        } catch (Exception e) {
            e.printStackTrace();
        }
       
}

}       
       





_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: VTK JAVA 2D charts

Jim Labiak

Just sending again in case I catch a Java user...


On 3/18/2017 2:40 PM, Jim Labiak wrote:

Hello vtk users,

I've been trying to use the JAVA VTK chart class to create 2D plots, but it is not working. The JRE crashes every time at the spot where the plot is added to the chart. During debugging, I trace the crash to the JAVA Vector.class at line 477 (method directly below), which is the return statement... I've extended vtkRenderWindowPanel and use that class to do my rendering as it seemed to be the most robust approach for my application. Only a portion of the code from that class is shown below.

The JAVA wrapper is known to be difficult to learn, but 2D charts really must work for this (vtk) to be a viable JAVA program. I could create 3D charts and make them look 2D, but it seems like I must be missing something in the 2D charts... I don't see "test" programs in the documentation for this class (vtkChart) and related ones in JAVA - was this ever tested during development, and anyone know how extensively? Or, is the wrapper just kind of generated and then exists "as-is"? Some of the statements required and shown in other language examples are difficult to translate into JAVA accurately.

Thanks for any suggestions,

Jim

Excerpt from Vector.class:

    /**
     * Returns the component at the specified index.
     *
     * <p>This method is identical in functionality to the {@link #get(int)}
     * method (which is part of the {@link List} interface).
     *
     * @param      index   an index into this vector
     * @return     the component at the specified index
     * @throws ArrayIndexOutOfBoundsException if the index is out of range
     *         ({@code index < 0 || index >= size()})
     */
    public synchronized E elementAt(int index) {
        if (index >= elementCount) {
            throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
        }

        return elementData(index);
    }

--------------------------------------------------------------------------------------------------------------------------

public class RenderWindowPanel extends vtkRenderWindowPanel {

// Only relevant part of the class is shown...

public void updateRenderWindowPanelYPosData(Object[] aObject) {
    this.xData = (vtkFloatArray) this.objectArrayXData[3];
    this.yData = (vtkFloatArray) this.objectArrayYData[4];

        this.table = new vtkTable();
        vtkDoubleArray arrX = new vtkDoubleArray();
        arrX.SetName("ArrayX");
        vtkDoubleArray arrY = new vtkDoubleArray();
        arrY.SetName("ArrayY");
       
        this.table.SetNumberOfRows(this.xData.GetNumberOfTuples());
            double tempx = 0;
            double tempy = 0;
           
            // Column 0
            for (int i = 0; i < this.xData.GetNumberOfTuples(); i++) {
                tempx = this.xData.GetValue(i);
                arrX.InsertNextTuple1(tempx);   
            }
            this.table.AddColumn(arrX);
           
            // Column 1
            for (int i = 0; i < this.yData.GetNumberOfTuples(); i++) {
                tempy = this.yData.GetValue(i);
                arrY.InsertNextTuple1(tempy);   
            }
            this.table.AddColumn(arrY);
       
        this.chart = new vtkChart();
        this.plot = new vtkPlot();
        this.chart.AddPlot(this.plot);
        // Note: also tried this.plot = this.chart.AddPlot(0);
        this.plot.SetColor(0.0, 0.0, 255.0);
        this.plot.SetWidth(1.0);
        this.plot.SetInputData(this.table, "ArrayX", "ArrayY");
       
        this.view = new vtkContextView();
        this.view.SetRenderWindow(this.GetRenderWindow());
        this.view.SetRenderer(this.renderer);
        this.view.GetRenderWindow().SetMultiSamples(0);
        this.view.GetScene().AddItem(this.chart);
                       
        this.renderer.SetActiveCamera(this.camera);
        this.renderer.AddActor(this.textActor);
        this.renderer.SetBackground(255, 255, 255); // white
        this.renderer.ResetCamera();
        this.renderWindowInteractor = this.view.GetInteractor();
        this.view.GetInteractor().Initialize();
        this.view.GetInteractor().Start();
           
        try {
            this.Render();
            System.out.println("Debug break after render");
        } catch (Exception e) {
            e.printStackTrace();
        }
       
}

}       
       






_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Loading...