| 1 | // File: IntPatch_PrmPrmIntersection.cxx |
| 2 | // Created: Tue Feb 2 18:05:43 1993 |
| 3 | // Author: Laurent BUCHARD |
| 4 | // Copyright: OPEN CASCADE 1993 |
| 5 | |
| 6 | // modified by Edward AGAPOV (eap) Tue Jan 22 12:29:55 2002 |
| 7 | // modified by Oleg FEDYAED (ofv) Fri Nov 29 16:08:02 2002 |
| 8 | |
| 9 | #include <IntPatch_PrmPrmIntersection.ixx> |
| 10 | |
| 11 | #include <IntPatch_TheInterfPolyhedron.hxx> |
| 12 | #include <IntPatch_ThePWalkingInter.hxx> |
| 13 | #include <IntPatch_WLine.hxx> |
| 14 | #include <IntPatch_RstInt.hxx> |
| 15 | |
| 16 | #include <IntPatch_Line.hxx> |
| 17 | |
| 18 | #include <Handle_IntSurf_LineOn2S.hxx> |
| 19 | #include <IntSurf_PntOn2S.hxx> |
| 20 | #include <IntSurf_LineOn2S.hxx> |
| 21 | #include <TColStd_Array1OfReal.hxx> |
| 22 | #include <Intf_PIType.hxx> |
| 23 | #include <Intf_SectionLine.hxx> |
| 24 | #include <Intf_TangentZone.hxx> |
| 25 | #include <Intf_SectionPoint.hxx> |
| 26 | #include <gp_Pnt.hxx> |
| 27 | #include <gp_Dir.hxx> |
| 28 | #include <IntPolyh_Intersection.hxx> |
| 29 | |
| 30 | #include <TColStd_SequenceOfInteger.hxx> |
| 31 | #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx> |
| 32 | #include <TColStd_HArray1OfReal.hxx> |
| 33 | |
| 34 | static void SectionPointToParameters(const Intf_SectionPoint& Sp, |
| 35 | const IntPatch_Polyhedron& Surf1, |
| 36 | const IntPatch_Polyhedron& Surf2, |
| 37 | Standard_Real& u1, |
| 38 | Standard_Real& v1, |
| 39 | Standard_Real& u2, |
| 40 | Standard_Real& v2); |
| 41 | |
| 42 | |
| 43 | static |
| 44 | void AdjustOnPeriodic(const Handle(Adaptor3d_HSurface)& Surf1, |
| 45 | const Handle(Adaptor3d_HSurface)& Surf2, |
| 46 | IntPatch_SequenceOfLine& aSLin); |
| 47 | |
| 48 | //================================================================================== |
| 49 | // function : |
| 50 | // purpose : |
| 51 | //================================================================================== |
| 52 | IntPatch_PrmPrmIntersection::IntPatch_PrmPrmIntersection(): done(Standard_False) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | //================================================================================== |
| 57 | // function : Perform |
| 58 | // purpose : |
| 59 | //================================================================================== |
| 60 | void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1, |
| 61 | const Handle(Adaptor3d_TopolTool)& D1, |
| 62 | const Standard_Real TolTangency, |
| 63 | const Standard_Real Epsilon, |
| 64 | const Standard_Real Deflection, |
| 65 | const Standard_Real Increment) |
| 66 | { |
| 67 | IntPatch_Polyhedron Poly1( Surf1, D1->NbSamplesU(), D1->NbSamplesV() ); |
| 68 | Perform( Surf1, Poly1, D1, TolTangency, Epsilon, Deflection, Increment ); |
| 69 | } |
| 70 | |
| 71 | //================================================================================== |
| 72 | // function : Perform |
| 73 | // purpose : |
| 74 | //================================================================================== |
| 75 | void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1, |
| 76 | const IntPatch_Polyhedron& Poly1, |
| 77 | const Handle(Adaptor3d_TopolTool)& D1, |
| 78 | const Handle(Adaptor3d_HSurface)& Surf2, |
| 79 | const Handle(Adaptor3d_TopolTool)& D2, |
| 80 | const Standard_Real TolTangency, |
| 81 | const Standard_Real Epsilon, |
| 82 | const Standard_Real Deflection, |
| 83 | const Standard_Real Increment) |
| 84 | { |
| 85 | IntPatch_Polyhedron Poly2( Surf2 ); |
| 86 | Perform( Surf1, Poly1, D1, Surf2, Poly2, D2, TolTangency, Epsilon, Deflection, Increment); |
| 87 | } |
| 88 | |
| 89 | //================================================================================== |
| 90 | // function : Perform |
| 91 | // purpose : |
| 92 | //================================================================================== |
| 93 | void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1, |
| 94 | const Handle(Adaptor3d_TopolTool)& D1, |
| 95 | const Handle(Adaptor3d_HSurface)& Surf2, |
| 96 | const IntPatch_Polyhedron& Poly2, |
| 97 | const Handle(Adaptor3d_TopolTool)& D2, |
| 98 | const Standard_Real TolTangency, |
| 99 | const Standard_Real Epsilon, |
| 100 | const Standard_Real Deflection, |
| 101 | const Standard_Real Increment) |
| 102 | { |
| 103 | IntPatch_Polyhedron Poly1( Surf1 ); |
| 104 | Perform( Surf1, Poly1, D1, Surf2, Poly2, D2, TolTangency, Epsilon, Deflection, Increment ); |
| 105 | } |
| 106 | |
| 107 | //================================================================================== |
| 108 | // function : Perform |
| 109 | // purpose : |
| 110 | //================================================================================== |
| 111 | void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1, |
| 112 | const IntPatch_Polyhedron& Poly1, |
| 113 | const Handle(Adaptor3d_TopolTool)& D1, |
| 114 | const Handle(Adaptor3d_HSurface)& Surf2, |
| 115 | const IntPatch_Polyhedron& Poly2, |
| 116 | const Handle(Adaptor3d_TopolTool)& D2, |
| 117 | const Standard_Real TolTangency, |
| 118 | const Standard_Real Epsilon, |
| 119 | const Standard_Real Deflection, |
| 120 | const Standard_Real Increment) |
| 121 | { |
| 122 | IntPatch_TheInterfPolyhedron Interference(Poly1,Poly2); |
| 123 | empt = Standard_True; |
| 124 | done = Standard_True; |
| 125 | SLin.Clear(); |
| 126 | |
| 127 | Standard_Real Deflection2 = Deflection*Deflection; |
| 128 | Standard_Integer nbLigSec = Interference.NbSectionLines(); |
| 129 | Standard_Integer nbTanZon = Interference.NbTangentZones(); |
| 130 | |
| 131 | Standard_Integer NbPntOn2SOnLine; |
| 132 | Standard_Integer NbLigCalculee = 0; |
| 133 | |
| 134 | Standard_Real U1,U2,V1,V2; |
| 135 | Standard_Real pu1,pu2,pv1,pv2; |
| 136 | |
| 137 | TColStd_Array1OfReal StartParams(1,4); |
| 138 | |
| 139 | IntPatch_ThePWalkingInter PW( Surf1, Surf2, TolTangency, Epsilon, Deflection, Increment ); |
| 140 | |
| 141 | Standard_Real SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant |
| 142 | Standard_Real incidence; |
| 143 | Standard_Real dminiPointLigne; |
| 144 | |
| 145 | Standard_Boolean HasStartPoint,RejetLigne; |
| 146 | |
| 147 | IntSurf_PntOn2S StartPOn2S; |
| 148 | |
| 149 | Standard_Integer ver; |
| 150 | |
| 151 | gp_Pnt Point3dDebut,Point3dFin; |
| 152 | |
| 153 | if( nbLigSec >= 1 ) { |
| 154 | Standard_Integer *TabL = new Standard_Integer [nbLigSec+1]; |
| 155 | Standard_Integer ls; |
| 156 | for( ls = 1; ls <= nbLigSec; ls++ ) |
| 157 | TabL[ls]=ls; |
| 158 | |
| 159 | Standard_Boolean triok; |
| 160 | do { |
| 161 | triok=Standard_True; |
| 162 | for(Standard_Integer b=2; b<=nbLigSec; b++) { |
| 163 | Standard_Integer nb_B = Interference.LineValue(TabL[b]).NumberOfPoints(); |
| 164 | Standard_Integer nb_A = Interference.LineValue(TabL[b-1]).NumberOfPoints(); |
| 165 | if( nb_B > nb_A ) { |
| 166 | Standard_Integer tyu=TabL[b]; |
| 167 | TabL[b]=TabL[b-1]; |
| 168 | TabL[b-1]=tyu; |
| 169 | triok=Standard_False; |
| 170 | } |
| 171 | } |
| 172 | } while( triok==Standard_False ); |
| 173 | |
| 174 | for( ls = 1; ls <= nbLigSec; ls++) { |
| 175 | const Intf_SectionLine& LineSec=Interference.LineValue(TabL[ls]); |
| 176 | Standard_Integer nbp = LineSec.NumberOfPoints(); |
| 177 | |
| 178 | Standard_Integer *TabPtDep = new Standard_Integer [nbp+1]; |
| 179 | Standard_Integer ilig; |
| 180 | for( ilig = 1; ilig <= nbp; ilig++) |
| 181 | TabPtDep[ilig]=0; |
| 182 | |
| 183 | Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1; |
| 184 | Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2; |
| 185 | |
| 186 | SectionPointToParameters(LineSec.GetPoint(1),Poly1,Poly2,UminLig1,VminLig1,UminLig2,VminLig2); |
| 187 | |
| 188 | UmaxLig1=UminLig1; |
| 189 | VmaxLig1=VminLig1; |
| 190 | UmaxLig2=UminLig2; |
| 191 | VmaxLig2=VminLig2; |
| 192 | |
| 193 | for( ilig = 2; ilig <= nbp; ilig++ ) { |
| 194 | SectionPointToParameters(LineSec.GetPoint(ilig),Poly1,Poly2,U1,V1,U2,V2); |
| 195 | |
| 196 | if(U1>UmaxLig1) UmaxLig1=U1; |
| 197 | if(V1>VmaxLig1) VmaxLig1=V1; |
| 198 | if(U2>UmaxLig2) UmaxLig2=U2; |
| 199 | if(V2>VmaxLig2) VmaxLig2=V2; |
| 200 | |
| 201 | if(U1<UminLig1) UminLig1=U1; |
| 202 | if(V1<VminLig1) VminLig1=V1; |
| 203 | if(U2<UminLig2) UminLig2=U2; |
| 204 | if(V2<VminLig2) VminLig2=V2; |
| 205 | } |
| 206 | |
| 207 | Standard_Integer nbps2 = (nbp>3)? (nbp/2) : 1; |
| 208 | Standard_Integer NombreDePointsDeDepartDuCheminement = 0; |
| 209 | Standard_Integer IndicePointdeDepart1 = 0,IndicePointdeDepart2 = 0; |
| 210 | Standard_Boolean lignetrouvee=Standard_False; |
| 211 | |
| 212 | do { |
| 213 | NombreDePointsDeDepartDuCheminement++; |
| 214 | if(NombreDePointsDeDepartDuCheminement == 1) { |
| 215 | incidence=3.0; |
| 216 | Standard_Integer nbp1_4=nbp/4; |
| 217 | Standard_Integer nbp3_4=nbp-nbp1_4; |
| 218 | |
| 219 | Standard_Integer nsp; |
| 220 | for(nsp=nbp/2; nsp<nbp3_4; nsp++) { |
| 221 | Standard_Real CurrentIncidence = LineSec.GetPoint(nsp).Incidence(); |
| 222 | if(CurrentIncidence < incidence) { |
| 223 | nbps2 = nsp; |
| 224 | incidence = 0.9*CurrentIncidence; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | for(nsp=nbp/2; nsp>nbp1_4; nsp--) { |
| 229 | Standard_Real CurrentIncidence = LineSec.GetPoint(nsp).Incidence(); |
| 230 | if(CurrentIncidence < incidence) { |
| 231 | nbps2 = nsp; |
| 232 | incidence = 0.9*CurrentIncidence; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | if(nbp<3) |
| 237 | NombreDePointsDeDepartDuCheminement=3; |
| 238 | |
| 239 | IndicePointdeDepart1 = nbps2; |
| 240 | } |
| 241 | else if(NombreDePointsDeDepartDuCheminement == 2) { |
| 242 | if(IndicePointdeDepart1 == 1) { |
| 243 | nbps2 = nbp/2; |
| 244 | IndicePointdeDepart2 = nbps2; |
| 245 | } |
| 246 | else { |
| 247 | nbps2 = 1; |
| 248 | IndicePointdeDepart2 = 1; |
| 249 | } |
| 250 | } |
| 251 | else if(NombreDePointsDeDepartDuCheminement == 3) { |
| 252 | if(IndicePointdeDepart1 == nbp) |
| 253 | nbps2 = (IndicePointdeDepart1+IndicePointdeDepart2)/2; |
| 254 | else |
| 255 | nbps2 = nbp; |
| 256 | } |
| 257 | else { |
| 258 | nbps2 = NombreDePointsDeDepartDuCheminement-3; |
| 259 | NombreDePointsDeDepartDuCheminement++; |
| 260 | } |
| 261 | |
| 262 | if(TabPtDep[nbps2]==0) { |
| 263 | TabPtDep[nbps2]=1; |
| 264 | SectionPointToParameters(LineSec.GetPoint(nbps2),Poly1,Poly2,U1,V1,U2,V2); |
| 265 | |
| 266 | StartParams(1) = U1; |
| 267 | StartParams(2) = V1; |
| 268 | StartParams(3) = U2; |
| 269 | StartParams(4) = V2; |
| 270 | |
| 271 | HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S); |
| 272 | dminiPointLigne = SeuildPointLigne + SeuildPointLigne; |
| 273 | |
| 274 | if(HasStartPoint) { |
| 275 | StartPOn2S.Parameters(pu1,pv1,pu2,pv2); |
| 276 | NbLigCalculee = SLin.Length(); |
| 277 | Standard_Integer l; |
| 278 | for( l=1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { |
| 279 | Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l)); |
| 280 | if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) && |
| 281 | (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) && |
| 282 | (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) { |
| 283 | NbPntOn2SOnLine = testwline->NbPnts(); |
| 284 | Standard_Integer ll; |
| 285 | for( ll=1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) { |
| 286 | const gp_Pnt &Pa = testwline->Point(ll).Value(); |
| 287 | const gp_Pnt &Pb = testwline->Point(ll+1).Value(); |
| 288 | const gp_Pnt &PStart = StartPOn2S.Value(); |
| 289 | gp_Vec AM(Pa,PStart); |
| 290 | gp_Vec MB(PStart,Pb); |
| 291 | Standard_Real AMMB = AM.Dot(MB); |
| 292 | if(AMMB > 0.0) { |
| 293 | gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z()); |
| 294 | Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z(); |
| 295 | gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z()); |
| 296 | gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z()); |
| 297 | Standard_Real d = 0.0; |
| 298 | if(HM.X() < Deflection) { |
| 299 | d+=HM.X()*HM.X(); |
| 300 | if(HM.Y() < Deflection) { |
| 301 | d+=HM.Y()*HM.Y(); |
| 302 | if(HM.Z() < Deflection) |
| 303 | d+=HM.Z()*HM.Z(); |
| 304 | else |
| 305 | d=Deflection2; |
| 306 | } |
| 307 | else |
| 308 | d=Deflection2; |
| 309 | } |
| 310 | else |
| 311 | d=Deflection2; |
| 312 | |
| 313 | if(d<Deflection2) |
| 314 | dminiPointLigne = 0.0; |
| 315 | } |
| 316 | else { |
| 317 | Standard_Real dab = Pa.SquareDistance(Pb); |
| 318 | Standard_Real dap = Pa.SquareDistance(PStart); |
| 319 | if(dap < dab) |
| 320 | dminiPointLigne=0; |
| 321 | else { |
| 322 | Standard_Real dbp = Pb.SquareDistance(PStart); |
| 323 | if(dbp < dab) |
| 324 | dminiPointLigne=0; |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | } // for ( l ... |
| 330 | |
| 331 | if(dminiPointLigne > SeuildPointLigne) { |
| 332 | PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2); |
| 333 | if(PW.IsDone()) { |
| 334 | if(PW.NbPoints()>2) { |
| 335 | RejetLigne = Standard_False; |
| 336 | Point3dDebut = PW.Value(1).Value(); |
| 337 | Point3dFin = PW.Value(PW.NbPoints()).Value(); |
| 338 | for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { |
| 339 | const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver)); |
| 340 | const IntSurf_PntOn2S& verPointDebut = verwline->Point(1); |
| 341 | const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts()); |
| 342 | if( Point3dDebut.Distance(verPointDebut.Value()) <= TolTangency ) { |
| 343 | if(Point3dFin.Distance(verPointFin.Value()) <= TolTangency) |
| 344 | RejetLigne = Standard_True; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | if(!RejetLigne) { |
| 349 | // Calculation transition |
| 350 | IntSurf_TypeTrans trans1,trans2; |
| 351 | Standard_Real locu,locv; |
| 352 | gp_Vec norm1,norm2,d1u,d1v; |
| 353 | gp_Pnt ptbid; |
| 354 | Standard_Integer indextg; |
| 355 | gp_Vec tgline(PW.TangentAtLine(indextg)); |
| 356 | PW.Line()->Value(indextg).ParametersOnS1(locu,locv); |
| 357 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 358 | norm1 = d1u.Crossed(d1v); |
| 359 | PW.Line()->Value(indextg).ParametersOnS2(locu,locv); |
| 360 | Surf2->D1(locu,locv,ptbid,d1u,d1v); |
| 361 | norm2 = d1u.Crossed(d1v); |
| 362 | if(tgline.DotCross(norm2,norm1)>0.) { |
| 363 | trans1 = IntSurf_Out; |
| 364 | trans2 = IntSurf_In; |
| 365 | } |
| 366 | else { |
| 367 | trans1 = IntSurf_In; |
| 368 | trans2 = IntSurf_Out; |
| 369 | } |
| 370 | |
| 371 | Standard_Real TolTang = TolTangency; |
| 372 | Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2); |
| 373 | IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang); |
| 374 | IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang); |
| 375 | |
| 376 | if(wline->NbVertex() == 0) { |
| 377 | IntPatch_Point vtx; |
| 378 | IntSurf_PntOn2S POn2S = PW.Line()->Value(1); |
| 379 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 380 | vtx.SetValue(Point3dDebut,TolTang,Standard_False); |
| 381 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 382 | vtx.SetParameter(1); |
| 383 | wline->AddVertex(vtx); |
| 384 | |
| 385 | POn2S = PW.Line()->Value(wline->NbPnts()); |
| 386 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 387 | vtx.SetValue(Point3dFin,TolTang,Standard_False); |
| 388 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 389 | vtx.SetParameter(wline->NbPnts()); |
| 390 | wline->AddVertex(vtx); |
| 391 | } |
| 392 | |
| 393 | lignetrouvee = Standard_True; |
| 394 | SLin.Append(wline); |
| 395 | empt = Standard_False; |
| 396 | }// !RejetLigne |
| 397 | }// PW.NbPoints()>2 |
| 398 | }// done is True |
| 399 | }// dminiPointLigne > SeuildPointLigne |
| 400 | }// HasStartPoint |
| 401 | }// TabPtDep[nbps2]==0 |
| 402 | } while( nbp>5 && ( !( ( (NombreDePointsDeDepartDuCheminement >= 3) && lignetrouvee ) || |
| 403 | ( (NombreDePointsDeDepartDuCheminement-3>=nbp) && !lignetrouvee ) ) ) ); |
| 404 | |
| 405 | delete [] TabPtDep; |
| 406 | }// for( ls ... |
| 407 | |
| 408 | delete [] TabL; |
| 409 | }// nbLigSec >= 1 |
| 410 | |
| 411 | Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1; |
| 412 | Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2; |
| 413 | |
| 414 | UminLig1=VminLig1=UminLig2=VminLig2=RealLast(); |
| 415 | UmaxLig1=VmaxLig1=UmaxLig2=VmaxLig2=-UminLig1; |
| 416 | |
| 417 | Standard_Integer z; |
| 418 | for(z=1; z <= nbTanZon; z++) { |
| 419 | const Intf_TangentZone& TangentZone=Interference.ZoneValue(z); |
| 420 | for(Standard_Integer pz=1; pz<=TangentZone.NumberOfPoints(); pz++) { |
| 421 | SectionPointToParameters(TangentZone.GetPoint(pz),Poly1,Poly2,U1,V1,U2,V2); |
| 422 | |
| 423 | if(U1>UmaxLig1) UmaxLig1=U1; |
| 424 | if(V1>VmaxLig1) VmaxLig1=V1; |
| 425 | if(U2>UmaxLig2) UmaxLig2=U2; |
| 426 | if(V2>VmaxLig2) VmaxLig2=V2; |
| 427 | |
| 428 | if(U1<UminLig1) UminLig1=U1; |
| 429 | if(V1<VminLig1) VminLig1=V1; |
| 430 | if(U2<UminLig2) UminLig2=U2; |
| 431 | if(V2<VminLig2) VminLig2=V2; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | for(z=1; z <= nbTanZon; z++) { |
| 436 | const Intf_TangentZone& TangentZone=Interference.ZoneValue(z); |
| 437 | Standard_Integer pz; |
| 438 | for( pz=1; pz<=TangentZone.NumberOfPoints(); pz++) { |
| 439 | SectionPointToParameters(TangentZone.GetPoint(pz),Poly1,Poly2,U1,V1,U2,V2); |
| 440 | |
| 441 | StartParams(1) = U1; |
| 442 | StartParams(2) = V1; |
| 443 | StartParams(3) = U2; |
| 444 | StartParams(4) = V2; |
| 445 | |
| 446 | HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S); |
| 447 | if(HasStartPoint) { |
| 448 | StartPOn2S.Parameters(pu1,pv1,pu2,pv2); |
| 449 | NbLigCalculee = SLin.Length(); |
| 450 | dminiPointLigne = SeuildPointLigne + SeuildPointLigne; |
| 451 | Standard_Integer l; |
| 452 | for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { |
| 453 | Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l)); |
| 454 | if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) && |
| 455 | (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) && |
| 456 | (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) { |
| 457 | NbPntOn2SOnLine = testwline->NbPnts(); |
| 458 | Standard_Integer ll; |
| 459 | for( ll = 1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) { |
| 460 | const gp_Pnt& Pa = testwline->Point(ll).Value(); |
| 461 | const gp_Pnt& Pb = testwline->Point(ll+1).Value(); |
| 462 | const gp_Pnt& PStart=StartPOn2S.Value(); |
| 463 | gp_Vec AM(Pa,PStart); |
| 464 | gp_Vec MB(PStart,Pb); |
| 465 | Standard_Real AMMB = AM.Dot(MB); |
| 466 | if(AMMB > 0.0) { |
| 467 | gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z()); |
| 468 | Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z(); |
| 469 | gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z()); |
| 470 | gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z()); |
| 471 | Standard_Real d = 0.0; |
| 472 | if(HM.X() < Deflection) { |
| 473 | d+=HM.X()*HM.X(); |
| 474 | if(HM.Y() < Deflection) { |
| 475 | d+=HM.Y()*HM.Y(); |
| 476 | if(HM.Z() < Deflection) |
| 477 | d+=HM.Z()*HM.Z(); |
| 478 | else |
| 479 | d=Deflection2; |
| 480 | } |
| 481 | else |
| 482 | d=Deflection2; |
| 483 | } |
| 484 | else |
| 485 | d=Deflection2; |
| 486 | |
| 487 | if(d<Deflection2) |
| 488 | dminiPointLigne = 0.0; |
| 489 | } |
| 490 | else { |
| 491 | Standard_Real dab = Pa.Distance(Pb); |
| 492 | Standard_Real dap = Pa.Distance(PStart); |
| 493 | if(dap < dab) |
| 494 | dminiPointLigne=0; |
| 495 | else { |
| 496 | Standard_Real dbp = Pb.Distance(PStart); |
| 497 | if(dbp < dab) |
| 498 | dminiPointLigne=0; |
| 499 | } |
| 500 | } |
| 501 | }// for( ll ... |
| 502 | }// if ... |
| 503 | }// for( l ... |
| 504 | |
| 505 | if(dminiPointLigne > SeuildPointLigne) { |
| 506 | PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2); |
| 507 | if(PW.IsDone()) { |
| 508 | if(PW.NbPoints()>2) { |
| 509 | RejetLigne = Standard_False; |
| 510 | Point3dDebut = PW.Value(1).Value(); |
| 511 | Point3dFin = PW.Value(PW.NbPoints()).Value(); |
| 512 | for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { |
| 513 | const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver)); |
| 514 | const IntSurf_PntOn2S& verPointDebut = verwline->Point(1); |
| 515 | const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts()); |
| 516 | if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency) |
| 517 | RejetLigne = Standard_True; |
| 518 | else { |
| 519 | if(Point3dFin.Distance(verPointFin.Value()) < TolTangency) |
| 520 | RejetLigne = Standard_True; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | if(!RejetLigne) { |
| 525 | IntSurf_TypeTrans trans1,trans2; |
| 526 | Standard_Real locu,locv; |
| 527 | gp_Vec norm1,norm2,d1u,d1v; |
| 528 | gp_Pnt ptbid; |
| 529 | Standard_Integer indextg; |
| 530 | gp_Vec tgline(PW.TangentAtLine(indextg)); |
| 531 | PW.Line()->Value(indextg).ParametersOnS1(locu,locv); |
| 532 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 533 | norm1 = d1u.Crossed(d1v); |
| 534 | PW.Line()->Value(indextg).ParametersOnS2(locu,locv); |
| 535 | Surf2->D1(locu,locv,ptbid,d1u,d1v); |
| 536 | norm2 = d1u.Crossed(d1v); |
| 537 | if(tgline.DotCross(norm2,norm1)>0.) { |
| 538 | trans1 = IntSurf_Out; |
| 539 | trans2 = IntSurf_In; |
| 540 | } |
| 541 | else { |
| 542 | trans1 = IntSurf_In; |
| 543 | trans2 = IntSurf_Out; |
| 544 | } |
| 545 | |
| 546 | Standard_Real TolTang = TolTangency; |
| 547 | Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2); |
| 548 | IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang); |
| 549 | IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang); |
| 550 | |
| 551 | if(wline->NbVertex() == 0) { |
| 552 | IntPatch_Point vtx; |
| 553 | IntSurf_PntOn2S POn2S = PW.Line()->Value(1); |
| 554 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 555 | vtx.SetValue(Point3dDebut,TolTang,Standard_False); |
| 556 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 557 | vtx.SetParameter(1); |
| 558 | wline->AddVertex(vtx); |
| 559 | |
| 560 | POn2S = PW.Line()->Value(wline->NbPnts()); |
| 561 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 562 | vtx.SetValue(Point3dFin,TolTang,Standard_False); |
| 563 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 564 | vtx.SetParameter(wline->NbPnts()); |
| 565 | wline->AddVertex(vtx); |
| 566 | } |
| 567 | |
| 568 | SLin.Append(wline); |
| 569 | empt = Standard_False; |
| 570 | }// if !RejetLigne |
| 571 | }// PW.NbPoints()>2 |
| 572 | }// done is True |
| 573 | }// dminiPointLigne > SeuildPointLigne |
| 574 | }// HasStartPoint |
| 575 | }// for( pz ... |
| 576 | }// for( z ... |
| 577 | } |
| 578 | |
| 579 | //================================================================================== |
| 580 | // function : Perform |
| 581 | // purpose : |
| 582 | //================================================================================== |
| 583 | void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1, |
| 584 | const IntPatch_Polyhedron& Poly1, |
| 585 | const Handle(Adaptor3d_TopolTool)& D1, |
| 586 | const Standard_Real TolTangency, |
| 587 | const Standard_Real Epsilon, |
| 588 | const Standard_Real Deflection, |
| 589 | const Standard_Real Increment) |
| 590 | { |
| 591 | IntPatch_TheInterfPolyhedron Interference(Poly1); |
| 592 | empt = Standard_True; |
| 593 | done = Standard_True; |
| 594 | SLin.Clear(); |
| 595 | |
| 596 | Standard_Integer nbLigSec = Interference.NbSectionLines(); |
| 597 | Standard_Integer nbTanZon = Interference.NbTangentZones(); |
| 598 | |
| 599 | Standard_Integer NbPntOn2SOnLine; |
| 600 | Standard_Integer NbLigCalculee = 0; |
| 601 | |
| 602 | Standard_Real U1,U2,V1,V2; |
| 603 | Standard_Real pu1,pu2,pv1,pv2; |
| 604 | |
| 605 | TColStd_Array1OfReal StartParams(1,4); |
| 606 | IntPatch_ThePWalkingInter PW(Surf1,Surf1,TolTangency,Epsilon,Deflection,Increment); |
| 607 | |
| 608 | Standard_Real SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant |
| 609 | Standard_Real incidence; |
| 610 | Standard_Real dminiPointLigne; |
| 611 | |
| 612 | Standard_Boolean HasStartPoint,RejetLigne; |
| 613 | |
| 614 | IntSurf_PntOn2S StartPOn2S; |
| 615 | |
| 616 | Standard_Integer ver; |
| 617 | |
| 618 | gp_Pnt Point3dDebut,Point3dFin; |
| 619 | |
| 620 | if(nbLigSec>=1) { |
| 621 | Standard_Integer ls; |
| 622 | for( ls = 1; ls <= nbLigSec; ls++) { |
| 623 | const Intf_SectionLine& LineSec=Interference.LineValue(ls); |
| 624 | Standard_Integer nbp = LineSec.NumberOfPoints(); |
| 625 | Standard_Integer nbps2 = (nbp>3)? (nbp/2) : 1; |
| 626 | Standard_Integer NombreDePointsDeDepartDuCheminement = 0; |
| 627 | Standard_Integer IndicePointdeDepart1 = 0, IndicePointdeDepart2 = 0; |
| 628 | do { |
| 629 | NombreDePointsDeDepartDuCheminement++; |
| 630 | if(NombreDePointsDeDepartDuCheminement == 1) { |
| 631 | incidence = 0.0; |
| 632 | Standard_Integer nsp1; |
| 633 | for( nsp1= nbp/2; nsp1 >= 1; nsp1--) { |
| 634 | SectionPointToParameters(LineSec.GetPoint(nsp1),Poly1,Poly1,U1,V1,U2,V2); |
| 635 | Standard_Real CurrentIncidence = Abs(U1-U2)+Abs(V1-V2); |
| 636 | if(CurrentIncidence > incidence) { |
| 637 | nbps2 = nsp1; |
| 638 | incidence = CurrentIncidence; |
| 639 | } |
| 640 | } |
| 641 | for( nsp1 = nbp/2; nsp1 <= nbp; nsp1++) { |
| 642 | SectionPointToParameters(LineSec.GetPoint(nsp1),Poly1,Poly1,U1,V1,U2,V2); |
| 643 | Standard_Real CurrentIncidence = Abs(U1-U2)+Abs(V1-V2); |
| 644 | if(CurrentIncidence > incidence) { |
| 645 | nbps2 = nsp1; |
| 646 | incidence = CurrentIncidence; |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | if(nbp<3) |
| 651 | NombreDePointsDeDepartDuCheminement=3; |
| 652 | |
| 653 | IndicePointdeDepart1 = nbps2; |
| 654 | } |
| 655 | else if(NombreDePointsDeDepartDuCheminement == 2) { |
| 656 | if(IndicePointdeDepart1 == 1) { |
| 657 | nbps2 = nbp/2; |
| 658 | IndicePointdeDepart2 = nbps2; |
| 659 | } |
| 660 | else { |
| 661 | nbps2 = 1; |
| 662 | IndicePointdeDepart2 = 1; |
| 663 | } |
| 664 | } |
| 665 | else { |
| 666 | if(IndicePointdeDepart1 == nbp) |
| 667 | nbps2 = (IndicePointdeDepart1+IndicePointdeDepart2)/2; |
| 668 | else |
| 669 | nbps2 = nbp; |
| 670 | } |
| 671 | |
| 672 | SectionPointToParameters(LineSec.GetPoint(nbps2),Poly1,Poly1,U1,V1,U2,V2); |
| 673 | |
| 674 | StartParams(1) = U1; |
| 675 | StartParams(2) = V1; |
| 676 | StartParams(3) = U2; |
| 677 | StartParams(4) = V2; |
| 678 | |
| 679 | HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S); |
| 680 | dminiPointLigne = SeuildPointLigne + SeuildPointLigne; |
| 681 | if(HasStartPoint) { |
| 682 | StartPOn2S.Parameters(pu1,pv1,pu2,pv2); |
| 683 | if(Abs(pu1-pu2)>1e-7 || Abs(pv1-pv2)>1e-7) { |
| 684 | NbLigCalculee = SLin.Length(); |
| 685 | Standard_Integer l; |
| 686 | for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { |
| 687 | Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l)); |
| 688 | if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) && |
| 689 | (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) && |
| 690 | (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) { |
| 691 | NbPntOn2SOnLine = testwline->NbPnts(); |
| 692 | Standard_Integer ll; |
| 693 | for( ll=1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) { |
| 694 | Standard_Real t,Au1,Av1,Au2,Av2,Bu1,Bv1,Bu2,Bv2; |
| 695 | testwline->Point(ll).Parameters(Au1,Av1,Au2,Av2); |
| 696 | testwline->Point(ll+1).Parameters(Bu1,Bv1,Bu2,Bv2); |
| 697 | if(Au1>Bu1) { |
| 698 | t=Au1; |
| 699 | Au1=Bu1; |
| 700 | Bu1=t; |
| 701 | } |
| 702 | if(Av1>Bv1) { |
| 703 | t=Av1; |
| 704 | Av1=Bv1; |
| 705 | Bv1=t; |
| 706 | } |
| 707 | Au1-=1.0e-7; |
| 708 | Av1-=1.0e-7; |
| 709 | Bu1+=1.0e-7; |
| 710 | Bv1+=1.0e-7; |
| 711 | |
| 712 | if((pu1>=Au1) && (pu1<=Bu1) && (pv1>=Av1) && (pv1<=Bv1)) |
| 713 | dminiPointLigne = 0.0; |
| 714 | else { |
| 715 | if((pu2>=Au1) && (pu2<=Bu1) && (pv2>=Av1) && (pv2<=Bv1)) |
| 716 | dminiPointLigne = 0.0; |
| 717 | } |
| 718 | }// for( ll ... |
| 719 | }// if ... |
| 720 | }// for( l ... |
| 721 | |
| 722 | if(dminiPointLigne > SeuildPointLigne) { |
| 723 | PW.Perform(StartParams); |
| 724 | if(PW.IsDone()) { |
| 725 | if(PW.NbPoints()>2) { |
| 726 | RejetLigne = Standard_False; |
| 727 | Point3dDebut = PW.Value(1).Value(); |
| 728 | Point3dFin = PW.Value(PW.NbPoints()).Value(); |
| 729 | for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { |
| 730 | const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver)); |
| 731 | const IntSurf_PntOn2S& verPointDebut = verwline->Point(1); |
| 732 | const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts()); |
| 733 | if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency) |
| 734 | RejetLigne = Standard_True; |
| 735 | else { |
| 736 | if(Point3dFin.Distance(verPointFin.Value()) < TolTangency) |
| 737 | RejetLigne = Standard_True; |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | if(!RejetLigne) { |
| 742 | IntSurf_TypeTrans trans1,trans2; |
| 743 | Standard_Real locu,locv; |
| 744 | gp_Vec norm1,norm2,d1u,d1v; |
| 745 | gp_Pnt ptbid; |
| 746 | Standard_Integer indextg; |
| 747 | gp_Vec tgline(PW.TangentAtLine(indextg)); |
| 748 | PW.Line()->Value(indextg).ParametersOnS1(locu,locv); |
| 749 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 750 | norm1 = d1u.Crossed(d1v); |
| 751 | PW.Line()->Value(indextg).ParametersOnS2(locu,locv); |
| 752 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 753 | norm2 = d1u.Crossed(d1v); |
| 754 | if (tgline.DotCross(norm2,norm1)>0.) { |
| 755 | trans1 = IntSurf_Out; |
| 756 | trans2 = IntSurf_In; |
| 757 | } |
| 758 | else { |
| 759 | trans1 = IntSurf_In; |
| 760 | trans2 = IntSurf_Out; |
| 761 | } |
| 762 | |
| 763 | IntSurf_LineOn2S LineOn2S; |
| 764 | Standard_Integer nbpw,imin,imax,i; |
| 765 | nbpw = PW.Line()->NbPoints(); |
| 766 | Standard_Real u1,v1,u2,v2; |
| 767 | i=0; |
| 768 | do { |
| 769 | i++; |
| 770 | imin=i; |
| 771 | const IntSurf_PntOn2S& Pi = PW.Line()->Value(i); |
| 772 | Pi.Parameters(u1,v1,u2,v2); |
| 773 | } while((i<nbpw)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6)); |
| 774 | |
| 775 | if(imin>2) |
| 776 | imin--; |
| 777 | |
| 778 | i=nbpw+1; |
| 779 | do { |
| 780 | i--; |
| 781 | imax=i; |
| 782 | const IntSurf_PntOn2S& Pi = PW.Line()->Value(i); |
| 783 | Pi.Parameters(u1,v1,u2,v2); |
| 784 | } while((i>2)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6)); |
| 785 | |
| 786 | if(imax<nbpw) |
| 787 | imax++; |
| 788 | |
| 789 | if(imin<imax) { |
| 790 | Handle_IntSurf_LineOn2S PWLine = new IntSurf_LineOn2S(); |
| 791 | for(i=imin;i<=imax;i++) |
| 792 | PWLine->Add(PW.Line()->Value(i)); |
| 793 | |
| 794 | Standard_Real TolTang = TolTangency; |
| 795 | Handle(IntPatch_WLine) wline = new IntPatch_WLine(PWLine,Standard_False,trans1,trans2); |
| 796 | const IntSurf_PntOn2S& POn2SDeb = wline->Point(1); |
| 797 | const IntSurf_PntOn2S& POn2SFin = wline->Point(wline->NbPnts()); |
| 798 | if((POn2SDeb.Value()).Distance(POn2SFin.Value()) <= TolTangency) { |
| 799 | Standard_Real u1t,v1t,u2t,v2t; |
| 800 | POn2SDeb.Parameters(u1t,v1t,u2t,v2t); |
| 801 | IntPatch_Point vtx; |
| 802 | vtx.SetValue(POn2SDeb.Value(),TolTang,Standard_False); |
| 803 | vtx.SetParameters(u2t,v2t,u1t,v1t); |
| 804 | vtx.SetParameter(wline->NbPnts()); |
| 805 | wline->SetPoint(wline->NbPnts(),vtx); |
| 806 | } |
| 807 | IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf1,Standard_True,TolTang); |
| 808 | if(wline->NbVertex() == 0) { |
| 809 | IntPatch_Point vtx; |
| 810 | IntSurf_PntOn2S POn2S = PW.Line()->Value(1); |
| 811 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 812 | vtx.SetValue(Point3dDebut,TolTang,Standard_False); |
| 813 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 814 | vtx.SetParameter(1); |
| 815 | wline->AddVertex(vtx); |
| 816 | |
| 817 | POn2S = PW.Line()->Value(wline->NbPnts()); |
| 818 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 819 | vtx.SetValue(Point3dFin,TolTang,Standard_False); |
| 820 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 821 | vtx.SetParameter(wline->NbPnts()); |
| 822 | wline->AddVertex(vtx); |
| 823 | } |
| 824 | SLin.Append(wline); |
| 825 | empt = Standard_False; |
| 826 | }// imin<imax |
| 827 | }// !RejetLigne |
| 828 | }// PW.NbPoints()>2 |
| 829 | }// done is True |
| 830 | }// dminiPointLigne > SeuildPointLigne |
| 831 | }// Abs || Abs |
| 832 | }// HasStartPoint |
| 833 | } while(nbp>5 && NombreDePointsDeDepartDuCheminement<3); |
| 834 | }// for( ls ... |
| 835 | }// nbLigSec>=1 |
| 836 | |
| 837 | Standard_Integer z; |
| 838 | for( z = 1; z <= nbTanZon; z++) { |
| 839 | const Intf_TangentZone& TangentZone=Interference.ZoneValue(z); |
| 840 | for(Standard_Integer pz=1; pz<=TangentZone.NumberOfPoints(); pz++) { |
| 841 | SectionPointToParameters(TangentZone.GetPoint(pz),Poly1,Poly1,U1,V1,U2,V2); |
| 842 | |
| 843 | StartParams(1) = U1; |
| 844 | StartParams(2) = V1; |
| 845 | StartParams(3) = U2; |
| 846 | StartParams(4) = V2; |
| 847 | |
| 848 | HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S); |
| 849 | if(HasStartPoint) { |
| 850 | StartPOn2S.Parameters(pu1,pv1,pu2,pv2); |
| 851 | if(Abs(pu1-pu2)>1e-7 || Abs(pv1-pv2)>1e-7) { |
| 852 | NbLigCalculee = SLin.Length(); |
| 853 | dminiPointLigne = SeuildPointLigne + SeuildPointLigne; |
| 854 | Standard_Integer l; |
| 855 | for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { |
| 856 | Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l)); |
| 857 | if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) && |
| 858 | (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) && |
| 859 | (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) { |
| 860 | NbPntOn2SOnLine = testwline->NbPnts(); |
| 861 | Standard_Integer ll; |
| 862 | for( ll = 1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) { |
| 863 | Standard_Real t,Au1,Av1,Au2,Av2,Bu1,Bv1,Bu2,Bv2; |
| 864 | testwline->Point(ll).Parameters(Au1,Av1,Au2,Av2); |
| 865 | testwline->Point(ll+1).Parameters(Bu1,Bv1,Bu2,Bv2); |
| 866 | if(Au1>Bu1) { |
| 867 | t=Au1; |
| 868 | Au1=Bu1; |
| 869 | Bu1=t; |
| 870 | } |
| 871 | if(Av1>Bv1) { |
| 872 | t=Av1; |
| 873 | Av1=Bv1; |
| 874 | Bv1=t; |
| 875 | } |
| 876 | Au1-=1.0e-7; |
| 877 | Av1-=1.0e-7; |
| 878 | Bu1+=1.0e-7; |
| 879 | Bv1+=1.0e-7; |
| 880 | if((pu1>=Au1) && (pu1<=Bu1) && (pv1>=Av1) && (pv1<=Bv1)) |
| 881 | dminiPointLigne = 0.0; |
| 882 | else { |
| 883 | if((pu2>=Au1) && (pu2<=Bu1) && (pv2>=Av1) && (pv2<=Bv1)) |
| 884 | dminiPointLigne = 0.0; |
| 885 | } |
| 886 | }// for( ll ... |
| 887 | }// if ... |
| 888 | }// for( l ... |
| 889 | |
| 890 | if(dminiPointLigne > SeuildPointLigne) { |
| 891 | PW.Perform(StartParams); |
| 892 | if(PW.IsDone()) { |
| 893 | if(PW.NbPoints()>2) { |
| 894 | RejetLigne = Standard_False; |
| 895 | Point3dDebut = PW.Value(1).Value(); |
| 896 | Point3dFin = PW.Value(PW.NbPoints()).Value(); |
| 897 | for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { |
| 898 | const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver)); |
| 899 | const IntSurf_PntOn2S& verPointDebut = verwline->Point(1); |
| 900 | const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts()); |
| 901 | if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency) |
| 902 | RejetLigne = Standard_True; |
| 903 | else { |
| 904 | if(Point3dFin.Distance(verPointFin.Value()) < TolTangency) |
| 905 | RejetLigne = Standard_True; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | if(!RejetLigne) { |
| 910 | IntSurf_TypeTrans trans1,trans2; |
| 911 | Standard_Real locu,locv; |
| 912 | gp_Vec norm1,norm2,d1u,d1v; |
| 913 | gp_Pnt ptbid; |
| 914 | Standard_Integer indextg; |
| 915 | gp_Vec tgline(PW.TangentAtLine(indextg)); |
| 916 | PW.Line()->Value(indextg).ParametersOnS1(locu,locv); |
| 917 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 918 | norm1 = d1u.Crossed(d1v); |
| 919 | PW.Line()->Value(indextg).ParametersOnS2(locu,locv); |
| 920 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 921 | norm2 = d1u.Crossed(d1v); |
| 922 | if(tgline.DotCross(norm2,norm1)>0.) { |
| 923 | trans1 = IntSurf_Out; |
| 924 | trans2 = IntSurf_In; |
| 925 | } |
| 926 | else { |
| 927 | trans1 = IntSurf_In; |
| 928 | trans2 = IntSurf_Out; |
| 929 | } |
| 930 | |
| 931 | IntSurf_LineOn2S LineOn2S; |
| 932 | Standard_Integer nbp,imin,imax,i; |
| 933 | nbp = PW.Line()->NbPoints(); |
| 934 | Standard_Real u1,v1,u2,v2; |
| 935 | i=0; |
| 936 | do { |
| 937 | i++; |
| 938 | imin=i; |
| 939 | const IntSurf_PntOn2S& Pi = PW.Line()->Value(i); |
| 940 | Pi.Parameters(u1,v1,u2,v2); |
| 941 | } while((i<nbp)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6)); |
| 942 | |
| 943 | if(imin>2) |
| 944 | imin--; |
| 945 | |
| 946 | i=nbp+1; |
| 947 | do { |
| 948 | i--; |
| 949 | imax=i; |
| 950 | const IntSurf_PntOn2S& Pi = PW.Line()->Value(i); |
| 951 | Pi.Parameters(u1,v1,u2,v2); |
| 952 | } while((i>2)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6)); |
| 953 | |
| 954 | if(imax<nbp) |
| 955 | imax++; |
| 956 | |
| 957 | if(imin<imax) { |
| 958 | Handle_IntSurf_LineOn2S PWLine = new IntSurf_LineOn2S(); |
| 959 | for(i=imin;i<=imax;i++) |
| 960 | PWLine->Add(PW.Line()->Value(i)); |
| 961 | |
| 962 | Standard_Real TolTang = TolTangency; |
| 963 | Handle(IntPatch_WLine) wline = new IntPatch_WLine(PWLine,Standard_False,trans1,trans2); |
| 964 | const IntSurf_PntOn2S& POn2SDeb = wline->Point(1); |
| 965 | const IntSurf_PntOn2S& POn2SFin = wline->Point(wline->NbPnts()); |
| 966 | if((POn2SDeb.Value()).Distance(POn2SFin.Value()) <= TolTangency) { |
| 967 | Standard_Real u1t,v1t,u2t,v2t; |
| 968 | POn2SDeb.Parameters(u1t,v1t,u2t,v2t); |
| 969 | IntPatch_Point vtx; |
| 970 | vtx.SetValue(POn2SDeb.Value(),TolTang,Standard_False); |
| 971 | vtx.SetParameters(u2t,v2t,u1t,v1t); |
| 972 | vtx.SetParameter(wline->NbPnts()); |
| 973 | wline->SetPoint(wline->NbPnts(),vtx); |
| 974 | } |
| 975 | |
| 976 | IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf1,Standard_True,TolTang); |
| 977 | |
| 978 | if(wline->NbVertex() == 0) { |
| 979 | IntPatch_Point vtx; |
| 980 | IntSurf_PntOn2S POn2S = PW.Line()->Value(1); |
| 981 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 982 | vtx.SetValue(Point3dDebut,TolTang,Standard_False); |
| 983 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 984 | vtx.SetParameter(1); |
| 985 | wline->AddVertex(vtx); |
| 986 | |
| 987 | POn2S = PW.Line()->Value(wline->NbPnts()); |
| 988 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 989 | vtx.SetValue(Point3dFin,TolTang,Standard_False); |
| 990 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 991 | vtx.SetParameter(wline->NbPnts()); |
| 992 | wline->AddVertex(vtx); |
| 993 | } |
| 994 | |
| 995 | SLin.Append(wline); |
| 996 | empt = Standard_False; |
| 997 | }// imin<imax |
| 998 | }// !RejetLigne |
| 999 | }// PW.NbPoints()>2 |
| 1000 | }// done a True |
| 1001 | }// dminiPointLigne > SeuildPointLigne |
| 1002 | }// Abs || Abs |
| 1003 | }// HasStartPoint |
| 1004 | }// for ( pz ... |
| 1005 | }// for( z ... |
| 1006 | } |
| 1007 | |
| 1008 | //================================================================================== |
| 1009 | // function : NewLine |
| 1010 | // purpose : |
| 1011 | //================================================================================== |
| 1012 | Handle_IntPatch_Line IntPatch_PrmPrmIntersection::NewLine (const Handle(Adaptor3d_HSurface)& Surf1, |
| 1013 | const Handle(Adaptor3d_HSurface)& Surf2, |
| 1014 | const Standard_Integer NumLine, |
| 1015 | const Standard_Integer Low, |
| 1016 | const Standard_Integer High, |
| 1017 | const Standard_Integer NbPntsToInsert) const |
| 1018 | { |
| 1019 | Standard_Integer NbPnts = NbPntsToInsert + High - Low; |
| 1020 | if(NumLine>NbLines() || NumLine<1 || Low>=High ) |
| 1021 | Standard_OutOfRange::Raise(" IntPatch_PrmPrmIntersection NewLine "); |
| 1022 | //------------------------------------------------------------------ |
| 1023 | //-- Indice : Low Low+1 I I+1 High -- |
| 1024 | //-- -- |
| 1025 | //-- Abs.Curv. : S(Low) S(I) S(I+1) S(High) -- |
| 1026 | //-- -- |
| 1027 | //-- On echantillonne a abcisse curviligne -- |
| 1028 | //-- constante. -- |
| 1029 | //-- L abcisse est calculee sur les params U1,V1 -- |
| 1030 | //------------------------------------------------------------------ |
| 1031 | TColStd_Array1OfReal U1(Low,High); |
| 1032 | TColStd_Array1OfReal V1(Low,High); |
| 1033 | TColStd_Array1OfReal U2(Low,High); |
| 1034 | TColStd_Array1OfReal V2(Low,High); |
| 1035 | TColStd_Array1OfReal AC(Low,High); |
| 1036 | |
| 1037 | Standard_Real s,ds; |
| 1038 | Handle(IntPatch_WLine) TheLine = Handle(IntPatch_WLine)::DownCast(Line(NumLine)); |
| 1039 | const IntSurf_PntOn2S& Point=TheLine->Point(Low); |
| 1040 | Standard_Real u1,v1,u2,v2; |
| 1041 | Point.Parameters(u1,v1,u2,v2); |
| 1042 | U1(Low) = u1; |
| 1043 | V1(Low) = v1; |
| 1044 | U2(Low) = u2; |
| 1045 | V2(Low) = v2; |
| 1046 | AC(Low) =0.0; |
| 1047 | |
| 1048 | IntPatch_ThePWalkingInter PW(Surf1,Surf2,0.000001,0.000001,0.001,0.001); |
| 1049 | |
| 1050 | Standard_Integer i; |
| 1051 | for(i=Low+1; i<=High; i++) |
| 1052 | { |
| 1053 | const IntSurf_PntOn2S& Pointi=TheLine->Point(i); |
| 1054 | Pointi.Parameters(u1,v1,u2,v2); |
| 1055 | U1(i) = u1; |
| 1056 | V1(i) = v1; |
| 1057 | U2(i) = u2; |
| 1058 | V2(i) = v2; |
| 1059 | |
| 1060 | Standard_Real du1=u1-U1(i-1); |
| 1061 | Standard_Real dv1=v1-V1(i-1); |
| 1062 | |
| 1063 | AC(i) = AC(i-1) + Sqrt((du1*du1)+(dv1*dv1)); |
| 1064 | } |
| 1065 | |
| 1066 | Handle(IntSurf_LineOn2S) ResultPntOn2SLine = new IntSurf_LineOn2S(); |
| 1067 | |
| 1068 | IntSurf_PntOn2S StartPOn2S; |
| 1069 | TColStd_Array1OfReal StartParams(1,4); |
| 1070 | |
| 1071 | ResultPntOn2SLine->Add(TheLine->Point(Low)); |
| 1072 | |
| 1073 | ds = AC(High) / (NbPnts-1); |
| 1074 | Standard_Integer Indice = Low; |
| 1075 | |
| 1076 | Standard_Real dsmin = ds*0.3; |
| 1077 | Standard_Real smax = AC(High); |
| 1078 | |
| 1079 | for(i=2,s=ds; (i<NbPnts)&&(s<smax); i++,s+=ds) |
| 1080 | { |
| 1081 | while(AC(Indice+1) <= s) |
| 1082 | { |
| 1083 | ResultPntOn2SLine->Add(TheLine->Point(Indice)); |
| 1084 | Indice++; |
| 1085 | } |
| 1086 | Standard_Real a = s - AC(Indice); |
| 1087 | Standard_Real b = AC(Indice+1) - s; |
| 1088 | Standard_Real nab = 1.0/(a+b); |
| 1089 | //---------------------------------------------------------- |
| 1090 | //-- Verification : Si Dist au prochain point < dsmin -- |
| 1091 | //-- Si Dist au precedent point < dsmin -- |
| 1092 | //-- -- |
| 1093 | //---------------------------------------------------------- |
| 1094 | if((nab > ds)&&(a>dsmin)&&(b>dsmin)) |
| 1095 | { |
| 1096 | StartParams(1) = (U1(Indice) * b + U1(Indice+1) * a) * nab; |
| 1097 | StartParams(2) = (V1(Indice) * b + V1(Indice+1) * a) * nab; |
| 1098 | StartParams(3) = (U2(Indice) * b + U2(Indice+1) * a) * nab; |
| 1099 | StartParams(4) = (V2(Indice) * b + V2(Indice+1) * a) * nab; |
| 1100 | |
| 1101 | Standard_Boolean HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S); |
| 1102 | if(HasStartPoint) |
| 1103 | ResultPntOn2SLine->Add(StartPOn2S); |
| 1104 | } |
| 1105 | else |
| 1106 | s+=dsmin; |
| 1107 | } |
| 1108 | |
| 1109 | ResultPntOn2SLine->Add(TheLine->Point(High)); |
| 1110 | |
| 1111 | return(new IntPatch_WLine(ResultPntOn2SLine,Standard_False)); |
| 1112 | } |
| 1113 | |
| 1114 | //================================================================================== |
| 1115 | // function : SectionPointToParameters |
| 1116 | // purpose : |
| 1117 | //================================================================================== |
| 1118 | void SectionPointToParameters(const Intf_SectionPoint& Sp, |
| 1119 | const IntPatch_Polyhedron& Poly1, |
| 1120 | const IntPatch_Polyhedron& Poly2, |
| 1121 | Standard_Real& u1, |
| 1122 | Standard_Real& v1, |
| 1123 | Standard_Real& u2, |
| 1124 | Standard_Real& v2) |
| 1125 | { |
| 1126 | Intf_PIType typ; |
| 1127 | Standard_Integer Adr1,Adr2; |
| 1128 | Standard_Real Param,u,v; |
| 1129 | gp_Pnt P(Sp.Pnt()); |
| 1130 | |
| 1131 | Standard_Integer Pt1,Pt2,Pt3; |
| 1132 | |
| 1133 | Sp.InfoFirst(typ,Adr1,Adr2,Param); |
| 1134 | switch(typ) { |
| 1135 | case Intf_VERTEX: //-- Adr1 est le numero du vertex |
| 1136 | { |
| 1137 | Poly1.Parameters(Adr1,u1,v1); |
| 1138 | break; |
| 1139 | } |
| 1140 | case Intf_EDGE: |
| 1141 | { |
| 1142 | Poly1.Parameters(Adr1,u1,v1); |
| 1143 | Poly1.Parameters(Adr2,u,v); |
| 1144 | u1+= Param * (u-u1); |
| 1145 | v1+= Param * (v-v1); |
| 1146 | break; |
| 1147 | } |
| 1148 | case Intf_FACE: |
| 1149 | { |
| 1150 | Standard_Real ua,va,ub,vb,uc,vc,ca,cb,cc,cabc; |
| 1151 | Poly1.Triangle(Adr1,Pt1,Pt2,Pt3); |
| 1152 | gp_Pnt PA(Poly1.Point(Pt1)); |
| 1153 | gp_Pnt PB(Poly1.Point(Pt2)); |
| 1154 | gp_Pnt PC(Poly1.Point(Pt3)); |
| 1155 | Poly1.Parameters(Pt1,ua,va); |
| 1156 | Poly1.Parameters(Pt2,ub,vb); |
| 1157 | Poly1.Parameters(Pt3,uc,vc); |
| 1158 | gp_Vec Normale(gp_Vec(PA,PB).Crossed(gp_Vec(PA,PC))); |
| 1159 | cc = (gp_Vec(PA,PB).Crossed(gp_Vec(PA,P))).Dot(Normale); |
| 1160 | ca = (gp_Vec(PB,PC).Crossed(gp_Vec(PB,P))).Dot(Normale); |
| 1161 | cb = (gp_Vec(PC,PA).Crossed(gp_Vec(PC,P))).Dot(Normale); |
| 1162 | cabc = ca + cb + cc; |
| 1163 | |
| 1164 | ca/=cabc; cb/=cabc; cc/=cabc; |
| 1165 | |
| 1166 | u1 = ca * ua + cb * ub + cc * uc; |
| 1167 | v1 = ca * va + cb * vb + cc * vc; |
| 1168 | break; |
| 1169 | } |
| 1170 | default: |
| 1171 | { |
| 1172 | //-- cout<<" Default dans SectionPointToParameters "<<endl; |
| 1173 | break; |
| 1174 | } |
| 1175 | } |
| 1176 | |
| 1177 | |
| 1178 | Sp.InfoSecond(typ,Adr1,Adr2,Param); |
| 1179 | switch(typ) { |
| 1180 | case Intf_VERTEX: //-- Adr1 est le numero du vertex |
| 1181 | { |
| 1182 | Poly2.Parameters(Adr1,u2,v2); |
| 1183 | break; |
| 1184 | } |
| 1185 | case Intf_EDGE: |
| 1186 | { |
| 1187 | Poly2.Parameters(Adr1,u2,v2); |
| 1188 | Poly2.Parameters(Adr2,u,v); |
| 1189 | u2+= Param * (u-u2); |
| 1190 | v2+= Param * (v-v2); |
| 1191 | break; |
| 1192 | } |
| 1193 | case Intf_FACE: |
| 1194 | { |
| 1195 | Standard_Real ua,va,ub,vb,uc,vc,ca,cb,cc,cabc; |
| 1196 | Poly2.Triangle(Adr1,Pt1,Pt2,Pt3); |
| 1197 | gp_Pnt PA(Poly2.Point(Pt1)); |
| 1198 | gp_Pnt PB(Poly2.Point(Pt2)); |
| 1199 | gp_Pnt PC(Poly2.Point(Pt3)); |
| 1200 | Poly2.Parameters(Pt1,ua,va); |
| 1201 | Poly2.Parameters(Pt2,ub,vb); |
| 1202 | Poly2.Parameters(Pt3,uc,vc); |
| 1203 | gp_Vec Normale(gp_Vec(PA,PB).Crossed(gp_Vec(PA,PC))); |
| 1204 | cc = (gp_Vec(PA,PB).Crossed(gp_Vec(PA,P))).Dot(Normale); |
| 1205 | ca = (gp_Vec(PB,PC).Crossed(gp_Vec(PB,P))).Dot(Normale); |
| 1206 | cb = (gp_Vec(PC,PA).Crossed(gp_Vec(PC,P))).Dot(Normale); |
| 1207 | cabc = ca + cb + cc; |
| 1208 | |
| 1209 | ca/=cabc; cb/=cabc; cc/=cabc; |
| 1210 | |
| 1211 | u2 = ca * ua + cb * ub + cc * uc; |
| 1212 | v2 = ca * va + cb * vb + cc * vc; |
| 1213 | break; |
| 1214 | } |
| 1215 | default: |
| 1216 | { |
| 1217 | //-- cout<<" Default dans SectionPointToParameters "<<endl; |
| 1218 | break; |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | #define NBI 200 |
| 1224 | |
| 1225 | static gp_Pnt P1[NBI][NBI]; |
| 1226 | static gp_Pnt P2[NBI][NBI]; |
| 1227 | static Standard_Integer IP1[NBI][NBI]; |
| 1228 | static Standard_Integer IP2[NBI][NBI]; |
| 1229 | |
| 1230 | static char P1DS2[NBI][NBI]; |
| 1231 | static char P2DS1[NBI][NBI]; |
| 1232 | |
| 1233 | #define _DECAL 7 |
| 1234 | #define _DECAL2 14 |
| 1235 | #define _BASE 128 |
| 1236 | #define _BASEM1 127 |
| 1237 | |
| 1238 | long unsigned nbappelstri=0; |
| 1239 | long unsigned nbappelslin=0; |
| 1240 | |
| 1241 | |
| 1242 | //================================================================================== |
| 1243 | // function : RemplitLin |
| 1244 | // purpose : |
| 1245 | //================================================================================== |
| 1246 | void IntPatch_PrmPrmIntersection::RemplitLin(const Standard_Integer x1, |
| 1247 | const Standard_Integer y1, |
| 1248 | const Standard_Integer z1, |
| 1249 | const Standard_Integer x2, |
| 1250 | const Standard_Integer y2, |
| 1251 | const Standard_Integer z2, |
| 1252 | IntPatch_PrmPrmIntersection_T3Bits& Map) const |
| 1253 | { |
| 1254 | int xg,yg,zg; |
| 1255 | xg=x1-x2; if(xg<0) xg=-xg; |
| 1256 | yg=y1-y2; if(yg<0) yg=-yg; |
| 1257 | zg=z1-z2; if(zg<0) zg=-zg; |
| 1258 | if(DansGrille(x1) && DansGrille(y1) && DansGrille(z1)) { |
| 1259 | Standard_Integer t = GrilleInteger(x1,y1,z1); |
| 1260 | Map.Add(t); |
| 1261 | } |
| 1262 | if(xg<=1 && yg<=1 && zg<=1) return; |
| 1263 | xg = (x1+x2)>>1; |
| 1264 | yg = (y1+y2)>>1; |
| 1265 | zg = (z1+z2)>>1; |
| 1266 | RemplitLin(x1,y1,z1,xg,yg,zg,Map); |
| 1267 | RemplitLin(x2,y2,z2,xg,yg,zg,Map); |
| 1268 | } |
| 1269 | |
| 1270 | //================================================================================== |
| 1271 | // function : RemplitTri |
| 1272 | // purpose : |
| 1273 | //================================================================================== |
| 1274 | void IntPatch_PrmPrmIntersection::RemplitTri(const Standard_Integer x1, |
| 1275 | const Standard_Integer y1, |
| 1276 | const Standard_Integer z1, |
| 1277 | const Standard_Integer x2, |
| 1278 | const Standard_Integer y2, |
| 1279 | const Standard_Integer z2, |
| 1280 | const Standard_Integer x3, |
| 1281 | const Standard_Integer y3, |
| 1282 | const Standard_Integer z3, |
| 1283 | IntPatch_PrmPrmIntersection_T3Bits& Map) const |
| 1284 | { |
| 1285 | if(x1==x2 && x1==x3 && y1==y2 && y1==y3 && z1==z2 && z1==z3) { |
| 1286 | if(DansGrille(x1) && DansGrille(y1) && DansGrille(z1)) { |
| 1287 | Standard_Integer t = GrilleInteger(x1,y1,z1); |
| 1288 | Map.Add(t); |
| 1289 | } |
| 1290 | return; |
| 1291 | } |
| 1292 | else { |
| 1293 | Standard_Integer xg=(x1+x2+x3)/3; |
| 1294 | Standard_Integer yg=(y1+y2+y3)/3; |
| 1295 | Standard_Integer zg=(z1+z2+z3)/3; |
| 1296 | if(xg==x1 && yg==y1 && zg==z1) { |
| 1297 | RemplitLin(x1,y1,z1,x2,y2,z2,Map); |
| 1298 | RemplitLin(x1,y1,z1,x3,y3,z3,Map); |
| 1299 | return; |
| 1300 | } |
| 1301 | if(xg==x2 && yg==y2 && zg==z2) { |
| 1302 | RemplitLin(x2,y2,z2,x1,y1,z1,Map); |
| 1303 | RemplitLin(x2,y2,z2,x3,y3,z3,Map); |
| 1304 | return; |
| 1305 | } |
| 1306 | if(xg==x3 && yg==y3 && zg==z3) { |
| 1307 | RemplitLin(x3,y3,z3,x2,y2,z2,Map); |
| 1308 | RemplitLin(x3,y3,z3,x1,y1,z1,Map); |
| 1309 | return; |
| 1310 | } |
| 1311 | if(DansGrille(xg) && DansGrille(yg) && DansGrille(zg)) { |
| 1312 | Standard_Integer t = GrilleInteger(xg,yg,zg); |
| 1313 | Map.Add(t); |
| 1314 | } |
| 1315 | if(xg!=x3 || yg!=y3 || zg!=z3) RemplitTri(x1,y1,z1, x2,y2,z2, xg,yg,zg, Map); |
| 1316 | if(xg!=x1 || yg!=y1 || zg!=z1) RemplitTri(xg,yg,zg, x2,y2,z2, x3,y3,z3, Map); |
| 1317 | if(xg!=x2 || yg!=y2 || zg!=z2) RemplitTri(x1,y1,z1, xg,yg,zg, x3,y3,z3, Map); |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | //================================================================================== |
| 1322 | // function : Remplit |
| 1323 | // purpose : |
| 1324 | //================================================================================== |
| 1325 | void IntPatch_PrmPrmIntersection::Remplit(const Standard_Integer a, |
| 1326 | const Standard_Integer b, |
| 1327 | const Standard_Integer c, |
| 1328 | IntPatch_PrmPrmIntersection_T3Bits& Map) const |
| 1329 | { |
| 1330 | int iax,iay,iaz,ibx,iby,ibz,icx,icy,icz; |
| 1331 | if(a!=-1) Map.Add(a); |
| 1332 | if(b!=-1) Map.Add(b); |
| 1333 | if(c!=-1) Map.Add(c); |
| 1334 | |
| 1335 | if(a!=-1 && b!=-1 && c!=-1 ) { |
| 1336 | IntegerGrille(a,iax,iay,iaz); |
| 1337 | IntegerGrille(b,ibx,iby,ibz); |
| 1338 | IntegerGrille(c,icx,icy,icz); |
| 1339 | RemplitTri(iax,iay,iaz,ibx,iby,ibz,icx,icy,icz,Map); |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | //================================================================================== |
| 1344 | // function : PointDepart |
| 1345 | // purpose : |
| 1346 | //================================================================================== |
| 1347 | void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S, |
| 1348 | const Handle(Adaptor3d_HSurface)& S1, |
| 1349 | const Standard_Integer SU_1, |
| 1350 | const Standard_Integer SV_1, |
| 1351 | const Handle(Adaptor3d_HSurface)& S2, |
| 1352 | const Standard_Integer SU_2, |
| 1353 | const Standard_Integer SV_2) const |
| 1354 | { |
| 1355 | |
| 1356 | Standard_Integer SU1 =SU_1 ; |
| 1357 | Standard_Integer SV1 =SV_1 ; |
| 1358 | Standard_Integer SU2 =SU_2 ; |
| 1359 | Standard_Integer SV2 =SV_2 ; |
| 1360 | |
| 1361 | SU1*=15; |
| 1362 | SU2*=15; |
| 1363 | SV1*=15; |
| 1364 | SV2*=15; |
| 1365 | |
| 1366 | if(NBI<SU1) SU1 = NBI; |
| 1367 | if(NBI<SV1) SV1 = NBI; |
| 1368 | if(NBI<SU2) SU2 = NBI; |
| 1369 | if(NBI<SV2) SV2 = NBI; |
| 1370 | |
| 1371 | //-- cout<<"\n SU1 "<<SU1<<" SV1 "<<SV1<<" SU2 "<<SU2<<" SV2 "<<SV2<<endl; |
| 1372 | Bnd_Box Box1; |
| 1373 | Bnd_Box Box2; |
| 1374 | |
| 1375 | Standard_Real U0 = S1->FirstUParameter(); |
| 1376 | Standard_Real U1 = S1->LastUParameter(); |
| 1377 | Standard_Real V0 = S1->FirstVParameter(); |
| 1378 | Standard_Real V1 = S1->LastVParameter(); |
| 1379 | |
| 1380 | Standard_Real resu0,resu1,resv0,resv1; |
| 1381 | resu0=U0;resu1=U1;resv1=V1;resv0=V0; |
| 1382 | |
| 1383 | Standard_Real du1,du2,dv1,dv2; |
| 1384 | du1 = (U1-U0)/(SU1-1); |
| 1385 | dv1 = (V1-V0)/(SV1-1); |
| 1386 | Standard_Real U,V; |
| 1387 | |
| 1388 | Standard_Integer i,j; |
| 1389 | |
| 1390 | Standard_Real dmaxOn1 = 0.0; |
| 1391 | Standard_Real dmaxOn2 = 0.0; |
| 1392 | |
| 1393 | |
| 1394 | for(U=U0,i=0; i<SU1; i++,U+=du1) { |
| 1395 | for(V=V0,j=0; j<SV1; V+=dv1,j++) { |
| 1396 | P1[i][j] = S1->Value(U,V); |
| 1397 | Box1.Add(P1[i][j]); |
| 1398 | if(i>0 && j>0) { |
| 1399 | Standard_Real x0,y0,z0; |
| 1400 | Standard_Real x1,y1,z1; |
| 1401 | P1[i][j].Coord(x0,y0,z0); |
| 1402 | P1[i-1][j-1].Coord(x1,y1,z1); |
| 1403 | |
| 1404 | Standard_Real d = Abs(x1-x0)+Abs(y1-y0)+Abs(z1-z0); |
| 1405 | if(d>dmaxOn1) dmaxOn1 = d; |
| 1406 | } |
| 1407 | } |
| 1408 | } |
| 1409 | //-- cout<<" P(.,.) du 1 fini "<<endl; |
| 1410 | U0 = S2->FirstUParameter(); |
| 1411 | U1 = S2->LastUParameter(); |
| 1412 | V0 = S2->FirstVParameter(); |
| 1413 | V1 = S2->LastVParameter(); |
| 1414 | |
| 1415 | du2 = (U1-U0)/(SU2-1); dv2 = (V1-V0)/(SV2-1); |
| 1416 | |
| 1417 | for(U=U0,i=0; i<SU2; i++,U+=du2) { |
| 1418 | for(V=V0,j=0; j<SV2; V+=dv2,j++) { |
| 1419 | P2[i][j] = S2->Value(U,V); |
| 1420 | Box2.Add(P2[i][j]); |
| 1421 | if(i>0 && j>0) { |
| 1422 | Standard_Real x0,y0,z0; |
| 1423 | Standard_Real x1,y1,z1; |
| 1424 | P2[i][j].Coord(x0,y0,z0); |
| 1425 | P2[i-1][j-1].Coord(x1,y1,z1); |
| 1426 | |
| 1427 | Standard_Real d = Abs(x1-x0)+Abs(y1-y0)+Abs(z1-z0); |
| 1428 | if(d>dmaxOn2) dmaxOn2 = d; |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | //-- cout<<" P(.,.) du 1 fini "<<endl; |
| 1433 | Box1.Enlarge(1e-8); |
| 1434 | Box2.Enlarge(1e-8); |
| 1435 | |
| 1436 | if(Box1.IsOut(Box2)) { |
| 1437 | //-- cout<<" Rejection entre boites "<<endl; |
| 1438 | return; |
| 1439 | } |
| 1440 | Standard_Real x10,y10,z10,x11,y11,z11; |
| 1441 | Standard_Real x20,y20,z20,x21,y21,z21; |
| 1442 | Standard_Real x0,y0,z0,x1,y1,z1; |
| 1443 | |
| 1444 | Box1.Get(x10,y10,z10,x11,y11,z11); |
| 1445 | Box2.Get(x20,y20,z20,x21,y21,z21); |
| 1446 | x0 = (x10>x20)? x10 : x20; |
| 1447 | y0 = (y10>y20)? y10 : y20; |
| 1448 | z0 = (z10>z20)? z10 : z20; |
| 1449 | |
| 1450 | x1 = (x11<x21)? x11 : x21; |
| 1451 | y1 = (y11<y21)? y11 : y21; |
| 1452 | z1 = (z11<z21)? z11 : z21; |
| 1453 | if(dmaxOn2 > dmaxOn1) dmaxOn1 = dmaxOn2; |
| 1454 | dmaxOn1+=dmaxOn1; |
| 1455 | x0-=dmaxOn1; |
| 1456 | y0-=dmaxOn1; |
| 1457 | z0-=dmaxOn1; |
| 1458 | x1+=dmaxOn1; |
| 1459 | y1+=dmaxOn1; |
| 1460 | z1+=dmaxOn1; |
| 1461 | |
| 1462 | |
| 1463 | x10-=dmaxOn1; y10-=dmaxOn1; z10-=dmaxOn1; |
| 1464 | x11+=dmaxOn1; y11+=dmaxOn1; z11+=dmaxOn1; |
| 1465 | |
| 1466 | x20-=dmaxOn1; y20-=dmaxOn1; z20-=dmaxOn1; |
| 1467 | x21+=dmaxOn1; y21+=dmaxOn1; z21+=dmaxOn1; |
| 1468 | |
| 1469 | |
| 1470 | Standard_Real dx = (x1-x0)/NbPointsGrille(); |
| 1471 | Standard_Real dy = (y1-y0)/NbPointsGrille(); |
| 1472 | Standard_Real dz = (z1-z0)/NbPointsGrille(); |
| 1473 | |
| 1474 | //Standard_Integer INCRX,INCRY,INCRZ; |
| 1475 | |
| 1476 | Standard_Real dmax = dx; |
| 1477 | if(dy>dmax) dmax = dy; |
| 1478 | if(dz>dmax) dmax = dz; |
| 1479 | |
| 1480 | |
| 1481 | if(dx<dmax*0.01) dx = dmax*0.01; |
| 1482 | if(dy<dmax*0.01) dy = dmax*0.01; |
| 1483 | if(dz<dmax*0.01) dz = dmax*0.01; |
| 1484 | Standard_Real dx2 = dx*0.5; |
| 1485 | Standard_Real dy2 = dy*0.5; |
| 1486 | Standard_Real dz2 = dz*0.5 ; |
| 1487 | |
| 1488 | |
| 1489 | |
| 1490 | IntPatch_PrmPrmIntersection_T3Bits M1(_BASE); |
| 1491 | IntPatch_PrmPrmIntersection_T3Bits M2(_BASE); |
| 1492 | |
| 1493 | for(i=0;i<SU1;i++) { |
| 1494 | for(j=0;j<SV1;j++) { |
| 1495 | IP1[i][j]=-1; |
| 1496 | const gp_Pnt& P=P1[i][j]; |
| 1497 | P1DS2[i][j] = CodeReject(x20,y20,z20,x21,y21,z21,P.X(),P.Y(),P.Z()); |
| 1498 | int ix = (int)((P.X()-x0 + dx2 )/dx); |
| 1499 | if(DansGrille(ix)) { |
| 1500 | int iy = (int)((P.Y()-y0 + dy2)/dy); |
| 1501 | if(DansGrille(iy)) { |
| 1502 | int iz = (int)((P.Z()-z0 + dz2)/dz); |
| 1503 | if(DansGrille(iz)) { |
| 1504 | IP1[i][j] = GrilleInteger(ix,iy,iz); |
| 1505 | } |
| 1506 | } |
| 1507 | } |
| 1508 | } |
| 1509 | } |
| 1510 | //-- cout<<" Grille du 1 fini "<<endl; |
| 1511 | for(i=0;i<SU2;i++) { |
| 1512 | for(j=0;j<SV2;j++) { |
| 1513 | IP2[i][j]=-1; |
| 1514 | const gp_Pnt& P=P2[i][j]; |
| 1515 | P2DS1[i][j] = CodeReject(x10,y10,z10,x11,y11,z11,P.X(),P.Y(),P.Z()); |
| 1516 | int ix = (int)((P.X()-x0 + dx2)/dx); |
| 1517 | if(DansGrille(ix)) { |
| 1518 | int iy = (int)((P.Y()-y0 + dy2)/dy); |
| 1519 | if(DansGrille(iy)) { |
| 1520 | int iz = (int)((P.Z()-z0 + dz2)/dz); |
| 1521 | if(DansGrille(iz)) { |
| 1522 | IP2[i][j] = GrilleInteger(ix,iy,iz); |
| 1523 | } |
| 1524 | } |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | //-- cout<<" Grille du 2 fini "<<endl; |
| 1529 | for(i=0;i<SU1-1;i+=1) { |
| 1530 | for(j=0;j<SV1-1;j+=1) { |
| 1531 | if(!((P1DS2[i][j] & P1DS2[i+1][j]) || (P1DS2[i][j] & P1DS2[i+1][j+1])) ) |
| 1532 | Remplit(IP1[i][j],IP1[i+1][j],IP1[i+1][j+1],M1); |
| 1533 | if(!((P1DS2[i][j] & P1DS2[i][j+1]) || (P1DS2[i][j] & P1DS2[i+1][j+1]))) |
| 1534 | Remplit(IP1[i][j],IP1[i][j+1],IP1[i+1][j+1],M1); |
| 1535 | } |
| 1536 | } |
| 1537 | //-- cout<<" Remplissage du 1 fini "<<endl; |
| 1538 | for(i=0;i<SU2-1;i+=1) { |
| 1539 | for(j=0;j<SV2-1;j+=1) { |
| 1540 | if(!((P2DS1[i][j] & P2DS1[i+1][j]) || (P2DS1[i][j] & P2DS1[i+1][j+1]))) |
| 1541 | Remplit(IP2[i][j],IP2[i+1][j],IP2[i+1][j+1],M2); |
| 1542 | if(!((P2DS1[i][j] & P2DS1[i][j+1]) || (P2DS1[i][j] & P2DS1[i+1][j+1]))) |
| 1543 | Remplit(IP2[i][j],IP2[i][j+1],IP2[i+1][j+1],M2); |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | //-- cout<<" Remplissage du 2 fini "<<endl; |
| 1548 | |
| 1549 | |
| 1550 | M1.ResetAnd(); |
| 1551 | M2.ResetAnd(); |
| 1552 | #ifdef DEB |
| 1553 | long unsigned ind=0; |
| 1554 | #endif |
| 1555 | //POP |
| 1556 | int newind=0; |
| 1557 | // long unsigned newind=0; |
| 1558 | long unsigned Compt=0; |
| 1559 | //long unsigned ComptTrouve=0; |
| 1560 | int ok=0; |
| 1561 | int indicepointtraite = 0; |
| 1562 | |
| 1563 | Standard_Integer k; |
| 1564 | Standard_Integer nu,nv; |
| 1565 | |
| 1566 | do { |
| 1567 | indicepointtraite--; |
| 1568 | ok = M1.And(M2,newind); |
| 1569 | if(ok) { |
| 1570 | IntegerGrille(newind,i,j,k); |
| 1571 | |
| 1572 | |
| 1573 | int nb=0; |
| 1574 | int LIM=3; |
| 1575 | if( DansGrille(i-1) && DansGrille(j-1) && DansGrille(k-1) |
| 1576 | && DansGrille(i+1) && DansGrille(j+1) && DansGrille(k+1)) { |
| 1577 | int si,sj,sk; |
| 1578 | for(si=-1; si<= 1 && nb<LIM; si++) { |
| 1579 | for(sj=-1; sj<= 1 && nb<LIM; sj++) { |
| 1580 | for(sk=-1; sk<= 1 && nb<LIM; sk++) { |
| 1581 | long unsigned lu=GrilleInteger(i+si,j+sj,k+sk); |
| 1582 | if(M1.Val(lu) && M2.Val(lu)) { |
| 1583 | nb++; |
| 1584 | } |
| 1585 | } |
| 1586 | } |
| 1587 | } |
| 1588 | if(nb>=LIM) { |
| 1589 | for(si=-1; si<= 1; si++) { |
| 1590 | for(sj=-1; sj<= 1; sj++) { |
| 1591 | for(sk=-1; sk<= 1; sk++) { |
| 1592 | if(si || sj || sk) { |
| 1593 | long unsigned lu=GrilleInteger(i+si,j+sj,k+sk); |
| 1594 | M1.Raz(lu); |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | |
| 1603 | gp_Pnt P(dx*i + x0, dy*j + y0, dz*k+z0); |
| 1604 | |
| 1605 | //Standard_Integer ok12 = 1; |
| 1606 | Standard_Integer nu1=-1,nu2=-1; |
| 1607 | #ifndef DEB |
| 1608 | Standard_Integer nv1=0, nv2=0; |
| 1609 | #else |
| 1610 | Standard_Integer nv1, nv2; |
| 1611 | #endif |
| 1612 | int nbsur1 = 0; |
| 1613 | for(nu=0;nu1<0 && nu<SU1;nu++) { |
| 1614 | for(nv=0;nu1<0 && nv<SV1;nv++) { |
| 1615 | #ifndef DEB |
| 1616 | if( IP1[nu][nv]==(Standard_Integer) newind ) { |
| 1617 | #else |
| 1618 | if( IP1[nu][nv]==newind ) { |
| 1619 | #endif |
| 1620 | nbsur1++; |
| 1621 | IP1[nu][nv]=indicepointtraite; |
| 1622 | nu1=nu; nv1=nv; |
| 1623 | } |
| 1624 | } |
| 1625 | } |
| 1626 | if(nu1>=0) { |
| 1627 | int nbsur2 = 0; |
| 1628 | for(nu=0;nu2<0 && nu<SU2;nu++) { |
| 1629 | for(nv=0;nu2<0 && nv<SV2;nv++) { |
| 1630 | #ifndef DEB |
| 1631 | if( IP2[nu][nv]==(Standard_Integer) newind ) { |
| 1632 | #else |
| 1633 | if( IP2[nu][nv]==newind ) { |
| 1634 | #endif |
| 1635 | nbsur2++; |
| 1636 | IP2[nu][nv]=indicepointtraite; |
| 1637 | nu2=nu; nv2=nv; |
| 1638 | } |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | if(nu1>=0 && nu2>=0) { |
| 1643 | IntSurf_PntOn2S POn2S; |
| 1644 | POn2S.SetValue(P, |
| 1645 | S1->FirstUParameter()+nu1*du1, |
| 1646 | S1->FirstVParameter()+nv1*dv1, |
| 1647 | S2->FirstUParameter()+nu2*du2, |
| 1648 | S2->FirstVParameter()+nv2*dv2); |
| 1649 | LineOn2S->Add(POn2S); |
| 1650 | Compt++; |
| 1651 | } |
| 1652 | else { |
| 1653 | //-- aucun point du triangle n a ete trouve assez proche |
| 1654 | //-- on recherche les 3 points les plus proches de P |
| 1655 | //-- dans chacun des tableaux |
| 1656 | Standard_Real Dist3[3],u3[3],v3[3]; |
| 1657 | Dist3[0]=Dist3[1]=Dist3[2]=RealLast(); |
| 1658 | for(U=resu0,i=0; i<SU1; i++,U+=du1) { |
| 1659 | for(V=resv0,j=0; j<SV1; V+=dv1,j++) { |
| 1660 | //-- On place les 3 meilleures valeurs dans Dist1,Dist2,Dist3 |
| 1661 | Standard_Real t = P1[i][j].SquareDistance(P); |
| 1662 | //-- On remplace la plus grande valeur ds Dist[.] par la val courante |
| 1663 | if(Dist3[0]<Dist3[1]) { |
| 1664 | Standard_Real z; |
| 1665 | z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z; |
| 1666 | z=u3[0]; u3[0]=u3[1]; u3[1]=z; |
| 1667 | z=v3[0]; v3[0]=v3[1]; v3[1]=z; |
| 1668 | } |
| 1669 | if(Dist3[1]<Dist3[2]) { |
| 1670 | Standard_Real z; |
| 1671 | z=Dist3[1]; Dist3[1]=Dist3[2]; Dist3[2]=z; |
| 1672 | z=u3[1]; u3[1]=u3[2]; u3[2]=z; |
| 1673 | z=v3[1]; v3[1]=v3[2]; v3[2]=z; |
| 1674 | } |
| 1675 | if(Dist3[0]<Dist3[1]) { |
| 1676 | Standard_Real z; |
| 1677 | z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z; |
| 1678 | z=u3[0]; u3[0]=u3[1]; u3[1]=z; |
| 1679 | z=v3[0]; v3[0]=v3[1]; v3[1]=z; |
| 1680 | } |
| 1681 | //-- la plus grande valeur est dans Dist3[0] |
| 1682 | if(t<Dist3[0]) { |
| 1683 | Dist3[0]=t; u3[0]=U; v3[0]=V; |
| 1684 | } |
| 1685 | } |
| 1686 | } |
| 1687 | // |
| 1688 | Standard_Real U1_3 = (u3[0]+u3[1]+u3[2])/3.0; |
| 1689 | Standard_Real V1_3 = (v3[0]+v3[1]+v3[2])/3.0; |
| 1690 | |
| 1691 | Dist3[0]=Dist3[1]=Dist3[2]=RealLast(); |
| 1692 | for(U=U0,i=0; i<SU2; i++,U+=du2) { |
| 1693 | for(V=V0,j=0; j<SV2; V+=dv2,j++) { |
| 1694 | //-- On place les 3 meilleures valeurs dans Dist1,Dist2,Dist3 |
| 1695 | Standard_Real t = P2[i][j].SquareDistance(P); |
| 1696 | //-- On remplace la plus grande valeur ds Dist3[.] par la val courante |
| 1697 | if(Dist3[0]<Dist3[1]) { |
| 1698 | Standard_Real z; |
| 1699 | z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z; |
| 1700 | z=u3[0]; u3[0]=u3[1]; u3[1]=z; |
| 1701 | z=v3[0]; v3[0]=v3[1]; v3[1]=z; |
| 1702 | } |
| 1703 | if(Dist3[1]<Dist3[2]) { |
| 1704 | Standard_Real z; |
| 1705 | z=Dist3[1]; Dist3[1]=Dist3[2]; Dist3[2]=z; |
| 1706 | z=u3[1]; u3[1]=u3[2]; u3[2]=z; |
| 1707 | z=v3[1]; v3[1]=v3[2]; v3[2]=z; |
| 1708 | } |
| 1709 | if(Dist3[0]<Dist3[1]) { |
| 1710 | Standard_Real z; |
| 1711 | z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z; |
| 1712 | z=u3[0]; u3[0]=u3[1]; u3[1]=z; |
| 1713 | z=v3[0]; v3[0]=v3[1]; v3[1]=z; |
| 1714 | } |
| 1715 | //-- la plus grande valeur est dans Dist3[0] |
| 1716 | if(t<Dist3[0]) { |
| 1717 | Dist3[0]=t; u3[0]=U; v3[0]=V; |
| 1718 | } |
| 1719 | } |
| 1720 | } |
| 1721 | // |
| 1722 | Standard_Real U2_3 = (u3[0]+u3[1]+u3[2])/3.0; |
| 1723 | Standard_Real V2_3 = (v3[0]+v3[1]+v3[2])/3.0; |
| 1724 | |
| 1725 | IntSurf_PntOn2S POn2S; |
| 1726 | POn2S.SetValue(P,U1_3,V1_3,U2_3,V2_3); |
| 1727 | LineOn2S->Add(POn2S); |
| 1728 | Compt++; |
| 1729 | } |
| 1730 | } |
| 1731 | } |
| 1732 | while(ok); |
| 1733 | } |
| 1734 | |
| 1735 | //================================================================================== |
| 1736 | // function : Perform |
| 1737 | // purpose : base SS Int. function |
| 1738 | //================================================================================== |
| 1739 | void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1, |
| 1740 | const Handle(Adaptor3d_TopolTool)& D1, |
| 1741 | const Handle(Adaptor3d_HSurface)& Surf2, |
| 1742 | const Handle(Adaptor3d_TopolTool)& D2, |
| 1743 | const Standard_Real TolTangency, |
| 1744 | const Standard_Real Epsilon, |
| 1745 | const Standard_Real Deflection, |
| 1746 | const Standard_Real Increment, |
| 1747 | const Standard_Boolean ClearFlag) |
| 1748 | { |
| 1749 | |
| 1750 | D1->SamplePnts(Deflection, 10, 10); |
| 1751 | D2->SamplePnts(Deflection, 10, 10); |
| 1752 | |
| 1753 | //================================================================================= |
| 1754 | Standard_Integer NbU1 = D1->NbSamplesU(); |
| 1755 | Standard_Integer NbV1 = D1->NbSamplesV(); |
| 1756 | Standard_Integer NbU2 = D2->NbSamplesU(); |
| 1757 | Standard_Integer NbV2 = D2->NbSamplesV(); |
| 1758 | TColStd_Array1OfReal anUpars1(1, NbU1), aVpars1(1, NbV1); |
| 1759 | TColStd_Array1OfReal anUpars2(1, NbU2), aVpars2(1, NbV2); |
| 1760 | D1->UParameters(anUpars1); D1->VParameters(aVpars1); |
| 1761 | D2->UParameters(anUpars2); D2->VParameters(aVpars2); |
| 1762 | //======================================================================= |
| 1763 | Standard_Integer Limit = 2500; |
| 1764 | |
| 1765 | if((NbU1*NbV1<=Limit && NbV2*NbU2<=Limit)) { |
| 1766 | empt = Standard_True; |
| 1767 | // modified by NIZHNY-AMV Tue Oct 18 12:37:02 2005.BEGIN |
| 1768 | if (ClearFlag) |
| 1769 | SLin.Clear(); |
| 1770 | // modified by NIZHNY-AMV Tue Oct 18 12:37:02 2005.END |
| 1771 | // |
| 1772 | //IntPolyh_Intersection Interference(Surf1,NbU1,NbV1,Surf2,NbU2,NbV2); |
| 1773 | // IntPolyh_Intersection Interference(Surf1, anUpars1, aVpars1, |
| 1774 | // Surf2, anUpars2, aVpars2); |
| 1775 | |
| 1776 | IntPolyh_Intersection* pInterference = NULL; |
| 1777 | |
| 1778 | if ( D1->IsUniformSampling() || D2->IsUniformSampling() ) { |
| 1779 | pInterference = new IntPolyh_Intersection(Surf1,NbU1,NbV1,Surf2,NbU2,NbV2); |
| 1780 | } |
| 1781 | else { |
| 1782 | pInterference = new IntPolyh_Intersection(Surf1, anUpars1, aVpars1, |
| 1783 | Surf2, anUpars2, aVpars2 ); |
| 1784 | } |
| 1785 | if ( !pInterference ) { |
| 1786 | done = Standard_False; |
| 1787 | return; |
| 1788 | } |
| 1789 | // |
| 1790 | IntPolyh_Intersection& Interference = *pInterference; |
| 1791 | // |
| 1792 | done = Interference.IsDone(); |
| 1793 | if( !done ) { |
| 1794 | if ( pInterference ) { |
| 1795 | delete pInterference; |
| 1796 | pInterference = NULL; |
| 1797 | } |
| 1798 | return; |
| 1799 | } |
| 1800 | |
| 1801 | Standard_Real Deflection2 = Deflection*Deflection; |
| 1802 | Standard_Integer nbLigSec = Interference.NbSectionLines(); |
| 1803 | Standard_Integer nbTanZon = Interference.NbTangentZones(); |
| 1804 | Standard_Real SeuildPointLigne = 15.0 * Increment * Increment; |
| 1805 | |
| 1806 | Standard_Integer NbPntOn2SOnLine = 0, NbLigCalculee = 0, ver; |
| 1807 | Standard_Real U1,U2,V1,V2, pu1,pu2,pv1,pv2, incidence, dminiPointLigne; |
| 1808 | Standard_Boolean HasStartPoint,RejetLigne; |
| 1809 | IntSurf_PntOn2S StartPOn2S; |
| 1810 | gp_Pnt Point3dDebut,Point3dFin; |
| 1811 | |
| 1812 | TColStd_Array1OfReal StartParams(1,4); |
| 1813 | IntPatch_ThePWalkingInter PW(Surf1,Surf2,TolTangency,Epsilon,Deflection,Increment); |
| 1814 | |
| 1815 | if(nbLigSec>=1) { |
| 1816 | Standard_Integer *TabL = new Standard_Integer [nbLigSec+1]; |
| 1817 | Standard_Integer ls; |
| 1818 | for(ls=1;ls<=nbLigSec;ls++) |
| 1819 | TabL[ls]=ls; |
| 1820 | |
| 1821 | Standard_Boolean triok; |
| 1822 | do { |
| 1823 | triok=Standard_True; |
| 1824 | Standard_Integer b; |
| 1825 | for( b = 2; b <= nbLigSec; b++ ) { |
| 1826 | Standard_Integer nb_B = Interference.NbPointsInLine(TabL[b]); |
| 1827 | Standard_Integer nb_A = Interference.NbPointsInLine(TabL[b-1]); |
| 1828 | if( nb_B > nb_A ) { |
| 1829 | Standard_Integer tyu=TabL[b]; |
| 1830 | TabL[b]=TabL[b-1]; |
| 1831 | TabL[b-1]=tyu; |
| 1832 | triok=Standard_False; |
| 1833 | } |
| 1834 | } |
| 1835 | } while(triok==Standard_False); |
| 1836 | // |
| 1837 | for( ls = 1; ls <= nbLigSec; ls++) { |
| 1838 | Standard_Integer nbp, ilig, *TabPtDep; |
| 1839 | // |
| 1840 | nbp = Interference.NbPointsInLine(TabL[ls]); |
| 1841 | //modified by NIZNHY-PKV Fri Sep 5 15:19:28 2008f |
| 1842 | if (!nbp) { |
| 1843 | continue; |
| 1844 | } |
| 1845 | //modified by NIZNHY-PKV Fri Sep 5 15:19:31 2008t |
| 1846 | TabPtDep = new Standard_Integer [nbp+1]; |
| 1847 | // |
| 1848 | for( ilig = 1; ilig <= nbp; ilig++ ) |
| 1849 | TabPtDep[ilig]=0; |
| 1850 | |
| 1851 | Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1; |
| 1852 | Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2; |
| 1853 | Standard_Real _x,_y,_z; |
| 1854 | |
| 1855 | Interference.GetLinePoint(TabL[ls],1,_x,_y,_z,UminLig1,VminLig1,UminLig2,VminLig2,incidence); |
| 1856 | |
| 1857 | UmaxLig1=UminLig1; |
| 1858 | VmaxLig1=VminLig1; |
| 1859 | UmaxLig2=UminLig2; |
| 1860 | VmaxLig2=VminLig2; |
| 1861 | |
| 1862 | for( ilig = 2; ilig <= nbp; ilig++ ) { |
| 1863 | Interference.GetLinePoint(TabL[ls],ilig,_x,_y,_z,U1,V1,U2,V2,incidence); |
| 1864 | |
| 1865 | if(U1>UmaxLig1) UmaxLig1=U1; |
| 1866 | if(V1>VmaxLig1) VmaxLig1=V1; |
| 1867 | if(U2>UmaxLig2) UmaxLig2=U2; |
| 1868 | if(V2>VmaxLig2) VmaxLig2=V2; |
| 1869 | |
| 1870 | if(U1<UminLig1) UminLig1=U1; |
| 1871 | if(V1<VminLig1) VminLig1=V1; |
| 1872 | if(U2<UminLig2) UminLig2=U2; |
| 1873 | if(V2<VminLig2) VminLig2=V2; |
| 1874 | } |
| 1875 | |
| 1876 | Standard_Integer nbps2 = (nbp>3)? (nbp/2) : 1; |
| 1877 | Standard_Integer NombreDePointsDeDepartDuCheminement = 0; |
| 1878 | Standard_Boolean lignetrouvee=Standard_False; |
| 1879 | const Standard_Integer NbDePointsDeDepartDuChmLimit = 5; |
| 1880 | // |
| 1881 | do { |
| 1882 | NombreDePointsDeDepartDuCheminement++; |
| 1883 | switch (NombreDePointsDeDepartDuCheminement) { |
| 1884 | case 1: |
| 1885 | nbps2 = (nbp > 1) ? nbp/2 : 1; |
| 1886 | if(nbp<3) |
| 1887 | NombreDePointsDeDepartDuCheminement = NbDePointsDeDepartDuChmLimit; |
| 1888 | break; |
| 1889 | case 2: |
| 1890 | nbps2 = 1; |
| 1891 | break; |
| 1892 | case 3: |
| 1893 | nbps2 = nbp-1; |
| 1894 | break; |
| 1895 | case 4: |
| 1896 | nbps2 = 3 * nbp / 4; |
| 1897 | break; |
| 1898 | case 5: |
| 1899 | nbps2 = nbp / 4; |
| 1900 | break; |
| 1901 | default: |
| 1902 | nbps2 = NombreDePointsDeDepartDuCheminement-3; |
| 1903 | NombreDePointsDeDepartDuCheminement++; |
| 1904 | } |
| 1905 | // |
| 1906 | if(TabPtDep[nbps2] == 0) { |
| 1907 | TabPtDep[nbps2] = 1; |
| 1908 | Interference.GetLinePoint(TabL[ls],nbps2,_x,_y,_z,U1,V1,U2,V2,incidence); |
| 1909 | |
| 1910 | StartParams(1) = U1; |
| 1911 | StartParams(2) = V1; |
| 1912 | StartParams(3) = U2; |
| 1913 | StartParams(4) = V2; |
| 1914 | |
| 1915 | HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S); |
| 1916 | dminiPointLigne = SeuildPointLigne + SeuildPointLigne; |
| 1917 | if(HasStartPoint) { |
| 1918 | StartPOn2S.Parameters(pu1,pv1,pu2,pv2); |
| 1919 | NbLigCalculee = SLin.Length(); |
| 1920 | Standard_Integer l; |
| 1921 | for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { |
| 1922 | Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l)); |
| 1923 | if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) && |
| 1924 | (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) && |
| 1925 | (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) { |
| 1926 | NbPntOn2SOnLine = testwline->NbPnts(); |
| 1927 | Standard_Integer ll; |
| 1928 | for( ll = 1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) { |
| 1929 | const gp_Pnt &Pa = testwline->Point(ll).Value(); |
| 1930 | const gp_Pnt &Pb = testwline->Point(ll+1).Value(); |
| 1931 | const gp_Pnt &PStart = StartPOn2S.Value(); |
| 1932 | gp_Vec AM(Pa,PStart); |
| 1933 | gp_Vec MB(PStart,Pb); |
| 1934 | Standard_Real AMMB = AM.Dot(MB); |
| 1935 | if(AMMB > 0.0) { |
| 1936 | gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z()); |
| 1937 | Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z(); |
| 1938 | gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z()); |
| 1939 | gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z()); |
| 1940 | Standard_Real d = 0.0; |
| 1941 | if(HM.X() < Deflection) { |
| 1942 | d+=HM.X()*HM.X(); |
| 1943 | if(HM.Y() < Deflection) { |
| 1944 | d+=HM.Y()*HM.Y(); |
| 1945 | if(HM.Z() < Deflection) |
| 1946 | d+=HM.Z()*HM.Z(); |
| 1947 | else |
| 1948 | d=Deflection2; |
| 1949 | } |
| 1950 | else |
| 1951 | d=Deflection2; |
| 1952 | } |
| 1953 | else |
| 1954 | d=Deflection2; |
| 1955 | |
| 1956 | if(d<Deflection2) |
| 1957 | dminiPointLigne = 0.0; |
| 1958 | } |
| 1959 | else { |
| 1960 | Standard_Real dab = Pa.SquareDistance(Pb); |
| 1961 | Standard_Real dap = Pa.SquareDistance(PStart); |
| 1962 | if(dap < dab) |
| 1963 | dminiPointLigne=0; |
| 1964 | else { |
| 1965 | Standard_Real dbp = Pb.SquareDistance(PStart); |
| 1966 | if(dbp < dab) |
| 1967 | dminiPointLigne=0; |
| 1968 | } |
| 1969 | } |
| 1970 | }// for( ll ... |
| 1971 | }// if ... |
| 1972 | }// for( l ... |
| 1973 | |
| 1974 | if(dminiPointLigne > SeuildPointLigne) { |
| 1975 | PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2); |
| 1976 | //xf |
| 1977 | Standard_Boolean bPWIsDone; |
| 1978 | Standard_Integer iPWNbPoints, aNbPointsVer; |
| 1979 | Standard_Real aD11, aD12, aD21, aD22, aDx; |
| 1980 | // |
| 1981 | bPWIsDone=PW.IsDone(); |
| 1982 | //xt |
| 1983 | if(bPWIsDone) { |
| 1984 | iPWNbPoints=PW.NbPoints(); |
| 1985 | // |
| 1986 | if( iPWNbPoints > 2 ) { |
| 1987 | RejetLigne = Standard_False; |
| 1988 | Point3dDebut = PW.Value(1).Value(); |
| 1989 | Point3dFin = PW.Value(PW.NbPoints()).Value(); |
| 1990 | for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { |
| 1991 | const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver)); |
| 1992 | // |
| 1993 | aNbPointsVer=verwline->NbPnts(); |
| 1994 | if (aNbPointsVer<3) { |
| 1995 | continue; |
| 1996 | } |
| 1997 | // |
| 1998 | const IntSurf_PntOn2S& verPointDebut = verwline->Point(1); |
| 1999 | const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts()); |
| 2000 | //xf |
| 2001 | const gp_Pnt& aP21=verPointDebut.Value(); |
| 2002 | const gp_Pnt& aP22=verPointFin.Value(); |
| 2003 | // |
| 2004 | aD11=Point3dDebut.Distance(aP21); |
| 2005 | aD12=Point3dDebut.Distance(aP22); |
| 2006 | aD21=Point3dFin.Distance(aP21); |
| 2007 | aD22=Point3dFin.Distance(aP22); |
| 2008 | // |
| 2009 | if((aD11<=TolTangency && aD22<=TolTangency) || |
| 2010 | (aD12<=TolTangency && aD21<=TolTangency)) { |
| 2011 | Standard_Integer m, mx; |
| 2012 | // |
| 2013 | mx=aNbPointsVer/2; |
| 2014 | if (aNbPointsVer%2) { |
| 2015 | ++mx; |
| 2016 | } |
| 2017 | // |
| 2018 | const gp_Pnt& aPx=verwline->Point(mx).Value(); |
| 2019 | for(m=1; m<iPWNbPoints; ++m){ |
| 2020 | const gp_Pnt& aP1=PW.Value(m).Value(); |
| 2021 | const gp_Pnt& aP2=PW.Value(m+1).Value(); |
| 2022 | gp_Vec aVec12(aP1, aP2); |
| 2023 | if (aVec12.SquareMagnitude()<1.e-20){ |
| 2024 | continue; |
| 2025 | } |
| 2026 | // |
| 2027 | gp_Dir aDir12(aVec12); |
| 2028 | gp_Lin aLin12(aP1, aDir12); |
| 2029 | aDx=aLin12.Distance(aPx); |
| 2030 | if (aDx<=TolTangency) { |
| 2031 | RejetLigne = Standard_True; |
| 2032 | break; |
| 2033 | } |
| 2034 | } |
| 2035 | } |
| 2036 | } |
| 2037 | // |
| 2038 | if(!RejetLigne) { |
| 2039 | IntSurf_TypeTrans trans1,trans2; |
| 2040 | Standard_Real locu,locv; |
| 2041 | gp_Vec norm1,norm2,d1u,d1v; |
| 2042 | gp_Pnt ptbid; |
| 2043 | Standard_Integer indextg; |
| 2044 | gp_Vec tgline(PW.TangentAtLine(indextg)); |
| 2045 | PW.Line()->Value(indextg).ParametersOnS1(locu,locv); |
| 2046 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 2047 | norm1 = d1u.Crossed(d1v); |
| 2048 | PW.Line()->Value(indextg).ParametersOnS2(locu,locv); |
| 2049 | Surf2->D1(locu,locv,ptbid,d1u,d1v); |
| 2050 | norm2 = d1u.Crossed(d1v); |
| 2051 | if( tgline.DotCross(norm2,norm1) >= 0. ) { |
| 2052 | trans1 = IntSurf_Out; |
| 2053 | trans2 = IntSurf_In; |
| 2054 | } |
| 2055 | else { |
| 2056 | trans1 = IntSurf_In; |
| 2057 | trans2 = IntSurf_Out; |
| 2058 | } |
| 2059 | |
| 2060 | Standard_Real TolTang = TolTangency; |
| 2061 | Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2); |
| 2062 | IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang); |
| 2063 | IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang); |
| 2064 | |
| 2065 | if(wline->NbVertex() == 0) { |
| 2066 | IntPatch_Point vtx; |
| 2067 | IntSurf_PntOn2S POn2S = PW.Line()->Value(1); |
| 2068 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 2069 | vtx.SetValue(Point3dDebut,TolTang,Standard_False); |
| 2070 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 2071 | vtx.SetParameter(1); |
| 2072 | wline->AddVertex(vtx); |
| 2073 | |
| 2074 | POn2S = PW.Line()->Value(wline->NbPnts()); |
| 2075 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 2076 | vtx.SetValue(Point3dFin,TolTang,Standard_False); |
| 2077 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 2078 | vtx.SetParameter(wline->NbPnts()); |
| 2079 | wline->AddVertex(vtx); |
| 2080 | } |
| 2081 | |
| 2082 | lignetrouvee = Standard_True; |
| 2083 | |
| 2084 | Standard_Integer slinlen = SLin.Length(); |
| 2085 | if( slinlen > 0 ) { |
| 2086 | Standard_Integer cnbV = wline->NbVertex(); |
| 2087 | Standard_Integer ciV; |
| 2088 | for( ciV = 1; ciV <= cnbV; ciV++ ) { |
| 2089 | Standard_Real pntDMin = 1.e+100; |
| 2090 | Standard_Integer VDMin = 0; |
| 2091 | Standard_Integer WLDMin = 0; |
| 2092 | gp_Pnt cPV = wline->Vertex(ciV).Value(); |
| 2093 | Standard_Integer iL; |
| 2094 | for( iL = 1; iL <= slinlen; iL++) { |
| 2095 | const Handle(IntPatch_Line)& aSLine = SLin.Value(iL); |
| 2096 | IntPatch_IType aType = aSLine->ArcType(); |
| 2097 | if( aType != IntPatch_Walking) |
| 2098 | continue; |
| 2099 | const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&aSLine)); |
| 2100 | Standard_Integer tnbV = aWLine->NbVertex(); |
| 2101 | Standard_Integer tiV; |
| 2102 | for( tiV = 1; tiV <= tnbV; tiV++ ) { |
| 2103 | gp_Pnt tPV = aWLine->Vertex(tiV).Value(); |
| 2104 | Standard_Real tDistance = cPV.Distance(tPV); |
| 2105 | Standard_Real uRs1 = Surf1->Surface().UResolution(tDistance); |
| 2106 | Standard_Real vRs1 = Surf1->Surface().VResolution(tDistance); |
| 2107 | Standard_Real uRs2 = Surf2->Surface().UResolution(tDistance); |
| 2108 | Standard_Real vRs2 = Surf2->Surface().VResolution(tDistance); |
| 2109 | Standard_Real RmaxS1 = Max(uRs1,vRs1); |
| 2110 | Standard_Real RmaxS2 = Max(uRs2,vRs2); |
| 2111 | if(RmaxS1 < 1.e-4 && RmaxS2 < 1.e-4) { |
| 2112 | if( pntDMin > tDistance && tDistance > 1.e-9) { |
| 2113 | pntDMin = tDistance; |
| 2114 | VDMin = tiV; |
| 2115 | WLDMin = iL; |
| 2116 | } |
| 2117 | } |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | if( VDMin != 0 ) { |
| 2122 | const Handle(IntPatch_Line)& aSLine = SLin.Value(WLDMin); |
| 2123 | const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&aSLine)); |
| 2124 | Standard_Integer tiVpar = (Standard_Integer)aWLine->Vertex(VDMin).ParameterOnLine(); |
| 2125 | Standard_Integer ciVpar = (Standard_Integer)wline->Vertex(ciV).ParameterOnLine(); |
| 2126 | Standard_Real u11 = 0., u12 = 0., v11 = 0., v12 = 0.; |
| 2127 | Standard_Real u21 = 0., u22 = 0., v21 = 0., v22 = 0.; |
| 2128 | wline->Point(ciVpar).Parameters(u11,v11,u12,v12); |
| 2129 | aWLine->Point(tiVpar).Parameters(u21,v21,u22,v22); |
| 2130 | |
| 2131 | Handle(IntSurf_LineOn2S) newL2s = new IntSurf_LineOn2S(); |
| 2132 | IntSurf_PntOn2S replacePnt = aWLine->Point(tiVpar); |
| 2133 | Standard_Integer cNbP = wline->NbPnts(); |
| 2134 | |
| 2135 | TColStd_SequenceOfInteger VPold; |
| 2136 | Standard_Integer iPo; |
| 2137 | for( iPo = 1; iPo <= cnbV; iPo++ ) { |
| 2138 | Standard_Real Po = wline->Vertex(iPo).ParameterOnLine(); |
| 2139 | Standard_Integer IPo = (Standard_Integer) Po; |
| 2140 | VPold.Append(IPo); |
| 2141 | } |
| 2142 | |
| 2143 | Standard_Boolean removeNext = Standard_False; |
| 2144 | Standard_Boolean removePrev = Standard_False; |
| 2145 | if( ciV == 1) { |
| 2146 | Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV+1)); |
| 2147 | if(dPar > 10) { |
| 2148 | removeNext = Standard_True; |
| 2149 | for( iPo = (ciV+1); iPo <= cnbV; iPo++ ) |
| 2150 | VPold.SetValue(iPo, VPold.Value(iPo) - 1 ); |
| 2151 | } |
| 2152 | } |
| 2153 | else if( ciV == cnbV) { |
| 2154 | Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV-1)); |
| 2155 | if(dPar > 10) { |
| 2156 | removePrev = Standard_True; |
| 2157 | VPold.SetValue(ciV, VPold.Value(ciV) - 1 ); |
| 2158 | } |
| 2159 | } |
| 2160 | else { |
| 2161 | Standard_Integer dParMi = Abs( VPold.Value(ciV) - VPold.Value(ciV-1)); |
| 2162 | Standard_Integer dParMa = Abs( VPold.Value(ciV) - VPold.Value(ciV+1)); |
| 2163 | if(dParMi > 10) { |
| 2164 | removePrev = Standard_True; |
| 2165 | VPold.SetValue(ciV, VPold.Value(ciV) - 1 ); |
| 2166 | } |
| 2167 | if(dParMa > 10) { |
| 2168 | removeNext = Standard_True; |
| 2169 | for( iPo = (ciV+1); iPo <= cnbV; iPo++ ) { |
| 2170 | if(dParMi > 10) |
| 2171 | VPold.SetValue(iPo, VPold.Value(iPo) - 2 ); |
| 2172 | else |
| 2173 | VPold.SetValue(iPo, VPold.Value(iPo) - 1 ); |
| 2174 | } |
| 2175 | } |
| 2176 | else { |
| 2177 | if(dParMi > 10) |
| 2178 | for( iPo = (ciV+1); iPo <= cnbV; iPo++ ) |
| 2179 | VPold.SetValue(iPo, VPold.Value(iPo) - 1 ); |
| 2180 | } |
| 2181 | } |
| 2182 | Standard_Integer pI = (Standard_Integer) ciVpar; |
| 2183 | |
| 2184 | Standard_Integer iP; |
| 2185 | for( iP = 1; iP <= cNbP; iP++) { |
| 2186 | if( pI == iP ) |
| 2187 | newL2s->Add(replacePnt); |
| 2188 | else if(removeNext && iP == (pI + 1)) |
| 2189 | continue; |
| 2190 | else if(removePrev && iP == (pI - 1)) |
| 2191 | continue; |
| 2192 | else |
| 2193 | newL2s->Add(wline->Point(iP)); |
| 2194 | } |
| 2195 | |
| 2196 | IntPatch_Point newVtx; |
| 2197 | gp_Pnt Pnt3dV = aWLine->Vertex(VDMin).Value(); |
| 2198 | newVtx.SetValue(Pnt3dV,TolTang,Standard_False); |
| 2199 | newVtx.SetParameters(u21,v21,u22,v22); |
| 2200 | newVtx.SetParameter(VPold.Value(ciV)); |
| 2201 | |
| 2202 | Handle(IntPatch_WLine) NWLine = new IntPatch_WLine(newL2s,Standard_False,trans1,trans2); |
| 2203 | |
| 2204 | Standard_Integer iV; |
| 2205 | for( iV = 1; iV <= cnbV; iV++ ) { |
| 2206 | if( iV == ciV ) |
| 2207 | NWLine->AddVertex(newVtx); |
| 2208 | else { |
| 2209 | IntPatch_Point theVtx = wline->Vertex(iV); |
| 2210 | theVtx.SetParameter(VPold.Value(iV)); |
| 2211 | NWLine->AddVertex(theVtx); |
| 2212 | } |
| 2213 | } |
| 2214 | |
| 2215 | wline = NWLine; |
| 2216 | } |
| 2217 | } |
| 2218 | }// SLin.Length > 0 |
| 2219 | |
| 2220 | SLin.Append(wline); |
| 2221 | empt = Standard_False; |
| 2222 | }// !RejetLigne |
| 2223 | }// PW points > 2 |
| 2224 | }// done is True |
| 2225 | }// dminiPointLigne > SeuildPointLigne |
| 2226 | }// HasStartPoint |
| 2227 | }// if TabPtDep[nbps2] == 0 |
| 2228 | } while(nbp>5 && !( (NombreDePointsDeDepartDuCheminement >= NbDePointsDeDepartDuChmLimit && lignetrouvee) || |
| 2229 | (NombreDePointsDeDepartDuCheminement-3 >= nbp && (!lignetrouvee)))); |
| 2230 | delete [] TabPtDep; |
| 2231 | }// for( ls ... |
| 2232 | |
| 2233 | delete [] TabL; |
| 2234 | |
| 2235 | }// if nbLigSec >= 1 |
| 2236 | // |
| 2237 | AdjustOnPeriodic(Surf1, Surf2, SLin); |
| 2238 | // |
| 2239 | |
| 2240 | //-------------------------------------------------------------------- |
| 2241 | //-- Calcul des parametres approches a partir des Zones De Tangence -- |
| 2242 | //-------------------------------------------------------------------- |
| 2243 | Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1; |
| 2244 | Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2; |
| 2245 | |
| 2246 | UminLig1=VminLig1=UminLig2=VminLig2=RealLast(); |
| 2247 | UmaxLig1=VmaxLig1=UmaxLig2=VmaxLig2=-UminLig1; |
| 2248 | |
| 2249 | // NbPointsInTangentZone always == 1 (eap) |
| 2250 | |
| 2251 | Standard_Integer z; |
| 2252 | for( z=1; z <= nbTanZon; z++) { |
| 2253 | //Standard_Integer NbPointsInTangentZone=Interference.NbPointsInTangentZone(z); |
| 2254 | //for(Standard_Integer pz=1; pz<=NbPointsInTangentZone; pz++) { |
| 2255 | Standard_Integer pz=1; |
| 2256 | Standard_Real _x,_y,_z; |
| 2257 | Interference.GetTangentZonePoint(z,pz,_x,_y,_z,U1,V1,U2,V2); |
| 2258 | |
| 2259 | if(U1>UmaxLig1) UmaxLig1=U1; |
| 2260 | if(V1>VmaxLig1) VmaxLig1=V1; |
| 2261 | if(U2>UmaxLig2) UmaxLig2=U2; |
| 2262 | if(V2>VmaxLig2) VmaxLig2=V2; |
| 2263 | |
| 2264 | if(U1<UminLig1) UminLig1=U1; |
| 2265 | if(V1<VminLig1) VminLig1=V1; |
| 2266 | if(U2<UminLig2) UminLig2=U2; |
| 2267 | if(V2<VminLig2) VminLig2=V2; |
| 2268 | //} |
| 2269 | } |
| 2270 | for(z=1; z <= nbTanZon; z++) { |
| 2271 | |
| 2272 | //Standard_Integer NbPointsInTangentZone=Interference.NbPointsInTangentZone(z); |
| 2273 | //for(Standard_Integer pz=1; pz<=NbPointsInTangentZone; pz++) { |
| 2274 | Standard_Integer pz=1; |
| 2275 | Standard_Real _x,_y,_z; |
| 2276 | Interference.GetTangentZonePoint(z,pz,_x,_y,_z,U1,V1,U2,V2); |
| 2277 | |
| 2278 | StartParams(1) = U1; |
| 2279 | StartParams(2) = V1; |
| 2280 | StartParams(3) = U2; |
| 2281 | StartParams(4) = V2; |
| 2282 | |
| 2283 | //----------------------------------------------------------------------- |
| 2284 | //-- Calcul du premier point de cheminement a partir du point approche -- |
| 2285 | //----------------------------------------------------------------------- |
| 2286 | HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S); |
| 2287 | if(HasStartPoint) { |
| 2288 | //------------------------------------------------- |
| 2289 | //-- Un point a ete trouve -- |
| 2290 | //-- On verifie qu il n appartient pas -- |
| 2291 | //-- a une ligne de cheminement deja calculee. -- |
| 2292 | //------------------------------------------------- |
| 2293 | StartPOn2S.Parameters(pu1,pv1,pu2,pv2); |
| 2294 | |
| 2295 | NbLigCalculee = SLin.Length(); |
| 2296 | dminiPointLigne = SeuildPointLigne + SeuildPointLigne; |
| 2297 | |
| 2298 | for(Standard_Integer l=1; |
| 2299 | (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); |
| 2300 | l++) { |
| 2301 | Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l)); |
| 2302 | |
| 2303 | if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) |
| 2304 | &&(testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) |
| 2305 | &&(testwline->IsOutBox(StartPOn2S.Value())==Standard_False)) { |
| 2306 | |
| 2307 | |
| 2308 | //-- Handle(IntPatch_WLine) testwline=Handle(IntPatch_WLine)::DownCast(SLin.Value(l)); |
| 2309 | NbPntOn2SOnLine = testwline->NbPnts(); |
| 2310 | for(Standard_Integer ll=1; |
| 2311 | (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); |
| 2312 | ll++) { |
| 2313 | const gp_Pnt& Pa = testwline->Point(ll).Value(); |
| 2314 | const gp_Pnt& Pb = testwline->Point(ll+1).Value(); |
| 2315 | const gp_Pnt& PStart=StartPOn2S.Value(); |
| 2316 | gp_Vec AM(Pa,PStart); |
| 2317 | gp_Vec MB(PStart,Pb); |
| 2318 | Standard_Real AMMB = AM.Dot(MB); |
| 2319 | if(AMMB > 0.0) { |
| 2320 | gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z()); |
| 2321 | Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z(); |
| 2322 | gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z()); |
| 2323 | gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z()); |
| 2324 | |
| 2325 | Standard_Real d = 0.0; |
| 2326 | if(HM.X() < Deflection) { |
| 2327 | d+=HM.X()*HM.X(); |
| 2328 | if(HM.Y() < Deflection) { |
| 2329 | d+=HM.Y()*HM.Y(); |
| 2330 | if(HM.Z() < Deflection) { |
| 2331 | d+=HM.Z()*HM.Z(); |
| 2332 | } |
| 2333 | else { |
| 2334 | d=Deflection2; |
| 2335 | } |
| 2336 | } |
| 2337 | else { |
| 2338 | d=Deflection2; |
| 2339 | } |
| 2340 | } |
| 2341 | else { |
| 2342 | d=Deflection2; |
| 2343 | } |
| 2344 | if(d<Deflection2) { |
| 2345 | dminiPointLigne = 0.0; |
| 2346 | } |
| 2347 | } |
| 2348 | else { |
| 2349 | Standard_Real dab = Pa.Distance(Pb); |
| 2350 | Standard_Real dap = Pa.Distance(PStart); |
| 2351 | if(dap < dab) { |
| 2352 | dminiPointLigne=0; |
| 2353 | } |
| 2354 | else { |
| 2355 | Standard_Real dbp = Pb.Distance(PStart); |
| 2356 | if(dbp < dab) { |
| 2357 | dminiPointLigne=0; |
| 2358 | } |
| 2359 | } |
| 2360 | } |
| 2361 | } |
| 2362 | } //-- rejection sur les boites |
| 2363 | } |
| 2364 | |
| 2365 | |
| 2366 | //-- Fin d exploration des lignes |
| 2367 | if(dminiPointLigne > SeuildPointLigne) { |
| 2368 | //--------------------------------------------------- |
| 2369 | //-- Le point de depart du nouveau cheminement -- |
| 2370 | //-- n est present dans aucune ligne deja calculee.-- |
| 2371 | //--------------------------------------------------- |
| 2372 | PW.Perform(StartParams, |
| 2373 | UminLig1,VminLig1,UminLig2,VminLig2, |
| 2374 | UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2); |
| 2375 | if(PW.IsDone()) { |
| 2376 | if(PW.NbPoints()>2) { |
| 2377 | //----------------------------------------------- |
| 2378 | //-- Verification a posteriori : |
| 2379 | //-- On teste si le point de depart et de fin de |
| 2380 | //-- la ligne de cheminement est present dans une |
| 2381 | //-- autre ligne . |
| 2382 | //----------------------------------------------- |
| 2383 | RejetLigne = Standard_False; |
| 2384 | Point3dDebut = PW.Value(1).Value(); |
| 2385 | Point3dFin = PW.Value(PW.NbPoints()).Value(); |
| 2386 | |
| 2387 | for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { |
| 2388 | const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver)); |
| 2389 | //-- Handle(IntPatch_WLine) verwline=Handle(IntPatch_WLine)::DownCast(SLin.Value(ver)); |
| 2390 | const IntSurf_PntOn2S& verPointDebut = verwline->Point(1); |
| 2391 | const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts()); |
| 2392 | if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency) { |
| 2393 | RejetLigne = Standard_True; |
| 2394 | } |
| 2395 | else { |
| 2396 | if(Point3dFin.Distance(verPointFin.Value()) < TolTangency) { |
| 2397 | RejetLigne = Standard_True; |
| 2398 | } |
| 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | if(!RejetLigne) { |
| 2403 | |
| 2404 | IntSurf_TypeTrans trans1,trans2; |
| 2405 | Standard_Real locu,locv; |
| 2406 | gp_Vec norm1,norm2,d1u,d1v; |
| 2407 | gp_Pnt ptbid; |
| 2408 | Standard_Integer indextg; |
| 2409 | gp_Vec tgline(PW.TangentAtLine(indextg)); |
| 2410 | PW.Line()->Value(indextg).ParametersOnS1(locu,locv); |
| 2411 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 2412 | norm1 = d1u.Crossed(d1v); |
| 2413 | PW.Line()->Value(indextg).ParametersOnS2(locu,locv); |
| 2414 | Surf2->D1(locu,locv,ptbid,d1u,d1v); |
| 2415 | norm2 = d1u.Crossed(d1v); |
| 2416 | if (tgline.DotCross(norm2,norm1)>0.) { |
| 2417 | trans1 = IntSurf_Out; |
| 2418 | trans2 = IntSurf_In; |
| 2419 | } |
| 2420 | else { |
| 2421 | trans1 = IntSurf_In; |
| 2422 | trans2 = IntSurf_Out; |
| 2423 | } |
| 2424 | |
| 2425 | |
| 2426 | |
| 2427 | Standard_Real TolTang = TolTangency; |
| 2428 | Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2); |
| 2429 | IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang); |
| 2430 | IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang); |
| 2431 | |
| 2432 | //--------------- |
| 2433 | if(wline->NbVertex() == 0) { |
| 2434 | IntPatch_Point vtx; |
| 2435 | IntSurf_PntOn2S POn2S = PW.Line()->Value(1); |
| 2436 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 2437 | vtx.SetValue(Point3dDebut,TolTang,Standard_False); |
| 2438 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 2439 | vtx.SetParameter(1); |
| 2440 | wline->AddVertex(vtx); |
| 2441 | |
| 2442 | POn2S = PW.Line()->Value(wline->NbPnts()); |
| 2443 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 2444 | vtx.SetValue(Point3dFin,TolTang,Standard_False); |
| 2445 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 2446 | vtx.SetParameter(wline->NbPnts()); |
| 2447 | wline->AddVertex(vtx); |
| 2448 | } |
| 2449 | |
| 2450 | //--------------- |
| 2451 | SLin.Append(wline); |
| 2452 | empt = Standard_False; |
| 2453 | |
| 2454 | } |
| 2455 | else { |
| 2456 | //-- cout<<" ----- REJET DE LIGNE (POINT DE DEPART) ----- "<<endl; |
| 2457 | } |
| 2458 | //------------------------------------------------------------ |
| 2459 | } |
| 2460 | } //-- le cheminement a reussi (done a True) |
| 2461 | } //-- le point approche ne renvoie pas sur une ligne existante |
| 2462 | } //-- Si HasStartPoint |
| 2463 | //} //-- Boucle Sur les Points de la Tangent Zone |
| 2464 | } //-- Boucle sur Les Tangent Zones |
| 2465 | |
| 2466 | if ( pInterference ) { |
| 2467 | delete pInterference; |
| 2468 | pInterference = NULL; |
| 2469 | } |
| 2470 | return; |
| 2471 | } |
| 2472 | |
| 2473 | Handle(IntSurf_LineOn2S) LOn2S = new IntSurf_LineOn2S(); |
| 2474 | PointDepart( LOn2S, Surf1, NbU1, NbV1, Surf2, NbU2, NbV2 ); |
| 2475 | empt = Standard_True; |
| 2476 | done = Standard_True; |
| 2477 | SLin.Clear(); |
| 2478 | Standard_Real Deflection2 = Deflection*Deflection; |
| 2479 | |
| 2480 | Standard_Integer NbPntOn2SOnLine; |
| 2481 | Standard_Integer NbLigCalculee = 0; |
| 2482 | Standard_Real U1,U2,V1,V2; |
| 2483 | Standard_Real pu1,pu2,pv1,pv2; |
| 2484 | |
| 2485 | TColStd_Array1OfReal StartParams(1,4); |
| 2486 | Standard_Integer MaxOscill = NbU1; |
| 2487 | if(MaxOscill < NbU2) MaxOscill=NbU2; |
| 2488 | if(MaxOscill < NbV1) MaxOscill=NbV1; |
| 2489 | if(MaxOscill < NbV2) MaxOscill=NbV2; |
| 2490 | |
| 2491 | Standard_Real nIncrement=Increment; |
| 2492 | //if(MaxOscill>10) |
| 2493 | //nIncrement/=0.5*MaxOscill; |
| 2494 | |
| 2495 | IntPatch_ThePWalkingInter PW(Surf1,Surf2,TolTangency,Epsilon,Deflection,nIncrement); |
| 2496 | Standard_Real SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant |
| 2497 | Standard_Real dminiPointLigne; |
| 2498 | Standard_Boolean HasStartPoint,RejetLigne; |
| 2499 | IntSurf_PntOn2S StartPOn2S; |
| 2500 | Standard_Integer ver; |
| 2501 | gp_Pnt Point3dDebut,Point3dFin; |
| 2502 | |
| 2503 | //------------------------------------------------------------ |
| 2504 | //-- Calcul des parametres approches a partir des Zones De Tangence -- |
| 2505 | //-------------------------------------------------------------------- |
| 2506 | Standard_Integer nbTanZon = LOn2S->NbPoints(); |
| 2507 | for(Standard_Integer z=1; z <= nbTanZon; z++) { |
| 2508 | const IntSurf_PntOn2S& POn2S = LOn2S->Value(z); |
| 2509 | POn2S.Parameters(U1,V1,U2,V2); |
| 2510 | StartParams(1) = U1; |
| 2511 | StartParams(2) = V1; |
| 2512 | StartParams(3) = U2; |
| 2513 | StartParams(4) = V2; |
| 2514 | |
| 2515 | //----------------------------------------------------------------------- |
| 2516 | //-- Calcul du premier point de cheminement a partir du point approche -- |
| 2517 | //----------------------------------------------------------------------- |
| 2518 | HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S); |
| 2519 | if(HasStartPoint) { |
| 2520 | //------------------------------------------------- |
| 2521 | //-- Un point a ete trouve -- |
| 2522 | //-- On verifie qu il n appartient pas -- |
| 2523 | //-- a une ligne de cheminement deja calculee. -- |
| 2524 | //------------------------------------------------- |
| 2525 | StartPOn2S.Parameters(pu1,pv1,pu2,pv2); |
| 2526 | |
| 2527 | NbLigCalculee = SLin.Length(); |
| 2528 | dminiPointLigne = SeuildPointLigne + SeuildPointLigne; |
| 2529 | |
| 2530 | for(Standard_Integer l=1; |
| 2531 | (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); |
| 2532 | l++) { |
| 2533 | const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l)); |
| 2534 | |
| 2535 | if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) |
| 2536 | &&(testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) |
| 2537 | &&(testwline->IsOutBox(StartPOn2S.Value())==Standard_False)) { |
| 2538 | |
| 2539 | NbPntOn2SOnLine = testwline->NbPnts(); |
| 2540 | for(Standard_Integer ll=1; |
| 2541 | (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); |
| 2542 | ll++) { |
| 2543 | |
| 2544 | const gp_Pnt& Pa = testwline->Point(ll).Value(); |
| 2545 | const gp_Pnt& Pb = testwline->Point(ll+1).Value(); |
| 2546 | const gp_Pnt& PStart=StartPOn2S.Value(); |
| 2547 | gp_Vec AM(Pa,PStart); |
| 2548 | gp_Vec MB(PStart,Pb); |
| 2549 | Standard_Real AMMB = AM.Dot(MB); |
| 2550 | if(AMMB > 0.0) { |
| 2551 | gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z()); |
| 2552 | Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z(); |
| 2553 | gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z()); |
| 2554 | gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z()); |
| 2555 | |
| 2556 | Standard_Real d = 0.0; |
| 2557 | if(HM.X() < Deflection) { |
| 2558 | d+=HM.X()*HM.X(); |
| 2559 | if(HM.Y() < Deflection) { |
| 2560 | d+=HM.Y()*HM.Y(); |
| 2561 | if(HM.Z() < Deflection) { |
| 2562 | d+=HM.Z()*HM.Z(); |
| 2563 | } |
| 2564 | else { |
| 2565 | d=Deflection2; |
| 2566 | } |
| 2567 | } |
| 2568 | else { |
| 2569 | d=Deflection2; |
| 2570 | } |
| 2571 | } |
| 2572 | else { |
| 2573 | d=Deflection2; |
| 2574 | } |
| 2575 | if(d<Deflection2) { |
| 2576 | dminiPointLigne = 0.0; |
| 2577 | } |
| 2578 | } |
| 2579 | else { |
| 2580 | Standard_Real dab = Pa.Distance(Pb); |
| 2581 | Standard_Real dap = Pa.Distance(PStart); |
| 2582 | if(dap < dab) { |
| 2583 | dminiPointLigne=0; |
| 2584 | } |
| 2585 | else { |
| 2586 | Standard_Real dbp = Pb.Distance(PStart); |
| 2587 | if(dbp < dab) { |
| 2588 | dminiPointLigne=0; |
| 2589 | } |
| 2590 | } |
| 2591 | } |
| 2592 | } |
| 2593 | } //-- Rejections Boites |
| 2594 | //-- else { |
| 2595 | //-- cout<<" Rejet Boites "<<endl; |
| 2596 | //-- } |
| 2597 | } |
| 2598 | |
| 2599 | |
| 2600 | //-- Fin d exploration des lignes |
| 2601 | if(dminiPointLigne > SeuildPointLigne) { |
| 2602 | //--------------------------------------------------- |
| 2603 | //-- Le point de depart du nouveau cheminement -- |
| 2604 | //-- n est present dans aucune ligne deja calculee.-- |
| 2605 | //--------------------------------------------------- |
| 2606 | PW.Perform(StartParams); |
| 2607 | if(PW.IsDone()) { |
| 2608 | if(PW.NbPoints()>2) { |
| 2609 | //----------------------------------------------- |
| 2610 | //-- Verification a posteriori : |
| 2611 | //-- On teste si le point de depart et de fin de |
| 2612 | //-- la ligne de cheminement est present dans une |
| 2613 | //-- autre ligne . |
| 2614 | //----------------------------------------------- |
| 2615 | RejetLigne = Standard_False; |
| 2616 | Point3dDebut = PW.Value(1).Value(); |
| 2617 | Point3dFin = PW.Value(PW.NbPoints()).Value(); |
| 2618 | |
| 2619 | for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { |
| 2620 | const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver)); |
| 2621 | //-- Handle(IntPatch_WLine) verwline=Handle(IntPatch_WLine)::DownCast(SLin.Value(ver)); |
| 2622 | const IntSurf_PntOn2S& verPointDebut = verwline->Point(1); |
| 2623 | const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts()); |
| 2624 | if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency) { |
| 2625 | RejetLigne = Standard_True; |
| 2626 | } |
| 2627 | else { |
| 2628 | if(Point3dFin.Distance(verPointFin.Value()) < TolTangency) { |
| 2629 | RejetLigne = Standard_True; |
| 2630 | } |
| 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | if(!RejetLigne) { |
| 2635 | |
| 2636 | IntSurf_TypeTrans trans1,trans2; |
| 2637 | Standard_Real locu,locv; |
| 2638 | gp_Vec norm1,norm2,d1u,d1v; |
| 2639 | gp_Pnt ptbid; |
| 2640 | Standard_Integer indextg; |
| 2641 | gp_Vec tgline(PW.TangentAtLine(indextg)); |
| 2642 | PW.Line()->Value(indextg).ParametersOnS1(locu,locv); |
| 2643 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 2644 | norm1 = d1u.Crossed(d1v); |
| 2645 | PW.Line()->Value(indextg).ParametersOnS2(locu,locv); |
| 2646 | Surf2->D1(locu,locv,ptbid,d1u,d1v); |
| 2647 | norm2 = d1u.Crossed(d1v); |
| 2648 | if (tgline.DotCross(norm2,norm1)>0.) { |
| 2649 | trans1 = IntSurf_Out; |
| 2650 | trans2 = IntSurf_In; |
| 2651 | } |
| 2652 | else { |
| 2653 | trans1 = IntSurf_In; |
| 2654 | trans2 = IntSurf_Out; |
| 2655 | } |
| 2656 | |
| 2657 | |
| 2658 | |
| 2659 | Standard_Real TolTang = TolTangency; |
| 2660 | Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2); |
| 2661 | IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang); |
| 2662 | IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang); |
| 2663 | |
| 2664 | //--------------- |
| 2665 | if(wline->NbVertex() == 0) { |
| 2666 | IntPatch_Point vtx; |
| 2667 | const IntSurf_PntOn2S& POn2Sf = PW.Line()->Value(1); |
| 2668 | POn2Sf.Parameters(pu1,pv1,pu2,pv2); |
| 2669 | vtx.SetValue(Point3dDebut,TolTang,Standard_False); |
| 2670 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 2671 | vtx.SetParameter(1); |
| 2672 | wline->AddVertex(vtx); |
| 2673 | |
| 2674 | const IntSurf_PntOn2S& POn2Sl = PW.Line()->Value(wline->NbPnts()); |
| 2675 | POn2Sl.Parameters(pu1,pv1,pu2,pv2); |
| 2676 | vtx.SetValue(Point3dFin,TolTang,Standard_False); |
| 2677 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 2678 | vtx.SetParameter(wline->NbPnts()); |
| 2679 | wline->AddVertex(vtx); |
| 2680 | } |
| 2681 | |
| 2682 | //--------------- |
| 2683 | SLin.Append(wline); |
| 2684 | empt = Standard_False; |
| 2685 | |
| 2686 | } |
| 2687 | else { |
| 2688 | //-- cout<<" ----- REJET DE LIGNE (POINT DE DEPART) ----- "<<endl; |
| 2689 | } |
| 2690 | //------------------------------------------------------------ |
| 2691 | } |
| 2692 | } //-- le cheminement a reussi (done a True) |
| 2693 | } //-- le point approche ne renvoie pas sur une ligne existante |
| 2694 | } //-- Si HasStartPoint |
| 2695 | } //-- Boucle sur Les Tangent Zones |
| 2696 | |
| 2697 | } |
| 2698 | // modified by NIZHNY-AMV Tue Oct 18 12:37:02 2005 |
| 2699 | void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1, |
| 2700 | const Handle(Adaptor3d_TopolTool)& D1, |
| 2701 | const Handle(Adaptor3d_HSurface)& Surf2, |
| 2702 | const Handle(Adaptor3d_TopolTool)& D2, |
| 2703 | const Standard_Real TolTangency, |
| 2704 | const Standard_Real Epsilon, |
| 2705 | const Standard_Real Deflection, |
| 2706 | const Standard_Real Increment, |
| 2707 | IntSurf_ListOfPntOn2S& LOfPnts, |
| 2708 | const Standard_Boolean RestrictLine) |
| 2709 | { |
| 2710 | if (LOfPnts.IsEmpty()){ |
| 2711 | done = Standard_True; |
| 2712 | return; |
| 2713 | } |
| 2714 | |
| 2715 | empt = Standard_True; |
| 2716 | SLin.Clear(); |
| 2717 | |
| 2718 | Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1; |
| 2719 | Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2; |
| 2720 | Standard_Real U1,U2,V1,V2; |
| 2721 | |
| 2722 | UminLig1 = Surf1->FirstUParameter(); |
| 2723 | VminLig1 = Surf1->FirstVParameter(); |
| 2724 | UmaxLig1 = Surf1->LastUParameter(); |
| 2725 | VmaxLig1 = Surf1->LastVParameter(); |
| 2726 | UminLig2 = Surf2->FirstUParameter(); |
| 2727 | VminLig2 = Surf2->FirstVParameter(); |
| 2728 | UmaxLig2 = Surf2->LastUParameter(); |
| 2729 | VmaxLig2 = Surf2->LastVParameter(); |
| 2730 | |
| 2731 | IntSurf_ListIteratorOfListOfPntOn2S IterLOP1(LOfPnts); |
| 2732 | |
| 2733 | for(; IterLOP1.More(); IterLOP1.Next()){ |
| 2734 | IntSurf_PntOn2S Pnt = IterLOP1.Value(); |
| 2735 | Pnt.Parameters(U1, V1, U2, V2); |
| 2736 | if(U1>UmaxLig1) UmaxLig1=U1; |
| 2737 | if(V1>VmaxLig1) VmaxLig1=V1; |
| 2738 | if(U2>UmaxLig2) UmaxLig2=U2; |
| 2739 | if(V2>VmaxLig2) VmaxLig2=V2; |
| 2740 | |
| 2741 | if(U1<UminLig1) UminLig1=U1; |
| 2742 | if(V1<VminLig1) VminLig1=V1; |
| 2743 | if(U2<UminLig2) UminLig2=U2; |
| 2744 | if(V2<VminLig2) VminLig2=V2; |
| 2745 | } |
| 2746 | |
| 2747 | Standard_Real Deflection2 = Deflection*Deflection; |
| 2748 | |
| 2749 | Standard_Real SeuildPointLigne = 15.0 * Increment * Increment; |
| 2750 | |
| 2751 | Standard_Integer NbPntOn2SOnLine = 0, NbLigCalculee = 0, ver; |
| 2752 | Standard_Real pu1,pu2,pv1,pv2, dminiPointLigne; |
| 2753 | Standard_Boolean HasStartPoint,RejetLigne; |
| 2754 | IntSurf_PntOn2S StartPOn2S; |
| 2755 | gp_Pnt Point3dDebut,Point3dFin; |
| 2756 | |
| 2757 | TColStd_Array1OfReal StartParams(1,4); |
| 2758 | IntPatch_ThePWalkingInter PW(Surf1,Surf2,TolTangency,Epsilon,Deflection,Increment); |
| 2759 | |
| 2760 | IntSurf_ListIteratorOfListOfPntOn2S IterLOP2(LOfPnts); |
| 2761 | for(; IterLOP2.More(); IterLOP2.Next() ){ |
| 2762 | |
| 2763 | IntSurf_PntOn2S cPnt = IterLOP2.Value(); |
| 2764 | cPnt.Parameters(U1, V1, U2, V2); |
| 2765 | |
| 2766 | StartParams(1) = U1; |
| 2767 | StartParams(2) = V1; |
| 2768 | StartParams(3) = U2; |
| 2769 | StartParams(4) = V2; |
| 2770 | |
| 2771 | HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S); |
| 2772 | dminiPointLigne = SeuildPointLigne + SeuildPointLigne; |
| 2773 | if(HasStartPoint) { |
| 2774 | StartPOn2S.Parameters(pu1,pv1,pu2,pv2); |
| 2775 | NbLigCalculee = SLin.Length(); |
| 2776 | Standard_Integer l; |
| 2777 | for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { |
| 2778 | Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l)); |
| 2779 | if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) && |
| 2780 | (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) && |
| 2781 | (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) { |
| 2782 | NbPntOn2SOnLine = testwline->NbPnts(); |
| 2783 | Standard_Integer ll; |
| 2784 | for( ll = 1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) { |
| 2785 | const gp_Pnt &Pa = testwline->Point(ll).Value(); |
| 2786 | const gp_Pnt &Pb = testwline->Point(ll+1).Value(); |
| 2787 | const gp_Pnt &PStart = StartPOn2S.Value(); |
| 2788 | gp_Vec AM(Pa,PStart); |
| 2789 | gp_Vec MB(PStart,Pb); |
| 2790 | Standard_Real AMMB = AM.Dot(MB); |
| 2791 | if(AMMB > 0.0) { |
| 2792 | gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z()); |
| 2793 | Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z(); |
| 2794 | gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z()); |
| 2795 | gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z()); |
| 2796 | Standard_Real d = 0.0; |
| 2797 | if(HM.X() < Deflection) { |
| 2798 | d+=HM.X()*HM.X(); |
| 2799 | if(HM.Y() < Deflection) { |
| 2800 | d+=HM.Y()*HM.Y(); |
| 2801 | if(HM.Z() < Deflection) |
| 2802 | d+=HM.Z()*HM.Z(); |
| 2803 | else |
| 2804 | d=Deflection2; |
| 2805 | } |
| 2806 | else |
| 2807 | d=Deflection2; |
| 2808 | } |
| 2809 | else |
| 2810 | d=Deflection2; |
| 2811 | |
| 2812 | if(d<Deflection2) |
| 2813 | dminiPointLigne = 0.0; |
| 2814 | } |
| 2815 | else { |
| 2816 | Standard_Real dab = Pa.SquareDistance(Pb); |
| 2817 | Standard_Real dap = Pa.SquareDistance(PStart); |
| 2818 | if(dap < dab) |
| 2819 | dminiPointLigne=0; |
| 2820 | else { |
| 2821 | Standard_Real dbp = Pb.SquareDistance(PStart); |
| 2822 | if(dbp < dab) |
| 2823 | dminiPointLigne=0; |
| 2824 | } |
| 2825 | } |
| 2826 | }// for( ll ... |
| 2827 | }// if ... |
| 2828 | }// for( l ... |
| 2829 | |
| 2830 | if(dminiPointLigne > SeuildPointLigne) { |
| 2831 | PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2); |
| 2832 | if(PW.IsDone()) { |
| 2833 | if(PW.NbPoints()>2) { |
| 2834 | RejetLigne = Standard_False; |
| 2835 | Point3dDebut = PW.Value(1).Value(); |
| 2836 | Point3dFin = PW.Value(PW.NbPoints()).Value(); |
| 2837 | for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { |
| 2838 | const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver)); |
| 2839 | const IntSurf_PntOn2S& verPointDebut = verwline->Point(1); |
| 2840 | const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts()); |
| 2841 | if(Point3dDebut.Distance(verPointDebut.Value()) <= TolTangency) { |
| 2842 | if(Point3dFin.Distance(verPointFin.Value()) <= TolTangency) |
| 2843 | RejetLigne = Standard_True; |
| 2844 | } |
| 2845 | } |
| 2846 | |
| 2847 | if(!RejetLigne) { |
| 2848 | IntSurf_TypeTrans trans1,trans2; |
| 2849 | Standard_Real locu,locv; |
| 2850 | gp_Vec norm1,norm2,d1u,d1v; |
| 2851 | gp_Pnt ptbid; |
| 2852 | Standard_Integer indextg; |
| 2853 | gp_Vec tgline(PW.TangentAtLine(indextg)); |
| 2854 | PW.Line()->Value(indextg).ParametersOnS1(locu,locv); |
| 2855 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 2856 | norm1 = d1u.Crossed(d1v); |
| 2857 | PW.Line()->Value(indextg).ParametersOnS2(locu,locv); |
| 2858 | Surf2->D1(locu,locv,ptbid,d1u,d1v); |
| 2859 | norm2 = d1u.Crossed(d1v); |
| 2860 | if( tgline.DotCross(norm2,norm1) >= 0. ) { |
| 2861 | trans1 = IntSurf_Out; |
| 2862 | trans2 = IntSurf_In; |
| 2863 | } |
| 2864 | else { |
| 2865 | trans1 = IntSurf_In; |
| 2866 | trans2 = IntSurf_Out; |
| 2867 | } |
| 2868 | |
| 2869 | Standard_Real TolTang = TolTangency; |
| 2870 | Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2); |
| 2871 | if (RestrictLine){ |
| 2872 | IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang); |
| 2873 | IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang); |
| 2874 | } |
| 2875 | |
| 2876 | if(wline->NbVertex() == 0) { |
| 2877 | IntPatch_Point vtx; |
| 2878 | IntSurf_PntOn2S POn2S = PW.Line()->Value(1); |
| 2879 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 2880 | vtx.SetValue(Point3dDebut,TolTang,Standard_False); |
| 2881 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 2882 | vtx.SetParameter(1); |
| 2883 | wline->AddVertex(vtx); |
| 2884 | |
| 2885 | POn2S = PW.Line()->Value(wline->NbPnts()); |
| 2886 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 2887 | vtx.SetValue(Point3dFin,TolTang,Standard_False); |
| 2888 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 2889 | vtx.SetParameter(wline->NbPnts()); |
| 2890 | wline->AddVertex(vtx); |
| 2891 | } |
| 2892 | |
| 2893 | Standard_Integer slinlen = SLin.Length(); |
| 2894 | if( slinlen > 0 ) { |
| 2895 | Standard_Integer cnbV = wline->NbVertex(); |
| 2896 | Standard_Integer ciV; |
| 2897 | for( ciV = 1; ciV <= cnbV; ciV++ ) { |
| 2898 | Standard_Real pntDMin = 1.e+100; |
| 2899 | Standard_Integer VDMin = 0; |
| 2900 | Standard_Integer WLDMin = 0; |
| 2901 | gp_Pnt cPV = wline->Vertex(ciV).Value(); |
| 2902 | Standard_Integer iL; |
| 2903 | for( iL = 1; iL <= slinlen; iL++) { |
| 2904 | const Handle(IntPatch_Line)& aSLine = SLin.Value(iL); |
| 2905 | IntPatch_IType aType = aSLine->ArcType(); |
| 2906 | if( aType != IntPatch_Walking) |
| 2907 | continue; |
| 2908 | const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&aSLine)); |
| 2909 | Standard_Integer tnbV = aWLine->NbVertex(); |
| 2910 | Standard_Integer tiV; |
| 2911 | for( tiV = 1; tiV <= tnbV; tiV++ ) { |
| 2912 | gp_Pnt tPV = aWLine->Vertex(tiV).Value(); |
| 2913 | Standard_Real tDistance = cPV.Distance(tPV); |
| 2914 | Standard_Real uRs1 = Surf1->Surface().UResolution(tDistance); |
| 2915 | Standard_Real vRs1 = Surf1->Surface().VResolution(tDistance); |
| 2916 | Standard_Real uRs2 = Surf2->Surface().UResolution(tDistance); |
| 2917 | Standard_Real vRs2 = Surf2->Surface().VResolution(tDistance); |
| 2918 | Standard_Real RmaxS1 = Max(uRs1,vRs1); |
| 2919 | Standard_Real RmaxS2 = Max(uRs2,vRs2); |
| 2920 | if(RmaxS1 < 1.e-4 && RmaxS2 < 1.e-4) { |
| 2921 | if( pntDMin > tDistance && tDistance > 1.e-9) { |
| 2922 | pntDMin = tDistance; |
| 2923 | VDMin = tiV; |
| 2924 | WLDMin = iL; |
| 2925 | } |
| 2926 | } |
| 2927 | } |
| 2928 | } |
| 2929 | |
| 2930 | if( VDMin != 0 ) { |
| 2931 | const Handle(IntPatch_Line)& aSLine = SLin.Value(WLDMin); |
| 2932 | const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&aSLine)); |
| 2933 | Standard_Integer tiVpar = (Standard_Integer)aWLine->Vertex(VDMin).ParameterOnLine(); |
| 2934 | Standard_Integer ciVpar = (Standard_Integer)wline->Vertex(ciV).ParameterOnLine(); |
| 2935 | Standard_Real u11 = 0., u12 = 0., v11 = 0., v12 = 0.; |
| 2936 | Standard_Real u21 = 0., u22 = 0., v21 = 0., v22 = 0.; |
| 2937 | wline->Point(ciVpar).Parameters(u11,v11,u12,v12); |
| 2938 | aWLine->Point(tiVpar).Parameters(u21,v21,u22,v22); |
| 2939 | |
| 2940 | Handle(IntSurf_LineOn2S) newL2s = new IntSurf_LineOn2S(); |
| 2941 | IntSurf_PntOn2S replacePnt = aWLine->Point(tiVpar); |
| 2942 | Standard_Integer cNbP = wline->NbPnts(); |
| 2943 | |
| 2944 | TColStd_SequenceOfInteger VPold; |
| 2945 | Standard_Integer iPo; |
| 2946 | for( iPo = 1; iPo <= cnbV; iPo++ ) { |
| 2947 | Standard_Real Po = wline->Vertex(iPo).ParameterOnLine(); |
| 2948 | Standard_Integer IPo = (Standard_Integer) Po; |
| 2949 | VPold.Append(IPo); |
| 2950 | } |
| 2951 | |
| 2952 | Standard_Boolean removeNext = Standard_False; |
| 2953 | Standard_Boolean removePrev = Standard_False; |
| 2954 | if( ciV == 1) { |
| 2955 | Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV+1)); |
| 2956 | if(dPar > 10) { |
| 2957 | removeNext = Standard_True; |
| 2958 | for( iPo = (ciV+1); iPo <= cnbV; iPo++ ) |
| 2959 | VPold.SetValue(iPo, VPold.Value(iPo) - 1 ); |
| 2960 | } |
| 2961 | } |
| 2962 | else if( ciV == cnbV) { |
| 2963 | Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV-1)); |
| 2964 | if(dPar > 10) { |
| 2965 | removePrev = Standard_True; |
| 2966 | VPold.SetValue(ciV, VPold.Value(ciV) - 1 ); |
| 2967 | } |
| 2968 | } |
| 2969 | else { |
| 2970 | Standard_Integer dParMi = Abs( VPold.Value(ciV) - VPold.Value(ciV-1)); |
| 2971 | Standard_Integer dParMa = Abs( VPold.Value(ciV) - VPold.Value(ciV+1)); |
| 2972 | if(dParMi > 10) { |
| 2973 | removePrev = Standard_True; |
| 2974 | VPold.SetValue(ciV, VPold.Value(ciV) - 1 ); |
| 2975 | } |
| 2976 | if(dParMa > 10) { |
| 2977 | removeNext = Standard_True; |
| 2978 | for( iPo = (ciV+1); iPo <= cnbV; iPo++ ) { |
| 2979 | if(dParMi > 10) |
| 2980 | VPold.SetValue(iPo, VPold.Value(iPo) - 2 ); |
| 2981 | else |
| 2982 | VPold.SetValue(iPo, VPold.Value(iPo) - 1 ); |
| 2983 | } |
| 2984 | } |
| 2985 | else { |
| 2986 | if(dParMi > 10) |
| 2987 | for( iPo = (ciV+1); iPo <= cnbV; iPo++ ) |
| 2988 | VPold.SetValue(iPo, VPold.Value(iPo) - 1 ); |
| 2989 | } |
| 2990 | } |
| 2991 | Standard_Integer pI = (Standard_Integer) ciVpar; |
| 2992 | |
| 2993 | Standard_Integer iP; |
| 2994 | for( iP = 1; iP <= cNbP; iP++) { |
| 2995 | if( pI == iP ) |
| 2996 | newL2s->Add(replacePnt); |
| 2997 | else if(removeNext && iP == (pI + 1)) |
| 2998 | continue; |
| 2999 | else if(removePrev && iP == (pI - 1)) |
| 3000 | continue; |
| 3001 | else |
| 3002 | newL2s->Add(wline->Point(iP)); |
| 3003 | } |
| 3004 | |
| 3005 | IntPatch_Point newVtx; |
| 3006 | gp_Pnt Pnt3dV = aWLine->Vertex(VDMin).Value(); |
| 3007 | newVtx.SetValue(Pnt3dV,TolTang,Standard_False); |
| 3008 | newVtx.SetParameters(u21,v21,u22,v22); |
| 3009 | newVtx.SetParameter(VPold.Value(ciV)); |
| 3010 | |
| 3011 | Handle(IntPatch_WLine) NWLine = new IntPatch_WLine(newL2s,Standard_False,trans1,trans2); |
| 3012 | |
| 3013 | Standard_Integer iV; |
| 3014 | for( iV = 1; iV <= cnbV; iV++ ) { |
| 3015 | if( iV == ciV ) |
| 3016 | NWLine->AddVertex(newVtx); |
| 3017 | else { |
| 3018 | IntPatch_Point theVtx = wline->Vertex(iV); |
| 3019 | theVtx.SetParameter(VPold.Value(iV)); |
| 3020 | NWLine->AddVertex(theVtx); |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | wline = NWLine; |
| 3025 | } |
| 3026 | } |
| 3027 | }// SLin.Length > 0 |
| 3028 | |
| 3029 | SLin.Append(wline); |
| 3030 | empt = Standard_False; |
| 3031 | }// !RejetLigne |
| 3032 | }// PW points > 2 |
| 3033 | }// done is True |
| 3034 | }// dminiPointLigne > SeuildPointLigne |
| 3035 | }// HasStartPoint |
| 3036 | }// for( IterLOP ... |
| 3037 | done = Standard_True; |
| 3038 | return; |
| 3039 | } |
| 3040 | |
| 3041 | //====================================================================== |
| 3042 | void IntPatch_PrmPrmIntersection::Perform(const Handle(Adaptor3d_HSurface)& Surf1, |
| 3043 | const Handle(Adaptor3d_TopolTool)& D1, |
| 3044 | const Handle(Adaptor3d_HSurface)& Surf2, |
| 3045 | const Handle(Adaptor3d_TopolTool)& D2, |
| 3046 | const Standard_Real U1Depart, |
| 3047 | const Standard_Real V1Depart, |
| 3048 | const Standard_Real U2Depart, |
| 3049 | const Standard_Real V2Depart, |
| 3050 | const Standard_Real TolTangency, |
| 3051 | const Standard_Real Epsilon, |
| 3052 | const Standard_Real Deflection, |
| 3053 | const Standard_Real Increment) { |
| 3054 | |
| 3055 | |
| 3056 | |
| 3057 | // Standard_Integer NbU1 = D1->NbSamplesU(); |
| 3058 | // Standard_Integer NbV1 = D1->NbSamplesV(); |
| 3059 | // Standard_Integer NbU2 = D2->NbSamplesU(); |
| 3060 | // Standard_Integer NbV2 = D2->NbSamplesV(); |
| 3061 | |
| 3062 | //-- Traitement des Lignes de sections |
| 3063 | empt = Standard_True; |
| 3064 | done = Standard_True; |
| 3065 | SLin.Clear(); |
| 3066 | |
| 3067 | //------------------------------------------------------------ |
| 3068 | |
| 3069 | Standard_Real pu1,pu2,pv1,pv2; |
| 3070 | |
| 3071 | TColStd_Array1OfReal StartParams(1,4); |
| 3072 | |
| 3073 | // Standard_Integer MaxOscill = NbU1; |
| 3074 | // if(MaxOscill < NbU2) MaxOscill=NbU2; |
| 3075 | // if(MaxOscill < NbV1) MaxOscill=NbV1; |
| 3076 | // if(MaxOscill < NbV2) MaxOscill=NbV2; |
| 3077 | |
| 3078 | // Standard_Real nIncrement=Increment; |
| 3079 | // if(MaxOscill>10) { |
| 3080 | // #ifdef DEB |
| 3081 | // cout<<"\n IntPatch_PrmPrmIntersection.gxx : Increment:"<<Increment<<" -> "<<Increment/(0.5*MaxOscill)<<endl; |
| 3082 | // #endif |
| 3083 | // nIncrement/=0.5*MaxOscill; |
| 3084 | // } |
| 3085 | |
| 3086 | IntPatch_ThePWalkingInter PW(Surf1,Surf2, |
| 3087 | TolTangency, |
| 3088 | Epsilon, |
| 3089 | Deflection, |
| 3090 | Increment); //nIncrement); |
| 3091 | |
| 3092 | |
| 3093 | //Standard_Real SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant |
| 3094 | //Standard_Real incidence; |
| 3095 | //Standard_Real dminiPointLigne; |
| 3096 | |
| 3097 | Standard_Boolean HasStartPoint;//,RejetLigne; |
| 3098 | |
| 3099 | IntSurf_PntOn2S StartPOn2S; |
| 3100 | |
| 3101 | //Standard_Integer ver; |
| 3102 | |
| 3103 | gp_Pnt Point3dDebut,Point3dFin; |
| 3104 | |
| 3105 | //------------------------------------------------------------ |
| 3106 | |
| 3107 | StartParams(1) = U1Depart; |
| 3108 | StartParams(2) = V1Depart; |
| 3109 | StartParams(3) = U2Depart; |
| 3110 | StartParams(4) = V2Depart; |
| 3111 | |
| 3112 | //----------------------------------------------------------------------- |
| 3113 | //-- Calcul du premier point de cheminement a partir du point approche -- |
| 3114 | //----------------------------------------------------------------------- |
| 3115 | HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S); |
| 3116 | if(HasStartPoint) { |
| 3117 | //------------------------------------------------- |
| 3118 | //-- Un point a ete trouve -- |
| 3119 | //-- On verifie qu il n appartient pas -- |
| 3120 | //-- a une ligne de cheminement deja calculee. -- |
| 3121 | //------------------------------------------------- |
| 3122 | |
| 3123 | PW.Perform(StartParams); |
| 3124 | if(PW.IsDone()) { |
| 3125 | |
| 3126 | Point3dDebut = PW.Value(1).Value(); |
| 3127 | Point3dFin = PW.Value(PW.NbPoints()).Value(); |
| 3128 | |
| 3129 | IntSurf_TypeTrans trans1,trans2; |
| 3130 | Standard_Real locu,locv; |
| 3131 | gp_Vec norm1,norm2,d1u,d1v; |
| 3132 | gp_Pnt ptbid; |
| 3133 | Standard_Integer indextg; |
| 3134 | gp_Vec tgline(PW.TangentAtLine(indextg)); |
| 3135 | PW.Line()->Value(indextg).ParametersOnS1(locu,locv); |
| 3136 | Surf1->D1(locu,locv,ptbid,d1u,d1v); |
| 3137 | norm1 = d1u.Crossed(d1v); |
| 3138 | PW.Line()->Value(indextg).ParametersOnS2(locu,locv); |
| 3139 | Surf2->D1(locu,locv,ptbid,d1u,d1v); |
| 3140 | norm2 = d1u.Crossed(d1v); |
| 3141 | if (tgline.DotCross(norm2,norm1)>0.) { |
| 3142 | trans1 = IntSurf_Out; |
| 3143 | trans2 = IntSurf_In; |
| 3144 | } |
| 3145 | else { |
| 3146 | trans1 = IntSurf_In; |
| 3147 | trans2 = IntSurf_Out; |
| 3148 | } |
| 3149 | |
| 3150 | |
| 3151 | |
| 3152 | Standard_Real TolTang = TolTangency; |
| 3153 | Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2); |
| 3154 | IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang); |
| 3155 | IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang); |
| 3156 | |
| 3157 | //--------------- |
| 3158 | if(wline->NbVertex() == 0) { |
| 3159 | IntPatch_Point vtx; |
| 3160 | IntSurf_PntOn2S POn2S = PW.Line()->Value(1); |
| 3161 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 3162 | vtx.SetValue(Point3dDebut,TolTang,Standard_False); |
| 3163 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 3164 | vtx.SetParameter(1); |
| 3165 | wline->AddVertex(vtx); |
| 3166 | |
| 3167 | POn2S = PW.Line()->Value(wline->NbPnts()); |
| 3168 | POn2S.Parameters(pu1,pv1,pu2,pv2); |
| 3169 | vtx.SetValue(Point3dFin,TolTang,Standard_False); |
| 3170 | vtx.SetParameters(pu1,pv1,pu2,pv2); |
| 3171 | vtx.SetParameter(wline->NbPnts()); |
| 3172 | wline->AddVertex(vtx); |
| 3173 | } |
| 3174 | |
| 3175 | //--------------- |
| 3176 | SLin.Append(wline); |
| 3177 | empt = Standard_False; |
| 3178 | |
| 3179 | } |
| 3180 | } |
| 3181 | } |
| 3182 | |
| 3183 | |
| 3184 | //xf |
| 3185 | //================================================================================== |
| 3186 | // function : AdjustOnPeriodic |
| 3187 | // purpose : |
| 3188 | //================================================================================== |
| 3189 | void AdjustOnPeriodic(const Handle(Adaptor3d_HSurface)& Surf1, |
| 3190 | const Handle(Adaptor3d_HSurface)& Surf2, |
| 3191 | IntPatch_SequenceOfLine& aSLin) |
| 3192 | { |
| 3193 | Standard_Boolean bIsPeriodic[4], bModified, bIsNull, bIsPeriod; |
| 3194 | Standard_Integer i, j, k, aNbLines, aNbPx, aIndx, aIndq; |
| 3195 | Standard_Real aPeriod[4], dPeriod[4], ux[4], uq[4], aEps, du; |
| 3196 | // |
| 3197 | aEps=Precision::Confusion(); |
| 3198 | // |
| 3199 | for (k=0; k<4; ++k) { |
| 3200 | aPeriod[k]=0.; |
| 3201 | } |
| 3202 | // |
| 3203 | bIsPeriodic[0]=Surf1->IsUPeriodic(); |
| 3204 | bIsPeriodic[1]=Surf1->IsVPeriodic(); |
| 3205 | bIsPeriodic[2]=Surf2->IsUPeriodic(); |
| 3206 | bIsPeriodic[3]=Surf2->IsVPeriodic(); |
| 3207 | // |
| 3208 | if (bIsPeriodic[0]){ |
| 3209 | aPeriod[0]=Surf1->UPeriod(); |
| 3210 | } |
| 3211 | if (bIsPeriodic[1]){ |
| 3212 | aPeriod[1]=Surf1->VPeriod(); |
| 3213 | } |
| 3214 | if (bIsPeriodic[2]){ |
| 3215 | aPeriod[2]=Surf2->UPeriod(); |
| 3216 | } |
| 3217 | if (bIsPeriodic[3]){ |
| 3218 | aPeriod[3]=Surf2->VPeriod(); |
| 3219 | } |
| 3220 | // |
| 3221 | for (k=0; k<4; ++k) { |
| 3222 | dPeriod[k]=0.25*aPeriod[k]; |
| 3223 | } |
| 3224 | // |
| 3225 | aNbLines=aSLin.Length(); |
| 3226 | for (i=1; i<=aNbLines; ++i) { |
| 3227 | Handle(IntPatch_WLine) aIL=Handle(IntPatch_WLine)::DownCast(aSLin.Value(i)); |
| 3228 | Handle(IntSurf_LineOn2S) aL=aIL->Curve(); |
| 3229 | |
| 3230 | aNbPx=aL->NbPoints(); |
| 3231 | if (aNbPx<10) { |
| 3232 | continue; |
| 3233 | } |
| 3234 | // |
| 3235 | for (j=0; j<2; ++j) { |
| 3236 | bModified=Standard_False; |
| 3237 | aIndx=1; |
| 3238 | aIndq=2; |
| 3239 | if (j) { |
| 3240 | aIndx=aNbPx; |
| 3241 | aIndq=aNbPx-1; |
| 3242 | } |
| 3243 | // |
| 3244 | const IntSurf_PntOn2S& aPSx=aL->Value(aIndx); |
| 3245 | const IntSurf_PntOn2S& aPSq=aL->Value(aIndq); |
| 3246 | // |
| 3247 | aPSx.Parameters(ux[0], ux[1], ux[2], ux[3]); |
| 3248 | aPSq.Parameters(uq[0], uq[1], uq[2], uq[3]); |
| 3249 | // |
| 3250 | for (k=0; k<4; ++k) { |
| 3251 | bIsNull=Standard_False; |
| 3252 | bIsPeriod=Standard_False; |
| 3253 | // |
| 3254 | if (!bIsPeriodic[k]) { |
| 3255 | continue; |
| 3256 | } |
| 3257 | // |
| 3258 | if (fabs(ux[k])<aEps) { |
| 3259 | bModified=Standard_True; |
| 3260 | bIsNull=Standard_True; |
| 3261 | } |
| 3262 | // |
| 3263 | else if (fabs(ux[k]-aPeriod[k])<aEps) { |
| 3264 | bModified=Standard_True; |
| 3265 | bIsPeriod=Standard_True; |
| 3266 | } |
| 3267 | // |
| 3268 | if (bModified) { |
| 3269 | du=fabs(ux[k]-uq[k]); |
| 3270 | if (du > dPeriod[k]) { |
| 3271 | if(bIsNull){ |
| 3272 | ux[k]=aPeriod[k]; |
| 3273 | } |
| 3274 | if(bIsPeriod) { |
| 3275 | ux[k]=0.; |
| 3276 | } |
| 3277 | } |
| 3278 | } |
| 3279 | }//for (k=0; k<4; ++k) |
| 3280 | if (bModified) { |
| 3281 | IntSurf_PntOn2S aPntOn2S; |
| 3282 | // |
| 3283 | aPntOn2S=aPSx; |
| 3284 | aPntOn2S.SetValue(ux[0], ux[1], ux[2], ux[3]); |
| 3285 | aL->Value(aIndx, aPntOn2S); |
| 3286 | } |
| 3287 | }//for (j=0; j<1; ++j) { |
| 3288 | }//for (i=1; i<=aNbLines; ++i) |
| 3289 | } |
| 3290 | //xt |