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:

  • Some of the menu items, especially the “radio” menus, require using a special integer class existing in Tkinter.  For this reason, instead of doing the standard assignment (=), it is necessary to use a set function to assign a value and a get function to retrieve a value.  The two variables that fall into this category are self.__vizType and self.__vizDataset.
    • Most of the stuff is self-explanatory.  The statusLabel is a twist on a label except for the fact that it uses the “SUNKEN feature to make it look more believable. 









































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 )




__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:

  • Remember when declaring the menu to set the tearoff parameter equal to 0. This will prevent the menus from having the ability to be torn off.
  • Menu items that are radiobuttons require the programmer to set value and variable parameters.  The value can be an ordinary integer, in this case.  The variable should be of type Tkinter.IntVar.  In fact, the menus labeled “Head” and “Feet” are connected to the variable self.__vizDataset.






    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 )


            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 ):



        elif ( dataset == self.__vtkViewport.FEET ):

            if ( viz == self.__vtkViewport.ISO ):




__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 ):








__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 ):





__doMenuFileExit:  The private menu function will cause the application to exit when the “Exit” menu item is selected.


    def __doMenuFileExit( self ):

        print "Bye"



        sys.exit( 0 )

        print "Done"


Example 4.1: Code for GUI class






<<< Previous

Creating the Application



Table of Contents



Next >>>