本文整理汇总了Python中vtk.vtkXMLPolyDataWriter方法的典型用法代码示例。如果您正苦于以下问题:Python vtk.vtkXMLPolyDataWriter方法的具体用法?Python vtk.vtkXMLPolyDataWriter怎么用?Python vtk.vtkXMLPolyDataWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vtk
的用法示例。
在下文中一共展示了vtk.vtkXMLPolyDataWriter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _write_vtp
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkXMLPolyDataWriter [as 别名]
def _write_vtp(self):
'''Internal function to write VTK PolyData mesh files
'''
if self.VTK_installed is False:
raise VTK_Exception('VTK must be installed write VTP/VTK meshes, please select a different output mesh_format')
writer = vtk.vtkXMLPolyDataWriter()
writer.SetFileName(self.files['vtp'])
if vtk.VTK_MAJOR_VERSION >= 6:
writer.SetInputData(self.vtp_mesh)
else:
writer.SetInput(self.vtp_mesh)
writer.SetDataModeToAscii()
writer.Write()
print 'Wrote VTK PolyData mesh to: ' + str(self.files['vtp'])
示例2: save_vtk
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkXMLPolyDataWriter [as 别名]
def save_vtk(filename, tracts, lines_indices=None, scalars = None):
lengths = [len(p) for p in tracts]
line_starts = ns.numpy.r_[0, ns.numpy.cumsum(lengths)]
if lines_indices is None:
lines_indices = [ns.numpy.arange(length) + line_start for length, line_start in izip(lengths, line_starts)]
ids = ns.numpy.hstack([ns.numpy.r_[c[0], c[1]] for c in izip(lengths, lines_indices)])
vtk_ids = ns.numpy_to_vtkIdTypeArray(ids, deep=True)
cell_array = vtk.vtkCellArray()
cell_array.SetCells(len(tracts), vtk_ids)
points = ns.numpy.vstack(tracts).astype(ns.get_vtk_to_numpy_typemap()[vtk.VTK_DOUBLE])
points_array = ns.numpy_to_vtk(points, deep=True)
poly_data = vtk.vtkPolyData()
vtk_points = vtk.vtkPoints()
vtk_points.SetData(points_array)
poly_data.SetPoints(vtk_points)
poly_data.SetLines(cell_array)
poly_data.BuildCells()
if filename.endswith('.xml') or filename.endswith('.vtp'):
writer = vtk.vtkXMLPolyDataWriter()
writer.SetDataModeToBinary()
else:
writer = vtk.vtkPolyDataWriter()
writer.SetFileTypeToBinary()
writer.SetFileName(filename)
if hasattr(vtk, 'VTK_MAJOR_VERSION') and vtk.VTK_MAJOR_VERSION > 5:
writer.SetInputData(poly_data)
else:
writer.SetInput(poly_data)
writer.Write()
示例3: save_vtk_labels
# 需要导入模块: import vtk [as 别名]
# 或者: from vtk import vtkXMLPolyDataWriter [as 别名]
def save_vtk_labels(filename, tracts, scalars, lines_indices=None):
lengths = [len(p) for p in tracts]
line_starts = ns.numpy.r_[0, ns.numpy.cumsum(lengths)]
if lines_indices is None:
lines_indices = [ns.numpy.arange(length) + line_start for length, line_start in izip(lengths, line_starts)]
ids = ns.numpy.hstack([ns.numpy.r_[c[0], c[1]] for c in izip(lengths, lines_indices)])
vtk_ids = ns.numpy_to_vtkIdTypeArray(ids, deep=True)
cell_array = vtk.vtkCellArray()
cell_array.SetCells(len(tracts), vtk_ids)
points = ns.numpy.vstack(tracts).astype(ns.get_vtk_to_numpy_typemap()[vtk.VTK_DOUBLE])
points_array = ns.numpy_to_vtk(points, deep=True)
poly_data = vtk.vtkPolyData()
vtk_points = vtk.vtkPoints()
vtk_points.SetData(points_array)
poly_data.SetPoints(vtk_points)
poly_data.SetLines(cell_array)
poly_data.GetPointData().SetScalars(ns.numpy_to_vtk(scalars))
poly_data.BuildCells()
# poly_data.SetScalars(scalars)
if filename.endswith('.xml') or filename.endswith('.vtp'):
writer = vtk.vtkXMLPolyDataWriter()
writer.SetDataModeToBinary()
else:
writer = vtk.vtkPolyDataWriter()
writer.SetFileTypeToBinary()
writer.SetFileName(filename)
if hasattr(vtk, 'VTK_MAJOR_VERSION') and vtk.VTK_MAJOR_VERSION > 5:
writer.SetInputData(poly_data)
else:
writer.SetInput(poly_data)
writer.Write()