[vtkusers] Use of vtkCellArray's InsertNextCell method from java
Julian Ibarz
julian.ibarz at gmail.com
Tue Jun 17 03:55:18 EDT 2008
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 :
int[] array=...;
vtkIntArray intArray = new vtkIntArray();
for(int i = 0 ; i < array.length ; ++i)
intArray.SetValue(i, array[i]); // We go to native world array.length
time
It will be very much slower than :
int[] array=...;
vtkIntArray intArray = new vtkIntArray();
intArray.SetJavaArray(array); // We go to native world one time
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.
But I agree with you it would have been simplifier if the SetJavaArray
method for vtkIdTypeArray existed... but it's not the case :).
/** Create a vtkPoints array from doubles */
public static vtkPoints createPoints(double[] points)
{
vtkPoints vtkPoints = new vtkPoints();
vtkDoubleArray d = new vtkDoubleArray();
d.SetJavaArray(points);
d.SetNumberOfComponents(3);
vtkPoints.SetData(d);
return vtkPoints;
}
/**
* Create an index array for beams to be used as input from createCells
* change {a, b, c, d} to {2, a, b, 2, c, d}
*/
public static int[] createBeamCells(int[] beams)
{
int numberOfBeam = beams.length / 2;
int k = 0;
int j = 0;
int[] fCells = new int[3 * numberOfBeam];
for (int i = 0; i < numberOfBeam; i++)
{
fCells[k++] = 2;
fCells[k++] = beams[j++];
fCells[k++] = beams[j++];
}
return fCells;
}
}
/** Create an index array for triangles to be used as input from
createCells */
public static int[] createTriangleCells(int[] cells, int offSetID)
{
int k = 0;
int nCell = cells.length / 3;
int[] fCells = new int[nCell * 4];
for (int i = 0; i < nCell * 3; i += 3)
{
fCells[k++] = 3;
fCells[k++] = cells[i] + offSetID;
fCells[k++] = cells[i + 1] + offSetID;
fCells[k++] = cells[i + 2] + offSetID;
}
return fCells;
}
/** Create a vtkCellArray from indexes */
public static vtkCellArray createCells(int cellNumber, int[] cells)
{
vtkCellArray vtkCells = new vtkCellArray();
vtkIdTypeArray array = new vtkIdTypeArray();
vtkIntArray intArray = new vtkIntArray();
intArray.SetJavaArray(cells);
array.DeepCopy(intArray);
vtkCells.SetCells(cellNumber, array);
return vtkCells;
}
public static int[] getValues(vtkIdTypeArray idarray)
{
vtkIntArray iarray = new vtkIntArray();
iarray.DeepCopy(idarray);
return iarray.GetJavaArray();
}
public static vtkIdTypeArray setValues(int[] values)
{
vtkIntArray iarray = new vtkIntArray();
iarray.SetJavaArray(values);
vtkIdTypeArray array = new vtkIdTypeArray();
array.DeepCopy(iarray);
System.out.println("values : " + values.length);
System.out.println("iarray : " + array.GetNumberOfTuples());
return array;
}
Example of use :
int[] indicesBeams = ...;
int[] indicesTriangles = ...;
vtkPolyData data = new vtkPolyData();
data.SetPoints(Utils.createPoints(dataProvider.getNodes()));
data.SetLines(Utils.createCells(indiceBeams.length / 2,
Utils.createBeamCells(indiceBeams));
data.SetPolys(Utils.createCells(indicesTriangles.length / 3,
Utils.createTriangleCells(indicesTriangles, 0)));
2008/6/17 Phil Goddard <philgoddard at telus.net>:
>
> I'm trying to visualize some planes in 3D space (e.g. 8 such planes
> appropriately oriented would look like a cube) and had been planning on
> using the InsertNextCell method of vtkCellArray in conjunction with
> vtkStructuredGrid.
> However it seems that the java wrappers do no implement this method (which
> requires a vtkTypeId as the input data type).
>
> Can anyone confirm the non implementation of this method for me (or perhaps
> I'm just misusing it).
> And if so, recommend another approach?
>
> Much appreciated.
> Phil.
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
--
Julian Ibarz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080617/841186d2/attachment.htm>
More information about the vtkusers
mailing list