Isosurface Generation Using VTK




Creating the Application



4.3. DialogOptionVOI



This class is divided into a number of different functions.  Below is the code for the classes in addition to commentary on the code.



Figure 4.1: Dialog box for the “Global Sampling Level” that will adjust the sampling rate for the current volume of interest.


__init__: This function initializes the class, sets up some constants, assigns some variables, and calls a private function to build the GUI for this dialog.

class DialogOptionVOI( Dialog ):

    def __init__( self, topWindow, vtkWindow ):

        Dialog.__init__( self, topWindow, 'Global Sampling Level', I_TRUE )


        self.__vtkWindow = vtkWindow


        # Constants

        self.I_ERROR = -5

        self.I_OK = 0

        self.I_CANCEL = -10


        self.__action = self.I_CANCEL


        self.__xSampleRate = 1.0

        self.__ySampleRate = 1.0

        self.__zSampleRate = 1.0




  • __setErrorMessage: This function is not used but is kept in case there is a status bar added to this dialog box to describe errors that occur rather than displaying them in another popup dialog box.  Tkinter is not suited to present popup dialogs considering the difficulty there is in simply displaying a single modal dialog (which the author is not doing because of this complexity). 

    def __setErrorMessage( self, message ):

        self.setStatusBarMessage( B_USE_ERROR_COLOR, message )

  • __buildDialog: This function simply creates the dialog box.  The grid widget placer is used.  The packItem function is part of the GUIFactory class that arranges the widgets on the dialog box.  Other comments:









    def __buildDialog( self ):

        guiFactory = GUIFactory()


        gridSettings = { 'padx':5, 'pady':5, 'sticky':Tkinter.SW,

                         'row':0, 'rowspan':1, 'column':0, 'columnspan':1 }


        labelX = guiFactory.newLabel( self.dialog, 'X', {'justify':Tkinter.RIGHT} )

        gridSettings[ 'sticky' ] = Tkinter.NW

        gridSettings[ 'row' ] = 0

        gridSettings[ 'column' ] = 0

        gridSettings[ 'columnspan' ] = 1

        guiFactory.packItem( labelX, gridSettings )


    • As indicated by the slider values, the shrinking factor for the sampling level can go up to 8.  As a result, the subsample will have 1/83 the original volume as before.


    • Because the slider ends up changing the properties of the visualization pipeline, the function addSliderCommandBinding must be called in order to override the default command binding of the slider.  In this manner, this new function named __doUpdateSample will have to take care of the basic functionality in addition to updating the pipeline.  (There are better ways to do this, but the author did not implement them).







        self.__sliderSampleX = SliderWithValue( self.dialog, 1,8 )

        #self.__sliderSampleX.configureScale( {'variable':self.__xSampleRate} )

        self.__widgetSampleX = self.__sliderSampleX.getWidget()

        gridSettings[ 'column' ] = 1

        self.__sliderSampleX.addSliderCommandBinding( self.__doUpdateSample )

        guiFactory.packItem( self.__widgetSampleX, gridSettings )



        labelY = guiFactory.newLabel( self.dialog, 'Y', {'justify':Tkinter.RIGHT} )

        gridSettings[ 'sticky' ] = Tkinter.NW

        gridSettings[ 'row' ] = 1

        gridSettings[ 'column' ] = 0

        gridSettings[ 'columnspan' ] = 1

        guiFactory.packItem( labelY, gridSettings )



        self.__sliderSampleY = SliderWithValue( self.dialog, 1,8 )

        self.__widgetSampleY = self.__sliderSampleY.getWidget()

        gridSettings[ 'column' ] = 1

        self.__sliderSampleY.addSliderCommandBinding( self.__doUpdateSample )

        guiFactory.packItem( self.__widgetSampleY, gridSettings )



        labelZ = guiFactory.newLabel( self.dialog, 'Z', {'justify':Tkinter.RIGHT} )

        gridSettings[ 'sticky' ] = Tkinter.NW

        gridSettings[ 'row' ] = 2

        gridSettings[ 'column' ] = 0

        gridSettings[ 'columnspan' ] = 1

        guiFactory.packItem( labelZ, gridSettings )



        self.__sliderSampleZ = SliderWithValue( self.dialog, 1,8 )

        self.__widgetSampleZ = self.__sliderSampleZ.getWidget()

        gridSettings[ 'column' ] = 1

        self.__sliderSampleZ.addSliderCommandBinding( self.__doUpdateSample )

        guiFactory.packItem( self.__widgetSampleZ, gridSettings )       

  • updateSamplingRate: This private member function is calls the function responsible in the VTKRender class for updating the pipeline with the new sampling rates for each of the axes.  Since it had overridden the previous default function called when the slider is moved, this function has to perform the simple updating of the value display label related to the Tkinter.Scale (slider) widget.


    def __doUpdateSample( self, *unusedArgument ):

        self.__xSampleRate = self.__sliderSampleX.getValue()

        self.__ySampleRate = self.__sliderSampleY.getValue()

        self.__zSampleRate = self.__sliderSampleZ.getValue()


        self.__sliderSampleX.configureLabel( { 'text':self.__xSampleRate } )

        self.__sliderSampleY.configureLabel( { 'text':self.__ySampleRate } )

        self.__sliderSampleZ.configureLabel( { 'text':self.__zSampleRate } )



            self.__xSampleRate, self.__ySampleRate, self.__zSampleRate )


Example 4.3: Code for DialogOptionVOI class




<<< Previous




Table of Contents



Next >>>