Changeset 13041 for OpenSceneGraph/trunk/src/osgUtil/MeshOptimizers.cpp
 Timestamp:
 03/21/12 18:36:20 (3 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/src/osgUtil/MeshOptimizers.cpp
r12292 r13041 2 2 * Copyright (C) 2010 Tim Moore 3 3 * 4 * This library is open source and may be redistributed and/or modified under 5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 4 * This library is open source and may be redistributed and/or modified under 5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 6 6 * (at your option) any later version. The full license is in LICENSE file 7 7 * included with this distribution, and on the openscenegraph.org website. 8 * 8 * 9 9 * This library is distributed in the hope that it will be useful, 10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 12 * OpenSceneGraph Public License for more details. 13 13 */ … … 99 99 } 100 100 } 101 101 102 102 ArrayList _arrayList; 103 103 // True if geometry contains bindings that are compatible with … … 114 114 { 115 115 } 116 116 117 117 bool operator() (unsigned int lhs, unsigned int rhs) const 118 118 { … … 126 126 } 127 127 return false; 128 } 128 } 129 129 130 130 int compare(unsigned int lhs, unsigned int rhs) … … 142 142 143 143 protected: 144 VertexAttribComparitor& operator = (const VertexAttribComparitor&) { return *this; } 144 VertexAttribComparitor& operator = (const VertexAttribComparitor&) { return *this; } 145 145 146 146 }; … … 151 151 public: 152 152 RemapArray(const IndexList& remapping):_remapping(remapping) {} 153 153 154 154 const IndexList& _remapping; 155 155 156 156 template<class T> 157 157 inline void remap(T& array) … … 166 166 array.erase(array.begin()+_remapping.size(),array.end()); 167 167 } 168 168 169 169 virtual void apply(osg::Array&) {} 170 170 virtual void apply(osg::ByteArray& array) { remap(array); } … … 180 180 virtual void apply(osg::Vec3Array& array) { remap(array); } 181 181 virtual void apply(osg::Vec4Array& array) { remap(array); } 182 182 183 183 virtual void apply(osg::Vec4ubArray& array) { remap(array); } 184 184 185 virtual void apply(osg::Vec2bArray& array) { remap(array); } 186 virtual void apply(osg::Vec3bArray& array) { remap(array); } 187 virtual void apply(osg::Vec4bArray& array) { remap(array); } 185 virtual void apply(osg::Vec2bArray& array) { remap(array); } 186 virtual void apply(osg::Vec3bArray& array) { remap(array); } 187 virtual void apply(osg::Vec4bArray& array) { remap(array); } 188 188 189 189 virtual void apply(osg::Vec2sArray& array) { remap(array); } … … 194 194 virtual void apply(osg::Vec3dArray& array) { remap(array); } 195 195 virtual void apply(osg::Vec4dArray& array) { remap(array); } 196 196 197 197 virtual void apply(osg::MatrixfArray& array) { remap(array); } 198 198 protected: … … 237 237 if (geom.getColorBinding()==osg::Geometry::BIND_PER_PRIMITIVE  238 238 geom.getColorBinding()==osg::Geometry::BIND_PER_PRIMITIVE_SET) return; 239 239 240 240 if (geom.getSecondaryColorBinding()==osg::Geometry::BIND_PER_PRIMITIVE  241 241 geom.getSecondaryColorBinding()==osg::Geometry::BIND_PER_PRIMITIVE_SET) return; … … 276 276 numNonIndexedPrimitives++; 277 277 } 278 278 279 279 // nothing to index 280 280 if (!numSurfacePrimitives  !numNonIndexedPrimitives) return; … … 290 290 291 291 // compute duplicate vertices 292 292 293 293 typedef std::vector<unsigned int> IndexList; 294 294 unsigned int numVertices = geom.getVertexArray()>getNumElements(); … … 299 299 indices[i] = i; 300 300 } 301 301 302 302 VertexAttribComparitor arrayComparitor(geom); 303 303 std::sort(indices.begin(),indices.end(),arrayComparitor); … … 312 312 ++numUnique; 313 313 } 314 314 315 315 } 316 316 IndexList remapDuplicatesToOrignals(numVertices); … … 333 333 lastUnique = i; 334 334 } 335 335 336 336 } 337 337 unsigned int min_index = indices[lastUnique]; … … 346 346 347 347 348 // copy the arrays. 348 // copy the arrays. 349 349 IndexList finalMapping(numVertices); 350 350 IndexList copyMapping; … … 353 353 for(i=0;i<numVertices;++i) 354 354 { 355 if (remapDuplicatesToOrignals[i]==i) 355 if (remapDuplicatesToOrignals[i]==i) 356 356 { 357 357 finalMapping[i] = currentIndex; … … 360 360 } 361 361 } 362 362 363 363 for(i=0;i<numVertices;++i) 364 364 { 365 if (remapDuplicatesToOrignals[i]!=i) 365 if (remapDuplicatesToOrignals[i]!=i) 366 366 { 367 367 finalMapping[i] = finalMapping[remapDuplicatesToOrignals[i]]; 368 368 } 369 369 } 370 371 370 371 372 372 MyTriangleIndexFunctor taf; 373 373 taf._remapIndices.swap(finalMapping); … … 839 839 assert(triToAdd != 0 && triToAdd>score > 0.0); 840 840 // Add triangle vertices, and remove triangle from the 841 // vertices that use it. 841 // vertices that use it. 842 842 triToAdd>score = 1.0f; 843 843 unsigned triToAddIdx = triToAdd  &triangles[0]; … … 1056 1056 virtual void apply(osg::Vec3Array& array) { remap(array); } 1057 1057 virtual void apply(osg::Vec4Array& array) { remap(array); } 1058 1058 1059 1059 virtual void apply(osg::Vec4ubArray& array) { remap(array); } 1060 1060 1061 virtual void apply(osg::Vec2bArray& array) { remap(array); } 1062 virtual void apply(osg::Vec3bArray& array) { remap(array); } 1063 virtual void apply(osg::Vec4bArray& array) { remap(array); } 1061 virtual void apply(osg::Vec2bArray& array) { remap(array); } 1062 virtual void apply(osg::Vec3bArray& array) { remap(array); } 1063 virtual void apply(osg::Vec4bArray& array) { remap(array); } 1064 1064 1065 1065 virtual void apply(osg::Vec2sArray& array) { remap(array); } … … 1070 1070 virtual void apply(osg::Vec3dArray& array) { remap(array); } 1071 1071 virtual void apply(osg::Vec4dArray& array) { remap(array); } 1072 1072 1073 1073 virtual void apply(osg::MatrixfArray& array) { remap(array); } 1074 1074 }; … … 1082 1082 vector<unsigned> remap; 1083 1083 1084 VertexReorderOperator() : seq(0) 1085 { 1086 } 1087 1084 VertexReorderOperator() : seq(0) 1085 { 1086 } 1087 1088 1088 void inline doVertex(unsigned v) 1089 1089 { … … 1105 1105 remap.resize(numVerts, Remapper::invalidIndex); 1106 1106 } 1107 1107 1108 1108 }; 1109 1109 }