| 1 | #if defined(_MSC_VER) |
|---|
| 2 | #pragma warning( disable : 4786 ) |
|---|
| 3 | #endif |
|---|
| 4 | |
|---|
| 5 | #include "osg/ConvexPlanarOccluder" |
|---|
| 6 | #include "osg/Notify" |
|---|
| 7 | |
|---|
| 8 | #include "osgDB/Registry" |
|---|
| 9 | #include "osgDB/Input" |
|---|
| 10 | #include "osgDB/Output" |
|---|
| 11 | |
|---|
| 12 | using namespace osg; |
|---|
| 13 | using namespace osgDB; |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | bool ConvexPlanarOccluder_readLocalData(Object& obj, Input& fr); |
|---|
| 17 | bool ConvexPlanarOccluder_writeLocalData(const Object& obj, Output& fw); |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | REGISTER_DOTOSGWRAPPER(ConvexPlanarOccluder) |
|---|
| 21 | ( |
|---|
| 22 | new osg::ConvexPlanarOccluder, |
|---|
| 23 | "ConvexPlanarOccluder", |
|---|
| 24 | "Object ConvexPlanarOccluder", |
|---|
| 25 | &ConvexPlanarOccluder_readLocalData, |
|---|
| 26 | &ConvexPlanarOccluder_writeLocalData, |
|---|
| 27 | DotOsgWrapper::READ_AND_WRITE |
|---|
| 28 | ); |
|---|
| 29 | |
|---|
| 30 | bool ConvexPlanarOccluder_readLocalData(Object& obj, Input& fr) |
|---|
| 31 | { |
|---|
| 32 | bool iteratorAdvanced = false; |
|---|
| 33 | |
|---|
| 34 | ConvexPlanarOccluder& cpo = static_cast<ConvexPlanarOccluder&>(obj); |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | bool matchFirst; |
|---|
| 38 | if ((matchFirst=fr.matchSequence("Occluder {")) || fr.matchSequence("Occluder %i {")) |
|---|
| 39 | { |
|---|
| 40 | |
|---|
| 41 | ConvexPlanarPolygon& cpp = cpo.getOccluder(); |
|---|
| 42 | ConvexPlanarPolygon::VertexList& vertexList = cpp.getVertexList(); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | int entry = fr[0].getNoNestedBrackets(); |
|---|
| 46 | |
|---|
| 47 | if (matchFirst) |
|---|
| 48 | { |
|---|
| 49 | fr += 2; |
|---|
| 50 | } |
|---|
| 51 | else |
|---|
| 52 | { |
|---|
| 53 | int capacity; |
|---|
| 54 | fr[1].getInt(capacity); |
|---|
| 55 | |
|---|
| 56 | vertexList.reserve(capacity); |
|---|
| 57 | |
|---|
| 58 | fr += 3; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) |
|---|
| 62 | { |
|---|
| 63 | Vec3 v; |
|---|
| 64 | if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z())) |
|---|
| 65 | { |
|---|
| 66 | fr += 3; |
|---|
| 67 | vertexList.push_back(v); |
|---|
| 68 | } |
|---|
| 69 | else |
|---|
| 70 | { |
|---|
| 71 | ++fr; |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | iteratorAdvanced = true; |
|---|
| 75 | ++fr; |
|---|
| 76 | |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | ConvexPlanarOccluder::HoleList& holeList = cpo.getHoleList(); |
|---|
| 80 | |
|---|
| 81 | while ((matchFirst=fr.matchSequence("Hole {")) || fr.matchSequence("Hole %i {")) |
|---|
| 82 | { |
|---|
| 83 | holeList.push_back(ConvexPlanarPolygon()); |
|---|
| 84 | |
|---|
| 85 | ConvexPlanarPolygon& cpp = holeList.back(); |
|---|
| 86 | ConvexPlanarPolygon::VertexList& vertexList = cpp.getVertexList(); |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | int entry = fr[0].getNoNestedBrackets(); |
|---|
| 90 | |
|---|
| 91 | if (matchFirst) |
|---|
| 92 | { |
|---|
| 93 | fr += 2; |
|---|
| 94 | } |
|---|
| 95 | else |
|---|
| 96 | { |
|---|
| 97 | int capacity; |
|---|
| 98 | fr[1].getInt(capacity); |
|---|
| 99 | |
|---|
| 100 | vertexList.reserve(capacity); |
|---|
| 101 | |
|---|
| 102 | fr += 3; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) |
|---|
| 106 | { |
|---|
| 107 | Vec3 v; |
|---|
| 108 | if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z())) |
|---|
| 109 | { |
|---|
| 110 | fr += 3; |
|---|
| 111 | vertexList.push_back(v); |
|---|
| 112 | } |
|---|
| 113 | else |
|---|
| 114 | { |
|---|
| 115 | ++fr; |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | iteratorAdvanced = true; |
|---|
| 119 | ++fr; |
|---|
| 120 | |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | return iteratorAdvanced; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | bool ConvexPlanarOccluder_writeLocalData(const Object& obj, Output& fw) |
|---|
| 128 | { |
|---|
| 129 | const ConvexPlanarOccluder& cpo = static_cast<const ConvexPlanarOccluder&>(obj); |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | { |
|---|
| 133 | const ConvexPlanarPolygon::VertexList& vertexList = cpo.getOccluder().getVertexList(); |
|---|
| 134 | |
|---|
| 135 | fw.indent() << "Occluder " << vertexList.size()<< "{"<< std::endl; |
|---|
| 136 | fw.moveIn(); |
|---|
| 137 | |
|---|
| 138 | for(ConvexPlanarPolygon::VertexList::const_iterator itr=vertexList.begin(); |
|---|
| 139 | itr!=vertexList.end(); |
|---|
| 140 | ++itr) |
|---|
| 141 | { |
|---|
| 142 | fw.indent() << (*itr)[0] << ' ' << (*itr)[1] << ' ' << (*itr)[2] << std::endl; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | fw.moveOut(); |
|---|
| 146 | fw.indent()<<"}"<< std::endl; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | const ConvexPlanarOccluder::HoleList& holeList = cpo.getHoleList(); |
|---|
| 151 | for(ConvexPlanarOccluder::HoleList::const_iterator holeItr=holeList.begin(); |
|---|
| 152 | holeItr!=holeList.end(); |
|---|
| 153 | ++holeItr) |
|---|
| 154 | { |
|---|
| 155 | const ConvexPlanarPolygon::VertexList& vertexList = holeItr->getVertexList(); |
|---|
| 156 | |
|---|
| 157 | fw.indent() << "Hole " << vertexList.size() << "{"<< std::endl; |
|---|
| 158 | fw.moveIn(); |
|---|
| 159 | |
|---|
| 160 | for(ConvexPlanarPolygon::VertexList::const_iterator itr=vertexList.begin(); |
|---|
| 161 | itr!=vertexList.end(); |
|---|
| 162 | ++itr) |
|---|
| 163 | { |
|---|
| 164 | fw.indent() << (*itr)[0] << ' ' << (*itr)[1] << ' ' << (*itr)[2] << std::endl; |
|---|
| 165 | } |
|---|
| 166 | |
|---|
| 167 | fw.moveOut(); |
|---|
| 168 | fw.indent()<<"}"<< std::endl; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | return true; |
|---|
| 173 | } |
|---|