| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | #ifndef __TILEMAPPER_H_ |
|---|
| 19 | #define __TILEMAPPER_H_ |
|---|
| 20 | |
|---|
| 21 | #include "trpage_sys.h" |
|---|
| 22 | #include "trpage_read.h" |
|---|
| 23 | |
|---|
| 24 | #include <osg/CullStack> |
|---|
| 25 | #include <osg/NodeVisitor> |
|---|
| 26 | |
|---|
| 27 | #include <set> |
|---|
| 28 | |
|---|
| 29 | namespace txp |
|---|
| 30 | { |
|---|
| 31 | |
|---|
| 32 | struct TileIdentifier : public osg::Referenced |
|---|
| 33 | { |
|---|
| 34 | TileIdentifier(): |
|---|
| 35 | x(-1), |
|---|
| 36 | y(-1), |
|---|
| 37 | lod(-1) |
|---|
| 38 | {} |
|---|
| 39 | |
|---|
| 40 | TileIdentifier(int ax, int ay, int alod): |
|---|
| 41 | x(ax), |
|---|
| 42 | y(ay), |
|---|
| 43 | lod(alod) |
|---|
| 44 | {} |
|---|
| 45 | |
|---|
| 46 | TileIdentifier(const TileIdentifier& rhs): |
|---|
| 47 | osg::Referenced(), |
|---|
| 48 | x(rhs.x), |
|---|
| 49 | y(rhs.y), |
|---|
| 50 | lod(rhs.lod) |
|---|
| 51 | {} |
|---|
| 52 | |
|---|
| 53 | TileIdentifier& operator = (const TileIdentifier& rhs) |
|---|
| 54 | { |
|---|
| 55 | if (this==&rhs) return *this; |
|---|
| 56 | x = rhs.x; |
|---|
| 57 | y = rhs.y; |
|---|
| 58 | lod = rhs.lod; |
|---|
| 59 | return *this; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | void set(int ax, int ay, int alod) |
|---|
| 63 | { |
|---|
| 64 | x = ax; |
|---|
| 65 | y = ay; |
|---|
| 66 | lod = alod; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | bool operator < (const TileIdentifier& rhs) const |
|---|
| 70 | { |
|---|
| 71 | if (lod<rhs.lod) |
|---|
| 72 | return true; |
|---|
| 73 | if (lod>rhs.lod) |
|---|
| 74 | return false; |
|---|
| 75 | if (x<rhs.x) |
|---|
| 76 | return true; |
|---|
| 77 | if (x>rhs.x) |
|---|
| 78 | return false; |
|---|
| 79 | if (y<rhs.y) |
|---|
| 80 | return true; |
|---|
| 81 | if (y>rhs.y) |
|---|
| 82 | return false; |
|---|
| 83 | return false; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | int x,y,lod; |
|---|
| 87 | |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | class TileMapper : public osg::NodeVisitor, public osg::CullStack |
|---|
| 91 | { |
|---|
| 92 | public: |
|---|
| 93 | |
|---|
| 94 | typedef osg::Matrix::value_type value_type; |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | TileMapper(): |
|---|
| 98 | osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN) {} |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | virtual osg::Vec3 getEyePoint() const |
|---|
| 102 | { |
|---|
| 103 | return getEyeLocal(); |
|---|
| 104 | } |
|---|
| 105 | virtual float getDistanceToEyePoint(const osg::Vec3& pos, bool withLODScale) const; |
|---|
| 106 | virtual float getDistanceFromEyePoint(const osg::Vec3& pos, bool withLODScale) const; |
|---|
| 107 | |
|---|
| 108 | virtual void apply(osg::Node& node); |
|---|
| 109 | virtual void apply(osg::Group& node); |
|---|
| 110 | virtual void apply(osg::Geode& node); |
|---|
| 111 | virtual void apply(osg::PagedLOD& node); |
|---|
| 112 | |
|---|
| 113 | void insertTile(const TileIdentifier& tid); |
|---|
| 114 | |
|---|
| 115 | bool isTileNeighbourALowerLODLevel(const TileIdentifier& tid, int dx, int dy) const; |
|---|
| 116 | |
|---|
| 117 | protected: |
|---|
| 118 | |
|---|
| 119 | typedef std::map< TileIdentifier, int> TileMap; |
|---|
| 120 | TileMap _tileMap; |
|---|
| 121 | bool _containsGeode; |
|---|
| 122 | |
|---|
| 123 | }; |
|---|
| 124 | |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | #endif // __TILEMAPPER_H_ |
|---|