Package Pmv :: Module grid3DCommands
[hide private]
[frames] | no frames]

Source Code for Module Pmv.grid3DCommands

   1  ######################################################################## 
   2  # 
   3  # Authors: Sargis Dallakyan, Michel Sanner 
   4  # 
   5  #    sargis@scripps.edu 
   6  #    sanner@scripps.edu 
   7  # 
   8  #       The Scripps Research Institute (TSRI) 
   9  #       Molecular Graphics Lab 
  10  #       La Jolla, CA 92037, USA 
  11  # 
  12  # Copyright: Sargis Dallakyan, Michel Sanner and TSRI 
  13  # 
  14  ######################################################################### 
  15  #  
  16  # $Header: /opt/cvs/python/packages/share1.5/Pmv/grid3DCommands.py,v 1.61.2.4 2007/09/17 20:30:31 vareille Exp $ 
  17  # $Id: grid3DCommands.py,v 1.61.2.4 2007/09/17 20:30:31 vareille Exp $ 
  18  """This module integrates Volume.Grid3D with PMV for rendering 3D Grids. 
  19  It includes Add/Remove, Isocontour, OrthoSlice and VolRender commands, and a  
  20  table widget for navigating between grids.  
  21  """ 
  22  import sys 
  23  import re, types, os, math, pickle 
  24  import Tkinter, Pmw, tkFileDialog, tkMessageBox 
  25  import Image, ImageTk 
  26  from tkColorChooser import askcolor 
  27  from DejaVu.Geom import Geom 
  28  from Pmv.mvCommand import MVCommand, MVCommandGUI 
  29  from ViewerFramework.VFCommand import CommandGUI 
  30  from mglutil.gui import widgetsOnBackWindowsCanGrabFocus 
  31  from mglutil.gui.BasicWidgets.Tk.customizedWidgets import ListChooser 
  32  from mglutil.gui.InputForm.Tk.gui import InputFormDescr, InputForm 
  33  from mglutil.gui.BasicWidgets.Tk.multiListbox import MultiListbox 
  34  from Volume.IO.volReaders import ReadMRC, ReadCCP4, ReadCNS, ReadGRD, ReadBRIX,\ 
  35                                      ReadSPIDER, ReadRawiv, ReadEM, ReadFLDBinary 
  36  from Volume.IO.volWriters import WriteCCP4 
  37  from Volume.IO.UHBDGridReader import UHBDReaderASCII 
  38  from Volume.IO.DelphiReader import DelphiReaderBin 
  39  from Volume.IO.dxReader import ReadDX 
  40  from Volume.IO.AutoGridReader import ReadAutoGrid 
  41  from Volume.IO.gamessOrbitalsReader import ReadGamessOrbitals 
  42  from Volume.Grid3D import Grid3D, Grid3DD, Grid3DF, Grid3DI, \ 
  43       Grid3DSI, Grid3DUI, Grid3DUSI, Grid3DUC, ArrayTypeToGrid, GridTypeToArray 
  44  from Volume.Renderers.UTVolumeLibrary.DejaVu.UTVolRenGeom import UTVolRenGeom      
  45  from mglutil.util.packageFilePath import findFilePath 
  46  from DejaVu.extendedSlider import ExtendedSlider 
  47  try: 
  48      from UTpackages.UTisocontour import isocontour 
  49  except ImportError: 
  50      isocontour = None 
  51   
  52  from DejaVu.IndexedPolygons import IndexedPolygons 
  53  from DejaVu.Box import Box 
  54  from DejaVu.Textured2DArray import textured2DArray 
  55  import Numeric 
  56  from AutoDockTools.histogram import Histogram 
  57  from DejaVu.colorMap import ColorMap 
  58  from DejaVu.ColormapGui import ColorMapGUI 
  59  from opengltk.OpenGL import GL 
  60  Grid_ICONPATH = findFilePath('Icons', 'Pmv') 
  61  Grid_ICONPATH = os.path.join(Grid_ICONPATH, 'Grid3D') 
  62  if sys.platform == 'darwin': 
  63      rightClick = "Apple-Click" 
  64  else: 
  65      rightClick = "Right-Click" 
66 -def get_icon(icon):
67 iconfile = os.path.join(Grid_ICONPATH, icon) 68 head, ext = os.path.splitext(iconfile) 69 if ext == '.gif': 70 Icon = Tkinter.PhotoImage(file=iconfile) 71 else: 72 image = Image.open(iconfile) 73 Icon = ImageTk.PhotoImage(image=image) 74 return Icon
75 76 typecodeDict = {'D':'Complex64', 'F':'Complex32', 'd':'Float64', 'f':'Float32', 77 'l':'Int32', 'i':'Int32', 's':'Int16', '1':'Int8', 78 'u':'UInt32', 'w':'UInt16','b':'UInt8'} 79
80 -class readAnyGrid(MVCommand):
81 """ The readAnyGrid reads any of the grids supported by Volume.IO and 82 saves Grid3D object in self.vf.grids3D[gridFile] where gridFile can be provided 83 by Grid3D-->Read GUI 84 \nPackage : Pmv 85 \nModule : grid3DCommands 86 \nClass : readAnyGrid 87 \nCommand : readAnyGrid 88 \nSynopsis:\n 89 grid3D<-readAnyGrid(gridFile)\n 90 \nRequired Arguments:\n 91 gridFile : location of the grid file\n 92 """
93 - def __init__(self, func=None):
94 MVCommand.__init__(self) 95 self.grid_counter = 0 96 self.ifd=InputFormDescr(title='Map Types') 97 mapItems = [('AutoGrid',None), 98 ('BRIX/DSN6',None), 99 ('CCP4',None), 100 ('CNS/XPLOR',None), 101 ('Data Explorer(DX)',None), 102 ('Delphi',None), 103 ('GRD',None), 104 ('MRC',None), 105 ('Rawiv',None), 106 ('SPIDER',None), 107 ('UHBD/GRID',None), 108 ('AVS/FLD Binary',None), 109 ] 110 self.ifd.append({'name':'listchooser', 111 'widgetType':ListChooser, 112 'wcfg':{'title':'Select a Map Type:', 113 'entries':mapItems, 114 'lbwcfg':{'width':20,'height':12}, 115 'mode':'single', 116 }, 117 'gridcfg':{'sticky':'w','row':-1} 118 })
119
120 - def onAddCmdToViewer(self):
121 if not hasattr(self.vf, 'grids3D'): 122 self.vf.grids3D={}
123
124 - def __call__(self, gridFile, **kw):
125 """Grid3D object<-readAnyGrid(gridFile)\n 126 \nRequired Arguments:\n 127 gridFile : location of the grid file\n 128 """ 129 return apply(self.doitWrapper, (gridFile,), kw)
130
131 - def doit(self, gridFile, name=None, show=True, normalize=True):
132 """Reads gridFile and adds it to Control Panel 133 Optoinal Arguments: 134 name : name of the grid file used as a key in self.vf.grid3d 135 if None os.path.basename(gridFile) is used 136 show : if True show Control panel 137 normalize : if true calls Normalize the Viewer 138 """ 139 if not gridFile: return 140 else: 141 if(re.search('\.mrc$',gridFile,re.I)): 142 reader = ReadMRC() 143 elif(re.search('\.ccp4*$',gridFile,re.I)): 144 reader = ReadCCP4() 145 elif(re.search('\.cns$|\.xplo*r*$',gridFile,re.I)): 146 reader = ReadCNS() 147 elif(re.search('\.grd$',gridFile,re.I)): 148 reader = ReadGRD() 149 elif(re.search('\.fld$',gridFile,re.I)): 150 reader = ReadFLDBinary() 151 elif(re.search('\.map$',gridFile,re.I)): 152 reader = ReadAutoGrid() 153 elif(re.search('\.omap$|\.brix$|\.dsn6$|\.dn6$',gridFile,re.I)): 154 reader = ReadBRIX() 155 elif(re.search('\.rawiv$',gridFile,re.I)): 156 reader = ReadRawiv() 157 elif(re.search('\.d*e*l*phi$',gridFile,re.I)): 158 reader = DelphiReaderBin() 159 elif(re.search('\.uhbd$',gridFile,re.I)): 160 reader = UHBDReaderASCII() 161 elif(re.search('\.dx$',gridFile,re.I)): 162 reader = ReadDX() 163 elif(re.search('\.spi$',gridFile,re.I)): 164 reader = ReadSPIDER() 165 else: 166 reader = self.askMapType() 167 if not reader: 168 return 169 try: 170 grid3D = reader.read(gridFile, normalize=True) 171 except Exception, inst: 172 print inst 173 reader = self.askMapType() 174 if not reader: 175 return 176 try: 177 grid3D = reader.read(gridFile, normalize=True) 178 except Exception, inst: 179 print inst 180 tkMessageBox.showerror("Error: in choosing a map", 181 "Could not parse %s. Please open Python shell for Traceback"%gridFile) 182 183 if not grid3D: 184 reader = self.askMapType() 185 if not reader: 186 return 187 try: 188 grid3D = reader.read(gridFile, normalize=True) 189 except Exception, inst: 190 print inst 191 tkMessageBox.showerror("Error: in choosing a map", 192 "Could not parse %s. Please open Python shell for Traceback"%gridFile) 193 194 if name: 195 grid_basename = name 196 else: 197 grid_basename = os.path.basename(gridFile) 198 if grid3D: 199 self.grid_counter += 1 200 grid3D.path = gridFile 201 grid3D.origin_copy = grid3D.origin 202 grid3D.stepSize_copy = grid3D.stepSize 203 mini, maxi, mean, std = grid3D.stats() 204 grid3D.mini = mini 205 grid3D.maxi = maxi 206 grid3D.mean = mean 207 grid3D.std = std 208 209 if self.vf.grids3D.has_key(grid_basename): 210 grid_basename += "_"+str(self.grid_counter) 211 def returnStringRepr(): 212 return None, "\"" + grid_basename + "\""
213 grid3D.returnStringRepr = returnStringRepr 214 if not hasattr(grid3D,'geomContainer'): 215 grid3D.geomContainer = {} 216 g = Geom(grid_basename) 217 grid3D.master_geom = g 218 self.vf.GUI.VIEWER.AddObject(g) 219 grid3D.geomContainer['IsoSurf'] = {} 220 grid3D.geomContainer['OrthoSlice'] = {} 221 IsoSurf = Geom('IsoSurf') 222 OrthoSlice = Geom('OrthoSlice') 223 box = Box('BoundingBox') 224 225 pt1 = grid3D.origin 226 dims = grid3D.data.shape 227 pt2 = [pt1[0]+(grid3D.stepSize[0]*(dims[0]-1)), 228 pt1[1]+(grid3D.stepSize[1]*(dims[1]-1)), 229 pt1[2]+(grid3D.stepSize[2]*(dims[2]-1))] 230 if grid3D.crystal: 231 ptList=((pt2[0],pt2[1],pt1[2]), 232 (pt1[0],pt2[1],pt1[2]), 233 (pt1[0],pt1[1],pt1[2]), 234 (pt2[0],pt1[1],pt1[2]), 235 (pt2[0],pt2[1],pt2[2]), 236 (pt1[0],pt2[1],pt2[2]), 237 (pt1[0],pt1[1],pt2[2]), 238 (pt2[0],pt1[1],pt2[2])) 239 coords = grid3D.crystal.toCartesian(ptList) 240 box.Set(vertices=coords) 241 else: 242 coords = (pt1, pt2) 243 box.Set(cornerPoints=coords) 244 245 grid3D.geomContainer['Box'] = box 246 self.vf.GUI.VIEWER.AddObject(box,parent=g) 247 self.vf.GUI.VIEWER.AddObject(IsoSurf,parent=g) 248 self.vf.GUI.VIEWER.AddObject(OrthoSlice,parent=g) 249 grid3D.IsoSurf = IsoSurf 250 grid3D.OrthoSlice = OrthoSlice 251 if normalize: 252 self.vf.GUI.VIEWER.Normalize_cb() 253 self.vf.grids3D[grid_basename] = grid3D 254 255 if self.vf.Grid3DCommands.root: 256 grid_name = grid_basename 257 grid_type = typecodeDict[grid3D.data.typecode()] 258 self.vf.Grid3DCommands.mlb.insert(Tkinter.END, (grid_name, 259 grid3D.dimensions, grid_type )) 260 261 if show: 262 self.vf.Grid3DCommands.show() 263 #self.vf.Grid3DCommands.mlb.selection_clear(0, Tkinter.END) 264 #self.vf.Grid3DCommands.mlb.selection_set(Tkinter.END) 265 #self.vf.Grid3DAddRemove.select() 266 267 return grid3D
268
269 - def askMapType(self):
270 """Opens Select Map Type widget""" 271 f = InputForm(master=Tkinter._default_root, 272 root=Tkinter.Toplevel(), 273 descr=self.ifd, blocking=1, modal=1) 274 maptype=f.go() 275 if not maptype: 276 return False 277 choice=maptype['listchooser'][0] 278 if choice=='AutoGrid': reader=ReadAutoGrid() 279 elif choice=='BRIX/DSN6': reader=ReadBRIX() 280 elif choice=='CCP4': reader=ReadCCP4() 281 elif choice=='CNS/XPLOR': reader=ReadCNS() 282 elif choice=='Data Explorer(DX)': reader=ReadDX() 283 elif choice=='Delphi': reader=DelphiReaderBin() 284 elif choice=='GRD':reader=ReadGRD() 285 elif choice=='MRC':reader=ReadMRC() 286 elif choice=='Rawiv':reader=ReadRawiv() 287 elif choice=='SPIDER':reader=ReadSPIDER() 288 elif choice=='UHBD/GRID':reader=UHBDReaderASCII() 289 elif choice=='AVS/FLD Binarcmd.y':self.reader=ReadFLDBinary() 290 else: 291 tkMessageBox.showerror("Error: in choosing a map", 292 "Error: in choosing" + choice) 293 return False 294 return reader
295
296 - def guiCallback(self, parent = None):
297 """called each time the 'Grid3D -> Import...' sequence is pressed""" 298 fileTypes = [('All supported files', '*.map *.fld *.ccp4 *.dx *.grd '+ 299 '*.omap *.brix* *.dsn6* *.cns *.xplo*r* *.d*e*l*phi *.mrc *.rawiv *.spi *.uhbd'), 300 ('AutoGrid', '*.map'), 301 ('AVS/FLD Binary', '*.fld'), 302 ('BRIX/DSN6', '*.omap *.brix* *.dsn6*'), 303 ('CCP4', '*.ccp4'), 304 ('CNS/XPLOR', '*.cns *.xplo*r*'), 305 ('Data Explorer(DX)', '*.dx'), 306 ('Delphi', '*.d*e*l*phi'), 307 ('GRD', '*.grd'), 308 ('MRC', '*.mrc'), 309 ('Rawiv', '*.rawiv'), 310 ('SPIDER', '*.spi'), 311 ('UHBD/GRID', '*.uhbd'), 312 ('all', '*')] 313 gridFile = tkFileDialog.askopenfilename(parent = parent, 314 filetypes=fileTypes, title = 'Grid File:') 315 if gridFile is not None and len(gridFile): 316 self.doitWrapper(gridFile, redraw=0)
317 318 readAnyGridGUI = CommandGUI() 319 readAnyGridGUI.addMenuCommand('menuRoot', 'Grid3D', 'Read...') 320
321 -class GridMultiListbox(MultiListbox):
322 """Extends MultiListbox from mglutil.gui.BasicWidgets.Tk.multiListbox"""
323 - def __init__(self, master, lists, **kw):
324 MultiListbox.__init__(self, master, lists, **kw) 325 self.girdName = ''
326 - def _select(self, y):
327 self.Grid3DCommands.root.config(cursor='watch') 328 self.Grid3DCommands.root.update() 329 row = self.lists[0].nearest(y) 330 self.selection_clear(0, Tkinter.END) 331 self.selection_set(row) 332 if row != -1: 333 girdName = self.Grid3DCommands.get_grid_name() 334 if girdName != self.girdName: 335 self.Grid3DCommands.current_cmd.select() 336 self.girdName = girdName 337 self.Grid3DCommands.root.config(cursor='') 338 return 'break'
339 340 width = 440 #width of the GUI 341 height = 200 #height of the GUI 342
343 -class Grid3DCommands(MVCommand):
344 """This is the main class that adds GridMultiListbox widget with 345 Add/Remove, Isocontour and OrthoSlice icons and widgets 346 """
347 - def __init__(self, func=None):
348 MVCommand.__init__(self) 349 self.root = None 350 self.Icons = [] 351 self.Checkbuttons = {}
352
353 - def onAddCmdToViewer(self):
354 if not hasattr(self.vf, 'grids3D'): 355 self.vf.grids3D={}
356
357 - def get_grid_name(self):
358 select = self.mlb.curselection() 359 if not select: 360 return None 361 grid_name = self.mlb.get(select[0]) 362 return grid_name[0]
363
364 - def select(self, name):
365 "Selects Listbox by Grid Name" 366 grids = self.mlb.lists[0].get(0,Tkinter.END) 367 grids = list(grids) 368 index = grids.index(name) 369 self.mlb.selection_clear(0,Tkinter.END) 370 self.mlb.selection_set(index)
371
372 - def doit(self, show = True, **kw):
373 if show: 374 self.show() 375 else: 376 self.hide()
377
378 - def guiCallback(self, **kw):
379 if not self.root: 380 self.root = Tkinter.Toplevel() 381 self.root.title('3D Grid Rendering Control Panel') 382 self.root.protocol("WM_DELETE_WINDOW", self.hide) 383 menu = Tkinter.Menu(self.root) 384 self.root.config(menu=menu) 385 self.root.minsize(width+5,width-5) 386 file = Tkinter.Menu(menu) 387 file.add_command(label='Open Grid...', 388 command=self.vf.Grid3DAddRemove.add) 389 file.add_command(label='Load Settings...', command=self.open) 390 file.add_command(label='Save Settings...', command=self.save) 391 392 menu.add_cascade(label='File', menu=file) 393 394 self.PanedWindow = Tkinter.PanedWindow(self.root, handlepad=0, 395 handlesize=0, orient=Tkinter.VERTICAL, bd=1, 396 width=width,height=2*height) 397 self.PanedWindow.pack(fill=Tkinter.BOTH, expand=1) 398 399 self.mlb = GridMultiListbox(self.PanedWindow, ((' Grid Name', 33), 400 ('Dimensions ', 15), 401 ('Type', 6)), 402 hull_height = 100, 403 usehullsize = 1, 404 hull_width = width) 405 406 self.mlb.pack(expand=Tkinter.NO, fill=Tkinter.X) 407 self.mlb.Grid3DCommands = self 408 for grid in self.vf.grids3D: 409 grid_name = grid 410 # if len(grid_name) > 40: 411 # grid_name = grid_name[-37:] 412 # grid_name = '...'+grid_name 413 grid_type = typecodeDict[self.vf.grids3D[grid].data.typecode()] 414 self.vf.Grid3DCommands.mlb.insert(Tkinter.END, (grid_name, 415 self.vf.grids3D[grid].dimensions, grid_type )) 416 self.PanedWindow.add(self.mlb) 417 418 main_frame = Tkinter.Frame(self.PanedWindow) 419 main_frame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) 420 self.PanedWindow.add(main_frame, height=height+90) 421 toolbar_frame = Tkinter.Frame(main_frame, bg='white', 422 relief=Tkinter.RIDGE, bd=2) 423 toolbar_frame.pack(expand=Tkinter.NO, fill=Tkinter.X) 424 self.toolbar_frame = toolbar_frame 425 widget_frame = Tkinter.Frame(main_frame) 426 widget_frame.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) 427 428 self.widget_frame = widget_frame 429 cmd_list = [ 430 ('Add/Remove', 'add_rem.png', self.Add_Remove, 'Add/Remove 3D Gird')] 431 if isocontour: 432 cmd_list.append(('Isocontour', 'iso.png', self.Isocontour, 433 'Isocontouring Widget')) 434 cmd_list.append(('OrthoSlice', 'ortho.png', self.OrthoSlice, 435 'Orthogonal Slices')) 436 from Volume.Renderers.UTVolumeLibrary import UTVolumeLibrary 437 test = UTVolumeLibrary.VolumeRenderer() 438 flag = test.initRenderer() 439 if flag: 440 cmd_list.append(('VolRen', 'VolRen.png', self.VolRen, 441 '3D Texture-Based Volume Renderer')) 442 else: 443 print "Volume Renderer is Disabled" 444 #font LucidaTypewriter Marumoji, MiscFixed 14 445 for name, icon, func, txt in cmd_list: 446 Icon = get_icon(icon) 447 self.Icons.append(Icon) 448 Checkbutton = Tkinter.Checkbutton(toolbar_frame, image=Icon, 449 indicatoron=0, command=func, 450 bg='white') 451 Checkbutton.ballon = Pmw.Balloon() 452 Checkbutton.ballon.bind(Checkbutton, txt) 453 self.Checkbuttons[name] = Checkbutton 454 Checkbutton.pack(side=Tkinter.LEFT) 455 456 457 idf = self.vf.Grid3DAddRemove.ifd 458 self.add_remove_form = InputForm(main_frame,self.widget_frame,idf, 459 okcancel=0,closeWithWindow=0, 460 width=width, height=height) 461 self.add_remove_form.mf.config(bd =0) 462 self.add_remove_form.mf.pack_forget() 463 idf = self.vf.Grid3DIsocontour.ifd 464 self.isocontour_form = InputForm(main_frame,self.widget_frame,idf, 465 okcancel=0,closeWithWindow=0, 466 width=width, height=height) 467 self.isocontour_form.mf.config(bd =0) 468 self.isocontour_form.mf.pack_forget() 469 470 idf = self.vf.Grid3DOrthoSlice.ifd 471 self.OrthoSlice_form = InputForm(main_frame,self.widget_frame,idf, 472 okcancel=0,closeWithWindow=0, 473 width=width, height=height) 474 self.OrthoSlice_form.mf.config(bd =0) 475 self.OrthoSlice_form.mf.pack_forget() 476 477 idf = self.vf.Grid3DVolRen.ifd 478 self.VolRen_form = InputForm(main_frame,self.widget_frame,idf, 479 okcancel=0,closeWithWindow=0, 480 width=width, height=height) 481 self.VolRen_form.mf.config(bd =0) 482 self.VolRen_form.mf.pack_forget() 483 484 self.add_remove_form.mf.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) 485 self.current_obj = self.add_remove_form 486 self.current_cmd = self.vf.Grid3DAddRemove 487 bottom_frame = Tkinter.Frame(main_frame) 488 bottom_frame.pack(fill=Tkinter.X) 489 self.close_b = Tkinter.Button(bottom_frame, text=" Dismiss ", 490 command=self.hide) 491 self.close_b.pack(expand=Tkinter.NO) 492 self.current_checkbutton = self.Checkbuttons['Add/Remove'] 493 self.current_checkbutton.toggle() 494 self.vf.GUI.toolbarCheckbuttons['Grid3D']['Variable'].set(1) 495 self.GUI.menuButton.menu.entryconfig(3, label='Hide Control Panel', 496 command=self.hide) 497 h = self.root.winfo_reqheight() 498 w = self.mlb.interior().winfo_reqwidth() 499 if w > self.root.winfo_width(): 500 self.root.geometry('%dx%d' % (w,h)) 501 502 elif self.vf.GUI.toolbarCheckbuttons['Grid3D']['Variable'].get() == 0 \ 503 and self.root: 504 self.root.withdraw() 505 self.GUI.menuButton.menu.entryconfig(3,label='Show Control Panel', 506 command=self.show) 507 508 509 elif self.vf.GUI.toolbarCheckbuttons['Grid3D']['Variable'].get() == 1 \ 510 and self.root: 511 self.root.deiconify() 512 self.GUI.menuButton.menu.entryconfig(3,label='Hide Control Panel', 513 command=self.hide)
514
515 - def show(self, event=None):
516 if self.root is None: 517 self.guiCallback() 518 else: 519 self.root.deiconify() 520 self.vf.GUI.toolbarCheckbuttons['Grid3D']['Variable'].set(1) 521 self.GUI.menuButton.menu.entryconfig(3, label='Hide Control Panel', 522 command=self.hide)
523
524 - def hide(self, event=None):
525 if self.root: 526 self.root.withdraw() 527 self.vf.GUI.toolbarCheckbuttons['Grid3D']['Variable'].set(0) 528 self.GUI.menuButton.menu.entryconfig(3,label='Show Control Panel', 529 command=self.show)
530
531 - def Add_Remove(self):
532 if self.current_cmd == self.vf.Grid3DVolRen: 533 self.current_cmd.ifd.entryByName['VolRen']['widget'].merge_function() 534 self.current_cmd.saveLUT_Dict() 535 self.current_checkbutton.config(state='normal') 536 self.current_checkbutton.toggle() 537 self.current_obj.mf.pack_forget() 538 self.add_remove_form.mf.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) 539 self.current_obj = self.add_remove_form 540 self.Checkbuttons['Add/Remove'].config(state='disabled') 541 self.current_checkbutton = self.Checkbuttons['Add/Remove'] 542 self.current_cmd = self.vf.Grid3DAddRemove 543 self.current_cmd.select()
544
545 - def Isocontour(self):
546 self.root.configure(cursor='watch') 547 self.root.update() 548 if self.current_cmd == self.vf.Grid3DVolRen: 549 self.current_cmd.ifd.entryByName['VolRen']['widget'].merge_function() 550 self.current_cmd.saveLUT_Dict() 551 self.current_checkbutton.config(state='normal') 552 self.current_checkbutton.toggle() 553 self.current_obj.mf.pack_forget() 554 self.isocontour_form.mf.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) 555 self.current_obj = self.isocontour_form 556 self.Checkbuttons['Isocontour'].config(state='disabled') 557 self.current_checkbutton = self.Checkbuttons['Isocontour'] 558 self.current_cmd = self.vf.Grid3DIsocontour 559 self.current_cmd.select()
560
561 - def OrthoSlice(self):
562 self.root.configure(cursor='watch') 563 self.root.update() 564 #This in needed to save the VolRen 565 if self.current_cmd == self.vf.Grid3DVolRen: 566 self.current_cmd.ifd.entryByName['VolRen']['widget'].merge_function() 567 self.current_cmd.saveLUT_Dict() 568 self.current_checkbutton.config(state='normal') 569 self.current_checkbutton.toggle() 570 self.current_obj.mf.pack_forget() 571 self.OrthoSlice_form.mf.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) 572 self.current_obj = self.OrthoSlice_form 573 self.Checkbuttons['OrthoSlice'].config(state='disabled') 574 self.current_checkbutton = self.Checkbuttons['OrthoSlice'] 575 self.current_cmd = self.vf.Grid3DOrthoSlice 576 self.current_cmd.select()
577
578 - def VolRen(self):
579 self.root.configure(cursor='watch') 580 self.root.update() 581 self.current_checkbutton.config(state='normal') 582 self.current_checkbutton.toggle() 583 self.current_obj.mf.pack_forget() 584 self.VolRen_form.mf.pack(expand=Tkinter.YES, fill=Tkinter.BOTH) 585 self.current_obj = self.VolRen_form 586 self.Checkbuttons['VolRen'].config(state='disabled') 587 self.current_checkbutton = self.Checkbuttons['VolRen'] 588 self.current_cmd = self.vf.Grid3DVolRen 589 self.current_cmd.select()
590
591 - def save(self):
592 outFile = tkFileDialog.asksaveasfile(parent=self.root, 593 filetypes=[('Grid settings', 594 '*.pkl')], 595 title='Save Grid Control Panel File As:') 596 if not outFile: 597 return 598 self.vf.Grid3DCommands.root.config(cursor='watch') 599 settings = [] 600 for gridName in self.vf.grids3D: 601 gridSettings = {} 602 gridSettings['name'] = gridName 603 grid = self.vf.grids3D[gridName] 604 gridSettings['path'] = grid.path 605 gridSettings['origin'] = grid.origin 606 gridSettings['stepSize'] = grid.stepSize 607 gridSettings['boxVisible'] = grid.geomContainer['Box'].visible 608 gridSettings['masterVisible'] = grid.master_geom.visible 609 if hasattr(grid,'isoBarNumber'): #saves Isocontour attributes 610 gridSettings['isoBarNumber'] = grid.isoBarNumber 611 gridSettings['isoBarTags'] = grid.isoBarTags 612 gridSettings['isoLastColor'] = grid.isoLastColor 613 gridSettings['isoLastX'] = grid.isoLastX 614 if hasattr(grid,'_X_Slice'): #saves OrthSlice attributes 615 gridSettings['_X_Slice'] = grid._X_Slice 616 gridSettings['_X_Vis'] = grid._X_Vis 617 if hasattr(grid,'_Y_Slice'): 618 gridSettings['_Y_Slice'] = grid._Y_Slice 619 gridSettings['_Y_Vis'] = grid._Y_Vis 620 if hasattr(grid,'_Z_Slice'): 621 gridSettings['_Z_Slice'] = grid._Z_Slice 622 gridSettings['_Z_Vis'] = grid._Z_Vis 623 if hasattr(grid,'volRenGrid'): #saves volRenGrid attributes 624 gridSettings['LUTintervals_list'] = grid.LUT_data.intervals_list 625 gridSettings['LUTshapes'] = grid.LUT_data.shapes 626 gridSettings['LUTvalues'] = grid.LUT_data.values 627 gridSettings['LUTcolor_arr'] = grid.LUT_data.color_arr 628 gridSettings['LUTalpha_arr'] = grid.LUT_data.alpha_arr 629 settings.append(gridSettings) 630 pickle.dump(settings, outFile) 631 outFile.close() 632 self.vf.Grid3DCommands.root.config(cursor='') 633 self.vf.Grid3DCommands.PanedWindow.config(cursor='')
634
635 - def open(self):
636 inFile = tkFileDialog.askopenfile(parent=self.root, 637 filetypes=[('Grid settings', 638 '*.pkl'), 639 ('all', '*') ], 640 title='Open Grid Control Panel File:') 641 if not inFile: 642 return 643 self.vf.Grid3DCommands.root.config(cursor='watch') 644 645 settings = pickle.load(inFile) 646 for gridSettings in settings: 647 self.vf.Grid3DReadAny.doit(gridSettings['path'], 648 name=gridSettings['name']) 649 grid = self.vf.grids3D[gridSettings['name']] 650 grid.origin = gridSettings['origin'] 651 grid.stepSize = gridSettings['stepSize'] 652 grid.geomContainer['Box'].visible = gridSettings['boxVisible'] 653 grid.master_geom.visible = gridSettings['masterVisible'] 654 if gridSettings.has_key('isoBarNumber'): 655 grid.isoBarNumber = gridSettings['isoBarNumber'] 656 grid.isoBarTags = gridSettings['isoBarTags'] 657 grid.isoLastColor = gridSettings['isoLastColor'] 658 grid.isoLastX = gridSettings['isoLastX'] 659 660 origin = Numeric.array(grid.origin).astype('f') 661 stepsize = Numeric.array(grid.stepSize).astype('f') 662 data = grid.data 663 if data.typecode()!=Numeric.Float32: 664 data = data.astype('f') 665 self.vf.Grid3DIsocontour.newgrid3D = Numeric.reshape( 666 Numeric.transpose(data), 667 (1, 1)+tuple(data.shape) ) 668 if self.vf.Grid3DIsocontour.iso_data: 669 isocontour.delDatasetReg(self.vf.Grid3DIsocontour.iso_data) 670 self.vf.Grid3DIsocontour.iso_data = isocontour.\ 671 newDatasetRegFloat3D(self.vf.Grid3DIsocontour.newgrid3D, 672 origin, stepsize) 673 for i in range(1, grid.isoBarNumber+1): 674 tag = grid.isoBarTags[i-1] 675 if grid.isoLastX[tag]<0: 676 invertNormals = True 677 else: 678 invertNormals = False 679 color = grid.isoLastColor[tag] 680 r = int(color[1:3], 16) 681 g = int(color[3:5], 16) 682 b = int(color[5:7], 16) 683 self.vf.Grid3DIsocontour.doit(grid, name=tag, 684 isovalue=grid.isoLastX[tag], 685 invertNormals=invertNormals, 686 material=(r/255., g/255., b/255, 0.5)) 687 if gridSettings.has_key('_X_Slice'): 688 grid._X_Slice = gridSettings['_X_Slice'] 689 grid._X_Vis = gridSettings['_X_Vis'] 690 geom = textured2DArray('OrthoSlice_X', 691 inheritLighting=False, 692 lighting=False) 693 self.vf.GUI.VIEWER.AddObject(geom, parent=grid.OrthoSlice) 694 grid.geomContainer['OrthoSlice']['X'] = geom 695 data, vertices = grid.get2DOrthoSlice('x', grid._X_Slice) 696 geom.Set(vertices=vertices, array=data, visible=grid._X_Vis) 697 if gridSettings.has_key('_Y_Slice'): 698 grid._Y_Slice = gridSettings['_Y_Slice'] 699 grid._Y_Vis = gridSettings['_Y_Vis'] 700 geom = textured2DArray('OrthoSlice_Y', 701 inheritLighting=False, 702 lighting=False) 703 self.vf.GUI.VIEWER.AddObject(geom, parent=grid.OrthoSlice) 704 grid.geomContainer['OrthoSlice']['Y'] = geom 705 data, vertices = grid.get2DOrthoSlice('y', grid._Y_Slice) 706 geom.Set(vertices=vertices, array=data, visible=grid._Y_Vis) 707 if gridSettings.has_key('_Z_Slice'): 708 grid._Z_Slice = gridSettings['_Z_Slice'] 709 grid._Z_Vis = gridSettings['_Z_Vis'] 710 geom = textured2DArray('OrthoSlice_Z', 711 inheritLighting=False, 712 lighting=False) 713 self.vf.GUI.VIEWER.AddObject(geom, parent=grid.OrthoSlice) 714 grid.geomContainer['OrthoSlice']['Z'] = geom 715 data, vertices = grid.get2DOrthoSlice('z', grid._Z_Slice) 716 geom.Set(vertices=vertices, array=data, visible=grid._Z_Vis) 717 if gridSettings.has_key('LUTintervals_list'): 718 from Volume.Operators.MapData import MapGridData 719 datamap = {} 720 datamap['src_min'] = grid.mini 721 datamap['src_max'] = grid.maxi 722 datamap['dst_min'] = 0 723 datamap['dst_max'] = 255 724 datamap['map_type'] = 'linear' 725 mapper = MapGridData() 726 result = mapper(grid.data, datatype=Numeric.UInt8, datamap=datamap, 727 powerOf2=True) 728 gtype = ArrayTypeToGrid[result.typecode()] 729 if grid.crystal: 730 from mglutil.math.crystal import Crystal 731 crystal = Crystal( grid.crystal.length, grid.crystal.angles) 732 else: 733 crystal = None 734 newgrid = gtype(result, grid.origin, grid.stepSize, 735 grid.header.copy(), crystal) 736 newgrid.dataDims = grid.data.shape[:] 737 grid.volRenGrid = newgrid 738 geom = UTVolRenGeom('VolRender') 739 grid.geomContainer['VolRender'] = geom 740 self.vf.GUI.VIEWER.AddObject(geom, parent=grid.master_geom) 741 geom.AddGrid3D(newgrid) 742 self.vf.GUI.VIEWER.OneRedraw() 743 grid.LUT_data = LUT_data() 744 grid.LUT_data.intervals_list = gridSettings['LUTintervals_list'] 745 grid.LUT_data.shapes = gridSettings['LUTshapes'] 746 grid.LUT_data.values = gridSettings['LUTvalues'] 747 grid.LUT_data.color_arr = gridSettings['LUTcolor_arr'] 748 grid.LUT_data.alpha_arr = gridSettings['LUTalpha_arr'] 749 geom.setVolRenAlpha([0,grid.LUT_data.alpha_arr]) 750 geom.setVolRenColors([0,grid.LUT_data.color_arr]) 751 752 inFile.close() 753 self.vf.Grid3DCommands.root.config(cursor='') 754 self.vf.Grid3DCommands.PanedWindow.config(cursor='')
755 756 Grid3DGUI = MVCommandGUI() 757 msg = '3D Grid/Volume Rendering' 758 from moleculeViewer import ICONPATH 759 Grid3DGUI.addToolBar('Grid3D', icon1='vol.png', balloonhelp=msg, index=13., 760 icon_dir=ICONPATH) 761 Grid3DGUI.addMenuCommand('menuRoot', 'Grid3D', 'Show Control Panel') 762
763 -class AddRemove(MVCommand):
764 - def __init__(self, func=None):
765 MVCommand.__init__(self) 766 self.boundingBoxVisible = Tkinter.BooleanVar() 767 self.boundingBoxVisible.set(1) 768 self.childGeomVisible = Tkinter.BooleanVar() 769 self.childGeomVisible.set(1) 770 self.Icons = [] 771 self.ifd = InputFormDescr(title = "Add Ion") 772 773 self.ifd.append({'name':'step_size_label', 774 'widgetType':Tkinter.Label, 775 'wcfg':{'text':''}, 776 'gridcfg':{'row':0, 'column':1, 'sticky':'w'} 777 }) 778 779 Icon = get_icon('add.png') 780 self.Icons.append(Icon) 781 self.ifd.append({'name':'Add', 782 'widgetType':Tkinter.Button, 783 'wcfg':{'text':'Add', 'image':Icon, 'command':self.add}, 784 'gridcfg':{'row':1, 'column':0, 'sticky':'we'} 785 }) 786 787 self.ifd.append({'name':'Name', 788 'widgetType':Pmw.EntryField, 789 'wcfg':{'labelpos':'w', 'label_text':'Grid Name:', 790 'command':self.apply}, 791 'gridcfg':{'row':1, 'column':1, 'columnspan':4,'sticky':'we'} 792 }) 793 794 self.ifd.append({'name':'l_add', 795 'widgetType':Tkinter.Label, 796 'wcfg':{'text':'Add'}, 797 'gridcfg':{'row':2, 'column':0, 'sticky':'we'} 798 }) 799 800 self.ifd.append({'name':'origin_label', 801 'widgetType':Tkinter.Label, 802 'wcfg':{'text':' Origin:'}, 803 'gridcfg':{'row':3, 'column':1, 'sticky':'w'} 804 }) 805 806 self.ifd.append({'name':'X_origin', 807 'widgetType':Pmw.EntryField, 808 'wcfg':{'labelpos':'e', 'label_text':'X', 'entry_width':8, 809 'validate':{'validator' : 'real'},'sticky':'w', 810 'command':self.apply}, 811 'gridcfg':{'row':3, 'column':2, 'sticky':'w'} 812 }) 813 814 self.ifd.append({'name':'Y_origin', 815 'widgetType':Pmw.EntryField, 816 'wcfg':{'labelpos':'e', 'label_text':'Y', 'entry_width':8, 817 'validate':{'validator' : 'real'},'sticky':'w', 818 'command':self.apply}, 819 'gridcfg':{'row':3, 'column':3, 'sticky':'w'} 820 }) 821 822 self.ifd.append({'name':'Z_origin', 823 'widgetType':Pmw.EntryField, 824 'wcfg':{'labelpos':'e', 'label_text':'Z', 'entry_width':8, 825 'validate':{'validator' : 'real'},'sticky':'w', 826 'command':self.apply}, 827 'gridcfg':{'row':3, 'column':4, 'sticky':'w'} 828 }) 829 830 Icon = get_icon('rem.png') 831 self.Icons.append(Icon) 832 self.ifd.append({'name':'Remove', 833 'widgetType':Tkinter.Button, 834 'wcfg':{'text':'Remove','image':Icon,'command':self.remove}, 835 'gridcfg':{'row':3, 'column':0, 'sticky':'we'} 836 }) 837 838 self.ifd.append({'name':'l_remove', 839 'widgetType':Tkinter.Label, 840 'wcfg':{'text':'Remove'}, 841 'gridcfg':{'row':4, 'column':0, 'sticky':'we'} 842 }) 843 844 self.ifd.append({'name':'step_size_label', 845 'widgetType':Tkinter.Label, 846 'wcfg':{'text':' Step Size:'}, 847 'gridcfg':{'row':4, 'column':1, 'sticky':'w'} 848 }) 849 850 self.ifd.append({'name':'dX', 851 'widgetType':Pmw.EntryField, 852 'wcfg':{'labelpos':'e', 'label_text':'dX', 'entry_width':8, 853 'validate':{'validator' : 'real'},'sticky':'w', 854 'command':self.apply}, 855 'gridcfg':{'row':4, 'column':2, 'sticky':'w'} 856 }) 857 858 self.ifd.append({'name':'dY', 859 'widgetType':Pmw.EntryField, 860 'wcfg':{'labelpos':'e', 'label_text':'dY', 'entry_width':8, 861 'validate':{'validator' : 'real'},'sticky':'w', 862 'command':self.apply}, 863 'gridcfg':{'row':4, 'column':3, 'sticky':'w'} 864 }) 865 866 self.ifd.append({'name':'dZ', 867 'widgetType':Pmw.EntryField, 868 'wcfg':{'labelpos':'e', 'label_text':'dZ', 'entry_width':8, 869 'validate':{'validator' : 'real'},'sticky':'w', 870 'command':self.apply}, 871 'gridcfg':{'row':4, 'column':4, 'sticky':'w'} 872 }) 873 874 875 self.ifd.append({'name':'Apply', 876 'widgetType':Tkinter.Button, 877 'wcfg':{'text':'Apply', 'command':self.apply}, 878 'gridcfg':{'row':5, 'column':3,'sticky':'we'} 879 }) 880 881 self.ifd.append({'name':'Reset', 882 'widgetType':Tkinter.Button, 883 'wcfg':{'text':'Reset', 'command':self.reset}, 884 'gridcfg':{'row':5, 'column':4, 'sticky':'we'} 885 }) 886 887 888 self.ifd.append({'name':'childGeomVisible', 889 'widgetType':Tkinter.Checkbutton, 890 'wcfg':{'text':'Show/Hide Volume', 891 'command':self.changeChildrenVisible, 892 'variable':self.childGeomVisible}, 893 'gridcfg':{'row':6, 'column':0,'columnspan':3, 'sticky':'w'} 894 }) 895 896 self.ifd.append({'name':'boundingBoxVisible', 897 'widgetType':Tkinter.Checkbutton, 898 'wcfg':{'text':'Show Bounding Box','command':self.changeBox, 899 'variable':self.boundingBoxVisible}, 900 'gridcfg':{'row':6, 'column':3,'columnspan':3} 901 })
902 903
904 - def onAddCmdToViewer(self):
905 if not hasattr(self.vf, 'grids3D'): 906 self.vf.grids3D={}
907
908 - def __call__(self, grid3D, **kw):
909 apply(self.doitWrapper, (grid3D,), kw)
910
911 - def doit(self, grid3D, remove = True):
912 grid3D = self.vf.grids3D[grid3D] 913 self.vf.GUI.VIEWER.Redraw()
914
915 - def guiCallback(self):
916 self.vf.Grid3DCommands.show() 917 if self.vf.Grid3DCommands.current_cmd != self.vf.Grid3DAddRemove: 918 self.vf.Grid3DCommands.Checkbuttons["Add/Remove"].toggle() 919 self.vf.Grid3DCommands.Add_Remove()
920
921 - def changeBox(self,event=None):
922 grid_name = self.vf.Grid3DCommands.get_grid_name() 923 if not grid_name: 924 return 925 if self.boundingBoxVisible.get(): 926 self.vf.grids3D[grid_name].geomContainer['Box'].Set(visible=1) 927 else: 928 self.vf.grids3D[grid_name].geomContainer['Box'].Set(visible=0) 929 self.vf.GUI.VIEWER.Redraw()
930
931 - def changeChildrenVisible(self, event=None):
932 grid_name = self.vf.Grid3DCommands.get_grid_name() 933 if not grid_name: 934 return 935 if self.childGeomVisible.get(): 936 self.vf.grids3D[grid_name].master_geom.Set(visible=1) 937 self.ifd.entryByName['boundingBoxVisible']['widget'].configure(state='normal') 938 else: 939 self.vf.grids3D[grid_name].master_geom.Set(visible=0) 940 self.ifd.entryByName['boundingBoxVisible']['widget'].configure(state='disabled') 941 self.vf.GUI.VIEWER.Redraw()
942
943 - def add(self):
944 self.vf.Grid3DCommands.root.config(cursor='watch') 945 self.vf.Grid3DReadAny.guiCallback(parent = self.vf.Grid3DCommands.root) 946 self.vf.Grid3DCommands.mlb.selection_clear(0, Tkinter.END) 947 self.vf.Grid3DCommands.mlb.selection_set(Tkinter.END) 948 self.select() 949 self.vf.Grid3DCommands.root.config(cursor='') 950 self.vf.Grid3DCommands.PanedWindow.config(cursor='')
951
952 - def remove(self):
953 grid_name = self.vf.Grid3DCommands.get_grid_name() 954 if not grid_name: 955 if self.vf.Grid3DCommands.mlb.size() != 0: 956 self.ifd.entryByName['Name']['widget'].\ 957 setvalue('Please select grid from the list') 958 else: 959 self.ifd.entryByName['Name']['widget'].\ 960 setvalue('There are no grids in the list') 961 return 962 grid3D = self.vf.grids3D[grid_name] 963 for geoms in grid3D.geomContainer: 964 if hasattr(grid3D.geomContainer[geoms],'__iter__'): 965 for geom in grid3D.geomContainer[geoms]: 966 self.vf.GUI.VIEWER.RemoveObject(grid3D.geomContainer[geoms][geom]) 967 else: 968 self.vf.GUI.VIEWER.RemoveObject(grid3D.geomContainer[geoms]) 969 for children in grid3D.master_geom.children: 970 children.protected = False 971 grid3D.master_geom.protected = False 972 self.vf.GUI.VIEWER.RemoveObject(grid3D.master_geom) 973 self.vf.grids3D.pop(grid_name) 974 select = self.vf.Grid3DCommands.mlb.curselection()[0] 975 self.vf.Grid3DCommands.mlb.delete(select) 976 self.ifd.entryByName['Name']['widget'].setvalue('') 977 self.ifd.entryByName['X_origin']['widget'].setvalue('') 978 self.ifd.entryByName['Y_origin']['widget'].setvalue('') 979 self.ifd.entryByName['Z_origin']['widget'].setvalue('') 980 self.ifd.entryByName['dX']['widget'].setvalue('') 981 self.ifd.entryByName['dY']['widget'].setvalue('') 982 self.ifd.entryByName['dZ']['widget'].setvalue('') 983 self.vf.GUI.VIEWER.Redraw() 984 self.vf.Grid3DCommands.mlb.girdName = None
985
986 - def select(self):
987 grid_name = self.vf.Grid3DCommands.get_grid_name() 988 if not grid_name: 989 return 990 self.vf.Grid3DCommands.mlb.girdName = grid_name 991 self.ifd.entryByName['Name']['widget'].setvalue(grid_name) 992 grid = self.vf.grids3D[grid_name] 993 origin = grid.origin 994 self.ifd.entryByName['X_origin']['widget'].setvalue(origin[0]) 995 self.ifd.entryByName['Y_origin']['widget'].setvalue(origin[1]) 996 self.ifd.entryByName['Z_origin']['widget'].setvalue(origin[2]) 997 stepSize = grid.stepSize 998 self.ifd.entryByName['dX']['widget'].setvalue(stepSize[0]) 999 self.ifd.entryByName['dY']['widget'].setvalue(stepSize[1]) 1000 self.ifd.entryByName['dZ']['widget'].setvalue(stepSize[2]) 1001 visible = grid.geomContainer['Box'].visible 1002 self.boundingBoxVisible.set(visible) 1003 visible = grid.master_geom.visible 1004 self.childGeomVisible.set(visible) 1005 if visible: 1006 self.ifd.entryByName['boundingBoxVisible']['widget'].configure(state='normal') 1007 else: 1008 self.ifd.entryByName['boundingBoxVisible']['widget'].configure(state='disabled')
1009
1010 - def apply(self):
1011 grid_name = self.vf.Grid3DCommands.get_grid_name() 1012 if not grid_name: 1013 if self.vf.Grid3DCommands.mlb.size() != 0: 1014 self.ifd.entryByName['Name']['widget'].\ 1015 setvalue('Please select grid from the list') 1016 else: 1017 self.ifd.entryByName['Name']['widget'].\ 1018 setvalue('There a no grids added') 1019 return 1020 1021 tmp_grid = self.vf.grids3D[grid_name] 1022 self.vf.grids3D.pop(grid_name) 1023 new_name = self.ifd.entryByName['Name']['widget'].getvalue() 1024 tmp_grid.master_geom.Set(name=new_name) 1025 self.vf.grids3D[new_name] = tmp_grid 1026 row = self.vf.Grid3DCommands.mlb.curselection()[0] 1027 l = self.vf.Grid3DCommands.mlb.lists[0] 1028 l.delete(row) 1029 l.insert(row,new_name) 1030 self.vf.Grid3DCommands.mlb.selection_set(row) 1031 X = self.ifd.entryByName['X_origin']['widget'].getvalue() 1032 Y = self.ifd.entryByName['Y_origin']['widget'].getvalue() 1033 Z = self.ifd.entryByName['Z_origin']['widget'].getvalue() 1034 tmp_grid.origin = (float(X),float(Y),float(Z)) 1035 dX = self.ifd.entryByName['dX']['widget'].getvalue() 1036 dY = self.ifd.entryByName['dY']['widget'].getvalue() 1037 dZ = self.ifd.entryByName['dZ']['widget'].getvalue() 1038 tmp_grid.stepSize = [float(dX),float(dY),float(dZ)]
1039
1040 - def reset(self):
1041 grid_name = self.vf.Grid3DCommands.get_grid_name() 1042 if not grid_name: 1043 return 1044 tmp_grid = self.vf.grids3D[grid_name] 1045 self.vf.grids3D.pop(grid_name) 1046 grid_basename = os.path.basename(tmp_grid.path) 1047 self.vf.grids3D[grid_basename] = tmp_grid 1048 tmp_grid.master_geom.Set(name=grid_basename) 1049 tmp_grid.origin = tmp_grid.origin_copy 1050 tmp_grid.stepSize = tmp_grid.stepSize_copy 1051 row = self.vf.Grid3DCommands.mlb.curselection()[0] 1052 l = self.vf.Grid3DCommands.mlb.lists[0] 1053 l.delete(row) 1054 l.insert(row,grid_basename) 1055 self.vf.Grid3DCommands.mlb.selection_clear(0, Tkinter.END) 1056 self.vf.Grid3DCommands.mlb.selection_set(row) 1057 self.select()
1058 1059 AddRemoveGUI = CommandGUI() 1060 AddRemoveGUI.addMenuCommand('menuRoot', 'Grid3D', 'Add/Remove...') 1061
1062 -class IGraph(Tkinter.Frame):
1063 """Extends Tkinter.Frame by adding a canvas with histogram and bars for 1064 isocontouring. 1065 """
1066 - def __init__(self, master, width = width, height = height, 1067 labelsBarFormat = '%4.2f'):
1068 self.width = width - 10 1069 self.height = height 1070 self.offset_y1 = 6 1071 self.offset_y2 = 20 1072 self.a_x = 1 1073 self.b_x = 0 1074 self.a_y = -1 1075 self.b_y = height 1076 self.sig_tags = ['area', 'min_vol', 'max_vol', 'gradient'] 1077 self.colors = ['red', 'green', 'blue', 'orange']#used in Plot Signature 1078 self.labelsBarFormat = labelsBarFormat 1079 Tkinter.Frame.__init__(self, master) 1080 #Tkinter.Grid.config(self) 1081 self.upperLabel = Tkinter.Label(self, text = "(0, 0)",width=20) 1082 self.upperLabel.grid(row=0, column=0,sticky='we') 1083 self.log_var = Tkinter.IntVar() 1084 self.log_var.set(1) 1085 self.sig_var = Tkinter.IntVar() 1086 self.log_cb = Tkinter.Checkbutton(self, text='Logarithmic',anchor="w", 1087 command = self.plot_historgam, 1088 variable=self.log_var) 1089 self.log_cb.grid(row=0, column=1,sticky='e') 1090 self.sig_cb = Tkinter.Checkbutton(self, text='Plot Signature',anchor="e", 1091 command = self.plot_signature, 1092 variable=self.sig_var) 1093 self.sig_cb.grid(row=0, column=2,sticky='e') 1094 1095 #self.canvasFrame = Tkinter.Frame(self) 1096 #self.canvasFrame.grid(row=1, column=0,columnspan=4, sticky='wens') 1097 self.canvas = Tkinter.Canvas(self, width=self.width,cursor = 'cross', 1098 highlightbackground = 'blue', 1099 height=height, background='white') 1100 self.canvas.grid(row=1, column=0,columnspan=3) 1101 1102 self.minEntry = Pmw.ComboBox(self,label_text = 'min',labelpos = 'e', 1103 dropdown=1, selectioncommand=self.setMin) 1104 self.minEntry.grid(row=2, column=0, sticky='w') 1105 self.minEntry._entryWidget.configure(width=8) 1106 self.balloon = Pmw.Balloon(self) 1107 self.balloon.bind(self, "Press Shift and mouse click inside the canvas to add Isocontour") 1108 1109 self.maxEntry = Pmw.ComboBox(self,label_text = 'max',labelpos = 'w', 1110 dropdown=1, selectioncommand=self.setMax) 1111 self.maxEntry.grid(row=2, column=2, sticky='e') 1112 self.maxEntry._entryWidget.configure(width=8) 1113 1114 Tkinter.Widget.bind(self.canvas, "<1>", self.selectMoveBar) 1115 Tkinter.Widget.bind(self.canvas, "<B1-Motion>", self.moveBar) 1116 Tkinter.Widget.bind(self.canvas, "<Motion>", self.onMouseOver) 1117 Tkinter.Widget.bind(self.canvas,'<Button-3>', self.button3) 1118 Tkinter.Widget.bind(self.canvas,'<Shift-Button-1>', self.addBar) 1119 1120 #Tkinter.Widget.bind(self.canvas, '<Double-Button-1>', self.showDejaVu) 1121 #Tkinter.Widget.bind(self, '<Configure>', self.changeSize) 1122 1123 self.valueLabel = {} 1124 self.bar_text = 'IsoSurf_' 1125 self.isoBarNumber = 0 1126 self.last_tag = None 1127 self.canvas.create_rectangle(0,self.offset_y1,self.width, 1128 self.offset_y1+1,fill='gray68', tag='h_bar') 1129 self.canvas.create_rectangle(0,self.height - self.offset_y2,self.width, 1130 self.height - self.offset_y2+1,fill='gray68', tag='h_bar') 1131 1132 self.menu = Tkinter.Menu(self.master, title='Isocontour - Menu') 1133 1134 self.menu.add_command(label='Set IsoValue...',command=self.isoValueGUI) 1135 self.menu.add_command(label='Color...',command=self.colorBar) 1136 self.menu.add_command(label='Set 3D Surface Properties...', 1137 command=self.showDejaVu) 1138 self.menu.add_command(label='Hide', command=self.hideShowIso) 1139 self.menu.add_command(label='Transparency',command=self.setTransparency) 1140 self.menu.add_command(label='Delete',command=self.deleteCB) 1141 self.menu.add_command(label='Cancel',command=self.cancelManu) 1142 self.menu.bind('<FocusOut>', self.cancelManu)
1143
1144 - def cancelManu(self, event=None):
1145 self.menu.unpost()
1146
1147 - def changeSize(self, event):
1148 self.canvas.scale('all',0,0,float(event.width)/float(self.width), 1149 float(event.height)/float(self.height) ) 1150 self.width = event.width 1151 self.height = event.height
1152
1153 - def plot_signature(self):
1154 if not self.cmd.grid: 1155 return 1156 for s in range(4): 1157 self.canvas.delete(self.sig_tags[s]) 1158 if not self.sig_var.get(): 1159 return 1160 self.cmd.vf.Grid3DCommands.root.configure(cursor='watch') 1161 self.cmd.vf.Grid3DCommands.PanedWindow.config(cursor='watch') 1162 self.cmd.vf.Grid3DCommands.root.update() 1163 for s in range(4): 1164 if hasattr(self.cmd.grid,'signature'): 1165 sig = self.cmd.grid.signature[s] 1166 else: 1167 self.cmd.grid.signature = [] 1168 for si in range(4): 1169 self.cmd.grid.signature.append( 1170 self.cmd.iso_data.getSignature(0, 0, si)) 1171 sig =self.cmd.grid.signature[s] 1172 x = Numeric.zeros( (sig.nval,), 'f') 1173 sig.getFx(x) 1174 y = Numeric.zeros( (sig.nval,), 'f') 1175 sig.getFy(y) 1176 max_y = max(y) 1177 min_y = min(y) 1178 a_y = (self.offset_y1 - self.height + self.offset_y2)/(max_y - min_y) 1179 b_y = self.height - self.offset_y2 - a_y*min_y 1180 coords = [] 1181 for i in range(len(x)): 1182 screen_x = self.a_x*x[i] + self.b_x 1183 screen_y = a_y*y[i] + b_y 1184 coords.append(screen_x) 1185 coords.append(screen_y) 1186 self.canvas.create_line( coords,fill=self.colors[s], tag=self.sig_tags[s] ) 1187 self.canvas.create_text( self.width-40 , 15*s + self.offset_y2, 1188 fill=self.colors[s], 1189 text=sig.name, tag=self.sig_tags[s]) 1190 self.cmd.vf.Grid3DCommands.root.configure(cursor='') 1191 self.cmd.vf.Grid3DCommands.PanedWindow.config(cursor='')
1192
1193 - def plot_historgam(self, event = None, data = None):