diff --git a/src/osgSim/SphereSegment.cpp b/src/osgSim/SphereSegment.cpp index 79fe37671..b36208c72 100644 --- a/src/osgSim/SphereSegment.cpp +++ b/src/osgSim/SphereSegment.cpp @@ -1345,27 +1345,6 @@ struct TriangleIntersectOperator Edge* _e3; }; - struct Polygon - { - Polygon(Triangle* tri) - { - osg::notify(osg::NOTICE)<<"Polgyon"<_e1) _edges.push_back(tri->_e1); - else osg::notify(osg::NOTICE)<<" Missing edge"<_e2) _edges.push_back(tri->_e2); - else osg::notify(osg::NOTICE)<<" Missing edge"<_e3) _edges.push_back(tri->_e3); - else osg::notify(osg::NOTICE)<<" Missing edge"< - unsigned int computeHitEdges(TriangleIntersectOperator& tio, I intersector, SurfaceType surfaceType); - - bool createLine(TriangleIntersectOperator& tio, SphereSegment::LineList& generatedLines) const; - - EdgeList _edges; - - }; struct Region { @@ -1516,25 +1495,6 @@ struct TriangleIntersectOperator return Region::INTERSECTS; } - Region::Classification overallClassification(SurfaceType surfaceType, SurfaceType assocatedSurfaceType) const - { - // if all vertices are outside any of the surfaces then we are completely outside - if ((assocatedSurfaceType!=RADIUS_SURFACE && surfaceType!=RADIUS_SURFACE && _outside_radiusSurface==_numVertices) || - (assocatedSurfaceType!=LEFT_SURFACE && surfaceType!=LEFT_SURFACE && _outside_leftSurface==_numVertices) || - (assocatedSurfaceType!=RIGHT_SURFACE && surfaceType!=RIGHT_SURFACE && _outside_rightSurface==_numVertices) || - (assocatedSurfaceType!=TOP_SURFACE && surfaceType!=TOP_SURFACE && _outside_topSurface==_numVertices) || - (assocatedSurfaceType!=BOTTOM_SURFACE && surfaceType!=BOTTOM_SURFACE && _outside_bottomSurface==_numVertices)) return Region::OUTSIDE; - - // if all the vertices on all the sides and inside then we are completely inside - if ((assocatedSurfaceType!=RADIUS_SURFACE && surfaceType!=RADIUS_SURFACE && _inside_radiusSurface==_numVertices) && - (assocatedSurfaceType!=LEFT_SURFACE && surfaceType!=LEFT_SURFACE && _inside_leftSurface==_numVertices) && - (assocatedSurfaceType!=RIGHT_SURFACE && surfaceType!=RIGHT_SURFACE && _inside_rightSurface==_numVertices) && - (assocatedSurfaceType!=TOP_SURFACE && surfaceType!=TOP_SURFACE && _inside_topSurface==_numVertices) && - (assocatedSurfaceType!=BOTTOM_SURFACE && surfaceType!=BOTTOM_SURFACE && _inside_bottomSurface==_numVertices)) return Region::INSIDE; - - return Region::INTERSECTS; - } - bool intersecting(SurfaceType surfaceType) const { // if all vertices are outside any of the surfaces then we are completely outside @@ -1779,27 +1739,18 @@ struct TriangleIntersectOperator ++itr) { Triangle* tri = itr->get(); -#if 1 + RegionCounter rc; rc.add(_regions[tri->_p1]); rc.add(_regions[tri->_p2]); rc.add(_regions[tri->_p3]); int numIntersections = rc.numberOfIntersectingSurfaces(); - #if 0 - if (numIntersections==1) - { - buildEdges(tri); - } - #else + if (numIntersections>=1) { buildEdges(tri); } - #endif -#else - buildEdges(tri); -#endif } osg::notify(osg::NOTICE)<<"Number of edges "<<_edges.size()<empty()) return; - osg::notify(osg::NOTICE)<<"Testing line of "<size()<size()<size()) @@ -2014,7 +1963,7 @@ struct TriangleIntersectOperator if (first==sourceLine->size()) { - osg::notify(osg::NOTICE)<<"No valid points found"<size()) { - osg::notify(osg::NOTICE)<<"Copying complete line"<empty()) return; - osg::notify(osg::NOTICE)<<"Testing line of "<size()<size()<size()) @@ -2079,7 +2028,7 @@ struct TriangleIntersectOperator if (first==sourceLine->size()) { - osg::notify(osg::NOTICE)<<"No valid points found"<size()) { - osg::notify(osg::NOTICE)<<"Copying complete line"<=0.0 && (end2<0.0 || end1<=end2)) + + // work out which intersector to use by discounting the one that + // isn't a plausible candiate. + bool possible1 = end1>=0.0; + bool possible2 = end2>=0.0; + if (possible1 && possible2) + { + + double start1 = intersector1.distance(start); + double start2 = intersector2.distance(start); + + // need to check which intersection is latest. + double end1 = intersector1.distance(end); + double delta1 = (end1-start1); + + double end2 = intersector2.distance(end); + double delta2 = (end2-start2); + + double r1 = fabs(delta1)>0.0 ? start1/delta1 : 0.0; + double r2 = fabs(delta2)>0.0 ? start2/delta2 : 0.0; + + // choose intersection which is nearest the end point. + if (r1push_back(intersector1.intersectionPoint(start, end)+_centre); } else { - // end2 must be >= 0.0 therefore use for intersection point newLine->push_back(intersector2.intersectionPoint(start, end)+_centre); - } + } + } for(unsigned int i=first; i=0.0; + bool possible2 = start2>=0.0; + if (possible1 && possible2) + { + double end1 = intersector1.distance(end); + double end2 = intersector2.distance(end); + + possible1 = end1<0.0; + possible2 = end2<0.0; + + if (possible1 && possible2) + { + // need to check which intersection is latest. + double end1 = intersector1.distance(end); + double delta1 = (end1-start1); + + double end2 = intersector2.distance(end); + double delta2 = (end2-start2); + + double r1 = fabs(delta1)>0.0 ? start1/delta1 : 0.0; + double r2 = fabs(delta2)>0.0 ? start2/delta2 : 0.0; + + // choose intersection which is nearest the end point. + if (r1>r2) + { + osg::notify(osg::NOTICE)<<"end point, 1 near to end than 2"<push_back(intersector1.intersectionPoint(start, end)+_centre); } else { newLine->push_back(intersector2.intersectionPoint(start, end)+_centre); - } + } + } lineList.push_back(newLine); @@ -2355,7 +2379,7 @@ struct AzimPlaneIntersector return false; } - osg::notify(osg::NOTICE)<<"r = "<=2) - { - Edge* edge1 = hitEdges.front().get(); hitEdges.pop_front(); - int p1 = tio._originalVertices.size(); - edge1->_intersectionVertexIndex = p1; - tio._originalVertices.push_back(edge1->_intersectionVertex); - tio._regions.push_back(Region()); - tio._regions[p1].classify(edge1->_intersectionVertex, radius2, tio._azMin, tio._azMax, tio._elevMin, tio._elevMax); - - Edge* edge2 = hitEdges.front().get(); hitEdges.pop_front(); - int p2 = tio._originalVertices.size(); - edge2->_intersectionVertexIndex = p2; - tio._originalVertices.push_back(edge2->_intersectionVertex); - tio._regions.push_back(Region()); - tio._regions[p2].classify(edge2->_intersectionVertex, radius2, tio._azMin, tio._azMax, tio._elevMin, tio._elevMax); - - newEdgeList.push_back(new Edge(p1,p2,surfaceType)); - } - - for(EdgeList::iterator itr = _edges.begin(); - itr != _edges.end(); - ++itr) - { - Edge* edge = const_cast(itr->get()); - if (!(edge->completlyOutside())) - { - if (edge->_intersectionType==Edge::NO_INTERSECTION) - { - osg::notify(osg::NOTICE)<<"accept A"<_p1Outside) - { - osg::notify(osg::NOTICE)<<"accept B"<_intersectionVertexIndex, edge->_p1, edge->_intersectionEdge)); - } - else if (!edge->_p2Outside) - { - osg::notify(osg::NOTICE)<<"accept C"<_intersectionVertexIndex, edge->_p2, edge->_intersectionEdge)); - } - else - { - osg::notify(osg::NOTICE)<<"Problem"<>>>>>>>>>>>>>> disgarding Edge. <<<<<<<<<<<<<<<"< > EdgeVector; - EdgeVector edges; - for(EdgeList::const_iterator itr = _edges.begin(); - itr != _edges.end(); - ++itr) - { - -#if 1 - if ((*itr)->_intersectionEdge) - { - edges.push_back(*itr); - } -#else - if ((*itr)->_intersectionEdge) - { - - RegionCounter rc; - rc.add(tio._regions[(*itr)->_p1]); - rc.add(tio._regions[(*itr)->_p2]); - - #if 1 - - Region::Classification classification = rc.overallClassification((*itr)->_intersectionEdge, adjacentEdge[(*itr)->_intersectionEdge]); - -// Region::Classification classification = rc.overallClassification(); - - // reject if outside. - if (classification==Region::OUTSIDE) - { - osg::notify(osg::NOTICE)<<"********************************* disgarding outside edge "<<(*itr)->_p1<<" "<<(*itr)->_p2<_p1<<" "<<(*itr)->_p2<_p1<<" "<<(*itr)->_p2<_intersectionEdge)) - { - osg::notify(osg::NOTICE)<<" accepting edge "<<(*itr)->_p1<<" "<<(*itr)->_p2<_p1<<" "<<(*itr)->_p2<_p1 == edges[j]->_p1) || (edges[i]->_p1 == edges[j]->_p2)) - { - ++numMatchesFor_p1; - } - - if ((edges[i]->_p2 == edges[j]->_p1) || (edges[i]->_p2 == edges[j]->_p2)) - { - ++numMatchesFor_p2; - } - } - if (numMatchesFor_p1==0) break; - if (numMatchesFor_p2==0) break; - } - - // get first edge. - osg::ref_ptr edge = edges[i]; - edges.erase(edges.begin()+i); - - // start a new line, add it to the list of lines. - osg::Vec3Array* newLine = new osg::Vec3Array; - generatedLines.push_back(newLine); - - unsigned int activePoint = 0; - if (numMatchesFor_p1==0) - { - newLine->push_back(tio._originalVertices[edge->_p1]+tio._centre); - newLine->push_back(tio._originalVertices[edge->_p2]+tio._centre); - activePoint = edge->_p2; - } - else - { - newLine->push_back(tio._originalVertices[edge->_p2]+tio._centre); - newLine->push_back(tio._originalVertices[edge->_p1]+tio._centre); - activePoint = edge->_p1; - } - - osg::notify(osg::NOTICE)<<"Start with "<_p1<<" "<_p2<<" activePoint="<_p1 == activePoint) - { - - activePoint = (*itr)->_p2; - newLine->push_back(tio._originalVertices[activePoint]+tio._centre); - - osg::notify(osg::NOTICE)<<"A Found "<<(*itr)->_p1<<" "<<(*itr)->_p2<<" activePoint="<_p2 == activePoint) - { - activePoint = (*itr)->_p1; - newLine->push_back(tio._originalVertices[activePoint]+tio._centre); - osg::notify(osg::NOTICE)<<"B Found "<<(*itr)->_p1<<" "<<(*itr)->_p2<<" activePoint="< edge = edges.front(); - edges.erase(edges.begin()); - - newLine->push_back(tio._originalVertices[edge->_p1]+tio._centre); - newLine->push_back(tio._originalVertices[edge->_p2]+tio._centre); - activePoint = edge->_p2; - - osg::notify(osg::NOTICE)<<"*********** Problem 2 with "<_p1<<" "<_p2<<" activePoint="<get(); - RegionCounter rc; - rc.add(_regions[tri->_p1]); - rc.add(_regions[tri->_p2]); - rc.add(_regions[tri->_p3]); - int numIntersections = rc.numberOfIntersectingSurfaces(); - if (numIntersections==0) ++numZero; - else if (numIntersections==1) ++numOne; - else if (numIntersections==2) ++numTwo; - else if (numIntersections>=3) ++numMore; - - if (numIntersections>=2) - { - buildEdges(tri); - - osg::notify(osg::NOTICE)<<"Testing Polygon with numIntersections = "<0) - { - polygon.createLine(*this, _generatedLines); - } - } - - } - osg::notify(osg::NOTICE)<<" numZero "<getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);