📄 robustlineintersector.cpp
字号:
if (!ISNAN(p1.z)) { ztot+=p1.z; hits++; } if ( hits ) intPt[0].z = ztot/hits;#endif intPt[1].setCoordinate(p2);#if COMPUTE_Z ztot=0; hits=0; p2z = interpolateZ(p2, q1, q2); if (!ISNAN(p2z)) { ztot+=p2z; hits++; } if (!ISNAN(p2.z)) { ztot+=p2.z; hits++; } if ( hits ) intPt[1].z = ztot/hits;#endif return COLLINEAR; } if (p1q1p2 && q1p1q2) {#if DEBUG cerr<<" p1q1p2 && q1p1q2"<<endl;#endif intPt[0].setCoordinate(q1);#if COMPUTE_Z ztot=0; hits=0; q1z = interpolateZ(q1, p1, p2); if (!ISNAN(q1z)) { ztot+=q1z; hits++; } if (!ISNAN(q1.z)) { ztot+=q1.z; hits++; } if ( hits ) intPt[0].z = ztot/hits;#endif intPt[1].setCoordinate(p1);#if COMPUTE_Z ztot=0; hits=0; p1z = interpolateZ(p1, q1, q2); if (!ISNAN(p1z)) { ztot+=p1z; hits++; } if (!ISNAN(p1.z)) { ztot+=p1.z; hits++; } if ( hits ) intPt[1].z = ztot/hits;#endif#if DEBUG cerr<<" intPt[0]: "<<intPt[0].toString()<<endl; cerr<<" intPt[1]: "<<intPt[1].toString()<<endl;#endif return (q1==p1) && !p1q2p2 && !q1p2q2 ? DO_INTERSECT : COLLINEAR; } if (p1q1p2 && q1p2q2) {#if DEBUG cerr<<" p1q1p2 && q1p2q2"<<endl;#endif intPt[0].setCoordinate(q1);#if COMPUTE_Z ztot=0; hits=0; q1z = interpolateZ(q1, p1, p2); if (!ISNAN(q1z)) { ztot+=q1z; hits++; } if (!ISNAN(q1.z)) { ztot+=q1.z; hits++; } if ( hits ) intPt[0].z = ztot/hits;#endif intPt[1].setCoordinate(p2);#if COMPUTE_Z ztot=0; hits=0; p2z = interpolateZ(p2, q1, q2); if (!ISNAN(p2z)) { ztot+=p2z; hits++; } if (!ISNAN(p2.z)) { ztot+=p2.z; hits++; } if ( hits ) intPt[1].z = ztot/hits;#endif#if DEBUG cerr<<" intPt[0]: "<<intPt[0].toString()<<endl; cerr<<" intPt[1]: "<<intPt[1].toString()<<endl;#endif return (q1==p2) && !p1q2p2 && !q1p1q2 ? DO_INTERSECT : COLLINEAR; } if (p1q2p2 && q1p1q2) {#if DEBUG cerr<<" p1q2p2 && q1p1q2"<<endl;#endif intPt[0].setCoordinate(q2);#if COMPUTE_Z ztot=0; hits=0; q2z = interpolateZ(q2, p1, p2); if (!ISNAN(q2z)) { ztot+=q2z; hits++; } if (!ISNAN(q2.z)) { ztot+=q2.z; hits++; } if ( hits ) intPt[0].z = ztot/hits;#endif intPt[1].setCoordinate(p1);#if COMPUTE_Z ztot=0; hits=0; p1z = interpolateZ(p1, q1, q2); if (!ISNAN(p1z)) { ztot+=p1z; hits++; } if (!ISNAN(p1.z)) { ztot+=p1.z; hits++; } if ( hits ) intPt[1].z = ztot/hits;#endif#if DEBUG cerr<<" intPt[0]: "<<intPt[0].toString()<<endl; cerr<<" intPt[1]: "<<intPt[1].toString()<<endl;#endif return (q2==p1) && !p1q1p2 && !q1p2q2 ? DO_INTERSECT : COLLINEAR; } if (p1q2p2 && q1p2q2) {#if DEBUG cerr<<" p1q2p2 && q1p2q2"<<endl;#endif intPt[0].setCoordinate(q2);#if COMPUTE_Z ztot=0; hits=0; q2z = interpolateZ(q2, p1, p2); if (!ISNAN(q2z)) { ztot+=q2z; hits++; } if (!ISNAN(q2.z)) { ztot+=q2.z; hits++; } if ( hits ) intPt[0].z = ztot/hits;#endif intPt[1].setCoordinate(p2);#if COMPUTE_Z ztot=0; hits=0; p2z = interpolateZ(p2, q1, q2); if (!ISNAN(p2z)) { ztot+=p2z; hits++; } if (!ISNAN(p2.z)) { ztot+=p2.z; hits++; } if ( hits ) intPt[1].z = ztot/hits;#endif#if DEBUG cerr<<" intPt[0]: "<<intPt[0].toString()<<endl; cerr<<" intPt[1]: "<<intPt[1].toString()<<endl;#endif return (q2==p2) && !p1q1p2 && !q1p1q2 ? DO_INTERSECT : COLLINEAR; } return DONT_INTERSECT;}Coordinate*RobustLineIntersector::intersection(const Coordinate& p1,const Coordinate& p2,const Coordinate& q1,const Coordinate& q2) const{ Coordinate n1=p1; Coordinate n2=p2; Coordinate n3=q1; Coordinate n4=q2; Coordinate normPt; //normalize(n1, n2, n3, n4, normPt); normalizeToEnvCentre(n1, n2, n3, n4, normPt); Coordinate *intPt=NULL; try { intPt=HCoordinate::intersection(n1,n2,n3,n4); } catch (NotRepresentableException *e) { delete intPt; Assert::shouldNeverReachHere("Coordinate for intersection is not calculable"+e->toString()); } intPt->x += normPt.x; intPt->y += normPt.y;/** * * MD - May 4 2005 - This is still a problem. Here is a failure case: * * LINESTRING (2089426.5233462777 1180182.3877339689, * 2085646.6891757075 1195618.7333999649) * LINESTRING (1889281.8148903656 1997547.0560044837, * 2259977.3672235999 483675.17050843034) * int point = (2097408.2633752143,1144595.8008114607) */ if (precisionModel!=NULL) precisionModel->makePrecise(intPt);#if COMPUTE_Z double ztot = 0; double zvals = 0; double zp = interpolateZ(*intPt, p1, p2); double zq = interpolateZ(*intPt, q1, q2); if ( !ISNAN(zp)) { ztot += zp; zvals++; } if ( !ISNAN(zq)) { ztot += zq; zvals++; } if ( zvals ) intPt->z = ztot/zvals;#endif // COMPUTE_Z return intPt;}voidRobustLineIntersector::normalize(Coordinate *n1,Coordinate *n2,Coordinate *n3,Coordinate *n4,Coordinate *normPt) const{ normPt->x=smallestInAbsValue(n1->x,n2->x,n3->x,n4->x); normPt->y=smallestInAbsValue(n1->y,n2->y,n3->y,n4->y); n1->x-=normPt->x; n1->y-=normPt->y; n2->x-=normPt->x; n2->y-=normPt->y; n3->x-=normPt->x; n3->y-=normPt->y; n4->x-=normPt->x; n4->y-=normPt->y;#if COMPUTE_Z normPt->z=smallestInAbsValue(n1->z,n2->z,n3->z,n4->z); n1->z-=normPt->z; n2->z-=normPt->z; n3->z-=normPt->z; n4->z-=normPt->z;#endif}doubleRobustLineIntersector::smallestInAbsValue(double x1,double x2,double x3,double x4) const{ double x=x1; double xabs=fabs(x); if(fabs(x2)<xabs) { x=x2; xabs=fabs(x2); } if(fabs(x3)<xabs) { x=x3; xabs=fabs(x3); } if(fabs(x4)<xabs) { x=x4; } return x;}/* * Test whether a point lies in the envelopes of both input segments. * A correctly computed intersection point should return <code>true</code> * for this test. * Since this test is for debugging purposes only, no attempt is * made to optimize the envelope test. * * @return <code>true</code> if the input point lies within both input * segment envelopes */boolRobustLineIntersector::isInSegmentEnvelopes(const Coordinate& intPt){ Envelope *env0=new Envelope(inputLines[0][0], inputLines[0][1]); Envelope *env1=new Envelope(inputLines[1][0], inputLines[1][1]); return env0->contains(intPt) && env1->contains(intPt);}} // namespace geos/********************************************************************** * $Log: RobustLineIntersector.cpp,v $ * Revision 1.29.2.1 2005/05/23 16:39:37 strk * Ported JTS robustness patch for RobustLineIntersector * * Revision 1.29 2004/12/08 13:54:43 strk * gcc warnings checked and fixed, general cleanups. * * Revision 1.28 2004/11/29 16:05:33 strk * Fixed a bug in LineIntersector::interpolateZ causing NaN values * to come out. * Handled dimensional collapses in ElevationMatrix. * Added ISNAN macro and changed ISNAN/FINITE macros to avoid * dispendious isnan() and finite() calls. * * Revision 1.27 2004/11/26 09:53:48 strk * Added more FINITE calls, and added inf and -inf to FINITE checks * * Revision 1.26 2004/11/23 19:53:06 strk * Had LineIntersector compute Z by interpolation. * * Revision 1.25 2004/11/22 13:02:40 strk * Fixed a bug in Collinear intersection Z computation * * Revision 1.24 2004/11/22 11:34:16 strk * Added Z computation for CollinearIntersections * * Revision 1.23 2004/11/20 15:40:49 strk * Added Z computation in point-segment intersection. * * Revision 1.22 2004/11/17 15:09:08 strk * Changed COMPUTE_Z defaults to be more conservative * * Revision 1.21 2004/11/17 08:41:42 strk * Fixed a bug in Z computation and removed debugging output by default. * * Revision 1.20 2004/11/17 08:13:16 strk * Indentation changes. * Some Z_COMPUTATION activated by default. * * Revision 1.19 2004/10/21 22:29:54 strk * Indentation changes and some more COMPUTE_Z rules * * Revision 1.18 2004/10/20 17:32:14 strk * Initial approach to 2.5d intersection() * * Revision 1.17 2004/07/02 13:28:26 strk * Fixed all #include lines to reflect headers layout change. * Added client application build tips in README. * * Revision 1.16 2004/03/25 02:23:55 ybychkov * All "index/" packages upgraded to JTS 1.4 * * Revision 1.15 2004/03/17 02:00:33 ybychkov * "Algorithm" upgraded to JTS 1.4 * * Revision 1.14 2003/11/07 01:23:42 pramsey * Add standard CVS headers licence notices and copyrights to all cpp and h * files. * * **********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -