def Start(self): ## create VTK interactor (this is the most important object) # this need a Tkinter GUI object (render_frame) and a VTK render window (renWindow) to work self.renWinInteractor = vtkTkRenderWindowInteractor(self.render_frame, rw=self.renWindow, width=600, height=600) self.renWinInteractor.SetInteractorStyle( vtk.vtkInteractorStyleTrackballCamera( )) # set the trackball behaviour # we can add additional configurations for this interactor here axes = vtk.vtkAxesActor() marker = vtk.vtkOrientationMarkerWidget() marker.SetOutlineColor(0.93, 0.57, 0.13) marker.SetOrientationMarker(axes) marker.SetInteractor(self.renWinInteractor) marker.SetViewport(0.0, 0.0, 0.4, 0.4) marker.SetEnabled(1) marker.InteractiveOff() ## initialize the interactor and align it to the frame self.renWinInteractor.Initialize() self.renWinInteractor.pack(side='top', fill='both', expand=1) self.renWindow.Render() self.renWinInteractor.Start() ## main loop self.root.mainloop()
def setenv(self, root): self.renderer = vtk.vtkOpenGLRenderer() #self.renderer.SetBackground(1,1,1) self.renwin = vtk.vtkXOpenGLRenderWindow() self.renwin.AddRenderer(self.renderer) #self.renwin.SetStereoTypeToRedBlue() #self.renwin.StereoCapableWindowOn() #self.renwin.SetStereoTypeToCrystalEyes() #self.renwin.StereoRenderOn() #activer la stereoscopie self.renwin.SetStereoTypeToAnaglyph() #self.renwin.SetAnaglyphColorMask(4,2) #gauche,droite | r=4, v=2 ,b=1 self.iren = vtkTkRenderWindowInteractor(root, rw=self.renwin, width=1000, height=800) self.istyle = vtk.vtkInteractorStyleSwitch() self.iren.SetInteractorStyle(self.istyle) self.istyle.SetCurrentStyleToTrackballCamera() self.iren.Initialize() self.iren.pack(side='top', fill='both', expand=1) self.addobservers() self.setcam() self.setaxes() #self.make_fog() #charger le fog par defaut ? /!\ modifier la variable has_fog self.iren.Start() self.display_ascii_logo()
def __init__(self, gfx, frame): self.renderer = vtk.vtkOpenGLRenderer() self.renwin = vtk.vtkXOpenGLRenderWindow() self.renwin.AddRenderer(self.renderer) self.renwin.SetStereoTypeToAnaglyph() self.iren = vtkTkRenderWindowInteractor(frame, rw=self.renwin, width=500, height=500) self.istyle = vtk.vtkInteractorStyleSwitch() self.iren.SetInteractorStyle(self.istyle) self.istyle.SetCurrentStyleToTrackballCamera() self.iren.Initialize() self.iren.pack(side='bottom', fill='both', expand=0) self.iren.Start() self.camera = vtk.vtkCamera() self.camera.SetFocalPoint(0, 0, 0) self.camera.SetPosition(0, 0, 250) self.camera.SetViewUp(0, 0, 0) self.camera.SetEyeAngle(5.0) self.tm = None self.renderer.SetActiveCamera(self.camera) self.renwin.Render() self.currentmod = None self.nbstep = None self.oldon = None self.tloop = None self.tloopobs = None self.gfx = gfx
def __init__(self, parent, model=MathModel1(), w=400, h=400): self.parent = parent self.model = model self.frame = Tkinter.Frame(parent, borderwidth=2, colormap='new') self.parent.bind('<q>', self.quit) self.__planet_source = self.__planet_mapper = None # create renderer and renderwindow self.renderer = vtkRenderer() from vtk.tk.vtkTkRenderWindowInteractor import \ vtkTkRenderWindowInteractor self.window_w = vtkTkRenderWindowInteractor(master) self.window_w.pack(side='top', expand=1, fill='both') self.window = self.window_w.GetRenderWindow() self.window.AddRenderer(self.renderer) self.planets = {} # sun and planets # create sun: self.create_sun() # create planet 1: self.create_planet('earth', 0.2, 0.3, 0) # gooey: self.delay = Tkinter.DoubleVar() self.delay.set(0.01) delay_scale = Tkinter.Scale(self.frame, orient='horizontal', from_=0.01, to=1, tickinterval=100, resolution=0.01, label='slow-down of motion', length=300, variable=self.delay) delay_scale.pack(side='top') button_row = Tkinter.Frame(self.frame, borderwidth=2, colormap='new') button_row.pack(side='top', fill='both', expand=True) b = Tkinter.Button(button_row, text="start animatation", command=self.animate) b.pack(side='left', fill='x', expand=True) b = Tkinter.Button(button_row, text="stop animation", command=self.stop) b.pack(side='right', fill='x', expand=True) self.frame.pack(fill='both', expand=True) self.window.Render() self.__animate_thread_active = 0
class TestTkRenderWindowInteractor(Testing.vtkTest): # Stick your VTK pipeline here if you want to create the pipeline # only once. If you put it in the constructor or in the function # the pipeline will be created afresh for each and every test. # create a dummy Tkinter root window. root = tkinter.Tk() # create a rendering window and renderer ren = vtk.vtkRenderer() tkrw = vtkTkRenderWindowInteractor(root, width=300, height=300) tkrw.Initialize() tkrw.pack() rw = tkrw.GetRenderWindow() rw.AddRenderer(ren) # create an actor and give it cone geometry cs = vtk.vtkConeSource() cs.SetResolution(8) map = vtk.vtkPolyDataMapper() map.SetInputConnection(cs.GetOutputPort()) act = vtk.vtkActor() act.SetMapper(map) # assign our actor to the renderer ren.AddActor(act) def testvtkTkRenderWindowInteractor(self): "Test if vtkTkRenderWindowInteractor works." self.tkrw.Start() self.tkrw.Render() self.root.update() img_file = "TestTkRenderWindowInteractor.png" Testing.compareImage(self.rw, Testing.getAbsImagePath(img_file)) Testing.interact() self.tkrw.destroy() # These are useful blackbox tests (not dummy ones!) def testParse(self): "Test if vtkTkRenderWindowInteractor is parseable" self._testParse(self.tkrw) def testGetSet(self): "Testing Get/Set methods of vtkTkRenderWindowInteractor" self._testGetSet(self.tkrw) def testBoolean(self): "Testing Boolean methods of vtkTkRenderWindowInteractor" self._testBoolean(self.tkrw)
def returnCubeObjects(root): cube = vtk.vtkCubeSource() cube.Modified() mapper = vtk.vtkPolyDataMapper() actor = vtk.vtkActor() mapper.SetInputConnection(cube.GetOutputPort()) actor.SetMapper(mapper) render = vtk.vtkRenderer() render.AddActor(actor) renWindow = vtk.vtkRenderWindow() renWindow.AddRenderer(render) renWinInteract = vtkTkRenderWindowInteractor(root,rw=renWindow, width=800, height=800) return actor,render,renWindow,renWinInteract
def __init__(self, parent, model=MathModel1(), w=400, h=400): self.parent = parent self.model = model self.frame = Tkinter.Frame(parent, borderwidth=2, colormap='new') self.parent.bind('<q>', self.quit) self.__planet_source = self.__planet_mapper = None # create renderer and renderwindow self.renderer = vtkRenderer() from vtk.tk.vtkTkRenderWindowInteractor import \ vtkTkRenderWindowInteractor self.window_w = vtkTkRenderWindowInteractor(master) self.window_w.pack( side = 'top', expand = 1, fill = 'both' ) self.window = self.window_w.GetRenderWindow() self.window.AddRenderer( self.renderer ) self.planets = {} # sun and planets # create sun: self.create_sun() # create planet 1: self.create_planet('earth', 0.2, 0.3, 0) # gooey: self.delay = Tkinter.DoubleVar(); self.delay.set(0.01); delay_scale = Tkinter.Scale(self.frame, orient='horizontal', from_=0.01, to=1, tickinterval=100, resolution=0.01, label='slow-down of motion', length=300, variable=self.delay) delay_scale.pack(side='top') button_row = Tkinter.Frame(self.frame, borderwidth=2, colormap='new') button_row.pack(side='top', fill='both', expand=True) b = Tkinter.Button(button_row, text="start animatation", command=self.animate) b.pack(side='left',fill='x',expand=True) b = Tkinter.Button(button_row, text="stop animation", command=self.stop) b.pack(side='right',fill='x',expand=True) self.frame.pack(fill='both', expand=True) self.window.Render() self.__animate_thread_active = 0
def __init__(self,frame): self.renderer = vtk.vtkOpenGLRenderer() self.renwin = vtk.vtkXOpenGLRenderWindow() self.renwin.AddRenderer(self.renderer) self.renwin.SetStereoTypeToAnaglyph() #self.renwin.SetAnaglyphColorMask(4,2) self.iren = vtkTkRenderWindowInteractor(frame,rw=self.renwin, width=300, height=300 ) self.istyle = vtk.vtkInteractorStyleSwitch() self.iren.SetInteractorStyle(self.istyle) self.istyle.SetCurrentStyleToTrackballCamera() self.iren.Initialize() self.iren.pack(side='bottom', fill='none', expand=0) self.iren.Start() self.camera=vtk.vtkCamera() self.camera.SetFocalPoint(0, 0, 0) self.camera.SetPosition(0, 0, 250) self.camera.SetViewUp(0, 0, 0) self.camera.SetEyeAngle(5.0) self.renderer.SetActiveCamera(self.camera) self.renwin.Render()
def _build(self): from tkinter import Tk from vtk.tk.vtkTkRenderWindowInteractor import vtkTkRenderWindowInteractor # Create Tk root tk = Tk() tk.title("lib3d-mec-ginac") # Create TK window render widget rw = vtkRenderWindow() iren = vtkTkRenderWindowInteractor(tk, rw=rw, width=600, height=600) iren.pack(fill='both') # Initialize the interactor iren.Initialize() # Save tk root, render window and interactor self._tk, self._iren, self._rw = tk, iren, rw # Return the interactor return iren
def volumeRender(self): #Create transfer mapping scalar value to opacity opacityTransferFunction = vtk.vtkPiecewiseFunction() opacityTransferFunction.AddPoint(1, 0.0) opacityTransferFunction.AddPoint(100, 0.1) opacityTransferFunction.AddPoint(255,1.0) colorTransferFunction = vtk.vtkColorTransferFunction() colorTransferFunction.AddRGBPoint(0.0,0.0,0.0,0.0) colorTransferFunction.AddRGBPoint(64.0,1.0,0.0,0.0) colorTransferFunction.AddRGBPoint(128.0,0.0,0.0,1.0) colorTransferFunction.AddRGBPoint(192.0,0.0,1.0,0.0) colorTransferFunction.AddRGBPoint(255.0,0.0,0.2,0.0) volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeProperty.ShadeOn() volumeProperty.SetInterpolationTypeToLinear() compositeFunction = vtk.vtkVolumeRayCastCompositeFunction() volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper() volumeMapper.SetInputConnection(self.reader.GetOutputPort()) volume = vtk.vtkVolume() volume.SetMapper(volumeMapper) volume.SetProperty(volumeProperty) ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtkTkRenderWindowInteractor(self.root, rw=renWin, width=640, height=480) iren.Initialize() ren.AddVolume(volume) ren.SetBackground(1,1,1) renWin.Render()
def Start(self): ## create VTK interactor (this is the most important object) # this need a Tkinter GUI object (render_frame) and a VTK render window (renWindow) to work self.renWinInteractor = vtkTkRenderWindowInteractor(self.render_frame, rw=self.renWindow, width=600, height=600) self.renWinInteractor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera()) # set the trackball behaviour # we can add additional configurations for this interactor here axes = vtk.vtkAxesActor() marker = vtk.vtkOrientationMarkerWidget() marker.SetOutlineColor(0.93, 0.57, 0.13) marker.SetOrientationMarker(axes) marker.SetInteractor(self.renWinInteractor) marker.SetViewport(0.0, 0.0, 0.4, 0.4) marker.SetEnabled(1) marker.InteractiveOff() ## initialize the interactor and align it to the frame self.renWinInteractor.Initialize() self.renWinInteractor.pack(side='top', fill='both', expand=1) self.renWindow.Render() self.renWinInteractor.Start() ## main loop self.root.mainloop()
def setenv(self,root): self.renderer = vtk.vtkOpenGLRenderer() #self.renderer.SetBackground(1,1,1) self.renwin = vtk.vtkXOpenGLRenderWindow() self.renwin.AddRenderer(self.renderer) #self.renwin.SetStereoTypeToRedBlue() #self.renwin.StereoCapableWindowOn() #self.renwin.SetStereoTypeToCrystalEyes() #self.renwin.StereoRenderOn() #activer la stereoscopie self.renwin.SetStereoTypeToAnaglyph() #self.renwin.SetAnaglyphColorMask(4,2) #gauche,droite | r=4, v=2 ,b=1 self.iren = vtkTkRenderWindowInteractor(root,rw=self.renwin, width=1000, height=800) self.istyle = vtk.vtkInteractorStyleSwitch() self.iren.SetInteractorStyle(self.istyle) self.istyle.SetCurrentStyleToTrackballCamera() self.iren.Initialize() self.iren.pack(side='top', fill='both', expand=1) self.addobservers() self.setcam() self.setaxes() #self.make_fog() #charger le fog par defaut ? /!\ modifier la variable has_fog self.iren.Start() self.display_ascii_logo()
def _build(self): from vtk.tk.vtkTkRenderWindowInteractor import vtkTkRenderWindowInteractor from .idle.pyshell import build as build_idle, main as idle_mainloop # Build IDLE tk = build_idle(self) self._tk = tk top_level = tk.children['!listedtoplevel'] menu_bar = tk.children['!menu'] # Build extra widgets for IDLE self._load_fonts() self._build_menus(menu_bar) self._adjust_idle_widgets(top_level) # Add event handlers self._add_event_handlers() # Update GUI tk.update() # Create TK window render widget rw = vtkRenderWindow() iren = vtkTkRenderWindowInteractor(top_level, width=600, height=600, rw=rw) iren.pack(expand=True, side='right', fill='both') # Initialize the interactor iren.Initialize() # Save render window and interactor self._iren, self._rw = iren, rw # Return the interactor return iren
def InitializeGUI(self,w,h): self.top = Tkinter.Toplevel(self.root) # make sure exit happens gracefully def quit(obj=self.root): obj.quit() self.top.protocol("WM_DELETE_WINDOW",quit) self.frmDisplay = Tkinter.Frame(self.top) self.frmRender = Tkinter.Frame(self.frmDisplay) for f in (self.frmDisplay,self.frmRender): f.pack(padx=3,pady=3, side="top", anchor="n", fill="both", expand="false") rwi = vtkTkRenderWindowInteractor(self.frmRender, rw=Globals.renWin, width=w,height=h) rwi.pack() rwi.Render() self.renderWidget = rwi self.root.update() frmModes = Tkinter.Frame(self.top) frmModes.pack() self.radioVar = Tkinter.IntVar() self.radioVar.set(0) self.dicGuiModes = { 0:"Navigation", 1:"Add Region", 2:"Laplace", 3:"Profile Inspector", 4:"Highlight", 5:"Delete Region" } for k in self.dicGuiModes.keys(): Tkinter.Radiobutton(frmModes, text=self.dicGuiModes[k], variable=self.radioVar, value=k, command=self.ChangeMode).pack(side="left") # Add a slice scale to browse the current slice stack sliceNumber = Tkinter.IntVar() smin,smax = Globals.imagePipeline.GetAxisExtent() sliceNumber.set( Globals.imagePipeline.GetSliceIndex() ) self.scaleSlice = Tkinter.Scale(self.top, from_=smin, to=smax, orient="horizontal", command=self.SetSlice, variable=sliceNumber, label="Slice") self.scaleSlice.pack(fill="x",expand="false") self.SetupMenubar()
# Create the toplevel window top = tkinter.Toplevel(root) top.title("Sphere Puzzle") top.protocol("WM_DELETE_WINDOW", quit) # Create some frames f1 = tkinter.Frame(top) f2 = tkinter.Frame(top) f1.pack(side="top", anchor="n", expand=1, fill="both") f2.pack(side="bottom", anchor="s", expand="t", fill="x") # Create the Tk render widget, and bind the events rw = vtkTkRenderWindowInteractor(f1, width=400, height=400, rw=renWin) rw.pack(expand="t", fill="both") def reset(evt=None): puzzle.Reset() renWin.Render() # Display some information l1 = tkinter.Label(f2, text="Position cursor over the rotation plane.") l2 = tkinter.Label(f2, text="Moving pieces will be highlighted.") l3 = tkinter.Label(f2, text="Press 'm' to make a move.") reset = tkinter.Button(f2, text="Reset", command=reset) b1 = tkinter.Button(f2, text="Quit", command=quit)
# Window window = vtk.vtkRenderWindow() window.AddRenderer(renderer) # Set up Tk GUI root = tk.Tk("Frog") # Define a quit method that exits cleanly def quit(obj=root): obj.quit() root.protocol("WM_DELETE_WINDOW", quit) vtkw = vtkTkRenderWindowInteractor(root, rw=window, width=300, height=300) vtkw.pack(side="left", expand="true", fill="both") menu = tk.Frame(root, height=300, width=150) menu.pack(side="left", fill="y") buttons = dict() icons = dict() functions = dict() opacities = dict() # def set_color(b): # new_color = tkColorChooser.askcolor() # icons[b].configure(background=new_color[1]) # tissues[b-1].GetProperty().SetColor(float(new_color[0][0]) / 255, float(new_color[0][1]) / 255, float(new_color[0][2] / 255))
Q = (P[0], P[1], v) cp = CuttingPlane(*Q) pn = PlaneNormal(*Q) clipper.SetClipFunction(cp) clipper.SetValue(0) cutEdges.SetCutFunction(cp) cutEdges.SetValue(0, 0) cutStrips.Update() cutPoly.SetPoints(cutStrips.GetOutput().GetPoints()) cutPoly.SetPolys(cutStrips.GetOutput().GetLines()) cutMapper.Update() renWin.Render() root = Tkinter.Tk() vtkw = vtkTkRenderWindowInteractor(root, rw=renWin, width=800) def set_cut(sz): sz = float(sz) # print ren.GetActiveCamera() Cut(sz) # propagate this GUI setting to the corresponding VTK object. size_slider = Tkinter.Scale(root, from_=0.0, to=2.0, res=0.01, orient='horizontal', label="Clipping Center",
mapper.Update() actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetColor(1,0.547237,0.319073) actor.GetProperty().SetOpacity(.3) #create render window and interactor ren = vtk.vtkRenderer() ren.SetBackground(0.329412, 0.34902, 0.427451) #paraview blue from tutorial ren.ResetCameraClippingRange() ren.AddActor(actor) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renWin.PolygonSmoothingOn() #Setup interactor iren = vtkTkRenderWindowInteractor(root,rw=renWin, width=400, height=400) iren.Initialize() iren.pack(side='top', fill='both', expand=1) iren.Start() #Init the interactor and render Start the interactor renWin.Render() root.mainloop()
ren.AddActor(actor) button = Tkinter.Button(root, text="Quit", command=root.quit) button.pack(fill='x', expand='t') start = Tkinter.IntVar() targetx = Tkinter.DoubleVar() targety = Tkinter.DoubleVar() target = [targetx, targety] but_run = Tkinter.Button(root, text="Run", command=lambda: runfnc(start, target)) but_run.pack(fill='x', expand='t') interactor = vtkTkRenderWindowInteractor(root, rw=renwin) interactor.pack(side='top', fill='both', expand=1) interactor.Initialize() style = MouseInteractorStyle() style.SetDefaultRenderer(ren) style.user_data = ugrid style.rw = renwin style.ren = ren style.startp = start style.target = target interactor.SetInteractorStyle(style) interactor.Start() root.mainloop()
############################ Create outline ################## outline = vtk.vtkOutlineFilter() outline.SetInputConnection(reader1.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(1, 1, 1) ############################## Graphics stuff#################### ren1 = vtk.vtkRenderer() iren = vtkTkRenderWindowInteractor(root, height=512, width=512) renWin = iren.GetRenderWindow() renWin.AddRenderer(ren1) iren.SetInteractorStyle(style) #ren1.AddActor(outlineActor) not used in the original given file ren1.AddVolume(volume) ren1.SetBackground(0, 0, 0) def TkCheckAbort(obj, event): #check abortion foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) return
def InitializeGUI(self,w,h): self.top = Tkinter.Toplevel(Globals.root) # handle graceful exit def quit(obj=Globals.root): obj.quit() self.top.protocol("WM_DELETE_WINDOW",quit) self.frmDisplay = Tkinter.Frame(self.top) self.frmRender = Tkinter.Frame(self.frmDisplay) for f in (self.frmDisplay,self.frmRender): f.pack(padx=3,pady=3, side="top", anchor="n", fill="both", expand="false") rwi = vtkTkRenderWindowInteractor(self.frmRender, rw=Globals.renWin, width=w,height=h) rwi.pack() rwi.Render() self.renderWidget = rwi Globals.root.update() ############################# # # setup modes frmModes = Tkinter.Frame(self.top) frmModes.pack() self.dicGuiModes = { 0:"Navigation", 1:"Add Spline" } self.radioVar = Tkinter.IntVar() self.radioVar.set(0) for k in self.dicGuiModes.keys(): Tkinter.Radiobutton(frmModes, text=self.dicGuiModes[k], variable=self.radioVar, value=k, command=self.ChangeMode).pack( side="left") ############################# # # setup labels frmLabels = Tkinter.Frame(self.top) frmLabels.pack() self.dicLabels = {} counter = 0 for lbl in Globals.objectSet.labels: self.dicLabels[counter] = lbl counter += 1 self.lblVar = Tkinter.IntVar() self.lblVar.set(0) Globals.objectSet.currentLabel = self.dicLabels[0] for k in self.dicLabels.keys(): Tkinter.Radiobutton(frmLabels, text=self.dicLabels[k], variable=self.lblVar, value=k, command=self.ChangeCurrentLabel).pack( side="left") #################################### # Add a slice scale to browse the current slice stack sliceNumber = Tkinter.IntVar() smin,smax = Globals.imagePipeline.GetAxisExtent() sliceNumber.set( Globals.imagePipeline.GetSliceIndex() ) self.scaleSlice = Tkinter.Scale(self.top, from_=smin, to=smax, orient="horizontal", command=self.SetSlice, variable=sliceNumber, label="Slice") self.scaleSlice.pack(fill="x", expand="false") self.SetupMenubar()
def vtkrender(d1=None, d2=None): x = (arange(50.0)-25)/2.0 y = (arange(50.0)-25)/2.0 r = sqrt(x[:]**2+y**2) z = 5.0*signal.special.j0(r) # Bessel function of order 0 z1 = reshape(transpose(z), (-1,)) point_data = vtk.vtkPointData(vtk.vtkScalars(z1)) grid = vtk.vtkStructuredPoints((50,50, 1), (-12.5, -12.5, 0), (0.5, 0.5, 1)) data = vtk.VtkData(grid, point_data) data.tofile('/tmp/test.vtk') d1 = d2 = '/tmp/test.vtk' #v2,v1,data1,data2 = inputs() if d1 == None: d1 = "/home/danc/E0058brain.vtk" #d1 = "/home/danc/vtk/data1.vtk" if d2 == None: d2 = "/home/danc/E0058MEG.vtk" #d2='/home/danc/vtk/data2.vtk' #d2 = "/home/danc/mrvtk_0003overlay.vtk" v1 = vtk.vtkStructuredPointsReader() #v1.SetFileName("/home/danc/mrvtk.vtk") v1.SetFileName(d1) v2 = vtk.vtkStructuredPointsReader() #v2.SetFileName("/home/danc/mrvtk_overlay.vtk") v2.SetFileName(d2) v1.SetLookupTableName('/home/danc/colortable.lut') v1.SetReadAllColorScalars v1.Update() v2.Update() global xMax, xMin, yMin, yMax, zMin, zMax, current_widget, slice_number xMin, xMax, yMin, yMax, zMin, zMax = v1.GetOutput().GetWholeExtent() spacing = v1.GetOutput().GetSpacing() sx, sy, sz = spacing origin = v1.GetOutput().GetOrigin() ox, oy, oz = origin # An outline is shown for context. outline = vtk.vtkOutlineFilter() outline.SetInput(v1.GetOutput()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInput(outline.GetOutput()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(1,1,1) # The shared picker enables us to use 3 planes at one time # and gets the picking order right picker = vtk.vtkCellPicker() picker.SetTolerance(0.005) # The 3 image plane widgets are used to probe the dataset. planeWidgetX = vtk.vtkImagePlaneWidget() planeWidgetX.DisplayTextOn() planeWidgetX.SetInput(v1.GetOutput()) planeWidgetX.SetPlaneOrientationToXAxes() planeWidgetX.SetSliceIndex(int(round(xMax/2))) planeWidgetX.SetPicker(picker) planeWidgetX.SetKeyPressActivationValue("x") planeWidgetX.GetPlaneProperty().SetDiffuseColor((0,1,1)) #planeWidgetX.GetPlaneProperty().SetColor(0,1,1) #planeWidgetX.GetPlaneProperty().SetSpecularColor(0,1,1) #planeWidgetX.GetPlaneProperty().SetAmbientColor(0,1,1) planeWidgetX.GetPlaneProperty().SetFrontfaceCulling(10) planeWidgetX.GetPlaneProperty().SetRepresentationToWireframe #planeWidgetX.GetColorMap() #print planeWidgetX.GetColorMap() #planeWidgetX.SetHueRange(0.667,0.0) #planeWidgetX.SetLookupTable('/home/danc/colortable.lut') prop1 = planeWidgetX.GetPlaneProperty() prop1.SetDiffuseColor(1, 0, 0) prop1.SetColor(1,0,0) prop1.SetSpecularColor(0, 1, 1) #print planeWidgetX.GetLookupTable() g = planeWidgetX.GetLookupTable() #print g ## arrow = vtk.vtkArrowSource() #### arrow.SetShaftRadius(100) #### arrow.SetShaftResolution(80) #### arrow.SetTipRadius(100) #### arrow.SetTipLength(1000) #### #arrow.SetTipResolution(80) ## arrowMapper = vtk.vtkPolyDataMapper() ## arrowMapper.SetInput(arrow.GetOutput()) ## arrowActor = vtk.vtkActor() ## arrowActor.SetMapper(arrowMapper) ## arrowActor.SetPosition(0, 0, 0) ## arrowActor.GetProperty().SetColor(0, 1, 0) planeWidgetY = vtk.vtkImagePlaneWidget() planeWidgetY.DisplayTextOn() planeWidgetY.SetInput(v1.GetOutput()) planeWidgetY.SetPlaneOrientationToYAxes() planeWidgetY.SetSliceIndex(int(round(yMax/2))) planeWidgetY.SetPicker(picker) planeWidgetY.SetKeyPressActivationValue("y") prop2 = planeWidgetY.GetPlaneProperty() prop2.SetColor(1, 1, 0) planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable()) planeWidgetY.GetPlaneProperty().SetDiffuseColor(0,1,1) # for the z-slice, turn off texture interpolation: # interpolation is now nearest neighbour, to demonstrate # cross-hair cursor snapping to pixel centers planeWidgetZ = vtk.vtkImagePlaneWidget() planeWidgetZ.SetSliceIndex(100) planeWidgetZ.SetSlicePosition(100) planeWidgetZ.DisplayTextOn() planeWidgetZ.SetInput(v1.GetOutput()) planeWidgetZ.SetPlaneOrientationToZAxes() planeWidgetZ.SetSliceIndex(int(round(yMax/2))) planeWidgetZ.SetPicker(picker) planeWidgetZ.SetKeyPressActivationValue("z") prop3 = planeWidgetZ.GetPlaneProperty() prop3.SetColor(0, 0, 1) planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable()) planeWidgetZ.GetPlaneProperty().SetDiffuseColor(0,1,1) filelist = [v2,v1]; for i in filelist: coloroniso = vtk.vtkStructuredPointsReader() coloroniso.SetFileName(i.GetFileName()) coloroniso.SetScalarsName("colors") coloroniso.Update() isosurface = vtk.vtkStructuredPointsReader() isosurface.SetFileName(i.GetFileName()) isosurface.SetScalarsName("scalars") isosurface.Update() iso = vtk.vtkContourFilter() iso.SetInput(i.GetOutput()) #iso.SetInput(isosurface.GetOutput()) if i == v1: iso.SetValue(0, 20) else: iso.SetValue(0,10) #iso.SetNumberOfContours(10) probe = vtk.vtkProbeFilter() probe.SetInput(iso.GetOutput()) probe.SetSource(coloroniso.GetOutput()) cast = vtk.vtkCastToConcrete() cast.SetInput(probe.GetOutput()) normals = vtk.vtkPolyDataNormals() #normals.SetMaxRecursionDepth(100) normals.SetInput(cast.GetPolyDataOutput()) normals.SetFeatureAngle(45) ## clut = vtk.vtkLookupTable() ## clut.SetHueRange(0, .67) ## clut.Build() ## clut.SetValueRange(coloroniso.GetOutput().GetScalarRange()) ## normals = vtk.vtkPolyDataNormals() ## normals.SetInput(iso.GetOutput()) ## normals.SetFeatureAngle(45) isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInput(normals.GetOutput()) isoMapper.ScalarVisibilityOn() #isoMapper.SetColorModeToMapScalars() isoMapper.ColorByArrayComponent(0, 100)#("VelocityMagnitude", 0) isoMapper.SetScalarRange([1, 200]) ## isoMapper.SetLookupTable(clut) isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) ## isoActor.GetProperty().SetDiffuseColor([.5,.5,.5]) ## isoActor.GetProperty().SetSpecularColor([1,1,1]) ## isoActor.GetProperty().SetDiffuse(.5) ## isoActor.GetProperty().SetSpecular(.5) ## isoActor.GetProperty().SetSpecularPower(15) ## isoActor.GetProperty().SetOpacity(.6) isoActor.GetProperty().SetDiffuseColor(1, .2, .2) isoActor.GetProperty().SetSpecular(.7) isoActor.GetProperty().SetSpecularPower(20) isoActor.GetProperty().SetOpacity(0.5) if i == v1: print 'under' isoActorUnderlay = isoActor else: print 'over' isoActorOverlay = isoActor # Create the RenderWindow and Renderer ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) # Add the outline actor to the renderer, set the background color and size ren.AddActor(outlineActor) #ren.AddActor(sphereActor) renWin.SetSize(700, 700) ren.SetBackground(0, 0, 0) current_widget = planeWidgetZ mode_widget = planeWidgetZ # Create the GUI # We first create the supporting functions (callbacks) for the GUI # # Align the camera so that it faces the desired widget def AlignCamera(): #global ox, oy, oz, sx, sy, sz, xMax, xMin, yMax, yMin, zMax, \ # zMin, slice_number #global current_widget cx = ox+(0.5*(xMax-xMin))*sx cy = oy+(0.5*(yMax-yMin))*sy cz = oy+(0.5*(zMax-zMin))*sz vx, vy, vz = 0, 0, 0 nx, ny, nz = 0, 0, 0 iaxis = current_widget.GetPlaneOrientation() if iaxis == 0: vz = -1 nx = ox + xMax*sx cx = ox + slice_number*sx elif iaxis == 1: vz = -1 ny = oy+yMax*sy cy = oy+slice_number*sy else: vy = 1 nz = oz+zMax*sz cz = oz+slice_number*sz px = cx+nx*2 py = cy+ny*2 pz = cz+nz*3 camera = ren.GetActiveCamera() camera.SetViewUp(vx, vy, vz) camera.SetFocalPoint(cx, cy, cz) camera.SetPosition(px, py, pz) camera.OrthogonalizeViewUp() ren.ResetCameraClippingRange() renWin.Render() # Capture the display and place in a tiff def CaptureImage(): w2i = vtk.vtkWindowToImageFilter() writer = vtk.vtkTIFFWriter() w2i.SetInput(renWin) w2i.Update() writer.SetInput(w2i.GetOutput()) writer.SetFileName("/home/danc/image.tif") renWin.Render() writer.Write() # Align the widget back into orthonormal position, # set the slider to reflect the widget's position, # call AlignCamera to set the camera facing the widget def AlignXaxis(): global xMax, xMin, current_widget, slice_number po = planeWidgetX.GetPlaneOrientation() if po == 3: planeWidgetX.SetPlaneOrientationToXAxes() slice_number = (xMax-xMin)/2 planeWidgetX.SetSliceIndex(slice_number) else: slice_number = planeWidgetX.GetSliceIndex() current_widget = planeWidgetX slice.config(from_=xMin, to=xMax) slice.set(slice_number) AlignCamera() def AlignYaxis(): global yMin, yMax, current_widget, slice_number po = planeWidgetY.GetPlaneOrientation() if po == 3: planeWidgetY.SetPlaneOrientationToYAxes() slice_number = (yMax-yMin)/2 planeWidgetY.SetSliceIndex(slice_number) else: slice_number = planeWidgetY.GetSliceIndex() current_widget = planeWidgetY slice.config(from_=yMin, to=yMax) slice.set(slice_number) AlignCamera() def AlignZaxis(): global yMin, yMax, current_widget, slice_number po = planeWidgetZ.GetPlaneOrientation() if po == 3: planeWidgetZ.SetPlaneOrientationToZAxes() slice_number = (zMax-zMin)/2 planeWidgetZ.SetSliceIndex(slice_number) else: slice_number = planeWidgetZ.GetSliceIndex() current_widget = planeWidgetZ slice.config(from_=zMin, to=zMax) slice.set(slice_number) AlignCamera() ##################def flag(sw): def underlay(): print 'under' global overunderstatus overunderstatus = 'under' isoActor = isoActorUnderlay u_button.config(relief='sunken') o_button.config(relief='raised') six=planeWidgetX.GetSliceIndex() siy=planeWidgetY.GetSliceIndex() siz=planeWidgetZ.GetSliceIndex() data = v1 planeWidgetX.SetInput(data.GetOutput()) planeWidgetY.SetInput(data.GetOutput()) planeWidgetZ.SetInput(data.GetOutput()) planeWidgetX.SetSliceIndex(six) planeWidgetY.SetSliceIndex(siy) planeWidgetZ.SetSliceIndex(siz) renWin.Render() def overlay(): print 'over' global overunderstatus overunderstatus = 'over' isoActor = isoActorOverlay o_button.config(relief='sunken') u_button.config(relief='raised') six=planeWidgetX.GetSliceIndex() siy=planeWidgetY.GetSliceIndex() siz=planeWidgetZ.GetSliceIndex() data = v2 planeWidgetX.SetInput(data.GetOutput()) planeWidgetY.SetInput(data.GetOutput()) planeWidgetZ.SetInput(data.GetOutput()) planeWidgetX.SetSliceIndex(six) planeWidgetY.SetSliceIndex(siy) planeWidgetZ.SetSliceIndex(siz) renWin.Render() def render3d(): print '3d rend' global buttonpos try: if overunderstatus == 'under': isoActor = isoActorUnderlay else: isoActor = isoActorOverlay except NameError: isoActor = isoActorUnderlay try: buttonpos print buttonpos except NameError: buttonpos = 0 print buttonpos r_button.config(relief='sunken') ren.AddActor(isoActor) renWin.Render() else: if buttonpos == 0: buttonpos = 1 r_button.config(relief='raised') ren.RemoveActor(isoActor) ren.RemoveActor(isoActorUnderlay) ren.RemoveActor(isoActorOverlay) renWin.Render() else: buttonpos = 0 r_button.config(relief='sunken') print o_button ren.AddActor(isoActor) renWin.Render() return buttonpos # Set the widget's reslice interpolation mode # to the corresponding popup menu choice def SetInterpolation(): global mode_widget, mode if mode.get() == 0: mode_widget.TextureInterpolateOff() else: mode_widget.TextureInterpolateOn() mode_widget.SetResliceInterpolate(mode.get()) renWin.Render() # Share the popup menu among buttons, keeping track of associated # widget's interpolation mode def buttonEvent(event, arg=None): global mode, mode_widget, popm if arg == 0: mode_widget = planeWidgetX elif arg == 1: mode_widget = planeWidgetY elif arg == 2: mode_widget = planeWidgetZ else: return mode.set(mode_widget.GetResliceInterpolate()) popm.entryconfigure(arg, variable=mode) popm.post(event.x + event.x_root, event.y + event.y_root) def SetSlice(sl): global current_widget current_widget.SetSliceIndex(int(sl)) ren.ResetCameraClippingRange() renWin.Render() ### # Now actually create the GUI root = Tkinter.Tk() root.withdraw() top = Tkinter.Toplevel(root) # Define a quit method that exits cleanly. def quit(obj=root): print obj obj.quit() obj.destroy() #vtkrender.destroy() # Popup menu popm = Tkinter.Menu(top, tearoff=0) mode = Tkinter.IntVar() mode.set(1) popm.add_radiobutton(label="nearest", variable=mode, value=0, command=SetInterpolation) popm.add_radiobutton(label="linear", variable=mode, value=1, command=SetInterpolation) popm.add_radiobutton(label="cubic", variable=mode, value=2, command=SetInterpolation) display_frame = Tkinter.Frame(top) display_frame.pack(side="top", anchor="n", fill="both", expand="false") # Buttons ctrl_buttons = Tkinter.Frame(top) ctrl_buttons.pack(side="top", anchor="n", fill="both", expand="false") quit_button = Tkinter.Button(ctrl_buttons, text="Quit", command=quit) capture_button = Tkinter.Button(ctrl_buttons, text="Tif", command=CaptureImage) quit_button.config(background='#C0C0C0') x_button = Tkinter.Button(ctrl_buttons, text="x", command=AlignXaxis) y_button = Tkinter.Button(ctrl_buttons, text="y", command=AlignYaxis) z_button = Tkinter.Button(ctrl_buttons, text="z", command=AlignZaxis) u_button = Tkinter.Button(ctrl_buttons, text="underlay", command=underlay) o_button = Tkinter.Button(ctrl_buttons, text="overlay", command=overlay) r_button = Tkinter.Button(ctrl_buttons, text="3d render", command=render3d) o_button.config(background='#FFFFFF') u_button.config(relief='sunken') x_button.bind("<Button-3>", lambda e: buttonEvent(e, 0)) y_button.bind("<Button-3>", lambda e: buttonEvent(e, 1)) z_button.bind("<Button-3>", lambda e: buttonEvent(e, 2)) u_button.bind("<Button-3>", lambda e: buttonEvent(e, 3)) o_button.bind("<Button-3>", lambda e: buttonEvent(e, 4)) r_button.bind("<Button-3>", lambda e: buttonEvent(e, 5)) for i in (quit_button, capture_button, x_button, y_button, z_button, u_button, o_button, r_button): i.pack(side="left", expand="true", fill="both") # Create the render widget renderer_frame = Tkinter.Frame(display_frame) renderer_frame.pack(padx=3, pady=3,side="left", anchor="n", fill="both", expand="false") render_widget = vtkTkRenderWindowInteractor(renderer_frame, rw=renWin, width=600, height=600) for i in (render_widget, display_frame): i.pack(side="top", anchor="n",fill="both", expand="false") # Add a slice scale to browse the current slice stack slice_number = Tkinter.IntVar() slice_number.set(current_widget.GetSliceIndex()) slice = Tkinter.Scale(top, from_=zMin, to=zMax, orient="horizontal", command=SetSlice,variable=slice_number, label="Slice") slice.pack(fill="x", expand="false") # Done with the GUI. ### # Set the interactor for the widgets iact = render_widget.GetRenderWindow().GetInteractor() planeWidgetX.SetInteractor(iact) planeWidgetX.On() planeWidgetY.SetInteractor(iact) planeWidgetY.On() planeWidgetZ.SetInteractor(iact) planeWidgetZ.On() # Create an initial interesting view cam1 = ren.GetActiveCamera() cam1.Elevation(210) cam1.SetViewUp(1, -1, 1) cam1.Azimuth(-145) ren.ResetCameraClippingRange() # Render it render_widget.Render() iact.Initialize() renWin.Render() iact.Start() # Start Tkinter event loop root.mainloop()
def returnHeartObjects(root, file): dataset_directory = file # Read data reader = vtk.vtkDICOMImageReader() reader.SetDirectoryName(dataset_directory) reader.Update() volume = vtk.vtkVolume() render = vtk.vtkRenderer() renWindow = vtk.vtkRenderWindow() renWindow.AddRenderer(render) renWinInteract = vtkTkRenderWindowInteractor(root, rw=renWindow, width=800, height=800) # Define volume mapper #volumeMapper = vtk.vtkSmartVolumeMapper() volumeMapper = vtk.vtkGPUVolumeRayCastMapper() volumeMapper.SetInputConnection(reader.GetOutputPort()) # Create colour transfer function colorFunc = vtk.vtkColorTransferFunction() ''' colorFunc.AddRGBPoint(1, 0.0, 0.0, 0.0) colorFunc.AddRGBPoint(2, 0.54902, 0.25098, 0.14902) colorFunc.AddRGBPoint(3, 0.882353, 0.603922, 0.290196) colorFunc.AddRGBPoint(4, 1, 0.937033, 0.954531) colorFunc.AddRGBPoint(5, 0.615686, 0, 0) colorFunc.AddRGBPoint(6, 0.827451, 0.658824, 1) ''' alphaChannelFunc = vtk.vtkPiecewiseFunction() ''' alphaChannelFunc.AddPoint(1, 0.0) alphaChannelFunc.AddPoint(2, 0.0) alphaChannelFunc.AddPoint(3, 0.29) alphaChannelFunc.AddPoint(4, 0.55) alphaChannelFunc.AddPoint(5, 0.84) alphaChannelFunc.AddPoint(6, 0.875) ''' # Define volume properties volumeProperty = vtk.vtkVolumeProperty() ''' volumeProperty.SetScalarOpacity(alphaChannelFunc) volumeProperty.SetColor(colorFunc) volumeProperty.ShadeOn() ''' # Set the mapper and volume properties ''' volume.SetMapper(volumeMapper) volume.SetProperty(volumeProperty) ''' # Add the volume to the renderer ''' render.AddVolume(volume) ''' return volumeMapper, volume, render, renWindow, renWinInteract, colorFunc, alphaChannelFunc, volumeProperty
def main(): print ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" \ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n" \ "FSIViewer - simple visualizer for FSI data\n\n" \ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" \ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n" \ "Copyright (C) 2015 Andreas Hessenthaler\n" \ " University of Stuttgart\n" \ " [email protected]\n\n" \ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" \ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n" \ "This program is free software: you can redistribute it and/" \ "or modify it under the terms of the\n" \ "GNU Lesser General Public License as published by the Free " \ "Software Foundation, either version 3\n" \ "of the License, or (at your option) any later version.\n\n" \ "This program is distributed in the hope that it will be use" \ "ful, but WITHOUT ANY WARRANTY; without\n" \ "even the implied warranty of MERCHANTABILITY or FITNESS FOR" \ " A PARTICULAR PURPOSE. See the GNU\n" \ "Lesser General Public License for more details.\n\n" \ "You should have received a copy of the GNU Lesser General " \ "Public License along with this program.\n" \ "If not, see <http://www.gnu.org/licenses/>.\n\n" \ "Please state the original author.\n\n" \ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" \ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n" \ "File I/O:\n" \ " Numpy: http://www.numpy.org/\n" \ " Cython: http://cython.org/\n" \ "GUI:\n" \ " Tkinter: http://www.tkdocs.com/tutorial/index.html\n" \ " Silk icon set 1.3 by Mark James: http://www.famfamfam.com/lab/icons/silk/\n" \ " VTK: http://www.vtk.org/\n\n" \ "Make sure that the following packages are installed:\n" \ "gcc\n" \ "python2.x\n" \ "python-tk\n" \ "python-imaging-tk\n" \ "python-dev\n" \ "python-numpy\n" \ "cython\n" \ "vtk\n\n" \ "Note: This software has been developed with VTK 5.8.0\n" \ "You are using VTK", vtk.vtkVersion().GetVTKVersion(), \ "\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" \ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" \ # create window window = gui() window.root = Tkinter.Tk() # initialise visualization visualization = fsi() # set username and read configuration visualization.username = getpass.getuser() if (os.path.exists("config/"+visualization.username+".config")): print "User-specific configuration file found:\n", \ " config/"+visualization.username+".config", \ "\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" \ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" visualization.readConfiguration( \ "config/"+visualization.username+".config") elif (os.path.exists("config/default.config")): print "Default configuration file found:\n", \ ". /config/default.config", \ "\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" \ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" visualization.readConfiguration( \ "config/default.config") else: print "No configuration file found. Please create one." # get vtk version visualization.vtkVersionMajor = vtk.vtkVersion().GetVTKMajorVersion() visualization.vtkVersionMinor = vtk.vtkVersion().GetVTKMinorVersion() visualization.vtkVersionBuild = vtk.vtkVersion().GetVTKBuildVersion() # set debug level if visualization.DEBUG: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.INFO) window.configureRoot() window.configureGUI() window.mainframe = ttk.Frame(window.root, borderwidth=5, style='My.TFrame') window.configureMainframe() window.toolbar = ttk.Frame(window.mainframe, borderwidth=5, style='My.TFrame') window.configureToolbar(visualization.installDirectory) window.loadBtn = ttk.Button(window.toolbar, image=window.useLoadIcon, \ command=lambda:visualization.defineSequence(window), style='My.TButton') window.loadBtn.pack(side=Tkinter.LEFT, fill=Tkinter.X, padx=1) window.refreshConfigBtn = ttk.Button(window.toolbar, \ image=window.useRefreshConfigIcon, \ command=visualization.refreshConfiguration, \ style='My.TButton') window.refreshConfigBtn.pack(side=Tkinter.LEFT, fill=Tkinter.X, padx=1) window.quitBtn = ttk.Button(window.toolbar, image=window.useQuitIcon, \ command=quit, style='My.TButton') window.quitBtn.pack(side=Tkinter.LEFT, fill=Tkinter.X, padx=1) ## tabs window.notebook = ttk.Notebook(window.mainframe, style='My.TNotebook') window.configureNotebook() # fluid tab window.subframeF = ttk.Frame(window.notebook, style='My.TNotebook.Tab') window.subframeF.pack() window.notebook.add(window.subframeF, text="F", state="disabled") visualization.showF = Tkinter.StringVar() visualization.showF.set("vel") ttk.Radiobutton(window.subframeF, text="pressure", \ command=visualization.updateFluid, \ variable=visualization.showF, value="presF", \ style='My.TRadiobutton').grid(column=0, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text="velocity", \ command=visualization.updateFluid, \ variable=visualization.showF, value="vel", \ style='My.TRadiobutton').grid(column=0, row = 1, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text="domain velocity", \ command=visualization.updateFluid, \ variable=visualization.showF, value="wel", \ style='My.TRadiobutton').grid(column=0, row = 2, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text="vorticity", \ command=visualization.updateFluid, \ variable=visualization.showF, value="vort", \ style='My.TRadiobutton').grid(column=0, row = 3, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text="tet quality", \ command=visualization.updateFluid, \ variable=visualization.showF, value="quality", \ style='My.TRadiobutton').grid(column=0, row = 4, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text="directional scalar", \ command=visualization.updateFluid, \ variable=visualization.showF, value="phi", \ style='My.TRadiobutton').grid(column=0, row = 5, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text="none", \ command=visualization.updateFluid, \ variable=visualization.showF, value="none", \ style='My.TRadiobutton').grid(column=0, row = 6, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Separator(window.subframeF, orient=Tkinter.HORIZONTAL).grid(column=0, \ row = 7, sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.clipFnormal = Tkinter.StringVar() visualization.clipFnormal.set('-1') ttk.Radiobutton(window.subframeF, text='full', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value="-1", \ style='My.TRadiobutton').grid(column=0, row = 8, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='clip w/ normal x (elem)', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value="xe", \ style='My.TRadiobutton').grid(column=0, row = 9, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='clip w/ normal y (elem)', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value="ye", \ style='My.TRadiobutton').grid(column=0, row = 10, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text="clip w/ normal z (elem)", \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='ze', \ style='My.TRadiobutton').grid(column=0, row = 11, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='clip w/ normal x', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='x', \ style='My.TRadiobutton').grid(column=0, row = 17, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='clip w/ normal y', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='y', \ style='My.TRadiobutton').grid(column=0, row = 18, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='clip w/ normal z', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='z', \ style='My.TRadiobutton').grid(column=0, row = 19, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='plane w/ normal x', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='a', \ style='My.TRadiobutton').grid(column=0, row = 20, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='plane w/ normal y', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='b', \ style='My.TRadiobutton').grid(column=0, row = 21, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='plane w/ normal z', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='c', \ style='My.TRadiobutton').grid(column=0, row = 22, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='vortex structure', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='vortex-structure', \ style='My.TRadiobutton').grid(column=0, row = 23, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) # ttk.Separator(window.subframeF, orient=Tkinter.HORIZONTAL).grid(column=0, \ # row = 23, sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.boolEdgesF = Tkinter.BooleanVar() visualization.boolEdgesF.set(False) ttk.Checkbutton(window.subframeF, \ variable=visualization.boolEdgesF, text='Show tri/tet edges', \ command=visualization.edgesOnOffF, \ style='My.TCheckbutton').grid(column=0, row = 24, \ sticky=(Tkinter.W, Tkinter.E)) ttk.Separator(window.subframeF, orient=Tkinter.HORIZONTAL).grid(column=0, \ row = 25, sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.boolShowScalarBarF = Tkinter.BooleanVar() visualization.boolShowScalarBarF.set(False) ttk.Checkbutton(window.subframeF, \ variable=visualization.boolShowScalarBarF, text='Show scalarbar', \ command=visualization.scalarBarOnOffF, \ style='My.TCheckbutton').grid(column=0, row = 26, \ sticky=(Tkinter.W, Tkinter.E)) window.componentFrameF = ttk.Frame(window.subframeF, style='My.TFrame') window.componentFrameF.grid(column=0, row=27, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) ttk.Label(window.componentFrameF, width=15, text="Use component:", \ style='My.TLabel').grid(column=0, row=0, sticky=Tkinter.S) visualization.componentDropDownF = ttk.Combobox(window.componentFrameF, \ justify=Tkinter.LEFT, width=10) visualization.componentDropDownF.grid(column=1, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.componentDropDownF.bind('<<ComboboxSelected>>', \ visualization.componentUpdateF) visualization.componentDropDownF['values'] = \ ("magnitude", "x", "y", "z") visualization.componentDropDownF.set("magnitude") ttk.Checkbutton(window.componentFrameF, \ variable=visualization.boolAutoRangeF, text='Auto-range', \ command=lambda:visualization.enableUserRangeF(window), \ style='My.TCheckbutton').grid(column=0, row=1, \ sticky=(Tkinter.W, Tkinter.E)) window.entryMinF = ttk.Entry(window.componentFrameF, width=5, \ textvariable=visualization.userMinF, \ justify=Tkinter.RIGHT, state=["disabled"]) window.entryMinF.grid(column=0, row=2, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) window.entryMaxF = ttk.Entry(window.componentFrameF, width=5, \ textvariable=visualization.userMaxF, \ justify=Tkinter.RIGHT, state=["disabled"]) window.entryMaxF.grid(column=1, row=2, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) visualization.boolShowOutlineF = Tkinter.BooleanVar() visualization.boolShowOutlineF.set(False) ttk.Checkbutton(window.subframeF, \ variable=visualization.boolShowOutlineF, text='Show outline', \ command=visualization.outlineOnOffF, \ style='My.TCheckbutton').grid(column=0, row = 28, \ sticky=(Tkinter.W, Tkinter.E)) ttk.Separator(window.subframeF, orient=Tkinter.HORIZONTAL).grid(column=0, \ row = 29, sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) labelsDropDown = ttk.Combobox(window.subframeF, \ textvariable=visualization.labelVar) labelsDropDown.grid(column=0, row = 30, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) # labelsDropDown.bind('<<ComboboxSelected>>', modifyLabelF) labelsDropDown['values'] = ('No label', 'Node ID', 'Node coordinates', 'Cell ID', 'Pressure', 'Velocity') labelsDropDown.set('no label') ttk.Radiobutton(window.subframeF, text='plane w/ normal x (resample)', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='i', \ style='My.TRadiobutton').grid(column=0, row = 31, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='plane w/ normal y (resample)', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='j', \ style='My.TRadiobutton').grid(column=0, row = 32, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeF, text='plane w/ normal z (resample)', \ command=visualization.updateFluid, \ variable=visualization.clipFnormal, value='k', \ style='My.TRadiobutton').grid(column=0, row = 33, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) # solid tab window.subframeS = ttk.Frame(window.notebook, style='My.TNotebook.Tab') window.subframeS.pack() window.notebook.add(window.subframeS, text="S", state="disabled") visualization.showS = Tkinter.StringVar() visualization.showS.set("disp") ttk.Radiobutton(window.subframeS, text="pressure", \ command=visualization.updateSolid, \ variable=visualization.showS, value="presS", \ style='My.TRadiobutton').grid(column=0, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeS, text="displacement", \ command=visualization.updateSolid, \ variable=visualization.showS, value="disp", \ style='My.TRadiobutton').grid(column=0, row = 1, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeS, text="velocity", \ command=visualization.updateSolid, \ variable=visualization.showS, value="vel", \ style='My.TRadiobutton').grid(column=0, row = 2, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeS, text="Cauchy stress", \ command=visualization.updateSolid, \ variable=visualization.showS, value="cauchy", \ style='My.TRadiobutton').grid(column=0, row = 3, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeS, text="tet quality", \ command=visualization.updateSolid, \ variable=visualization.showS, value="quality", \ style='My.TRadiobutton').grid(column=0, row = 4, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeS, text="none", \ command=visualization.updateSolid, \ variable=visualization.showS, value="none", \ style='My.TRadiobutton').grid(column=0, row = 5, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Separator(window.subframeS, \ orient=Tkinter.HORIZONTAL).grid(column=0, row = 6, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.boolEdgesS = Tkinter.BooleanVar() visualization.boolEdgesS.set(False) ttk.Checkbutton(window.subframeS, \ variable=visualization.boolEdgesS, text='Show tri/tet edges', \ command=visualization.meshTubesOnOffS, \ style='My.TCheckbutton').grid(column=0, row = 7, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.boolShowScalarBarS = Tkinter.BooleanVar() visualization.boolShowScalarBarS.set(False) ttk.Checkbutton(window.subframeS, \ variable=visualization.boolShowScalarBarS, text='Show scalarbar', \ command=visualization.scalarBarOnOffS, \ style='My.TCheckbutton').grid(column=0, row = 8, \ sticky=(Tkinter.W, Tkinter.E)) window.componentFrameS = ttk.Frame(window.subframeS, style='My.TFrame') window.componentFrameS.grid(column=0, row=9, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) ttk.Label(window.componentFrameS, width=15, text="Use component:", \ style='My.TLabel').grid(column=0, row=0, sticky=Tkinter.S) visualization.componentDropDownS = ttk.Combobox(window.componentFrameS, \ justify=Tkinter.LEFT, width=10) visualization.componentDropDownS.grid(column=1, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.componentDropDownS.bind('<<ComboboxSelected>>', \ visualization.componentUpdateS) visualization.componentDropDownS['values'] = \ ("magnitude", "x", "y", "z") visualization.componentDropDownS.set("magnitude") ttk.Checkbutton(window.componentFrameS, \ variable=visualization.boolAutoRangeS, text='Auto-range', \ command=lambda:visualization.enableUserRangeS(window), \ style='My.TCheckbutton').grid(column=0, row=1, \ sticky=(Tkinter.W, Tkinter.E)) window.entryMinS = ttk.Entry(window.componentFrameS, width=5, \ textvariable=visualization.userMinS, \ justify=Tkinter.RIGHT, state=["disabled"]) window.entryMinS.grid(column=0, row=2, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) window.entryMaxS = ttk.Entry(window.componentFrameS, width=5, \ textvariable=visualization.userMaxS, \ justify=Tkinter.RIGHT, state=["disabled"]) window.entryMaxS.grid(column=1, row=2, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) visualization.boolShowOutlineS = Tkinter.BooleanVar() visualization.boolShowOutlineS.set(False) ttk.Checkbutton(window.subframeS, \ variable=visualization.boolShowOutlineS, text='Show outline', \ command=visualization.outlineOnOffS, \ style='My.TCheckbutton').grid(column=0, row = 16, \ sticky=(Tkinter.W, Tkinter.E)) visualization.boolShowOnReferenceS = Tkinter.BooleanVar() visualization.boolShowOnReferenceS.set(False) ttk.Checkbutton(window.subframeS, \ variable=visualization.boolShowOnReferenceS, text='Use reference configuration', \ command=visualization.referenceOnOffS, \ style='My.TCheckbutton').grid(column=0, row = 17, \ sticky=(Tkinter.W, Tkinter.E)) ttk.Separator(window.subframeS, orient=Tkinter.HORIZONTAL).grid(column=0, \ row = 18, sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) window.nodeFrameS = ttk.Frame(window.subframeS, style='My.TFrame') window.nodeFrameS.grid(column=0, row=19, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) nodeButtonS = ttk.Button(window.nodeFrameS, \ command=visualization.updateNodeS, \ text="Track node:", style='My.TButton') nodeButtonS.grid(column=0, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) window.entryNodeS = ttk.Entry(window.nodeFrameS, width=6, \ textvariable=visualization.nodeS, \ justify=Tkinter.RIGHT) window.entryNodeS.grid(column=1, row=0, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E, Tkinter.N)) ttk.Entry(window.nodeFrameS, width=8, \ textvariable=visualization.nodeSrefX, \ justify=Tkinter.RIGHT).grid( \ column=0, row=1, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E, Tkinter.N)) ttk.Entry(window.nodeFrameS, width=8, \ textvariable=visualization.nodeSrefY, \ justify=Tkinter.RIGHT).grid( \ column=0, row=2, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E, Tkinter.N)) ttk.Entry(window.nodeFrameS, width=8, \ textvariable=visualization.nodeSrefZ, \ justify=Tkinter.RIGHT).grid( \ column=0, row=3, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E, Tkinter.N)) ttk.Entry(window.nodeFrameS, width=8, \ textvariable=visualization.nodeSx, \ justify=Tkinter.RIGHT).grid( \ column=1, row=1, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E, Tkinter.N)) ttk.Entry(window.nodeFrameS, width=8, \ textvariable=visualization.nodeSy, \ justify=Tkinter.RIGHT).grid( \ column=1, row=2, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E, Tkinter.N)) ttk.Entry(window.nodeFrameS, width=8, \ textvariable=visualization.nodeSz, \ justify=Tkinter.RIGHT).grid( \ column=1, row=3, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E, Tkinter.N)) # interface tab window.subframeI = ttk.Frame(window.notebook, style='My.TNotebook.Tab') window.subframeI.pack() window.notebook.add(window.subframeI, text="I", state="disabled") visualization.showI = Tkinter.StringVar() visualization.showI.set("lm") ttk.Radiobutton(window.subframeI, text='Lagrange multiplier', \ command=visualization.updateInterface, \ variable=visualization.showI, value='lm', \ style='My.TRadiobutton').grid(column=0, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Radiobutton(window.subframeI, text='none', \ command=visualization.updateInterface, \ variable=visualization.showI, value='none', \ style='My.TRadiobutton').grid(column=0, row = 3, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Separator(window.subframeI, \ orient=Tkinter.HORIZONTAL).grid(column=0, row = 4, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.boolEdgesI = Tkinter.BooleanVar() visualization.boolEdgesI.set(False) ttk.Checkbutton(window.subframeI, \ variable=visualization.boolEdgesI, text='Show tri/tet edges', \ command=visualization.edgesOnOffI, \ style='My.TCheckbutton').grid(column=0, row = 5, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.boolShowScalarBarI = Tkinter.BooleanVar() visualization.boolShowScalarBarI.set(False) ttk.Checkbutton(window.subframeI, \ variable=visualization.boolShowScalarBarI, text='Show scalarbar', \ command=visualization.scalarBarOnOffI, \ style='My.TCheckbutton').grid(column=0, row = 6, \ sticky=(Tkinter.W, Tkinter.E)) window.componentFrameI = ttk.Frame(window.subframeI, style='My.TFrame') window.componentFrameI.grid(column=0, row=7, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) ttk.Label(window.componentFrameI, width=15, text="Use component:", \ style='My.TLabel').grid(column=0, row=0, sticky=Tkinter.S) visualization.componentDropDownI = ttk.Combobox(window.componentFrameI, \ justify=Tkinter.LEFT, width=10) visualization.componentDropDownI.grid(column=1, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.componentDropDownI.bind('<<ComboboxSelected>>', \ visualization.componentUpdateI) visualization.componentDropDownI['values'] = \ ("magnitude", "x", "y", "z") visualization.componentDropDownI.set("magnitude") ttk.Checkbutton(window.componentFrameI, \ variable=visualization.boolAutoRangeI, text='Auto-range', \ command=lambda:visualization.enableUserRangeI(window), \ style='My.TCheckbutton').grid(column=0, row=1, \ sticky=(Tkinter.W, Tkinter.E)) window.entryMinI = ttk.Entry(window.componentFrameI, width=5, \ textvariable=visualization.userMinI, \ justify=Tkinter.RIGHT, state=["disabled"]) window.entryMinI.grid(column=0, row=2, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) window.entryMaxI = ttk.Entry(window.componentFrameI, width=5, \ textvariable=visualization.userMaxI, \ justify=Tkinter.RIGHT, state=["disabled"]) window.entryMaxI.grid(column=1, row=2, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) visualization.boolShowOutlineI = Tkinter.BooleanVar() visualization.boolShowOutlineI.set(False) ttk.Checkbutton(window.subframeI, \ variable=visualization.boolShowOutlineI, text='Show outline', \ command=visualization.outlineOnOffI, \ style='My.TCheckbutton').grid(column=0, row = 16, \ sticky=(Tkinter.W, Tkinter.E)) # viewer tab window.subframeV = ttk.Frame(window.notebook, style='My.TNotebook.Tab') window.subframeV.pack() window.notebook.add(window.subframeV, text="Viewer ", state="normal") visualization.backgroundDropDown = ttk.Combobox(window.subframeV) visualization.backgroundDropDown.grid(column=0, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.backgroundDropDown.bind('<<ComboboxSelected>>', \ visualization.modifyBackground) visualization.backgroundDropDown['values'] = \ ('black background', 'black-white background', \ 'white background', 'white-black background', \ 'custom background', 'custom-white background') visualization.backgroundDropDown.set('white background') ttk.Button(window.subframeV, \ command=lambda:visualization.modifyCamera(window), \ text="Modify camera view", style='My.TButton').grid(column=0, row = 2, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Button(window.subframeV, \ command=visualization.screenshot, \ text="Screenshot", style='My.TButton').grid(column=0, row = 4, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) #ttk.Separator(window.subframeV, orient=Tkinter.HORIZONTAL).grid(column=0, \ # row = 5, sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) fromFrame = ttk.Frame(window.subframeV, style='My.TFrame') fromFrame.grid(column=0, row=7, sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) toFrame = ttk.Frame(window.subframeV, style='My.TFrame') toFrame.grid(column=0, row=8, sticky=(Tkinter.W, Tkinter.N, Tkinter.E)) visualization.animateFromStr = Tkinter.StringVar() visualization.animateToStr = Tkinter.StringVar() visualization.animateFromStr.set(str(visualization.animateFromT)) visualization.animateToStr.set(str(visualization.animateToT)) ttk.Label(fromFrame, width=7, text="from:", \ style='My.TLabel').grid(column=0, row=0, sticky=Tkinter.S) ttk.Entry(fromFrame, width=10, textvariable=visualization.animateFromStr, \ justify=Tkinter.RIGHT).grid(column=1, row=0, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) ttk.Label(toFrame, width=7, text="to: ", \ style='My.TLabel').grid(column=0, row=0, sticky=Tkinter.S) ttk.Entry(toFrame, width=10, textvariable=visualization.animateToStr, \ justify=Tkinter.RIGHT).grid(column=1, row=0, \ sticky=(Tkinter.W, Tkinter.N, Tkinter.E)) screenshotFrame = ttk.Frame(window.subframeV, style='My.TFrame') screenshotFrame.grid(column=0, row=9, sticky=(Tkinter.W, Tkinter.E)) visualization.screenshotFolderStr = Tkinter.StringVar() visualization.screenshotFolderStr.set("png/") ttk.Label(screenshotFrame, width=7, text="folder:", \ style='My.TLabel').grid(column=0, row=0, sticky=Tkinter.S) ttk.Entry(screenshotFrame, width=10, \ textvariable=visualization.screenshotFolderStr, \ justify=Tkinter.RIGHT).grid(column=1, row=0, \ sticky=(Tkinter.W, Tkinter.S, Tkinter.E)) animateSaveFrame = ttk.Frame(window.subframeV) animateSaveFrame.grid(column=0, row=10, sticky=(Tkinter.W, Tkinter.E)) animateButton = ttk.Button(animateSaveFrame, \ command=visualization.animate, \ text="Animate", style='My.TButton') animateButton.grid(column=0, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) saveButton = ttk.Button(animateSaveFrame, \ command=visualization.animateNsave, \ text="Animate & save", style='My.TButton') saveButton.grid(column=1, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) phasesFrame = ttk.Frame(window.subframeV, style='My.TFrame') phasesFrame.grid(column=0, row=15, sticky=(Tkinter.W, Tkinter.E)) probeButtonI = ttk.Button(phasesFrame, \ command=lambda:visualization.phaseIorII(window, 1), \ text="Phase I", style='My.TButton').grid(column=0, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) probeButtonII = ttk.Button(phasesFrame, \ command=lambda:visualization.phaseIorII(window, 2), \ text="Phase II", style='My.TButton').grid(column=1, row = 0, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) ttk.Button(window.subframeV, \ command=lambda:visualization.displayPoints(window), \ text="Display points", style='My.TButton').grid(column=0, row = 20, \ sticky=(Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.boolShowPoints = Tkinter.BooleanVar() visualization.boolShowPoints.set(False) visualization.showPointsCheckbutton = ttk.Checkbutton(window.subframeV, \ variable=visualization.boolShowPoints, text='Show points', \ command=visualization.pointsOnOff, \ style='My.TCheckbutton').grid(column=0, row = 21, \ sticky=(Tkinter.W, Tkinter.E)) visualization.configureCamera() visualization.renderer = vtk.vtkRenderer() visualization.configureRenderer() visualization.addSphere() visualization.renderWindow = vtk.vtkRenderWindow() visualization.renderWindow.AddRenderer(visualization.renderer) visualization.renderWidget = vtkTkRenderWindowInteractor(window.mainframe, \ rw=visualization.renderWindow) visualization.renderWidget.grid(column=2, row=0, rowspan=window.gridy-2, \ columnspan=window.gridx-2, \ sticky = (Tkinter.N, Tkinter.W, Tkinter.E, Tkinter.S)) visualization.renderWidget.focus() # create slider for modifying current time visualization.timeSlider = Tkinter.Scale(window.mainframe, \ from_=visualization.fromT, to=visualization.toT, \ resolution=visualization.increment, \ orient=Tkinter.HORIZONTAL, \ showvalue=0, state=Tkinter.DISABLED, \ background=window.linuxMintHEX, foreground='black', \ relief='flat', borderwidth=0) visualization.timeSlider.set(visualization.currentT) visualization.timeSlider.grid(padx=0, pady=5, column=2, row=window.gridy-1, \ columnspan=window.gridx-3, sticky = (Tkinter.W, Tkinter.E)) visualization.timeLabelText = Tkinter.StringVar() visualization.timeLabelText.set(str(visualization.currentT)) # toolbar for +/- increments toolbarPM = ttk.Frame(window.mainframe, style='My.TFrame', \ height=5, width=45) toolbarPM.grid(row=window.gridy-1, column=window.gridx-1, \ sticky=(Tkinter.W, Tkinter.E)) toolbarPMlabel = ttk.Label(toolbarPM, \ textvariable=visualization.timeLabelText, width=6, style='My.TLabel') toolbarPMlabel.grid(row=0, column=0, padx=5) buttonMinus = ttk.Button(toolbarPM, text='-', \ command=visualization.previousT, \ style='My.TButton') buttonMinus.grid(row=0, column=1) buttonPlus = ttk.Button(toolbarPM, text='+', \ command=visualization.nextT, \ style='My.TButton') buttonPlus.grid(row=0, column=2) # progress bar visualization.progress = ttk.Progressbar(window.mainframe, \ orient=Tkinter.HORIZONTAL, mode='determinate') visualization.progress.grid(column=0, row=window.gridy-1, \ sticky = (Tkinter.W, Tkinter.E)) visualization.progress.grid_remove() # renderWindowInteractor visualization.interactor = \ visualization.renderWidget.GetRenderWindow().GetInteractor() visualization.interactorStyle = vtk.vtkInteractorStyleTrackballCamera() visualization.interactor.SetInteractorStyle(visualization.interactorStyle) visualization.interactor.AddObserver("KeyPressEvent", visualization.keypress) # create a popup menu to choose colorbar map menu = Tkinter.Menu(window.root, tearoff=0) visualization.scalarBarCacheF = Tkinter.IntVar() visualization.scalarBarCacheF.set(visualization.ctfNumberF) visualization.scalarBarCacheS = Tkinter.IntVar() visualization.scalarBarCacheS.set(visualization.ctfNumberS) visualization.scalarBarCacheI = Tkinter.IntVar() visualization.scalarBarCacheI.set(visualization.ctfNumberI) menu.add_radiobutton(label="Rainbow", \ command=lambda:visualization.nextCTF("fluid"), \ variable=visualization.scalarBarCacheF, value=0) menu.add_radiobutton(label="Blue-red", \ command=lambda:visualization.nextCTF("fluid"), \ variable=visualization.scalarBarCacheF, value=1) menu.add_radiobutton(label="Blue-white-red", \ command=lambda:visualization.nextCTF("fluid"), \ variable=visualization.scalarBarCacheF, value=2) menu.add_radiobutton(label="Black-white", \ command=lambda:visualization.nextCTF("fluid"), \ variable=visualization.scalarBarCacheF, value=3) menu.add_separator() menu.add_radiobutton(label="Rainbow", \ command=lambda:visualization.nextCTF("solid"), \ variable=visualization.scalarBarCacheS, value=0) menu.add_radiobutton(label="Blue-red", \ command=lambda:visualization.nextCTF("solid"), \ variable=visualization.scalarBarCacheS, value=1) menu.add_radiobutton(label="Blue-white-red", \ command=lambda:visualization.nextCTF("solid"), \ variable=visualization.scalarBarCacheS, value=2) menu.add_radiobutton(label="Black-white", \ command=lambda:visualization.nextCTF("solid"), \ variable=visualization.scalarBarCacheS, value=3) menu.add_separator() menu.add_radiobutton(label="Rainbow", \ command=lambda:visualization.nextCTF("interface"), \ variable=visualization.scalarBarCacheI, value=0) menu.add_radiobutton(label="Blue-red", \ command=lambda:visualization.nextCTF("interface"), \ variable=visualization.scalarBarCacheI, value=1) menu.add_radiobutton(label="Blue-white-red", \ command=lambda:visualization.nextCTF("interface"), \ variable=visualization.scalarBarCacheI, value=2) menu.add_radiobutton(label="Black-white", \ command=lambda:visualization.nextCTF("interface"), \ variable=visualization.scalarBarCacheI, value=3) def popup(event): menu.post(event.x_root, event.y_root) window.root.bind("<Button-3>", popup) # render scene visualization.renderWidget.Render() visualization.cameraUpdate() # start main loop window.root.mainloop()
z_button = Tkinter.Button(ctrl_buttons, text="z", command=AlignZaxis) x_button.bind("<Button-3>", lambda e: buttonEvent(e, 0)) y_button.bind("<Button-3>", lambda e: buttonEvent(e, 1)) z_button.bind("<Button-3>", lambda e: buttonEvent(e, 2)) for i in (quit_button, capture_button, x_button, y_button, z_button): i.pack(side="left", expand="true", fill="both") # Create the render widget renderer_frame = Tkinter.Frame(display_frame) renderer_frame.pack(padx=3, pady=3,side="left", anchor="n", fill="both", expand="false") render_widget = vtkTkRenderWindowInteractor(renderer_frame, rw=renWin, width=600, height=600) for i in (render_widget, display_frame): i.pack(side="top", anchor="n",fill="both", expand="false") # Add a slice scale to browse the current slice stack slice_number = Tkinter.IntVar() slice_number.set(current_widget.GetSliceIndex()) slice = Tkinter.Scale(top, from_=zMin, to=zMax, orient="horizontal", command=SetSlice,variable=slice_number, label="Slice") slice.pack(fill="x", expand="false") # Done with the GUI. ###
def __init__(self, parent, config): self.config = config tk.Frame.__init__(self, parent) self.parent = parent parent.wm_title('radcal-gui') self.pack(fill='both', expand=1) # left section self.frame_dir = tk.Frame(self) self.frame_dir.pack(side='left', fill='y', expand=0) tk.Button(self.frame_dir, text='Open...', command=self.open_dir).pack(side='top') tk.Label(self.frame_dir, text='current directory:', anchor='w', width=30).pack(side='top') self.var_dirname = tk.StringVar() tk.Label(self.frame_dir, textvariable=self.var_dirname, anchor='w', width=30).pack(side='top') self.list_file = tk.Listbox(self.frame_dir, selectmode='browse') self.list_file.bind('<<ListboxSelect>>', self.file_modified) self.list_file.pack(fill='x') # main section self.frame_main = tk.Frame(self) self.frame_main.pack(fill='both', expand=1) # top section self.frame_file = tk.Frame(self.frame_main, bd=1, relief='sunken') self.frame_file.pack(fill='x', expand=0) tk.Button(self.frame_file, text='Open file', command=self.open_file).pack(side='left') self.var_filename = tk.StringVar() tk.Label(self.frame_file, textvariable=self.var_filename).pack(side='left') # middle section frame_main = tk.Frame(self.frame_main) frame_main.pack(fill='both', expand=1) ren_win = vtk.vtkRenderWindow() iren = vtkTkRenderWindowInteractor(frame_main, rw=ren_win, width=600, height=600) self.vtk = vtkgui.VtkGui(iren) iren.pack(side='left', fill='both', expand=1) frame_control = tk.Frame(frame_main) frame_control.pack(side='left') frame_dim = tk.Frame(frame_control) frame_dim.pack(fill='x', expand=0) self.var_dim = tk.IntVar() self.var_dim.set(3) tk.Radiobutton(frame_dim, text='2D', variable=self.var_dim, value=2, command=self.dim_modified).pack(side='left', fill='x', expand=1) tk.Radiobutton(frame_dim, text='3D', variable=self.var_dim, value=3, command=self.dim_modified).pack(side='right', fill='x', expand=1) self.button_render = tk.Button(frame_control, text='Render', command=self.render, state='disabled') self.button_render.pack(fill='x', expand=0) self.button_clear = tk.Button(frame_control, text='Clear', command=self.clear) self.button_clear.pack(fill='x', expand=0) self.var_scalarbar = tk.IntVar() self.check_scalarbar = tk.Checkbutton(frame_control, text='Scalar Bar', variable=self.var_scalarbar, command=self.scalarbar_modified) self.check_scalarbar.pack(fill='x') self.var_contour = tk.IntVar() self.check_contour = tk.Checkbutton(frame_control, text='Contour', variable=self.var_contour, command=self.contour_modified) self.check_contour.pack(fill='x') tk.Label(frame_control, text='Variables:').pack() self.list_var = tk.Listbox(frame_control, selectmode='browse') self.list_var.bind('<<ListboxSelect>>', self.var_modified) self.list_var.pack(fill='x') tk.Label(frame_control, text='Probing line:').pack() self.frame_probe = tk.Frame(frame_control) self.frame_probe.pack(fill='x', expand=1) command_val_float = (self.parent.register(validate_float), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W') self.var_coord = tk.StringVar() # self.var_coord.set('x') coord_tab = ['x', 'y', 'z'] counter = 0 self.entry_coord = {} self.radio_coord = {} self.label_coord = {} for c in coord_tab: self.radio_coord[c] = tk.Radiobutton(self.frame_probe, text=c, variable=self.var_coord, value=c, command=self.coord_modified) self.radio_coord[c].grid(row=counter, column=0) self.entry_coord[c] = tk.Entry(self.frame_probe, validate='key', validatecommand=command_val_float) self.entry_coord[c].grid(row=counter, column=1) self.label_coord[c] = tk.StringVar() tk.Label(self.frame_probe, textvariable=self.label_coord[c]).grid(row=counter, column=2) counter += 1 self.var_timeplot = tk.IntVar() self.check_timeplot = tk.Checkbutton(self.frame_probe, text='time plot', variable=self.var_timeplot, command=self.timeplot_modified, state='disabled') self.check_timeplot.grid(row=3, column=0, columnspan=2) # bottom section self.frame_control = tk.Frame(self.frame_main, bd=1, relief='sunken') self.frame_control.pack(fill='x', expand=0) tk.Button(self.frame_control, text='Quit', command=self.parent.quit, padx=5, pady=5).pack(side='right') tk.Button(self.frame_control, text='Save', command=self.write, padx=5, pady=5).pack(side='right') tk.Button(self.frame_control, text='Print', command=self.screenshot, padx=5, pady=5).pack(side='right') frame_time = tk.Frame(self.frame_control) frame_time.pack(side='left') button_cfg = {'side': 'left'} self.button_first = tk.Button(frame_time, text='|<', command=lambda: self.set_timestep(0), width=3) self.button_first.pack(**button_cfg) self.button_prev = tk.Button( frame_time, text='<', command=lambda: self.set_timestep(self.var_curtimestep.get() - 1), width=3) self.button_prev.pack(**button_cfg) self.button_play = tk.Button(frame_time, text='|>', command=self.play, width=3) self.button_play.pack(**button_cfg) self.button_next = tk.Button( frame_time, text='>', command=lambda: self.set_timestep(self.var_curtimestep.get() + 1), width=3) self.button_next.pack(**button_cfg) self.button_last = tk.Button( frame_time, text='>|', command=lambda: self.set_timestep(self.vtk.data.num_times - 1), width=3) self.button_last.pack(**button_cfg) tk.Label(frame_time, text='time:').pack(side='left', padx=10) self.var_curtime = tk.DoubleVar() self.var_curtime.set(0.0) tk.Label(frame_time, textvariable=self.var_curtime, relief='sunken', width=10).pack(side='left') tk.Label(frame_time, text='timestep:').pack(side='left', padx=10) self.var_curtimestep = tk.IntVar() self.var_curtimestep.set('0') command_val_int = (self.parent.register(validate_int), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W') self.entry_timestep = tk.Entry(frame_time, text=self.var_curtimestep, validate='key', validatecommand=command_val_int, relief='sunken', width=10, justify='right') self.entry_timestep.pack(side='left') self.string_timestep = tk.StringVar() self.label_timestep = tk.Label(frame_time, textvariable=self.string_timestep) self.label_timestep.pack(side='left') self.button_go = tk.Button(frame_time, text='go', command=self.timestep_modified) self.button_go.pack(side='left') self.clear() self.init_kshortcuts()
z_button.bind("<Button-3>", lambda e: buttonEvent(e, 2)) for i in (quit_button, capture_button, x_button, y_button, z_button): i.pack(side="left", expand="true", fill="both") # Create the render widget renderer_frame = Tkinter.Frame(display_frame) renderer_frame.pack(padx=3, pady=3, side="left", anchor="n", fill="both", expand="false") render_widget = vtkTkRenderWindowInteractor(renderer_frame, rw=renWin, width=600, height=600) for i in (render_widget, display_frame): i.pack(side="top", anchor="n", fill="both", expand="false") # Add a slice scale to browse the current slice stack slice_number = Tkinter.IntVar() slice_number.set(current_widget.GetSliceIndex()) slice = Tkinter.Scale(top, from_=zMin, to=zMax, orient="horizontal", command=SetSlice, variable=slice_number, label="Slice") slice.pack(fill="x", expand="false")
def run(self): doImports() self.renWin = vtk.vtkRenderWindow() self.ren = vtk.vtkRenderer() self.renWin.AddRenderer(self.ren) self.renWin.SetSize(600, 600) self.ren.SetBackground(0.7, 0.7, 0.7) self.ren.ResetCamera() self.cam = self.ren.GetActiveCamera() self.axes = vtk.vtkCubeAxesActor2D() self.axes.SetCamera(self.ren.GetActiveCamera()) self.undefinedActor=vtk.vtkTextActor() self.undefinedActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() self.undefinedActor.GetPositionCoordinate().SetValue(0.05,0.2) self.undefinedActor.GetTextProperty().SetColor(1.,0.,0.) self.undefinedActor.SetInput("") try: self.readFile() except Exception: e = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e' warning("While reading",self.parser.getArgs()[0],"this happened:",e) raise e self.ren.ResetCamera() self.root = tkinter.Tk() self.root.withdraw() # Create the toplevel window self.top = tkinter.Toplevel(self.root) self.top.title("blockMesh-Viewer") self.top.protocol("WM_DELETE_WINDOW", self.quit) # Create some frames self.f1 = tkinter.Frame(self.top) self.f2 = tkinter.Frame(self.top) self.f1.pack(side="top", anchor="n", expand=1, fill="both") self.f2.pack(side="bottom", anchor="s", expand="f", fill="x") # Create the Tk render widget, and bind the events self.rw = vtkTkRenderWindowInteractor(self.f1, width=400, height=400, rw=self.renWin) self.rw.pack(expand="t", fill="both") self.blockHigh=tkinter.IntVar() self.blockHigh.set(-1) self.oldBlock=-1 self.blockActor=None self.blockTextActor=None self.patchHigh=tkinter.IntVar() self.patchHigh.set(-1) self.oldPatch=-1 self.patchActor=None self.patchTextActor=vtk.vtkTextActor() self.patchTextActor.GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay() self.patchTextActor.GetPositionCoordinate().SetValue(0.05,0.1) self.patchTextActor.GetTextProperty().SetColor(0.,0.,0.) self.patchTextActor.SetInput("Patch: <none>") self.scroll=tkinter.Scale(self.f2,orient='horizontal', from_=-1,to=len(self.blocks)-1,resolution=1,tickinterval=1, label="Block (-1 is none)", variable=self.blockHigh,command=self.colorBlock) self.scroll.pack(side="top", expand="t", fill="x") self.scroll2=tkinter.Scale(self.f2,orient='horizontal', from_=-1,to=len(list(self.patches.keys()))-1,resolution=1,tickinterval=1, label="Patch (-1 is none)", variable=self.patchHigh,command=self.colorPatch) self.scroll2.pack(side="top", expand="t", fill="x") self.f3 = tkinter.Frame(self.f2) self.f3.pack(side="bottom", anchor="s", expand="f", fill="x") self.b1 = tkinter.Button(self.f3, text="Quit", command=self.quit) self.b1.pack(side="left", expand="t", fill="x") self.b2 = tkinter.Button(self.f3, text="Reread blockMeshDict", command=self.reread) self.b2.pack(side="left", expand="t", fill="x") self.root.update() self.iren = self.renWin.GetInteractor() self.istyle = vtk.vtkInteractorStyleSwitch() self.iren.SetInteractorStyle(self.istyle) self.istyle.SetCurrentStyleToTrackballCamera() self.addProps() self.iren.Initialize() self.renWin.Render() self.iren.Start() self.root.mainloop()
def InitializeGUI(self, w, h): self.top = Tkinter.Toplevel(self.root) # make sure exit happens gracefully def quit(obj=self.root): obj.quit() self.top.protocol("WM_DELETE_WINDOW", quit) self.frmDisplay = Tkinter.Frame(self.top) self.frmRender = Tkinter.Frame(self.frmDisplay) for f in (self.frmDisplay, self.frmRender): f.pack(padx=3, pady=3, side="top", anchor="n", fill="both", expand="false") rwi = vtkTkRenderWindowInteractor(self.frmRender, rw=Globals.renWin, width=w, height=h) rwi.pack() rwi.Render() self.renderWidget = rwi self.root.update() frmModes = Tkinter.Frame(self.top) frmModes.pack() self.radioVar = Tkinter.IntVar() self.radioVar.set(0) self.dicGuiModes = { 0: "Navigation", 1: "Add Region", 2: "Laplace", 3: "Profile Inspector", 4: "Highlight", 5: "Delete Region" } for k in self.dicGuiModes.keys(): Tkinter.Radiobutton(frmModes, text=self.dicGuiModes[k], variable=self.radioVar, value=k, command=self.ChangeMode).pack(side="left") # Add a slice scale to browse the current slice stack sliceNumber = Tkinter.IntVar() smin, smax = Globals.imagePipeline.GetAxisExtent() sliceNumber.set(Globals.imagePipeline.GetSliceIndex()) self.scaleSlice = Tkinter.Scale(self.top, from_=smin, to=smax, orient="horizontal", command=self.SetSlice, variable=sliceNumber, label="Slice") self.scaleSlice.pack(fill="x", expand="false") self.SetupMenubar()
def __init__(self, parent, config): self.config = config tk.Frame.__init__(self, parent) self.parent = parent parent.wm_title('radcal-gui') self.pack(fill='both', expand=1) # left section self.frame_dir = tk.Frame(self) self.frame_dir.pack(side='left', fill='y', expand=0) tk.Button(self.frame_dir, text='Open...', command=self.open_dir).pack(side='top') tk.Label(self.frame_dir, text='current directory:', anchor='w', width=30).pack(side='top') self.var_dirname = tk.StringVar() tk.Label(self.frame_dir, textvariable=self.var_dirname, anchor='w', width=30).pack(side='top') self.list_file = tk.Listbox(self.frame_dir, selectmode='browse') self.list_file.bind('<<ListboxSelect>>', self.file_modified) self.list_file.pack(fill='x') # main section self.frame_main = tk.Frame(self) self.frame_main.pack(fill='both', expand=1) # top section self.frame_file = tk.Frame(self.frame_main, bd=1, relief='sunken') self.frame_file.pack(fill='x', expand=0) tk.Button(self.frame_file, text='Open file', command=self.open_file).pack(side='left') self.var_filename = tk.StringVar() tk.Label(self.frame_file, textvariable=self.var_filename).pack(side='left') # middle section frame_main = tk.Frame(self.frame_main) frame_main.pack(fill='both', expand=1) ren_win = vtk.vtkRenderWindow() iren = vtkTkRenderWindowInteractor(frame_main, rw=ren_win, width=600, height=600) self.vtk = vtkgui.VtkGui(iren) iren.pack(side='left', fill='both', expand=1) frame_control = tk.Frame(frame_main) frame_control.pack(side='left') frame_dim = tk.Frame(frame_control) frame_dim.pack(fill='x', expand=0) self.var_dim = tk.IntVar() self.var_dim.set(3) tk.Radiobutton(frame_dim, text='2D', variable=self.var_dim, value=2, command=self.dim_modified).pack(side='left', fill='x', expand=1) tk.Radiobutton(frame_dim, text='3D', variable=self.var_dim, value=3, command=self.dim_modified).pack(side='right', fill='x', expand=1) self.button_render = tk.Button(frame_control, text='Render', command=self.render, state='disabled') self.button_render.pack(fill='x', expand=0) self.button_clear = tk.Button(frame_control, text='Clear', command=self.clear) self.button_clear.pack(fill='x', expand=0) self.var_scalarbar = tk.IntVar() self.check_scalarbar = tk.Checkbutton(frame_control, text='Scalar Bar', variable=self.var_scalarbar, command=self.scalarbar_modified) self.check_scalarbar.pack(fill='x') self.var_contour = tk.IntVar() self.check_contour = tk.Checkbutton(frame_control, text='Contour', variable=self.var_contour, command=self.contour_modified) self.check_contour.pack(fill='x') tk.Label(frame_control, text='Variables:').pack() self.list_var = tk.Listbox(frame_control, selectmode='browse') self.list_var.bind('<<ListboxSelect>>', self.var_modified) self.list_var.pack(fill='x') tk.Label(frame_control, text='Probing line:').pack() self.frame_probe = tk.Frame(frame_control) self.frame_probe.pack(fill='x',expand=1) command_val_float = (self.parent.register(validate_float), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W') self.var_coord = tk.StringVar() # self.var_coord.set('x') coord_tab = [ 'x', 'y', 'z' ] counter=0 self.entry_coord = {} self.radio_coord = {} self.label_coord = {} for c in coord_tab: self.radio_coord[c] = tk.Radiobutton(self.frame_probe, text=c, variable=self.var_coord, value=c, command=self.coord_modified) self.radio_coord[c].grid(row=counter, column=0) self.entry_coord[c] = tk.Entry(self.frame_probe, validate='key', validatecommand=command_val_float) self.entry_coord[c].grid(row=counter, column=1) self.label_coord[c] = tk.StringVar() tk.Label(self.frame_probe, textvariable=self.label_coord[c]).grid(row=counter, column=2) counter += 1 self.var_timeplot = tk.IntVar() self.check_timeplot = tk.Checkbutton(self.frame_probe, text='time plot', variable=self.var_timeplot, command=self.timeplot_modified, state='disabled') self.check_timeplot.grid(row=3, column=0, columnspan=2) # bottom section self.frame_control = tk.Frame(self.frame_main, bd=1, relief='sunken') self.frame_control.pack(fill='x', expand=0) tk.Button(self.frame_control, text='Quit', command=self.parent.quit, padx=5, pady=5).pack(side='right') tk.Button(self.frame_control, text='Save', command=self.write, padx=5, pady=5).pack(side='right') tk.Button(self.frame_control, text='Print', command=self.screenshot, padx=5, pady=5).pack(side='right') frame_time = tk.Frame(self.frame_control) frame_time.pack(side='left') button_cfg = { 'side': 'left' } self.button_first = tk.Button(frame_time, text='|<', command=lambda: self.set_timestep(0), width=3) self.button_first.pack(**button_cfg) self.button_prev = tk.Button(frame_time, text='<', command=lambda: self.set_timestep(self.var_curtimestep.get()-1), width=3) self.button_prev.pack(**button_cfg) self.button_play = tk.Button(frame_time, text='|>', command=self.play, width=3) self.button_play.pack(**button_cfg) self.button_next = tk.Button(frame_time, text='>', command=lambda: self.set_timestep(self.var_curtimestep.get()+1), width=3) self.button_next.pack(**button_cfg) self.button_last = tk.Button(frame_time, text='>|', command=lambda: self.set_timestep(self.vtk.data.num_times-1), width=3) self.button_last.pack(**button_cfg) tk.Label(frame_time, text='time:').pack(side='left', padx=10) self.var_curtime = tk.DoubleVar() self.var_curtime.set(0.0) tk.Label(frame_time, textvariable=self.var_curtime, relief='sunken', width=10).pack(side='left') tk.Label(frame_time, text='timestep:').pack(side='left', padx=10) self.var_curtimestep = tk.IntVar() self.var_curtimestep.set('0') command_val_int = (self.parent.register(validate_int), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W') self.entry_timestep = tk.Entry(frame_time, text=self.var_curtimestep, validate='key', validatecommand=command_val_int, relief='sunken', width=10, justify='right') self.entry_timestep.pack(side='left') self.string_timestep = tk.StringVar() self.label_timestep = tk.Label(frame_time, textvariable=self.string_timestep) self.label_timestep.pack(side='left') self.button_go = tk.Button(frame_time, text='go', command=self.timestep_modified) self.button_go.pack(side='left') self.clear() self.init_kshortcuts()
tk.Grid.columnconfigure(frame_sbu,0,weight=1) tk.Grid.columnconfigure(frame_sbu,1,weight=1) tk.Grid.rowconfigure(frame_sbu,0,weight=1) tk.Grid.columnconfigure(frame_disp,0,weight=1) tk.Grid.rowconfigure(frame_disp,0,weight=1) tk.Grid.columnconfigure(frame_link,0,weight=1) tk.Grid.rowconfigure(frame_link,0,weight=1) tk.Grid.columnconfigure(frame_cent,0,weight=1) tk.Grid.rowconfigure(frame_cent,0,weight=1) tk.Grid.columnconfigure(root,0,weight=1) #creation of renderers for 3D visualization ren_disp = vtkRenderer() #for the created mofs renWin_disp = vtkRenderWindow() renWin_disp.AddRenderer(ren_disp) disp_widget = vtkTkRenderWindowInteractor(frame_disp,rw=renWin_disp) disp_widget.grid(row=0,column=0, sticky='n'+'s'+'e'+'w') disp_widget.Initialize() disp_widget.AddObserver("StartPickEvent", functionalize) disp_widget.Start() ren_cent = vtkRenderer() #for the selected center renWin_cent = vtkRenderWindow() renWin_cent.AddRenderer(ren_cent) center_widget = vtkTkRenderWindowInteractor(frame_cent,rw=renWin_cent) center_widget.grid(row=0,column=0, sticky='n'+'s'+'e'+'w') center_widget.Initialize() center_widget.Start() ren_link = vtkRenderer() #for the selected linker renWin_link = vtkRenderWindow()
mapper = vtk.vtkPolyDataMapper() actor = vtk.vtkActor() mapper.SetInputConnection(cube.GetOutputPort()) actor.SetMapper(mapper) # render = vtk.vtkRenderer() #render.SetBackground(val,val,val) render.AddActor(actor) renWindow = vtk.vtkRenderWindow() renWindow.AddRenderer(render) renWinInteract = vtkTkRenderWindowInteractor(root,rw=renWindow, width=400, height=400) renWinInteract.Initialize() renWinInteract.pack(side='top', fill='both', expand=1) def change_background(num): val = float("{0:.2f}".format(slider.get()/255)) label.config(text=str(val)) #render.SetBackground(val,val,val) actor.GetProperty().SetColor(val,0,val) renWindow.Render() #Slider to change the background colour of the renderer slider = Scale(root,from_=0, to_=255, orient = HORIZONTAL,command=change_background,label="BG_COL") #slider = Scale(root,from_=0, to_=255, orient = HORIZONTAL) slider.set(0)
def Cut(v): Q = (P[0], P[1], v) cp = CuttingPlane(*Q) pn = PlaneNormal(*Q) clipper.SetClipFunction(cp) clipper.SetValue(0) cutEdges.SetCutFunction(cp) cutEdges.SetValue(0, 0) cutStrips.Update() cutPoly.SetPoints(cutStrips.GetOutput().GetPoints()) cutPoly.SetPolys(cutStrips.GetOutput().GetLines()) cutMapper.Update() renWin.Render() root = tkinter.Tk() vtkw = vtkTkRenderWindowInteractor(root, rw=renWin, width=800) def set_cut(sz): sz = float(sz) # print(ren.GetActiveCamera()) Cut(sz) # propagate this GUI setting to the corresponding VTK object. size_slider = tkinter.Scale(root, from_=0.0, to=2.0, res=0.01, orient='horizontal', label="Clipping Center", command=set_cut) size_slider.set(P[2]) vtkw.Initialize() size_slider.pack(side="top", fill="both")
def Main(): global datamin, datamax, lut, renWin # Load bathymetry dataset bathymetryReader = vtk.vtkStructuredPointsReader() bathymetryReader.SetFileName(sys.argv[1]) bathymetryReader.Update() r = bathymetryReader.GetOutput().GetPointData().GetScalars().GetRange() datamin = r[0] datamax = r[1] loadContinuousFile(sys.argv[2]) loadDiscreteFile(sys.argv[3]) # Setup color mapping lut = vtk.vtkColorTransferFunction() lut.SetColorSpaceToHSV() # Load bathymetry data into Geometry Filter geometry = vtk.vtkImageDataGeometryFilter() geometry.SetInputConnection(bathymetryReader.GetOutputPort()) mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(geometry.GetOutputPort()) mapper.SetLookupTable(lut) mapper.ImmediateModeRenderingOff() # Setup color mapping bar colorBar = vtkScalarBarActor() colorBar.SetLookupTable(mapper.GetLookupTable()) colorBar.SetTitle("color map") colorBar.SetNumberOfLabels(6) colorBar.SetLabelFormat("%4.0f") colorBar.SetPosition(0.9, 0.1) colorBar.SetWidth(0.07) colorBar.SetHeight(0.8) actor = vtk.vtkActor() actor.SetMapper(mapper) # Create renderer stuff ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renWin.SetSize(1280, 800) # Add the actors to the renderer, set the background and size ren.AddActor(actor) ren.AddActor(colorBar) ren.ResetCamera() ren.SetBackground(0, 0, 0) ren.ResetCameraClippingRange() root = Tkinter.Tk() root.title('Task 2. MRI Data') frame = Tkinter.Frame(root) frame.pack(fill=Tkinter.BOTH, expand="false", side=Tkinter.TOP) mode = Tkinter.IntVar() mode.set(1) Tkinter.Radiobutton(frame, text="Continuous color map", padx=20, variable=mode, value=1, command=showContinuous).pack(anchor=Tkinter.W) Tkinter.Radiobutton(frame, text="Discrete color map", padx=20, variable=mode, value=2, command=showDiscrete).pack(anchor=Tkinter.W) # Setup for rendering window interactor renWinInteract = vtkTkRenderWindowInteractor(frame, rw=renWin, width=1280, height=800) # Specify interaction with 2D image style = vtk.vtkInteractorStyleImage() style.SetInteractionModeToImage2D() renWinInteract.SetInteractorStyle(style) renWinInteract.Initialize() renWinInteract.pack(side='top', fill='both', expand="false") renWinInteract.Start() updateUI(0) renWin.Render() root.mainloop()