Changeset 125


Ignore:
Timestamp:
Jul 11, 2005, 5:45:03 PM (19 years ago)
Author:
darran
Message:
  • adding -movie ability ...
Location:
Swollen/swollen
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • Swollen/swollen/Makefile

    r121 r125  
    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 customargumentparser.o
     31                    directionallight.o state.o customviewereventhandler.o customargumentparser.o \
     32                    animation.o
    3233CPPFLAGS         =  -F/System/Library/Frameworks -Wall -DDARWIN_QUICKTIME \
    3334                    $(OPTIMIZATION)
  • Swollen/swollen/customargumentparser.h

    r121 r125  
    2020    void write(std::ostream& s);
    2121    bool isSWM(){ return _isswm; };
     22    std::string getFilename(){ return *_filename; }
    2223
    2324
  • Swollen/swollen/customviewer.h

    r116 r125  
     1/*
     2    CustomViewer Class
     3
     4    An OpenSceneGraph viewer for pyVolution .sww files.
     5    copyright (C) 2004-2005 Geoscience Australia
     6*/
     7
     8
     9#ifndef CUSTOMVIEWER_H
     10#define CUSTOMVIEWER_H
     11
    112
    213#include <project.h>
     
    2536};
    2637
     38#endif  // CUSTOMVIEWER_H
  • Swollen/swollen/main.cpp

    r121 r125  
    1717#include <osgDB/FileNameUtils>
    1818
     19#include <animation.h>
    1920#include <project.h>
    2021#include <SWWReader.h>
     
    3738
    3839   // use an ArgumentParser object to manage the program arguments.
    39    // this custom version handles detects if the last argument is a macro file
     40   // this custom version detects if the last argument is a macro file
    4041   // and modifies the argument list accordingly so the following code works ...
    4142   CustomArgumentParser arguments( &argc, argv );
     
    7273
    7374
     75   // animation
     76   StateList statelist;
     77   bool playbackmode;
     78   bool recordingmode = false;
     79   bool savemovie = false;
     80   unsigned int playback_index = 0;
     81   std::string moviedir;
     82   Animation animation;
     83
     84   if( arguments.isSWM() )
     85   {
     86      playbackmode = true;
     87      statelist.read( arguments.getFilename() );
     88      if( arguments.read("-movie",moviedir) )
     89      {
     90         savemovie = true;  // flag to store frames and quit ...
     91         animation.setDirectory( moviedir );
     92         animation.setViewer( viewer );
     93      }
     94   }
     95   else
     96   {
     97      playbackmode = false;
     98      savemovie = false;
     99   }
     100
     101
    74102   // get details on keyboard and mouse bindings used by the viewer
    75103   viewer.getUsage(*arguments.getApplicationUsage());
    76104
    77105   // if user requested help, write it out to cout
    78    if( arguments.read("-help") )
     106   if( arguments.read("-help") || arguments.read("--help") || arguments.read("-h") )
    79107   {
    80108      arguments.getApplicationUsage()->write(std::cout);
     
    147175   HeadsUpDisplay* hud = new HeadsUpDisplay();
    148176   hud->setTitle("pyVolution SWW Viewer");
     177   if( arguments.isSWM() )
     178      hud->setMode("playback");
    149179
    150180
     
    214244   terrainmanipulator->moveToHome();
    215245   terrainmanipulator->enable();
    216 
    217 
    218    // animation
    219    StateList statelist;
    220    bool recordingmode = false;
    221    bool playbackmode = arguments.isSWM() ? true : false;
    222    unsigned int playback_index = 0;
    223246
    224247 
     
    290313
    291314      {
     315         // might need to save image from previous pass ...
     316         if( savemovie )
     317            animation.saveImage( playback_index );
     318
    292319         // in playback mode
    293320         State state = statelist.at( playback_index );
     
    313340      }
    314341
     342
    315343      // '3' key causes compiled animation to be saved to disk
    316344      if( event_handler->toggleSave() )
  • Swollen/swollen/state.cpp

    r121 r125  
    66*/
    77
     8
     9#define MAX_LINE_LENGTH 200
    810
    911#include <state.h>
     
    3436
    3537// reconstitute self from named stream
    36 void State::read(std::istream s)
     38bool State::read(std::istream& s)
    3739{
    38    s >> _timestep;
    39    s >> _position.x() >> _position.y() >> _position.z();
    40    s >> _orientation.x() >> _orientation.y() >> _orientation.z() >> _orientation.w();
    41    s >> _culling;
    42    s >> _wireframe;
     40   s >> _timestep
     41     >>  _position.x() >> _position.y() >> _position.z()
     42     >>  _orientation.x() >> _orientation.y() >> _orientation.z() >> _orientation.w()
     43     >> _culling
     44     >> _wireframe;
     45
     46   return s.fail() ? false : true;
    4347}
    4448
     
    8185
    8286
    83 bool StateList::read(std::istream& s)
     87
     88
     89
     90bool StateList::read(std::string filename)
    8491{
    85    // s >> "# SWM DATA" >> std::endl;
    8692
    87    return true;
     93   // attempt to open the macro file ...
     94   std::fstream f;
     95   f.open( filename.c_str(), std::fstream::in );
     96   if( f.is_open() )
     97   {
     98      char str[MAX_LINE_LENGTH];
     99      char *p;
     100      int index = 0;
     101
     102      // search for data section
     103      // FIXME: not very safe, what if data section missing?
     104      do
     105      {
     106         f.getline(str, MAX_LINE_LENGTH);
     107         p = strstr(str, "# SWM DATA");
     108         index++;
     109
     110      } while( p != str );
     111
     112
     113      bool valid;
     114      index = 0;
     115      do
     116      {
     117         State* s = new State();
     118         valid = s->read(f);
     119         if( valid )
     120         {
     121            this->push_back( *s );
     122            index++;
     123         }
     124      } while( valid );
     125
     126      std::cout << "Read " << index << " frames of animation for playback ..." << std::endl;
     127
     128      f.close();
     129
     130      // success only on non-empty animation
     131      if( index )
     132         return true;
     133   }
     134
     135   return false;
     136
    88137}
  • Swollen/swollen/state.h

    r121 r125  
    6565
    6666    virtual void write(std::ostream &s);
    67     virtual void read(std::istream s);
     67    virtual bool read(std::istream& s);
    6868
    6969    virtual ~State();
     
    9191   StateList();
    9292   bool write(std::ostream& s);
    93    bool read(std::istream& s);
     93   bool read(std::string filename);
    9494
    9595   //void ~StateList();
  • Swollen/swollen/version.cpp

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