Changeset 11681 for OpenSceneGraph/trunk/examples/osgtext3D/osgtext3D.cpp
 Timestamp:
 07/20/10 12:46:27 (4 years ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/examples/osgtext3D/osgtext3D.cpp
r11680 r11681 38 38 if (denominator==0.0) 39 39 { 40 OSG_NOTICE<<"computeRayIntersectionPoint()<<denominator==0.0"<<std::endl;40 //OSG_NOTICE<<"computeRayIntersectionPoint()<<denominator==0.0"<<std::endl; 41 41 // line segments must be parallel. 42 42 return (a+c)*0.5; … … 75 75 osg::Vec2 ab(a.x()b.x(), a.y()b.y()); 76 76 osg::Vec2 dc(d.x()c.x(), d.y()c.y()); 77 float length_ab =ab.normalize();78 float length_dc =dc.normalize();77 /*float length_ab =*/ ab.normalize(); 78 /*float length_dc =*/ dc.normalize(); 79 79 80 80 float e = dc.y()  ab.y(); … … 103 103 if (bisector_abcd==bisector_cdef) 104 104 { 105 OSG_NOTICE<<"computeBisectorIntersector(["<<a<<"], ["<<b<<"], ["<<c<<"], ["<<d<<"], ["<<e<<"], ["<<f<<"[)"<<std::endl;106 OSG_NOTICE<<" bisectors parallel, thickness = "<<FLT_MAX<<std::endl;105 //OSG_NOTICE<<"computeBisectorIntersector(["<<a<<"], ["<<b<<"], ["<<c<<"], ["<<d<<"], ["<<e<<"], ["<<f<<"[)"<<std::endl; 106 //OSG_NOTICE<<" bisectors parallel, thickness = "<<FLT_MAX<<std::endl; 107 107 return FLT_MAX; 108 108 } … … 113 113 if (cd_length==0) 114 114 { 115 OSG_NOTICE<<"computeBisectorIntersector(["<<a<<"], ["<<b<<"], ["<<c<<"], ["<<d<<"], ["<<e<<"], ["<<f<<"[)"<<std::endl;116 OSG_NOTICE<<" segment length==0, thickness = "<<FLT_MAX<<std::endl;115 //OSG_NOTICE<<"computeBisectorIntersector(["<<a<<"], ["<<b<<"], ["<<c<<"], ["<<d<<"], ["<<e<<"], ["<<f<<"[)"<<std::endl; 116 //OSG_NOTICE<<" segment length==0, thickness = "<<FLT_MAX<<std::endl; 117 117 return FLT_MAX; 118 118 } … … 142 142 if ((*_vertices)[start]==(*_vertices)[start+count1]) 143 143 { 144 OSG_NOTICE<<"Boundary is a line loop"<<std::endl;144 // OSG_NOTICE<<"Boundary is a line loop"<<std::endl; 145 145 } 146 146 else … … 195 195 void removeAllSegmentsBelowThickness(float targetThickness) 196 196 { 197 OSG_NOTICE<<"removeAllSegmentsBelowThickness("<<targetThickness<<")"<<std::endl;197 // OSG_NOTICE<<"removeAllSegmentsBelowThickness("<<targetThickness<<")"<<std::endl; 198 198 for(;;) 199 199 { … … 202 202 if (!findMinThickness(minThickness_i,minThickness)) break; 203 203 204 OSG_NOTICE<<" removing segment _segments["<<minThickness_i<<"] ("<<_segments[minThickness_i].first<<", "<<_segments[minThickness_i].second<<" with thickness="<<minThickness<<" "<<std::endl;204 // OSG_NOTICE<<" removing segment _segments["<<minThickness_i<<"] ("<<_segments[minThickness_i].first<<", "<<_segments[minThickness_i].second<<" with thickness="<<minThickness<<" "<<std::endl; 205 205 _segments.erase(_segments.begin()+minThickness_i); 206 206 } 207 } 208 209 osg::Vec3 computeBisectorPoint(unsigned int i, float targetThickness) 210 { 211 Segment& seg_before = _segments[ (i+_segments.size()1) % _segments.size() ]; 212 Segment& seg_target = _segments[ (i) % _segments.size() ]; 213 osg::Vec3& a = (*_vertices)[seg_before.first]; 214 osg::Vec3& b = (*_vertices)[seg_before.second]; 215 osg::Vec3& c = (*_vertices)[seg_target.first]; 216 osg::Vec3& d = (*_vertices)[seg_target.second]; 217 osg::Vec3 intersection_abcd = computeIntersectionPoint(a,b,c,d); 218 osg::Vec3 bisector_abcd = computeBisectorNormal(a,b,c,d); 219 osg::Vec3 ab_sidevector(b.y()a.y(), a.x()b.x(), 0.0); 220 ab_sidevector.normalize(); 221 float scale_factor = 1.0/ (bisector_abcd*ab_sidevector); 222 osg::Vec3 new_vertex = intersection_abcd + bisector_abcd*(scale_factor*targetThickness); 223 224 // OSG_NOTICE<<"bisector_abcd = "<<bisector_abcd<<", ab_sidevector="<<ab_sidevector<<", ba="<<ba<<", scale_factor="<<scale_factor<<std::endl; 225 226 new_vertex.z() += 0.5f; 227 return new_vertex; 228 } 229 230 void addBoundaryToGeometry(osg::Geometry* geometry, float targetThickness) 231 { 232 if (_segments.empty()) return; 233 234 if (geometry>getVertexArray()==0) geometry>setVertexArray(new osg::Vec3Array); 235 osg::Vec3Array* new_vertices = dynamic_cast<osg::Vec3Array*>(geometry>getVertexArray()); 236 237 unsigned int first = new_vertices>size(); 238 unsigned int count = 0; 239 240 // reserve enough space in the vertex array to accomodate the vertices associated with the segments 241 // new_vertices>reserve(new_vertices>size()+_segments.size()+1); 242 243 // create vertices 244 unsigned int previous_second = _segments[0].second; 245 osg::Vec3 newPoint = computeBisectorPoint(0, targetThickness); 246 new_vertices>push_back(newPoint); 247 ++count; 248 249 for(unsigned int i=1; i<_segments.size(); ++i) 250 { 251 previous_second = _segments[i].second; 252 newPoint = computeBisectorPoint(i, targetThickness); 253 new_vertices>push_back(newPoint); 254 ++count; 255 } 256 257 // repeat the first point to make it a full closed loop 258 new_vertices>push_back((*new_vertices)[first]); 259 ++count; 260 261 // add DrawArrays primitive set for polygon 262 if (count!=0) geometry>addPrimitiveSet(new osg::DrawArrays(GL_POLYGON, first, count)); 207 263 } 208 264 … … 223 279 void computeBoundaryAngles(osg::Vec3Array& vertices, unsigned int start, unsigned int count) 224 280 { 225 OSG_NOTICE<<"computeBoundaryAngles("<<vertices.size()<<", "<<start<<", "<<count<<")"<<std::endl;281 //OSG_NOTICE<<"computeBoundaryAngles("<<vertices.size()<<", "<<start<<", "<<count<<")"<<std::endl; 226 282 if (vertices[start+count1]==vertices[start]) 227 283 { 228 OSG_NOTICE<<"is a line loop"<<std::endl;284 // OSG_NOTICE<<"is a line loop"<<std::endl; 229 285 } 230 286 else … … 352 408 { 353 409 354 OSG_NOTICE<<"computeBevelEdge("<<orig_vertices.size()<<", "<<start<<", "<<count<<")"<<std::endl;410 // OSG_NOTICE<<"computeBevelEdge("<<orig_vertices.size()<<", "<<start<<", "<<count<<")"<<std::endl; 355 411 if (orig_vertices[start+count1]==orig_vertices[start]) 356 412 { 357 OSG_NOTICE<<"is a line loop"<<std::endl;413 // OSG_NOTICE<<"is a line loop"<<std::endl; 358 414 } 359 415 else … … 379 435 osg::Geometry* computeBevelEdge(osg::Geometry* orig_geometry) 380 436 { 381 OSG_NOTICE<<"computeBoundaryAngles("<<orig_geometry<<")"<<std::endl;437 // OSG_NOTICE<<"computeBoundaryAngles("<<orig_geometry<<")"<<std::endl; 382 438 osg::Vec3Array* orig_vertices = dynamic_cast<osg::Vec3Array*>(orig_geometry>getVertexArray()); 383 439 osg::Geometry::PrimitiveSetList& orig_primitives = orig_geometry>getPrimitiveSetList(); … … 409 465 osg::Geometry* computeThickness(osg::Geometry* orig_geometry, float thickness) 410 466 { 411 OSG_NOTICE<<"computeThickness("<<orig_geometry<<")"<<std::endl;467 // OSG_NOTICE<<"computeThickness("<<orig_geometry<<")"<<std::endl; 412 468 osg::Vec3Array* orig_vertices = dynamic_cast<osg::Vec3Array*>(orig_geometry>getVertexArray()); 413 469 osg::Geometry::PrimitiveSetList& orig_primitives = orig_geometry>getPrimitiveSetList(); 470 471 osg::Geometry* new_geometry = new osg::Geometry; 472 473 osg::Vec4Array* new_colours = new osg::Vec4Array; 474 new_colours>push_back(osg::Vec4(1.0,1.0,0.0,1.0)); 475 new_geometry>setColorArray(new_colours); 476 new_geometry>setColorBinding(osg::Geometry::BIND_OVERALL); 414 477 415 478 for(osg::Geometry::PrimitiveSetList::iterator itr = orig_primitives.begin(); … … 424 487 425 488 boundary.removeAllSegmentsBelowThickness(thickness); 426 }427 }428 return 0;429 } 430 489 boundary.addBoundaryToGeometry(new_geometry, thickness); 490 } 491 } 492 return new_geometry; 493 } 431 494 432 495 int main(int argc, char** argv) … … 447 510 448 511 std::string word("This is a simple test"); 512 513 while(arguments.read("ascii")) 514 { 515 word.clear(); 516 for(unsigned int c=' '; c<=127;++c) 517 { 518 word.push_back(c); 519 } 520 } 521 449 522 while(arguments.read("w",word)) {} 450 523 … … 453 526 OSG_NOTICE<<"Read font "<<fontFile<<" font="<<font.get()<<std::endl; 454 527 528 bool useOldBoundaryCalc = false; 529 while(arguments.read("old")) useOldBoundaryCalc = true; 455 530 456 531 bool useTessellator = false; … … 487 562 geometry>setColorBinding(osg::Geometry::BIND_OVERALL); 488 563 489 // computeBoundaryAngles(geometry); 490 491 osg::Geometry* bevel = computeBevelEdge(geometry); 492 geode>addDrawable(bevel); 493 494 computeThickness(geometry, thickness); 564 osg::Geometry* bevel = 0; 565 if (useOldBoundaryCalc) 566 { 567 bevel = computeBevelEdge(geometry); 568 } 569 else 570 { 571 bevel = computeThickness(geometry, thickness); 572 } 573 574 if (bevel) geode>addDrawable(bevel); 495 575 496 576 if (useTessellator) 497 577 { 498 osgUtil::Tessellator ts; 499 ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); 500 ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); 501 ts.retessellatePolygons(*geometry); 502 503 ts.retessellatePolygons(*bevel); 578 if (geometry) 579 { 580 osgUtil::Tessellator ts; 581 ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); 582 ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); 583 ts.retessellatePolygons(*geometry); 584 } 585 586 if (bevel) 587 { 588 osgUtil::Tessellator ts; 589 ts.setWindingType(osgUtil::Tessellator::TESS_WINDING_POSITIVE); 590 ts.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); 591 ts.retessellatePolygons(*bevel); 592 } 504 593 505 594 }