Previous

Section

<<<

Isosurface Generation Using VTK

Next

Section

>>>

Creating the Application

 

 

4.4. DialogIsosurfaces

 

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.2: Surface properties dialog box generated by the code below

 

__init__: This function initializes the class, sets up some constants, assigns some variables, calls a private function to build the GUI for this dialog, and sets the default toggle button by calling the function __doSetSkinTissue.  In this dialog, there is a button that appears

class DialogIsosurfaces( Dialog ):

    global I_TRUE, I_FALSE

   

    def __init__( self, topWindow, vtkWindow, vizType ):

        Dialog.__init__( self, topWindow, 'Surface Properties', I_TRUE )

        self.__vtkWindow = vtkWindow

        self.__vizType = vizType

 

        self.__tissue = Tkinter.IntVar()

 

        self.__skinValuesDict = {}

        self.__boneValuesDict = {}

 

        self.__skinValuesDict[ 'tissue' ] = self.__vtkWindow.SKIN

        self.__skinValuesDict[ 'red' ] = 0

        self.__skinValuesDict[ 'green' ] = 0

        self.__skinValuesDict[ 'blue' ] = 0

        self.__skinValuesDict[ 'opaque' ] = 0

       

        self.__boneValuesDict[ 'tissue' ] = self.__vtkWindow.BONE

        self.__boneValuesDict[ 'red' ] = 0

        self.__boneValuesDict[ 'green' ] = 0

        self.__boneValuesDict[ 'blue' ] = 0

        self.__boneValuesDict[ 'opaque' ] = 0

 

        self.__buildDialog()

        self.__doSetSkinTissue()

  • __buildDialog: This private member function tediously builds the dialog box.  Below shows a graphical part-by-part building of the dialog box.

 

 

 

 

    def __buildDialog( self ):

        guiFactory = GUIFactory()

       

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

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

 

 

 

 

        ###### Tissue Type

        labelType = guiFactory.newLabel( self.dialog, 'Tissue', {} )

        gridSettings[ 'row' ] = 0

        gridSettings[ 'rowspan' ] = 1       

        gridSettings[ 'column' ] = 0

        gridSettings[ 'columnspan' ] = 1

        guiFactory.packItem( labelType, gridSettings )

 

 

 

 

 

 

        ############ Radiobutton Types

        self.__radioMarchingCubes = guiFactory.newRadiobutton( self.dialog,

            'Skin', self.__doSetSkinTissue,

            self.__tissue, self.__vtkWindow.SKIN, {} ) 

        gridSettings[ 'column' ] = 1

        guiFactory.packItem( self.__radioMarchingCubes, gridSettings )

 

        self.__radioRaycastComposite = guiFactory.newRadiobutton( self.dialog,

            'Bone',  self.__doSetBoneTissue, self.__tissue,

            self.__vtkWindow.BONE, {} )

        gridSettings[ 'column' ] = 2

        guiFactory.packItem( self.__radioRaycastComposite, gridSettings )

 

 

 

 

 

        ###### Color Picker

        labelColor = guiFactory.newLabel( self.dialog, 'Color',

                                          {'justify':Tkinter.LEFT} )

        gridSettings[ 'row' ] = 1

        gridSettings[ 'column' ] = 0

        gridSettings[ 'columnspan' ] = 1

        guiFactory.packItem( labelColor, gridSettings )

 

        self.__labelColorChanger = guiFactory.newLabel( self.dialog, '',

            {'justify':Tkinter.LEFT, 'width':18} )

        gridSettings[ 'column' ] = 1

        gridSettings[ 'columnspan' ] = 2

        guiFactory.packItem( self.__labelColorChanger, gridSettings )

       

 

 

  • Because the color sliders change 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 __doUpdateColorLabelsEtc 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).

 

 

 

       

        labelRed = guiFactory.newLabel( self.dialog, 'Red',

                                        {'justify':Tkinter.LEFT} )

        gridSettings[ 'row' ] = 2

        gridSettings[ 'column' ] = 0

        gridSettings[ 'columnspan' ] = 1

        guiFactory.packItem( labelRed, gridSettings )

 

        self.__sliderRed = SliderWithValue( self.dialog, 0, 255 )

self.__sliderRed.addSliderCommandBinding( self.__doUpdateColorLabelsEtc )

        self.__widgetRed = self.__sliderRed.getWidget()

        gridSettings[ 'column' ] = 1

        gridSettings[ 'columnspan' ] = 2

        guiFactory.packItem( self.__widgetRed, gridSettings )

 

 

 

 

 

        labelGreen = guiFactory.newLabel( self.dialog, 'Green',

                                          {'justify':Tkinter.LEFT} )

        gridSettings[ 'row' ] = 3

        gridSettings[ 'column' ] = 0

        gridSettings[ 'columnspan' ] = 1

        guiFactory.packItem( labelGreen, gridSettings )

 

        self.__sliderGreen = SliderWithValue( self.dialog, 0, 255 )

        self.__sliderGreen.addSliderCommandBinding( self.__doUpdateColorLabelsEtc )

 

        self.__widgetGreen = self.__sliderGreen.getWidget()

        gridSettings[ 'column' ] = 1

        gridSettings[ 'columnspan' ] = 2

        guiFactory.packItem( self.__widgetGreen, gridSettings )

 

 

 

        labelBlue = guiFactory.newLabel( self.dialog, 'Blue',

                                         {'justify':Tkinter.LEFT} )

        gridSettings[ 'row' ] = 4

        gridSettings[ 'column' ] = 0

        gridSettings[ 'columnspan' ] = 1

        guiFactory.packItem( labelBlue, gridSettings )

 

        self.__sliderBlue = SliderWithValue( self.dialog, 0, 255 )

        self.__sliderBlue.addSliderCommandBinding( self.__doUpdateColorLabelsEtc )

 

        self.__widgetBlue = self.__sliderBlue.getWidget()

        gridSettings[ 'column' ] = 1

        gridSettings[ 'columnspan' ] = 2

        guiFactory.packItem( self.__widgetBlue, gridSettings )

 

        self.__doUpdateColorLabelsEtc()

 

 

        ###### Opacity Value

        self.__labelOpacity = guiFactory.newLabel( self.dialog, 'Opaque (%)',

                                        {'justify':Tkinter.LEFT} )

        gridSettings[ 'row' ] = 5

        gridSettings[ 'column' ] = 0

        gridSettings[ 'columnspan' ] = 1

        guiFactory.packItem( self.__labelOpacity, gridSettings )

 

        self.__sliderOpacity = SliderWithValue( self.dialog, 0, 100 )

        self.__widgetOpacity = self.__sliderOpacity.getWidget()

        gridSettings[ 'column' ] = 1

        guiFactory.packItem( self.__widgetOpacity, gridSettings )

       

  • Similarly, the same case occurs for the opacity slider.  Here, the update function is __doUpdateOpacity.

 

self.__sliderOpacity.addSliderCommandBinding( self.__doUpdateOpacity )   

  • __doUpdateColorLabelsEtc: This private member function will obtain the current values of the sliders, update their adjacent text labels, send a specially formatted string consisting of the hexadecimal values for red, green, and blue to the “color label”, and then update the appropriate isosurface depending on which radiobutton (skin or bone) was selected.  Also note that *unusedArgument is used to get around a mismatch in the parameter count even though this parameter is not used for anything.

 

 

 

 

 

 

 

 

    # Color extraction function adapted from that given in the web resource

    # "An Introduction to Tkinter".

    def __doUpdateColorLabelsEtc( self, *unusedArgument ):

        redValue = self.__sliderRed.getValue()

        greenValue = self.__sliderGreen.getValue()

        blueValue = self.__sliderBlue.getValue()

 

        self.__sliderRed.configureLabel( { 'text':redValue } )

        self.__sliderGreen.configureLabel( { 'text':greenValue } )

        self.__sliderBlue.configureLabel( { 'text':blueValue } )

       

        self.__rgbColor = "#%02x%02x%02x" % ( redValue,

                                              greenValue,

                                              blueValue )

        self.__labelColorChanger.config( background=self.__rgbColor )

 

        tissueValue = self.__tissue.get()

        if ( tissueValue == self.__vtkWindow.SKIN ):

            self.__skinValuesDict[ 'red' ] = redValue

            self.__skinValuesDict[ 'green' ] = greenValue

            self.__skinValuesDict[ 'blue' ] = blueValue

            self.__vtkWindow.updateSurface( self.__skinValuesDict )

 

        elif ( tissueValue == self.__vtkWindow.BONE ):

            self.__boneValuesDict[ 'red' ] = redValue

            self.__boneValuesDict[ 'green' ] = greenValue

            self.__boneValuesDict[ 'blue' ] = blueValue

            self.__vtkWindow.updateSurface( self.__boneValuesDict )   

 

  • __doUpdateOpacity: This private member function will obtain the current values of the opacity slider, update its adjacent text label, and then update the appropriate isosurface depending on which radiobutton (skin or bone) was selected.  Equally as important, it will set its current slider values to values in a hash table so that when a different isosurface is selected, the last correct values can be retrieved.  Also note that *unusedArgument is used to get around a mismatch in the parameter count even though this parameter is not used for anything.

 

 

 

 

 

 

 

    def __doUpdateOpacity( self, *unusedArgument ):

        tissueValue = self.__tissue.get()

        opacityValue = self.__sliderOpacity.getValue()

        self.__sliderOpacity.configureLabel( { 'text':opacityValue } )

 

        if ( tissueValue == self.__vtkWindow.SKIN ):

            self.__skinValuesDict[ 'opaque' ] = opacityValue

            self.__vtkWindow.updateSurface( self.__skinValuesDict )

 

        elif ( tissueValue == self.__vtkWindow.BONE ):

            self.__boneValuesDict[ 'opaque' ] = opacityValue

            self.__vtkWindow.updateSurface( self.__boneValuesDict )       

  • __doSetSkinTissue: This private member function will retrieve the RGB and opacity values from the skin tissue hash and set the slider values with its last settings.  This function will also call the function __doUpdateColorLabelsEtc to update the isosurface if necessary.

    def __doSetSkinTissue( self ):

        self.__tissue.set( self.__vtkWindow.SKIN )

 

        self.__sliderOpacity.setScaleValue( self.__skinValuesDict[ 'opaque' ] )

        self.__doUpdateOpacity()

       

        self.__sliderRed.setScaleValue( self.__skinValuesDict[ 'red' ] )

        self.__sliderGreen.setScaleValue( self.__skinValuesDict[ 'green' ] )

        self.__sliderBlue.setScaleValue( self.__skinValuesDict[ 'blue' ] )

        self.__doUpdateColorLabelsEtc()   

  • __ doSetBoneTissue: This private member function will retrieve the RGB and opacity values from the bone tissue hash and set the slider values with its last settings.  This function will also call the function __doUpdateColorLabelsEtc to update the isosurface if necessary.

    def __doSetBoneTissue( self ):

        self.__tissue.set( self.__vtkWindow.BONE )

 

        self.__sliderOpacity.setScaleValue( self.__boneValuesDict[ 'opaque' ] )

        self.__doUpdateOpacity()

       

        self.__sliderRed.setScaleValue( self.__boneValuesDict[ 'red' ] )

        self.__sliderGreen.setScaleValue( self.__boneValuesDict[ 'green' ] )

        self.__sliderBlue.setScaleValue( self.__boneValuesDict[ 'blue' ] )

        self.__doUpdateColorLabelsEtc()

 

Example 4.4: Code for DialogIsosurfaces class

 

 

 

<<< Previous

DialogOptionVOI

 

 

Table of Contents

 

 

Next >>>

Main Part of Program