Isosurface Generation Using VTK
|
||||||||
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() |
|||||||
|
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 ) |
|||||||
|
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
) |
|||||||
|
self.__sliderOpacity.addSliderCommandBinding( self.__doUpdateOpacity
) |
|||||||
|
# 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 ) |
|||||||
|
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 ) |
|||||||
|
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() |
|||||||
|
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 |
|||||||
|
||||||||
|
||||||||
|
|
|
|
|
||||