From 305cc3f88a9120b28345ea9e4077fc27e82dad4c Mon Sep 17 00:00:00 2001 From: gka Date: Fri, 14 Dec 2012 16:38:05 +0400 Subject: [PATCH] 0023587: Operation "2dintersect "in TestHarness can not find intersection point of two intersecting 2d curves. Modified DRAW command "2dintersect" added optional parameter "tolerance for intersection". Test case for bug 0023587 : Check intersections of four 2d curves Adding test cases for this fix Deleting temporary test case --- .../GeomliteTest_API2dCommands.cxx | 37 +++-- src/IntCurve/IntCurve_IntPolyPolyGen.cdl | 22 ++- src/IntCurve/IntCurve_IntPolyPolyGen.gxx | 146 ++++++++++++------ tests/bugs/moddata/bug23587 | 36 +++++ 4 files changed, 176 insertions(+), 65 deletions(-) create mode 100755 tests/bugs/moddata/bug23587 diff --git a/src/GeomliteTest/GeomliteTest_API2dCommands.cxx b/src/GeomliteTest/GeomliteTest_API2dCommands.cxx index 391f6c238e..44ad2eda13 100755 --- a/src/GeomliteTest/GeomliteTest_API2dCommands.cxx +++ b/src/GeomliteTest/GeomliteTest_API2dCommands.cxx @@ -278,12 +278,15 @@ static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const //purpose : //======================================================================= -static Standard_Integer intersect(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a) +static Standard_Integer intersect(Draw_Interpretor& di, Standard_Integer n, const char** a) { if( n < 2) + { + cout<< "2dintersect curve curve [Tol]"< #include #include +#include //====================================================================== @@ -731,11 +732,8 @@ void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1 ,const Standard_Real DeltaU ,const Standard_Real DeltaV) { - gp_Vec2d Tan1,Tan2,Norm1,Norm2; - gp_Pnt2d P1,P2; Standard_Integer nbsamplesOnC1,nbsamplesOnC2; done = Standard_False; - Standard_Boolean AnErrorOccurred = Standard_False; if(NbIter>NBITER_MAX_POLYGON) return; @@ -767,29 +765,30 @@ void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1 } ///////////////////////////////////////////// - IntCurve_ThePolygon2d *PtrPoly1,*PtrPoly2; + + NCollection_Handle aPoly1 ,aPoly2; if(nbsamplesOnC2 > nbsamplesOnC1) { - PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol); - if(PtrPoly1->DeflectionOverEstimation() < TolConf) { - PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol); + aPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol); + if(aPoly1->DeflectionOverEstimation() < TolConf) { + aPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol); } else { - PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol,PtrPoly1->Bounding()); - PtrPoly1->SetDeflectionOverEstimation( PtrPoly2->DeflectionOverEstimation() - +PtrPoly1->DeflectionOverEstimation()); - PtrPoly1->ComputeWithBox(C1,PtrPoly2->Bounding()); + aPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol,aPoly1->Bounding()); + aPoly1->SetDeflectionOverEstimation( aPoly2->DeflectionOverEstimation() + + aPoly1->DeflectionOverEstimation()); + aPoly1->ComputeWithBox(C1,aPoly2->Bounding()); } } else { - PtrPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol); - if(PtrPoly2->DeflectionOverEstimation() < TolConf) { - PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol); + aPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol); + if(aPoly2->DeflectionOverEstimation() < TolConf) { + aPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol); } else { - PtrPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol,PtrPoly2->Bounding()); - PtrPoly2->SetDeflectionOverEstimation( PtrPoly2->DeflectionOverEstimation() - +PtrPoly1->DeflectionOverEstimation()); - PtrPoly2->ComputeWithBox(C2,PtrPoly1->Bounding()); + aPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol,aPoly2->Bounding()); + aPoly2->SetDeflectionOverEstimation( aPoly2->DeflectionOverEstimation() + + aPoly1->DeflectionOverEstimation()); + aPoly2->ComputeWithBox(C2,aPoly1->Bounding()); } } //---------------------------------------------------------------------- @@ -798,13 +797,64 @@ void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1 //-- (Detection des Zones de Tangence) //---------------------------------------------------------------------- - if(PtrPoly1->DeflectionOverEstimation() < TolConf) { - PtrPoly1->SetDeflectionOverEstimation(TolConf); + if(aPoly1->DeflectionOverEstimation() < TolConf) { + aPoly1->SetDeflectionOverEstimation(TolConf); } - if(PtrPoly2->DeflectionOverEstimation() < TolConf) { - PtrPoly2->SetDeflectionOverEstimation(TolConf); + if(aPoly2->DeflectionOverEstimation() < TolConf) { + aPoly2->SetDeflectionOverEstimation(TolConf); + } + //for case when a few polygon points were replaced by line + //if exact solution was not found + //then search of precise solution will be repeat + //for polygon conatins all initial points + //secondary search will be performed only for case when initial points + //were dropped + Standard_Boolean isFullRepresentation = ( aPoly1->NbSegments() == nbsamplesOnC1 && + aPoly2->NbSegments() == nbsamplesOnC2 ); + + if( !findIntersect( C1, D1, C2, D2, TolConf, Tol, NbIter, + DeltaU, DeltaV, *aPoly1, *aPoly2, isFullRepresentation ) && !isFullRepresentation ) + { + if(aPoly1->NbSegments() < nbsamplesOnC1) + { + aPoly1 = new IntCurve_ThePolygon2d(C1,nbsamplesOnC1,D1,Tol); + } + if(aPoly2->NbSegments() < nbsamplesOnC2) + { + aPoly2 = new IntCurve_ThePolygon2d(C2,nbsamplesOnC2,D2,Tol); + } + + findIntersect( C1, D1, C2, D2, TolConf, Tol, NbIter, + DeltaU, DeltaV, *aPoly1, *aPoly2, + Standard_True); + } - Intf_InterferencePolygon2d InterPP(*PtrPoly1,*PtrPoly2); + + done = Standard_True; +} + +//====================================================================== +// Purpose : +//====================================================================== + +Standard_Boolean IntCurve_IntPolyPolyGen::findIntersect( + const TheCurve& C1, + const IntRes2d_Domain& D1, + const TheCurve& C2, + const IntRes2d_Domain& D2, + const Standard_Real TolConf, + const Standard_Real Tol, + const Standard_Integer NbIter, + const Standard_Real DeltaU, + const Standard_Real DeltaV, + const IntCurve_ThePolygon2d& thePoly1, + const IntCurve_ThePolygon2d& thePoly2, + Standard_Boolean isFullPolygon ) +{ + + gp_Vec2d Tan1,Tan2,Norm1,Norm2; + gp_Pnt2d P1,P2; + Intf_InterferencePolygon2d InterPP(thePoly1,thePoly2); IntCurve_ExactIntersectionPoint EIP(C1,C2,TolConf); Standard_Real U,V; @@ -812,19 +862,21 @@ void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1 //-- Traitement des SectionPoint //---------------------------------------------------------------------- Standard_Integer Nbsp = InterPP.NbSectionPoints(); - - if(Nbsp>=1) { - for(Standard_Integer sp=1; sp <= Nbsp; sp++) { - const Intf_SectionPoint& SPnt = InterPP.PntValue(sp); - Standard_Integer SegIndex1,SegIndex2; - Standard_Real ParamOn1,ParamOn2; - Intf_PIType Type; - - SPnt.InfoFirst(Type,SegIndex1,ParamOn1); - SPnt.InfoSecond(Type,SegIndex2,ParamOn2); - EIP.Perform(*PtrPoly1,*PtrPoly2,SegIndex1,SegIndex2,ParamOn1,ParamOn2); - AnErrorOccurred = EIP.AnErrorOccurred(); - if(EIP.NbRoots()>=1) { + + for(Standard_Integer sp=1; sp <= Nbsp; sp++) { + const Intf_SectionPoint& SPnt = InterPP.PntValue(sp); + Standard_Integer SegIndex1,SegIndex2; + Standard_Real ParamOn1,ParamOn2; + Intf_PIType Type; + + SPnt.InfoFirst(Type,SegIndex1,ParamOn1); + SPnt.InfoSecond(Type,SegIndex2,ParamOn2); + EIP.Perform(thePoly1,thePoly2,SegIndex1,SegIndex2,ParamOn1,ParamOn2); + //AnErrorOccurred = EIP.AnErrorOccurred(); + if( !EIP.NbRoots() && !isFullPolygon) + return Standard_False; + + //-------------------------------------------------------------------- //-- On verifie que le point trouve est bien une racine //-------------------------------------------------------------------- @@ -881,11 +933,8 @@ void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1 IntRes2d_IntersectionPoint IP(P1,U,V,Trans1,Trans2,Standard_False); Insert(IP); } - } //-- if(EIP.NbRoots()>=1) - } } - //---------------------------------------------------------------------- //-- Traitement des TangentZone //---------------------------------------------------------------------- @@ -918,14 +967,14 @@ void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1 Standard_Real _PolyUInf,_PolyVInf; SPnt1.InfoFirst(Type,SegIndex1onP1,ParamOnLine); - if(SegIndex1onP1 >= PtrPoly1->NbSegments()) { SegIndex1onP1--; ParamOnLine = 1.0; } + if(SegIndex1onP1 >= thePoly1.NbSegments()) { SegIndex1onP1--; ParamOnLine = 1.0; } if(SegIndex1onP1 <= 0) { SegIndex1onP1=1; ParamOnLine = 0.0; } - _PolyUInf = PtrPoly1->ApproxParamOnCurve(SegIndex1onP1,ParamOnLine); + _PolyUInf = thePoly1.ApproxParamOnCurve(SegIndex1onP1,ParamOnLine); SPnt1.InfoSecond(Type,SegIndex1onP2,ParamOnLine); - if(SegIndex1onP2 >= PtrPoly2->NbSegments()) { SegIndex1onP2--; ParamOnLine = 1.0; } + if(SegIndex1onP2 >= thePoly2.NbSegments()) { SegIndex1onP2--; ParamOnLine = 1.0; } if(SegIndex1onP2 <= 0) { SegIndex1onP2=1; ParamOnLine = 0.0; } - _PolyVInf = PtrPoly2->ApproxParamOnCurve(SegIndex1onP2,ParamOnLine); + _PolyVInf = thePoly2.ApproxParamOnCurve(SegIndex1onP2,ParamOnLine); //---------------------------------------------------------------------- @@ -953,8 +1002,8 @@ void IntCurve_IntPolyPolyGen::Perform( const TheCurve& C1 - if( ( (PtrPoly1->DeflectionOverEstimation() > TolConf) - ||(PtrPoly2->DeflectionOverEstimation() > TolConf)) + if( ( (thePoly1.DeflectionOverEstimation() > TolConf) + ||(thePoly2.DeflectionOverEstimation() > TolConf)) &&(NbIter