本文整理汇总了Python中vtk.vtkXMLImageDataWriter函数的典型用法代码示例。如果您正苦于以下问题:Python vtkXMLImageDataWriter函数的具体用法?Python vtkXMLImageDataWriter怎么用?Python vtkXMLImageDataWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkXMLImageDataWriter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_vtk
def write_vtk(self, DX=2.0, DY=2.0, DZ=0.05):
"""Reads cell data from vals array and writes into a VTK file called
'Stratal_Arch.vti' and is a structure grid object. Spacing defaults
are 2.0/2.0/0.05"""
vtk_obj = vtkImageData()
vtk_obj.SetSpacing(DX, DY, DZ)
vtk_obj.SetDimensions(self.dims[0]+1, self.dims[1]+1, self.dims[2]+1)
# Start writing from the top of the object to match output from Eclipse
vtk_obj.SetOrigin(0, 0, self.dims[2]+1)
array = vtkIntArray()
array.SetName("Stratal Architecture")
array.SetNumberOfComponents(1)
for z in range(0, self.dims[2]):
for y in range(0, self.dims[1]):
for x in range(0, self.dims[0]):
val = self.vals[x][y][z]
array.InsertNextTuple1(val)
vtk_obj.GetCellData().AddArray(array)
vtk_f = vtkXMLImageDataWriter()
vtk_f.SetFileName("Stratal_Arch.vti")
vtk_f.SetInputData(vtk_obj)
vtk_f.Write()
示例2: dicom_to_vti
def dicom_to_vti(imagedata, filename):
logging.debug("In data.dicom_to_vti()")
extent = imagedata.GetWholeExtent()
spacing = imagedata.GetSpacing()
origin = imagedata.GetOrigin()
center = (
origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]),
origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]),
origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]),
)
resliceAxes = vtk.vtkMatrix4x4()
vtkMatrix = (1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
resliceAxes.DeepCopy(vtkMatrix)
resliceAxes.SetElement(0, 3, center[0])
resliceAxes.SetElement(1, 3, center[1])
resliceAxes.SetElement(2, 3, center[2])
reslice = vtk.vtkImageReslice()
reslice.SetInput(imagedata)
reslice.SetInformationInput(imagedata)
reslice.SetResliceAxes(resliceAxes)
reslice.SetOutputDimensionality(3)
reslice.Update()
imagedata = reslice.GetOutput()
writer = vtk.vtkXMLImageDataWriter()
writer.SetInput(imagedata)
writer.SetFileName(filename)
writer.Write()
示例3: save_to_vti
def save_to_vti(imagedata, file_output):
print("Saving")
w = vtk.vtkXMLImageDataWriter()
w.SetInputData(imagedata)
w.SetFileName(file_output)
w.Write()
print("Saved")
示例4: __init__
def __init__(self, module_manager):
SimpleVTKClassModuleBase.__init__(
self, module_manager,
vtk.vtkXMLImageDataWriter(), 'Writing vtkXMLImageData.',
('vtkXMLImageData',), (),
replaceDoc=True,
inputFunctions=None, outputFunctions=None)
示例5: write_data
def write_data(data,x,y,z):
siz = x*y*z
fs="%dH"%siz
print "min(data)=",min(data),"max(data)=",max(data)
print "size=",siz,"len of data=",len(data)
ss = struct.pack(fs,*data)
print "min(ss)=",min(ss),"max(ss)=",max(ss),"len(ss)=",len(ss)
importer=vtk.vtkImageImport()
importer.CopyImportVoidPointer(ss,len(ss))
importer.SetDataScalarTypeToUnsignedShort()
#importer.SetDataScalarTypeToUnsignedChar()
#importer.SetDataScalarType(5)
importer.SetNumberOfScalarComponents(1)
importer.SetDataExtent(0,x-1,0,y-1,0,z-1)
importer.SetWholeExtent(0,x-1,0,y-1,0,z-1)
importer.Update()
image = importer.GetOutput()
#print image
print "Image scalar range=",image.GetScalarRange()
print "Image scalar type=",image.GetScalarTypeAsString()
#print image
writer = vtk.vtkXMLImageDataWriter()
writer.SetInput(image)
writer.SetFileName("output.vti")
print "Writing..."
writer.Write()
print "done"
示例6: Export
def Export(imagedata, filename, bin=False):
writer = vtk.vtkXMLImageDataWriter()
writer.SetFileName(filename)
if bin:
writer.SetDataModeToBinary()
else:
writer.SetDataModeToAscii()
示例7: __del__
def __del__(self):
if self._needWrite:
import vtk
vw = vtk.vtkXMLImageDataWriter()
vw.SetFileName(self._vol_file)
vw.SetInputData(self._volume)
vw.Write()
示例8: _handlerVoiSaveButton
def _handlerVoiSaveButton(self, event):
input_data = self.getPrimaryInput()
filename = self.controlFrame.voiFilenameText.GetValue()
if input_data and self._voi_widget.GetEnabled() and filename:
# see if we need to reset to zero origin
zor = self.controlFrame.voiResetToOriginCheck.GetValue()
extractVOI = vtk.vtkExtractVOI()
extractVOI.SetInput(input_data)
extractVOI.SetVOI(self._currentVOI)
writer = vtk.vtkXMLImageDataWriter()
writer.SetDataModeToBinary()
writer.SetFileName(filename)
if zor:
ici = vtk.vtkImageChangeInformation()
ici.SetOutputExtentStart(0,0,0)
ici.SetInput(extractVOI.GetOutput())
writer.SetInput(ici.GetOutput())
else:
writer.SetInput(extractVOI.GetOutput())
writer.Write()
示例9: __init__
def __init__(self, module_manager):
# call parent constructor
ModuleBase.__init__(self, module_manager)
self._writer = vtk.vtkXMLImageDataWriter()
# ctor for this specific mixin
FilenameViewModuleMixin.__init__(
self,
'Select a filename',
'VTK Image Data (*.vti)|*.vti|All files (*)|*',
{'vtkXMLImageDataWriter': self._writer},
fileOpen=False)
module_utils.setup_vtk_object_progress(
self, self._writer,
'Writing VTK ImageData')
self._writer.SetDataModeToBinary()
# set up some defaults
self._config.filename = ''
self._module_manager.sync_module_logic_with_config(self)
示例10: WriteVTKXMLImageFile
def WriteVTKXMLImageFile(self):
if self.OutputFileName == "":
self.PrintError("Error: no OutputFileName.")
self.PrintLog("Writing VTK XML image file.")
writer = vtk.vtkXMLImageDataWriter()
writer.SetInput(self.Image)
writer.SetFileName(self.OutputFileName)
writer.Write()
示例11: WriteVTKXMLImageFile
def WriteVTKXMLImageFile(self):
if (self.OutputFileName == ''):
self.PrintError('Error: no OutputFileName.')
self.PrintLog('Writing VTK XML image file.')
writer = vtk.vtkXMLImageDataWriter()
writer.SetInputData(self.Image)
writer.SetFileName(self.OutputFileName)
writer.Write()
示例12: write_to_file
def write_to_file(self, fname):
if self.__data is not None:
writer = vtk.vtkXMLImageDataWriter()
writer.SetFileName(fname)
writer.SetInput(self.__data)
writer.Write()
else:
print "vtk object does not exist. Use VTKStructuredPoints.create_vtk_structured_points to initialize it"
示例13: write_sp
def write_sp(pd):
writer = vtk.vtkXMLImageDataWriter()
writer.SetFileName("mean_flow.vti")
if vtk.vtkVersion.GetVTKMajorVersion() <= 5:
writer.SetInput(pd)
else:
writer.SetInputData(pd)
writer.Write()
return
示例14: keyPressEvent
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Space:
if event.modifiers() == QtCore.Qt.NoModifier:
self.WordleView.Modified()
self.WordleView.Update()
elif event.modifiers() == QtCore.Qt.ShiftModifier:
self.table.Modified()
self.WordleView.Update()
# Change Fonts (f)
if event.key() == QtCore.Qt.Key_F:
if self.font_flag:
self.WordleView.SetFontFamily("Tekton Pro")
else:
self.WordleView.SetFontFamily("Rockwell")
self.font_flag = not self.font_flag
self.WordleView.Update()
# Write PNG (n)
# Trying to use a integer-based QImage
if event.key() == QtCore.Qt.Key_N:
self.WordleView.SaveImage("out.png")
# Grab ImageData (i)
if event.key() == QtCore.Qt.Key_I:
image = self.WordleView.GetImageData()
# print image
iw = vtk.vtkXMLImageDataWriter()
iw.SetInput(image)
iw.SetFileName("out.vti")
iw.Write()
# Write PDF (p)
if event.key() == QtCore.Qt.Key_P:
self.WordleView.SavePDF("out.pdf")
# Write SVG (s)
# SVG generation not compiled in by default...
# if event.key() == QtCore.Qt.Key_S:
# self.WordleView.SaveSVG("out.svg")
# Switch only colors
if event.key() == QtCore.Qt.Key_C:
self.color_by_array = not self.color_by_array
if event.modifiers() == QtCore.Qt.NoModifier:
self.WordleView.SetColorByArray(self.color_by_array)
self.WordleView.Update()
elif event.modifiers() == QtCore.Qt.ShiftModifier:
if self.color_by_array:
self.WordleView.ApplyViewTheme(self.vt)
else:
self.WordleView.ApplyViewTheme(self.vt2)
self.WordleView.Update()
示例15: vtkImageData2vti
def vtkImageData2vti(filePath, source):
"""Export a ``vtk.vtkImageData`` object to VTI file.
Parameters
----------
filePath : str
Full path for the VTI to be created.
source : vtk.vtkImageData
object.
"""
writer = vtk.vtkXMLImageDataWriter()
writer.SetFileName(filePath)
writer.SetInput(source)
writer.Write()