[vtkusers] RE: convert vtkRectilinearGrid to vtkStructuredGrid

Berk Geveci berk.geveci at kitware.com
Fri May 11 13:27:11 EDT 2001

> The key fact that I was missing is that vtkRectilinearGrid is
> conceptually a sub-class of vtkStructuredGrid. It is just not
> implemented that way (why???).

	Efficiency. Space. vtkRectilinearGrid uses less memory
	and is faster. Otherwise there would be no reason why a separate
	class for rectilinear grid should exist. If you don't care
	about these, you can use vtkStructuredGrid instead.
> The conversion from the specialized type (vtkRectilinearGrid) to the
> more general type (vtkStructuredGrid) is straight forward (although not
> as straight forward as it would be if the hierarchy was done right). The
> trick is to somehow get the data out of the vtkRectilinearGrid in the
> form of vtkPoints so that you can call vtkStructuredGrid::SetPoints().

	You will have to compute all the points yourself. You can get the
	points along each axis of the rectilinear grid with 
	GetXCoordinates(), GetYCoordinates() ... Afterwards, you need
	to generate the points using these. As an alternative, you
	can use vtkRectilinearGridGeometryFilter to do this. Here is
	an example:

vtkFloatArray co
co SetNumberOfTuples 3
co SetValue 0 0.5
co SetValue 1 2.0
co SetValue 2 5.0

vtkRectilinearGrid rg
rg SetDimensions 3 3 3
rg SetXCoordinates co
rg SetYCoordinates co
rg SetZCoordinates co

vtkRectilinearGridGeometryFilter rggf
rggf SetInput rg
rggf Update

puts stdout [[rggf GetOutput] GetNumberOfPoints]
puts stdout [[rggf GetOutput] GetPoint 5]

	However note that this filter generates polydata. You will have to
	get the points from this and put them into a vtkStructuredGrid.
	A filter to convert rectilinear grid to structured grid would be 
	somewhat useful. Maybe someone will add it in the future.


More information about the vtkusers mailing list