| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | #ifndef __READERWRITER_TXP_H_ |
|---|
| 35 | #define __READERWRITER_TXP_H_ |
|---|
| 36 | |
|---|
| 37 | #include "trpage_sys.h" |
|---|
| 38 | |
|---|
| 39 | #include <osg/Object> |
|---|
| 40 | #include <osg/Node> |
|---|
| 41 | #include <osgDB/Registry> |
|---|
| 42 | #include <osgDB/FileNameUtils> |
|---|
| 43 | #include <osg/Referenced> |
|---|
| 44 | #include <map> |
|---|
| 45 | |
|---|
| 46 | #include <OpenThreads/ScopedLock> |
|---|
| 47 | #include <OpenThreads/ReentrantMutex> |
|---|
| 48 | |
|---|
| 49 | #include "TXPArchive.h" |
|---|
| 50 | |
|---|
| 51 | namespace txp |
|---|
| 52 | { |
|---|
| 53 | class ReaderWriterTXP : public osgDB::ReaderWriter |
|---|
| 54 | { |
|---|
| 55 | public: |
|---|
| 56 | |
|---|
| 57 | ReaderWriterTXP() |
|---|
| 58 | { |
|---|
| 59 | supportsExtension("txp","Terrapage txp format"); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | virtual const char* className() const |
|---|
| 63 | { |
|---|
| 64 | return "TXP Reader/Writer"; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const |
|---|
| 68 | { |
|---|
| 69 | if( !acceptsExtension(osgDB::getFileExtension(file) )) |
|---|
| 70 | return ReadResult::FILE_NOT_HANDLED; |
|---|
| 71 | |
|---|
| 72 | OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex); |
|---|
| 73 | |
|---|
| 74 | return const_cast<ReaderWriterTXP*>(this)->local_readNode(file, options); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | bool removeArchive( int id ); |
|---|
| 78 | |
|---|
| 79 | protected: |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | ReadResult local_readNode(const std::string& file, const osgDB::ReaderWriter::Options* options); |
|---|
| 83 | |
|---|
| 84 | osg::ref_ptr< TXPArchive > getArchive(int id, const std::string&); |
|---|
| 85 | |
|---|
| 86 | osg::Node* getTileContent(const TXPArchive::TileInfo &info, int x, int y, int lod, TXPArchive* archive, std::vector<TXPArchive::TileLocationInfo>& childrenLoc); |
|---|
| 87 | osg::Node* getTileContent(const TXPArchive::TileInfo &info, const TXPArchive::TileLocationInfo& loc, TXPArchive* archive, std::vector<TXPArchive::TileLocationInfo>& childrenLoc); |
|---|
| 88 | void createChildrenLocationString(const std::vector<TXPArchive::TileLocationInfo>& locs, std::string& locString) const; |
|---|
| 89 | bool extractChildrenLocations(const std::string& name, int parentLod, std::vector<TXPArchive::TileLocationInfo>& locs, int nbChild) const; |
|---|
| 90 | |
|---|
| 91 | mutable OpenThreads::ReentrantMutex _serializerMutex; |
|---|
| 92 | |
|---|
| 93 | std::map< int,osg::ref_ptr<TXPArchive> > _archives; |
|---|
| 94 | static int _archiveId; |
|---|
| 95 | }; |
|---|
| 96 | |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | #endif // __READERWRITER_TXP_H_ |
|---|