[vtkusers] vtkUnstructuredGrid to vtkImageData

Luca Penasa luca.penasa at gmail.com
Mon Apr 11 05:16:36 EDT 2011


Hi everybody, 
i have a vtkUnstructuredGrid that comes from a terrestrial laserscanner
aquisition.
I would like to form a vtkImageData object projecting the points onto a
user defined plane, using some of the point data as scalar value.

For doing that i think i can use something like this (in python):

def Grid2vtkImageData(grid, delta = 1):
	#get infos on grid position/rotation
	x,y,z = grid.Getxyz().T   # <---  Those are some additional methods i
wrote for the vtkUnstructuredGridObjects
	normal = BestFitPlaneEig(x,y,z)
	
	#best view axis
	ax = np.abs(normal) == np.max(np.abs(normal)) * 1 
	
	#if it is not the x axis, rotate the cloud
	if (ax == [0,1,0]).any():
		grid.RotateZ(90) 
		
	elif (ax == [0,0,1]).any():
		grid.RotateY(90)
		
	### NOW the cloud is viewed from X-axis
	#infos on bounds etc
	minx, maxx, miny, maxy, minz, maxz = grid.GetBounds()
	deltay = maxy - miny
	y_dimension = int(np.fix(deltay/delta) + 1)
	
	deltaz = maxz - minz
	z_dimension = int(np.fix(deltaz/delta) + 1)
	
	#Create the imagedata object
	image = vtk.vtkImageData()
	image.SetScalarTypeToFloat()
	image.SetDimensions([y_dimension,z_dimension,1])
	image.SetOrigin(miny, minz, 0)
	image.SetSpacing(delta, delta, 1)
	image.AllocateScalars()
	return image


At this point i have encountered 2 problems:

1. i need to fast-locate the points within the pixel/voxel. Is there any
conveninet way for doing that? I could use a vtkKDTree, but i would need
something like a "FindPointsWithinBox" function :-)

2. I would cycle through all the pixels, but i think that for big
datasets this will be too slow (in pure python....). Any other chance??

I could use the ProjectPoint function of vtkPlane for projecting all
points onto my specified plane. But the problem of structurating the
dataset is not solved in this way, neither the problem of locating
points inside pixels.

same sage advice???


Thank you


-- 
---------------------------
Luca Penasa
Student at Geosciences Dpt.
University of Padua (IT)
luca.penasa at email.it
---------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110411/672cc8d8/attachment.htm>


More information about the vtkusers mailing list