| 1 | #include <osgTerrain/TerrainTile> |
|---|
| 2 | |
|---|
| 3 | #include <iostream> |
|---|
| 4 | #include <string> |
|---|
| 5 | |
|---|
| 6 | #include <osg/Vec3> |
|---|
| 7 | #include <osg/Vec4> |
|---|
| 8 | #include <osg/io_utils> |
|---|
| 9 | |
|---|
| 10 | #include <osgDB/ReadFile> |
|---|
| 11 | #include <osgDB/Registry> |
|---|
| 12 | #include <osgDB/Input> |
|---|
| 13 | #include <osgDB/Output> |
|---|
| 14 | #include <osgDB/ParameterOutput> |
|---|
| 15 | |
|---|
| 16 | bool Locator_readLocalData(osg::Object &obj, osgDB::Input &fr); |
|---|
| 17 | bool Locator_writeLocalData(const osg::Object &obj, osgDB::Output &fw); |
|---|
| 18 | |
|---|
| 19 | REGISTER_DOTOSGWRAPPER(Locator_Proxy) |
|---|
| 20 | ( |
|---|
| 21 | new osgTerrain::Locator, |
|---|
| 22 | "Locator", |
|---|
| 23 | "Object Locator", |
|---|
| 24 | Locator_readLocalData, |
|---|
| 25 | Locator_writeLocalData |
|---|
| 26 | ); |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | bool Locator_readLocalData(osg::Object& obj, osgDB::Input &fr) |
|---|
| 30 | { |
|---|
| 31 | osgTerrain::Locator& locator = static_cast<osgTerrain::Locator&>(obj); |
|---|
| 32 | |
|---|
| 33 | bool itrAdvanced = false; |
|---|
| 34 | |
|---|
| 35 | if (fr.matchSequence("Format %w") || fr.matchSequence("Format %s") ) |
|---|
| 36 | { |
|---|
| 37 | locator.setFormat(fr[1].getStr()); |
|---|
| 38 | |
|---|
| 39 | fr += 2; |
|---|
| 40 | itrAdvanced = true; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | if (fr.matchSequence("CoordinateSystemType %w")) |
|---|
| 44 | { |
|---|
| 45 | if (fr[1].matchWord("GEOCENTRIC")) locator.setCoordinateSystemType(osgTerrain::Locator::GEOCENTRIC); |
|---|
| 46 | else if (fr[1].matchWord("GEOGRAPHIC")) locator.setCoordinateSystemType(osgTerrain::Locator::GEOGRAPHIC); |
|---|
| 47 | else locator.setCoordinateSystemType(osgTerrain::Locator::PROJECTED); |
|---|
| 48 | |
|---|
| 49 | fr += 2; |
|---|
| 50 | itrAdvanced = true; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | if (fr.matchSequence("CoordinateSystem %w") || fr.matchSequence("CoordinateSystem %s") ) |
|---|
| 54 | { |
|---|
| 55 | locator.setCoordinateSystem(fr[1].getStr()); |
|---|
| 56 | |
|---|
| 57 | fr += 2; |
|---|
| 58 | itrAdvanced = true; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | if (fr.matchSequence("TransformScaledByResolution %w")) |
|---|
| 62 | { |
|---|
| 63 | locator.setTransformScaledByResolution(fr[1].matchWord("TRUE") || fr[1].matchWord("True") || fr[1].matchWord("true")); |
|---|
| 64 | fr += 2; |
|---|
| 65 | itrAdvanced = true; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | if (fr.matchSequence("Transform {")) |
|---|
| 69 | { |
|---|
| 70 | int tansform_entry = fr[0].getNoNestedBrackets(); |
|---|
| 71 | |
|---|
| 72 | fr += 2; |
|---|
| 73 | |
|---|
| 74 | int row=0; |
|---|
| 75 | int col=0; |
|---|
| 76 | double v; |
|---|
| 77 | osg::Matrixd matrix; |
|---|
| 78 | while (!fr.eof() && fr[0].getNoNestedBrackets()>tansform_entry) |
|---|
| 79 | { |
|---|
| 80 | if (fr[0].getFloat(v)) |
|---|
| 81 | { |
|---|
| 82 | matrix(row,col)=v; |
|---|
| 83 | ++col; |
|---|
| 84 | if (col>=4) |
|---|
| 85 | { |
|---|
| 86 | col = 0; |
|---|
| 87 | ++row; |
|---|
| 88 | } |
|---|
| 89 | ++fr; |
|---|
| 90 | } |
|---|
| 91 | else fr.advanceOverCurrentFieldOrBlock(); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | locator.setTransform(matrix); |
|---|
| 95 | |
|---|
| 96 | ++fr; |
|---|
| 97 | itrAdvanced = true; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | if (fr.matchSequence("Extents %f %f %f %f")) |
|---|
| 102 | { |
|---|
| 103 | double minX,minY,maxX,maxY; |
|---|
| 104 | fr[1].getFloat(minX); |
|---|
| 105 | fr[2].getFloat(minY); |
|---|
| 106 | fr[3].getFloat(maxX); |
|---|
| 107 | fr[4].getFloat(maxY); |
|---|
| 108 | |
|---|
| 109 | locator.setTransformAsExtents(minX, minY, maxX, maxY); |
|---|
| 110 | |
|---|
| 111 | fr += 5; |
|---|
| 112 | itrAdvanced = true; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | return itrAdvanced; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | bool Locator_writeLocalData(const osg::Object& obj, osgDB::Output& fw) |
|---|
| 119 | { |
|---|
| 120 | const osgTerrain::Locator& locator = static_cast<const osgTerrain::Locator&>(obj); |
|---|
| 121 | |
|---|
| 122 | if (!locator.getFormat().empty()) fw.indent()<<"Format "<<fw.wrapString(locator.getFormat())<<std::endl; |
|---|
| 123 | if (!locator.getCoordinateSystem().empty()) fw.indent()<<"CoordinateSystem "<<fw.wrapString(locator.getCoordinateSystem())<<std::endl; |
|---|
| 124 | |
|---|
| 125 | fw.indent()<<"CoordinateSystemType "; |
|---|
| 126 | switch(locator.getCoordinateSystemType()) |
|---|
| 127 | { |
|---|
| 128 | case(osgTerrain::Locator::GEOCENTRIC): |
|---|
| 129 | { |
|---|
| 130 | fw<<"GEOCENTRIC"<<std::endl; |
|---|
| 131 | break; |
|---|
| 132 | } |
|---|
| 133 | case(osgTerrain::Locator::GEOGRAPHIC): |
|---|
| 134 | { |
|---|
| 135 | fw<<"GEOGRAPHIC"<<std::endl; |
|---|
| 136 | break; |
|---|
| 137 | } |
|---|
| 138 | case(osgTerrain::Locator::PROJECTED): |
|---|
| 139 | { |
|---|
| 140 | fw<<"PROJECTED"<<std::endl; |
|---|
| 141 | break; |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | fw.indent()<<"TransformScaledByResolution " << (locator.getTransformScaledByResolution() ? "TRUE":"FALSE") <<std::endl; |
|---|
| 146 | |
|---|
| 147 | const osg::Matrixd& matrix = locator.getTransform(); |
|---|
| 148 | fw.indent() << "Transform {" << std::endl; |
|---|
| 149 | fw.moveIn(); |
|---|
| 150 | fw.indent() << matrix(0,0) << " " << matrix(0,1) << " " << matrix(0,2) << " " << matrix(0,3) << std::endl; |
|---|
| 151 | fw.indent() << matrix(1,0) << " " << matrix(1,1) << " " << matrix(1,2) << " " << matrix(1,3) << std::endl; |
|---|
| 152 | fw.indent() << matrix(2,0) << " " << matrix(2,1) << " " << matrix(2,2) << " " << matrix(2,3) << std::endl; |
|---|
| 153 | fw.indent() << matrix(3,0) << " " << matrix(3,1) << " " << matrix(3,2) << " " << matrix(3,3) << std::endl; |
|---|
| 154 | fw.moveOut(); |
|---|
| 155 | fw.indent() << "}"<< std::endl; |
|---|
| 156 | |
|---|
| 157 | return true; |
|---|
| 158 | } |
|---|