Commit cd1c29e6 authored by David Gobbi's avatar David Gobbi

Clean up by destroying the vtkTkRenderWidget.

Currently, the only way for Python/Tk to force Tcl to delete the
vtkTkRenderWidget is to destroy() the widget.  This has to be done with
care, since the widget must hold the only reference to its vtkRenderWindow
at the time of its destruction.  If the widget is not destroyed, then a
memory leak results.
parent be7e8d24
......@@ -33,9 +33,8 @@ class SuperQuadricViewer(Testing.vtkTest):
Provide a testing framework for squadViewer.
Note:
root, the top-level widget for Tk,
tkrw, the vtkTkRenderWidget and
renWin, the vtkRenderindow
root, the top-level widget for Tk, and
tkrw, the vtkTkRenderWidget
are accessible from any function in this class
after SetUp() has run.
'''
......@@ -82,7 +81,7 @@ class SuperQuadricViewer(Testing.vtkTest):
# Create render window
self.tkrw = vtkTkRenderWidget(self.root, width=550, height=450)
self.tkrw.BindTkRenderWidget()
self.renWin = self.tkrw.GetRenderWindow()
renWin = self.tkrw.GetRenderWindow()
# Create parameter sliders
#
......@@ -152,13 +151,13 @@ class SuperQuadricViewer(Testing.vtkTest):
squad.SetToroidal(toroid.get())
squad.SetThickness(thicks.get())
squad.SetScale(1, 1, 1)
SetTexture(actor, atext, self.renWin)
SetTexture(actor, atext, renWin)
# Create renderer stuff
#
ren = vtk.vtkRenderer()
ren.SetAmbient(1.0, 1.0, 1.0)
self.renWin.AddRenderer(ren)
renWin.AddRenderer(ren)
# Add the actors to the renderer, set the background and size
......@@ -172,23 +171,24 @@ class SuperQuadricViewer(Testing.vtkTest):
# Associate the functions with the sliders and check buttons.
#
prs.config(command=partial(SetPhi, squad, self.renWin))
trs.config(command=partial(SetTheta, squad, self.renWin))
thicks.config(command=partial(SetThickness,squad, self.renWin))
torbut.config(command=partial(SetToroid, squad, thicks, self.renWin))
texbut.config(command=partial(SetTexture, actor, atext, self.renWin))
prs.config(command=partial(SetPhi, squad, self.tkrw))
trs.config(command=partial(SetTheta, squad, self.tkrw))
thicks.config(command=partial(SetThickness,squad, self.tkrw))
torbut.config(command=partial(SetToroid, squad, thicks, self.tkrw))
texbut.config(command=partial(SetTexture, actor, atext, self.tkrw))
def DoIt(self):
self.SetUp()
self.renWin.Render()
self.tkrw.Render()
self.root.update()
# If you want to interact and use the sliders etc,
# uncomment the following line.
#self.root.mainloop()
img_file = "squadViewer.png"
Testing.compareImage(self.renWin, Testing.getAbsImagePath(img_file))
Testing.compareImage(self.tkrw.GetRenderWindow(),
Testing.getAbsImagePath(img_file))
Testing.interact()
self.tkrw.destroy()
if __name__ == '__main__':
cases = [(SuperQuadricViewer, 'DoIt')]
......
......@@ -49,9 +49,8 @@ class TestTextActor3DViewer(Testing.vtkTest):
Provide a testing framework for for TestTextActor3D.
Note:
root, the top-level widget for Tk,
tkrw, the vtkTkRenderWidget and
renWin, the vtkRenderindow
root, the top-level widget for Tk, and
tkrw, the vtkTkRenderWidget
are accessible from any function in this class
after SetUp() has run.
'''
......@@ -128,12 +127,12 @@ class TestTextActor3DViewer(Testing.vtkTest):
tprop.SetOrientation(orientation)
tprop.SetOpacity(opacity)
self.renWin.Render()
self.tkrw.Render()
ren = vtk.vtkRenderer()
ren.SetBackground(0.1, 0.2, 0.4)
self.renWin = vtk.vtkRenderWindow()
self.renWin.AddRenderer(ren)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
#self.renWin.SetSize(600, 600)
self.root = tkinter.Tk()
......@@ -143,9 +142,9 @@ class TestTextActor3DViewer(Testing.vtkTest):
# The Tk render widget.
self.tkrw = vtkTkRenderWidget(
self.root, width=450, height=450, rw=self.renWin)
self.root, width=450, height=450, rw=renWin)
self.tkrw.BindTkRenderWidget()
#self.renWin.GetInteractor().GetInteractorStyle().SetCurrentStyleToTrackballCamera()
#renWin.GetInteractor().GetInteractorStyle().SetCurrentStyleToTrackballCamera()
self.tkrw.pack(side=LEFT, fill=BOTH, expand=YES)
# Base text property
......@@ -233,15 +232,16 @@ class TestTextActor3DViewer(Testing.vtkTest):
def DoIt(self):
self.SetUp()
self.renWin.Render()
self.tkrw.Render()
self.root.update()
# If you want to interact and use the sliders etc,
# uncomment the following line.
#self.root.mainloop()
img_file = "TestTextActor3D.png"
Testing.compareImage(self.renWin, Testing.getAbsImagePath(img_file))
Testing.compareImage(self.tkrw.GetRenderWindow(),
Testing.getAbsImagePath(img_file))
Testing.interact()
self.tkrw.destroy()
if __name__ == '__main__':
cases = [(TestTextActor3DViewer, 'DoIt')]
......
......@@ -26,8 +26,7 @@ class TestTkRenderWidget(Testing.vtkTest):
ren = vtk.vtkRenderer()
tkrw = vtkTkRenderWidget(root, width=300, height=300)
tkrw.pack()
rw = tkrw.GetRenderWindow()
rw.AddRenderer(ren)
tkrw.GetRenderWindow().AddRenderer(ren)
# create an actor and give it cone geometry
cs = vtk.vtkConeSource()
......@@ -42,11 +41,13 @@ class TestTkRenderWidget(Testing.vtkTest):
def testvtkTkRenderWidget(self):
"Test if vtkTkRenderWidget works."
self.rw.Render()
self.tkrw.Render()
self.root.update()
img_file = "TestTkRenderWidget.png"
Testing.compareImage(self.rw, Testing.getAbsImagePath(img_file))
Testing.compareImage(self.tkrw.GetRenderWindow(),
Testing.getAbsImagePath(img_file))
Testing.interact()
self.root.destroy()
# Dummy tests to demonstrate how the blackbox tests can be done.
def testParse(self):
......
......@@ -50,6 +50,7 @@ class TestTkRenderWindowInteractor(Testing.vtkTest):
img_file = "TestTkRenderWindowInteractor.png"
Testing.compareImage(self.rw, Testing.getAbsImagePath(img_file))
Testing.interact()
self.tkrw.destroy()
# These are useful blackbox tests (not dummy ones!)
def testParse(self):
......
......@@ -64,7 +64,7 @@ class Cursor3DViewer(Testing.vtkTest):
Note:
root, the top-level widget for Tk,
tkrw, the vtkTkRenderWidget and
viewer, the Image viewer
tkvw, the vtkTkImageViewerWidget
are accessible from any function in this class
after SetUp() has run.
'''
......@@ -77,17 +77,20 @@ class Cursor3DViewer(Testing.vtkTest):
def OnClosing():
self.root.quit()
def ViewerDown(viewer):
ViewerSetZSlice(viewer, viewer.GetZSlice() - 1)
def ViewerDown(tkvw):
viewer = tkvw.GetImageViewer()
ViewerSetZSlice(tkvw, viewer.GetZSlice() - 1)
def ViewerUp(viewer):
ViewerSetZSlice(viewer, viewer.GetZSlice() + 1)
def ViewerUp(tkvw):
viewer = tkvw.GetImageViewer()
ViewerSetZSlice(tkvw, viewer.GetZSlice() + 1)
def ViewerSetZSlice(viewer, z):
def ViewerSetZSlice(tkvw, z):
viewer = tkvw.GetImageViewer()
viewer.SetZSlice(z)
txt = 'slice: ' + str(z)
sliceLabel.configure(text=txt)
viewer.Render()
tkvw.Render()
def SetCursorFromViewer(event):
x = int(event.x)
......@@ -96,7 +99,7 @@ class Cursor3DViewer(Testing.vtkTest):
self.root.update_idletasks()
height = int(self.tkvw.configure()['height'][4])
y = height - y
z = self.viewer.GetZSlice()
z = self.tkvw.GetImageViewer().GetZSlice()
SetCursor( x / IMAGE_MAG_X, y / IMAGE_MAG_Y, z / IMAGE_MAG_Z )
def SetCursor(x, y, z):
......@@ -112,7 +115,7 @@ class Cursor3DViewer(Testing.vtkTest):
CURSOR_Z * IMAGE_MAG_Z)
self.viewer.Render()
self.renWin.Render()
self.tkrw.Render()
# Pipeline stuff.
reader = vtk.vtkSLCReader()
......@@ -145,11 +148,11 @@ class Cursor3DViewer(Testing.vtkTest):
axesActor.GetProperty().SetAmbient(0.5)
# Image viewer stuff.
self.viewer = vtk.vtkImageViewer()
self.viewer.SetInputConnection(imageCursor.GetOutputPort())
self.viewer.SetZSlice(CURSOR_Z*IMAGE_MAG_Z)
self.viewer.SetColorWindow(256)
self.viewer.SetColorLevel(128)
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()
......@@ -195,9 +198,9 @@ class Cursor3DViewer(Testing.vtkTest):
ren.AddVolume(volume)
ren.SetBackground(0.1, 0.2, 0.4)
self.renWin = vtk.vtkRenderWindow()
self.renWin.AddRenderer(ren)
self.renWin.SetSize(256, 256)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(256, 256)
# Create the GUI: two renderer widgets and a quit button.
self.root = tkinter.Tk()
......@@ -221,15 +224,15 @@ class Cursor3DViewer(Testing.vtkTest):
viewerFrame = tkinter.Frame(displayFrame)
viewerFrame.pack(padx=3, pady=3, side=LEFT, anchor=N,
fill=BOTH, expand=FALSE)
self.tkvw = vtkTkImageViewerWidget(viewerFrame, iv=self.viewer,
self.tkvw = vtkTkImageViewerWidget(viewerFrame, iv=viewer,
width=264, height=264)
viewerControls = tkinter.Frame(viewerFrame)
viewerControls.pack(side=BOTTOM, anchor=S, fill=BOTH, expand=TRUE)
self.tkvw.pack(side=TOP, anchor=N, fill=BOTH, expand=FALSE)
downButton = tkinter.Button(viewerControls, text="Down",
command=[ViewerDown,self.viewer])
command=[ViewerDown,self.tkvw])
upButton = tkinter.Button(viewerControls, text="Up",
command=[ViewerUp,self.viewer])
command=[ViewerUp,self.tkvw])
sliceLabel = tkinter.Label(viewerControls,
text="slice: "+str(CURSOR_Z*IMAGE_MAG_Z))
downButton.pack(side=LEFT, expand=TRUE, fill=BOTH)
......@@ -240,7 +243,7 @@ class Cursor3DViewer(Testing.vtkTest):
renderFrame = tkinter.Frame(displayFrame)
renderFrame.pack(padx=3, pady=3, side=LEFT, anchor=N,
fill=BOTH, expand=TRUE)
self.tkrw = vtkTkRenderWidget(renderFrame, rw=self.renWin,
self.tkrw = vtkTkRenderWidget(renderFrame, rw=renWin,
width=264, height=264)
self.tkrw.pack(side=TOP, anchor=N, fill=BOTH, expand=TRUE)
......@@ -256,20 +259,22 @@ class Cursor3DViewer(Testing.vtkTest):
# Associate the functions with the buttons and label.
#
downButton.config(command=partial(ViewerDown, self.viewer))
upButton.config(command=partial(ViewerUp, self.viewer))
downButton.config(command=partial(ViewerDown, self.tkvw))
upButton.config(command=partial(ViewerUp, self.tkvw))
def DoIt(self):
self.SetUp()
self.viewer.Render()
self.tkvw.Render()
self.tkrw.Render()
self.root.update()
# If you want to interact and use the sliders etc,
# uncomment the following line.
#self.root.mainloop()
img_file = "cursor3D.png"
Testing.compareImage(self.viewer.GetRenderWindow(), Testing.getAbsImagePath(img_file))
# Testing.interact()
Testing.compareImage(self.tkvw.GetImageViewer().GetRenderWindow(),
Testing.getAbsImagePath(img_file))
# Testing.interact()
self.root.destroy()
if __name__ == '__main__':
cases = [(Cursor3DViewer, 'DoIt')]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment