[vtkusers] set scalar component in a vtkImageData using only the point ID

Luca Penasa luca.penasa at gmail.com
Mon May 2 14:49:45 EDT 2011


I see that vtkImageData class permits to set the scalar component using
the SetScalarComponentFrom* methods. Those methods require position (as
integers values) of the voxel for which i want to set the scalar value
(and id of scalar component too). 
Does anybody know if it is possible to set the scalar component using
only the point id?

I mean:

i have my vtkImageData 'image' and i want to set as scalar component a
random number for every voxel, i was wondering if i could write code
like that:

scalar_component_id = 0
for point_id in range(image.GetNumberOfPoints()):
	image.SetScalarComponentFromFloat(point_id, scalar_component_id,
randn())


This problem has occuoured trying to write a function for converting an
UnstructuredGrid to vtkImage.


A function of this type would, for every point/voxel in the image:
- take the voxel position using xyz = image.GetPoint(point_id)
- determinate the nearest neighbor for those coordinates in another
DataSet (the vtkUnstructuredGrid)
- and then populate the ScalarComponent of the image with the value of
an array of the unstructured grid, taking the nearest neighbor point.

the problem is that when i have the value which i want to use as scalar
component i dont know how to set it into my image, using only the point
ID.
Is there a way to get the voxel coordinates (as image's coordinates -
integers -)?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110502/31dc139f/attachment.htm>


More information about the vtkusers mailing list