[vtkusers] vtkUnstructuredGrid and vtkCellArray
Helvin Lui
helvinlui at gmail.com
Sun Aug 23 02:51:03 EDT 2009
I'm gonna cry soon if I don't get this done. > <
I have a .txt file of points and connectivity data. How do I read this in as
an unstructuredGrid?
How do I use vtkCellArray?
At the moment, I have this:
with open('C:\\Qt\\SimLCM\\Default\\Data_Input_Geometry.txt', 'r') as f:
#with open('C:\\Qt\\SimLCM\\Default\\Data_Input_Geometry_trial2.txt', 'r')
as f:
meshPoints = vtk.vtkPoints()
# Can't use voxels, because they specify corners that are perpendicular
# Get number of points
no_points = f.readline()
no_points = int(no_points)
print no_points # Check reading
# Set number of points in mesh
meshPoints.SetNumberOfPoints(no_points)
for i in range(no_points):
# Get coord info for each point
point_info = f.readline().split() # I need to split, before I assign
to point_coord
# else the whole thing is split
into single numbers
#print point_info # Check reading
point_ID = (int(point_info[0])-1) # -1 because the IDs need to start
with 0.
point_x = float(point_info[1])
point_y = float(point_info[2])
point_z = float(point_info[3])
print point_ID, point_x, point_y, point_z
# Set coord info in mesh
meshPoints.InsertPoint(point_ID, point_x, point_y, point_z)
# Don't need the input file anymore. Get on with the display
aMeshGrid = vtk.vtkUnstructuredGrid()
aMeshGrid.Allocate(180,1)
cellTypes = vtk.vtkCellTypes()
aMeshGrid.InsertNextCell(cellTypes,[1,2,13])
aMeshGrid.SetPoints(meshPoints)
etc...
But this second last line gives an error saying: TypeError: An Integer is
required.
PLEASE help! Please...
--
Helvin
"Though the world may promise me more, I'm just made to be filled with the
Lord."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090823/b558f1f1/attachment.htm>
More information about the vtkusers
mailing list