Changeset 13041 for OpenSceneGraph/trunk/src/osgUtil/TriStripVisitor.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgUtil/TriStripVisitor.cpp
r12457 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 34 34 public: 35 35 WriteValue(std::ostream& o):_o(o) {} 36 36 37 37 std::ostream& _o; 38 38 39 39 virtual void apply(const GLbyte& v) { _o << v; } 40 40 virtual void apply(const GLshort& v) { _o << v; } … … 50 50 51 51 protected: 52 52 53 53 WriteValue& operator = (const WriteValue&) { return *this; } 54 54 }; … … 74 74 } 75 75 } 76 76 77 77 void add(osg::Array* array, osg::Geometry::AttributeBinding binding) 78 78 { … … 83 83 ++itr) 84 84 { 85 if ((*itr) == array) 85 if ((*itr) == array) 86 86 return; 87 87 } … … 89 89 } 90 90 } 91 91 92 92 typedef std::vector<osg::Array*> ArrayList; 93 93 94 94 ArrayList _arrayList; 95 95 96 96 bool operator() (unsigned int lhs, unsigned int rhs) const 97 97 { … … 105 105 } 106 106 return false; 107 } 107 } 108 108 109 109 int compare(unsigned int lhs, unsigned int rhs) … … 117 117 if (compare==1) return 1; 118 118 } 119 // 119 // 120 120 // WriteValue wv(std::cout); 121 // 121 // 122 122 // std::cout<<"Values equal"<<std::endl; 123 123 // for(ArrayList::iterator itr=_arrayList.begin(); … … 129 129 // std::cout<<std::endl; 130 130 // } 131 131 132 132 133 133 return 0; 134 134 } 135 135 136 136 void accept(osg::ArrayVisitor& av) 137 137 { … … 146 146 protected: 147 147 148 VertexAttribComparitor& operator = (const VertexAttribComparitor&) { return *this; } 148 VertexAttribComparitor& operator = (const VertexAttribComparitor&) { return *this; } 149 149 150 150 }; … … 154 154 public: 155 155 RemapArray(const IndexList& remapping):_remapping(remapping) {} 156 156 157 157 const IndexList& _remapping; 158 158 159 159 template<class T> 160 160 inline void remap(T& array) … … 169 169 array.erase(array.begin()+_remapping.size(),array.end()); 170 170 } 171 171 172 172 virtual void apply(osg::Array&) {} 173 173 virtual void apply(osg::ByteArray& array) { remap(array); } … … 221 221 if (geom.getColorBinding()==osg::Geometry::BIND_PER_PRIMITIVE || 222 222 geom.getColorBinding()==osg::Geometry::BIND_PER_PRIMITIVE_SET) return; 223 223 224 224 if (geom.getSecondaryColorBinding()==osg::Geometry::BIND_PER_PRIMITIVE || 225 225 geom.getSecondaryColorBinding()==osg::Geometry::BIND_PER_PRIMITIVE_SET) return; … … 261 261 ++numNonSurfacePrimitives; 262 262 break; 263 264 } 265 } 266 263 264 } 265 } 266 267 267 // nothitng to tri strip leave. 268 268 if (!numSurfacePrimitives) return; 269 269 270 270 // compute duplicate vertices 271 271 272 272 typedef std::vector<unsigned int> IndexList; 273 273 unsigned int numVertices = geom.getVertexArray()->getNumElements(); … … 278 278 indices[i] = i; 279 279 } 280 280 281 281 VertexAttribComparitor arrayComparitor(geom); 282 282 std::sort(indices.begin(),indices.end(),arrayComparitor); … … 292 292 ++numDuplicate; 293 293 } 294 else 294 else 295 295 { 296 296 //std::cout<<" unique "<<indices[i]<<std::endl; … … 298 298 ++numUnique; 299 299 } 300 300 301 301 } 302 302 // std::cout<<" Number of duplicates "<<numDuplicate<<std::endl; … … 304 304 // std::cout<<" Total number of vertices required "<<numUnique<<" vs original "<<numVertices<<std::endl; 305 305 // std::cout<<" % size "<<(float)numUnique/(float)numVertices*100.0f<<std::endl; 306 306 307 307 IndexList remapDuplicatesToOrignals(numVertices); 308 308 lastUnique = 0; … … 324 324 lastUnique = i; 325 325 } 326 326 327 327 } 328 328 unsigned int min_index = indices[lastUnique]; … … 337 337 338 338 339 // copy the arrays. 339 // copy the arrays. 340 340 IndexList finalMapping(numVertices); 341 341 IndexList copyMapping; … … 344 344 for(i=0;i<numVertices;++i) 345 345 { 346 if (remapDuplicatesToOrignals[i]==i) 346 if (remapDuplicatesToOrignals[i]==i) 347 347 { 348 348 finalMapping[i] = currentIndex; … … 351 351 } 352 352 } 353 353 354 354 for(i=0;i<numVertices;++i) 355 355 { 356 if (remapDuplicatesToOrignals[i]!=i) 356 if (remapDuplicatesToOrignals[i]!=i) 357 357 { 358 358 finalMapping[i] = finalMapping[remapDuplicatesToOrignals[i]]; 359 359 } 360 360 } 361 362 361 362 363 363 MyTriangleIndexFunctor taf; 364 364 taf._remapIndices.swap(finalMapping); … … 387 387 } 388 388 } 389 389 390 390 float minimum_ratio_of_indices_to_unique_vertices = 1; 391 391 float ratio_of_indices_to_unique_vertices = ((float)taf._in_indices.size()/(float)numUnique); … … 393 393 OSG_INFO<<"TriStripVisitor::stripify(Geometry&): Number of indices"<<taf._in_indices.size()<<" numUnique"<< numUnique << std::endl; 394 394 OSG_INFO<<"TriStripVisitor::stripify(Geometry&): ratio indices/numUnique"<< ratio_of_indices_to_unique_vertices << std::endl; 395 395 396 396 // only tri strip if there is point in doing so. 397 397 if (!taf._in_indices.empty() && ratio_of_indices_to_unique_vertices>=minimum_ratio_of_indices_to_unique_vertices) … … 409 409 // so increment to give to the corrent number of verticies. 410 410 ++in_numVertices; 411 411 412 412 // remap any shared vertex attributes 413 413 RemapArray ra(copyMapping); … … 435 435 QuadMap quadMap; 436 436 437 // pick out quads and place them in the quadMap, and also look for the max 437 // pick out quads and place them in the quadMap, and also look for the max 438 438 for(pitr=outPrimitives.begin(); 439 439 pitr!=outPrimitives.end(); … … 455 455 indices.reserve(4*quadMap.size()); 456 456 457 // adds all the quads into the quad primitive, in ascending order 457 // adds all the quads into the quad primitive, in ascending order 458 458 // and the QuadMap stores the quad's in ascending order. 459 459 for(QuadMap::iterator qitr=quadMap.begin(); … … 473 473 indices.push_back(pitr->Indices[(min_pos+2)%4]); 474 474 indices.push_back(pitr->Indices[(min_pos+3)%4]); 475 } 475 } 476 476 477 477 bool inOrder = true; … … 507 507 } 508 508 } 509 } 510 } 511 512 // handle non quad primitives 509 } 510 } 511 512 // handle non quad primitives 513 513 for(pitr=outPrimitives.begin(); 514 514 pitr!=outPrimitives.end(); … … 554 554 geom.setPrimitiveSetList(new_primitives); 555 555 556 #if 0 557 // debugging code for indentifying the tri-strips. 556 #if 0 557 // debugging code for indentifying the tri-strips. 558 558 osg::Vec4Array* colors = new osg::Vec4Array(new_primitives.size()); 559 559 for(i=0;i<colors->size();++i) … … 566 566 geom.setColorArray(colors); 567 567 geom.setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET); 568 #endif 568 #endif 569 569 } 570 570 else … … 582 582 { 583 583 stripify(*(*itr)); 584 584 585 585 // osgUtil::SmoothingVisitor sv; 586 586 // sv.smooth(*(*itr));
