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