📄 osggeostructs.h
字号:
/*===========================================================================*\NAME: osgGeoStructs.hDESCRIPTION: OSG data format for reading a Geo file into OSGAUTHOR: Geoff Michel// -------------------------------------------------------------------------\ *===========================================================================*/#ifndef _GEO_STRUCTS_H_#define _GEO_STRUCTS_H_ 1typedef std::vector< geoExtensionDefRec > geoExtensionDefList;class geoField { // holds one field of data as read from the disk of a GEO filepublic: geoField() { tokenId=TypeId=0; numItems=0;storeSize=0; storage=NULL; } void init() { tokenId=TypeId=0; numItems=0;storeSize=0; storage=NULL; } unsigned char *readStorage(std::ifstream &fin, const unsigned sz) { unsigned char *st=new unsigned char[numItems*sz]; storeSize=sz; fin.read((char *)st, sz*numItems); return st; } void storageRead(std::ifstream &fin) { switch (TypeId) { case DB_CHAR: storage=readStorage(fin,SIZEOF_CHAR); break; case DB_SHORT: storage=readStorage(fin,SIZEOF_SHORT); break; case DB_INT: storage=readStorage(fin,SIZEOF_INT); break; case DB_FLOAT: storage=readStorage(fin,SIZEOF_FLOAT); break; case DB_LONG: storage=readStorage(fin,SIZEOF_LONG); break; case DB_ULONG: storage=readStorage(fin,SIZEOF_ULONG); break; case DB_DOUBLE: storage=readStorage(fin,SIZEOF_DOUBLE); break; case DB_VEC2F: storage=readStorage(fin,SIZEOF_VEC2F); break; case DB_VEC3F: storage=readStorage(fin,SIZEOF_VEC3F); break; case DB_VEC4F: storage=readStorage(fin,SIZEOF_VEC4F); break; case DB_VEC16F: storage=readStorage(fin,SIZEOF_VEC16F); break; case DB_VEC2I: storage=readStorage(fin,SIZEOF_VEC2I); break; case DB_VEC3I: storage=readStorage(fin,SIZEOF_VEC3I); break; case DB_VEC4I: storage=readStorage(fin,SIZEOF_VEC4I); break; case DB_VEC2D: storage=readStorage(fin,SIZEOF_VEC2D); break; case DB_VEC3D: storage=readStorage(fin,SIZEOF_VEC3D); break; case DB_VEC4D: storage=readStorage(fin,SIZEOF_VEC4D); break; case DB_VEC16D: storage=readStorage(fin,SIZEOF_VEC16D); break; case DB_VRTX_STRUCT: storage=readStorage(fin,SIZEOF_VRTX_STRUCT); break; case DB_UINT: storage=readStorage(fin,SIZEOF_UINT); break; case DB_USHORT: storage=readStorage(fin,SIZEOF_USHORT); break; case DB_UCHAR: storage=readStorage(fin,SIZEOF_UCHAR); break; case DB_EXT_STRUCT: storage=readStorage(fin,SIZEOF_EXT_STRUCT); break; case DB_SHORT_WITH_PADDING: storage=readStorage(fin,SIZEOF_ULONG); break; case DB_CHAR_WITH_PADDING: storage=readStorage(fin,SIZEOF_CHAR_WITH_PADDING); break; case DB_USHORT_WITH_PADDING: storage=readStorage(fin,SIZEOF_USHORT_WITH_PADDING); break; case DB_UCHAR_WITH_PADDING: storage=readStorage(fin,SIZEOF_UCHAR_WITH_PADDING); break; case DB_BOOL_WITH_PADDING: storage=readStorage(fin,SIZEOF_BOOL_WITH_PADDING); break; case DB_EXTENDED_FIELD_STRUCT: storage=readStorage(fin,SIZEOF_EXTENDED_FIELD_STRUCT); break; case DB_VEC4UC: storage=readStorage(fin,SIZEOF_VEC4UC); break; case DB_DISCRETE_MAPPING_STRUCT: storage=readStorage(fin,SIZEOF_DISCRETE_MAPPING_STRUCT); break; case DB_BITFLAGS: storage=readStorage(fin,SIZEOF_BITFLAGS); break; } } void set(unsigned short id,unsigned int fid) { // to set values TypeId=DB_UINT; tokenId=id; storeSize=SIZEOF_UINT; numItems=1; storage=new unsigned char[SIZEOF_UINT]; memcpy(storage,&fid,SIZEOF_UINT); } void set(unsigned short id,float *cen,const int nsize) { // to set values if (nsize==3) { TypeId=DB_VEC3F; tokenId=id; storeSize=SIZEOF_VEC3F; } else if (nsize==2) { TypeId=DB_VEC2F; tokenId=id; storeSize=SIZEOF_VEC2F; } else if (nsize==4) { TypeId=DB_VEC4F; tokenId=id; storeSize=SIZEOF_VEC4F; } numItems=1; storage=new unsigned char[storeSize]; memcpy(storage,cen,storeSize); } void readfile(std::ifstream &fin, const unsigned int id); // is part of a record id void parseExt(std::ifstream &fin) const; // Feb 2003 parse node extension fields void writefile(std::ofstream &fout) { // write binary file if (numItems<32767 && tokenId<256) { unsigned char tokid=tokenId, type=TypeId; fout.write((char *)&tokid, 1);fout.write((char *)&type,1); fout.write((char *)&numItems,sizeof(unsigned short)); } else { } fout.write((char *)storage, storeSize*numItems); } inline unsigned char getToken() const { return tokenId;} inline unsigned char getType() const { return TypeId;} inline unsigned short getNum() const { return numItems;} inline unsigned char *getstore (unsigned int i) const { return storage+i*storeSize; } void uncompress() { // follow the recipe to uncompress if (TypeId==DB_VEC3F) { // already uncompressed } else { float *norms=new float[numItems*SIZEOF_VEC3F]; // uncompressed size for (unsigned int i=0; i<numItems; i++) { switch (TypeId) { case DB_UINT: norms[3*i]=storage[4*i+1]/255.0f; norms[3*i+1]=storage[4*i+2]/255.0f; norms[3*i+2]=storage[4*i+3]/255.0f; if (storage[4*i] & 0x01) norms[3*i] *= -1; if (storage[4*i] & 0x02) norms[3*i+1] *= -1; if (storage[4*i] & 0x04) norms[3*i+2] *= -1; break; case DB_SHORT: norms[3*i]=(storage[6*i]*255+storage[6*i+1])/32767.0f; norms[3*i+1]=(storage[6*i+2]*255+storage[6*i+3])/32767.0f; norms[3*i+2]=(storage[6*i+4]*255+storage[6*i+5])/32767.0f; break; case DB_CHAR: norms[3*i]=storage[3*i]/127.0f; norms[3*i+1]=storage[3*i+1]/127.0f; norms[3*i+2]=storage[3*i+2]/127.0f; break; } } delete [] storage; TypeId=DB_VEC3F; storage=(unsigned char *)norms; } } inline void warn(const char *type, unsigned tval) const { if (getType() != tval) osg::notify(osg::WARN) << "Wrong type " << type << (int)tval <<" expecting "<< (int)getType() << std::endl;} inline unsigned int getUInt() const {warn("getUInt",DB_UINT); return *((unsigned int*)storage);} // return int value inline char *getChar() const {warn("getChar",DB_CHAR); return (char *)storage;} // return chars, eg for name or file name inline unsigned char getUChar() const {warn("getUChar",DB_CHAR); return *storage;} // return chars, eg for name or file name inline int getInt() const { warn("getInt", DB_INT); int val; memcpy(&val,storage,sizeof(int)); return val;} // return int value inline float getFloat() const {warn("getFloat", DB_FLOAT); return (*(float *)storage); } inline float *getFloatArr() const {warn("getFloatArr", DB_FLOAT); return ( (float *)storage); } inline int *getIntArr() const {warn("getIntArr", DB_INT); return ( (int *)storage); } inline float *getVec3Arr() const {warn("getVec3Arr", DB_VEC3F); return ( (float *)storage); } inline float *getMat44Arr() const {warn("getMat44Arr", DB_VEC16F); return ( (float *)storage); } inline double getDouble() const {warn("getDouble", DB_DOUBLE); return (*(double *)storage); } inline unsigned short getUShort() const {warn("getUShort", DB_USHORT); return (*(ushort *)storage); } inline unsigned short getShort() const {warn("getShort", DB_SHORT); return (*(short *)storage); } inline unsigned short getUShortPad() const {warn("getUShortPad", DB_USHORT_WITH_PADDING); return (*(ushort *)storage); } inline unsigned short getShortPad() const {warn("getShortPad", DB_SHORT_WITH_PADDING); return (*(short *)storage); } inline unsigned char *getUCh4Arr() const {warn("getUChArr", DB_VEC4UC); return ((unsigned char *)storage); } inline bool getBool() const {warn("getBool", DB_BOOL_WITH_PADDING); return (storage[0] != 0); } friend inline std::ostream& operator << (osgDB::Output& output, const geoField& gf) { if (gf.tokenId!=GEO_DB_LAST_FIELD) { output.indent() << " Field:token " << (int)gf.tokenId << " datatype " << (int)gf.TypeId << " num its " << gf.numItems << " size " << gf.storeSize << std::endl; if (gf.TypeId==DB_CHAR) output.indent(); for (unsigned int i=0; i<gf.numItems; i++) { if (gf.storage==NULL) { output.indent() << "No storage" << std::endl; } else { int j,k; union { unsigned char *uch; char *ch; float *ft; int *in; unsigned int *uin; short *sh; unsigned short *ush; long *ln; unsigned long *uln; double *dbl; } st; st.uch=gf.storage+i*gf.storeSize; switch (gf.TypeId) { case DB_CHAR: if (st.ch[0]) output << st.ch[0]; break; case DB_SHORT: output.indent() << st.sh[0] << std::endl; break; case DB_INT: output.indent() << *(st.in) << std::endl; break; case DB_FLOAT: output.indent() << *(st.ft) << std::endl; break; case DB_LONG: output.indent() << st.ln[0] << std::endl; break; case DB_ULONG: output.indent() << st.uln[0] << std::endl; break; case DB_DOUBLE: output.indent() << st.dbl[0] << std::endl; break; case DB_VEC2F: output.indent() << st.ft[0] << " " << st.ft[1]; output << std::endl; break; case DB_VEC3F: output.indent(); for (j=0; j<3; j++) output << st.ft[j] << " "; output << std::endl; break; case DB_VEC4F: output.indent(); for (j=0; j<4; j++) output << st.ft[j] << " "; output << std::endl; break; case DB_VEC16F: for (j=0; j<4; j++) { output.indent(); for (k=0; k<4; k++) output << st.ft[j*4+k] << " "; output << std::endl; } break; case DB_VEC2I: output.indent() << st.in[0] << " " << st.in[1] << std::endl; break; case DB_VEC3I: output.indent(); for ( j=0; j<3; j++) output << " " << st.in[j]; output << std::endl; break; case DB_VEC4I: output.indent(); for ( j=0; j<4; j++) output << st.in[j] << " "; output << std::endl; break; case DB_VEC2D: output.indent(); for ( j=0; j<2; j++) output << st.dbl[j] << " "; output << std::endl; break; case DB_VEC3D: output.indent(); for ( j=0; j<3; j++) output << st.dbl[j] << " "; output << std::endl; break; case DB_VEC4D: output.indent(); for ( j=0; j<4; j++) output << st.dbl[j] << " "; output << std::endl; break; case DB_VEC16D: for (j=0; j<4; j++) { output.indent(); for (k=0; k<4; k++) output << st.dbl[j*4+k] << " "; output << std::endl; } break; case DB_VRTX_STRUCT: output.indent() << st.ch[0] << std::endl; break; case DB_UINT: output.indent() << st.uin[0] << std::endl; break; case DB_USHORT: output.indent() << st.ush[0] << std::endl; break; case DB_UCHAR: output.indent() << (int)st.ch[0] << std::endl; break; case DB_EXT_STRUCT: output.indent() << st.ch[0] << std::endl; break; case DB_SHORT_WITH_PADDING: output.indent() << st.sh[0] << std::endl; break; case DB_CHAR_WITH_PADDING: output.indent() << st.ch[0] << std::endl; break; case DB_USHORT_WITH_PADDING: output.indent() << st.ush[0] << std::endl; break; case DB_UCHAR_WITH_PADDING: output.indent() << st.ush << std::endl; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -