Changeset 121
- Timestamp:
- Jul 10, 2005, 11:22:30 PM (19 years ago)
- Location:
- Swollen/swollen
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
Swollen/swollen/Makefile
r117 r121 6 6 TOPDIR = .. 7 7 8 OPTIMIZATION = -O29 #OPTIMIZATION = -g8 #OPTIMIZATION = -O2 9 OPTIMIZATION = -g 10 10 11 11 OSG_INCLUDE = ${OSGHOME}/include … … 29 29 OBJ = customviewer.o hud.o keyboardeventhandler.o watersurface.o main.o version.o \ 30 30 bedslope.o createSky.o customtrackball.o customterrainmanipulator.o spotlight.o \ 31 directionallight.o state.o customviewereventhandler.o 31 directionallight.o state.o customviewereventhandler.o customargumentparser.o 32 32 CPPFLAGS = -F/System/Library/Frameworks -Wall -DDARWIN_QUICKTIME \ 33 33 $(OPTIMIZATION) -
Swollen/swollen/customargumentparser.cpp
r120 r121 1 1 2 2 #include "customargumentparser.h" 3 #include <fstream> 4 #include <iostream> 5 6 7 #define MAX_LINE_LENGTH 200 3 8 4 9 using namespace osg; … … 7 12 CustomArgumentParser::CustomArgumentParser(int* argc, char **argv) : ArgumentParser(argc, argv) 8 13 { 14 15 // last argument is either .sww or .swm filename 16 _filename = new std::string(argv[*argc-1]); 17 18 // ends in .swm? 19 if( _filename->substr(_filename->size()-4,4).find(".swm",0) != -1 ) 20 { 21 _isswm = true; 22 23 // attempt to open the macro file ... 24 std::fstream f; 25 f.open( _filename->c_str(), std::fstream::in ); 26 if( f.is_open() ) 27 { 28 char str[MAX_LINE_LENGTH]; 29 30 // FIXME: verify this really is the SWM header ... 31 f.getline(str,MAX_LINE_LENGTH); 32 33 // read the stored argc count 34 f.getline(str,MAX_LINE_LENGTH); 35 sscanf( str, "# SWM CLP %d", &_nargs ); 36 37 // we will modify the argv array to include the original 38 // argv[1] ... argv[argc-1] (ie., ignore the final argument which is the swm 39 // filename) extended by the stored arguments contained in the macro file. 40 char** newargv = new char*[*argc-1+_nargs]; 41 42 // current command line params (sans last entry, the .swm file) 43 for( int i=0; i<*argc-1; i++ ) 44 newargv[i] = argv[i]; 45 46 // now fill in the stored argv[] from the macro file 47 for( int i=0; i<_nargs; i++ ) 48 { 49 f.getline(str,MAX_LINE_LENGTH); 50 char *s = new char[strlen(str)+1]; 51 strcpy(s,str); 52 newargv[*argc-1+i] = s; 53 } 54 55 // change baseclass private members to the extended argc/argv 56 *_argc = *argc - 1 + _nargs; 57 _argv = newargv; 58 59 60 std::cout << "Modified argument list based on SWM contents" << std::endl; 61 for( int i=0; i<*_argc; i++ ) 62 std::cout << " " << i << ": " << _argv[i] << std::endl; 63 64 } 65 f.close(); 66 67 } 68 69 else 70 71 { 72 _isswm = false; 73 74 // local copies of current argc, argv[] as we may have to save them on '3' save. 75 // note that we don't save argv[0] which is the program name. 76 _nargs = *argc - 1; 77 for( int i=1; i<*argc; i++ ) 78 _vargs.push_back( std::string(argv[i]) ); 79 } 80 9 81 } 82 83 84 void CustomArgumentParser::write(std::ostream& s) 85 { 86 s << "# SWM CLP " << _nargs << std::endl; 87 88 for( int i=0; i < _nargs; i++ ) 89 s << _vargs[i] << std::endl; 90 91 } -
Swollen/swollen/customargumentparser.h
r120 r121 7 7 8 8 #include <osg/ArgumentParser> 9 #include <istream> 10 #include <vector> 11 #include <string> 9 12 10 13 … … 13 16 14 17 public: 18 15 19 CustomArgumentParser(int *argc, char **argv); 20 void write(std::ostream& s); 21 bool isSWM(){ return _isswm; }; 22 16 23 17 24 protected: 18 25 26 int _nargs; 27 std::vector<std::string> _vargs; 28 std::string* _filename; 29 bool _isswm; 19 30 }; 20 31 -
Swollen/swollen/main.cpp
r120 r121 5 5 copyright (C) 2004-2005 Geoscience Australia 6 6 */ 7 8 #include <iostream> 9 #include <fstream> 7 10 8 11 #include <osg/Group> … … 23 26 #include <watersurface.h> 24 27 #include <customviewer.h> 25 28 #include <customargumentparser.h> 26 29 27 30 // prototypes … … 33 36 { 34 37 35 // check if last argument is an swm macro recording, in which case the configuration parameters 36 // are in the swm header 37 std::string swmfile = std::string(argv[argc-1]); 38 std::cout << swmfile << std::endl; 39 if( swmfile.substr(swmfile.size()-4,4).find(".swm",0) != -1 ) // filename ends in .swm? 40 { 41 std::cout << "swm file ... need to read" << std::endl; 42 } 43 44 // use an ArgumentParser object to manage the program arguments 45 osg::ArgumentParser arguments( &argc, argv ); 38 // use an ArgumentParser object to manage the program arguments. 39 // this custom version handles detects if the last argument is a macro file 40 // and modifies the argument list accordingly so the following code works ... 41 CustomArgumentParser arguments( &argc, argv ); 42 46 43 47 44 // set up the usage document … … 49 46 arguments.getApplicationUsage()->setDescription( appname ); 50 47 arguments.getApplicationUsage()->setCommandLineUsage("swollen [options] swwfile ..."); 51 arguments.getApplicationUsage()->addCommandLineOption("-help","Display this information"); 52 arguments.getApplicationUsage()->addCommandLineOption("-scale <float>","Vertical scale factor"); 53 arguments.getApplicationUsage()->addCommandLineOption("-tps <rate>","Timesteps per second"); 54 arguments.getApplicationUsage()->addCommandLineOption("-hmin <float>","Height below which transparency is set to zero"); 55 arguments.getApplicationUsage()->addCommandLineOption("-hmax <float>","Height above which transparency is set to alphamax"); 56 arguments.getApplicationUsage()->addCommandLineOption("-alphamin <float 0-1>","Transparency value at hmin"); 57 arguments.getApplicationUsage()->addCommandLineOption("-alphamax <float 0-1>","Maximum transparency clamp value"); 58 arguments.getApplicationUsage()->addCommandLineOption("-lightpos <float>,<float>,<float>","x,y,z of bedslope directional light (z is up, default is overhead)"); 59 arguments.getApplicationUsage()->addCommandLineOption("-nosky","Omit background sky"); 60 arguments.getApplicationUsage()->addCommandLineOption("-cullangle <float angle 0-90>","Cull triangles steeper than this value"); 61 arguments.getApplicationUsage()->addCommandLineOption("-texture <file>","Image to use for bedslope topography"); 62 arguments.getApplicationUsage()->addCommandLineOption("-version","Revision number and creation (not compile) date"); 48 arguments.getApplicationUsage()->addCommandLineOption("-help", "Display this information"); 49 arguments.getApplicationUsage()->addCommandLineOption("-scale <float>", "Vertical scale factor"); 50 arguments.getApplicationUsage()->addCommandLineOption("-tps <rate>", "Timesteps per second"); 51 arguments.getApplicationUsage()->addCommandLineOption("-hmin <float>", "Height below which transparency is set to zero"); 52 arguments.getApplicationUsage()->addCommandLineOption("-hmax <float>", "Height above which transparency is set to alphamax"); 53 arguments.getApplicationUsage()->addCommandLineOption("-alphamin <float 0-1>", "Transparency value at hmin"); 54 arguments.getApplicationUsage()->addCommandLineOption("-alphamax <float 0-1>", "Maximum transparency clamp value"); 55 arguments.getApplicationUsage()->addCommandLineOption("-lightpos <float>,<float>,<float>", "x,y,z of bedslope directional light (z is up, default is overhead)"); 56 arguments.getApplicationUsage()->addCommandLineOption("-movie <dirname>", "Save numbered images to named directory and quit"); 57 arguments.getApplicationUsage()->addCommandLineOption("-nosky", "Omit background sky"); 58 arguments.getApplicationUsage()->addCommandLineOption("-cullangle <float angle 0-90>", "Cull triangles steeper than this value"); 59 arguments.getApplicationUsage()->addCommandLineOption("-texture <file>", "Image to use for bedslope topography"); 60 arguments.getApplicationUsage()->addCommandLineOption("-version", "Revision number and creation (not compile) date"); 63 61 64 62 65 63 // construct the viewer. 66 64 CustomViewer viewer(arguments); 65 67 66 68 67 // set up with sensible default event handlers … … 83 82 } 84 83 84 85 85 // same for version info 86 86 if( arguments.read("-version") ) … … 97 97 if( swwfile.substr(swwfile.size()-4,4).find(".sww",0) == -1 ) // ensure filename ends in .sww 98 98 { 99 std::cout << "Require last argument be an .sww file ... quitting" << std::endl;99 std::cout << "Require last argument be an .sww/.swm file ... quitting" << std::endl; 100 100 return 1; 101 101 } … … 219 219 StateList statelist; 220 220 bool recordingmode = false; 221 bool playbackmode = false;221 bool playbackmode = arguments.isSWM() ? true : false; 222 222 unsigned int playback_index = 0; 223 223 … … 316 316 if( event_handler->toggleSave() ) 317 317 { 318 statelist.write( std::string("movie.swm") ); 319 std::cout << argc << std::endl; 320 for( int i=0; i < argc; i++ ) 321 std::cout << argv[i] << std::endl; 318 std::fstream f; 319 f.open( "movie.swm", std::fstream::out ); 320 if( f.is_open() ) 321 { 322 f << "# SWM 1.0 START" << std::endl; 323 arguments.write( f ); 324 statelist.write( f ); 325 f << "# SWM END" << std::endl; 326 f.close(); 327 } 322 328 } 323 329 -
Swollen/swollen/state.cpp
r119 r121 8 8 9 9 #include <state.h> 10 #include <fstream>11 #include <iostream>12 10 13 11 … … 69 67 70 68 71 bool StateList::write( std::string filename)69 bool StateList::write(std::ostream& s) 72 70 { 73 71 if( this->size() == 0 ) 74 {75 std::cout << "Nothing to save, try '1' to start/stop recording ..." << std::endl;76 72 return false; 77 }78 73 79 std::ofstream f; 80 f.open( filename.c_str() ); 74 s << "# SWM DATA" << std::endl; 81 75 StateList::iterator iter = this->begin(); 82 for( ; iter < this->end(); iter++) 83 (*iter).write( f ); 84 f.close(); 85 std::cout << "Compiled animation saved to " << filename.c_str() << std::endl; 76 for( ; iter < this->end(); iter++ ) 77 (*iter).write( s ); 78 86 79 return true; 87 80 } 81 82 83 bool StateList::read(std::istream& s) 84 { 85 // s >> "# SWM DATA" >> std::endl; 86 87 return true; 88 } -
Swollen/swollen/state.h
r119 r121 44 44 #include <istream> 45 45 #include <vector> 46 #include <fstream> 47 #include <iostream> 48 46 49 47 50 class State … … 87 90 88 91 StateList(); 89 virtual bool write(std::string filename); 90 //virtual void read(std::string filename); 91 //virtual ~StateList(); 92 bool write(std::ostream& s); 93 bool read(std::istream& s); 94 95 //void ~StateList(); 92 96 93 97 protected: -
Swollen/swollen/version.cpp
r117 r121 1 const char* version() { const char* s = "Revision: 1 16M"; return s; }1 const char* version() { const char* s = "Revision: 120M"; return s; }
Note: See TracChangeset
for help on using the changeset viewer.