[vtkusers] Sum: getting double precision coordinates in vtkPoints (Java)

Karin Faulhaber faulhaber at ipf.uni-karlsruhe.de
Fri Jun 29 13:38:26 EDT 2001


Hi, I'm posting this in case sometime somebody has the same problem:

- If you have double precision coordinates you want to store in a
vtkPoints object and
- if you are using vtk (3.1) with java (where you don't have all of the
methods you have in 	the C++ classes)
the following code snippets are the solution.

Karin


------------
1. Create a vtkDoubleArray with three components and the correct number
of tuples:

       vtkDoubleArray da = new vtkDoubleArray();
       da.SetNumberOfComponents(3);
       da.SetNumberOfTuples(numberOfPoints);


2. Fill this array with values:

	double x1, y1, z1, x2, y2, z2 
	...
    	da.SetValue(0, x1);
	da.SetValue(1, y1);
	da.SetValue(2, z1);    	
	da.SetValue(3, x2);
	da.SetValue(4, y2);
	da.SetValue(5, z2);
	...


3. Create a vtkPoints object, set the number of components to 3 and fill
it with the array:

	vtkPoints coordinates = new vtkPoints();
	coordinates.GetData().SetNumberOfComponents(3);
	coordinates.SetData(da);


4. You can get the correct double precision numbers from the vtkPoints
object with the following line:

	double xOut = ((vtkDoubleArray)(coordinates[0].GetData())).GetValue(0);
	etc.


The following line doesn't seem to be necessary:

	coordinates.SetDataTypeToDouble();




-- 
Karin Faulhaber
Universitaet Karlsruhe
Institut fuer Photogrammetrie und Fernerkundung (IPF)
Englerstr. 7 
76128 Karlsruhe

Tel: 0721/608-3676
E-Mail: faulhaber at ipf.uni-karlsruhe.de




More information about the vtkusers mailing list