Changeset 13041 for OpenSceneGraph/trunk/src/osgSim/SphereSegment.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgSim/SphereSegment.cpp
r12387 r13041 230 230 //getOrCreateStateSet()->setAttributeAndModes(new osg::LineWidth(2.0),osg::StateAttribute::OFF); 231 231 } 232 232 233 233 virtual osg::BoundingBox computeBound() const; 234 234 … … 305 305 _elevMax = elev + elevRange; 306 306 307 // Calculate the azimuth range, cater for trig ambiguities 307 // Calculate the azimuth range, cater for trig ambiguities 308 308 float az = atan2(vec.x(), vec.y()); 309 309 … … 909 909 910 910 const std::type_info& _t; 911 911 912 912 protected: 913 913 … … 931 931 932 932 const std::type_info& _t; 933 933 934 934 protected: 935 935 … … 984 984 { 985 985 public: 986 986 987 987 typedef std::pair<osg::Matrix, osg::Polytope> MatrixPolytopePair; 988 988 typedef std::vector<MatrixPolytopePair> PolytopeStack; 989 989 990 990 struct Hit 991 991 { … … 999 999 osg::ref_ptr<osg::Drawable> _drawable; 1000 1000 }; 1001 1001 1002 1002 typedef std::vector<Hit> HitList; 1003 1003 … … 1010 1010 _polytopeStack.back().second.setAndTransformProvidingInverse(polytope, _polytopeStack.back().first); 1011 1011 } 1012 1012 1013 1013 META_NodeVisitor("osgSim","PolytopeVisitor") 1014 1014 … … 1018 1018 _hits.clear(); 1019 1019 } 1020 1020 1021 1021 void apply(osg::Node& node) 1022 1022 { … … 1035 1035 osg::Matrix matrix = _polytopeStack.back().first; 1036 1036 transform.computeLocalToWorldMatrix(matrix, this); 1037 1037 1038 1038 _polytopeStack.push_back(MatrixPolytopePair()); 1039 1039 _polytopeStack.back().first = matrix; … … 1041 1041 1042 1042 traverse(transform); 1043 1043 1044 1044 _polytopeStack.back(); 1045 1045 } … … 1058 1058 1059 1059 } 1060 1060 1061 1061 traverse(node); 1062 1062 } … … 1066 1066 1067 1067 protected: 1068 1068 1069 1069 PolytopeStack _polytopeStack; 1070 1070 HitList _hits; … … 1076 1076 { 1077 1077 OSG_INFO<<"Creating line intersection between sphere segment and subgraph."<<std::endl; 1078 1078 1079 1079 osg::BoundingBox bb = getBoundingBox(); 1080 1080 1081 1081 osg::Polytope polytope; 1082 polytope.add(osg::Plane(1.0,0.0,0.0,-bb.xMin())); 1083 polytope.add(osg::Plane(-1.0,0.0,0.0,bb.xMax())); 1084 polytope.add(osg::Plane(0.0,1.0,0.0,-bb.yMin())); 1085 polytope.add(osg::Plane(0.0,-1.0,0.0,bb.yMax())); 1086 polytope.add(osg::Plane(0.0,0.0,1.0,-bb.zMin())); 1087 polytope.add(osg::Plane(0.0,0.0,-1.0,bb.zMax())); 1088 1082 polytope.add(osg::Plane(1.0,0.0,0.0,-bb.xMin())); 1083 polytope.add(osg::Plane(-1.0,0.0,0.0,bb.xMax())); 1084 polytope.add(osg::Plane(0.0,1.0,0.0,-bb.yMin())); 1085 polytope.add(osg::Plane(0.0,-1.0,0.0,bb.yMax())); 1086 polytope.add(osg::Plane(0.0,0.0,1.0,-bb.zMin())); 1087 polytope.add(osg::Plane(0.0,0.0,-1.0,bb.zMax())); 1088 1089 1089 osg::Plane pl; 1090 1090 pl.set(osg::Vec3(-1.0,0.0,0.0), bb.corner(0)); 1091 1091 PolytopeVisitor polytopeVisitor(transform, polytope); 1092 1092 1093 1093 subgraph->accept(polytopeVisitor); 1094 1094 … … 1112 1112 all_lines.insert(all_lines.end(), lines.begin(), lines.end()); 1113 1113 } 1114 1114 1115 1115 // join all the lines that have ends that are close together.. 1116 1116 … … 1121 1121 { 1122 1122 OSG_INFO<<"Creating line intersection between sphere segment and subgraph."<<std::endl; 1123 1123 1124 1124 osg::BoundingBox bb = getBoundingBox(); 1125 1125 1126 1126 osg::Polytope polytope; 1127 polytope.add(osg::Plane(1.0,0.0,0.0,-bb.xMin())); 1128 polytope.add(osg::Plane(-1.0,0.0,0.0,bb.xMax())); 1129 polytope.add(osg::Plane(0.0,1.0,0.0,-bb.yMin())); 1130 polytope.add(osg::Plane(0.0,-1.0,0.0,bb.yMax())); 1131 polytope.add(osg::Plane(0.0,0.0,1.0,-bb.zMin())); 1132 polytope.add(osg::Plane(0.0,0.0,-1.0,bb.zMax())); 1133 1127 polytope.add(osg::Plane(1.0,0.0,0.0,-bb.xMin())); 1128 polytope.add(osg::Plane(-1.0,0.0,0.0,bb.xMax())); 1129 polytope.add(osg::Plane(0.0,1.0,0.0,-bb.yMin())); 1130 polytope.add(osg::Plane(0.0,-1.0,0.0,bb.yMax())); 1131 polytope.add(osg::Plane(0.0,0.0,1.0,-bb.zMin())); 1132 polytope.add(osg::Plane(0.0,0.0,-1.0,bb.zMax())); 1133 1134 1134 osg::Plane pl; 1135 1135 pl.set(osg::Vec3(-1.0,0.0,0.0), bb.corner(0)); 1136 1136 PolytopeVisitor polytopeVisitor(transform, polytope); 1137 1137 1138 1138 subgraph->accept(polytopeVisitor); 1139 1139 … … 1156 1156 group->addChild(computeIntersectionSubgraph(itr->_matrix, itr->_drawable.get())); 1157 1157 } 1158 1158 1159 1159 // join all the lines that have ends that are close together.. 1160 1160 … … 1189 1189 1190 1190 protected: 1191 1191 1192 1192 SortFunctor& operator = (const SortFunctor&) { return *this; } 1193 1193 }; … … 1376 1376 1377 1377 double rad2 = vertex.length2(); 1378 double length_xy = sqrtf(vertex.x()*vertex.x() + vertex.y()*vertex.y()); 1378 double length_xy = sqrtf(vertex.x()*vertex.x() + vertex.y()*vertex.y()); 1379 1379 double elevation = atan2((double)vertex.z(),length_xy); 1380 1380 … … 1495 1495 if (_inside_radiusSurface==_numVertices && 1496 1496 _inside_leftRightSurfaces==_numVertices && 1497 _inside_topSurface==_numVertices && 1497 _inside_topSurface==_numVertices && 1498 1498 _inside_bottomSurface==_numVertices) return Region::INSIDE; 1499 1499 … … 1513 1513 if ((surfaceType!=RADIUS_SURFACE && _inside_radiusSurface!=0) && 1514 1514 (surfaceType!=LEFT_SURFACE && _inside_leftSurface!=0) && 1515 (surfaceType!=RIGHT_SURFACE && _inside_rightSurface!=0) && 1516 (surfaceType!=TOP_SURFACE && _inside_topSurface!=0) && 1515 (surfaceType!=RIGHT_SURFACE && _inside_rightSurface!=0) && 1516 (surfaceType!=TOP_SURFACE && _inside_topSurface!=0) && 1517 1517 (surfaceType!=BOTTOM_SURFACE && _inside_bottomSurface!=0)) return false; 1518 1518 … … 1575 1575 1576 1576 osg::Vec3 _centre; 1577 double _radius; 1577 double _radius; 1578 1578 double _azMin, _azMax, _elevMin, _elevMax; 1579 1579 … … 1615 1615 { 1616 1616 ++_numOutside; 1617 return; 1617 return; 1618 1618 } 1619 1619 … … 1790 1790 if (itr==_edges.end()) 1791 1791 { 1792 edge->addTriangle(tri); 1792 edge->addTriangle(tri); 1793 1793 _edges.insert(edge); 1794 1794 return edge.get(); … … 1997 1997 1998 1998 1999 // handle a paired of surfaces that work to enclose a convex region, which means that 1999 // handle a paired of surfaces that work to enclose a convex region, which means that 2000 2000 // points can be inside either surface to be valid, and be outside both surfaces to be invalid. 2001 2001 template<class I> … … 2077 2077 possible2 = false; 2078 2078 } 2079 else 2079 else 2080 2080 { 2081 2081 OSG_INFO<<"start point, 2 near to end than 1"<<std::endl; … … 2140 2140 possible2 = false; 2141 2141 } 2142 else 2142 else 2143 2143 { 2144 2144 OSG_INFO<<"end point, 2 near to end than 1"<<std::endl; … … 2293 2293 _distance = distance; 2294 2294 } 2295 } 2295 } 2296 2296 } 2297 2297 }; … … 2336 2336 while (unfusedLines.size()>=1) 2337 2337 { 2338 // generate a set of line pairs to establish which 2338 // generate a set of line pairs to establish which 2339 2339 // line pair has the minimum distance. 2340 2340 typedef std::multiset<LinePair> LinePairSet; … … 2353 2353 } 2354 2354 } 2355 2355 2356 2356 if (linePairs.empty()) 2357 2357 { … … 2421 2421 // copy across all but fuse end of line1 2422 2422 for(int i=openEnd1; 2423 i != fuseEnd1; 2423 i != fuseEnd1; 2424 2424 i += direction1) 2425 2425 { … … 2442 2442 // copy across from the next point in from fuseEnd2 to the openEnd2. 2443 2443 for(int j=fuseEnd2 + direction2; 2444 j != openEnd2 + direction2; 2444 j != openEnd2 + direction2; 2445 2445 j += direction2) 2446 2446 { … … 2471 2471 _generatedLines.insert(_generatedLines.end(), unfusedLines.begin(), unfusedLines.end()); 2472 2472 2473 } 2473 } 2474 2474 } 2475 2475 … … 2556 2556 2557 2557 double div = d2-d1; 2558 if (div==0.0) 2558 if (div==0.0) 2559 2559 { 2560 2560 edge->_intersectionType = TriangleIntersectOperator::Edge::NO_INTERSECTION; … … 2587 2587 2588 2588 double div = d2-d1; 2589 if (div==0.0) 2589 if (div==0.0) 2590 2590 { 2591 2591 return v1; … … 2603 2603 return _lowerOutside ? _plane.distance(v) : -_plane.distance(v) ; 2604 2604 } 2605 2605 2606 2606 protected: 2607 2607 2608 2608 AzimPlaneIntersector& operator = (const AzimPlaneIntersector&) { return *this; } 2609 2609 }; … … 2744 2744 return _lowerOutside ? computedElev-_elev : _elev-computedElev ; 2745 2745 } 2746 2746 2747 2747 protected: 2748 2748 2749 2749 ElevationIntersector& operator = (const ElevationIntersector&) { return *this; } 2750 2750 … … 2876 2876 2877 2877 protected: 2878 2878 2879 2879 RadiusIntersector& operator = (const RadiusIntersector&) { return *this; } 2880 2880 … … 2889 2889 osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(drawable); 2890 2890 if (!geometry) return SphereSegment::LineList(); 2891 2891 2892 2892 // get vertices from geometry, return empty handed if a Vec3Array not present. 2893 2893 osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray()); 2894 2894 if (!vertices) return SphereSegment::LineList(); 2895 2895 2896 2896 typedef osg::TriangleIndexFunctor<TriangleIntersectOperator> TriangleIntersectFunctor; 2897 2897 TriangleIntersectFunctor tif; 2898 2898 2899 2899 tif._centre = _centre; 2900 2900 tif._radius = _radius; … … 2905 2905 2906 2906 tif.computePositionAndRegions(matrix, *vertices); 2907 2907 2908 2908 // traverse the triangles in the Geometry dedicating intersections 2909 2909 geometry->accept(tif); 2910 2910 2911 2911 OSG_INFO<<"_numOutside = "<<tif._numOutside<<std::endl; 2912 2912 OSG_INFO<<"_numInside = "<<tif._numInside<<std::endl; … … 2916 2916 tif.removeDuplicateTriangles(); 2917 2917 tif.buildEdges(); 2918 2919 2918 2919 2920 2920 RadiusIntersector radiusIntersector(tif); 2921 2921 AzimPlaneIntersector azMinIntersector(tif,_azMin, true); … … 2957 2957 if (azimRange<=osg::PI) 2958 2958 { 2959 // trim the radius and elevation intersection lines by the azimMin 2959 // trim the radius and elevation intersection lines by the azimMin 2960 2960 tif.trim(radiusLines, azMinIntersector); 2961 2961 tif.trim(elevMinLines, azMinIntersector); 2962 2962 tif.trim(elevMaxLines, azMinIntersector); 2963 2963 2964 // trim the radius and elevation intersection lines by the azimMax 2964 // trim the radius and elevation intersection lines by the azimMax 2965 2965 tif.trim(radiusLines, azMaxIntersector); 2966 2966 tif.trim(elevMinLines, azMaxIntersector); … … 2981 2981 tif.trim(elevMaxLines,radiusIntersector); 2982 2982 2983 // trim the radius and elevation intersection lines by the elevMin 2983 // trim the radius and elevation intersection lines by the elevMin 2984 2984 tif.trim(radiusLines, elevMinIntersector); 2985 2985 2986 // trim the radius and elevation intersection lines by the elevMax 2986 // trim the radius and elevation intersection lines by the elevMax 2987 2987 tif.trim(radiusLines, elevMaxIntersector); 2988 2988 … … 2993 2993 tif._generatedLines.insert(tif._generatedLines.end(), elevMinLines.begin(), elevMinLines.end()); 2994 2994 tif._generatedLines.insert(tif._generatedLines.end(), elevMaxLines.begin(), elevMaxLines.end()); 2995 2995 2996 2996 OSG_INFO<<"number of separate lines = "<<tif._generatedLines.size()<<std::endl; 2997 2997 … … 3007 3007 tif.joinEnds(joinDistance, false, true); 3008 3008 OSG_INFO<<"number of separate lines after second join = "<<tif._generatedLines.size()<<std::endl; 3009 3009 3010 3010 return tif._generatedLines; 3011 3011 } … … 3036 3036 { 3037 3037 osg::ShapeDrawable* sd = new osg::ShapeDrawable(new osg::Sphere(tif._originalVertices[i]+tif._centre,radius)); 3038 3038 3039 3039 TriangleIntersectFunctor::RegionCounter rc; 3040 3040 rc.add(tif._regions[i]); … … 3053 3053 sd->setColor(osg::Vec4(1.0,1.0,1.0,1.0)); 3054 3054 } 3055 3055 3056 3056 geode->addDrawable(sd); 3057 3057 }
