From 303411257717a652a645d764ec5bad45f30bb15f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 2 Jan 2004 17:30:05 +0000 Subject: [PATCH] Updates to TXP plugin from Nick. --- src/osgPlugins/txp/ReaderWriterTXP.cpp | 3 - src/osgPlugins/txp/ReaderWriterTXP.h | 63 +-- src/osgPlugins/txp/TXPArchive.cpp | 10 +- src/osgPlugins/txp/TXPArchive.h | 240 +++++---- src/osgPlugins/txp/TXPNode.h | 118 ++--- src/osgPlugins/txp/TXPPageManager.h | 42 +- src/osgPlugins/txp/TXPParser.cpp | 19 +- src/osgPlugins/txp/TXPParser.h | 646 +++++++++++++++---------- src/osgPlugins/txp/TXPSeamLOD.cpp | 6 +- src/osgPlugins/txp/TXPSeamLOD.h | 88 ++-- src/osgPlugins/txp/TXPTileNode.cpp | 11 +- src/osgPlugins/txp/TXPTileNode.h | 59 +-- src/osgPlugins/txp/TileMapper.h | 95 ++-- 13 files changed, 788 insertions(+), 612 deletions(-) diff --git a/src/osgPlugins/txp/ReaderWriterTXP.cpp b/src/osgPlugins/txp/ReaderWriterTXP.cpp index c5242d055..5653ea8fd 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.cpp +++ b/src/osgPlugins/txp/ReaderWriterTXP.cpp @@ -142,14 +142,11 @@ TXPArchive *ReaderWriterTXP::getArchive(int id, const std::string& dir) return NULL; } - /* - // We load the models on demand if (archive->loadModels() == false) { ReaderWriterTXPERROR("getArchive()") << "failed to load models from archive: \"" << archiveName << "\"" << std::endl; return NULL; } - */ if (archive->loadLightAttributes() == false) { diff --git a/src/osgPlugins/txp/ReaderWriterTXP.h b/src/osgPlugins/txp/ReaderWriterTXP.h index 771967ec6..a51e261a2 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.h +++ b/src/osgPlugins/txp/ReaderWriterTXP.h @@ -1,17 +1,17 @@ -/* ************************************************************************** -* December 2003 -* -* This TerraPage loader was re-written in a fashion to use PagedLOD -* to manage paging entirely, also includes a version of Terrex's smart mesh -* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, -* slight modified. -* nick at terrex dot com -* -* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield +/*************************************************************************** + * December 2003 + * + * This TerraPage loader was re-written in a fashion to use PagedLOD + * to manage paging entirely, also includes a version of Terrex's smart mesh + * adapted to work with PagedLOD. The essential code by Boris Bralo is still present, + * slight modified. + * nick at terrex dot com + * + * Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield *****************************************************************************/ -/* ************************************************************************** - * OpenSceneGraph loader for Terrapage format database +/*************************************************************************** + * OpenSceneGraph loader for Terrapage format database * by Boris Bralo 2002 * * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh @@ -45,25 +45,28 @@ namespace txp { - class TXPArchive; - class ReaderWriterTXP : public osgDB::ReaderWriter +class TXPArchive; +class ReaderWriterTXP : public osgDB::ReaderWriter +{ +public: + virtual const char* className() { - public: - virtual const char* className() { return "TXP Reader/Writer"; } - - virtual bool acceptsExtension(const std::string& extension) - { - return osgDB::equalCaseInsensitive(extension,"txp"); - } - - virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*); - - protected: - TXPArchive *getArchive(int id, const std::string&); - std::map< int,osg::ref_ptr > _archives; - - static int _archiveId; - }; + return "TXP Reader/Writer"; + } + + virtual bool acceptsExtension(const std::string& extension) + { + return osgDB::equalCaseInsensitive(extension,"txp"); + } + + virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*); + +protected: + TXPArchive *getArchive(int id, const std::string&); + std::map< int,osg::ref_ptr > _archives; + + static int _archiveId; +}; } // namespace diff --git a/src/osgPlugins/txp/TXPArchive.cpp b/src/osgPlugins/txp/TXPArchive.cpp index 2475cb33a..438f80bfe 100644 --- a/src/osgPlugins/txp/TXPArchive.cpp +++ b/src/osgPlugins/txp/TXPArchive.cpp @@ -95,7 +95,7 @@ bool TXPArchive::openFile(const std::string& archiveName) return true; } -bool TXPArchive::loadMaterial(int ix) +bool TXPArchive::loadMaterial(int /*ix*/) { return false; } @@ -580,7 +580,11 @@ bool TXPArchive::getTileInfo(int x, int y, int lod, TileInfo& info) return false; } -osg::Group* TXPArchive::getTileContent(int x, int y, int lod) +osg::Group* TXPArchive::getTileContent( + int x, int y, int lod, + double realMinRange, + double realMaxRange, + double usedMaxRange) { if (_parser.get() == 0) { @@ -594,6 +598,6 @@ osg::Group* TXPArchive::getTileContent(int x, int y, int lod) return new osg::Group; } - osg::Group *tileGroup = _parser->parseScene(buf,_gstates,_models); + osg::Group *tileGroup = _parser->parseScene(buf,_gstates,_models,realMinRange,realMaxRange,usedMaxRange); return tileGroup; } diff --git a/src/osgPlugins/txp/TXPArchive.h b/src/osgPlugins/txp/TXPArchive.h index c85741fc8..869d0ba90 100644 --- a/src/osgPlugins/txp/TXPArchive.h +++ b/src/osgPlugins/txp/TXPArchive.h @@ -1,17 +1,17 @@ -/* ************************************************************************** -* December 2003 -* -* This TerraPage loader was re-written in a fashion to use PagedLOD -* to manage paging entirely, also includes a version of Terrex's smart mesh -* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, -* slight modified. -* nick at terrex dot com -* -* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield +/*************************************************************************** + * December 2003 + * + * This TerraPage loader was re-written in a fashion to use PagedLOD + * to manage paging entirely, also includes a version of Terrex's smart mesh + * adapted to work with PagedLOD. The essential code by Boris Bralo is still present, + * slight modified. + * nick at terrex dot com + * + * Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield *****************************************************************************/ -/* ************************************************************************** - * OpenSceneGraph loader for Terrapage format database +/*************************************************************************** + * OpenSceneGraph loader for Terrapage format database * by Boris Bralo 2002 * * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh @@ -47,107 +47,133 @@ namespace txp { - // this one handles different placement of light direction in osg and terrapage - struct DefferedLightAttribute +// this one handles different placement of light direction in osg and terrapage +struct DefferedLightAttribute +{ + // light point at (0,0,0) looking in (0,0,0) direction + osg::ref_ptr lightPoint; + osg::ref_ptr fallback; + osg::Vec3 attitude; +}; + +class TXPParser; +class TXPArchive : public trpgr_Archive, public osg::Referenced +{ +public: + // Constructor + TXPArchive(); + + // Opens the archive file and reads the header + bool openFile(const std::string& archiveName); + + // Load the materials from the archve + bool loadMaterials(); + bool loadMaterial(int ix); + + // Load the models from the archive + bool loadModels(); + bool loadModel(int ix); + + // Load the light attribs from the archive + bool loadLightAttributes(); + + // Add light attrib + void addLightAttribute(osgSim::LightPointNode* lpn, osg::StateSet* fallback , const osg::Vec3& attitude); + + // Get light attrib + inline DefferedLightAttribute& getLightAttribute(unsigned int i) { - // light point at (0,0,0) looking in (0,0,0) direction - osg::ref_ptr lightPoint; - osg::ref_ptr fallback; - osg::Vec3 attitude; + return _lights[i]; }; - - class TXPParser; - class TXPArchive : public trpgr_Archive, public osg::Referenced + + // Gets some informations for a given tile + struct TileInfo { - public: - // Constructor - TXPArchive(); - - // Opens the archive file and reads the header - bool openFile(const std::string& archiveName); - - // Load the materials from the archve - bool loadMaterials(); - bool loadMaterial(int ix); - - // Load the models from the archive - bool loadModels(); - bool loadModel(int ix); - - // Load the light attribs from the archive - bool loadLightAttributes(); - - // Add light attrib - void addLightAttribute(osgSim::LightPointNode* lpn, osg::StateSet* fallback , const osg::Vec3& attitude); - - // Get light attrib - inline DefferedLightAttribute& getLightAttribute(unsigned int i) { return _lights[i]; }; - - // Gets some informations for a given tile - struct TileInfo - { - osg::Vec3 center; - double minRange; - double maxRange; - float radius; - osg::BoundingBox bbox; - }; - bool getTileInfo(int x, int y, int lod, TileInfo& info); - - // Set/Get the archive id - inline void setId(int id) { _id = id; } - inline const int& getId() const { return _id; } - - // Returns the number of LODs for this archive - inline const int& getNumLODs() const { return _numLODs; } - - // Returns the extents of the archive - inline void getExtents(osg::BoundingBox& extents) - { - extents.set(_swExtents.x,_swExtents.y,0.0f,_neExtents.x,_neExtents.y,0.0f); - } - - // Returns the origin of the archive - inline void getOrigin(double& x, double& y) { x=_swExtents.x; y=_swExtents.y; } - - inline osg::Texture2D* getGlobalTexture(int id) { return _textures[id].get(); } - - osg::Group* getTileContent(int x, int y, int lod); - + osg::Vec3 center; + double minRange; + double maxRange; + float radius; + osg::BoundingBox bbox; + }; + bool getTileInfo(int x, int y, int lod, TileInfo& info); + + // Set/Get the archive id + inline void setId(int id) + { + _id = id; + } + inline const int& getId() const + { + return _id; + } + + // Returns the number of LODs for this archive + inline const int& getNumLODs() const + { + return _numLODs; + } + + // Returns the extents of the archive + inline void getExtents(osg::BoundingBox& extents) + { + extents.set(_swExtents.x,_swExtents.y,0.0f,_neExtents.x,_neExtents.y,0.0f); + } + + // Returns the origin of the archive + inline void getOrigin(double& x, double& y) + { + x=_swExtents.x; + y=_swExtents.y; + } + + // Returns global texture + inline osg::Texture2D* getGlobalTexture(int id) + { + return _textures[id].get(); + } + + // Returns scenegraph representing the Tile + osg::Group* getTileContent( + int x, + int y, + int lod, + double realMinRange, + double realMaxRange, + double usedMaxRange); - protected: +protected: - - // Destructor - virtual ~TXPArchive(); - - // Id of the archive - int _id; - - // Number of the LODs - int _numLODs; - - // Archive extents - trpg2dPoint _swExtents; - trpg2dPoint _neExtents; - - // Terra Page Parser - osg::ref_ptr _parser; - - // Textures - std::vector< osg::ref_ptr > _textures; - - // States - std::vector< osg::ref_ptr > _gstates; - - // Models - std::vector< osg::ref_ptr > _models; - - // Light attributes vector - std::vector _lights; - - }; + // Destructor + virtual ~TXPArchive(); + + // Id of the archive + int _id; + + // Number of the LODs + int _numLODs; + + // Archive extents + trpg2dPoint _swExtents; + trpg2dPoint _neExtents; + + // Terra Page Parser + osg::ref_ptr _parser; + + // Textures + std::vector< osg::ref_ptr > _textures; + + // States + std::vector< osg::ref_ptr > _gstates; + + // Models + std::vector< osg::ref_ptr > _models; + + // Light attributes vector + std::vector _lights; + +}; } // namespace #endif // __TXPARCHIVE_H_ + diff --git a/src/osgPlugins/txp/TXPNode.h b/src/osgPlugins/txp/TXPNode.h index 00547ced3..25c1dfaad 100644 --- a/src/osgPlugins/txp/TXPNode.h +++ b/src/osgPlugins/txp/TXPNode.h @@ -1,17 +1,17 @@ -/* ************************************************************************** -* December 2003 -* -* This TerraPage loader was re-written in a fashion to use PagedLOD -* to manage paging entirely, also includes a version of Terrex's smart mesh -* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, -* slight modified. -* nick at terrex dot com -* -* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield +/*************************************************************************** + * December 2003 + * + * This TerraPage loader was re-written in a fashion to use PagedLOD + * to manage paging entirely, also includes a version of Terrex's smart mesh + * adapted to work with PagedLOD. The essential code by Boris Bralo is still present, + * slight modified. + * nick at terrex dot com + * + * Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield *****************************************************************************/ -/* ************************************************************************** - * OpenSceneGraph loader for Terrapage format database +/*************************************************************************** + * OpenSceneGraph loader for Terrapage format database * by Boris Bralo 2002 * * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh @@ -44,55 +44,55 @@ namespace txp { - class TXPNode : public osg::Group - { - public: +class TXPNode : public osg::Group +{ +public: + + TXPNode(); - TXPNode(); - - /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ - TXPNode(const TXPNode&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - - META_Node(txp, TXPNode); - - virtual void traverse(osg::NodeVisitor& nv); - - void setArchiveName(const std::string& archiveName); - void setOptions(const std::string& options); - - const std::string& getOptions() const; - const std::string& getArchiveName() const; - - bool loadArchive(); - - TXPArchive* getArchive(); - - protected: - - virtual ~TXPNode(); - - virtual bool computeBound() const; - - void updateEye(osg::NodeVisitor& nv); - void updateSceneGraph(); - - osg::Node* addPagedLODTile(int x, int y, int lod); - - std::string _archiveName; - std::string _options; - - osg::ref_ptr _archive; - osg::ref_ptr _pageManager; - - double _originX; - double _originY; - osg::BoundingBox _extents; - - std::vector _nodesToAdd; - std::vector _nodesToRemove; - - }; + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ + TXPNode(const TXPNode&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + META_Node(txp, TXPNode); + + virtual void traverse(osg::NodeVisitor& nv); + + void setArchiveName(const std::string& archiveName); + void setOptions(const std::string& options); + + const std::string& getOptions() const; + const std::string& getArchiveName() const; + + bool loadArchive(); + + TXPArchive* getArchive(); + +protected: + + virtual ~TXPNode(); + + virtual bool computeBound() const; + + void updateEye(osg::NodeVisitor& nv); + void updateSceneGraph(); + + osg::Node* addPagedLODTile(int x, int y, int lod); + + std::string _archiveName; + std::string _options; + + osg::ref_ptr _archive; + osg::ref_ptr _pageManager; + + double _originX; + double _originY; + osg::BoundingBox _extents; + + std::vector _nodesToAdd; + std::vector _nodesToRemove; + +}; + } // namespace diff --git a/src/osgPlugins/txp/TXPPageManager.h b/src/osgPlugins/txp/TXPPageManager.h index cc4d3a47e..45b024a79 100644 --- a/src/osgPlugins/txp/TXPPageManager.h +++ b/src/osgPlugins/txp/TXPPageManager.h @@ -1,17 +1,17 @@ -/* ************************************************************************** -* December 2003 -* -* This TerraPage loader was re-written in a fashion to use PagedLOD -* to manage paging entirely, also includes a version of Terrex's smart mesh -* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, -* slight modified. -* nick at terrex dot com -* -* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield +/*************************************************************************** + * December 2003 + * + * This TerraPage loader was re-written in a fashion to use PagedLOD + * to manage paging entirely, also includes a version of Terrex's smart mesh + * adapted to work with PagedLOD. The essential code by Boris Bralo is still present, + * slight modified. + * nick at terrex dot com + * + * Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield *****************************************************************************/ -/* ************************************************************************** - * OpenSceneGraph loader for Terrapage format database +/*************************************************************************** + * OpenSceneGraph loader for Terrapage format database * by Boris Bralo 2002 * * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh @@ -42,15 +42,15 @@ namespace txp { - class TXPPageManager : public trpgPageManager, public osg::Referenced - { - public: - TXPPageManager(); - - protected: - virtual ~TXPPageManager(); - - }; +class TXPPageManager : public trpgPageManager, public osg::Referenced +{ +public: + TXPPageManager(); + +protected: + virtual ~TXPPageManager(); + +}; } // namespace diff --git a/src/osgPlugins/txp/TXPParser.cpp b/src/osgPlugins/txp/TXPParser.cpp index b211d9062..0e7f7fba2 100644 --- a/src/osgPlugins/txp/TXPParser.cpp +++ b/src/osgPlugins/txp/TXPParser.cpp @@ -34,7 +34,10 @@ _numBillboardLevels(0), _underLayerSubgraph(false), _numLayerLevels(0), _layerGeode(0), -_defaultMaxAnisotropy(1.0f) +_defaultMaxAnisotropy(1.0f), +_realMinRange(0.0), +_realMaxRange(0.0), +_usedMaxRange(0.0) { AddCallback(TRPG_GEOMETRY,new geomRead(this)); AddCallback(TRPG_GROUP,new groupRead(this)); @@ -59,7 +62,8 @@ TXPParser::~TXPParser() osg::Group *TXPParser::parseScene( trpgReadBuffer &buf, std::vector > &materials, - std::vector > &models) + std::vector > &models, + double realMinRange, double realMaxRange, double usedMaxRange) { if (_archive == 0) return NULL; @@ -75,6 +79,10 @@ osg::Group *TXPParser::parseScene( _underLayerSubgraph = false; _numLayerLevels = 0; + _realMinRange = realMinRange; + _realMaxRange = realMaxRange; + _usedMaxRange = usedMaxRange; + if (!Parse(buf)) { osg::notify(osg::NOTICE) << "txp::TXPParser::parseScene(): failed to parse the given tile" << std::endl; @@ -473,7 +481,12 @@ void* lodRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) osgCenter[1] = center.y; osgCenter[2] = center.z; osgLod->setCenter(osgCenter); - osgLod->setRange(0,minRange, maxRange ); + //osgLod->setRange(0,minRange, maxRange ); + osgLod->setRange( + 0, + _parse->checkAndGetMinRange(minRange), + _parse->checkAndGetMaxRange(maxRange) + ); // Our LODs are binary so we need to add a group under this LOD and attach stuff // to that instead of the LOD diff --git a/src/osgPlugins/txp/TXPParser.h b/src/osgPlugins/txp/TXPParser.h index 71fd920b4..7fcef5a7d 100644 --- a/src/osgPlugins/txp/TXPParser.h +++ b/src/osgPlugins/txp/TXPParser.h @@ -1,17 +1,17 @@ -/* ************************************************************************** -* December 2003 -* -* This TerraPage loader was re-written in a fashion to use PagedLOD -* to manage paging entirely, also includes a version of Terrex's smart mesh -* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, -* slight modified. -* nick at terrex dot com -* -* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield +/*************************************************************************** + * December 2003 + * + * This TerraPage loader was re-written in a fashion to use PagedLOD + * to manage paging entirely, also includes a version of Terrex's smart mesh + * adapted to work with PagedLOD. The essential code by Boris Bralo is still present, + * slight modified. + * nick at terrex dot com + * + * Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield *****************************************************************************/ -/* ************************************************************************** - * OpenSceneGraph loader for Terrapage format database +/*************************************************************************** + * OpenSceneGraph loader for Terrapage format database * by Boris Bralo 2002 * * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh @@ -31,6 +31,7 @@ * All Rights Reserved. * *****************************************************************************/ + #ifndef __TXPPARSER_H_ #define __TXPPARSER_H_ @@ -38,278 +39,387 @@ #include #include #include + #include + #include "trpage_read.h" namespace txp { - // Gets local texture via the image helper - osg::Texture2D* getLocalTexture(trpgrImageHelper& image_helper, const trpgTexture* tex); - osg::Texture2D* getTemplateTexture(trpgrImageHelper& image_helper, trpgLocalMaterial* locmat, const trpgTexture* tex, int index=0); - // This is group that will has geode node - // It is better since all the geometry children will be - // added into one Geode node as drawables, then having one - // geode node per child - // Means, instad of having - // Group - // +----------- - // | | - // Geode Geode - // | | - // Drawable Drawable - // we will have - // Group - // | - // Geode - // +----------- - // | | - // Drawable Drawable - class GeodeGroup : public osg::Group +// Gets local texture via the image helper +osg::Texture2D* getLocalTexture(trpgrImageHelper& image_helper, const trpgTexture* tex); +osg::Texture2D* getTemplateTexture(trpgrImageHelper& image_helper, trpgLocalMaterial* locmat, const trpgTexture* tex, int index=0); + + + +// This is group that will has geode node +// It is better since all the geometry children will be +// added into one Geode node as drawables, then having one +// geode node per child +// Means, instad of having +// Group +// +----------- +// | | +// Geode Geode +// | | +// Drawable Drawable +// we will have +// Group +// | +// Geode +// +----------- +// | | +// Drawable Drawable + +class GeodeGroup : public osg::Group +{ +public: + + GeodeGroup() : osg::Group(), _geode(NULL) + {}; + + GeodeGroup(const GeodeGroup& gg,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): + osg::Group(gg, copyop), _geode(gg._geode) + {}; + + META_Node(txp, GeodeGroup); + + osg::Geode* getGeode() { - public: - GeodeGroup() : osg::Group(), _geode(NULL) {}; - GeodeGroup(const GeodeGroup& gg,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY): - osg::Group(gg, copyop), _geode(gg._geode) {}; - META_Node(txp, GeodeGroup); - - osg::Geode* getGeode() - { - if (_geode == 0) - { - _geode = new osg::Geode(); - addChild(_geode); - } - - return _geode; + if (_geode == 0) + { + _geode = new osg::Geode(); + addChild(_geode); } - - protected: - osg::Geode* _geode; - }; - - - class TXPArchive; - struct DefferedLightAttribute; - class TXPParser : public trpgSceneParser, public osg::Referenced - { - public: - TXPParser(); - - // Sets the archive to be parsed - inline void setArchive(TXPArchive* archive) { _archive = archive; } - - // Scene parser - osg::Group *parseScene( - trpgReadBuffer &buf, - std::vector > &materials, - std::vector > &models); - - // Returns the current Top Group - inline osg::Group* getCurrTop() { return _currentTop ? _currentTop : _root.get(); } - - // Sets the group as potentional tile group - inline void setPotentionalTileGroup(osg::Group* grp) { _tileGroups[grp] = 1; } - - // Return the current material list (passed in to ParseScene()) - inline std::vector >* getMaterials() { return _materials; } - - // New to TerraPage 2.0 - local materials - std::vector >* getLocalMaterials() { return &_localMaterials; } - - // Load local materials - void loadLocalMaterials(); - - // Return the current model list - std::vector >* getModels() { return _models; } - - // Request a model to be load - bool requestModel(int ix); - - // Return a reference to the tile header (after a tile has been read) - inline trpgTileHeader *getTileHeaderRef() { return &_tileHeader; } - - // Returns true if we are under billboard subgraph - inline const bool underBillboardSubgraph() const { return _underBillboardSubgraph; } - - // Sets if we are under billboard subgraph - inline void setUnderBillboardSubgraph(bool b) { _underBillboardSubgraph = b; } - - // TXP Billboard info - struct TXPBillboardInfo - { - int type; - int mode; - trpg3dPoint center; - trpg3dPoint axis; - }; - - // Sets info for the last billboard parsed - inline void setLastBillboardInfo(TXPBillboardInfo& info) { _lastBillboardInfo = info; } - - // Gets info for the last billboard parsed - inline void getLastBillboardInfo(TXPBillboardInfo& info) { info = _lastBillboardInfo; } - - // Gets light attrib - DefferedLightAttribute& getLightAttribute(int ix); - - // Returns if we are under layer subgraph - inline const bool underLayerSubgraph() const { return _underLayerSubgraph; } - - // Sets if we are under layer subgraph - inline void setUnderLayerSubgraph(bool b) {_underLayerSubgraph = b; } - - // Set the current layer geode - inline void setLayerGeode(osg::Geode* layer) { _layerGeode = layer; } - - // Returns the current layer geode - inline osg::Geode* getLayerGeode() const { return _layerGeode; } - - // default value to use when setting up textures. - void setMaxAnisotropy(float anisotropy) { _defaultMaxAnisotropy = anisotropy; } - float getMaxAnisotropy() const { return _defaultMaxAnisotropy; } - - - protected: - virtual ~TXPParser(); - - // Removes any empty groups and LODs - void removeEmptyGroups(); - - // Called on start children - bool StartChildren(void *); - - // Called on end children - bool EndChildren(void *); - - // THE archive - TXPArchive *_archive; - - // Current parent - osg::Group* _currentTop; - - // The root of the til - osg::ref_ptr _root; - - // Parents list - std::stack _parents; - - // Potentional Tile groups - std::map _tileGroups; - - // Replace the tile lod to regular group - void replaceTileLod(osg::Group*); - - // Materials - std::vector >* _materials; - - // Local materials - std::vector > _localMaterials; - - // Model list - std::vector >* _models; - - // Tile header - trpgTileHeader _tileHeader; - - // true if we are under billboard subgraph - bool _underBillboardSubgraph; - - // Number of levels below the billboard node - int _numBillboardLevels; - - // Last billboard we parsed - TXPBillboardInfo _lastBillboardInfo; - - // true if we are under layer subgraph - bool _underLayerSubgraph; - - // Numbers of levels below layer subgraph - int _numLayerLevels; - - // Our Layer Geode - osg::Geode* _layerGeode; - // default value to use when setting up textures. - float _defaultMaxAnisotropy; + return _geode; + } +protected: + osg::Geode* _geode; +}; - // TEMP - osg::Geode* createBoundingBox(int x,int y, int lod); - }; - //! callback functions for various scene graph elements - //---------------------------------------------------------------------------- - class geomRead : public trpgr_Callback { - public: - geomRead(TXPParser *in_parse) : _parse(in_parse) {}; - void *Parse(trpgToken tok,trpgReadBuffer &buf); - protected: - TXPParser *_parse; +class TXPArchive; +struct DefferedLightAttribute; + +class TXPParser : public trpgSceneParser, public osg::Referenced +{ +public: + TXPParser(); + + // Sets the archive to be parsed + inline void setArchive(TXPArchive* archive) + { + _archive = archive; + } + + // Scene parser + osg::Group *parseScene( + trpgReadBuffer &buf, + std::vector > &materials, + std::vector > &models, + double realMinRange, double realMaxRange, double usedMaxRange); + + // Returns the current Top Group + inline osg::Group* getCurrTop() + { + return _currentTop ? _currentTop : _root.get(); + } + + // Sets the group as potentional tile group + inline void setPotentionalTileGroup(osg::Group* grp) + { + _tileGroups[grp] = 1; + } + + // Return the current material list (passed in to ParseScene()) + inline std::vector >* getMaterials() + { + return _materials; + } + + // New to TerraPage 2.0 - local materials + std::vector >* getLocalMaterials() + { + return &_localMaterials; + } + + // Load local materials + void loadLocalMaterials(); + + // Return the current model list + std::vector >* getModels() + { + return _models; + } + + // Request a model to be load + bool requestModel(int ix); + + // Return a reference to the tile header (after a tile has been read) + inline trpgTileHeader *getTileHeaderRef() + { + return &_tileHeader; + } + + + // Returns true if we are under billboard subgraph + inline const bool underBillboardSubgraph() const + { + return _underBillboardSubgraph; + } + + // Sets if we are under billboard subgraph + inline void setUnderBillboardSubgraph(bool b) + { + _underBillboardSubgraph = b; + } + + // TXP Billboard info + struct TXPBillboardInfo + { + int type; + int mode; + trpg3dPoint center; + trpg3dPoint axis; }; - //---------------------------------------------------------------------------- - class groupRead : public trpgr_Callback { - public: - groupRead(TXPParser *in_parse) : _parse(in_parse) {}; - void *Parse(trpgToken tok,trpgReadBuffer &buf); - protected: - TXPParser *_parse; - }; + // Sets info for the last billboard parsed + inline void setLastBillboardInfo(TXPBillboardInfo& info) + { + _lastBillboardInfo = info; + } - //---------------------------------------------------------------------------- - class lodRead : public trpgr_Callback { - public: - lodRead(TXPParser *in_parse) : _parse(in_parse) {}; - void *Parse(trpgToken tok,trpgReadBuffer &buf); - protected: - TXPParser *_parse; - }; - - //---------------------------------------------------------------------------- - class tileHeaderRead : public trpgr_Callback { - public: - tileHeaderRead(TXPParser *in_parse) : _parse(in_parse) {}; - void *Parse(trpgToken tok,trpgReadBuffer &buf); - protected: - TXPParser *_parse; - }; - - //---------------------------------------------------------------------------- - class modelRefRead : public trpgr_Callback { - public: - modelRefRead(TXPParser *in_parse) : _parse(in_parse) {}; - void *Parse(trpgToken tok,trpgReadBuffer &buf); - protected: - TXPParser *_parse; - }; - - //---------------------------------------------------------------------------- - class billboardRead : public trpgr_Callback { - public: - billboardRead(TXPParser *in_parse) : _parse(in_parse) {}; - void *Parse(trpgToken tok,trpgReadBuffer &buf); - protected: - TXPParser *_parse; - }; - - //---------------------------------------------------------------------------- - class lightRead: public trpgr_Callback { - public: - lightRead(TXPParser *in_parse) : _parse(in_parse) {}; - void *Parse(trpgToken tok,trpgReadBuffer &buf); - protected: - TXPParser *_parse; - }; + // Gets info for the last billboard parsed + inline void getLastBillboardInfo(TXPBillboardInfo& info) + { + info = _lastBillboardInfo; + } - //---------------------------------------------------------------------------- - class layerRead: public trpgr_Callback { - public: - layerRead(TXPParser *in_parse) : _parse(in_parse) {}; - void *Parse(trpgToken tok,trpgReadBuffer &buf); - protected: - TXPParser *_parse; - }; + // Gets light attrib + DefferedLightAttribute& getLightAttribute(int ix); + + // Returns if we are under layer subgraph + inline const bool underLayerSubgraph() const + { + return _underLayerSubgraph; + } + + // Sets if we are under layer subgraph + inline void setUnderLayerSubgraph(bool b) + { + _underLayerSubgraph = b; + } + + // Set the current layer geode + inline void setLayerGeode(osg::Geode* layer) + { + _layerGeode = layer; + } + + // Returns the current layer geode + inline osg::Geode* getLayerGeode() const + { + return _layerGeode; + } + + // default value to use when setting up textures. + void setMaxAnisotropy(float anisotropy) + { + _defaultMaxAnisotropy = anisotropy; + } + float getMaxAnisotropy() const + { + return _defaultMaxAnisotropy; + } + + // We need to change the LOD ranges within tiles since + // we have done it for the PagedLODs representing tiles + inline double checkAndGetMinRange(double range) + { + if ((range-_realMinRange) < 0.0001) + return 0.0; + else + return range; + } + inline double checkAndGetMaxRange(double range) + { + if ((range-_realMaxRange) < 0.0001) + return _usedMaxRange; + else + return range; + } + + +protected: + + virtual ~TXPParser(); + + // Removes any empty groups and LODs + void removeEmptyGroups(); + + // Called on start children + bool StartChildren(void *); + + // Called on end children + bool EndChildren(void *); + + // THE archive + TXPArchive *_archive; + + // Current parent + osg::Group* _currentTop; + + // The root of the tile + osg::ref_ptr _root; + + // Parents list + std::stack _parents; + + // Potentional Tile groups + std::map _tileGroups; + + // Replace the tile lod to regular group + void replaceTileLod(osg::Group*); + + // Materials + std::vector >* _materials; + + // Local materials + std::vector > _localMaterials; + + // Model list + std::vector >* _models; + + // Tile header + trpgTileHeader _tileHeader; + + // true if we are under billboard subgraph + bool _underBillboardSubgraph; + + // Number of levels below the billboard node + int _numBillboardLevels; + + // Last billboard we parsed + TXPBillboardInfo _lastBillboardInfo; + + // true if we are under layer subgraph + bool _underLayerSubgraph; + + // Numbers of levels below layer subgraph + int _numLayerLevels; + + // Our Layer Geode + osg::Geode* _layerGeode; + + // default value to use when setting up textures. + float _defaultMaxAnisotropy; + + // LOD ranges to be used when parsing tiles + double _realMinRange; + double _realMaxRange; + double _usedMaxRange; + + // TEMP + osg::Geode* createBoundingBox(int x,int y, int lod); + +}; + + +//! callback functions for various scene graph elements +//---------------------------------------------------------------------------- +class geomRead : public trpgr_Callback +{ +public: + + geomRead(TXPParser *in_parse) : _parse(in_parse) + {}; + void *Parse(trpgToken tok,trpgReadBuffer &buf); +protected: + TXPParser *_parse; +}; + + +//---------------------------------------------------------------------------- +class groupRead : public trpgr_Callback +{ +public: + groupRead(TXPParser *in_parse) : _parse(in_parse) + {}; + void *Parse(trpgToken tok,trpgReadBuffer &buf); +protected: + TXPParser *_parse; +}; + +//---------------------------------------------------------------------------- +class lodRead : public trpgr_Callback +{ +public: + lodRead(TXPParser *in_parse) : _parse(in_parse) + {}; + void *Parse(trpgToken tok,trpgReadBuffer &buf); +protected: + TXPParser *_parse; +}; + +//---------------------------------------------------------------------------- +class tileHeaderRead : public trpgr_Callback +{ +public: + tileHeaderRead(TXPParser *in_parse) : _parse(in_parse) + {}; + void *Parse(trpgToken tok,trpgReadBuffer &buf); +protected: + TXPParser *_parse; +}; + +//---------------------------------------------------------------------------- + +class modelRefRead : public trpgr_Callback +{ +public: + modelRefRead(TXPParser *in_parse) : _parse(in_parse) + {}; + void *Parse(trpgToken tok,trpgReadBuffer &buf); +protected: + TXPParser *_parse; +}; + +//---------------------------------------------------------------------------- +class billboardRead : public trpgr_Callback +{ +public: + billboardRead(TXPParser *in_parse) : _parse(in_parse) + {}; + void *Parse(trpgToken tok,trpgReadBuffer &buf); +protected: + TXPParser *_parse; +}; + +//---------------------------------------------------------------------------- +class lightRead: public trpgr_Callback +{ +public: + lightRead(TXPParser *in_parse) : _parse(in_parse) + {}; + void *Parse(trpgToken tok,trpgReadBuffer &buf); +protected: + TXPParser *_parse; +}; + +//---------------------------------------------------------------------------- +class layerRead: public trpgr_Callback +{ +public: + layerRead(TXPParser *in_parse) : _parse(in_parse) + {}; + void *Parse(trpgToken tok,trpgReadBuffer &buf); +protected: + TXPParser *_parse; +}; } // namespace #endif // __TXPPARSER_H_ + diff --git a/src/osgPlugins/txp/TXPSeamLOD.cpp b/src/osgPlugins/txp/TXPSeamLOD.cpp index 6ec74ce0b..4e159959b 100644 --- a/src/osgPlugins/txp/TXPSeamLOD.cpp +++ b/src/osgPlugins/txp/TXPSeamLOD.cpp @@ -5,7 +5,6 @@ using namespace txp; - TXPSeamLOD::TXPSeamLOD() : Group() { @@ -38,7 +37,6 @@ TXPSeamLOD::TXPSeamLOD(const TXPSeamLOD& ttg,const osg::CopyOp& copyop) : _neighbourTileX = ttg._neighbourTileX; _neighbourTileY = ttg._neighbourTileY; _neighbourTileLOD = ttg._neighbourTileLOD; - _tileRef = ttg._tileRef; _archive = ttg._archive; } @@ -47,9 +45,7 @@ void TXPSeamLOD::traverse(osg::NodeVisitor& nv) { if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR && _children.size()==2) { - float distance = nv.getDistanceToEyePoint(_center,true); - if (distance<_mid) { // cap the lod's that can be used to what is available in the adjacent PagedLOD. @@ -61,10 +57,10 @@ void TXPSeamLOD::traverse(osg::NodeVisitor& nv) { getChild(0)->accept(nv); } - } else { Group::traverse(nv); } } + diff --git a/src/osgPlugins/txp/TXPSeamLOD.h b/src/osgPlugins/txp/TXPSeamLOD.h index a42c81590..44bad76d6 100644 --- a/src/osgPlugins/txp/TXPSeamLOD.h +++ b/src/osgPlugins/txp/TXPSeamLOD.h @@ -1,17 +1,17 @@ -/* ************************************************************************** -* December 2003 -* -* This TerraPage loader was re-written in a fashion to use PagedLOD -* to manage paging entirely, also includes a version of Terrex's smart mesh -* adapted to work with PagedLOD. The basic code by Boris Bralo is still present, -* slight modified. -* nick at terrex dot com -* -* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield +/*************************************************************************** + * December 2003 + * + * This TerraPage loader was re-written in a fashion to use PagedLOD + * to manage paging entirely, also includes a version of Terrex's smart mesh + * adapted to work with PagedLOD. The essential code by Boris Bralo is still present, + * slight modified. + * nick at terrex dot com + * + * Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield *****************************************************************************/ -/* ************************************************************************** - * OpenSceneGraph loader for Terrapage format database +/*************************************************************************** + * OpenSceneGraph loader for Terrapage format database * by Boris Bralo 2002 * * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh @@ -31,6 +31,7 @@ * All Rights Reserved. * *****************************************************************************/ + #ifndef TXPSeamLOD_H #define TXPSeamLOD_H @@ -43,48 +44,61 @@ namespace txp { - class TXPSeamLOD : public osg::Group { public: - TXPSeamLOD(); - TXPSeamLOD(int x, int y, int lod, const osg::Vec3& center, float dmin, float dmid, float dmax); - TXPSeamLOD(const TXPSeamLOD&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + TXPSeamLOD(); - META_Node(txp, TXPSeamLOD); + TXPSeamLOD(int x, int y, int lod, const osg::Vec3& center, float dmin, + float dmid, float dmax); - virtual void traverse(osg::NodeVisitor& nv); + TXPSeamLOD(const TXPSeamLOD&, + const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); - void setTileRef(bool* b) - { - _tileRef = b; - } + META_Node(txp, TXPSeamLOD); - void setTxpNode(TXPTileNode* txpNode) { _txpNode = txpNode; } - TXPTileNode* getTxpNode() const { return _txpNode; } + virtual void traverse(osg::NodeVisitor& nv); - void setArchive(TXPArchive* ar) { _archive = ar; } + void setTileRef(bool* b) + { + _tileRef = b; + } + + void setTxpNode(TXPTileNode* txpNode) + { + _txpNode = txpNode; + } + + TXPTileNode* getTxpNode() const + { + return _txpNode; + } + + void setArchive(TXPArchive* ar) + { + _archive = ar; + } protected: - int _neighbourTileX; - int _neighbourTileY; - int _neighbourTileLOD; + int _neighbourTileX; + int _neighbourTileY; + int _neighbourTileLOD; - osg::Vec3 _center; - float _min; - float _mid; - float _max; + osg::Vec3 _center; - bool* _tileRef; + float _min; + float _mid; + float _max; - TXPTileNode* _txpNode; - TXPArchive* _archive; - - + bool* _tileRef; + + TXPTileNode* _txpNode; + TXPArchive* _archive; }; } #endif + diff --git a/src/osgPlugins/txp/TXPTileNode.cpp b/src/osgPlugins/txp/TXPTileNode.cpp index 5ff51f7d0..04daaa402 100644 --- a/src/osgPlugins/txp/TXPTileNode.cpp +++ b/src/osgPlugins/txp/TXPTileNode.cpp @@ -147,7 +147,10 @@ bool TXPTileNode::loadTile(int x, int y, int lod) if (validTile) { - osg::Group* tileGroup = _archive->getTileContent(x,y,lod); + double realMinRange = info.minRange; + double realMaxRange = info.maxRange; + double usedMaxRange = osg::maximum(info.maxRange,1e7); + osg::Group* tileGroup = _archive->getTileContent(x,y,lod,realMinRange,realMaxRange,usedMaxRange); // if group has only one child, then simply use its child. @@ -190,7 +193,7 @@ bool TXPTileNode::loadTile(int x, int y, int lod) _archive->getId() ); - osg::PagedLOD* pagedLOD = new osg::PagedLOD; + osg::ref_ptr pagedLOD = new osg::PagedLOD; // not use maximum(info.maxRange,1e7) as just maxRange would result in some corner tiles from being culled out. pagedLOD->addChild(tileGroup,info.minRange,osg::maximum(info.maxRange,1e7)); pagedLOD->setFileName(1,pagedLODfile); @@ -199,9 +202,9 @@ bool TXPTileNode::loadTile(int x, int y, int lod) pagedLOD->setRadius(info.radius); pagedLOD->setNumChildrenThatCannotBeExpired(1); - TileMapper::instance()->insertPagedLOD(x,y,lod,pagedLOD); + TileMapper::instance()->insertPagedLOD(x,y,lod,pagedLOD.get()); - addChild(pagedLOD); + addChild(pagedLOD.get()); } else { diff --git a/src/osgPlugins/txp/TXPTileNode.h b/src/osgPlugins/txp/TXPTileNode.h index f0ea0cf8b..49cfb1e37 100644 --- a/src/osgPlugins/txp/TXPTileNode.h +++ b/src/osgPlugins/txp/TXPTileNode.h @@ -1,17 +1,17 @@ -/* ************************************************************************** -* December 2003 -* -* This TerraPage loader was re-written in a fashion to use PagedLOD -* to manage paging entirely, also includes a version of Terrex's smart mesh -* adapted to work with PagedLOD. The essential code by Boris Bralo is still present, -* slight modified. -* nick at terrex dot com -* -* Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield +/*************************************************************************** + * December 2003 + * + * This TerraPage loader was re-written in a fashion to use PagedLOD + * to manage paging entirely, also includes a version of Terrex's smart mesh + * adapted to work with PagedLOD. The essential code by Boris Bralo is still present, + * slight modified. + * nick at terrex dot com + * + * Ported to PagedLOD technology by Trajce Nikolov (Nick) & Robert Osfield *****************************************************************************/ -/* ************************************************************************** - * OpenSceneGraph loader for Terrapage format database +/*************************************************************************** + * OpenSceneGraph loader for Terrapage format database * by Boris Bralo 2002 * * based on/modifed sgl (Scene Graph Library) loader by Bryan Walsh @@ -39,29 +39,30 @@ namespace txp { - class TXPArchive; - class TXPTileNode : public osg::Group - { - public: - TXPTileNode(); - - /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ - TXPTileNode(const TXPTileNode&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); +class TXPArchive; +class TXPTileNode : public osg::Group +{ +public: + TXPTileNode(); - META_Node(txp, TXPTileNode); + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ + TXPTileNode(const TXPTileNode&, + const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY); - void setArchive(TXPArchive* archive); - bool loadTile(int x, int y, int lod); + META_Node(txp, TXPTileNode); - osg::Node* seamReplacement(osg::Node* child,int x, int y, int level, TXPArchive::TileInfo& info); + void setArchive(TXPArchive* archive); + bool loadTile(int x, int y, int lod); - protected: - - virtual ~TXPTileNode(); + osg::Node* seamReplacement(osg::Node* child, int x, int y, int level, + TXPArchive::TileInfo& info); - TXPArchive* _archive; - }; +protected: + virtual ~TXPTileNode(); + + TXPArchive* _archive; +}; } // namespace #endif // __TXPTILENODE_H_ diff --git a/src/osgPlugins/txp/TileMapper.h b/src/osgPlugins/txp/TileMapper.h index ced3e92c1..a590e43eb 100644 --- a/src/osgPlugins/txp/TileMapper.h +++ b/src/osgPlugins/txp/TileMapper.h @@ -11,53 +11,62 @@ namespace txp { - class TileMapper : public osg::Referenced +class TileMapper : public osg::Referenced +{ +public: + + static TileMapper* instance(); + + osg::PagedLOD* getPagedLOD(int x, int y, int lod); + + void insertPagedLOD(int x, int y, int lod, osg::PagedLOD* pagedLod); + + void removePagedLOD(int x, int y, int lod); + + void prunePagedLOD(); + +protected: + + // Constructor + TileMapper() + {} + + // Destructor + virtual ~TileMapper() + {} + + struct TileTriple { - public: - - static TileMapper* instance(); - - osg::PagedLOD* getPagedLOD(int x, int y, int lod); - - void insertPagedLOD(int x, int y, int lod, osg::PagedLOD* pagedLod); - - void removePagedLOD(int x, int y, int lod); - - void prunePagedLOD(); - - protected: - - // Constructor - TileMapper() {} - - // Destructor - virtual ~TileMapper() {} - - struct TileTriple + TileTriple(int ax, int ay, int alod): + x(ax),y(ay),lod(alod) + {} + + int x,y,lod; + + bool operator < (const TileTriple& rhs) const { - TileTriple(int ax, int ay, int alod): - x(ax),y(ay),lod(alod) {} - - int x,y,lod; - - bool operator < (const TileTriple& rhs) const - { - if (xrhs.x) return false; - if (yrhs.y) return false; - if (lodrhs.lod) return false; + if (xrhs.x) return false; - } - }; - - typedef std::map< TileTriple, osg::ref_ptr > TileMap; - - OpenThreads::Mutex _mutex; - TileMap _tileMap; - + if (yrhs.y) + return false; + if (lodrhs.lod) + return false; + return false; + } }; + + typedef std::map< TileTriple, osg::ref_ptr > TileMap; + + OpenThreads::Mutex _mutex; + TileMap _tileMap; + +}; } // namespace