| 1 | |
|---|
| 2 | #ifndef _GEO_NODES_H_ |
|---|
| 3 | #define _GEO_NODES_H_ |
|---|
| 4 | |
|---|
| 5 | #include <osg/Timer> |
|---|
| 6 | |
|---|
| 7 | class geoValue { |
|---|
| 8 | public: |
|---|
| 9 | geoValue() { |
|---|
| 10 | token=0; fid=0; val.d=0; name=""; |
|---|
| 11 | vmin=0; vmax=0; |
|---|
| 12 | constrained=false; |
|---|
| 13 | } |
|---|
| 14 | geoValue(const unsigned int tok, const unsigned int fident) { |
|---|
| 15 | token=tok; fid=fident; val.d=0; name=""; |
|---|
| 16 | vmin=0; vmax=0; |
|---|
| 17 | constrained=false; |
|---|
| 18 | } |
|---|
| 19 | ~geoValue() {} |
|---|
| 20 | inline unsigned int getToken() const { return token;} |
|---|
| 21 | inline unsigned int getFID() const { return fid;} |
|---|
| 22 | inline double *getVar() { |
|---|
| 23 | return &(val.d);} |
|---|
| 24 | inline const double getVal() const { return (val.d);} |
|---|
| 25 | void setVal(double v) { val.d=v; |
|---|
| 26 | if (constrained) { |
|---|
| 27 | if (v>vmax) val.d=vmax; |
|---|
| 28 | if (v<vmin) val.d=vmin; |
|---|
| 29 | } |
|---|
| 30 | } |
|---|
| 31 | const std::string getName(void) const { return name;} |
|---|
| 32 | void setName(const char *nm) { name=nm; } |
|---|
| 33 | void setMinRange(const float f) { vmin=f;} |
|---|
| 34 | void setMaxRange(const float f) { vmax=f; } |
|---|
| 35 | void setConstrained(bool onoff=true) { constrained=onoff;} |
|---|
| 36 | private: |
|---|
| 37 | union { |
|---|
| 38 | double d; |
|---|
| 39 | float f; |
|---|
| 40 | int i; |
|---|
| 41 | unsigned int ui; |
|---|
| 42 | } val; |
|---|
| 43 | unsigned int token; |
|---|
| 44 | unsigned int fid; |
|---|
| 45 | float vmin, vmax; |
|---|
| 46 | std::string name; |
|---|
| 47 | bool constrained; |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | class internalVars { |
|---|
| 51 | public: |
|---|
| 52 | internalVars() { } |
|---|
| 53 | internalVars(const internalVars &iv) { |
|---|
| 54 | vars=iv.vars; } |
|---|
| 55 | ~internalVars() { |
|---|
| 56 | } |
|---|
| 57 | void addInternalVars(const georecord &gr); |
|---|
| 58 | void update(const osg::FrameStamp *_frameStamp); |
|---|
| 59 | double *getVar(const unsigned fid) { |
|---|
| 60 | for (std::vector<geoValue>::iterator itr=vars.begin(); |
|---|
| 61 | itr!=vars.end(); |
|---|
| 62 | ++itr) |
|---|
| 63 | { |
|---|
| 64 | if ((*itr).getFID() == fid) { |
|---|
| 65 | return ((*itr).getVar()); |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | return NULL; |
|---|
| 69 | } |
|---|
| 70 | const geoValue *getGeoVar(const unsigned fid) const { |
|---|
| 71 | for (std::vector<geoValue>::const_iterator itr=vars.begin(); |
|---|
| 72 | itr!=vars.end(); |
|---|
| 73 | ++itr) |
|---|
| 74 | { |
|---|
| 75 | if ((*itr).getFID() == fid) { |
|---|
| 76 | return (&(*itr)); |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | return NULL; |
|---|
| 80 | } |
|---|
| 81 | private: |
|---|
| 82 | std::vector<geoValue> vars; |
|---|
| 83 | }; |
|---|
| 84 | |
|---|
| 85 | class userVars { |
|---|
| 86 | public: |
|---|
| 87 | userVars() {} |
|---|
| 88 | userVars(const userVars &iv) |
|---|
| 89 | { |
|---|
| 90 | vars=iv.vars; |
|---|
| 91 | } |
|---|
| 92 | ~userVars() {} |
|---|
| 93 | unsigned int number() { return vars.size();} |
|---|
| 94 | std::vector<geoValue> *getvars() { return &vars;} |
|---|
| 95 | double *getVar(const unsigned fid) { |
|---|
| 96 | for (std::vector<geoValue>::iterator itr=vars.begin(); itr<vars.end(); itr++) { |
|---|
| 97 | if (itr->getFID() == fid) return (itr->getVar()); |
|---|
| 98 | } |
|---|
| 99 | return NULL; |
|---|
| 100 | } |
|---|
| 101 | const geoValue *getGeoVar(const unsigned fid) const { |
|---|
| 102 | for (std::vector<geoValue>::const_iterator itr=vars.begin(); itr<vars.end(); itr++) { |
|---|
| 103 | if (itr->getFID() == fid) return (&(*itr)); |
|---|
| 104 | } |
|---|
| 105 | return NULL; |
|---|
| 106 | } |
|---|
| 107 | void addUserVar(const georecord &gr); |
|---|
| 108 | private: |
|---|
| 109 | std::vector<geoValue> vars; |
|---|
| 110 | }; |
|---|
| 111 | |
|---|
| 112 | class pack_colour { |
|---|
| 113 | public: |
|---|
| 114 | pack_colour() { cr=cg=cb=0; ca=1;} |
|---|
| 115 | ~pack_colour() {} |
|---|
| 116 | pack_colour(const unsigned char col[4]) { cr= col[0]; cg= col[1];cb= col[2];; ca= col[2];} |
|---|
| 117 | void get(unsigned char col[4]) const { col[0]=cr; col[1]=cg; col[2]=cb; col[3]=ca; } |
|---|
| 118 | friend inline std::ostream& operator << (std::ostream& output, const pack_colour& pc) |
|---|
| 119 | { |
|---|
| 120 | output << " cpalette: " <<(int)pc.cr << " " <<(int)pc.cg << " " <<(int)pc.cb << " " <<(int)pc.ca; |
|---|
| 121 | return output; |
|---|
| 122 | } |
|---|
| 123 | private: |
|---|
| 124 | unsigned char cr, cg, cb, ca; |
|---|
| 125 | }; |
|---|
| 126 | |
|---|
| 127 | typedef std::vector< pack_colour > colourPalette; |
|---|
| 128 | |
|---|
| 129 | class geoHeaderGeo: public geoHeader { |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | public: |
|---|
| 133 | geoHeaderGeo(); |
|---|
| 134 | geoHeaderGeo(const geoHeaderGeo &geo,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
|---|
| 135 | |
|---|
| 136 | void addInternalVars(const georecord &gr) { intVars->addInternalVars(gr);} |
|---|
| 137 | internalVars *getInternalVars(void) const { return intVars;} |
|---|
| 138 | const std::string getVarname(const unsigned fid) const { |
|---|
| 139 | const geoValue *gv=getGeoVar(fid); |
|---|
| 140 | return gv->getName(); |
|---|
| 141 | } |
|---|
| 142 | const geoValue *getGeoVar(const unsigned fid) const; |
|---|
| 143 | double *getVar(const unsigned fid) const; |
|---|
| 144 | void addUserVar(const georecord &gr); |
|---|
| 145 | |
|---|
| 146 | void update(const osg::FrameStamp *); |
|---|
| 147 | inline void getPalette(uint icp, float cll[4]) const { |
|---|
| 148 | uint maxcol=icp/128; |
|---|
| 149 | float frac = (float)(icp-maxcol*128)/128.0f; |
|---|
| 150 | |
|---|
| 151 | if (maxcol < color_palette->size()) { |
|---|
| 152 | unsigned char col[4]; |
|---|
| 153 | (*color_palette)[maxcol].get(col); |
|---|
| 154 | for (int i=0; i<4; i++) { |
|---|
| 155 | col[i]=(unsigned char)(col[i]*frac); |
|---|
| 156 | cll[i]=col[i]/255.0f; |
|---|
| 157 | } |
|---|
| 158 | } else { |
|---|
| 159 | unsigned char col[4]; |
|---|
| 160 | col[0]=(icp & 0xff000000)>> 24; |
|---|
| 161 | col[1]=(icp & 0xff0000) >> 16; |
|---|
| 162 | col[2]=(icp & 0xff00) >> 8; |
|---|
| 163 | col[3]= icp & 0xff; |
|---|
| 164 | for (int i=0; i<4; i++) { |
|---|
| 165 | cll[i]=col[i]/255.0f; |
|---|
| 166 | } |
|---|
| 167 | cll[0]=cll[1]=cll[2]=1.0f; |
|---|
| 168 | } |
|---|
| 169 | cll[3]=1.0f; |
|---|
| 170 | } |
|---|
| 171 | void addColour(unsigned char *cpal) {(*color_palette).push_back(cpal);} |
|---|
| 172 | inline colourPalette *getColorPalette() const { return color_palette;} |
|---|
| 173 | |
|---|
| 174 | protected: |
|---|
| 175 | virtual ~geoHeaderGeo(); |
|---|
| 176 | |
|---|
| 177 | private: |
|---|
| 178 | void moveit(const double t); |
|---|
| 179 | osg::Timer_t _lastFrameTick,_initialTick; |
|---|
| 180 | osg::Timer _timer; |
|---|
| 181 | internalVars *intVars; |
|---|
| 182 | userVars *useVars; |
|---|
| 183 | userVars *extVars; |
|---|
| 184 | colourPalette *color_palette; |
|---|
| 185 | }; |
|---|
| 186 | |
|---|
| 187 | #endif |
|---|