Isosurface Generation Using VTK
|
|||||||
Creating the Application |
|||||||
|
|||||||
4.1 GUI
This class is divided into a number of different functions. Below is the code for the classes in addition to commentary on the code. |
|||||||
__init__: This function initializes the class, declares constants, creates the main window, creates the dialog boxes, and initializes the default visualization type (head). Other comments:
|
class GUI: def __init__( self, rootWindow ): global I_TRUE, I_FALSE # Constants self.I_OK = 0 self.I_NO_FILE = -10 self.__vizType = Tkinter.IntVar() self.__vizDataset = Tkinter.IntVar() guiFactory = GUIFactory() # Create window
frame self.__rootWindow = rootWindow self.__rootWindow.title( 'Isosurface
Generation' ) self.__frame = Tkinter.Frame(
self.__rootWindow ) self.__frame.pack( fill=Tkinter.BOTH,
expand=1, side=Tkinter.TOP ) # Add VTK
rendering viewport self.__vtkViewport = VTKRender(
self.__frame ) # Add menu bar menuBar = Tkinter.Menu( self.__frame
) self.__rootWindow.config( menu=menuBar ) self.__buildMenu( menuBar ) # Add
pseudo-status bar (from "An Introduction to Tkinter" ) self.__statusLabel = guiFactory.newLabel( self.__frame,
'by: Allan Spale', {'relief':Tkinter.SUNKEN,'justify':Tkinter.LEFT,
'anchor':Tkinter.W } ) self.__statusErrorSettings = {
'background':'#ffffff',
'foreground':'#000099' } self.__statusOKSettings = {
'background':self.__statusLabel.cget( 'background' ),
'foreground':self.__statusLabel.cget( 'foreground' ) } self.__statusLabel.pack(
fill=Tkinter.BOTH, side=Tkinter.BOTTOM ) # Create dialog
boxes self.__dialogGlobalDetail =
DialogOptionVOI( self.__rootWindow, self.__vtkViewport ) self.__dialogDatasetProps =
DialogIsosurfaces( self.__rootWindow, self.__vtkViewport,
self.__vizType.get() ) # Initialize self.__vizType.set( self.__vtkViewport.ISO ) self.__vizDataset.set( self.__vtkViewport.HEAD ) self.__doSetVizType() |
||||||
__buildMenu: This private member function creates the menu on the main window and assigns functions to be called when different menu items are selected. Other comments:
|
def __buildMenu( self, menuMainMenu ): menuFile = Tkinter.Menu( menuMainMenu, tearoff=0 ) menuFile.add_command( label='Exit',
command=self.__doMenuFileExit ) menuMainMenu.add_cascade(
label='File', menu=menuFile ) self.__menuViz = Tkinter.Menu(
menuMainMenu, tearoff=0 ) self.__menuViz.add_radiobutton( label='Head',
value=self.__vtkViewport.HEAD, variable=self.__vizDataset,
command=self.__doSetVizType ) self.__menuViz.add_radiobutton( label='Feet',
value=self.__vtkViewport.FEET, variable=self.__vizDataset,
command=self.__doSetVizType ) menuMainMenu.add_cascade(
label='Visualization', menu=self.__menuViz ) self.__menuOptions = Tkinter.Menu(
menuMainMenu, tearoff=0 ) self.__menuOptions.add_command(
label='Dataset Properties',
command=self.__doMenuOptionProps ) self.__menuOptions.add_command( label='Global Level of Detail',
command=self.__doMenuOptionDetail ) menuMainMenu.add_cascade(
label='Options', menu=self.__menuOptions ) |
||||||
__doSetVizType: A private member function that will be called when visualization menu items are selected. |
def __doSetVizType( self ): dataset = self.__vizDataset.get() viz = self.__vizType.get() if ( dataset ==
self.__vtkViewport.HEAD ): if ( viz ==
self.__vtkViewport.ISO ): self.__vtkViewport.showIsosurfaceHead() elif ( dataset ==
self.__vtkViewport.FEET ): if ( viz ==
self.__vtkViewport.ISO ):
self.__vtkViewport.showIsosurfaceFeet() |
||||||
__doMenuOptionProps:
This private member function will simply display the Dataset Properties
dialog box that allows the user to change the color and opacity of the skin
and bone tissue isosurfaces when the menu its related menu item is selected. |
def __doMenuOptionProps( self ): self.__dialogDatasetProps.show() |
||||||
__doMenuOptionDetail:
This private member function will simply display a dialog box that allows the
user to change the sampling level of the dataset when the menu its related
menu item is selected. |
def __doMenuOptionDetail( self ): self.__dialogGlobalDetail.show() |
||||||
__doMenuFileExit: The private menu function will cause the application to exit when the “Exit” menu item is selected. |
def __doMenuFileExit( self ): print "Bye" self.__vtkViewport.destroy() self.__rootWindow.destroy() sys.exit( 0 ) print "Done" Example 4.1:
Code for GUI class |
||||||
|
|
||||||
|
|||||||
|
|||||||
|
|
|
|
|
|||