def __init__(self, parent, size = None, attribs = None, id = wx.ID_ANY): Canvas3D.__init__(self, parent, size, attribs, id) self.window = parent self.prevKey = None # Streams, to be supplied self.left = None self.right = None self.pipeline= None # Single, side by side or overlay view self.mono = True # Automatic if only one stream, no preference self.overlay = eval(app.config.Read("overlay", "0")) self.bkColor = (0.0, 0.0, 0.0) # Background color # Internal layout self.BORDER = 0.1
# # Tkinter3D is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Tkinter3D. If not, see <http://www.gnu.org/licenses/>. # from tkinter import Tk from canvas3d import Canvas3D, Frame3D, roty from scene import Thing3D as dot root = Tk() root.title("Rotating Cube Demo") c = Canvas3D(root) c.pack(expand=1, fill='both') # Zoom out a little. c.frame.T.z += -300.0 # Create a dot at world origin (0, 0, 0). origin = dot(c, width=4) c.frame.things.append(origin) # Make a frame for some objects to be in. cube_frame = Frame3D() c.frame.subframes.append(cube_frame) # Add a Z component to the cube frame's translation to offset the cube # from the world frame.
def initGL(self): Canvas3D.initGL(self) glClearColor(self.bkColor[0], self.bkColor[1], self.bkColor[2], 0) glDisable(GL_DEPTH_TEST) glEnableClientState(GL_VERTEX_ARRAY) self.initShaders()
def __init__(self): self.saved_views = {} self.gtk = gtk.Window(gtk.WINDOW_TOPLEVEL) self.gtk.set_title('Demo of a Mockup of OOF3D Interface') self.gtk.set_default_size(initial_width, initial_height) self.gtk.connect("destroy", self.destroy) self.gtk.connect("delete_event", self.destroy) self.cubeActor = None # set up areas self.panes = gtk.HPaned() self.gtk.add(self.panes) self.canvas = Canvas3D(self) self.panes.add2(self.canvas) self.toolboxframe = gtk.Frame() self.toolboxframe.set_shadow_type(gtk.SHADOW_IN) self.panes.add1(self.toolboxframe) self.scroll = gtk.ScrolledWindow() self.scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.toolboxframe.add(self.scroll) self.mainbox = gtk.VBox() self.scroll.add_with_viewport(self.mainbox) # viewer widgets viewerframe = gtk.Frame("Viewer Widgets") viewerframe.set_shadow_type(gtk.SHADOW_IN) self.mainbox.pack_start(viewerframe) viewerbox = gtk.VBox() viewerframe.add(viewerbox) self.tooltips = gtk.Tooltips() # camera position infoframe = gtk.Frame("Camera Info") infoframe.set_shadow_type(gtk.SHADOW_IN) viewerbox.pack_start(infoframe, fill=0, expand=0) infobox = gtk.VBox() infoframe.add(infobox) positionlabel = gtk.Label("Camera Position:") #self.tooltips.set_tip(positionlabel, "The position of the camera in world coordinates (pixel units)") infobox.pack_start(positionlabel,fill=0, expand=0) positiontable = gtk.Table(columns=3, rows=1) infobox.pack_start(positiontable,fill=0, expand=0) self.camera_x = gtk.Entry() self.camera_x.set_size_request(90,-1) self.camera_x.set_editable(0) positiontable.attach(self.camera_x,0,1,0,1) self.camera_y = gtk.Entry() self.camera_y.set_size_request(90,-1) self.camera_y.set_editable(0) positiontable.attach(self.camera_y,1,2,0,1) self.camera_z = gtk.Entry() self.camera_z.set_size_request(90,-1) self.camera_z.set_editable(0) positiontable.attach(self.camera_z,2,3,0,1) focalpointlabel = gtk.Label("Focal Point:") #self.tooltips.set_tip(focalpointlabel, "The position of the focal point in world coordinates (pixel units)") infobox.pack_start(focalpointlabel,fill=0, expand=0) focalpointtable = gtk.Table(columns=3, rows=1) infobox.pack_start(focalpointtable,fill=0, expand=0) self.fp_x = gtk.Entry() self.fp_x.set_size_request(90,-1) self.fp_x.set_editable(0) focalpointtable.attach(self.fp_x,0,1,0,1) self.fp_y = gtk.Entry() self.fp_y.set_size_request(90,-1) self.fp_y.set_editable(0) focalpointtable.attach(self.fp_y,1,2,0,1) self.fp_z = gtk.Entry() self.fp_z.set_size_request(90,-1) self.fp_z.set_editable(0) focalpointtable.attach(self.fp_z,2,3,0,1) viewuplabel = gtk.Label("View Up Vector:") #self.tooltips.set_tip(viewuplabel, "The vector that points up in the viewport") infobox.pack_start(viewuplabel,fill=0, expand=0) viewuptable = gtk.Table(columns=3, rows=1) infobox.pack_start(viewuptable,fill=0, expand=0) self.viewup_x = gtk.Entry() self.viewup_x.set_size_request(90,-1) self.viewup_x.set_editable(0) viewuptable.attach(self.viewup_x,0,1,0,1) self.viewup_y = gtk.Entry() self.viewup_y.set_size_request(90,-1) self.viewup_y.set_editable(0) viewuptable.attach(self.viewup_y,1,2,0,1) self.viewup_z = gtk.Entry() self.viewup_z.set_size_request(90,-1) self.viewup_z.set_editable(0) viewuptable.attach(self.viewup_z,2,3,0,1) distancetable = gtk.Table(columns=2, rows=1) infobox.pack_start(distancetable,fill=0, expand=0) distancelabel = gtk.Label("Distance:") #self.tooltips.set_tip(distancelabel, "The distance from the camera to the focal point") distancetable.attach(distancelabel,0,1,0,1) self.distance = gtk.Entry() self.distance.set_size_request(90,-1) self.distance.set_editable(0) distancetable.attach(self.distance,1,2,0,1) angletable = gtk.Table(columns=2, rows=1) infobox.pack_start(angletable,fill=0, expand=0) anglelabel = gtk.Label("View Angle:") #self.tooltips.set_tip(anglelabel, "The angle between the vectors from the camera to the focal point and from the camera to the top of the microstructure") angletable.attach(anglelabel,0,1,0,1) self.viewangle = gtk.Entry() self.viewangle.set_size_request(90,-1) self.viewangle.set_editable(0) angletable.attach(self.viewangle,1,2,0,1) printinfo = gtk.Button("Print Camera Info") gtklogger.connect(printinfo, 'clicked', self.printcam) self.tooltips.set_tip(printinfo, "Print the camera information in the console") infobox.pack_start(printinfo,fill=0, expand=0) # zoom - as in changing the viewing angle zoomframe = gtk.Frame("Zoom") zoomframe.set_shadow_type(gtk.SHADOW_IN) viewerbox.pack_start(zoomframe, fill=0, expand=0) zoombox = gtk.VBox() zoomframe.add(zoombox) buttonrow = gtk.HBox(homogeneous=1, spacing=2) zoombox.pack_start(buttonrow, expand=0, fill=1, padding=2) zinbutton = gtk.Button('Zoom In') self.tooltips.set_tip(zinbutton,"Decrease view angle to by given factor") buttonrow.pack_start(zinbutton, expand=0, fill=1) gtklogger.connect(zinbutton, 'clicked', self.zoomin) zoutbutton = gtk.Button('Zoom Out') self.tooltips.set_tip(zoutbutton, "Increase view angle by given factor") buttonrow.pack_start(zoutbutton, expand=0, fill=1) gtklogger.connect(zoutbutton, 'clicked', self.zoomout) zfillbutton = gtk.Button('Fill') self.tooltips.set_tip(zfillbutton, "Set view angle such that microstructure approximately fills viewport") buttonrow.pack_start(zfillbutton, expand=0, fill=1) gtklogger.connect(zfillbutton, 'clicked', self.zoomfill) factorrow = gtk.HBox() zoombox.pack_start(factorrow, expand=0, fill=0, padding=2) factorrow.pack_start(gtk.Label("Factor: "), expand=0, fill=0) self.zoomfactor = gtk.Entry() self.zoomfactor.set_editable(1) self.zoomfactor.set_size_request(80, -1) self.zoomfactor.set_text("1.5") self.tooltips.set_tip(self.zoomfactor, "Factor by which to shrink or magnify image") factorrow.pack_start(self.zoomfactor, expand=1, fill=1) # Translation # dolly transframe = gtk.Frame("Translation") transframe.set_shadow_type(gtk.SHADOW_IN) viewerbox.pack_start(transframe, fill=0, expand=0) transbox = gtk.VBox() transframe.add(transbox) dollyrow = gtk.HBox(homogeneous=1, spacing=2) transbox.pack_start(dollyrow, expand=0, fill=1, padding=2) inbutton = gtk.Button('Dolly In') self.tooltips.set_tip(inbutton,"Translate camera towards focal point by given factor") dollyrow.pack_start(inbutton, expand=0, fill=1) gtklogger.connect(inbutton, 'clicked', self.dollyin) outbutton = gtk.Button('Dolly Out') self.tooltips.set_tip(outbutton, "Translate camera away from focal point by given factor") dollyrow.pack_start(outbutton, expand=0, fill=1) gtklogger.connect(outbutton, 'clicked', self.dollyout) fillbutton = gtk.Button('Fill') self.tooltips.set_tip(fillbutton, "Set camera position such that microstructure approximately fills viewport") dollyrow.pack_start(fillbutton, expand=0, fill=1) gtklogger.connect(fillbutton, 'clicked', self.dollyfill) factorrow = gtk.HBox() transbox.pack_start(factorrow, expand=0, fill=0, padding=2) factorrow.pack_start(gtk.Label("Factor: "), expand=0, fill=0) self.dollyfactor = gtk.Entry() self.dollyfactor.set_editable(1) self.dollyfactor.set_size_request(80, -1) self.dollyfactor.set_text("1.5") self.tooltips.set_tip(self.dollyfactor, "Factor by which to multiply distance from camera to focal point") factorrow.pack_start(self.dollyfactor, expand=1, fill=1) # track trackrow = gtk.HBox(homogeneous=1, spacing=2) transbox.pack_start(trackrow, expand=0, fill=1, padding=2) horizbutton = gtk.Button('Horizontal') self.tooltips.set_tip(horizbutton,"Shift camera and focal point horizontally") trackrow.pack_start(horizbutton, expand=0, fill=1) gtklogger.connect(horizbutton, 'clicked', self.trackh) vertbutton = gtk.Button('Vertical') self.tooltips.set_tip(vertbutton, "Shift camera and focal point vertically") trackrow.pack_start(vertbutton, expand=0, fill=1) gtklogger.connect(vertbutton, 'clicked', self.trackv) recenterbutton = gtk.Button('Recenter') self.tooltips.set_tip(recenterbutton, "Recenter the microstructure in the viewport") trackrow.pack_start(recenterbutton, expand=0, fill=1) gtklogger.connect(recenterbutton, 'clicked', self.recenter) distrow = gtk.HBox() transbox.pack_start(distrow, expand=0, fill=0, padding=2) distrow.pack_start(gtk.Label("Distance: "), expand=0, fill=0) self.trackdist = gtk.Entry() self.trackdist.set_editable(1) self.trackdist.set_size_request(80, -1) self.trackdist.set_text("10.0") self.tooltips.set_tip(self.trackdist, "Distance by which to track camera in units of pixels") distrow.pack_start(self.trackdist, expand=1, fill=1) label = gtk.Label("Dolly: Right Mouse Button\nTrack: Middle Mouse Button") transbox.pack_start(label) #rotate rotateframe = gtk.Frame("Rotation") rotateframe.set_shadow_type(gtk.SHADOW_IN) viewerbox.pack_start(rotateframe, fill=0, expand=0) rotatebox = gtk.VBox() rotateframe.add(rotatebox) rotobjrow = gtk.HBox(homogeneous=1, spacing=2) rotatebox.pack_start(rotobjrow, expand=0, fill=1, padding=2) rollbutton = gtk.Button('Roll') self.tooltips.set_tip(rollbutton,"Rotate about direction of projection") rotobjrow.pack_start(rollbutton, expand=0, fill=1) gtklogger.connect(rollbutton, 'clicked', self.roll) azbutton = gtk.Button('Azimuth') self.tooltips.set_tip(azbutton, "Rotate about view up vector centered at focal point") rotobjrow.pack_start(azbutton, expand=0, fill=1) gtklogger.connect(azbutton, 'clicked', self.azimuth) elbutton = gtk.Button('Elevation') self.tooltips.set_tip(elbutton, "Rotate about cross product of direction of projection and view up vector centered at focal point") rotobjrow.pack_start(elbutton, expand=0, fill=1) gtklogger.connect(elbutton, 'clicked', self.elevation) rotcamrow = gtk.HBox(homogeneous=1, spacing=2) rotatebox.pack_start(rotcamrow, expand=0, fill=1, padding=2) yawbutton = gtk.Button('Yaw') self.tooltips.set_tip(yawbutton,"Rotate about view up vector centered at camera position") rotcamrow.pack_start(yawbutton, expand=0, fill=1) gtklogger.connect(yawbutton, 'clicked', self.yaw) pitchbutton = gtk.Button('Pitch') self.tooltips.set_tip(pitchbutton,"Rotate about cross product of direction of projection and view up vector centered at camera position") rotcamrow.pack_start(pitchbutton, expand=0, fill=1) gtklogger.connect(pitchbutton, 'clicked', self.pitch) anglerow = gtk.HBox() rotatebox.pack_start(anglerow, expand=0, fill=0, padding=2) anglerow.pack_start(gtk.Label("Angle: "), expand=0, fill=0) self.angle = gtk.Entry() self.angle.set_editable(1) self.angle.set_size_request(80, -1) self.angle.set_text("10.0") self.tooltips.set_tip(self.angle,"Angle in degrees by which to rotate by") anglerow.pack_start(self.angle, expand=1, fill=1) #clipping planes clippingframe = gtk.Frame("Clipping Range") clippingframe.set_shadow_type(gtk.SHADOW_IN) viewerbox.pack_start(clippingframe, fill=0, expand=0) clippingbox = gtk.VBox() clippingframe.add(clippingbox) self.clippingadj = gtk.Adjustment(value=100, lower=0, upper=100, step_incr=-1, page_incr=-5, page_size=0) gtklogger.connect(self.clippingadj, 'value_changed', self.setclipping) clippingscale = gtk.HScale(self.clippingadj) clippingscale.set_update_policy(gtk.UPDATE_DELAYED) self.tooltips.set_tip(clippingscale,"Adjust the near clipping plane to view cross section") clippingbox.pack_start(clippingscale) #opacity opacityframe = gtk.Frame("Opacity") opacityframe.set_shadow_type(gtk.SHADOW_IN) viewerbox.pack_start(opacityframe, fill=0, expand=0) opacitybox = gtk.VBox() opacityframe.add(opacitybox) self.opacityadj = gtk.Adjustment(value=100, lower=0, upper=100, step_incr=-1, page_incr=-5, page_size=0) gtklogger.connect(self.opacityadj, 'value_changed', self.setopacity) opacityscale = gtk.HScale(self.opacityadj) opacityscale.set_update_policy(gtk.UPDATE_DELAYED) self.tooltips.set_tip(opacityscale,"Adjust the opacity of the microstructure") opacitybox.pack_start(opacityscale) # save and restore saverestoreframe = gtk.Frame("Save and Restore Views") saverestoreframe.set_shadow_type(gtk.SHADOW_IN) viewerbox.pack_start(saverestoreframe, fill=0, expand=0) saverestorebox = gtk.VBox() saverestoreframe.add(saverestorebox) viewtable = gtk.Table(columns=2, rows=2) saverestorebox.pack_start(viewtable, fill=0, expand=0) saveviewbutton = gtk.Button("Save View:") self.tooltips.set_tip(saveviewbutton,"Save the current view settings") gtklogger.connect(saveviewbutton, 'clicked', self.saveview) viewtable.attach(saveviewbutton, 0,1,0,1) self.viewname = gtk.Entry() self.viewname.set_editable(1) self.viewname.set_size_request(80,-1) self.tooltips.set_tip(self.viewname,"Enter a name for the current view") viewtable.attach(self.viewname,1,2,0,1) setviewlabel = gtk.Label("Set View:") viewtable.attach(setviewlabel, 0,1,1,2) liststore = gtk.ListStore(gobject.TYPE_STRING) self.viewmenu = gtk.ComboBox(liststore) cell = gtk.CellRendererText() self.viewmenu.pack_start(cell, True) self.viewmenu.add_attribute(cell, 'text', 0) #self.tooltips.set_tip(self.viewmenu,"Restore a saved view") # menu items filled in later when saved_views is initialized self.signal = gtklogger.connect(self.viewmenu, 'changed', self.setview) viewtable.attach(self.viewmenu, 1,2,1,2) # end viewer widgets # voxel info widgets voxelinfoframe = gtk.Frame("Voxel Info Widgets") voxelinfoframe.set_shadow_type(gtk.SHADOW_IN) self.mainbox.pack_start(voxelinfoframe) voxelinfobox = gtk.VBox() voxelinfoframe.add(voxelinfobox) voxelinfotable = gtk.Table(rows=7,columns=2) voxelinfobox.pack_start(voxelinfotable) label = gtk.Label('x=') label.set_alignment(1.0, 0.5) voxelinfotable.attach(label, 0,1, 0,1, xpadding=5, xoptions=gtk.FILL) self.xtext = gtk.Entry() self.xtext.set_size_request(80, -1) voxelinfotable.attach(self.xtext, 1,2, 0,1, xpadding=5, xoptions=gtk.EXPAND|gtk.FILL) label = gtk.Label('y=') label.set_alignment(1.0, 0.5) voxelinfotable.attach(label, 0,1, 1,2, xpadding=5, xoptions=gtk.FILL) self.ytext = gtk.Entry() self.ytext.set_size_request(80, -1) voxelinfotable.attach(self.ytext, 1,2, 1,2, xpadding=5, xoptions=gtk.EXPAND|gtk.FILL) label = gtk.Label('z=') label.set_alignment(1.0, 0.5) voxelinfotable.attach(label, 0,1, 2,3, xpadding=5, xoptions=gtk.FILL) self.ztext = gtk.Entry() self.ztext.set_size_request(80, -1) voxelinfotable.attach(self.ztext, 1,2, 2,3, xpadding=5, xoptions=gtk.EXPAND|gtk.FILL) self.xtsignal = gtklogger.connect(self.xtext, 'changed', self.voxinfoChanged) self.ytsignal = gtklogger.connect(self.ytext, 'changed', self.voxinfoChanged) self.ztsignal = gtklogger.connect(self.ztext, 'changed', self.voxinfoChanged) box = gtk.HBox(homogeneous=True, spacing=2) self.updatebutton = gtk.Button(gtk.STOCK_REFRESH) #gtkutils.stockButton(gtk.STOCK_REFRESH, 'Update') box.pack_start(self.updatebutton, expand=1, fill=1) gtklogger.connect(self.updatebutton, 'clicked', self.updateVoxButtonCB) self.clearbutton = gtk.Button(gtk.STOCK_CLEAR) #gtkutils.stockButton(gtk.STOCK_CLEAR, 'Clear') box.pack_start(self.clearbutton, expand=1, fill=1) gtklogger.setWidgetName(self.clearbutton, "Clear") gtklogger.connect(self.clearbutton, 'clicked', self.clearVoxButtonCB) voxelinfotable.attach(box, 0,2,3,4, xpadding=5, xoptions=gtk.EXPAND|gtk.FILL, yoptions=0) label = gtk.Label('red=') label.set_alignment(1.0, 0.5) voxelinfotable.attach(label, 0,1, 4,5, xpadding=5, xoptions=gtk.FILL) self.redtext = gtk.Entry() self.redtext.set_size_request(80, -1) voxelinfotable.attach(self.redtext, 1,2, 4,5, xpadding=5, xoptions=gtk.EXPAND|gtk.FILL) label = gtk.Label('green=') label.set_alignment(1.0, 0.5) voxelinfotable.attach(label, 0,1, 5,6, xpadding=5, xoptions=gtk.FILL) self.greentext = gtk.Entry() self.greentext.set_size_request(80, -1) voxelinfotable.attach(self.greentext, 1,2, 5,6, xpadding=5, xoptions=gtk.EXPAND|gtk.FILL) label = gtk.Label('blue=') label.set_alignment(1.0, 0.5) voxelinfotable.attach(label, 0,1, 6,7, xpadding=5, xoptions=gtk.FILL) self.bluetext = gtk.Entry() self.bluetext.set_size_request(80, -1) voxelinfotable.attach(self.bluetext, 1,2, 6,7, xpadding=5, xoptions=gtk.EXPAND|gtk.FILL) currentVoxel = None # voxel select widgets ## voxelselectframe = gtk.Frame("Voxel Select Widgets") ## voxelselectframe.set_shadow_type(gtk.SHADOW_IN) ## self.mainbox.pack_start(voxelselectframe) ## voxelselectbox = gtk.VBox() ## voxelselectframe.add(voxelselectbox) ## button = gtk.Button("Hello World") ## voxelselectbox.pack_start(button) self.saveimage = gtk.Button("save image") gtklogger.connect(self.saveimage, 'clicked', self.saveimageCB) self.mainbox.pack_start(self.saveimage)