<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p><font face="Arial">Hello vtk users,</font></p>
<p><font face="Arial">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. <br>
</font></p>
<p><font face="Arial">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. <br>
</font></p>
<p><font face="Arial">Thanks for any suggestions,</font></p>
<p><font face="Arial">Jim<br>
</font></p>
<p><font face="Arial">Excerpt from Vector.class:</font><br>
</p>
/**<br>
* Returns the component at the specified index.<br>
*<br>
* <p>This method is identical in functionality to the
{@link #get(int)}<br>
* method (which is part of the {@link List} interface).<br>
*<br>
* @param index an index into this vector<br>
* @return the component at the specified index<br>
* @throws ArrayIndexOutOfBoundsException if the index is out of
range<br>
* ({@code index < 0 || index >= size()})<br>
*/<br>
public synchronized E elementAt(int index) {<br>
if (index >= elementCount) {<br>
throw new ArrayIndexOutOfBoundsException(index + " >=
" + elementCount);<br>
}<br>
<br>
return elementData(index);<br>
}<br>
<br>
--------------------------------------------------------------------------------------------------------------------------<br>
<br>
public class RenderWindowPanel extends vtkRenderWindowPanel {<br>
<br>
// Only relevant part of the class is shown...<br>
<br>
public void updateRenderWindowPanelYPosData(Object[] aObject) {<br>
this.xData = (vtkFloatArray) this.objectArrayXData[3];<br>
this.yData = (vtkFloatArray) this.objectArrayYData[4];<br>
<br>
this.table = new vtkTable();<br>
vtkDoubleArray arrX = new vtkDoubleArray();<br>
arrX.SetName("ArrayX");<br>
vtkDoubleArray arrY = new vtkDoubleArray();<br>
arrY.SetName("ArrayY");<br>
<br>
this.table.SetNumberOfRows(this.xData.GetNumberOfTuples());<br>
double tempx = 0;<br>
double tempy = 0;<br>
<br>
// Column 0<br>
for (int i = 0; i < this.xData.GetNumberOfTuples();
i++) {<br>
tempx = this.xData.GetValue(i);<br>
arrX.InsertNextTuple1(tempx); <br>
}<br>
this.table.AddColumn(arrX);<br>
<br>
// Column 1<br>
for (int i = 0; i < this.yData.GetNumberOfTuples();
i++) {<br>
tempy = this.yData.GetValue(i);<br>
arrY.InsertNextTuple1(tempy); <br>
}<br>
this.table.AddColumn(arrY);<br>
<br>
this.chart = new vtkChart();<br>
this.plot = new vtkPlot();<br>
this.chart.AddPlot(this.plot);<br>
// Note: also tried this.plot = this.chart.AddPlot(0);<br>
this.plot.SetColor(0.0, 0.0, 255.0);<br>
this.plot.SetWidth(1.0);<br>
this.plot.SetInputData(this.table, "ArrayX", "ArrayY");<br>
<br>
this.view = new vtkContextView();<br>
this.view.SetRenderWindow(this.GetRenderWindow());<br>
this.view.SetRenderer(this.renderer);<br>
this.view.GetRenderWindow().SetMultiSamples(0);<br>
this.view.GetScene().AddItem(this.chart);<br>
<br>
this.renderer.SetActiveCamera(this.camera);<br>
this.renderer.AddActor(this.textActor);<br>
this.renderer.SetBackground(255, 255, 255); // white<br>
this.renderer.ResetCamera();<br>
this.renderWindowInteractor = this.view.GetInteractor();<br>
this.view.GetInteractor().Initialize();<br>
this.view.GetInteractor().Start();<br>
<br>
try {<br>
this.Render();<br>
System.out.println("Debug break after render");<br>
} catch (Exception e) {<br>
e.printStackTrace();<br>
}<br>
<br>
}<br>
<br>
} <br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>