def readMasterFile(files): fin = osgDB.ifstream(_filename.c_str()) if fin : fr = osgDB.Input() fr.attach(fin) readFilename = False while not fr.eof() : itrAdvanced = False if fr.matchSequence("file %s") or fr.matchSequence("file %w") : files.insert(fr[1].getStr()) fr += 2 itrAdvanced = True readFilename = True if not itrAdvanced : ++fr return readFilename return False
system = return(cxapp) osg.notify(osg.INFO), "app not found not " return 1 # end printList() void readConfFile( char* confFile) # read confFile 1 osg.notify(osg.INFO), "Start reading confFile" fileName = osgDB.findDataFile(confFile) if fileName.empty() : osg.notify(osg.INFO), "Config file not found", confFile return in = osgDB.ifstream(fileName.c_str()) if not in : osg.notify(osg.INFO), "File ", fileName, " can not be opened not " exit(1) imageBuffer = str() appBuffer = str() while not in.eof() : std.getline(in, imageBuffer) std.getline(in, appBuffer) if imageBuffer == "" or appBuffer == "" : else: osg.notify(osg.INFO), "imageBuffer: ", imageBuffer osg.notify(osg.INFO), "appBuffer: ", appBuffer # jeweils checken ob image vorhanden ist.
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 use of node tracker.") arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()) arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information") # construct the viewer. viewer = osgViewer.Viewer(arguments) # add the state manipulator viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) ) # add the thread model handler viewer.addEventHandler(osgViewer.ThreadingHandler)() # add the window size toggle handler viewer.addEventHandler(osgViewer.WindowSizeHandler)() # add the stats handler viewer.addEventHandler(osgViewer.StatsHandler)() # add the record camera path handler viewer.addEventHandler(osgViewer.RecordCameraPathHandler)() # add the help handler viewer.addEventHandler(osgViewer.HelpHandler(arguments.getApplicationUsage())) # set the near far ration computation up. viewer.getCamera().setComputeNearFarMode(osg.CullSettings.COMPUTE_NEAR_FAR_USING_PRIMITIVES) viewer.getCamera().setNearFarRatio(0.000003) speed = 1.0 while arguments.read("-f") or arguments.read("--fixed") : speed = 0.0 rotation = osg.Quat() vec4 = osg.Vec4() while arguments.read("--rotate-model",vec4[0],vec4[1],vec4[2],vec4[3]) : local_rotate = osg.Quat() local_rotate.makeRotate(osg.DegreesToRadians(vec4[0]),vec4[1],vec4[2],vec4[3]) rotation = rotation * local_rotate nc = 0 flightpath_filename = str() while arguments.read("--flight-path",flightpath_filename) : fin = osgDB.ifstream(flightpath_filename.c_str()) if fin : path = osg.AnimationPath() path.read(fin) nc = osg.AnimationPathCallback(path) trackerMode = osgGA.NodeTrackerManipulator.NODE_CENTER_AND_ROTATION mode = str() while arguments.read("--tracker-mode",mode) : if mode=="NODE_CENTER_AND_ROTATION" : trackerMode = osgGA.NodeTrackerManipulator.NODE_CENTER_AND_ROTATION elif mode=="NODE_CENTER_AND_AZIM" : trackerMode = osgGA.NodeTrackerManipulator.NODE_CENTER_AND_AZIM elif mode=="NODE_CENTER" : trackerMode = osgGA.NodeTrackerManipulator.NODE_CENTER else: print "Unrecognized --tracker-mode option ", mode, ", valid options are:" print " NODE_CENTER_AND_ROTATION" print " NODE_CENTER_AND_AZIM" print " NODE_CENTER" return 1 rotationMode = osgGA.NodeTrackerManipulator.TRACKBALL while arguments.read("--rotation-mode",mode) : if mode=="TRACKBALL" : rotationMode = osgGA.NodeTrackerManipulator.TRACKBALL elif mode=="ELEVATION_AZIM" : rotationMode = osgGA.NodeTrackerManipulator.ELEVATION_AZIM else: print "Unrecognized --rotation-mode option ", mode, ", valid options are:" print " TRACKBALL" print " ELEVATION_AZIM" return 1 useOverlay = True while arguments.read("--no-overlay") or arguments.read("-n") : useOverlay = False technique = osgSim.OverlayNode.OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY while arguments.read("--object") : technique = osgSim.OverlayNode.OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY while arguments.read("--ortho") or arguments.read("--orthographic") : technique = osgSim.OverlayNode.VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY while arguments.read("--persp") or arguments.read("--perspective") : technique = osgSim.OverlayNode.VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY overlayTextureUnit = 1 while arguments.read("--unit", overlayTextureUnit) : pathfile = str() while arguments.read("-p",pathfile) : addFireEffect = arguments.read("--fire") # if user request help write it out to cout. if arguments.read("-h") or arguments.read("--help") : arguments.getApplicationUsage().write(std.cout) return 1 tm = osgGA.NodeTrackerManipulator() overlayFilename = str() while arguments.read("--overlay", overlayFilename) : # read the scene from the list of file specified commandline args. root = osgDB.readNodeFiles(arguments) if not root : root = createEarth() if not root : return 0 if not overlayFilename.empty() : #osg.Object *pObj = osgDB.readObjectFile("alaska_clean.shp") #osg.Geode shapefile = dynamic_cast<osg.Geode*> (pObj) # #ConvertLatLon2EllipsoidCoordinates latlon2em #shapefile.accept(latlon2em) shapefile = osgDB.readNodeFile(overlayFilename) if not shapefile : osg.notify(osg.NOTICE), "File `", overlayFilename, "` not found" return 1 csn = dynamic_cast<osg.CoordinateSystemNode*>(root) if csn : overlayNode = osgSim.OverlayNode(technique) overlayNode.getOrCreateStateSet().setTextureAttribute(1, osg.TexEnv(osg.TexEnv.DECAL)) overlayNode.setOverlaySubgraph(shapefile) overlayNode.setOverlayTextureSizeHint(1024) overlayNode.setOverlayTextureUnit(overlayTextureUnit) # insert the OverlayNode between the coordinate system node and its children. for(unsigned int i=0 i<csn.getNumChildren() ++i) overlayNode.addChild( csn.getChild(i) ) csn.removeChildren(0, csn.getNumChildren()) csn.addChild(overlayNode) viewer.setSceneData(csn) else: overlayNode = osgSim.OverlayNode(technique) overlayNode.getOrCreateStateSet().setTextureAttribute(1, osg.TexEnv(osg.TexEnv.DECAL)) overlayNode.setOverlaySubgraph(shapefile) overlayNode.setOverlayTextureSizeHint(1024) overlayNode.addChild(root) viewer.setSceneData(overlayNode) else: # add a viewport to the viewer and attach the scene graph. viewer.setSceneData(root) csn = dynamic_cast<osg.CoordinateSystemNode*>(root) if csn : overlayNode = osgSim.OverlayNode() if useOverlay : overlayNode = osgSim.OverlayNode(technique) # insert the OverlayNode between the coordinate system node and its children. for(unsigned int i=0 i<csn.getNumChildren() ++i) overlayNode.addChild( csn.getChild(i) ) csn.removeChildren(0, csn.getNumChildren()) csn.addChild(overlayNode) # tell the overlay node to continously update its overlay texture # as we know we'll be tracking a moving target. overlayNode.setContinuousUpdate(True) cessna = osgDB.readNodeFile("cessna.osgt") if cessna : s = 200000.0 / cessna.getBound().radius() scaler = osg.MatrixTransform() scaler.addChild(cessna) scaler.setMatrix(osg.Matrixd.scale(s,s,s)*osg.Matrixd.rotate(rotation)) scaler.getOrCreateStateSet().setMode(GL_RESCALE_NORMAL,osg.StateAttribute.ON) if addFireEffect : center = cessna.getBound().center() fire = osgParticle.FireEffect(center, 10.0) scaler.addChild(fire) if False : ss = osgSim.SphereSegment( osg.Vec3(0.0,0.0,0.0), # center 19.9, # radius osg.DegreesToRadians(135.0), osg.DegreesToRadians(240.0), osg.DegreesToRadians(-10.0), osg.DegreesToRadians(30.0), 60) scaler.addChild(ss) mt = osg.MatrixTransform() mt.addChild(scaler) if not nc : nc = ModelPositionCallback(speed) mt.setUpdateCallback(nc) csn.addChild(mt) # if we are using an overaly node, use the cessna subgraph as the overlay subgraph if overlayNode.valid() : overlayNode.setOverlaySubgraph(mt) tm = osgGA.NodeTrackerManipulator() tm.setTrackerMode(trackerMode) tm.setRotationMode(rotationMode) tm.setTrackNode(scaler) else: print "Failed to read cessna.osgt" # set up camera manipulators. keyswitchManipulator = osgGA.KeySwitchMatrixManipulator() if tm.valid() : keyswitchManipulator.addMatrixManipulator( ord("0"), "NodeTracker", tm ) keyswitchManipulator.addMatrixManipulator( ord("1"), "Trackball", osgGA.TrackballManipulator() ) keyswitchManipulator.addMatrixManipulator( ord("2"), "Flight", osgGA.FlightManipulator() ) keyswitchManipulator.addMatrixManipulator( ord("3"), "Drive", osgGA.DriveManipulator() ) keyswitchManipulator.addMatrixManipulator( ord("4"), "Terrain", osgGA.TerrainManipulator() ) if not pathfile.empty() : apm = osgGA.AnimationPathManipulator(pathfile) if apm or not apm.valid() : num = keyswitchManipulator.getNumMatrixManipulators() keyswitchManipulator.addMatrixManipulator( ord("5"), "Path", apm ) keyswitchManipulator.selectMatrixManipulator(num) viewer.setCameraManipulator( keyswitchManipulator ) # viewer.setThreadingModel(osgViewer.Viewer.SingleThreaded) return viewer.run() if __name__ == "__main__": main(sys.argv)
if _animationPath.valid() : cp = osg.AnimationPath.ControlPoint() _animationPath.getInterpolatedControlPoint( fs.getSimulationTime(), cp ) OSG_NOTICE, "CameraPathProperty ", fs.getFrameNumber(), " ", fs.getSimulationTime() matrix = osg.Matrixd() cp.getMatrix( matrix ) camera.setViewMatrix( osg.Matrix.inverse(matrix) ) void CameraPathProperty.loadAnimationPath() _animationPath = osg.AnimationPath() #_animationPath.setLoopMode(osg.AnimationPath.LOOP) in = osgDB.ifstream(_filename.c_str()) if not in : OSG_WARN, "CameraPathProperty: Cannot open animation path file \"", _filename, "\".\n" return _animationPath.read(in) bool CameraPathProperty.getTimeRange(double startTime, double endTime) if not _animationPath : return False tcpm = _animationPath.getTimeControlPointMap() if tcpm.empty() : return False startTime = tcpm.begin().first endTime = tcpm.rbegin().first
#include <osg/Notify> #include <osgDB/ReadFile> #include <osgDB/fstream> #include <osg/GraphicsContext> #include <iostream> #include <string.h> FILE_IDENTIFER = str("osgphotoalbum photo archive") PhotoArchive.PhotoArchive( str filename) readPhotoIndex(filename) bool PhotoArchive.readPhotoIndex( str filename) in = osgDB.ifstream(filename.c_str()) fileIndentifier = char [FILE_IDENTIFER.size()] in.read(fileIndentifier,FILE_IDENTIFER.size()) if FILE_IDENTIFER not =fileIndentifier : delete [] fileIndentifier return False delete [] fileIndentifier numPhotos = unsigned int() in.read((char*)numPhotos,sizeof(numPhotos)) _photoIndex.resize(numPhotos) in.read((char*)_photoIndex.front(),sizeof(PhotoHeader)*numPhotos)
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 use node masks to create stereo images.") arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye") arguments.getApplicationUsage().addCommandLineOption("-d <float>","Time delay in seconds between the display of successive image pairs when in auto advance mode.") arguments.getApplicationUsage().addCommandLineOption("-a","Enter auto advance of image pairs on start up.") arguments.getApplicationUsage().addCommandLineOption("-x <float>","Horizontal offset of left and right images.") arguments.getApplicationUsage().addCommandLineOption("-y <float>","Vertical offset of left and right images.") arguments.getApplicationUsage().addCommandLineOption("--disk","Keep images on disk") arguments.getApplicationUsage().addCommandLineOption("-files <filename>","Load filenames from a file") arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information") arguments.getApplicationUsage().addCommandLineOption("--SingleThreaded","Select SingleThreaded threading model for viewer.") arguments.getApplicationUsage().addCommandLineOption("--CullDrawThreadPerContext","Select CullDrawThreadPerContext threading model for viewer.") arguments.getApplicationUsage().addCommandLineOption("--DrawThreadPerContext","Select DrawThreadPerContext threading model for viewer.") arguments.getApplicationUsage().addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext","Select CullThreadPerCameraDrawThreadPerContext threading model for viewer.") # construct the viewer. viewer = osgViewer.Viewer(arguments) # register the handler to add keyboard and mouse handling. seh = SlideEventHandler() viewer.addEventHandler(seh) # read any time delay argument. timeDelayBetweenSlides = 5.0 while arguments.read("-d",timeDelayBetweenSlides) : autoSteppingActive = False while arguments.read("-a") : autoSteppingActive = True offsetX = 0.0 while arguments.read("-x",offsetX) : offsetY = 0.0 while arguments.read("-y",offsetY) : onDisk = False while arguments.read("--disk") : onDisk=True filename = "" fileList = FileList() # extract the filenames from the a file, one filename per line. while arguments.read("-files",filename) : is = osgDB.ifstream(filename.c_str()) if is : line = str() while std.getline(is,line,'\n') : fileList.push_back(line) is.close() # if user request help write it out to cout. if arguments.read("-h") or arguments.read("--help") : arguments.getApplicationUsage().write(std.cout) return 1 threading = osgViewer.Viewer.SingleThreaded while arguments.read("--SingleThreaded") : threading = osgViewer.Viewer.SingleThreaded while arguments.read("--CullDrawThreadPerContext") : threading = osgViewer.Viewer.CullDrawThreadPerContext while arguments.read("--DrawThreadPerContext") : threading = osgViewer.Viewer.DrawThreadPerContext while arguments.read("--CullThreadPerCameraDrawThreadPerContext") : threading = osgViewer.Viewer.CullThreadPerCameraDrawThreadPerContext viewer.setThreadingModel(threading) # any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized() # report any errors if they have occurred when parsing the program arguments. if arguments.errors() : arguments.writeErrorMessages(std.cout) return 1 # extract the filenames from the arguments list. for(int pos=1pos<arguments.argc()++pos) if arguments.isString(pos) : fileList.push_back(arguments[pos]) if fileList.empty() : fileList.push_back("Images/dog_left_eye.jpg") fileList.push_back("Images/dog_right_eye.jpg") elif fileList.size()<2 : arguments.getApplicationUsage().write(std.cout,osg.ApplicationUsage.COMMAND_LINE_OPTION) return 1