本文整理汇总了Python中vtk.vtkImageViewer函数的典型用法代码示例。如果您正苦于以下问题:Python vtkImageViewer函数的具体用法?Python vtkImageViewer怎么用?Python vtkImageViewer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vtkImageViewer函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
#os.system("pwd")
if os.path.exists(self.gladeFile):
theFile = self.gladeFile
elif os.path.exists("gui/"+self.gladeFile):
theFile = "gui/"+self.gladeFile
else:
theFile = os.path.join(
distutils.sysconfig.PREFIX,
'share', 'pbrain', self.gladeFile)
self.widgets = gtk.glade.XML (theFile)
self.widgets.signal_autoconnect(GladeHandlers.__dict__)
#self['entryDir'].set_text('/home/jdhunter/python/examples/vtk/images/')
self.outDim = 256, 256
self.viewer = vtk.vtkImageViewer()
self.preview = GtkGLExtVTKRenderWindow()
self.preview.set_size_request(self.outDim[0], self.outDim[1])
self.preview.show()
self.renderer = self.viewer.GetRenderer()
self.preview.GetRenderWindow().AddRenderer(self.renderer)
self['vboxPreview'].pack_start(self.preview, False, False)
self['vboxPreview'].reorder_child(self.preview, 1)
示例2: viewVtk
def viewVtk(mat):
import vtk
imageData = vtk.vtkImageData()
imageData.SetDimensions(mat.shape[0], mat.shape[1], 1)
imageData.SetScalarTypeToUnsignedShort()
imageData.SetNumberOfScalarComponents(1)
imageData.AllocateScalars()
viewer = vtk.vtkImageViewer()
viewer.SetInput(imageData)
viewer.SetZSlice(0)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(viewer.GetRenderWindow())
iren.Initialize()
iren.Start()
imageData = vtk.vtkImageSinusoidSource()
imageData.SetWholeExtent(0, 300, 0, 300, 0, 10)
imageData.SetAmplitude(63)
imageData.SetDirection(1, 1, 0)
imageData.SetPeriod(25)
viewer = vtk.vtkImageViewer()
viewer.SetInput(imageData.GetOutput())
viewer.SetColorWindow(126)
viewer.SetColorLevel(0)
viewer.SetZSlice(0)
def hamschti(obj, event):
print "Haam:"
print obj
print event
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(viewer.GetRenderWindow())
iren.Initialize()
interactor = vtk.vtkInteractorStyleImage()
##interactor.AddObserver('LeftButtonPressEvent', hamschti)
iren.SetInteractorStyle(interactor)
iren.Start()
示例3: View
def View(imagedata):
viewer = vtk.vtkImageViewer()
viewer.SetInput(imagedata)
viewer.SetColorWindow(200)
viewer.SetColorLevel(100)
viewer.Render()
import time
time.sleep(10)
示例4: __getattr__
def __getattr__(self, attr):
# because the tk part of vtkTkImageViewerWidget must have
# the only remaining reference to the ImageViewer when
# it is destroyed, we can't actually store the ImageViewer
# as an attribute but instead have to get it from the tk-side
if attr == "_ImageViewer":
addr = self.tk.call(self._w, "GetImageViewer")[5:]
return vtk.vtkImageViewer("_%s_vtkImageViewer_p" % addr)
raise AttributeError, self.__class__.__name__ + " has no attribute named " + attr
示例5: slotShowDICOMImage
def slotShowDICOMImage(self, item):
reader = vtkgdcm.vtkGDCMImageReader()
dicom_file = unicode(item.data(QtCore.Qt.UserRole).toString())
reader.SetFileName(dicom_file)
reader.Update()
imageViewer = vtk.vtkImageViewer()
imageViewer.SetInputConnection(reader.GetOutputPort())
self.qvtkWidget.SetRenderWindow(imageViewer.GetRenderWindow())
imageViewer.SetupInteractor(self.qvtkWidget.GetRenderWindow().GetInteractor())
#imageViewer.SetColorLevel(128)
#imageViewer.SetColorWindow(256)
imageViewer.SetSize(self.qvtkWidget.geometry().width(), self.qvtkWidget.geometry().height())
示例6: __init__
def __init__(self, master, cnf={}, **kw):
"""
Constructor.
Keyword arguments:
iv -- Use passed image viewer instead of creating a new one.
double -- If True, generate a double-buffered viewer.
Defaults to False.
focus_on_enter -- If True, use a focus-follows-mouse mode.
Defaults to False where the widget will use a click-to-focus
mode.
"""
# load the necessary extensions into tk
vtkLoadPythonTkWidgets(master.tk)
try: # use specified vtkImageViewer
imageViewer = kw['iv']
except KeyError: # or create one if none specified
imageViewer = vtk.vtkImageViewer()
doubleBuffer = 0
try:
if kw['double']:
doubleBuffer = 1
del kw['double']
except:
pass
# check if focus should follow mouse
if kw.get('focus_on_enter'):
self._FocusOnEnter = 1
del kw['focus_on_enter']
else:
self._FocusOnEnter = 0
kw['iv'] = imageViewer.GetAddressAsString("vtkImageViewer")
Tkinter.Widget.__init__(self, master, 'vtkTkImageViewerWidget',
cnf, kw)
if doubleBuffer:
imageViewer.GetRenderWindow().DoubleBufferOn()
self.BindTkImageViewer()
示例7: initGUI
def initGUI(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.setWindowTitle("Simple Dicom Viewer")
#self.dicomReader = vtk.vtkDICOMImageReader()
#self.dicomReader = vtkgdcm.vtkGDCMImageReader()
self.show()
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.toolbar = NavigationToolbar(self.canvas, self)
self.ui.numpyLayout.addWidget(self.toolbar)
self.ui.numpyLayout.addWidget(self.canvas)
self.vtkWidget = QVTKRenderWindowInteractor(self.ui.imageFrame)
self.vtkWidget.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
#self.ui.imageLayout.removeWidget(self.ui.dicomSlider)
self.ui.imageLayout.addWidget(self.vtkWidget)
#self.ui.imageLayout.addWidget(self.ui.dicomSlider)
self.disableSlider()
self.viewer= vtk.vtkImageViewer()
#self.viewer.SetupInteractor(MyInteractor())
self.vtkWidget.GetRenderWindow().AddRenderer(self.viewer.GetRenderer())
self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
#self.iren.SetRenderWindow(self.vtkWidget.GetRenderWindow())
self.drag = False
self.measuring = False
self.iren.AddObserver("LeftButtonPressEvent", self.leftClick)
self.iren.AddObserver("LeftButtonReleaseEvent", self.leftRelease)
self.iren.AddObserver("EnterEvent", self.mouseEntered)
self.iren.AddObserver("LeaveEvent", self.mouseLeft)
self.iren.AddObserver("MouseMoveEvent", self.mouseMoved)
示例8: processing
magnify2.SetInputConnection(reader.GetOutputPort())
magnify2.SetMagnificationFactors(IMAGE_MAG_X, IMAGE_MAG_Y, IMAGE_MAG_Z)
magnify2.ReleaseDataFlagOn()
# a filter that does in place processing (magnify ReleaseDataFlagOn)
cursor = vtk.vtkImageCursor3D()
cursor.SetInputConnection(magnify1.GetOutputPort())
cursor.SetCursorPosition(CURSOR_X * IMAGE_MAG_X,
CURSOR_Y * IMAGE_MAG_Y,
CURSOR_Z * IMAGE_MAG_Z)
cursor.SetCursorValue(255)
cursor.SetCursorRadius(50 * IMAGE_MAG_X)
# stream to increase coverage of in place filter.
# put the two together in one image
imageAppend = vtk.vtkImageAppend()
imageAppend.SetAppendAxis(0)
imageAppend.AddInputConnection(magnify2.GetOutputPort())
imageAppend.AddInputConnection(cursor.GetOutputPort())
viewer = vtk.vtkImageViewer()
viewer.SetInputConnection(imageAppend.GetOutputPort())
viewer.SetZSlice(CURSOR_Z * IMAGE_MAG_Z)
viewer.SetColorWindow(200)
viewer.SetColorLevel(80)
# viewer DebugOn
viewer.Render()
viewer.SetPosition(50, 50)
# make interface
viewer.Render()
示例9: SetUp
def SetUp(self):
"""
Set up cursor3D
"""
def OnClosing():
self.root.quit()
def ViewerDown(tkvw):
viewer = tkvw.GetImageViewer()
ViewerSetZSlice(tkvw, viewer.GetZSlice() - 1)
def ViewerUp(tkvw):
viewer = tkvw.GetImageViewer()
ViewerSetZSlice(tkvw, viewer.GetZSlice() + 1)
def ViewerSetZSlice(tkvw, z):
viewer = tkvw.GetImageViewer()
viewer.SetZSlice(z)
txt = "slice: " + str(z)
sliceLabel.configure(text=txt)
tkvw.Render()
def SetCursorFromViewer(event):
x = int(event.x)
y = int(event.y)
# We have to flip y axis because tk uses upper right origin.
self.root.update_idletasks()
height = int(self.tkvw.configure()["height"][4])
y = height - y
z = self.tkvw.GetImageViewer().GetZSlice()
SetCursor(x / IMAGE_MAG_X, y / IMAGE_MAG_Y, z / IMAGE_MAG_Z)
def SetCursor(x, y, z):
CURSOR_X = x
CURSOR_Y = y
CURSOR_Z = z
axes.SetOrigin(CURSOR_X, CURSOR_Y, CURSOR_Z)
imageCursor.SetCursorPosition(CURSOR_X * IMAGE_MAG_X, CURSOR_Y * IMAGE_MAG_Y, CURSOR_Z * IMAGE_MAG_Z)
self.viewer.Render()
self.tkrw.Render()
# Pipeline stuff.
reader = vtk.vtkSLCReader()
reader.SetFileName(VTK_DATA_ROOT + "/Data/neghip.slc")
# Cursor stuff
magnify = vtk.vtkImageMagnify()
magnify.SetInputConnection(reader.GetOutputPort())
magnify.SetMagnificationFactors(IMAGE_MAG_X, IMAGE_MAG_Y, IMAGE_MAG_Z)
imageCursor = vtk.vtkImageCursor3D()
imageCursor.SetInputConnection(magnify.GetOutputPort())
imageCursor.SetCursorPosition(CURSOR_X * IMAGE_MAG_X, CURSOR_Y * IMAGE_MAG_Y, CURSOR_Z * IMAGE_MAG_Z)
imageCursor.SetCursorValue(255)
imageCursor.SetCursorRadius(50 * IMAGE_MAG_X)
axes = vtk.vtkAxes()
axes.SymmetricOn()
axes.SetOrigin(CURSOR_X, CURSOR_Y, CURSOR_Z)
axes.SetScaleFactor(50.0)
axes_mapper = vtk.vtkPolyDataMapper()
axes_mapper.SetInputConnection(axes.GetOutputPort())
axesActor = vtk.vtkActor()
axesActor.SetMapper(axes_mapper)
axesActor.GetProperty().SetAmbient(0.5)
# Image viewer stuff.
viewer = vtk.vtkImageViewer()
viewer.SetInputConnection(imageCursor.GetOutputPort())
viewer.SetZSlice(CURSOR_Z * IMAGE_MAG_Z)
viewer.SetColorWindow(256)
viewer.SetColorLevel(128)
# Create transfer functions for opacity and color.
opacity_transfer_function = vtk.vtkPiecewiseFunction()
opacity_transfer_function.AddPoint(20, 0.0)
opacity_transfer_function.AddPoint(255, 0.2)
color_transfer_function = vtk.vtkColorTransferFunction()
color_transfer_function.AddRGBPoint(0, 0, 0, 0)
color_transfer_function.AddRGBPoint(64, 1, 0, 0)
color_transfer_function.AddRGBPoint(128, 0, 0, 1)
color_transfer_function.AddRGBPoint(192, 0, 1, 0)
color_transfer_function.AddRGBPoint(255, 0, 0.2, 0)
# Create properties, mappers, volume actors, and ray cast function.
volume_property = vtk.vtkVolumeProperty()
volume_property.SetColor(color_transfer_function)
# volume_property.SetColor(color_transfer_function[0],
# color_transfer_function[1],
# color_transfer_function[2])
volume_property.SetScalarOpacity(opacity_transfer_function)
volume_mapper = vtk.vtkFixedPointVolumeRayCastMapper()
#.........这里部分代码省略.........