Changeset 121


Ignore:
Timestamp:
Jul 10, 2005, 11:22:30 PM (19 years ago)
Author:
darran
Message:
  • working towards functional playback of .swm files
  • not quite there yet ... still need to reconstitute the StateList?.
Location:
Swollen/swollen
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • Swollen/swollen/Makefile

    r117 r121  
    66TOPDIR           =  ..
    77
    8 OPTIMIZATION     =  -O2
    9 #OPTIMIZATION     =  -g
     8#OPTIMIZATION     =  -O2
     9OPTIMIZATION     =  -g
    1010
    1111OSG_INCLUDE      =  ${OSGHOME}/include
     
    2929OBJ              =  customviewer.o hud.o keyboardeventhandler.o watersurface.o main.o version.o \
    3030                    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
    3232CPPFLAGS         =  -F/System/Library/Frameworks -Wall -DDARWIN_QUICKTIME \
    3333                    $(OPTIMIZATION)
  • Swollen/swollen/customargumentparser.cpp

    r120 r121  
    11
    22#include "customargumentparser.h"
     3#include <fstream>
     4#include <iostream>
     5
     6
     7#define MAX_LINE_LENGTH 200
    38
    49using namespace osg;
     
    712CustomArgumentParser::CustomArgumentParser(int* argc, char **argv) : ArgumentParser(argc, argv)
    813{
     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
    981}
     82
     83
     84void 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  
    77
    88#include <osg/ArgumentParser>
     9#include <istream>
     10#include <vector>
     11#include <string>
    912
    1013
     
    1316
    1417public:
     18
    1519    CustomArgumentParser(int *argc, char **argv);
     20    void write(std::ostream& s);
     21    bool isSWM(){ return _isswm; };
     22
    1623
    1724protected:
    1825
     26    int _nargs;
     27    std::vector<std::string> _vargs;
     28    std::string* _filename;
     29    bool _isswm;
    1930};
    2031
  • Swollen/swollen/main.cpp

    r120 r121  
    55  copyright (C) 2004-2005 Geoscience Australia
    66*/
     7
     8#include <iostream>
     9#include <fstream>
    710
    811#include <osg/Group>
     
    2326#include <watersurface.h>
    2427#include <customviewer.h>
    25 
     28#include <customargumentparser.h>
    2629
    2730// prototypes
     
    3336{
    3437
    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
    4643
    4744   // set up the usage document
     
    4946   arguments.getApplicationUsage()->setDescription( appname );
    5047   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");
    6361
    6462
    6563   // construct the viewer.
    6664   CustomViewer viewer(arguments);
     65
    6766
    6867   // set up with sensible default event handlers
     
    8382   }
    8483
     84
    8585   // same for version info
    8686   if( arguments.read("-version") )
     
    9797   if( swwfile.substr(swwfile.size()-4,4).find(".sww",0) == -1 )  // ensure filename ends in .sww
    9898   {
    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;
    100100      return 1;
    101101   }
     
    219219   StateList statelist;
    220220   bool recordingmode = false;
    221    bool playbackmode = false;
     221   bool playbackmode = arguments.isSWM() ? true : false;
    222222   unsigned int playback_index = 0;
    223223
     
    316316      if( event_handler->toggleSave() )
    317317      {
    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         }
    322328      }
    323329
  • Swollen/swollen/state.cpp

    r119 r121  
    88
    99#include <state.h>
    10 #include <fstream>
    11 #include <iostream>
    1210
    1311
     
    6967
    7068
    71 bool StateList::write( std::string filename )
     69bool StateList::write(std::ostream& s)
    7270{
    7371   if( this->size() == 0 )
    74    {
    75       std::cout << "Nothing to save, try '1' to start/stop recording ..." << std::endl;
    7672      return false;
    77    }
    7873
    79    std::ofstream f;
    80    f.open( filename.c_str() );
     74   s << "# SWM DATA" << std::endl;
    8175   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
    8679   return true;
    8780}
     81
     82
     83bool StateList::read(std::istream& s)
     84{
     85   // s >> "# SWM DATA" >> std::endl;
     86
     87   return true;
     88}
  • Swollen/swollen/state.h

    r119 r121  
    4444#include <istream>
    4545#include <vector>
     46#include <fstream>
     47#include <iostream>
     48
    4649
    4750class State
     
    8790
    8891   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();
    9296
    9397protected:
  • Swollen/swollen/version.cpp

    r117 r121  
    1 const char* version() { const char* s = "Revision: 116M"; return s; }
     1const char* version() { const char* s = "Revision: 120M"; return s; }
Note: See TracChangeset for help on using the changeset viewer.