In the end of the mail I put the utilities functions I made to use vtkCellArray and vtkIdTypeArray simplier in Java. You can see in setValue and getValue I make a copy of the int[] java array in a vtkIntArray and
make a deep copy of that. Why I do that ? Because the change into java "world" and native "world" is very slow so if I make that :<br><br>int[] array=...;<br>vtkIntArray intArray = new vtkIntArray();<br>
for(int i = 0 ; i < array.length ; ++i)<br> intArray.SetValue(i, array[i]); // We go to native world array.length time<br><br>It will be very much slower than :<br><br>int[] array=...;<br>
vtkIntArray intArray = new vtkIntArray();<br>
intArray.SetJavaArray(array); // We go to native world one time<br>
<br>So it is better to make a temporary copy of the array and send id to the native world than not making copy and going to the native world for each element.<br><br>But I agree with you it would have been simplifier if the SetJavaArray method for vtkIdTypeArray existed... but it's not the case :).<br>
<br>/** Create a vtkPoints array from doubles */<br> public static vtkPoints createPoints(double[] points)<br> {<br> vtkPoints vtkPoints = new vtkPoints();<br> vtkDoubleArray d = new vtkDoubleArray();<br>
d.SetJavaArray(points);<br> d.SetNumberOfComponents(3);<br> vtkPoints.SetData(d);<br> return vtkPoints;<br> }<br><br> /**<br> * Create an index array for beams to be used as input from createCells<br>
* change {a, b, c, d} to {2, a, b, 2, c, d}<br> */<br> public static int[] createBeamCells(int[] beams)<br> {<br> int numberOfBeam = beams.length / 2;<br> int k = 0;<br> int j = 0;<br> int[] fCells = new int[3 * numberOfBeam];<br>
for (int i = 0; i < numberOfBeam; i++)<br> {<br> fCells[k++] = 2;<br> fCells[k++] = beams[j++];<br> fCells[k++] = beams[j++];<br> }<br> return fCells;<br> }<br>
<br> }<br> /** Create an index array for triangles to be used as input from createCells */<br> public static int[] createTriangleCells(int[] cells, int offSetID)<br> {<br> int k = 0;<br> int nCell = cells.length / 3;<br>
int[] fCells = new int[nCell * 4];<br> for (int i = 0; i < nCell * 3; i += 3)<br> {<br> fCells[k++] = 3;<br> fCells[k++] = cells[i] + offSetID;<br> fCells[k++] = cells[i + 1] + offSetID;<br>
fCells[k++] = cells[i + 2] + offSetID;<br> }<br> return fCells;<br> }<br><br> /** Create a vtkCellArray from indexes */<br> public static vtkCellArray createCells(int cellNumber, int[] cells)<br>
{<br> vtkCellArray vtkCells = new vtkCellArray();<br> vtkIdTypeArray array = new vtkIdTypeArray();<br> vtkIntArray intArray = new vtkIntArray();<br> intArray.SetJavaArray(cells);<br> array.DeepCopy(intArray);<br>
vtkCells.SetCells(cellNumber, array);<br> return vtkCells;<br> }<br><br><br> public static int[] getValues(vtkIdTypeArray idarray)<br> {<br> vtkIntArray iarray = new vtkIntArray();<br> iarray.DeepCopy(idarray);<br>
return iarray.GetJavaArray();<br> }<br><br> public static vtkIdTypeArray setValues(int[] values)<br> {<br> vtkIntArray iarray = new vtkIntArray();<br> iarray.SetJavaArray(values);<br> vtkIdTypeArray array = new vtkIdTypeArray();<br>
array.DeepCopy(iarray);<br><br> System.out.println("values : " + values.length);<br> System.out.println("iarray : " + array.GetNumberOfTuples());<br><br> return array;<br> }<br>
<br>Example of use :<br><br>int[] indicesBeams = ...;<br>int[] indicesTriangles = ...;<br>vtkPolyData data = new vtkPolyData();<br> data.SetPoints(Utils.createPoints(dataProvider.getNodes()));<br> data.SetLines(Utils.createCells(indiceBeams.length / 2, Utils.createBeamCells(indiceBeams));<br>
data.SetPolys(Utils.createCells(indicesTriangles.length / 3, Utils.createTriangleCells(indicesTriangles, 0)));<br><div class="gmail_quote">2008/6/17 Phil Goddard <<a href="mailto:philgoddard@telus.net">philgoddard@telus.net</a>>:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
I'm trying to visualize some planes in 3D space (e.g. 8 such planes<br>
appropriately oriented would look like a cube) and had been planning on<br>
using the InsertNextCell method of vtkCellArray in conjunction with<br>
vtkStructuredGrid.<br>
However it seems that the java wrappers do no implement this method (which<br>
requires a vtkTypeId as the input data type).<br>
<br>
Can anyone confirm the non implementation of this method for me (or perhaps<br>
I'm just misusing it).<br>
And if so, recommend another approach?<br>
<br>
Much appreciated.<br>
Phil.<br>
<br>
<br>
_______________________________________________<br>
This is the private VTK discussion list.<br>
Please keep messages on-topic. Check the FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Julian Ibarz