Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-05-07 |
2 | // Created by: Jacques GOUSSARD | |
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 | // ---------------------------------------------------------------------- | |
18 | //-- lbr: Modifs importantes du 16-17 Nov 95 | |
19 | //-- - Chercher APointOnRstStillExist et OnDifferentRst | |
20 | //-- On veut pouvoir creer un Vtx (A1 sur S1, A2 sur S2) | |
21 | //-- et le Vtx (A1 sur S1, A2bis sur S2) | |
22 | //-- ce qui revient a distinguer un point deja pose sur une | |
23 | //-- restriction de S avec un point pose sur une nouvelle | |
24 | //-- restriction de S. | |
25 | //-- - Pour rester coherent avec cette facon de faire, | |
26 | //-- Chercher(Nbvtx++). | |
27 | ||
42cf5bc1 | 28 | #include <Adaptor2d_HCurve2d.hxx> |
29 | #include <Adaptor3d_HSurface.hxx> | |
30 | #include <Adaptor3d_TopolTool.hxx> | |
31 | #include <gp_Pnt2d.hxx> | |
7fd59977 | 32 | #include <Intf_SectionPoint.hxx> |
33 | #include <Intf_TangentZone.hxx> | |
7fd59977 | 34 | #include <IntPatch_CSFunction.hxx> |
35 | #include <IntPatch_CurvIntSurf.hxx> | |
42cf5bc1 | 36 | #include <IntPatch_HInterTool.hxx> |
37 | #include <IntPatch_Line.hxx> | |
38 | #include <IntPatch_PolyArc.hxx> | |
39 | #include <IntPatch_PolyLine.hxx> | |
40 | #include <IntPatch_RLine.hxx> | |
41 | #include <IntPatch_RstInt.hxx> | |
42 | #include <IntPatch_SearchPnt.hxx> | |
43 | #include <IntPatch_WLine.hxx> | |
44 | #include <IntSurf.hxx> | |
45 | #include <Precision.hxx> | |
46 | #include <Standard_DomainError.hxx> | |
47 | #include <TColgp_SequenceOfPnt.hxx> | |
48 | #include <TColgp_SequenceOfPnt2d.hxx> | |
7fd59977 | 49 | |
7c4e9501 | 50 | #define myInfinite 1.e15 // the same as was in Adaptor3d_TopolTool |
7fd59977 | 51 | |
52 | static void Recadre(GeomAbs_SurfaceType typeS1, | |
53 | GeomAbs_SurfaceType typeS2, | |
54 | const Handle(IntPatch_WLine)& wlin, | |
55 | Standard_Integer Param, | |
56 | Standard_Real& U1, | |
57 | Standard_Real& V1, | |
58 | Standard_Real& U2, | |
59 | Standard_Real& V2) | |
60 | { | |
61 | Standard_Integer nbpnts = wlin->NbPnts(); | |
62 | if(Param<1) Param=1; else if(Param>nbpnts) Param=nbpnts; | |
63 | Standard_Real U1p,V1p,U2p,V2p; | |
64 | ||
65 | wlin->Point(Param).Parameters(U1p,V1p,U2p,V2p); | |
66 | switch(typeS1) { | |
67 | case GeomAbs_Cylinder: | |
68 | case GeomAbs_Cone: | |
69 | case GeomAbs_Sphere: | |
70 | case GeomAbs_Torus: | |
c6541a0c D |
71 | while(U1<(U1p-1.5*M_PI)) U1+=M_PI+M_PI; |
72 | while(U1>(U1p+1.5*M_PI)) U1-=M_PI+M_PI; | |
7fd59977 | 73 | break; |
74 | default: | |
75 | break; | |
76 | } | |
77 | if(typeS1==GeomAbs_Torus) { | |
c6541a0c D |
78 | while(V1<(V1p-1.5*M_PI)) V1+=M_PI+M_PI; |
79 | while(V1>(V1p+1.5*M_PI)) V1-=M_PI+M_PI; | |
7fd59977 | 80 | } |
81 | ||
82 | switch(typeS2) { | |
83 | case GeomAbs_Cylinder: | |
84 | case GeomAbs_Cone: | |
85 | case GeomAbs_Sphere: | |
86 | case GeomAbs_Torus: | |
c6541a0c D |
87 | while(U2<(U2p-1.5*M_PI)) U2+=M_PI+M_PI; |
88 | while(U2>(U2p+1.5*M_PI)) U2-=M_PI+M_PI; | |
7fd59977 | 89 | break; |
90 | default: | |
91 | break; | |
92 | } | |
93 | if(typeS2==GeomAbs_Torus) { | |
c6541a0c D |
94 | while(V2<(V1p-1.5*M_PI)) V2+=M_PI+M_PI; |
95 | while(V2>(V2p+1.5*M_PI)) V2-=M_PI+M_PI; | |
7fd59977 | 96 | } |
97 | } | |
98 | ||
99 | const Standard_Real Confusion = Precision::Confusion(); | |
100 | ||
101 | inline Standard_Real Tol3d (const Handle(Adaptor3d_HVertex)& vtx, | |
102 | const Handle(Adaptor3d_TopolTool)& Domain, | |
103 | const Standard_Real tolDef = 0.) | |
104 | { | |
105 | return (Domain->Has3d() ? Domain->Tol3d(vtx) | |
106 | : tolDef < Confusion ? Confusion | |
107 | : tolDef); | |
108 | } | |
109 | ||
110 | inline Standard_Real Tol3d (const Handle(Adaptor2d_HCurve2d)& arc, | |
111 | const Handle(Adaptor3d_TopolTool)& Domain, | |
112 | const Standard_Real tolDef = 0.) | |
113 | { | |
114 | return (Domain->Has3d() ? Domain->Tol3d(arc) | |
115 | : tolDef < Confusion ? Confusion | |
116 | : tolDef); | |
117 | } | |
118 | ||
119 | static Standard_Boolean CoincideOnArc(const gp_Pnt& Ptsommet, | |
120 | const Handle(Adaptor2d_HCurve2d)& A, | |
121 | const Handle(Adaptor3d_HSurface)& Surf, | |
122 | const Standard_Real Toler, | |
123 | const Handle(Adaptor3d_TopolTool)& Domain, | |
124 | Handle(Adaptor3d_HVertex)& Vtx) | |
125 | { | |
126 | Standard_Real distmin = RealLast(); | |
127 | Standard_Real tolarc = Max(Toler,Tol3d(A,Domain)); | |
128 | ||
129 | Domain->Initialize(A); | |
130 | Domain->InitVertexIterator(); | |
131 | while (Domain->MoreVertex()) { | |
132 | Handle(Adaptor3d_HVertex) vtx1 = Domain->Vertex(); | |
133 | Standard_Real prm = IntPatch_HInterTool::Parameter(vtx1,A); | |
134 | gp_Pnt2d p2d = A->Value(prm); | |
135 | gp_Pnt point = Surf->Value(p2d.X(),p2d.Y()); | |
136 | const Standard_Real dist = point.Distance(Ptsommet); | |
137 | Standard_Real tol = Max (tolarc, Tol3d(vtx1,Domain)); | |
138 | ||
139 | if (dist <= tol && dist <= distmin) { // the best coincidence | |
140 | distmin = dist; | |
141 | Vtx = vtx1; | |
142 | } | |
143 | Domain->NextVertex(); | |
144 | } | |
145 | return distmin < RealLast(); | |
146 | } | |
147 | ||
148 | ||
149 | static void VerifyTgline(const Handle(IntPatch_WLine)& wlin, | |
150 | const Standard_Integer param, | |
151 | const Standard_Real Tol, | |
152 | gp_Vec& Tgl) { | |
153 | ||
154 | if( Abs(Tgl.X())<Tol | |
155 | && Abs(Tgl.Y())<Tol | |
156 | && Abs(Tgl.Z())<Tol) { | |
157 | //-- On construit une tangente plus grande | |
158 | //-- (Eviter des points tres proches ds Walking) | |
159 | Standard_Integer i, n, nbpt=wlin->NbPnts(); | |
160 | Standard_Boolean forward = (nbpt-param) >= (param-1); | |
161 | for (n = 2; n > 0; n--, forward = !forward) { | |
162 | if (forward) { | |
163 | for(i=param+1; i<=nbpt; i++) { | |
164 | gp_Vec T(wlin->Point(param).Value(),wlin->Point(i).Value()); | |
165 | if( Abs(T.X())>=Tol | |
166 | || Abs(T.Y())>=Tol | |
167 | || Abs(T.Z())>=Tol) { | |
168 | Tgl = T ; | |
169 | return; | |
170 | } | |
171 | } | |
172 | } | |
173 | else { | |
174 | for(i=param-1; i>=1; i--) { | |
175 | gp_Vec T(wlin->Point(i).Value(),wlin->Point(param).Value()); | |
176 | if( Abs(T.X())>=Tol | |
177 | || Abs(T.Y())>=Tol | |
178 | || Abs(T.Z())>=Tol) { | |
179 | Tgl = T ; | |
180 | return; | |
181 | } | |
182 | } | |
183 | } | |
184 | } | |
185 | } | |
186 | } | |
187 | ||
188 | static void GetLinePoint2d (const Handle(IntPatch_Line)& L, | |
189 | const Standard_Real param, | |
190 | const Standard_Boolean OnFirst, | |
191 | Standard_Real& U, Standard_Real& V) | |
192 | { | |
c04c30b3 | 193 | Handle(IntPatch_WLine) wlin = Handle(IntPatch_WLine)::DownCast(L); |
194 | Handle(IntPatch_RLine) rlin = Handle(IntPatch_RLine)::DownCast(L); | |
7fd59977 | 195 | IntPatch_IType typL = L->ArcType(); |
7fd59977 | 196 | Standard_Integer Nbptlin = (typL == IntPatch_Walking |
197 | ? wlin->NbPnts() | |
198 | : rlin->NbPnts()); | |
199 | ||
200 | Standard_Real par = IntegerPart(param); | |
201 | Standard_Integer Irang = Standard_Integer(par); | |
202 | if (Irang == Nbptlin) { | |
203 | Irang--; | |
204 | par = 1.0; | |
205 | } | |
206 | else | |
207 | par = Abs(param-par); | |
208 | ||
209 | Standard_Real us1,vs1,us2,vs2; | |
210 | if (typL == IntPatch_Walking) { | |
211 | if (OnFirst) { | |
212 | wlin->Point(Irang).ParametersOnS1(us1,vs1); | |
213 | wlin->Point(Irang+1).ParametersOnS1(us2,vs2); | |
214 | } | |
215 | else { | |
216 | wlin->Point(Irang).ParametersOnS2(us1,vs1); | |
217 | wlin->Point(Irang+1).ParametersOnS2(us2,vs2); | |
218 | } | |
219 | } | |
220 | else { | |
221 | if (OnFirst) { | |
222 | rlin->Point(Irang).ParametersOnS1(us1,vs1); | |
223 | rlin->Point(Irang+1).ParametersOnS1(us2,vs2); | |
224 | } | |
225 | else { | |
226 | rlin->Point(Irang).ParametersOnS2(us1,vs1); | |
227 | rlin->Point(Irang+1).ParametersOnS2(us2,vs2); | |
228 | } | |
229 | } | |
230 | ||
231 | U = (1.-par)*us1+par*us2; | |
232 | V = (1.-par)*vs1+par*vs2; | |
233 | } | |
234 | ||
235 | static void GetWLinePoint (const Handle(IntPatch_WLine)& wlin, | |
236 | const Standard_Real param, | |
237 | Standard_Real& U1, Standard_Real& V1, | |
238 | Standard_Real& U2, Standard_Real& V2, | |
239 | gp_Pnt& P) | |
240 | { | |
241 | Standard_Integer Nbptlin = wlin->NbPnts(); | |
242 | Standard_Real par = IntegerPart(param); | |
243 | Standard_Integer Irang = Standard_Integer(par); | |
244 | if (Irang == Nbptlin) { | |
245 | Irang--; | |
246 | par = 1.0; | |
247 | } | |
248 | else | |
249 | par = Abs(param-par); | |
250 | ||
251 | const IntSurf_PntOn2S& p2s1 = wlin->Point(Irang); | |
252 | const IntSurf_PntOn2S& p2s2 = wlin->Point(Irang+1); | |
253 | const gp_Pnt& p1 = p2s1.Value(); | |
254 | const gp_Pnt& p2 = p2s2.Value(); | |
255 | P.ChangeCoord().SetLinearForm(1.-par, p1.XYZ(), par, p2.XYZ()); | |
256 | ||
257 | Standard_Real us1,vs1,us2,vs2; | |
258 | p2s1.ParametersOnS1(us1,vs1); | |
259 | p2s2.ParametersOnS1(us2,vs2); | |
260 | U1 = (1.-par)*us1+par*us2; | |
261 | V1 = (1.-par)*vs1+par*vs2; | |
262 | ||
263 | p2s1.ParametersOnS2(us1,vs1); | |
264 | p2s2.ParametersOnS2(us2,vs2); | |
265 | U2 = (1.-par)*us1+par*us2; | |
266 | V2 = (1.-par)*vs1+par*vs2; | |
267 | } | |
268 | ||
269 | static Standard_Boolean FindParameter(const Handle(IntPatch_Line)& L, | |
270 | const Handle(Adaptor3d_HSurface)& OtherSurf, | |
271 | const Standard_Real Tol, | |
272 | const gp_Pnt& Ptsom, | |
273 | const gp_Pnt2d& Ptsom2d, | |
274 | Standard_Real& Param, | |
275 | gp_Vec& Tgl, | |
276 | const Standard_Integer ParamApproche, | |
277 | const Standard_Boolean OnFirst) | |
278 | ||
279 | { | |
280 | // MSV 28.03.2002: find parameter on WLine in 2d space | |
281 | ||
282 | //Si la ligne est de type restriction, c est qu on provient necessairement | |
283 | // du cas implicite/parametree, et que la ligne est restriction de | |
284 | // la surface bi-parametree. Cette surface bi-parametree est necessairement | |
285 | // passee en argument a PutVertexOnline dans la variable OtherSurf. | |
286 | ||
287 | // Dans le cas d une ligne de cheminement, il faudrait voir la projection | |
288 | // et le calcul de la tangente. | |
289 | ||
c5f3a425 | 290 | Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (L)); //-- aucune verification n est |
291 | Handle(IntPatch_WLine) wlin (Handle(IntPatch_WLine)::DownCast (L)); //-- faite au cast. | |
7fd59977 | 292 | gp_Pnt ptbid; |
293 | gp_Vec d1u,d1v; | |
294 | gp_Pnt2d p2d; | |
295 | gp_Vec2d d2d; | |
296 | Standard_Real Tol2 = Tol*Tol; | |
297 | IntPatch_IType typL = L->ArcType(); | |
298 | Tgl.SetCoord(0.0,0.0,0.0); | |
299 | ||
300 | if ( typL == IntPatch_Restriction) { | |
301 | if (!OnFirst && rlin->IsArcOnS1()) { | |
302 | IntPatch_HInterTool::Project(rlin->ArcOnS1(),Ptsom2d,Param,p2d); | |
303 | rlin->ArcOnS1()->D1(Param,p2d,d2d); | |
304 | } | |
305 | else if (OnFirst && rlin->IsArcOnS2()) { | |
306 | IntPatch_HInterTool::Project(rlin->ArcOnS2(),Ptsom2d,Param,p2d); | |
307 | rlin->ArcOnS2()->D1(Param,p2d,d2d); | |
308 | } | |
309 | else { | |
310 | return(Standard_False); | |
311 | } | |
312 | OtherSurf->D1(p2d.X(),p2d.Y(),ptbid,d1u,d1v); | |
313 | if (ptbid.SquareDistance(Ptsom) > Tol2) { | |
314 | return Standard_False; | |
315 | } | |
316 | Tgl.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
317 | return(Standard_True); | |
318 | } | |
319 | ||
320 | else if (typL == IntPatch_Walking) { | |
321 | Standard_Integer i, is, nbpt=wlin->NbPnts(); | |
322 | Standard_Real norm1,norm2; | |
323 | Standard_Integer ParamSearchInf=1; | |
324 | Standard_Integer ParamSearchSup=nbpt; | |
325 | ||
326 | if((ParamApproche-2) > ParamSearchInf) { | |
327 | ParamSearchInf = ParamApproche-2; | |
328 | } | |
329 | if((ParamApproche+2) < ParamSearchSup) { | |
330 | ParamSearchSup = ParamApproche+2; | |
331 | } | |
332 | ||
333 | Standard_Integer inf[3],sup[3]; | |
334 | // first search inside close bounding around ParamApproche; | |
335 | // then search to the nearest end of line; | |
336 | // and then search to the farest end of line. | |
337 | inf[0] = ParamSearchInf; sup[0] = ParamSearchSup; | |
338 | if (ParamSearchInf-1 < nbpt-ParamSearchSup) { | |
339 | inf[1] = 1; sup[1] = ParamSearchInf; | |
340 | inf[2] = ParamSearchSup; sup[2] = nbpt; | |
341 | } | |
342 | else { | |
343 | inf[1] = ParamSearchSup; sup[1] = nbpt; | |
344 | inf[2] = 1; sup[2] = ParamSearchInf; | |
345 | } | |
346 | ||
347 | Standard_Boolean found = Standard_False; | |
348 | for (is=0; is < 3 && !found; is++) { | |
349 | gp_Vec v1,v2; | |
350 | gp_Pnt p1,p2; | |
351 | p1 = wlin->Point(inf[is]).Value(); | |
352 | v1 = gp_Vec (Ptsom,p1); | |
353 | norm1 = v1.SquareMagnitude(); | |
354 | Standard_Real normmin = Tol2; | |
355 | Standard_Integer ibest = 0; | |
356 | if (norm1 <= normmin) { | |
357 | normmin = norm1; | |
358 | ibest = inf[is]; | |
359 | } | |
360 | for (i=inf[is]+1; i <= sup[is] && !found; i++) { | |
361 | p2 = wlin->Point(i).Value(); | |
362 | v2 = gp_Vec (Ptsom,p2); | |
363 | norm2 = v2.SquareMagnitude(); | |
364 | if (v1.Dot(v2) < 0.) { | |
365 | Param = (Standard_Real)(i-1) + 1./(1.+Sqrt(norm2/norm1)); | |
366 | Tgl = gp_Vec (p1,p2); | |
367 | found = Standard_True; | |
368 | } | |
369 | else if (norm2 < normmin) { | |
370 | normmin = norm2; | |
371 | ibest = i; | |
372 | } | |
373 | v1 = v2; p1 = p2; norm1 = norm2; | |
374 | } | |
375 | if (!found && ibest) { | |
376 | Param = (Standard_Real)ibest; | |
377 | found = Standard_True; | |
378 | } | |
379 | } | |
380 | if (found) return Standard_True; | |
381 | } | |
382 | else { | |
383 | Standard_DomainError::Raise(); | |
384 | } | |
385 | return Standard_False; | |
386 | } | |
387 | ||
388 | inline Standard_Boolean ArePnt2dEqual(const gp_Pnt2d& p1, const gp_Pnt2d& p2, | |
389 | const Standard_Real tolU, | |
390 | const Standard_Real tolV) | |
391 | { | |
392 | return Abs(p1.X()-p2.X()) < tolU && Abs(p1.Y()-p2.Y()) < tolV; | |
393 | } | |
394 | ||
395 | static gp_Pnt2d GetPointOnPolygo(const IntPatch_Polygo& Pol, | |
396 | const Standard_Real param) | |
397 | { | |
398 | Standard_Real par = IntegerPart(param); | |
399 | Standard_Integer irang = Standard_Integer(par) + 1; | |
400 | if (irang == Pol.NbPoints()) { | |
401 | irang--; | |
402 | par = 1.; | |
403 | } | |
404 | else { | |
405 | par = Abs(param-par); | |
406 | } | |
407 | gp_Pnt2d p1 = Pol.Point(irang); | |
408 | gp_Pnt2d p2 = Pol.Point(irang+1); | |
409 | gp_Pnt2d p; | |
410 | p.ChangeCoord().SetLinearForm(1.-par,p1.XY(),par,p2.XY()); | |
411 | return p; | |
412 | } | |
413 | ||
414 | static Standard_Boolean IsSegment2dSmall(const IntPatch_Polygo& Pol, | |
415 | const Standard_Real parmin, | |
416 | const Standard_Real parmax, | |
417 | const Standard_Real URes, | |
418 | const Standard_Real VRes) | |
419 | { | |
420 | Standard_Integer irang1 = Standard_Integer(IntegerPart(parmin)) + 2; | |
421 | Standard_Integer irang2 = Standard_Integer(IntegerPart(parmax)) + 1; | |
422 | gp_Pnt2d p1,p2; | |
423 | Standard_Real du=0.,dv=0.; | |
424 | p1 = GetPointOnPolygo(Pol,parmin); | |
425 | for (Standard_Integer i=irang1; i <= irang2 && du <= URes && dv <= VRes; i++) { | |
426 | p2 = Pol.Point(i); | |
427 | du += Abs(p2.X()-p1.X()); | |
428 | dv += Abs(p2.Y()-p1.Y()); | |
429 | p1 = p2; | |
430 | } | |
431 | if (du <= URes && dv <= VRes) { | |
432 | p2 = GetPointOnPolygo(Pol,parmax); | |
433 | du += Abs(p2.X()-p1.X()); | |
434 | dv += Abs(p2.Y()-p1.Y()); | |
435 | } | |
436 | return du <= URes && dv <= VRes; | |
437 | } | |
438 | ||
439 | //======================================================================= | |
440 | //function : PutVertexOnLine | |
441 | //purpose : | |
442 | //======================================================================= | |
443 | ||
7f22979e | 444 | void IntPatch_RstInt::PutVertexOnLine (const Handle(IntPatch_Line)& L, |
7fd59977 | 445 | const Handle(Adaptor3d_HSurface)& Surf, |
446 | const Handle(Adaptor3d_TopolTool)& Domain, | |
447 | const Handle(Adaptor3d_HSurface)& OtherSurf, | |
448 | const Standard_Boolean OnFirst, | |
c2c2f2b6 | 449 | const Standard_Real Tol, |
c04c30b3 | 450 | const Standard_Boolean hasBeenAdded) |
7fd59977 | 451 | { |
452 | ||
453 | // Domain est le domaine de restriction de la surface Surf. | |
454 | // On intersectera un arc de Surf avec la surface OtherSurf. | |
455 | // Si OnFirst = True, c est que la surface Surf correspond a la 1ere | |
456 | // surface donnee aux algo d intersection. | |
457 | ||
1ef32e96 | 458 | IntPatch_SearchPnt Commun; |
7fd59977 | 459 | |
460 | Standard_Real U,V,W; | |
1d47d8d0 | 461 | Standard_Real U1,V1,U2 = 0.,V2 = 0.; |
7fd59977 | 462 | Standard_Real paramarc=0.,paramline=0.; |
463 | Standard_Integer i,j,k; | |
464 | TColgp_SequenceOfPnt locpt; | |
465 | TColgp_SequenceOfPnt2d locpt2; | |
c5f3a425 | 466 | Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (L)); //-- aucune verification n est |
467 | Handle(IntPatch_WLine) wlin (Handle(IntPatch_WLine)::DownCast (L)); //-- faite au cast. | |
7fd59977 | 468 | Standard_Integer Nbvtx =0; |
469 | Standard_Integer Nbptlin =0; | |
470 | Standard_Real tolPLin = Surf->UResolution(Precision::Confusion()); | |
471 | tolPLin = Max (tolPLin, Surf->VResolution(Precision::Confusion())); | |
472 | tolPLin = Min (tolPLin, Precision::Confusion()); | |
473 | IntPatch_PolyLine PLin(tolPLin); | |
474 | ||
475 | Standard_Real PFirst,PLast; | |
476 | Standard_Integer NbEchant; | |
477 | gp_Pnt ptsommet, ptbid; | |
478 | gp_Vec tgline, tgrst, d1u, d1v, normsurf; | |
479 | ||
480 | gp_Pnt2d p2d; | |
481 | gp_Vec2d d2d; | |
482 | ||
483 | IntPatch_Point Sommet, ptline; | |
484 | Handle(Adaptor3d_HVertex) vtxarc,vtxline; | |
485 | Handle(Adaptor2d_HCurve2d) arc; | |
486 | Standard_Boolean VtxOnArc, duplicate, found; | |
487 | IntSurf_Transition transarc,transline; | |
488 | ||
489 | IntPatch_IType typL = L->ArcType(); | |
490 | if (typL == IntPatch_Walking) { | |
491 | Nbvtx = wlin->NbVertex(); | |
492 | PLin.SetWLine(OnFirst,wlin); | |
493 | Nbptlin = wlin->NbPnts(); | |
494 | } | |
495 | else if ( typL == IntPatch_Restriction) { | |
496 | Nbvtx = rlin->NbVertex(); | |
497 | PLin.SetRLine(OnFirst,rlin); | |
498 | Nbptlin = rlin->NbPnts(); | |
499 | } | |
500 | else { | |
501 | Standard_DomainError::Raise(); | |
502 | } | |
503 | if (!Domain->Has3d()) | |
504 | // don't use computed deflection in the mode of pure geometric intersection | |
505 | PLin.ResetError(); | |
506 | ||
507 | const Standard_Boolean SurfaceIsUClosed = Surf->IsUClosed(); | |
508 | const Standard_Boolean SurfaceIsVClosed = Surf->IsVClosed(); | |
509 | const Standard_Boolean OSurfaceIsUClosed = OtherSurf->IsUClosed(); | |
510 | const Standard_Boolean OSurfaceIsVClosed = OtherSurf->IsVClosed(); | |
511 | const Standard_Boolean possiblyClosed = (SurfaceIsUClosed || SurfaceIsVClosed || | |
512 | OSurfaceIsUClosed || OSurfaceIsVClosed); | |
513 | Standard_Real tolUClosed=0., tolVClosed=0., tolOUClosed=0., tolOVClosed=0.; | |
514 | if (possiblyClosed) { | |
515 | if (SurfaceIsUClosed) | |
516 | tolUClosed = (Surf->LastUParameter() - Surf->FirstUParameter()) * 0.01; | |
517 | if (SurfaceIsVClosed) | |
518 | tolVClosed = (Surf->LastVParameter() - Surf->FirstVParameter()) * 0.01; | |
519 | if (OSurfaceIsUClosed) | |
520 | tolOUClosed = (OtherSurf->LastUParameter() - OtherSurf->FirstUParameter()) * 0.01; | |
521 | if (OSurfaceIsVClosed) | |
522 | tolOVClosed = (OtherSurf->LastVParameter() - OtherSurf->FirstVParameter()) * 0.01; | |
523 | } | |
524 | ||
525 | //------------------------------------------------------------------------ | |
526 | //-- On traite le cas ou la surface est periodique -- | |
527 | //-- il faut dans ce cas considerer la restriction -- | |
528 | //-- la restriction decalee de +-2PI -- | |
529 | //------------------------------------------------------------------------ | |
530 | const Handle(Adaptor3d_HSurface)& Surf1 = (OnFirst ? Surf : OtherSurf); | |
531 | const Handle(Adaptor3d_HSurface)& Surf2 = (OnFirst ? OtherSurf : Surf); | |
532 | GeomAbs_SurfaceType TypeS1 = Surf1->GetType(); | |
533 | GeomAbs_SurfaceType TypeS2 = Surf2->GetType(); | |
534 | Standard_Boolean SurfaceIsPeriodic = Standard_False; | |
535 | Standard_Boolean SurfaceIsBiPeriodic = Standard_False; | |
536 | GeomAbs_SurfaceType surfacetype = (OnFirst ? TypeS1 : TypeS2); | |
537 | if( surfacetype == GeomAbs_Cylinder | |
538 | || surfacetype == GeomAbs_Cone | |
539 | || surfacetype == GeomAbs_Torus | |
540 | || surfacetype == GeomAbs_Sphere) { | |
541 | SurfaceIsPeriodic = Standard_True; | |
542 | if(surfacetype == GeomAbs_Torus) { | |
543 | SurfaceIsBiPeriodic = Standard_True; | |
544 | } | |
545 | } | |
546 | ||
547 | Standard_Integer NumeroEdge=0; | |
548 | Domain->Init(); | |
549 | while (Domain->More()) { | |
550 | NumeroEdge++; | |
551 | arc = Domain->Value(); | |
552 | ||
553 | // MSV Oct 15, 2001: use tolerance of this edge if possible | |
554 | Standard_Real edgeTol = Tol3d(arc,Domain,Tol); | |
555 | Standard_Real URes = Surf->UResolution(edgeTol); | |
556 | Standard_Real VRes = Surf->VResolution(edgeTol); | |
557 | ||
558 | IntPatch_HInterTool::Bounds(arc,PFirst,PLast); | |
7c4e9501 | 559 | if(Precision::IsNegativeInfinite(PFirst)) |
560 | PFirst = -myInfinite; | |
561 | if(Precision::IsPositiveInfinite(PLast)) | |
562 | PLast = myInfinite; | |
563 | //if (Precision::IsNegativeInfinite(PFirst) || | |
564 | // Precision::IsPositiveInfinite(PLast)) { | |
565 | // //-- cout<<" IntPatch_RstInt::PutVertexOnLine ---> Restrictions Infinies :"<<endl; | |
566 | // return; | |
567 | //} | |
7fd59977 | 568 | |
569 | Standard_Boolean isVFirst = Standard_False, isVLast = Standard_False; | |
570 | gp_Pnt2d p2dFirst,p2dLast; | |
571 | Standard_Real tolUFirst=0.,tolVFirst=0.,tolULast=0.,tolVLast=0.; | |
572 | Domain->Initialize(arc); | |
573 | for (Domain->InitVertexIterator(); Domain->MoreVertex(); Domain->NextVertex()) { | |
574 | Handle(Adaptor3d_HVertex) vtx = Domain->Vertex(); | |
575 | Standard_Real prm = IntPatch_HInterTool::Parameter(vtx,arc); | |
576 | if (Abs(prm - PFirst) < Precision::PConfusion()) { | |
577 | arc->D0(PFirst,p2dFirst); | |
578 | Standard_Real tol3d = Max (Tol3d(vtx,Domain), edgeTol); | |
579 | tolUFirst = Surf->UResolution(tol3d); | |
580 | tolVFirst = Surf->VResolution(tol3d); | |
581 | isVFirst = Standard_True; | |
582 | } | |
583 | else if (Abs(prm - PLast) < Precision::PConfusion()) { | |
584 | arc->D0(PLast,p2dLast); | |
585 | Standard_Real tol3d = Max (edgeTol, Tol3d(vtx,Domain)); | |
586 | tolULast = Surf->UResolution(tol3d); | |
587 | tolVLast = Surf->VResolution(tol3d); | |
588 | isVLast = Standard_True; | |
589 | } | |
590 | } | |
591 | ||
9530af27 | 592 | Bnd_Box2d BPLin = PLin.Bounding(); |
7fd59977 | 593 | |
594 | if(SurfaceIsPeriodic) { | |
595 | Standard_Real xmin,ymin,xmax,ymax,g; | |
596 | BPLin.Get(xmin,ymin,xmax,ymax); | |
597 | g = BPLin.GetGap(); | |
598 | BPLin.SetVoid(); | |
c6541a0c D |
599 | BPLin.Update(xmin-M_PI-M_PI,ymin, |
600 | xmax+M_PI+M_PI,ymax); | |
7fd59977 | 601 | BPLin.SetGap(g); |
602 | } | |
603 | if(SurfaceIsBiPeriodic) { | |
604 | Standard_Real xmin,ymin,xmax,ymax,g; | |
605 | BPLin.Get(xmin,ymin,xmax,ymax); | |
606 | g = BPLin.GetGap(); | |
607 | BPLin.SetVoid(); | |
c6541a0c D |
608 | BPLin.Update(xmin,ymin-M_PI-M_PI, |
609 | xmax,ymax+M_PI+M_PI); | |
7fd59977 | 610 | BPLin.SetGap(g); |
611 | } | |
612 | ||
613 | switch(arc->GetType()) | |
614 | { | |
615 | case GeomAbs_Line: NbEchant=10; break; | |
616 | case GeomAbs_BezierCurve: | |
617 | { | |
618 | NbEchant = (3 + arc->NbPoles()); | |
619 | if(NbEchant<10) NbEchant=10; | |
620 | else if(NbEchant>50) NbEchant=50; | |
621 | } | |
622 | break; | |
623 | case GeomAbs_BSplineCurve: | |
624 | { | |
625 | //szv:const Standard_Real nbs = (arc->NbKnots() * arc->Degree())*(arc->LastParameter() - arc->FirstParameter())/(PLast-PFirst); | |
626 | const Standard_Real nbs = (arc->NbKnots() * arc->Degree())*(PLast-PFirst)/(arc->LastParameter() - arc->FirstParameter()); | |
627 | NbEchant = (nbs < 2.0 ? 2 : (Standard_Integer)nbs); | |
628 | if(NbEchant<10) NbEchant=10; | |
629 | else if (NbEchant>50) NbEchant=50; | |
630 | } | |
631 | break; | |
632 | default: | |
633 | { | |
634 | NbEchant = 25; | |
635 | } | |
636 | } | |
637 | ||
638 | IntPatch_PolyArc Brise(arc,NbEchant,PFirst,PLast,BPLin); | |
639 | ||
640 | Standard_Integer IndiceOffsetBiPeriodic = 0; | |
641 | Standard_Integer IndiceOffsetPeriodic = 0; | |
642 | Standard_Real OffsetV = 0.0; | |
643 | Standard_Real OffsetU = 0.0; | |
644 | ||
645 | do { | |
646 | if(IndiceOffsetBiPeriodic == 1) | |
c6541a0c | 647 | OffsetV = -M_PI-M_PI; |
7fd59977 | 648 | else if(IndiceOffsetBiPeriodic == 2) |
c6541a0c | 649 | OffsetV = M_PI+M_PI; |
7fd59977 | 650 | |
651 | do { | |
652 | if(IndiceOffsetPeriodic == 1) | |
c6541a0c | 653 | OffsetU = -M_PI-M_PI; |
7fd59977 | 654 | else if(IndiceOffsetPeriodic == 2) |
c6541a0c | 655 | OffsetU = M_PI+M_PI; |
7fd59977 | 656 | |
657 | Brise.SetOffset(OffsetU,OffsetV); | |
658 | ||
659 | static int debug_polygon2d =0; | |
660 | if(debug_polygon2d) { | |
661 | cout<<" ***** Numero Restriction : "<<NumeroEdge<<" *****"<<endl; | |
9530af27 | 662 | PLin.Dump(); |
663 | Brise.Dump(); | |
7fd59977 | 664 | } |
665 | ||
666 | Commun.Perform(PLin,Brise); | |
667 | locpt.Clear(); | |
668 | locpt2.Clear(); | |
669 | Standard_Integer Commun_NbSectionPoints = Commun.NbSectionPoints(); | |
670 | Standard_Integer Commun_NbTangentZones = Commun.NbTangentZones(); | |
671 | Standard_Integer Commun_Section_Tangent = Commun_NbSectionPoints | |
672 | + Commun_NbTangentZones; | |
673 | for (i=1;i<=Commun_Section_Tangent;i++) { | |
674 | Standard_Real W1[2],W2[2]; | |
675 | Standard_Boolean refine[2],useWL[2]; | |
676 | Standard_Integer nbpt = 1; | |
677 | if(i<=Commun_NbSectionPoints) { | |
678 | // intersection point | |
679 | W1[0] = Commun.PntValue(i).ParamOnFirst(); | |
680 | W2[0] = Commun.PntValue(i).ParamOnSecond(); | |
681 | refine[0] = Standard_True; | |
682 | } | |
683 | else { | |
684 | // tangent zone | |
685 | Standard_Real UMinCh,UMaxCh; //-- ligne de cheminement 0..(Nbptlin-1) | |
686 | Standard_Real UMinAr,UMaxAr; //-- polyline of arc 0..(NbEchant-1) | |
687 | Commun.ZoneValue(i-Commun_NbSectionPoints).ParamOnFirst(UMinCh,UMaxCh); | |
688 | Commun.ZoneValue(i-Commun_NbSectionPoints).ParamOnSecond(UMinAr,UMaxAr); | |
689 | gp_Pnt2d p1Ar = GetPointOnPolygo(Brise,UMinAr); | |
690 | gp_Pnt2d p2Ar = GetPointOnPolygo(Brise,UMaxAr); | |
691 | Standard_Real tolU = URes*2.; | |
692 | Standard_Real tolV = VRes*2.; | |
693 | if (isVFirst && ArePnt2dEqual(p1Ar,p2dFirst,tolUFirst,tolVFirst)) { | |
694 | tolU = Max(tolUFirst,tolU); tolV = Max(tolVFirst,tolV); | |
695 | } | |
696 | if (isVLast && ArePnt2dEqual(p2Ar,p2dLast,tolULast,tolVLast)) { | |
697 | tolU = Max(tolULast,tolU); tolV = Max(tolVLast,tolV); | |
698 | } | |
699 | Standard_Real nptCh = UMaxCh-UMinCh; | |
0ebaa4db | 700 | Standard_Boolean isNptLow = (nptCh < 10. && nptCh < Nbptlin/100.) || |
701 | (!Domain->Has3d() && Standard_Integer(nptCh)+1 < Nbptlin); | |
7fd59977 | 702 | if (!isNptLow && !IsSegment2dSmall(Brise,UMinAr,UMaxAr,tolU,tolV)) { |
703 | // treat both ends | |
96a95605 DB |
704 | Standard_Real UMinChP,UMinArP,UMaxArP; |
705 | UMinChP = IntegerPart(UMinCh); | |
706 | UMinArP = IntegerPart(UMinAr); | |
707 | UMaxArP = IntegerPart(UMaxAr); | |
708 | Standard_Integer irangAr1,irangAr2; | |
709 | irangAr1 = Standard_Integer(UMinArP)+1; | |
710 | irangAr2 = Standard_Integer(UMaxArP)+1; | |
711 | UMinChP = UMinCh - UMinChP; | |
712 | UMinArP = UMinAr - UMinArP; | |
7fd59977 | 713 | //UMaxChP = UMaxCh - UMaxChP; UMaxArP = UMaxAr - UMaxArP; |
714 | const Standard_Real eps = 1e-10; | |
715 | // Standard_Boolean isChExtr1 = irangCh1==1 && UMinChP<eps; | |
716 | // Standard_Boolean isChExtr2 = irangCh2==Nbptlin; | |
717 | Standard_Boolean isArExtr1 = irangAr1==1 && UMinArP<eps; | |
718 | Standard_Boolean isArExtr2 = irangAr2==NbEchant; | |
719 | // detect orientation | |
720 | gp_Pnt2d p1Ch = GetPointOnPolygo(PLin,UMinCh); | |
721 | Standard_Real d11 = p1Ch.SquareDistance(p1Ar); | |
722 | Standard_Real d12 = p1Ch.SquareDistance(p2Ar); | |
723 | Standard_Boolean sameOri = d11 < d12; | |
724 | if (!sameOri) { | |
725 | Standard_Boolean itmp=isArExtr1; isArExtr1=isArExtr2; isArExtr2=itmp; | |
726 | Standard_Real dtmp=UMinAr; UMinAr=UMaxAr; UMaxAr=dtmp; | |
727 | } | |
728 | W1[0] = UMinCh; W1[1] = UMaxCh; | |
729 | W2[0] = UMinAr; W2[1] = UMaxAr; | |
730 | //refine[0] = ! (isChExtr1 || isArExtr1); | |
731 | //refine[1] = ! (isChExtr2 || isArExtr2); | |
732 | refine[0] = refine[1] = Standard_False; | |
733 | useWL[0] = !isArExtr1; | |
734 | useWL[1] = !isArExtr2; | |
735 | nbpt = 2; | |
736 | } | |
737 | else { | |
738 | // treat the middle point as an intersection point | |
739 | W1[0] = 0.5*(UMinCh+UMaxCh); | |
740 | W2[0] = 0.5*(UMinAr+UMaxAr); | |
741 | refine[0] = Standard_True; | |
742 | } | |
743 | } | |
744 | ||
745 | Standard_Boolean nbTreated = 0; | |
746 | for (Standard_Integer ip=0; ip < nbpt; ip++) { | |
747 | GetLinePoint2d (L, W1[ip]+1, !OnFirst, U,V); | |
748 | ||
749 | if (!refine[ip] && useWL[ip]) { | |
750 | Standard_Real aU1,aV1; | |
751 | GetLinePoint2d (L, W1[ip]+1, OnFirst, aU1,aV1); | |
752 | p2d.SetCoord(aU1,aV1); | |
753 | Standard_Real paramProj; | |
754 | if (!IntPatch_HInterTool::Project(arc,p2d,paramProj,p2d)) continue; | |
755 | W = paramProj; | |
756 | } | |
757 | else { | |
758 | Standard_Real par = IntegerPart(W2[ip]); | |
759 | Standard_Integer Irang = Standard_Integer(par) + 1; | |
760 | if (Irang == Brise.NbPoints()) { | |
761 | Irang--; | |
762 | par = 1.; | |
763 | } | |
764 | else { | |
765 | par =Abs(W2[ip]-par); | |
766 | } | |
767 | W = (1.-par)*Brise.Parameter(Irang) + par*Brise.Parameter(Irang+1); | |
768 | } | |
769 | ||
770 | Standard_Boolean refined = Standard_False; | |
0cbfb9f1 | 771 | if (refine[ip]) |
772 | { | |
773 | //------------------------------------------------------------------------ | |
774 | //-- On a trouve un point 2d approche Ua,Va intersection de la ligne | |
775 | //-- de cheminement et de la restriction. | |
776 | //-- | |
777 | //-- On injecte ce point ds les intersections Courbe-Surface | |
778 | //-- | |
779 | IntPatch_CSFunction thefunc(OtherSurf,arc,Surf); | |
780 | // MSV: extend UV bounds to not miss solution near the boundary | |
781 | Standard_Real margCoef = 0.004; | |
782 | IntPatch_CurvIntSurf IntCS(U,V,W,thefunc,edgeTol,margCoef); | |
783 | if (IntCS.IsDone()) | |
784 | { | |
785 | if (!IntCS.IsEmpty()) | |
786 | { | |
787 | ptsommet = IntCS.Point(); | |
788 | IntCS.ParameterOnSurface(U2,V2); | |
789 | gp_Pnt anOldPnt, aNewPnt; | |
790 | OtherSurf->D0(U,V, anOldPnt); | |
791 | OtherSurf->D0(U2,V2, aNewPnt); | |
792 | if (anOldPnt.SquareDistance(aNewPnt) < Precision::Confusion() | |
793 | * Precision::Confusion()) | |
794 | { | |
795 | U2 = U; | |
796 | V2 = V; | |
797 | } | |
798 | paramarc = IntCS.ParameterOnCurve(); | |
799 | refined = Standard_True; | |
800 | } | |
801 | } | |
802 | } | |
7fd59977 | 803 | else { |
804 | U2 = U; V2 = V; | |
805 | paramarc = W; | |
806 | arc->D0(paramarc,p2d); | |
807 | Surf->D0(p2d.X(),p2d.Y(),ptsommet); | |
808 | } | |
809 | ||
810 | if (!refine[ip] || refined) { | |
811 | duplicate = Standard_False; | |
812 | for (j=1; j<=locpt.Length();j++) { | |
813 | if (ptsommet.Distance(locpt(j)) <= edgeTol) { | |
814 | if (possiblyClosed) { | |
815 | locpt2(j).Coord(U,V); | |
0ebaa4db | 816 | if ((OSurfaceIsUClosed && Abs(U-U2) > tolOUClosed) || |
817 | (OSurfaceIsVClosed && Abs(V-V2) > tolOVClosed)) | |
7fd59977 | 818 | continue; |
819 | } | |
820 | duplicate = Standard_True; | |
821 | break; | |
822 | } | |
823 | } | |
824 | ||
825 | if (!duplicate) { | |
eafb234b | 826 | Standard_Integer ParamApproxOnLine = Standard_Integer(W1[ip])+1; |
827 | ||
828 | arc->D1(paramarc,p2d,d2d); | |
829 | U1 = p2d.X(); V1 = p2d.Y(); | |
830 | if (typL == IntPatch_Walking && SurfaceIsPeriodic) { | |
831 | if (OnFirst) | |
832 | Recadre(TypeS1,TypeS2,wlin,ParamApproxOnLine,U1,V1,U2,V2); | |
833 | else | |
834 | Recadre(TypeS1,TypeS2,wlin,ParamApproxOnLine,U2,V2,U1,V1); | |
835 | } | |
7fd59977 | 836 | locpt.Append(ptsommet); |
837 | locpt2.Append(gp_Pnt2d(U2,V2)); | |
838 | ||
839 | found = FindParameter(L,OtherSurf,edgeTol,ptsommet,gp_Pnt2d(U2,V2), | |
840 | paramline,tgline,ParamApproxOnLine,OnFirst); | |
841 | ||
842 | if (typL == IntPatch_Walking && found && possiblyClosed) { | |
843 | // check in 2d | |
844 | if (SurfaceIsUClosed || SurfaceIsVClosed) { | |
845 | GetLinePoint2d (L, paramline, OnFirst, U,V); | |
0ebaa4db | 846 | if ((SurfaceIsUClosed && Abs(U-U1) > tolUClosed) || |
847 | (SurfaceIsVClosed && Abs(V-V1) > tolVClosed)) | |
7fd59977 | 848 | found = Standard_False; |
849 | } | |
850 | if (found && (OSurfaceIsUClosed || OSurfaceIsVClosed)) { | |
851 | GetLinePoint2d (L, paramline, !OnFirst, U,V); | |
0ebaa4db | 852 | if ((OSurfaceIsUClosed && Abs(U-U2) > tolOUClosed) || |
853 | (OSurfaceIsVClosed && Abs(V-V2) > tolOVClosed)) | |
7fd59977 | 854 | found = Standard_False; |
855 | } | |
856 | } | |
857 | if (!found) { | |
858 | continue; | |
859 | } | |
860 | ||
861 | VtxOnArc = CoincideOnArc(ptsommet,arc,Surf,edgeTol,Domain,vtxarc); | |
862 | Standard_Real vtxTol; | |
863 | if (VtxOnArc) { | |
864 | vtxTol = Tol3d(vtxarc,Domain); | |
865 | if (edgeTol > vtxTol) vtxTol = edgeTol; | |
866 | } | |
867 | else vtxTol = edgeTol; | |
868 | ||
869 | //-- It is necessary to test that the point does not already exist | |
870 | //-- - It can be already a point on arc | |
871 | //-- BUT on a different arc | |
872 | // MSV 27.03.2002: find the nearest point; add check in 2d | |
873 | Standard_Integer ivtx = 0; | |
874 | Standard_Real dmin = RealLast(); | |
875 | for (j=1; j<=Nbvtx; j++) { | |
876 | const IntPatch_Point& Rptline = (typL == IntPatch_Walking | |
877 | ? wlin->Vertex(j) | |
878 | : rlin->Vertex(j)); | |
879 | Standard_Boolean APointOnRstStillExist = | |
0ebaa4db | 880 | ((OnFirst && Rptline.IsOnDomS1() && Rptline.ArcOnS1() == arc) || |
881 | (!OnFirst && Rptline.IsOnDomS2() && Rptline.ArcOnS2() == arc)); | |
7fd59977 | 882 | if(!APointOnRstStillExist) { |
883 | if (possiblyClosed) { | |
884 | if (SurfaceIsUClosed || SurfaceIsVClosed) { | |
885 | if (OnFirst) Rptline.ParametersOnS1(U,V); | |
886 | else Rptline.ParametersOnS2(U,V); | |
0ebaa4db | 887 | if ((SurfaceIsUClosed && Abs(U-U1) > tolUClosed) || |
888 | (SurfaceIsVClosed && Abs(V-V1) > tolVClosed)) | |
7fd59977 | 889 | continue; |
890 | } | |
891 | if (OSurfaceIsUClosed || OSurfaceIsVClosed) { | |
892 | if (OnFirst) Rptline.ParametersOnS2(U,V); | |
893 | else Rptline.ParametersOnS1(U,V); | |
0ebaa4db | 894 | if ((OSurfaceIsUClosed && Abs(U-U2) > tolOUClosed) || |
895 | (OSurfaceIsVClosed && Abs(V-V2) > tolOVClosed)) | |
7fd59977 | 896 | continue; |
897 | } | |
898 | } | |
899 | Standard_Real dist = ptsommet.Distance(Rptline.Value()); | |
900 | Standard_Real dt = Max(vtxTol, Rptline.Tolerance()); | |
901 | if (dist < dmin) { | |
902 | if (dist <= dt) { | |
903 | ptline = Rptline; | |
904 | ivtx = j; | |
905 | if( surfacetype == GeomAbs_Cone ) { | |
906 | ivtx = 0; | |
907 | } | |
908 | } | |
909 | else { | |
910 | // cancel previous solution because this point is better | |
911 | // but its tolerance is not large enough | |
912 | ivtx = 0; | |
913 | } | |
914 | dmin = dist; | |
915 | } | |
916 | } | |
917 | } | |
918 | if (ivtx) { | |
919 | if (ptline.Tolerance() > vtxTol) { | |
920 | vtxTol = ptline.Tolerance(); | |
921 | if (!VtxOnArc) { | |
922 | // now we should repeat attempt to coincide on a bound of arc | |
923 | VtxOnArc = CoincideOnArc(ptsommet,arc,Surf,vtxTol,Domain,vtxarc); | |
924 | if (VtxOnArc) { | |
925 | Standard_Real tol = Tol3d(vtxarc,Domain); | |
926 | if (tol > vtxTol) vtxTol = tol; | |
927 | } | |
928 | } | |
929 | } | |
930 | } | |
931 | ||
932 | if (typL == IntPatch_Walking) | |
933 | VerifyTgline(wlin,(Standard_Integer)paramline,edgeTol,tgline); | |
934 | ||
935 | Surf->D1(U1,V1,ptbid,d1u,d1v); | |
936 | tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
937 | ||
938 | normsurf = d1u.Crossed(d1v); | |
939 | if (normsurf.Magnitude() < gp::Resolution()) { | |
940 | transline.SetValue(Standard_True,IntSurf_Undecided); | |
941 | transarc.SetValue(Standard_True,IntSurf_Undecided); | |
942 | } | |
943 | else | |
944 | IntSurf::MakeTransition(tgline,tgrst,normsurf,transline,transarc); | |
945 | ||
946 | if (typL == IntPatch_Walking && !refine[ip]) { | |
947 | // for new vertex use coordinates from Line | |
948 | if (OnFirst) | |
949 | GetWLinePoint (wlin, paramline, U1,V1,U2,V2,ptsommet); | |
950 | else | |
951 | GetWLinePoint (wlin, paramline, U2,V2,U1,V1,ptsommet); | |
952 | } | |
953 | ||
954 | nbTreated++; | |
955 | if (!ivtx) { | |
956 | Sommet.SetValue(ptsommet,vtxTol,Standard_False); // pour tangence | |
957 | if (OnFirst) | |
958 | Sommet.SetParameters(U1,V1,U2,V2); | |
959 | else | |
960 | Sommet.SetParameters(U2,V2,U1,V1); | |
961 | ||
962 | if (VtxOnArc) | |
963 | Sommet.SetVertex(OnFirst,vtxarc); | |
964 | ||
965 | //--------------------------------------------------------- | |
966 | //-- lbr : On remplace le point d indice paramline sur la - | |
967 | //-- ligne par le vertex . - | |
968 | //--------------------------------------------------------- | |
969 | Sommet.SetParameter(paramline); // sur ligne d intersection | |
970 | Sommet.SetArc(OnFirst,arc,paramarc,transline,transarc); | |
971 | ||
972 | if (typL == IntPatch_Walking) { | |
973 | wlin->AddVertex(Sommet); | |
974 | Nbvtx++; | |
975 | } | |
976 | else { | |
977 | rlin->AddVertex(Sommet); | |
978 | Nbvtx++; | |
979 | } | |
980 | } | |
981 | else { | |
982 | // CAS DE FIGURE : en appelant s1 la surf sur laquelle on | |
983 | // connait les pts sur restriction, et s2 celle sur laquelle | |
984 | // on les cherche. Le point trouve verifie necessairement | |
985 | // IsOnDomS1 = True. | |
986 | // Pas vtxS1, pas vtxS2 : | |
987 | // on recupere le point et on applique SetArcOnS2 et | |
988 | // eventuellement SetVertexOnS2. Si on a deja IsOnDomS2, | |
989 | // on considere que le point est deja traite, mais ne devrait | |
990 | // pas se produire. | |
991 | // vtxS1, pas vtxS2 : | |
992 | // si pas IsOnDomS2 : pour chaque occurrence, faire SetArcOnS2, | |
993 | // et eventuellement SetVertexOnS2. | |
994 | // si IsOnDomS2 : impossible, on doit avoir IsVtxOnS2. | |
995 | // vtxS1,vtxS2 : | |
996 | // on doit avoir VtxOnArc = True. On duplique chaque occurrence | |
997 | // "sur S1" du point en changeant ArcOnS2. | |
998 | // pas vtxS1, vtxS2 : | |
999 | // on doit avoir VtxOnArc = True. On duplique le point sur S1 | |
1000 | // en changeant ArcOnS2. | |
1001 | Standard_Boolean OnDifferentRst = | |
0ebaa4db | 1002 | ((OnFirst && ptline.IsOnDomS1() && ptline.ArcOnS1() != arc) || |
1003 | (!OnFirst && ptline.IsOnDomS2() && ptline.ArcOnS2() != arc)); | |
7fd59977 | 1004 | ptline.SetTolerance(vtxTol); |
1005 | if ( (!ptline.IsVertexOnS1() && OnFirst) | |
1006 | || (!ptline.IsVertexOnS2() && !OnFirst) | |
1007 | || (OnDifferentRst)) { | |
1008 | if ( (!ptline.IsOnDomS2() && !OnFirst) | |
1009 | ||(!ptline.IsOnDomS1() && OnFirst) | |
1010 | ||(OnDifferentRst)) { | |
1011 | ptline.SetArc(OnFirst,arc,paramarc,transline,transarc); | |
1012 | //ptline.SetParameter(paramline); //-- rajout lbr le 20 nov 97 | |
1013 | if (VtxOnArc) | |
1014 | ptline.SetVertex(OnFirst,vtxarc); | |
1015 | if (typL == IntPatch_Walking) { | |
1016 | if(OnDifferentRst) { | |
1017 | wlin->AddVertex(ptline); | |
1018 | Nbvtx++; | |
1019 | } | |
1020 | else { | |
1021 | wlin->Replace(ivtx,ptline); | |
1022 | } | |
1023 | } | |
1024 | else { | |
1025 | if(OnDifferentRst) { | |
1026 | rlin->AddVertex(ptline); | |
1027 | Nbvtx++; | |
1028 | } | |
1029 | else { | |
1030 | rlin->Replace(ivtx,ptline); | |
1031 | } | |
1032 | } | |
1033 | } | |
1034 | else if ( ( OnFirst && ptline.IsVertexOnS2()) | |
1035 | ||(!OnFirst && ptline.IsVertexOnS1())) { | |
1036 | Sommet = ptline; | |
1037 | Sommet.SetArc(OnFirst,arc,paramarc,transline,transarc); | |
1038 | if (VtxOnArc) | |
1039 | Sommet.SetVertex(OnFirst,vtxarc); | |
1040 | if (typL == IntPatch_Walking) { | |
1041 | wlin->AddVertex(Sommet); | |
1042 | Nbvtx++; | |
1043 | } | |
1044 | else { | |
1045 | rlin->AddVertex(Sommet); | |
1046 | Nbvtx++; | |
1047 | } | |
1048 | } | |
1049 | else { | |
1050 | //-- cout << "pb dans RstInt Type 1 " << endl; | |
1051 | } | |
1052 | } | |
1053 | else { | |
1054 | Handle(Adaptor3d_HVertex) vtxref = (OnFirst)? (ptline.VertexOnS1()) : (ptline.VertexOnS2()) ; | |
1055 | if ( ( OnFirst && !ptline.IsOnDomS2()) | |
1056 | ||(!OnFirst && !ptline.IsOnDomS1())) { | |
1057 | ptline.SetArc(OnFirst,arc,paramarc,transline,transarc); | |
1058 | if (VtxOnArc) | |
1059 | ptline.SetVertex(OnFirst,vtxarc); | |
1060 | if (typL == IntPatch_Walking) { | |
1061 | wlin->Replace(ivtx,ptline); | |
1062 | } | |
1063 | else { | |
1064 | rlin->Replace(ivtx,ptline); | |
1065 | } | |
1066 | ||
1067 | for (k=1; k<=Nbvtx; k++) if (k != ivtx) { | |
1068 | if (typL == IntPatch_Walking) { | |
1069 | ptline = wlin->Vertex(k); | |
1070 | } | |
1071 | else { | |
1072 | ptline = rlin->Vertex(k); | |
1073 | } | |
1074 | if ( ( OnFirst && ptline.IsVertexOnS1()) | |
1075 | || (!OnFirst && ptline.IsVertexOnS2())) { | |
1076 | if (Domain->Identical(vtxref, (OnFirst)? (ptline.VertexOnS1()) : (ptline.VertexOnS2()))) { | |
1077 | if (ptline.Tolerance() < vtxTol) ptline.SetTolerance(vtxTol); | |
1078 | ptline.SetArc(OnFirst,arc,paramarc,transline,transarc); | |
1079 | if (VtxOnArc) | |
1080 | ptline.SetVertex(OnFirst,vtxarc); | |
1081 | if (typL == IntPatch_Walking) { | |
1082 | wlin->Replace(k,ptline); | |
1083 | } | |
1084 | else { | |
1085 | rlin->Replace(k,ptline); | |
1086 | } | |
1087 | } | |
1088 | } | |
1089 | } | |
1090 | } | |
1091 | else if( ( OnFirst && ptline.IsVertexOnS2()) | |
1092 | || (!OnFirst && ptline.IsVertexOnS1())) { | |
1093 | // on doit avoir vtxons2 = vtxarc... pas de verif... | |
1094 | Sommet = ptline; | |
1095 | Sommet.SetArc(OnFirst,arc,paramarc,transline,transarc); | |
1096 | if (typL == IntPatch_Walking) { | |
1097 | wlin->AddVertex(Sommet); | |
1098 | Nbvtx++; | |
1099 | } | |
1100 | else { | |
1101 | rlin->AddVertex(Sommet); | |
1102 | Nbvtx++; | |
1103 | } | |
1104 | for (k=1; k<=Nbvtx; k++) if (k != ivtx) { | |
1105 | if (typL == IntPatch_Walking) { | |
1106 | ptline = wlin->Vertex(k); | |
1107 | } | |
1108 | else { | |
1109 | ptline = rlin->Vertex(k); | |
1110 | } | |
1111 | if ( ( OnFirst && ptline.IsVertexOnS1()) | |
1112 | ||(!OnFirst && ptline.IsVertexOnS2())) { | |
1113 | if (Domain->Identical(vtxref,(OnFirst)? (ptline.VertexOnS1()) : (ptline.VertexOnS2()))) { | |
1114 | if (ptline.Tolerance() < vtxTol) ptline.SetTolerance(vtxTol); | |
1115 | Sommet = ptline; | |
1116 | Sommet.SetArc(OnFirst,arc,paramarc,transline,transarc); | |
1117 | if (typL == IntPatch_Walking) { | |
1118 | wlin->Replace(k,ptline); | |
1119 | wlin->AddVertex(Sommet); | |
1120 | Nbvtx++; | |
1121 | } | |
1122 | else { | |
1123 | rlin->Replace(k,ptline); | |
1124 | rlin->AddVertex(Sommet); | |
1125 | Nbvtx++; | |
1126 | } | |
1127 | } | |
1128 | } | |
1129 | } | |
1130 | ||
1131 | } | |
1132 | else { | |
1133 | //-- cout << "pb dans RstInt Type 2 " << endl; | |
1134 | } | |
1135 | } | |
1136 | } | |
1137 | } | |
1138 | } | |
1139 | } | |
1140 | if (nbTreated == 2 && typL == IntPatch_Walking) { | |
1141 | // We processed a tangent zone, and both ends have been treated. | |
1142 | // So mark WLine as having arc | |
1143 | if(OnFirst) wlin->SetArcOnS1(arc); | |
1144 | else wlin->SetArcOnS2(arc); | |
1145 | } | |
1146 | } | |
1147 | ||
1148 | IndiceOffsetPeriodic++; | |
1149 | } | |
1150 | while(SurfaceIsPeriodic && IndiceOffsetPeriodic<=2); | |
1151 | ||
1152 | IndiceOffsetBiPeriodic++; | |
1153 | } | |
1154 | while(SurfaceIsBiPeriodic && IndiceOffsetBiPeriodic<=2); | |
1155 | Domain->Next(); | |
1156 | } | |
1157 | ||
1158 | //-------------------------------------------------------------------------------- | |
1159 | //-- On reprend la ligne et on recale les parametres des vertex. | |
1160 | //-- | |
1161 | if (typL == IntPatch_Walking) { | |
1162 | Standard_Real pu1,pv1,pu2,pv2; | |
1163 | pu1=pv1=pu2=pv2=0.0; | |
1164 | switch(TypeS1) { | |
1165 | case GeomAbs_Cylinder: | |
1166 | case GeomAbs_Cone: | |
1167 | case GeomAbs_Sphere: | |
c6541a0c | 1168 | pu1=M_PI+M_PI; |
7fd59977 | 1169 | break; |
1170 | case GeomAbs_Torus: | |
c6541a0c | 1171 | pu1=pv1=M_PI+M_PI; |
7fd59977 | 1172 | break; |
1173 | default: | |
1174 | { | |
1175 | if( Surf1->IsUPeriodic()) { | |
1176 | pu1=Surf1->UPeriod(); | |
1177 | } | |
1178 | else if(Surf1->IsUClosed()) { | |
1179 | pu1=Surf1->LastUParameter() - Surf1->FirstUParameter(); | |
1180 | //cout<<" UClosed1 "<<pu1<<endl; | |
1181 | } | |
1182 | if( Surf1->IsVPeriodic()) { | |
1183 | pv1=Surf1->VPeriod(); | |
1184 | } | |
1185 | else if(Surf1->IsVClosed()) { | |
1186 | pv1=Surf1->LastVParameter() - Surf1->FirstVParameter(); | |
1187 | //cout<<" VClosed1 "<<pv1<<endl; | |
1188 | } | |
1189 | ||
1190 | break; | |
1191 | } | |
1192 | } | |
1193 | ||
1194 | switch(TypeS2) { | |
1195 | case GeomAbs_Cylinder: | |
1196 | case GeomAbs_Cone: | |
1197 | case GeomAbs_Sphere: | |
1198 | ||
c6541a0c | 1199 | pu2=M_PI+M_PI; |
7fd59977 | 1200 | break; |
1201 | case GeomAbs_Torus: | |
c6541a0c | 1202 | pu2=pv2=M_PI+M_PI; |
7fd59977 | 1203 | break; |
1204 | default: | |
1205 | { | |
1206 | if( Surf2->IsUPeriodic()) { | |
1207 | pu2=Surf2->UPeriod(); | |
1208 | } | |
1209 | else if(Surf2->IsUClosed()) { | |
1210 | pu2=Surf2->LastUParameter() - Surf2->FirstUParameter(); | |
1211 | //cout<<" UClosed2 "<<pu2<<endl; | |
1212 | } | |
1213 | ||
1214 | if( Surf2->IsVPeriodic()) { | |
1215 | pv2=Surf2->VPeriod(); | |
1216 | } | |
1217 | else if(Surf2->IsVClosed()) { | |
1218 | pv2=Surf2->LastVParameter() - Surf2->FirstVParameter(); | |
1219 | //cout<<" VClosed2 "<<pv2<<endl; | |
1220 | } | |
1221 | ||
1222 | break; | |
1223 | } | |
1224 | } | |
1225 | ||
1226 | /* | |
1227 | if(pu1==0) { | |
1228 | pu1=Surf1->LastUParameter() - Surf1->FirstUParameter(); | |
1229 | pu1+=pu1; | |
1230 | } | |
1231 | if(pu2==0) { | |
1232 | pu2=Surf2->LastUParameter() - Surf2->FirstUParameter(); | |
1233 | pu2+=pu2; | |
1234 | } | |
1235 | if(pv1==0) { | |
1236 | pv1=Surf1->LastVParameter() - Surf1->FirstVParameter(); | |
1237 | pv1+=pv1; | |
1238 | } | |
1239 | if(pv2==0) { | |
1240 | pv2=Surf2->LastVParameter() - Surf2->FirstVParameter(); | |
1241 | pv2+=pv2; | |
1242 | } | |
1243 | */ | |
1244 | ||
1245 | wlin->SetPeriod(pu1,pv1,pu2,pv2); | |
c2c2f2b6 | 1246 | wlin->ComputeVertexParameters(Tol, hasBeenAdded); |
7fd59977 | 1247 | } |
1248 | else { | |
7fd59977 | 1249 | rlin->ComputeVertexParameters(Tol); |
1250 | } | |
1251 | } |