#!/usr/bin/env python import sys from PyOSG import Producer from PyOSG import osg from PyOSG import osgDB from PyOSG import osgGA from PyOSG import osgUtil from PyOSG import osgProducer from PyOSG.osgSim import * from OpenGL.GL import * class MyScalarPrinter( ScalarBar.ScalarPrinter): def __init__(self): ScalarBar.ScalarPrinter.__init__(self) self._self = self def printScalar(self, scalar): print "In MyScalarPrinter.printScalar", scalar if scalar==0.0: return ScalarBar.ScalarPrinter.printScalar(self, scalar)+" Bottom" elif scalar==0.5: return ScalarBar.ScalarPrinter.printScalar(self, scalar)+" Middle" elif scalar==1.0: return ScalarBar.ScalarPrinter.printScalar(self, scalar)+" Top" else: return ScalarBar.ScalarPrinter.printScalar(self, scalar) def createScalarBar(): if True: #ScalarsToColors* stc = new ScalarsToColors(0.0,1.0) #ScalarBar* sb = new ScalarBar(2,3,stc,"STC_ScalarBar") # Create a custom color set cs = [] cs.append(osg.Vec4(1.0,0.0,0.0,1.0)) # R cs.append(osg.Vec4(0.0,1.0,0.0,1.0)) # G cs.append(osg.Vec4(1.0,1.0,0.0,1.0)) # G cs.append(osg.Vec4(0.0,0.0,1.0,1.0)) # B cs.append(osg.Vec4(0.0,1.0,1.0,1.0)) # R cr = ColorRange(0.0,1.0,cs) sb = ScalarBar(20, 11, cr, "ScalarBar", ScalarBar.VERTICAL, 0.1, MyScalarPrinter()) # sb.setScalarPrinter(MyScalarPrinter()) return sb else: sb = ScalarBar() tp = ScalarBar.TextProperties() tp._fontFile = "fonts/times.ttf" sb.setTextProperties(tp) return sb def createScalarBar_HUD(): geode = ScalarBar() tp = ScalarBar.TextProperties() tp._fontFile = "fonts/times.ttf" geode.setTextProperties(tp) stateset = geode.getOrCreateStateSet() stateset.setMode(GL_LIGHTING, osg.StateAttribute.OFF) stateset.setMode(GL_DEPTH_TEST,osg.StateAttribute.OFF) stateset.setRenderBinDetails(11, "RenderBin") modelview = osg.MatrixTransform() modelview.setReferenceFrame(osg.Transform.ABSOLUTE_RF) matrix = osg.Matrix.scale(1000,1000,1000) * osg.Matrix.translate(120,10,0) # I've played with these values a lot and it seems to work, but I have no idea why modelview.setMatrix(matrix) modelview.addChild(geode) projection = osg.Projection() projection.setMatrix(osg.Matrix.ortho2D(0,1280,0,1024)) # or whatever the OSG window res is projection.addChild(modelview) return projection #make sure you delete the return sb line def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage().setDescription(arguments.getApplicationName()+" is the example which demonstrates both text, animation and billboard via custom transform to create the OpenSceneGraph logo..") arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...") arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information") arguments.getApplicationUsage().addCommandLineOption("ps","Render the Professional Services logo") # construct the viewer. viewer = osgProducer.Viewer(arguments) # set up the value with sensible default event handlers. viewer.setUpViewer(osgProducer.Viewer.STANDARD_SETTINGS) # get details on keyboard and mouse bindings used by the viewer. viewer.getUsage(arguments.getApplicationUsage()) # if user request help write it out to cout. if arguments.read("-h") or arguments.read("--help"): arguments.getApplicationUsage().write(sys.stdout) return 1 # any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized() # report any errors if they have occured when parsing the program aguments. if arguments.errors(): arguments.writeErrorMessages(sys.stdout) return 1 group = osg.Group() group.addChild(createScalarBar()) group.addChild(createScalarBar_HUD()) # add model to viewer. viewer.setSceneData( group ) # create the windows and run the threads. viewer.realize() while not viewer.done(): # wait for all cull and draw threads to complete. viewer.sync() # update the scene by traversing it with the the update visitor which will # call all node update callbacks and animations. viewer.update() # fire off the cull and draw traversals of the scene. viewer.frame() # wait for all cull and draw threads to complete before exit. viewer.sync() return 0 if __name__ == "__main__": sys.exit(main(sys.argv))