source: Swollen/include/swwreader.h @ 61

Last change on this file since 61 was 61, checked in by darran, 20 years ago
  • Added AlphaFunc? for threshold (-alphamin <float>) culling of pixels
  • Prettified Ole's source code modifications to swwreader ;-)
File size: 5.0 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::DrawElementsUShort> getBedslopeIndexArray() {return _bedslopeindices;}
69    virtual osg::ref_ptr<osg::Vec3Array> getBedslopeCentroidArray() {return _bedslopecentroids;}
70    virtual osg::ref_ptr<osg::Vec2Array> getBedslopeTextureCoords() {return _bedslopetexcoords;}
71
72    // stage
73    virtual osg::ref_ptr<osg::Vec3Array> getStageVertexArray(unsigned int index);
74    virtual osg::ref_ptr<osg::Vec3Array> getStageVertexNormalArray() {return _stagevertexnormals;}
75    virtual osg::ref_ptr<osg::Vec3Array> getStageCentroidsArray() {return _stagecentroids;}
76    virtual osg::ref_ptr<osg::Vec4Array> getStageColorArray() {return _stagecolors;}
77
78
79    virtual float getTime(unsigned int index) {return *(_ptime+index);}
80    virtual size_t getNumberOfVertices() {return _npoints;}
81    virtual unsigned int getNumberOfTimesteps() {return _ntimesteps;}
82
83    virtual float getAlphaMin() {return _alphamin;}   
84    virtual float getAlphaMax() {return _alphamax;}   
85    virtual float getHeightMin() {return _heightmin;}       
86    virtual float getHeightMax() {return _heightmax;}           
87
88    virtual void setAlphaMin( float value ) {_alphamin = value;}   
89    virtual void setAlphaMax( float value ) {_alphamax = value;}       
90    virtual void setHeightMin( float value ) {_heightmin = value;}     
91    virtual void setHeightMax( float value ) {_heightmax = value;}       
92
93   
94    virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);}
95
96
97protected:
98
99    virtual ~SWWReader();
100
101    std::string* _filename;
102   
103    // constructor determines SWW validity (netcdf + proper structure)
104    bool _valid;
105
106    // netCDF file id
107    int _ncid;
108
109    // netcdf dimension ids
110    int _nvolumesid, _nverticesid, _npointsid, _ntimestepsid;
111
112    // netcdf dimension values
113    size_t _nvolumes, _nvertices, _npoints, _ntimesteps;
114
115    // netcdf variable ids
116    int _xid, _yid, _zid, _volumesid, _timeid, _stageid;
117
118    // netcdf variable values (allocated in constructor)
119    float *_px, *_py, *_pz, *_ptime, *_pstage;
120    unsigned int *_pvolumes;
121
122    // fixed geometry
123    osg::ref_ptr<osg::Vec3Array> _bedslopevertices;
124    osg::ref_ptr<osg::Vec3Array> _bedslopenormals;
125    osg::ref_ptr<osg::DrawElementsUShort> _bedslopeindices;
126    osg::ref_ptr<osg::Vec3Array> _bedslopecentroids;
127    osg::ref_ptr<osg::Vec2Array> _bedslopetexcoords;
128
129    // geometry that changes per timestep
130    osg::ref_ptr<osg::Vec3Array> _stagevertices;
131    osg::ref_ptr<osg::Vec3Array> _stageprimitivenormals;
132    osg::ref_ptr<osg::Vec3Array> _stagevertexnormals;
133    osg::ref_ptr<osg::Vec3Array> _stagecentroids;
134    osg::ref_ptr<osg::Vec4Array> _stagecolors;
135
136    // bedslope vertex scale and shift factors (for normalizing to unit cube)
137    float _xscale, _yscale, _zscale, _scale;
138    float _xoffset, _yoffset, _zoffset;
139    float _xcenter, _ycenter, _zcenter;
140
141    // stack of return values from netcdf function calls
142    std::vector<int> _status;
143
144    // error checker (iterates through _status stack)
145    bool _statusHasError();
146
147    // triangle connectivity, list (indexed by vertex number) of
148    // lists (indices of triangles sharing this vertex)
149    std::vector<triangle_list> _connectivity;
150
151    // define alpha (transparency) function
152    float _alphamax, _alphamin, _heightmax, _heightmin;
153
154};
155
156#endif  // SWWREADER_H
Note: See TracBrowser for help on using the repository browser.