source: Swollen/include/swwreader.h @ 6

Last change on this file since 6 was 6, checked in by darran, 19 years ago

new import

File size: 4.9 KB
Line 
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;}
77
78    virtual float getTime(unsigned int index) {return *(_ptime+index);}
79    virtual size_t getNumberOfVertices() {return _npoints;}
80    virtual unsigned int getNumberOfTimesteps() {return _ntimesteps;}
81    virtual int getNumberOfBedslopeIndices() {return _bedslopeindices->size();}
82    virtual int getNumberOfStageIndices() {return _stageindices->size();}
83
84    // stage culling
85    virtual void toggleCullNearZero() {_cullnearzero = _cullnearzero ? false : true;}
86    virtual bool getCullNearZero() {return _cullnearzero;}
87    virtual float getCullNearZeroValue() {return _cullnearzerovalue;}
88    virtual void toggleCullSteepAngle() {_cullsteepangle = _cullsteepangle ? false : true;}
89    virtual bool getCullSteepAngle() {return _cullsteepangle;}
90    virtual float getCullSteepAngleValue() {return _cullsteepanglevalue;}
91
92    virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);}
93
94
95protected:
96
97    virtual ~SWWReader();
98
99    std::string* _filename;
100   
101    // constructor determines SWW validity (netcdf + proper structure)
102    bool _valid;
103
104    // netCDF file id
105    int _ncid;
106
107    // netcdf dimension ids
108    int _nvolumesid, _nverticesid, _npointsid, _ntimestepsid;
109
110    // netcdf dimension values
111    size_t _nvolumes, _nvertices, _npoints, _ntimesteps;
112
113    // netcdf variable ids
114    int _xid, _yid, _zid, _volumesid, _timeid, _stageid;
115
116    // netcdf variable values (allocated in constructor)
117    float *_px, *_py, *_pz, *_ptime, *_pstage;
118    unsigned int *_pvolumes;
119
120    // fixed geometry
121    osg::ref_ptr<osg::Vec3Array> _bedslopevertices;
122    osg::ref_ptr<osg::Vec3Array> _bedslopenormals;
123    osg::ref_ptr<osg::UIntArray> _bedslopeindices;
124    osg::ref_ptr<osg::Vec3Array> _bedslopecentroids;
125
126    // geometry that changes per timestep
127    osg::ref_ptr<osg::Vec3Array> _stagevertices;
128    osg::ref_ptr<osg::Vec3Array> _stageprimitivenormals;
129    osg::ref_ptr<osg::UIntArray> _stageindices;
130    osg::ref_ptr<osg::Vec3Array> _stagevertexnormals;
131    osg::ref_ptr<osg::Vec3Array> _stagecentroids;
132
133
134    // stack of return values from netcdf function calls
135    std::vector<int> _status;
136
137    // error checker (iterates through _status stack)
138    bool _statusHasError();
139
140    // triangle connectivity, list (indexed by vertex number) of
141    // lists (indices of triangles sharing this vertex)
142    std::vector<triangle_list> _connectivity;
143
144    // stage culling
145    bool _cullnearzero;
146    float _cullnearzerovalue;
147    bool _cullsteepangle;
148    float _cullsteepanglevalue;
149
150};
151
152#endif  // SWWREADER_H
Note: See TracBrowser for help on using the repository browser.