def Mesh2VTKUGrid(mesh): vtkcelltypes=((),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE,vtk.VTK_TRIANGLE,vtk.VTK_QUAD,vtk.VTK_POLYGON,vtk.VTK_POLYGON),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE,vtk.VTK_TRIANGLE,vtk.VTK_TETRA,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_HEXAHEDRON)) npoints=mesh.num_vertices() geom=mesh.geometry() pts=vtk.vtkPoints() pts.SetNumberOfPoints(npoints) for i in xrange(npoints): p=geom.point(i) pts.SetPoint(i,p.x(),p.y(),p.z()) dim = mesh.topology().dim() ncells=mesh.num_cells() cells=vtk.vtkCellArray() cellTypes=vtk.vtkUnsignedCharArray() cellTypes.SetNumberOfTuples(ncells) cellLocations=vtk.vtkIdTypeArray() cellLocations.SetNumberOfTuples(ncells) loc=0 for (cell,i) in zip(mesh.cells(),xrange(ncells)) : ncellpoints=len(cell) cells.InsertNextCell(ncellpoints) for cpoint in cell: cells.InsertCellPoint(cpoint) cellTypes.SetTuple1(i,vtkcelltypes[dim][ncellpoints]) cellLocations.SetTuple1(i,loc) loc+=1+ncellpoints ugrid = vtk.vtkUnstructuredGrid() ugrid.SetPoints(pts) ugrid.SetCells(cellTypes,cellLocations,cells) return ugrid
def Mesh2VTKUGrid(mesh): vtkcelltypes=((),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE,vtk.VTK_TRIANGLE,vtk.VTK_QUAD,vtk.VTK_POLYGON,vtk.VTK_POLYGON),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE,vtk.VTK_TRIANGLE,vtk.VTK_TETRA,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_HEXAHEDRON)) npoints=mesh.num_vertices() geom=mesh.geometry() pts=vtk.vtkPoints() pts.SetNumberOfPoints(npoints) for i in xrange(npoints): p=geom.point(i) pts.SetPoint(i,p.x(),p.y(),p.z()) dim = mesh.topology().dim() ncells=mesh.num_cells() cells=vtk.vtkCellArray() cellTypes=vtk.vtkUnsignedCharArray() cellTypes.SetNumberOfTuples(ncells) cellLocations=vtk.vtkIdTypeArray() cellLocations.SetNumberOfTuples(ncells) loc=0 for (cell,i) in zip(mesh.cells(),xrange(ncells)) : ncellpoints=len(cell) cells.InsertNextCell(ncellpoints) for cpoint in cell: cells.InsertCellPoint(cpoint) cellTypes.SetTuple1(i,vtkcelltypes[dim][ncellpoints]) cellLocations.SetTuple1(i,loc) loc+=1+ncellpoints ugrid = vtk.vtkUnstructuredGrid() ugrid.SetPoints(pts) ugrid.SetCells(cellTypes,cellLocations,cells) return ugrid