diff --git a/src/osgPlugins/geo/ReaderWriterGEO.cpp b/src/osgPlugins/geo/ReaderWriterGEO.cpp index f923abbf0..45729e700 100644 --- a/src/osgPlugins/geo/ReaderWriterGEO.cpp +++ b/src/osgPlugins/geo/ReaderWriterGEO.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -44,10 +45,7 @@ #include "osgGeoStructs.h" #include "osgGeoNodes.h" #include "osgGeoAction.h" - -#ifdef USETEXT // buggy text feb 2003 #include // needed for text nodes -#endif // @@ -305,17 +303,19 @@ private: class geoInfo { // identifies properties required to make a new Geometry, and holds collection of vertices, indices, etc public: geoInfo(const int txidx=-2, const int sm=1, const bool bs=true) { texture=txidx; // will be -1 or 0-number of textures - geom=NULL; nstart=0; + geom=NULL; nstart=0; linewidth=1; bothsides=bs; shademodel=sm; } virtual ~geoInfo() { }; - inline int getShademodel() const { return shademodel;} - inline bool getBothsides() const { return bothsides;} - inline int getTexture() const { return texture;} - inline vertexInfo *getVinf() { return &vinf;} + inline int getShademodel(void) const { return shademodel;} + inline bool getBothsides(void) const { return bothsides;} + inline int getTexture(void) const { return texture;} + inline vertexInfo *getVinf(void) { return &vinf;} void setPools(const std::vector *coord_pool, const std::vector *normal_pool) { vinf.setPools(coord_pool,normal_pool); } + float getlinewidth(void) const { return linewidth;} + void setlineWidth(const int w) { linewidth=w;} void setGeom(osg::Geometry *nugeom) { geom=nugeom;} osg::Geometry *getGeom() const { return geom;} osg::Geometry *getGeom() { return geom;} @@ -331,6 +331,7 @@ private: int texture; // texture index bool bothsides; int shademodel; + int linewidth; vertexInfo vinf; uint nstart; // start vertex for a primitive osg::Geometry *geom; // the geometry created for this vinf and texture @@ -358,7 +359,6 @@ class ReaderWriterGEO : public ReaderWriter if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; std::ifstream fin(fileName.c_str(), std::ios::binary | std::ios::in ); - //std::ofstream fdup("geodup.geo", std::ios::binary | std::ios::out ); if (fin.is_open() ) { // read the input file. typedef std::vector NodeList; @@ -372,7 +372,7 @@ class ReaderWriterGEO : public ReaderWriter { georecord gr; gr.readfile(fin); - //if (gr.getType() != DB_DSK_INSTANCE) gr.writefile(fdup); // create a duplicate file +// osg::notify(osg::WARN) << "end of record " << (int)gr.getType() << std::endl; if (gr.getType() == DB_DSK_NORMAL_POOL) { geoField *gfff=gr.getModField(GEO_DB_NORMAL_POOL_VALUES); gfff->uncompress();// uncompress the normals @@ -380,19 +380,15 @@ class ReaderWriterGEO : public ReaderWriter recs.push_back(gr); // add to a list of all records } fin.close(); - //fdup.close(); // now sort the records so that any record followed by a PUSh has a child set = next record, etc std::vector sorted=sort(recs); // tree-list of sorted record pointers -//#ifdef _DEBUG +/*#ifdef _DEBUG osgDB::Output fout("georex.txt"); //, std::ios_base::out ); fout << "Debug file " << fileName << std::endl; output(fout,sorted); fout.close(); -//#endif - - nodeList=makeosg(sorted); // make a list of osg nodes - - +#endif */ + nodeList=makeosg(sorted); // make a list of osg nodes recs.clear(); geotxlist.clear(); geomatlist.clear(); @@ -642,6 +638,9 @@ class ReaderWriterGEO : public ReaderWriter } } } + osg::LineWidth *lw=new osg::LineWidth; + lw->setWidth(ginf.getlinewidth()); + dstate->setAttributeAndModes(lw,osg::StateAttribute::ON); nug->setStateSet( dstate ); ginf.setGeom(nug); return nug; @@ -702,7 +701,6 @@ class ReaderWriterGEO : public ReaderWriter } osg::MatrixTransform *makeText(georecord *gr) { // make transform, geode & text osg::MatrixTransform *numt=NULL; -#ifdef USETEXT // buggy text feb 2003 std::string ttfPath("fonts/times.ttf"); int gFontSize1=2; osgText::PolygonFont* polygonFont= new osgText::PolygonFont(ttfPath, @@ -777,7 +775,6 @@ class ReaderWriterGEO : public ReaderWriter } } } -#endif return numt; } void addPolyActions(std::vector< georecord *>bhv, geoInfo &gi , const uint nv) { @@ -973,6 +970,11 @@ class ReaderWriterGEO : public ReaderWriter int shademodel=gfd ? gfd->getInt() : GEO_POLY_SHADEMODEL_LIT_GOURAUD; geoInfo gi(txidx,shademodel, bothsides); gi.setPools(&coord_pool, &normal_pool); + gfd=grec->getField(GEO_DB_POLY_LINE_WIDTH); // integer line width... + if (gfd) { + int w=gfd->getInt(); + gi.setlineWidth(w); + } osg::Geometry *nugeom=makeNewGeometry(grec, gi, imat); nug->addDrawable(nugeom); igeom=ia->size(); @@ -1058,7 +1060,6 @@ class ReaderWriterGEO : public ReaderWriter igeom++; } } - // osg::notify(osg::WARN) << vinf; } return; } @@ -1666,6 +1667,12 @@ class ReaderWriterGEO : public ReaderWriter holder=makePage(gr); (*itr)->setNode(holder); break; + case DB_DSK_PERSPECTIVE_GRID_INFO: + { // relates to how model is viewed in Geo modeller + osg::Group *gp=new Group; + holder=gp; + } + break; case DB_DSK_FLOAT_VAR: case DB_DSK_INT_VAR: case DB_DSK_LONG_VAR: @@ -1691,8 +1698,8 @@ class ReaderWriterGEO : public ReaderWriter case DB_DSK_STRING_CONTENT_ACTION: default: { osg::Group *gp=new Group; - std::cout << "Unhandled item " << gr->getType() << std::endl; - std::cout << "Unhandled item " << (*itr) << std::endl; + std::cout << "Unhandled item " << gr->getType() << + "address " << (*itr) << std::endl; holder=gp; } break; @@ -1784,11 +1791,12 @@ class ReaderWriterGEO : public ReaderWriter } return NULL; } + private: geoRecordList recs; // the records read from file std::vector coord_pool; // current vertex ooords std::vector normal_pool; // current pool of normal vectors - geoHeaderGeo *theHeader; // has animation vars etc + geoHeaderGeo *theHeader; // an OSG class - has animation vars etc std::vector geotxlist; // list of geo::textures for this model std::vector geomatlist; // list of geo::materials for this model std::vector txlist; // list of osg::textures for this model @@ -1919,6 +1927,63 @@ void internalVars::update(const osg::FrameStamp *_frameStamp) { // std::cout<<"update callback - post traverse"<< (float)_frameStamp->getReferenceTime() <0) { + storageRead(fin); // allocate & fill the storage + if (tokenId == GEO_DB_USER_EXT_VALUE_FIELD) { + if (id==DB_DSK_POLYGON || id==DB_DSK_GEODE || id==DB_DSK_GROUP + || id==DB_DSK_LOD || id==DB_DSK_MESH || id==DB_DSK_CUBE + || id==DB_DSK_SPHERE || id==DB_DSK_CONE || id==DB_DSK_CYLINDER + || id==DB_DSK_TEXTURE || id==DB_DSK_MATERIAL || id==DB_DSK_VIEW) { + if (TypeId == DB_SHORT ||TypeId == DB_USHORT) fin.ignore(2); // skip padding + } + } + } + } + } +} + // now register with Registry to instantiate the above // reader/writer. osgDB::RegisterReaderWriterProxy gReaderWriter_GEO_Proxy; diff --git a/src/osgPlugins/geo/geoActions.cpp b/src/osgPlugins/geo/geoActions.cpp index 8f780d0a6..1d584497e 100644 --- a/src/osgPlugins/geo/geoActions.cpp +++ b/src/osgPlugins/geo/geoActions.cpp @@ -35,7 +35,7 @@ #include -void geoArithBehaviour::setType(uint iop) { +void geoArithBehaviour::setType(unsigned int iop) { switch (iop) { case 1: op=addv; break; /* op=addv; addv is a function so the operation can be accessed without a switch(type)... */ case 2: op=subv; break; @@ -64,7 +64,7 @@ bool geoArithBehaviour::makeBehave(const georecord *grec, geoHeaderGeo *theHeade out=theHeader->getVar(fid); // returns address of output var with fid //std::cout<< " Output " << fid << " : " << theHeader->getVarname(fid) << std::endl; gfd=grec->getField(GEO_DB_ARITHMETIC_ACTION_OP_TYPE); - uint iop=gfd?gfd->getUInt():1; + unsigned int iop=gfd?gfd->getUInt():1; setType(iop); // default add? gfd=grec->getField(GEO_DB_ARITHMETIC_ACTION_OPERAND_VALUE); if (gfd) { @@ -82,7 +82,7 @@ bool geoArithBehaviour::makeBehave(const georecord *grec, geoHeaderGeo *theHeade return ok; } -void geoAr3Behaviour::setType(uint iact) { +void geoAr3Behaviour::setType(unsigned int iact) { switch (iact) { case DB_DSK_LINEAR_ACTION: op=linear; break; /* op=addv; */ case DB_DSK_INVERSE_ACTION: op=lininv; break; @@ -122,7 +122,7 @@ void geoAr3Behaviour::doaction(osg::Node *) { // do math operation bool geoAr3Behaviour::makeBehave(const georecord *grec, geoHeaderGeo *theHeader) { bool ok=false; const geoField *gfd=grec->getField(GEO_DB_EQUATION_ACTION_INPUT_VAR); - const uint act=grec->getType(); + const unsigned int act=grec->getType(); if (gfd) { unsigned fid= gfd->getUInt(); // field identifier in=theHeader->getVar(fid); // returns address of input var with fid @@ -172,7 +172,7 @@ bool geoAr3Behaviour::makeBehave(const georecord *grec, geoHeaderGeo *theHeader) return ok; } -void geoCompareBehaviour::setType(uint iop) { +void geoCompareBehaviour::setType(unsigned int iop) { switch (iop) { case 1: oper=LESS;break; case 2: oper=LESSOREQ; break; @@ -207,7 +207,7 @@ bool geoCompareBehaviour::makeBehave(const georecord *grec, geoHeaderGeo *theHea fid= gfd->getUInt(); // field identifier out=theHeader->getVar(fid); // returns address of output var with fid gfd=grec->getField(GEO_DB_COMPARE_ACTION_OP_TYPE); - uint iop=gfd?gfd->getUInt():1; + unsigned int iop=gfd?gfd->getUInt():1; setType(iop); // default add? gfd=grec->getField(GEO_DB_COMPARE_ACTION_OPERAND_VALUE); if (gfd) { @@ -313,8 +313,8 @@ bool geoDiscreteBehaviour::makeBehave(const georecord *grec, geoHeaderGeo *theHe fid= gfd->getUInt(); // field identifier out=theHeader->getVar(fid); // returns address of output var with fid gfd=grec->getField(GEO_DB_DISCRETE_ACTION_NUM_ITEMS); - uint nr=gfd?gfd->getUInt():1; - uint i; + unsigned int nr=gfd?gfd->getUInt():1; + unsigned int i; for (i=0; igetType(); + const unsigned int act=grec->getType(); setType(act); if (act==DB_DSK_ROTATE_ACTION) { const geoField *gfd=grec->getField(GEO_DB_ROTATE_ACTION_INPUT_VAR); @@ -433,7 +433,7 @@ void geoMoveVertexBehaviour::doaction(osg::Matrix *mtr) { bool geoMoveVertexBehaviour::makeBehave(const georecord *grec, const geoHeaderGeo *theHeader) { - const uint act=grec->getType(); + const unsigned int act=grec->getType(); bool ok=false; setType(act); if (act==DB_DSK_ROTATE_ACTION) { @@ -524,14 +524,14 @@ void geoColourBehaviour::doaction(osg::Drawable *dr) { // do visibility operation on Node if (getVar()) { double val=getValue(); - uint idx=(uint)val; + unsigned int idx=(unsigned int)val; osg::Geometry *gm=dynamic_cast(dr); if (gm) { osg::Vec4Array* cla = dynamic_cast(gm->getColorArray()); if (cla) { // traps a colour behaviour added when using material for colour. - for (uint i=nstart; i<(nend); i++) { + for (unsigned int i=nstart; i<(nend); i++) { unsigned char col[4]; - uint idxtop=idx/128; + unsigned int idxtop=idx/128; (*colours)[idxtop].get(col); // from the colour palette float frac=(float)(idx-idxtop*128)/128.0f; (*cla)[i].set(col[0]*frac/255.0,col[1]*frac/255.0,col[2]*frac/255.0,1); @@ -564,7 +564,7 @@ void geoStrContentBehaviour::doaction(osg::Drawable *node) { // do new text txt->setText(std::string(content)); #endif } -bool geoStrContentBehaviour::makeBehave(const georecord *grec, geoHeaderGeo *theHeader) { +bool geoStrContentBehaviour::makeBehave(const georecord *grec, const geoHeaderGeo *theHeader) { bool ok=false; const geoField *gfd=grec->getField(GEO_DB_STRING_CONTENT_ACTION_INPUT_VAR); if (gfd) { diff --git a/src/osgPlugins/geo/osgGeoAction.h b/src/osgPlugins/geo/osgGeoAction.h index 0ca60cb25..922d23d28 100644 --- a/src/osgPlugins/geo/osgGeoAction.h +++ b/src/osgPlugins/geo/osgGeoAction.h @@ -238,7 +238,7 @@ public: geoVisibBehaviour() { } virtual ~geoVisibBehaviour() { } - bool makeBehave(const georecord *grec, const geoHeaderGeo *theHeader); + virtual bool makeBehave(const georecord *grec, const geoHeaderGeo *theHeader); virtual void doaction(osg::Node *node); private: }; @@ -267,7 +267,7 @@ public: PAD_FOR_SIGN=0; vt=UNKNOWN; } virtual ~geoStrContentBehaviour() { delete [] format;} virtual void doaction(osg::Drawable *node); // do new text - virtual bool makeBehave(const georecord *grec, geoHeaderGeo *theHeader); + virtual bool makeBehave(const georecord *grec, const geoHeaderGeo *theHeader); enum valuetype {UNKNOWN, INT, FLOAT, DOUBLE, CHAR}; private: char *format; diff --git a/src/osgPlugins/geo/osgGeoStructs.h b/src/osgPlugins/geo/osgGeoStructs.h index 15094f533..01c0849d3 100644 --- a/src/osgPlugins/geo/osgGeoStructs.h +++ b/src/osgPlugins/geo/osgGeoStructs.h @@ -14,15 +14,18 @@ AUTHOR: Geoff Michel #ifndef _GEO_STRUCTS_H_ -#define _GEO_STRUCTS_H_ +#define _GEO_STRUCTS_H_ 1 +typedef std::vector< geoExtensionDefRec > geoExtensionDefList; class geoField { // holds one field of data as read from the disk of a GEO file public: geoField() { - tokenId=TypeId=0; numItems=0;storeSize=0; + 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; @@ -129,22 +132,8 @@ public: break; } } - void readfile(std::ifstream &fin) { - unsigned char tokid, type; - unsigned short nits; - if (!fin.eof()) { - fin.read((char *)&tokid,1);fin.read((char *)&type,1); - fin.read((char *)&nits,sizeof(unsigned short)); - if (TypeId == GEO_DB_EXTENDED_FIELD) { - fin.read((char *)&tokenId,sizeof(tokenId));fin.read((char *)&TypeId,sizeof(TypeId)); - fin.read((char *)&numItems,sizeof(unsigned int)); - } else { - tokenId=tokid; TypeId=type; - numItems=nits; - } - storageRead(fin); // allocate & fill the storage - } - } + void readfile(std::ifstream &fin, const uint 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; @@ -216,6 +205,9 @@ public: << " num its " << gf.numItems << " size " << gf.storeSize << std::endl; if (gf.TypeId==DB_CHAR) output.indent(); for (uint i=0; igetPixelFormat() == GL_RGB ? 3 : img->getPixelFormat() == GL_RGBA ? 4 : 3; - uint *uim = (uint *)pfMalloc( ns * nt * ncomp, pfGetSharedArena() ); + unsigned int *uim = (unsigned int *)pfMalloc( ns * nt * ncomp, pfGetSharedArena() ); memcpy( uim, img->data(), ns * nt * ncomp );