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

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/src/osgUtil/EdgeCollector.cpp
r12292 r13041 1 /* *c++* OpenSceneGraph  Copyright (C) 19982006 Robert Osfield 1 /* *c++* OpenSceneGraph  Copyright (C) 19982006 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 */ … … 32 32 if ((triangle>_e2>_p1==this  triangle>_e2>_p2==this) && triangle>_e2>isBoundaryEdge()) return true; 33 33 if ((triangle>_e3>_p1==this  triangle>_e3>_p2==this) && triangle>_e3>isBoundaryEdge()) return true; 34 34 35 35 //if ((*itr)>isBoundaryTriangle()) return true; 36 36 } … … 47 47 } 48 48 49 50 49 50 51 51 bool EdgeCollector::Edge::operator < ( const Edge& rhs) const 52 52 { 53 53 if (dereference_check_less(_p1,rhs._p1)) return true; 54 54 if (dereference_check_less(rhs._p1,_p1)) return false; 55 55 56 56 return dereference_check_less(_p2,rhs._p2); 57 57 } … … 96 96 _op2 = 0; 97 97 _op3 = 0; 98 98 99 99 _e1 = 0; 100 100 _e2 = 0; … … 108 108 109 109 110 const Point* lhs_lower = dereference_check_less(_p2,_p3) ? _p2.get() : _p3.get(); 111 const Point* rhs_lower = dereference_check_less(rhs._p2,rhs._p3) ? rhs._p2.get() : rhs._p3.get(); 110 const Point* lhs_lower = dereference_check_less(_p2,_p3) ? _p2.get() : _p3.get(); 111 const Point* rhs_lower = dereference_check_less(rhs._p2,rhs._p3) ? rhs._p2.get() : rhs._p3.get(); 112 112 113 113 if (dereference_check_less(lhs_lower,rhs_lower)) return true; 114 114 if (dereference_check_less(rhs_lower,lhs_lower)) return false; 115 115 116 const Point* lhs_upper = dereference_check_less(_p2,_p3) ? _p3.get() : _p2.get(); 117 const Point* rhs_upper = dereference_check_less(rhs._p2,rhs._p3) ? rhs._p3.get() : rhs._p2.get(); 116 const Point* lhs_upper = dereference_check_less(_p2,_p3) ? _p3.get() : _p2.get(); 117 const Point* rhs_upper = dereference_check_less(rhs._p2,rhs._p3) ? rhs._p3.get() : rhs._p2.get(); 118 118 119 119 return dereference_check_less(lhs_upper,rhs_upper); … … 124 124 { 125 125 Point* points[3]; 126 126 127 127 _op1 = points[0] = p1; 128 128 _op2 = points[1] = p2; … … 137 137 _p2 = points[(lowest+1)%3]; 138 138 _p3 = points[(lowest+2)%3]; 139 139 140 140 _plane.set(_op1>_vertex,_op2>_vertex,_op3>_vertex); 141 141 } … … 143 143 144 144 145 145 146 146 osg::UIntArray * EdgeCollector::Edgeloop::toIndexArray() const 147 147 { 148 148 osg::UIntArray * indexArray = new osg::UIntArray; 149 149 150 150 EdgeList::const_iterator it = _edgeList.begin(), end = _edgeList.end(); 151 152 for (;it != end; ++it) 151 152 for (;it != end; ++it) 153 153 indexArray>push_back((*it)>_op1>_index); 154 154 155 155 return indexArray; 156 156 } 157 157 158 158 EdgeCollector::Triangle* EdgeCollector::addTriangle(unsigned int p1, unsigned int p2, unsigned int p3) 159 159 { … … 162 162 // detect if triangle is degenerate. 163 163 if (p1==p2  p2==p3  p1==p3) return 0; 164 if ((_originalPointList[p1]>_vertex == _originalPointList[p2]>_vertex)  164 if ((_originalPointList[p1]>_vertex == _originalPointList[p2]>_vertex)  165 165 (_originalPointList[p2]>_vertex == _originalPointList[p3]>_vertex)  166 166 (_originalPointList[p3]>_vertex == _originalPointList[p1]>_vertex)) return 0; 167 167 168 168 Triangle* triangle = new Triangle; 169 169 170 170 triangle>setOrderedPoints(addPoint(triangle, p1), addPoint(triangle, p2), addPoint(triangle, p3)); 171 171 172 172 triangle>_e1 = addEdge(triangle, triangle>_op1.get(), triangle>_op2.get()); 173 173 triangle>_e2 = addEdge(triangle, triangle>_op2.get(), triangle>_op3.get()); 174 174 triangle>_e3 = addEdge(triangle, triangle>_op3.get(), triangle>_op1.get()); 175 175 176 176 _triangleSet.insert(triangle); 177 177 178 178 return triangle; 179 179 } … … 185 185 // detect if triangle is degenerate. 186 186 if (p1==p2  p2==p3  p1==p3) return 0; 187 if ((p1>_vertex == p2>_vertex)  187 if ((p1>_vertex == p2>_vertex)  188 188 (p2>_vertex == p3>_vertex)  189 189 (p3>_vertex == p1>_vertex)) return 0; 190 190 191 191 Triangle* triangle = new Triangle; 192 192 … … 196 196 triangle>_e2 = addEdge(triangle, triangle>_op2.get(), triangle>_op3.get()); 197 197 triangle>_e3 = addEdge(triangle, triangle>_op3.get(), triangle>_op1.get()); 198 198 199 199 _triangleSet.insert(triangle); 200 200 … … 202 202 } 203 203 204 204 205 205 EdgeCollector::Edge* EdgeCollector::addEdge(Triangle* triangle, Point* p1, Point* p2) 206 206 { … … 208 208 osg::ref_ptr<Edge> edge = new Edge; 209 209 edge>setOrderedPoints(p1,p2); 210 210 211 211 EdgeSet::iterator itr = _edgeSet.find(edge); 212 212 if (itr==_edgeSet.end()) … … 220 220 edge = *itr; 221 221 } 222 222 223 223 edge>addTriangle(triangle); 224 224 225 225 return edge.get(); 226 226 } … … 231 231 EdgeCollector::Point* EdgeCollector::addPoint(Triangle* triangle, Point* point) 232 232 { 233 233 234 234 PointSet::iterator itr = _pointSet.find(point); 235 235 if (itr==_pointSet.end()) … … 245 245 246 246 point>_triangles.insert(triangle); 247 247 248 248 return point; 249 249 } … … 260 260 { 261 261 if (el.empty()) return false; 262 263 262 263 264 264 osg::ref_ptr<Edge> current = el.back(); 265 265 el.pop_back(); 266 266 267 267 // ** init the Edgeloop 268 268 edgeloop._edgeList.push_back(current.get()); 269 270 271 269 270 271 272 272 bool done = false; 273 273 while (!done) … … 286 286 } 287 287 } 288 288 289 289 if (!found) 290 290 { … … 297 297 current = it>get(); 298 298 el.erase(it); 299 299 300 300 if (edgeloop.isClosed()) done = true; 301 301 } … … 309 309 { 310 310 osg::ref_ptr<Edgeloop> edgeloop(new Edgeloop); 311 311 312 312 if (extractBoundaryEdgeloop(el, *edgeloop)) 313 313 edgeloopList.push_back(edgeloop); … … 317 317 return true; 318 318 } 319 320 321 322 323 324 319 320 321 322 323 324 325 325 326 326 struct CollectTriangleOperator … … 330 330 331 331 void setEdgeCollector(EdgeCollector* ec) { _ec = ec; } 332 333 EdgeCollector* _ec; 332 333 EdgeCollector* _ec; 334 334 335 335 // for use in the triangle functor. … … 349 349 CopyVertexArrayToPointsVisitor(EdgeCollector::PointList& pointList): 350 350 _pointList(pointList) {} 351 351 352 352 virtual void apply(osg::Vec2Array& array) 353 353 { 354 354 if (_pointList.size()!=array.size()) return; 355 356 for(unsigned int i=0;i<_pointList.size();++i) 357 { 358 _pointList[i] = new EdgeCollector::Point; 359 _pointList[i]>_index = i; 360 361 osgUtil::ConvertVec<osg::Vec2, osg::Vec3d>::convert(array[i], _pointList[i]>_vertex); 355 356 for(unsigned int i=0;i<_pointList.size();++i) 357 { 358 _pointList[i] = new EdgeCollector::Point; 359 _pointList[i]>_index = i; 360 361 osgUtil::ConvertVec<osg::Vec2, osg::Vec3d>::convert(array[i], _pointList[i]>_vertex); 362 362 } 363 363 } … … 366 366 { 367 367 if (_pointList.size()!=array.size()) return; 368 369 for(unsigned int i=0;i<_pointList.size();++i) 370 { 371 _pointList[i] = new EdgeCollector::Point; 372 _pointList[i]>_index = i; 373 368 369 for(unsigned int i=0;i<_pointList.size();++i) 370 { 371 _pointList[i] = new EdgeCollector::Point; 372 _pointList[i]>_index = i; 373 374 374 _pointList[i]>_vertex = array[i]; 375 375 } 376 376 } 377 377 378 378 virtual void apply(osg::Vec4Array& array) 379 379 { 380 380 if (_pointList.size()!=array.size()) return; 381 382 for(unsigned int i=0;i<_pointList.size();++i) 383 { 384 _pointList[i] = new EdgeCollector::Point; 385 _pointList[i]>_index = i; 386 387 osgUtil::ConvertVec<osg::Vec4, osg::Vec3d>::convert(array[i], _pointList[i]>_vertex); 381 382 for(unsigned int i=0;i<_pointList.size();++i) 383 { 384 _pointList[i] = new EdgeCollector::Point; 385 _pointList[i]>_index = i; 386 387 osgUtil::ConvertVec<osg::Vec4, osg::Vec3d>::convert(array[i], _pointList[i]>_vertex); 388 388 } 389 389 } … … 392 392 { 393 393 if (_pointList.size()!=array.size()) return; 394 395 for(unsigned int i=0;i<_pointList.size();++i) 396 { 397 _pointList[i] = new EdgeCollector::Point; 398 _pointList[i]>_index = i; 399 400 osgUtil::ConvertVec<osg::Vec2d, osg::Vec3d>::convert(array[i], _pointList[i]>_vertex); 401 } 402 } 403 394 395 for(unsigned int i=0;i<_pointList.size();++i) 396 { 397 _pointList[i] = new EdgeCollector::Point; 398 _pointList[i]>_index = i; 399 400 osgUtil::ConvertVec<osg::Vec2d, osg::Vec3d>::convert(array[i], _pointList[i]>_vertex); 401 } 402 } 403 404 404 virtual void apply(osg::Vec3dArray& array) 405 405 { 406 406 if (_pointList.size()!=array.size()) return; 407 408 for(unsigned int i=0;i<_pointList.size();++i) 409 { 410 _pointList[i] = new EdgeCollector::Point; 411 _pointList[i]>_index = i; 412 407 408 for(unsigned int i=0;i<_pointList.size();++i) 409 { 410 _pointList[i] = new EdgeCollector::Point; 411 _pointList[i]>_index = i; 412 413 413 _pointList[i]>_vertex = array[i]; 414 414 } 415 415 } 416 416 417 417 virtual void apply(osg::Vec4dArray& array) 418 418 { 419 419 if (_pointList.size()!=array.size()) return; 420 421 for(unsigned int i=0;i<_pointList.size();++i) 422 { 423 _pointList[i] = new EdgeCollector::Point; 424 _pointList[i]>_index = i; 425 426 osgUtil::ConvertVec<osg::Vec4d, osg::Vec3d>::convert(array[i], _pointList[i]>_vertex); 427 } 428 } 429 420 421 for(unsigned int i=0;i<_pointList.size();++i) 422 { 423 _pointList[i] = new EdgeCollector::Point; 424 _pointList[i]>_index = i; 425 426 osgUtil::ConvertVec<osg::Vec4d, osg::Vec3d>::convert(array[i], _pointList[i]>_vertex); 427 } 428 } 429 430 430 EdgeCollector::PointList& _pointList; 431 431 432 432 protected: 433 433 434 434 CopyVertexArrayToPointsVisitor& operator = (const CopyVertexArrayToPointsVisitor&) { return *this; } 435 435 }; … … 448 448 { 449 449 _geometry = geometry; 450 450 451 451 // check to see if vertex attributes indices exists, if so expand them to remove them 452 452 if (_geometry>suitableForOptimization()) … … 458 458 459 459 unsigned int numVertices = geometry>getVertexArray()>getNumElements(); 460 460 461 461 _originalPointList.resize(numVertices); 462 462 463 463 // copy vertices across to local point list 464 464 CopyVertexArrayToPointsVisitor copyVertexArrayToPoints(_originalPointList); 465 465 _geometry>getVertexArray()>accept(copyVertexArrayToPoints); 466 466 467 467 CollectTriangleIndexFunctor collectTriangles; 468 468 collectTriangles.setEdgeCollector(this); 469 469 470 470 _geometry>accept(collectTriangles); 471 471 } 472 472 473 473 // ** search BoundaryEdgeloop in the geometry, extrude this loop 474 474 // ** and create primitiveSet to link original loop and extruded loop 475 475 void EdgeCollector::getEdgeloopIndexList(IndexArrayList & ial) 476 { 476 { 477 477 // ** collect Boundary Edge 478 478 EdgeList edgeList; 479 479 getBoundaryEdgeList(edgeList); 480 480 481 481 // ** collect Edgeloop 482 482 EdgeloopList edgeloopList; … … 486 486 return; 487 487 } 488 488 489 489 // ** get IndexArray of each Edgeloop 490 490 EdgeloopList::iterator elIt, elEnd = edgeloopList.end();