/* SWWReader A C++ class for reading PyVolution SWW files from within OpenSceneGraph. An SWW file is the visualization output of the pyVolution Shallow Water Wave equation solver. SWW files contain bedslope geometry and a sequence of stages at known timesteps. The internal format is NetCDF: netcdf demo.sww { dimensions: number_of_volumes = ; number_of_vertices = 3 ; number_of_points = ; number_of_timesteps = UNLIMITED ; variables: float x(number_of_points) ; float y(number_of_points) ; float z(number_of_points) ; int volumes(number_of_volumes, number_of_vertices) ; float time(number_of_timesteps) ; float stage(number_of_timesteps, number_of_points) ; Authored under contract to Geoscience Australia by: Darran Edmundson ANU Supercomputer Facility Vizlab Australian National University Canberra, ACT 2600 copyright (C) 2004 Geoscience Australia */ #ifndef SWWREADER_H #define SWWREADER_H #include #include #include #include // needed to create a .lib file under win32/Visual Studio #if defined(_MSC_VER) #define SWWREADER_EXPORT __declspec(dllexport) #else #define SWWREADER_EXPORT #endif typedef std::vector triangle_list; class SWWREADER_EXPORT SWWReader { public: SWWReader(const std::string& filename); virtual bool isValid() {return _valid;} // bedslope virtual osg::ref_ptr getBedslopeVertexArray() {return _bedslopevertices;} virtual osg::ref_ptr getBedslopeNormalArray() {return _bedslopenormals;} virtual osg::ref_ptr getBedslopeIndexArray() {return _bedslopeindices;} virtual osg::ref_ptr getBedslopeCentroidArray() {return _bedslopecentroids;} virtual osg::ref_ptr getBedslopeTextureCoords(); virtual bool hasBedslopeTexture() {return (_state.bedslopetexturefilename != NULL);} virtual void setBedslopeTexture( std::string filename ); virtual osg::Image* getBedslopeTexture(); // stage virtual osg::ref_ptr getStageVertexArray(unsigned int index); virtual osg::ref_ptr getStageVertexNormalArray() {return _stagevertexnormals;} virtual osg::ref_ptr getStageCentroidsArray() {return _stagecentroids;} virtual osg::ref_ptr getStageColorArray() {return _stagecolors;} virtual float getTime(unsigned int index) {return *(_ptime+index);} virtual size_t getNumberOfVertices() {return _npoints;} virtual unsigned int getNumberOfTimesteps() {return _ntimesteps;} virtual float getAlphaMin() {return _state.alphamin;} virtual float getAlphaMax() {return _state.alphamax;} virtual float getHeightMin() {return _state.heightmin;} virtual float getHeightMax() {return _state.heightmax;} virtual float getCullAngle() {return _state.cullangle;} virtual void setAlphaMin( float value ) {_state.alphamin = value;} virtual void setAlphaMax( float value ) {_state.alphamax = value;} virtual void setHeightMin( float value ) {_state.heightmin = value;} virtual void setHeightMax( float value ) {_state.heightmax = value;} virtual void setCullAngle( float value ) {_state.cullangle = value;} virtual void toggleCulling() {_state.culling = _state.culling ? false : true;} virtual bool getCulling() {return _state.culling;} virtual void setCulling(bool value) {_state.culling = value;} virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);} const std::string getSwollenDir() {return *(_state.swollendirectory);} virtual void setSwollenDir(const std::string path) {_state.swollendirectory = new std::string(path);} protected: virtual ~SWWReader(); // state contains all the info needed to serialize struct { float alphamax; // define alpha (transparency) function float alphamin; float heightmax; float heightmin; float cullangle; // cull triangles with steepness angle above this value bool culling; // culling is on or off std::string* swwfilename; std::string* bedslopetexturefilename; std::string* swollendirectory; } _state; // constructor determines SWW validity (netcdf + proper structure) bool _valid; // netCDF file id int _ncid; // netcdf dimension ids int _nvolumesid, _nverticesid, _npointsid, _ntimestepsid; // netcdf dimension values size_t _nvolumes, _nvertices, _npoints, _ntimesteps; // netcdf variable ids int _xid, _yid, _zid, _volumesid, _timeid, _stageid; // netcdf variable values (allocated in constructor) float *_px, *_py, *_pz, *_ptime, *_pstage; unsigned int *_pvolumes; // fixed geometry osg::ref_ptr _bedslopevertices; osg::ref_ptr _bedslopenormals; osg::ref_ptr _bedslopeindices; osg::ref_ptr _bedslopecentroids; osg::ref_ptr _bedslopetexcoords; // geometry that changes per timestep osg::ref_ptr _stagevertices; osg::ref_ptr _stageprimitivenormals; osg::ref_ptr _stagevertexnormals; osg::ref_ptr _stagecentroids; osg::ref_ptr _stagecolors; // optional geodata for bedslope texture map struct { bool hasData; int xresolution, yresolution; float xorigin, yorigin; float xpixel, ypixel; float rotation; } _bedslopegeodata; // bedslope vertex scale and shift factors (for normalizing to unit cube) float _xscale, _yscale, _zscale, _scale; float _xoffset, _yoffset, _zoffset; float _xcenter, _ycenter, _zcenter; // sww file can contain optional global offset attributes float _xllcorner, _yllcorner; // stack of return values from netcdf function calls std::vector _status; // error checker (iterates through _status stack) bool _statusHasError(); // triangle connectivity, list (indexed by vertex number) of // lists (indices of triangles sharing this vertex) std::vector _connectivity; }; #endif // SWWREADER_H