#!/usr/bin/env python print 'Not implemented yet' """ /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield * * This application is open source and may be redistributed and/or modified under * the terms of the GNU Public License (GPL) version 1.0 or * (at your option) any later version. * * This library 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 * OpenSceneGraph Public License for more details. */ #include #include #include #include #include #include #include #include #include #include "ImageReaderWriter.h" using namespace osg # now register with Registry to instantiate the above reader/writer, # declaring in main so that the code to set up PagedLOD can get a handle # to the ImageReaderWriter's osgDB.RegisterReaderWriterProxy g_ImageReaderWriter class Album class Page : public osg.Transform { public: static Page* createPage(Album* album, unsigned int pageNo, const std.string& frontFileName, const std.string& backFileName, float width, float height) { osg.ref_ptr page = new Page(album, pageNo, frontFileName, backFileName, width, height) if (page.valid()) return page.release() else return 0 } virtual void traverse(osg.NodeVisitor& nv) void setRotation(float angle) { _rotation = angle _targetRotation = angle dirtyBound() } float getRotation() const { return _rotation; } void rotateTo(float angle, float timeToRotateBy) { _targetRotation = angle _targetTime = timeToRotateBy } bool rotating() const { return _targetRotation!=_rotation; } void setPageVisible(bool frontVisible,bool backVisible) { _switch.setValue(0,!frontVisible && !backVisible) _switch.setValue(1,frontVisible) _switch.setValue(2,backVisible) } osg.Switch* getSwitch() { return _switch.get(); } const osg.Switch* getSwitch() const { return _switch.get(); } public: virtual bool computeLocalToWorldMatrix(osg.Matrix& matrix,osg.NodeVisitor*) const { if (_referenceFrame==RELATIVE_RF) { matrix.preMult(getMatrix()) } else # absolute { matrix = getMatrix() } return true } /** Get the transformation matrix which moves from world coords to local coords.*/ virtual bool computeWorldToLocalMatrix(osg.Matrix& matrix,osg.NodeVisitor*) const { const osg.Matrix& inverse = getInverseMatrix() if (_referenceFrame==RELATIVE_RF) { matrix.postMult(inverse) } else # absolute { matrix = inverse } return true } osg.Matrix getMatrix() const { return _pageOffset*osg.Matrix.rotate(-_rotation,0.0,0.0,1.0); } osg.Matrix getInverseMatrix() const { return osg.Matrix.inverse(getMatrix()); } protected: Page(Album* album, unsigned int pageNo, const std.string& frontFileName, const std.string& backFileName, float width, float height) float _rotation osg.Matrix _pageOffset float _targetRotation float _targetTime float _lastTimeTraverse osg.ref_ptr _switch } class Album : public osg.Referenced { public: Album(osg.ArgumentParser& ap, float width, float height) osg.Group* getScene() { return _group.get(); } const osg.Group* getScene() const { return _group.get(); } osg.Matrix getPageOffset(unsigned int pageNo) const bool nextPage(float timeToRotateBy) { return gotoPage(_currentPageNo+1,timeToRotateBy); } bool previousPage(float timeToRotateBy) { return _currentPageNo>=1?gotoPage(_currentPageNo-1,timeToRotateBy):false; } bool gotoPage(unsigned int pageNo, float timeToRotateBy) osg.StateSet* getBackgroundStateSet() { return _backgroundStateSet.get(); } void setVisibility() protected: typedef std.vector< osg.ref_ptr > PageList osg.ref_ptr _group PageList _pages osg.ref_ptr _backgroundStateSet unsigned int _currentPageNo float _radiusOfRings float _startAngleOfPages float _deltaAngleBetweenPages } #////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Page.Page(Album* album, unsigned int pageNo, const std.string& frontFileName, const std.string& backFileName, float width, float height) { # set up transform parts. _rotation = 0 _targetRotation = 0 _targetTime = 0 _lastTimeTraverse = 0 _pageOffset = album.getPageOffset(pageNo) setNumChildrenRequiringUpdateTraversal(1) # set up subgraph osgDB.ReaderWriter* readerWriter = osgDB.Registry.instance().getReaderWriterForExtension("gdal") if (!readerWriter) { std.cout<<"Error: GDAL plugin not available, cannot preceed with database creation"<=_targetTime) _rotation = _targetRotation else _rotation += (_targetRotation-_rotation)*(t-_lastTimeTraverse)/(_targetTime-_lastTimeTraverse) dirtyBound() } _lastTimeTraverse = t } } Transform.traverse(nv) } #////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Album.Album(osg.ArgumentParser& arguments, float width, float height) { typedef std.vector FileList FileList fileList for(int pos=1;pos=_pages.size()) return false if (pageNo>_currentPageNo) { for(unsigned int i=_currentPageNo;i0?_pages[i-1].rotating():false) || i==_currentPageNo || i==0 bool back_visible = _pages[i].rotating() || ((i+1)<_pages.size()?_pages[i+1].rotating():false) || i==_currentPageNo-1 || i==_pages.size()-1 _pages[i].setPageVisible(front_visible,back_visible) } } #////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class SlideEventHandler : public osgGA.GUIEventHandler { public: SlideEventHandler() META_Object(osgStereImageApp,SlideEventHandler) void set(Album* album, float timePerSlide, bool autoSteppingActive) virtual void accept(osgGA.GUIEventHandlerVisitor& v) { v.visit(*this); } virtual bool handle(const osgGA.GUIEventAdapter& ea,osgGA.GUIActionAdapter&) virtual void getUsage(osg.ApplicationUsage& usage) const protected: ~SlideEventHandler() {} SlideEventHandler(const SlideEventHandler&,const osg.CopyOp&) {} osg.ref_ptr _album bool _firstTraversal double _previousTime double _timePerSlide bool _autoSteppingActive } SlideEventHandler.SlideEventHandler(): _album(0), _firstTraversal(true), _previousTime(-1.0), _timePerSlide(5.0), _autoSteppingActive(false) { } void SlideEventHandler.set(Album* album, float timePerSlide, bool autoSteppingActive) { _album = album _timePerSlide = timePerSlide _autoSteppingActive = autoSteppingActive } bool SlideEventHandler.handle(const osgGA.GUIEventAdapter& ea,osgGA.GUIActionAdapter&) { switch(ea.getEventType()) { case(osgGA.GUIEventAdapter.KEYDOWN): { if (ea.getKey()=='a') { _autoSteppingActive = !_autoSteppingActive _previousTime = ea.time() return true } else if (ea.getKey()=='n') { _album.nextPage(ea.time()+1.0) return true } else if (ea.getKey()=='p') { _album.previousPage(ea.time()+1.0) return true } return false } case(osgGA.GUIEventAdapter.FRAME): { if (_autoSteppingActive) { if (_firstTraversal) { _firstTraversal = false _previousTime = ea.time() } else if (ea.time()-_previousTime>_timePerSlide) { _previousTime = ea.time() _album.nextPage(ea.time()+1.0) } } _album.setVisibility() } default: return false } } void SlideEventHandler.getUsage(osg.ApplicationUsage& usage) const { usage.addKeyboardMouseBinding("Space","Reset the image position to center") usage.addKeyboardMouseBinding("a","Toggle on/off the automatic advancement for image to image") usage.addKeyboardMouseBinding("n","Advance to next image") usage.addKeyboardMouseBinding("p","Move to previous image") } int main( int argc, char **argv ) { # use an ArgumentParser object to manage the program arguments. osg.ArgumentParser arguments(&argc,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 [image_file]") arguments.getApplicationUsage().addCommandLineOption("-d ","Time delay in sceonds 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("-h or --help","Display this information") arguments.getApplicationUsage().addCommandLineOption("--create ","Create an photo archive of specified files") # construct the viewer. osgProducer.Viewer viewer(arguments) # set up the value with sensible default event handlers. #viewer.setUpViewer(osgProducer.Viewer.ESCAPE_SETS_DONE) viewer.setUpViewer() # register the handler to add keyboard and mosue handling. SlideEventHandler* seh = new SlideEventHandler() viewer.getEventHandlerList().push_front(seh) # get details on keyboard and mouse bindings used by the viewer. viewer.getUsage(*arguments.getApplicationUsage()) # read any time delay argument. float timeDelayBetweenSlides = 5.0 while (arguments.read("-d",timeDelayBetweenSlides)) {} bool autoSteppingActive = false while (arguments.read("-a")) autoSteppingActive = true # if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage().write(std.cout) return 1 } std.string archiveName while (arguments.read("--create",archiveName)) {} # 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(std.cout) return 1 } if (arguments.argc()<=1) { arguments.getApplicationUsage().write(std.cout,osg.ApplicationUsage.COMMAND_LINE_OPTION) return 1 } if (!archiveName.empty()) { # archive name set to create PhotoArchive.FileNameList fileNameList for(int i=1;i album = new Album(arguments,width,height) # creat the scene from the file list. osg.ref_ptr rootNode = album.getScene() if (!rootNode) return 0 #osgDB.writeNodeFile(*rootNode,"test.osg") # set the scene to render viewer.setSceneData(album.getScene()) # set up the SlideEventHandler. seh.set(album.get(),timeDelayBetweenSlides,autoSteppingActive) # create the windows and run the threads. viewer.realize() osg.Matrix homePosition homePosition.makeLookAt(osg.Vec3(0.0,0.0,0.0),osg.Vec3(0.0,1.0,0.0),osg.Vec3(0.0,0.0,1.0)) while( !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() #viewer.setView(homePosition) # 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 } """