source: Swollen/include/swwreader.h @ 44

Last change on this file since 44 was 44, checked in by darran, 20 years ago
  • terrible destruction of Swollen moving towards changes Robert suggests
File size: 5.1 KB
RevLine 
[6]1/*
2  SWWReader
3
4    A C++ class for reading PyVolution SWW files from within
5    OpenSceneGraph.
6
7    An SWW file is the visualization output of the pyVolution
8    Shallow Water Wave equation solver.  SWW files contain bedslope
9    geometry and a sequence of stages at known timesteps.  The
10    internal format is NetCDF:
11
12    netcdf demo.sww {
13        dimensions:
14            number_of_volumes = <integer> ;
15            number_of_vertices = 3 ;
16            number_of_points = <integer> ;
17            number_of_timesteps = UNLIMITED ;
18        variables:
19            float x(number_of_points) ;
20            float y(number_of_points) ;
21            float z(number_of_points) ;
22            int volumes(number_of_volumes, number_of_vertices) ;
23            float time(number_of_timesteps) ;
24            float stage(number_of_timesteps, number_of_points) ;
25
26
27    Authored under contract to Geoscience Australia by:
28
29            Darran Edmundson
30            ANU Supercomputer Facility Vizlab
31            Australian National University
32            Canberra, ACT 2600
33
34    copyright (C) 2004 Geoscience Australia
35*/
36
37#ifndef SWWREADER_H
38#define SWWREADER_H
39
40#include <string>
41#include <project.h>
42#include <iostream>
43#include <osg/Geometry>
44
45
46// needed to create a .lib file under win32/Visual Studio
47#if defined(_MSC_VER)
48    #define SWWREADER_EXPORT   __declspec(dllexport)
49#else
50    #define SWWREADER_EXPORT
51#endif
52
53
54typedef std::vector<unsigned int> triangle_list;
55
56class SWWREADER_EXPORT SWWReader
57{
58
59public:
60
61    SWWReader(const std::string& filename);
62
63    virtual bool isValid() {return _valid;}
64
65    // bedslope
66    virtual osg::ref_ptr<osg::Vec3Array> getBedslopeVertexArray() {return _bedslopevertices;}
67    virtual osg::ref_ptr<osg::Vec3Array> getBedslopeNormalArray() {return _bedslopenormals;}
68    virtual osg::ref_ptr<osg::UIntArray> getBedslopeIndexArray() {return _bedslopeindices;}
69    virtual osg::ref_ptr<osg::Vec3Array> getBedslopeCentroidArray() {return _bedslopecentroids;}
70
71    // stage
72    virtual osg::ref_ptr<osg::Vec3Array> getStageVertexArray(unsigned int index);
73    virtual osg::ref_ptr<osg::UIntArray> getStageIndexArray() {return _stageindices;}
74    virtual osg::ref_ptr<osg::Vec3Array> getStageVertexNormalArray() {return _stagevertexnormals;}
75    virtual osg::ref_ptr<osg::Vec3Array> getStagePrimitiveNormalArray() {return _stageprimitivenormals;}
76    virtual osg::ref_ptr<osg::Vec3Array> getStageCentroidsArray() {return _stagecentroids;}
[44]77    virtual osg::ref_ptr<osg::Vec4Array> getStageColorArray() {return _stagecolors;}
[6]78
[44]79
[6]80    virtual float getTime(unsigned int index) {return *(_ptime+index);}
81    virtual size_t getNumberOfVertices() {return _npoints;}
82    virtual unsigned int getNumberOfTimesteps() {return _ntimesteps;}
83    virtual int getNumberOfBedslopeIndices() {return _bedslopeindices->size();}
84    virtual int getNumberOfStageIndices() {return _stageindices->size();}
85
86    // stage culling
[13]87    virtual void toggleCullSetting();
88    virtual float getCullNearZero() {return _cullnearzero;}
89    virtual float getCullSteepAngle() {return _cullsteepangle;}
90    virtual void setCullNearZero( float value ) {_cullnearzero = value; }
91    virtual void setCullSteepAngle( float value ) {_cullsteepangle = value; }
[6]92
93    virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);}
94
95
96protected:
97
98    virtual ~SWWReader();
99
100    std::string* _filename;
101   
102    // constructor determines SWW validity (netcdf + proper structure)
103    bool _valid;
104
105    // netCDF file id
106    int _ncid;
107
108    // netcdf dimension ids
109    int _nvolumesid, _nverticesid, _npointsid, _ntimestepsid;
110
111    // netcdf dimension values
112    size_t _nvolumes, _nvertices, _npoints, _ntimesteps;
113
114    // netcdf variable ids
115    int _xid, _yid, _zid, _volumesid, _timeid, _stageid;
116
117    // netcdf variable values (allocated in constructor)
118    float *_px, *_py, *_pz, *_ptime, *_pstage;
119    unsigned int *_pvolumes;
120
121    // fixed geometry
122    osg::ref_ptr<osg::Vec3Array> _bedslopevertices;
123    osg::ref_ptr<osg::Vec3Array> _bedslopenormals;
124    osg::ref_ptr<osg::UIntArray> _bedslopeindices;
125    osg::ref_ptr<osg::Vec3Array> _bedslopecentroids;
126
127    // geometry that changes per timestep
128    osg::ref_ptr<osg::Vec3Array> _stagevertices;
129    osg::ref_ptr<osg::Vec3Array> _stageprimitivenormals;
130    osg::ref_ptr<osg::UIntArray> _stageindices;
131    osg::ref_ptr<osg::Vec3Array> _stagevertexnormals;
132    osg::ref_ptr<osg::Vec3Array> _stagecentroids;
[44]133    osg::ref_ptr<osg::Vec4Array> _stagecolors;
[6]134
[13]135    // bedslope vertex scale and shift factors (for normalizing to unit cube)
136    float _xscale, _yscale, _zscale;
137    float _xoffset, _yoffset, _zoffset;
[36]138    float _xcenter, _ycenter, _zcenter;
[6]139
140    // stack of return values from netcdf function calls
141    std::vector<int> _status;
142
143    // error checker (iterates through _status stack)
144    bool _statusHasError();
145
146    // triangle connectivity, list (indexed by vertex number) of
147    // lists (indices of triangles sharing this vertex)
148    std::vector<triangle_list> _connectivity;
149
150    // stage culling
[13]151    float _cullnearzero;
152    float _cullsteepangle;
153    enum cullstate { CULLALL, CULLNEARZERO, CULLSTEEPANGLE, CULLNONE };
154    cullstate _cullsetting;
[6]155
156};
157
[13]158#endif  // SWWREADER_H
Note: See TracBrowser for help on using the repository browser.