Changeset 13041 for OpenSceneGraph/trunk/src/osgSim/ElevationSlice.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgSim/ElevationSlice.cpp
r11487 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 */ … … 54 54 55 55 _angleIncrement = 0.005; 56 57 _radiusList.push_back(_startRadius); 56 57 _radiusList.push_back(_startRadius); 58 58 _distanceList.push_back(0.0); 59 59 60 60 osg::Matrixd rotationMatrix; 61 61 double angleBetweenStartEnd = acos( _startNormal * _endNormal ); … … 68 68 rotationMatrix.makeRotate(angle, normal); 69 69 osg::Vec3d newVector = osg::Matrixd::transform3x3(_startPoint, rotationMatrix); 70 70 71 71 _em->convertXYZToLatLongHeight(newVector.x(), newVector.y(), newVector.z(), latitude, longitude, height); 72 72 double newRadius = newVector.length() - height; 73 73 74 74 double distanceIncrement = _angleIncrement * (newRadius + prevRadius) *0.5; 75 75 distance += distanceIncrement; 76 76 77 77 _radiusList.push_back(newRadius); 78 78 _distanceList.push_back(distance); 79 79 80 80 // OSG_NOTICE<<" newVector = "<<newVector<<" newRadius = "<<newRadius<<" distanceIncrement="<<distanceIncrement<<std::endl; 81 81 82 82 prevRadius = newRadius; 83 83 } 84 84 85 85 } 86 87 86 87 88 88 void computeDistanceHeight(const osg::Vec3d& v, double& distance, double& height) const 89 89 { … … 95 95 _em->convertXYZToLatLongHeight(v.x(), v.y(), v.z(), 96 96 latitude, longitude, height); 97 97 98 98 // compute the radius at the point 99 99 double Rv = v.length() - height; … … 101 101 // compute the angle from the _startPoint 102 102 double alpha = acos( vNormal * _startNormal); 103 103 104 104 unsigned int int_alpha = static_cast<unsigned int>(floor(alpha / _angleIncrement)); 105 105 if (int_alpha >= _distanceList.size()) … … 107 107 int_alpha = _distanceList.size() - 1; 108 108 } 109 109 110 110 double prevAlpha = ((double)int_alpha) * _angleIncrement; 111 111 double deltaAlpha = alpha - prevAlpha; 112 112 double prevDistance = _distanceList[int_alpha]; 113 113 double prevRadius = _radiusList[int_alpha]; 114 114 115 115 double averageRadius = (prevRadius + Rv)*0.5; 116 116 double distanceIncrement = deltaAlpha * averageRadius; 117 117 118 118 distance = prevDistance + distanceIncrement; 119 119 120 120 #if 0 121 121 double oldDistance = alpha * (_startRadius + Rv) *0.5; 122 122 123 123 distance = oldDistance; 124 124 … … 141 141 142 142 double _angleIncrement; 143 144 DoubleList _radiusList; 145 DoubleList _distanceList; 143 144 DoubleList _radiusList; 145 DoubleList _distanceList; 146 146 147 147 }; … … 169 169 if (distance < rhs.distance) return true; 170 170 if (distance > rhs.distance) return false; 171 171 172 172 // smallest heights first 173 173 return (height < rhs.height); 174 174 } 175 175 176 176 bool operator == (const DistanceHeightXYZ& rhs) const 177 177 { 178 178 return distance==rhs.distance && height==rhs.height; 179 179 } 180 180 181 181 bool operator != (const DistanceHeightXYZ& rhs) const 182 182 { 183 183 return distance!=rhs.distance || height!=rhs.height; 184 184 } 185 185 186 186 bool equal_distance(const DistanceHeightXYZ& rhs, double epsilon=1e-6) const 187 187 { … … 202 202 //OSG_NOTICE<<"Point::Point distance="<<distance<<" height="<<height<<" position="<<position<<std::endl; 203 203 } 204 204 205 205 Point(const Point& point): 206 206 osg::Referenced(), … … 237 237 return (*_p2 < *rhs._p2); 238 238 } 239 239 240 240 enum Classification 241 241 { … … 248 248 ENCLOSED 249 249 }; 250 250 251 251 Classification compare(const Segment& rhs) const 252 252 { … … 267 267 268 268 if (rhs._p2->distance < _p1->distance || _p2->distance < rhs._p1->distance) return SEPERATE; 269 269 270 270 bool rhs_p1_inside = (_p1->distance <= rhs._p1->distance) && (rhs._p1->distance <= _p2->distance); 271 271 bool rhs_p2_inside = (_p1->distance <= rhs._p2->distance) && (rhs._p2->distance <= _p2->distance); 272 272 273 273 if (rhs_p1_inside && rhs_p2_inside) return ENCLOSING; 274 274 275 275 bool p1_inside = (rhs._p1->distance <= _p1->distance) && (_p1->distance <= rhs._p2->distance); 276 276 bool p2_inside = (rhs._p1->distance <= _p2->distance) && (_p2->distance <= rhs._p2->distance); … … 279 279 280 280 if (rhs_p1_inside || rhs_p2_inside || p1_inside || p2_inside) return OVERLAPPING; 281 281 282 282 return UNCLASSIFIED; 283 283 } 284 284 285 285 double height(double d) const 286 286 { … … 288 288 return _p1->height + ((_p2->height - _p1->height) * (d - _p1->distance) / delta); 289 289 } 290 290 291 291 double deltaHeight(Point& point) const 292 292 { 293 293 return point.height - height(point.distance); 294 294 } 295 295 296 296 Point* createPoint(double d) const 297 297 { 298 298 if (d == _p1->distance) return _p1.get(); 299 299 if (d == _p2->distance) return _p2.get(); 300 300 301 301 double delta = (_p2->distance - _p1->distance); 302 302 double r = (d - _p1->distance)/delta; 303 303 double one_minus_r = 1.0 - r; 304 return new Point(d, 304 return new Point(d, 305 305 _p1->height * one_minus_r + _p2->height * r, 306 306 _p1->position * one_minus_r + _p2->position * r); … … 313 313 double C = _p1->height; 314 314 double D = _p2->height - _p1->height; 315 315 316 316 double E = rhs._p1->distance; 317 317 double F = rhs._p2->distance - rhs._p1->distance; 318 318 double G = rhs._p1->height; 319 319 double H = rhs._p2->height - rhs._p1->height; 320 320 321 321 double div = D*F - B*H; 322 322 if (div==0.0) … … 325 325 return _p2.get(); 326 326 } 327 327 328 328 double r = (G*F - E*H + A*H - C*F) / div; 329 329 330 330 if (r<0.0) 331 331 { … … 333 333 return _p1.get(); 334 334 } 335 335 336 336 if (r>1.0) 337 337 { … … 339 339 return _p2.get(); 340 340 } 341 341 342 342 // OSG_NOTICE<<"ElevationSlideUtils::Segment::createIntersectionPoint(): r="<<r<<std::endl; 343 343 // OSG_NOTICE<<"\tp1 = "<<_p1->distance<<" "<<_p1->height<<" p2 = "<<_p2->distance<<" "<<_p2->height<<std::endl; … … 360 360 361 361 LineConstructor() {} 362 363 364 362 363 364 365 365 void add(double d, double h, const osg::Vec3d& pos) 366 366 { 367 367 osg::ref_ptr<Point> newPoint = new Point(d,h,pos); 368 369 368 369 370 370 if (_previousPoint.valid() && newPoint->distance != _previousPoint->distance) 371 371 { 372 372 const double maxGradient = 100.0; 373 373 double gradient = fabs( (newPoint->height - _previousPoint->height) / (newPoint->distance - _previousPoint->distance) ); 374 374 375 375 if (gradient < maxGradient) 376 376 { … … 378 378 } 379 379 } 380 380 381 381 _previousPoint = newPoint; 382 382 } 383 383 384 384 void endline() 385 385 { 386 386 _previousPoint = 0; 387 387 } 388 388 389 389 void report() 390 390 { 391 391 392 392 OSG_NOTICE<<"Number of segments = "<<_segments.size()<<std::endl; 393 393 394 394 for(SegmentSet::iterator itr = _segments.begin(); 395 395 itr != _segments.end(); … … 415 415 } 416 416 } 417 417 418 418 OSG_NOTICE<<std::endl; 419 419 … … 448 448 } 449 449 } 450 451 } 452 450 451 } 452 453 453 void pruneOverlappingSegments() 454 454 { … … 456 456 SegmentSet::iterator nextItr = prevItr; 457 457 ++nextItr; 458 458 459 459 double epsilon = 0.001; 460 460 461 461 for(SegmentSet::iterator itr = _segments.begin(); 462 462 itr != _segments.end(); … … 490 490 491 491 if (rhs_p1_inside && lhs_p2_inside) 492 { 493 double distance_between = osg::Vec2d(lhs._p2->distance - rhs._p1->distance, 492 { 493 double distance_between = osg::Vec2d(lhs._p2->distance - rhs._p1->distance, 494 494 lhs._p2->height - rhs._p1->height).length2(); 495 495 … … 500 500 Segment newSeg(lhs._p2.get(), rhs._p2.get()); 501 501 _segments.insert(newSeg); 502 502 503 503 _segments.erase(nextItr); 504 504 505 505 nextItr = _segments.find(newSeg); 506 506 } … … 526 526 Segment seg3( cp, lhs._p2.get() ); 527 527 Segment seg4( rhs.createPoint(lhs._p2->distance), lhs._p2.get() ); 528 528 529 529 _segments.erase(nextItr); 530 530 _segments.erase(itr); … … 534 534 _segments.insert(seg3); 535 535 _segments.insert(seg4); 536 536 537 537 itr = _segments.find(seg1); 538 538 nextItr = itr; … … 565 565 // OSG_NOTICE<<" rhs_p1 "<<rhs._p1->distance<<" "<<rhs._p1->height<<std::endl; 566 566 // OSG_NOTICE<<" rhs_p2 "<<rhs._p2->distance<<" "<<rhs._p2->height<<std::endl; 567 568 567 568 569 569 Segment newSeg(lhs._p1.get(), lhs.createPoint(rhs._p1->distance)); 570 570 … … 620 620 else if (dh1>=0.0 && dh2>=0.0) 621 621 { 622 622 623 623 double d_left = enclosed._p1->distance - enclosing._p1->distance; 624 624 double d_right = enclosing._p2->distance - enclosed._p2->distance; … … 626 626 if (d_left < epsilon && d_right < epsilon) 627 627 { 628 // treat ENCLOSED as ENCLOSING. 628 // treat ENCLOSED as ENCLOSING. 629 629 // OSG_NOTICE<<" Treat enclosed above as enclosing "<<std::endl; 630 630 … … 633 633 634 634 _segments.erase(itr); 635 635 636 636 itr = nextItr; 637 637 ++nextItr; … … 641 641 { 642 642 // OSG_NOTICE<<"ENCLOSING: ENCLOSING is below enclosed "<<dh1<<" "<<dh2<<std::endl; 643 // 643 // 644 644 // OSG_NOTICE<<" enclosing_p1 "<<enclosing._p1->distance<<" "<<enclosing._p1->height<<std::endl; 645 645 // OSG_NOTICE<<" enclosing_p2 "<<enclosing._p2->distance<<" "<<enclosing._p2->height<<std::endl; 646 646 // OSG_NOTICE<<" enclosed_p1 "<<enclosed._p1->distance<<" "<<enclosed._p1->height<<std::endl; 647 647 // OSG_NOTICE<<" enclosed_p2 "<<enclosed._p2->distance<<" "<<enclosed._p2->height<<std::endl; 648 // 648 // 649 649 // OSG_NOTICE<<" Replace enclosing with right section"<<std::endl; 650 650 … … 655 655 _segments.erase(itr); 656 656 _segments.insert(newSeg); 657 657 658 658 itr = nextItr; 659 659 ++nextItr; … … 665 665 { 666 666 // OSG_NOTICE<<"ENCLOSING: ENCLOSING is below enclosed "<<dh1<<" "<<dh2<<std::endl; 667 // 667 // 668 668 // OSG_NOTICE<<" enclosing_p1 "<<enclosing._p1->distance<<" "<<enclosing._p1->height<<std::endl; 669 669 // OSG_NOTICE<<" enclosing_p2 "<<enclosing._p2->distance<<" "<<enclosing._p2->height<<std::endl; 670 670 // OSG_NOTICE<<" enclosed_p1 "<<enclosed._p1->distance<<" "<<enclosed._p1->height<<std::endl; 671 671 // OSG_NOTICE<<" enclosed_p2 "<<enclosed._p2->distance<<" "<<enclosed._p2->height<<std::endl; 672 // 672 // 673 673 // OSG_NOTICE<<" Replace enclosing with left section"<<std::endl; 674 674 … … 685 685 // OSG_NOTICE<<" newSeg_p2 "<<newSeg._p2->distance<<" "<<newSeg._p2->height<<std::endl; 686 686 } 687 else 687 else 688 688 { 689 689 // OSG_NOTICE<<"ENCLOSING: ENCLOSING is below enclosed "<<dh1<<" "<<dh2<<std::endl; 690 // 690 // 691 691 // OSG_NOTICE<<" enclosing_p1 "<<enclosing._p1->distance<<" "<<enclosing._p1->height<<std::endl; 692 692 // OSG_NOTICE<<" enclosing_p2 "<<enclosing._p2->distance<<" "<<enclosing._p2->height<<std::endl; 693 693 // OSG_NOTICE<<" enclosed_p1 "<<enclosed._p1->distance<<" "<<enclosed._p1->height<<std::endl; 694 694 // OSG_NOTICE<<" enclosed_p2 "<<enclosed._p2->distance<<" "<<enclosed._p2->height<<std::endl; 695 // 695 // 696 696 // OSG_NOTICE<<" Replace enclosing with left and right sections"<<std::endl; 697 697 … … 703 703 _segments.insert(newSegLeft); 704 704 _segments.insert(newSegRight); 705 705 706 706 itr = _segments.find(newSegLeft); 707 707 nextItr = itr; … … 719 719 { 720 720 // OSG_NOTICE<<"ENCLOSING: ENCLOSING is crossing enclosed "<<dh1<<" "<<dh2<<std::endl; 721 // 721 // 722 722 // OSG_NOTICE<<" enclosing_p1 "<<enclosing._p1->distance<<" "<<enclosing._p1->height<<std::endl; 723 723 // OSG_NOTICE<<" enclosing_p2 "<<enclosing._p2->distance<<" "<<enclosing._p2->height<<std::endl; … … 730 730 if (d_left < epsilon && d_right < epsilon) 731 731 { 732 // treat ENCLOSED as ENCLOSING. 732 // treat ENCLOSED as ENCLOSING. 733 733 if (dh1 < 0.0) 734 734 { 735 735 // OSG_NOTICE<<" >> enclosing left side is above enclosed left side"<<std::endl; 736 736 737 737 Point* cp = enclosing.createIntersectionPoint(enclosed); 738 738 Segment newSegLeft(enclosing._p1.get(), cp); 739 739 Segment newSegRight(cp, enclosed._p2.get()); 740 740 741 741 _segments.erase(itr); 742 742 _segments.erase(nextItr); 743 743 744 744 _segments.insert(newSegLeft); 745 745 _segments.insert(newSegRight); 746 746 747 747 itr = _segments.find(newSegLeft); 748 748 nextItr = itr; 749 749 ++nextItr; 750 750 } 751 else 751 else 752 752 { 753 753 // OSG_NOTICE<<" >> enclosing left side is above enclosed left side"<<std::endl; 754 754 755 755 Point* cp = enclosing.createIntersectionPoint(enclosed); 756 756 Segment newSegLeft(enclosed._p1.get(), cp); 757 757 Segment newSegRight(cp, enclosing._p2.get()); 758 758 759 759 _segments.erase(itr); 760 760 _segments.erase(nextItr); 761 761 762 762 _segments.insert(newSegLeft); 763 763 _segments.insert(newSegRight); 764 764 765 765 itr = _segments.find(newSegLeft); 766 766 nextItr = itr; … … 776 776 { 777 777 // OSG_NOTICE<<" >> enclosing left side is above enclosed left side"<<std::endl; 778 778 779 779 Point* cp = enclosing.createIntersectionPoint(enclosed); 780 780 Segment newSegLeft(enclosing._p1.get(), cp); 781 781 Segment newSegMid(cp, enclosed._p2.get()); 782 782 Segment newSegRight(enclosing.createPoint(enclosed._p2->distance), enclosing._p2.get()); 783 783 784 784 _segments.erase(itr); 785 785 _segments.erase(nextItr); 786 786 787 787 _segments.insert(newSegLeft); 788 788 _segments.insert(newSegMid); 789 789 _segments.insert(newSegRight); 790 790 791 791 itr = _segments.find(newSegLeft); 792 792 nextItr = itr; 793 793 ++nextItr; 794 794 } 795 else 795 else 796 796 { 797 797 // OSG_NOTICE<<" >> enclosing left side is above enclosed left side"<<std::endl; 798 798 799 799 Point* cp = enclosing.createIntersectionPoint(enclosed); 800 800 Segment newSegLeft(enclosed._p1.get(), cp); 801 801 Segment newSegRight(cp, enclosing._p2.get()); 802 802 803 803 _segments.erase(itr); 804 804 _segments.erase(nextItr); 805 805 806 806 _segments.insert(newSegLeft); 807 807 _segments.insert(newSegRight); 808 808 809 809 itr = _segments.find(newSegLeft); 810 810 nextItr = itr; … … 819 819 { 820 820 // OSG_NOTICE<<" >> enclosing left side is above enclosed left side"<<std::endl; 821 821 822 822 Point* cp = enclosing.createIntersectionPoint(enclosed); 823 823 Segment newSegLeft(enclosing._p1.get(), cp); 824 824 Segment newSegRight(cp, enclosed._p2.get()); 825 825 826 826 _segments.erase(itr); 827 827 _segments.erase(nextItr); 828 828 829 829 _segments.insert(newSegLeft); 830 830 _segments.insert(newSegRight); 831 831 832 832 itr = _segments.find(newSegLeft); 833 833 nextItr = itr; 834 834 ++nextItr; 835 835 } 836 else 836 else 837 837 { 838 838 // OSG_NOTICE<<" >> enclosing left side is above enclosed left side"<<std::endl; 839 839 840 840 Point* cp = enclosing.createIntersectionPoint(enclosed); 841 841 Segment newSegLeft(enclosing._p1.get(), enclosing.createPoint(enclosed._p1->distance)); 842 842 Segment newSegMid(enclosed._p1.get(), cp); 843 843 Segment newSegRight(cp, enclosing._p2.get()); 844 844 845 845 _segments.erase(itr); 846 846 _segments.erase(nextItr); 847 847 848 848 _segments.insert(newSegLeft); 849 849 _segments.insert(newSegMid); 850 850 _segments.insert(newSegRight); 851 851 852 852 itr = _segments.find(newSegLeft); 853 853 nextItr = itr; … … 855 855 } 856 856 } 857 else 857 else 858 858 { 859 859 // OSG_NOTICE<<" >> Replace enclosing with left and right sections"<<std::endl; … … 863 863 { 864 864 // OSG_NOTICE<<" >> enclosing left side is above enclosed left side"<<std::endl; 865 865 866 866 Point* cp = enclosing.createIntersectionPoint(enclosed); 867 867 Segment newSegLeft(enclosing._p1.get(), cp); 868 868 Segment newSegMid(cp, enclosed._p2.get()); 869 869 Segment newSegRight(enclosing.createPoint(enclosed._p2->distance), enclosing._p2.get()); 870 870 871 871 _segments.erase(itr); 872 872 _segments.erase(nextItr); 873 873 874 874 _segments.insert(newSegLeft); 875 875 _segments.insert(newSegMid); 876 876 _segments.insert(newSegRight); 877 877 878 878 itr = _segments.find(newSegLeft); 879 879 nextItr = itr; 880 880 ++nextItr; 881 881 } 882 else 882 else 883 883 { 884 884 // OSG_NOTICE<<" >> enclosing left side is above enclosed left side"<<std::endl; 885 885 886 886 Point* cp = enclosing.createIntersectionPoint(enclosed); 887 887 Segment newSegLeft(enclosing._p1.get(), enclosing.createPoint(enclosed._p1->distance)); 888 888 Segment newSegMid(enclosed._p1.get(), cp); 889 889 Segment newSegRight(cp, enclosing._p2.get()); 890 890 891 891 _segments.erase(itr); 892 892 _segments.erase(nextItr); 893 893 894 894 _segments.insert(newSegLeft); 895 895 _segments.insert(newSegMid); 896 896 _segments.insert(newSegRight); 897 897 898 898 itr = _segments.find(newSegLeft); 899 899 nextItr = itr; … … 906 906 { 907 907 OSG_NOTICE<<"ENCLOSING: ENCLOSING - error case "<<dh1<<" "<<dh2<<std::endl; 908 908 909 909 OSG_NOTICE<<" enclosing_p1 "<<enclosing._p1->distance<<" "<<enclosing._p1->height<<std::endl; 910 910 OSG_NOTICE<<" enclosing_p2 "<<enclosing._p2->distance<<" "<<enclosing._p2->height<<std::endl; … … 926 926 double d_left = enclosed._p1->distance - enclosing._p1->distance; 927 927 double d_right = enclosing._p2->distance - enclosed._p2->distance; 928 928 929 929 if (d_left<=epsilon) 930 930 { … … 946 946 // OSG_NOTICE<<" enclosed_p1 "<<enclosed._p1->distance<<" "<<enclosed._p1->height<<std::endl; 947 947 // OSG_NOTICE<<" enclosed_p2 "<<enclosed._p2->distance<<" "<<enclosed._p2->height<<std::endl; 948 948 949 949 _segments.insert(Segment(enclosing.createPoint(enclosed._p2->distance), enclosed._p2.get())); 950 950 _segments.erase(nextItr); … … 960 960 // OSG_NOTICE<<" enclosed_p1 "<<enclosed._p1->distance<<" "<<enclosed._p1->height<<std::endl; 961 961 // OSG_NOTICE<<" enclosed_p2 "<<enclosed._p2->distance<<" "<<enclosed._p2->height<<std::endl; 962 962 963 963 if (d_right<=epsilon) 964 964 { … … 969 969 Segment segLeft(enclosed._p1.get(), cp); 970 970 Segment segRight(cp, enclosing._p2.get()); 971 971 972 972 _segments.erase(itr); 973 973 _segments.erase(nextItr); 974 974 975 975 _segments.insert(segLeft); 976 976 _segments.insert(segRight); 977 977 978 978 itr = _segments.find(segLeft); 979 979 nextItr = itr; … … 985 985 Segment segLeft(enclosing._p1.get(), cp); 986 986 Segment segRight(cp, enclosed._p2.get()); 987 987 988 988 _segments.erase(itr); 989 989 _segments.erase(nextItr); 990 990 991 991 _segments.insert(segLeft); 992 992 _segments.insert(segRight); 993 993 994 994 itr = _segments.find(segLeft); 995 995 nextItr = itr; … … 1005 1005 Segment segLeft(enclosed._p1.get(), cp); 1006 1006 Segment segRight(cp, enclosing._p2.get()); 1007 1007 1008 1008 _segments.erase(itr); 1009 1009 _segments.erase(nextItr); 1010 1010 1011 1011 _segments.insert(segLeft); 1012 1012 _segments.insert(segRight); 1013 1013 1014 1014 itr = _segments.find(segLeft); 1015 1015 nextItr = itr; … … 1022 1022 Segment segMid(cp, enclosed._p2.get()); 1023 1023 Segment segRight(enclosing.createPoint(enclosed._p2->distance), enclosing._p2.get()); 1024 1024 1025 1025 _segments.erase(itr); 1026 1026 _segments.erase(nextItr); 1027 1027 1028 1028 _segments.insert(segLeft); 1029 1029 _segments.insert(segMid); 1030 1030 _segments.insert(segRight); 1031 1031 1032 1032 itr = _segments.find(segLeft); 1033 1033 nextItr = itr; 1034 1034 ++nextItr; 1035 1035 } 1036 } 1036 } 1037 1037 } 1038 1038 else … … 1053 1053 break; 1054 1054 } 1055 default: 1055 default: 1056 1056 OSG_NOTICE<<"** Not handled, advancing"<<std::endl; 1057 1057 ++nextItr; 1058 1058 break; 1059 1059 } 1060 1060 1061 1061 classification = ((itr != _segments.end()) && (nextItr != _segments.end())) ? itr->compare(*nextItr) : Segment::UNCLASSIFIED; 1062 1062 } 1063 1063 } 1064 1064 } 1065 1065 1066 1066 unsigned int numOverlapping(SegmentSet::const_iterator startItr) const 1067 1067 { 1068 1068 if (startItr==_segments.end()) return 0; 1069 1069 1070 1070 SegmentSet::const_iterator nextItr = startItr; 1071 1071 ++nextItr; 1072 1072 1073 1073 unsigned int num = 0; 1074 1074 while (nextItr!=_segments.end() && startItr->compare(*nextItr)>=Segment::OVERLAPPING) … … 1079 1079 return num; 1080 1080 } 1081 1081 1082 1082 unsigned int totalNumOverlapping() const 1083 1083 { … … 1097 1097 SegmentSet::iterator nextItr = prevItr; 1098 1098 ++nextItr; 1099 1099 1100 1100 intersections.push_back( prevItr->_p1->position ); 1101 1101 distanceHeightIntersections.push_back( ElevationSlice::DistanceHeight(prevItr->_p1->distance, prevItr->_p1->height) ); 1102 1102 1103 1103 intersections.push_back( prevItr->_p2->position ); 1104 1104 distanceHeightIntersections.push_back( ElevationSlice::DistanceHeight(prevItr->_p2->distance, prevItr->_p2->height) ); 1105 1105 1106 for(; 1106 for(; 1107 1107 nextItr != _segments.end(); 1108 1108 ++nextItr,++prevItr) … … 1115 1115 intersections.push_back( nextItr->_p1->position ); 1116 1116 distanceHeightIntersections.push_back( ElevationSlice::DistanceHeight(nextItr->_p1->distance, nextItr->_p1->height) ); 1117 1117 1118 1118 intersections.push_back( nextItr->_p2->position ); 1119 1119 distanceHeightIntersections.push_back( ElevationSlice::DistanceHeight(nextItr->_p2->distance, nextItr->_p2->height) ); 1120 1120 break; 1121 1121 } 1122 case(Segment::JOINED): 1122 case(Segment::JOINED): 1123 1123 { 1124 1124 #if 1 1125 1125 intersections.push_back( nextItr->_p2->position ); 1126 1126 distanceHeightIntersections.push_back( ElevationSlice::DistanceHeight(nextItr->_p2->distance, nextItr->_p2->height) ); 1127 #else 1127 #else 1128 1128 intersections.push_back( nextItr->_p1->position ); 1129 1129 distanceHeightIntersections.push_back( ElevationSlice::DistanceHeight(nextItr->_p1->distance, nextItr->_p1->height) ); 1130 1130 1131 1131 intersections.push_back( nextItr->_p2->position ); 1132 1132 distanceHeightIntersections.push_back( ElevationSlice::DistanceHeight(nextItr->_p2->distance, nextItr->_p2->height) ); … … 1134 1134 break; 1135 1135 } 1136 default: 1136 default: 1137 1137 { 1138 1138 intersections.push_back( nextItr->_p1->position ); 1139 1139 distanceHeightIntersections.push_back( ElevationSlice::DistanceHeight(nextItr->_p1->distance, nextItr->_p1->height) ); 1140 1140 1141 1141 intersections.push_back( nextItr->_p2->position ); 1142 1142 distanceHeightIntersections.push_back( ElevationSlice::DistanceHeight(nextItr->_p2->distance, nextItr->_p2->height) ); … … 1144 1144 } 1145 1145 } 1146 1147 } 1148 1149 } 1150 1146 1147 } 1148 1149 } 1150 1151 1151 SegmentSet _segments; 1152 1152 osg::ref_ptr<Point> _previousPoint; 1153 1153 osg::Plane _plane; 1154 1154 osg::ref_ptr<osg::EllipsoidModel> _em; 1155 1155 1156 1156 }; 1157 1157 … … 1189 1189 1190 1190 OSG_NOTICE<<"end_lat = "<<end_latitude<<" end_longitude = "<<end_longitude<<" end_height = "<<end_height<<std::endl; 1191 1191 1192 1192 // set up the main intersection plane 1193 1193 osg::Vec3d planeNormal = (_endPoint - _startPoint) ^ start_upVector; 1194 planeNormal.normalize(); 1194 planeNormal.normalize(); 1195 1195 plane.set( planeNormal, _startPoint ); 1196 1196 1197 1197 // set up the start cut off plane 1198 1198 osg::Vec3d startPlaneNormal = start_upVector ^ planeNormal; 1199 1199 startPlaneNormal.normalize(); 1200 1200 boundingPolytope.add( osg::Plane(startPlaneNormal, _startPoint) ); 1201 1201 1202 1202 // set up the end cut off plane 1203 1203 osg::Vec3d endPlaneNormal = planeNormal ^ end_upVector; … … 1211 1211 // set up the main intersection plane 1212 1212 osg::Vec3d planeNormal = (_endPoint - _startPoint) ^ upVector; 1213 planeNormal.normalize(); 1213 planeNormal.normalize(); 1214 1214 plane.set( planeNormal, _startPoint ); 1215 1215 1216 1216 // set up the start cut off plane 1217 1217 osg::Vec3d startPlaneNormal = upVector ^ planeNormal; 1218 1218 startPlaneNormal.normalize(); 1219 1219 boundingPolytope.add( osg::Plane(startPlaneNormal, _startPoint) ); 1220 1220 1221 1221 // set up the end cut off plane 1222 1222 osg::Vec3d endPlaneNormal = planeNormal ^ upVector; … … 1224 1224 boundingPolytope.add( osg::Plane(endPlaneNormal, _endPoint) ); 1225 1225 } 1226 1226 1227 1227 osg::ref_ptr<osgUtil::PlaneIntersector> intersector = new osgUtil::PlaneIntersector(plane, boundingPolytope); 1228 1228 … … 1234 1234 _intersectionVisitor.setTraversalMask(traversalMask); 1235 1235 _intersectionVisitor.setIntersector( intersector.get() ); 1236 1236 1237 1237 scene->accept(_intersectionVisitor); 1238 1238 1239 1239 osgUtil::PlaneIntersector::Intersections& intersections = intersector->getIntersections(); 1240 1240 … … 1255 1255 { 1256 1256 // OSG_NOTICE<<" transforming "<<std::endl; 1257 // transform points on polyline 1257 // transform points on polyline 1258 1258 for(Polyline::iterator pitr = intersection.polyline.begin(); 1259 1259 pitr != intersection.polyline.end(); … … 1262 1262 *pitr = (*pitr) * (*intersection.matrix); 1263 1263 } 1264 1264 1265 1265 // matrix no longer needed. 1266 1266 intersection.matrix = 0; … … 1270 1270 #if 0 1271 1271 osg::ref_ptr<osg::Geode> geode = new osg::Geode; 1272 1272 1273 1273 for(itr = intersections.begin(); 1274 1274 itr != intersections.end(); … … 1290 1290 geometry->setVertexArray( vertices ); 1291 1291 geometry->addPrimitiveSet( new osg::DrawArrays(GL_LINE_STRIP, 0, vertices->size()) ); 1292 1292 1293 1293 osg::Vec4Array* colours = new osg::Vec4Array; 1294 1294 colours->push_back( osg::Vec4(1.0f,1.0f,1.0f,1.0f) ); 1295 1295 1296 1296 geometry->setColorArray( colours ); 1297 1297 … … 1299 1299 geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); 1300 1300 } 1301 1301 1302 1302 osgDB::writeNodeFile(*geode, "raw.osg"); 1303 1303 #endif … … 1317 1317 { 1318 1318 osgUtil::PlaneIntersector::Intersection& intersection = *itr; 1319 1319 1320 1320 if (intersection.attributes.size()!=intersection.polyline.size()) continue; 1321 1321 1322 1322 Attributes::iterator aitr = intersection.attributes.begin(); 1323 1323 for(Polyline::iterator pitr = intersection.polyline.begin(); … … 1328 1328 double distance, height; 1329 1329 dhc.computeDistanceHeight(v, distance, height); 1330 1330 1331 1331 double pi_height = *aitr; 1332 1332 1333 1333 // OSG_NOTICE<<"computed height = "<<height<<" PI height = "<<pi_height<<std::endl; 1334 1334 … … 1361 1361 constructor.endline(); 1362 1362 } 1363 } 1363 } 1364 1364 1365 1365 // copy final results … … 1374 1374 { 1375 1375 unsigned int previousNumOverlapping = numOverlapping; 1376 1376 1377 1377 constructor.pruneOverlappingSegments(); 1378 1378 // constructor.report(); 1379 1379 1380 1380 numOverlapping = constructor.totalNumOverlapping(); 1381 1381 if (previousNumOverlapping == numOverlapping) break; … … 1383 1383 1384 1384 constructor.copyPoints(_intersections, _distanceHeightIntersections); 1385 1385 1386 1386 #if 0 1387 1387 { … … 1419 1419 OSG_NOTICE<<"No intersections found."<<std::endl; 1420 1420 } 1421 1421 1422 1422 } 1423 1423
