b311480e |
1 | // Created by: Modelization |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
e2e0498b |
15 | #include <stdio.h> |
4e14c88f |
16 | #include <IntPatch_Intersection.hxx> |
7fd59977 |
17 | |
c22b52d6 |
18 | #include <Adaptor3d_Surface.hxx> |
42cf5bc1 |
19 | #include <Adaptor3d_TopolTool.hxx> |
20 | #include <IntPatch_ALine.hxx> |
7fd59977 |
21 | #include <IntPatch_ALineToWLine.hxx> |
22 | #include <IntPatch_GLine.hxx> |
7fd59977 |
23 | #include <IntPatch_ImpImpIntersection.hxx> |
42cf5bc1 |
24 | #include <IntPatch_ImpPrmIntersection.hxx> |
42cf5bc1 |
25 | #include <IntPatch_PrmPrmIntersection.hxx> |
4e14c88f |
26 | #include <IntPatch_WLineTool.hxx> |
7fd59977 |
27 | |
f48cb55d |
28 | #include <ProjLib_ProjectOnPlane.hxx> |
29 | #include <Geom_Plane.hxx> |
c22b52d6 |
30 | #include <GeomAdaptor_Surface.hxx> |
f48cb55d |
31 | #include <ProjLib_ProjectedCurve.hxx> |
32 | #include <Geom2dInt_GInter.hxx> |
33 | #include <Geom2dAdaptor_Curve.hxx> |
34 | #include <ProjLib.hxx> |
35 | |
9eee5ab7 |
36 | |
7fd59977 |
37 | //====================================================================== |
38 | // function: SequenceOfLine |
39 | //====================================================================== |
40 | const IntPatch_SequenceOfLine& IntPatch_Intersection::SequenceOfLine() const { return(slin); } |
41 | |
42 | //====================================================================== |
43 | // function: IntPatch_Intersection |
44 | //====================================================================== |
45 | IntPatch_Intersection::IntPatch_Intersection () |
46 | : done(Standard_False), |
d533dafb |
47 | empt(Standard_True), |
48 | tgte(Standard_False), |
49 | oppo(Standard_False), |
7fd59977 |
50 | myTolArc(0.0), myTolTang(0.0), |
51 | myUVMaxStep(0.0), myFleche(0.0), |
d533dafb |
52 | myIsStartPnt(Standard_False), |
53 | myU1Start(0.0), |
54 | myV1Start(0.0), |
55 | myU2Start(0.0), |
56 | myV2Start(0.0) |
7fd59977 |
57 | { |
58 | } |
59 | |
60 | //====================================================================== |
61 | // function: IntPatch_Intersection |
62 | //====================================================================== |
c22b52d6 |
63 | IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_Surface)& S1, |
7fd59977 |
64 | const Handle(Adaptor3d_TopolTool)& D1, |
c22b52d6 |
65 | const Handle(Adaptor3d_Surface)& S2, |
7fd59977 |
66 | const Handle(Adaptor3d_TopolTool)& D2, |
67 | const Standard_Real TolArc, |
68 | const Standard_Real TolTang) |
69 | : done(Standard_False), |
d533dafb |
70 | empt(Standard_True), |
71 | tgte(Standard_False), |
72 | oppo(Standard_False), |
7fd59977 |
73 | myTolArc(TolArc), myTolTang(TolTang), |
74 | myUVMaxStep(0.0), myFleche(0.0), |
d533dafb |
75 | myIsStartPnt(Standard_False), |
76 | myU1Start(0.0), |
77 | myV1Start(0.0), |
78 | myU2Start(0.0), |
79 | myV2Start(0.0) |
7fd59977 |
80 | { |
81 | if(myTolArc<1e-8) myTolArc=1e-8; |
82 | if(myTolTang<1e-8) myTolTang=1e-8; |
83 | if(myTolArc>0.5) myTolArc=0.5; |
84 | if(myTolTang>0.5) myTolTang=0.5; |
85 | Perform(S1,D1,S2,D2,TolArc,TolTang); |
86 | } |
87 | |
88 | //====================================================================== |
89 | // function: IntPatch_Intersection |
90 | //====================================================================== |
c22b52d6 |
91 | IntPatch_Intersection::IntPatch_Intersection(const Handle(Adaptor3d_Surface)& S1, |
7fd59977 |
92 | const Handle(Adaptor3d_TopolTool)& D1, |
93 | const Standard_Real TolArc, |
94 | const Standard_Real TolTang) |
95 | : done(Standard_False), |
d533dafb |
96 | empt(Standard_True), |
97 | tgte(Standard_False), |
98 | oppo(Standard_False), |
7fd59977 |
99 | myTolArc(TolArc), myTolTang(TolTang), |
100 | myUVMaxStep(0.0), myFleche(0.0), |
d533dafb |
101 | myIsStartPnt(Standard_False), |
102 | myU1Start(0.0), |
103 | myV1Start(0.0), |
104 | myU2Start(0.0), |
105 | myV2Start(0.0) |
7fd59977 |
106 | { |
107 | Perform(S1,D1,TolArc,TolTang); |
108 | } |
109 | |
110 | //====================================================================== |
111 | // function: SetTolerances |
112 | //====================================================================== |
113 | void IntPatch_Intersection::SetTolerances(const Standard_Real TolArc, |
114 | const Standard_Real TolTang, |
115 | const Standard_Real UVMaxStep, |
116 | const Standard_Real Fleche) |
117 | { |
118 | myTolArc = TolArc; |
119 | myTolTang = TolTang; |
120 | myUVMaxStep = UVMaxStep; |
121 | myFleche = Fleche; |
122 | if(myTolArc<1e-8) myTolArc=1e-8; |
123 | if(myTolTang<1e-8) myTolTang=1e-8; |
124 | if(myTolArc>0.5) myTolArc=0.5; |
125 | if(myTolTang>0.5) myTolTang=0.5; |
126 | if(myFleche<1.0e-3) myFleche=1e-3; |
9eee5ab7 |
127 | //if(myUVMaxStep<1.0e-3) myUVMaxStep=1e-3; |
7fd59977 |
128 | if(myFleche>10) myFleche=10; |
129 | if(myUVMaxStep>0.5) myUVMaxStep=0.5; |
130 | } |
131 | |
132 | //====================================================================== |
133 | // function: Perform |
134 | //====================================================================== |
c22b52d6 |
135 | void IntPatch_Intersection::Perform(const Handle(Adaptor3d_Surface)& S1, |
7fd59977 |
136 | const Handle(Adaptor3d_TopolTool)& D1, |
137 | const Standard_Real TolArc, |
138 | const Standard_Real TolTang) |
139 | { |
140 | myTolArc = TolArc; |
141 | myTolTang = TolTang; |
142 | if(myFleche == 0.0) myFleche = 0.01; |
143 | if(myUVMaxStep==0.0) myUVMaxStep = 0.01; |
144 | |
145 | done = Standard_True; |
146 | spnt.Clear(); |
147 | slin.Clear(); |
148 | |
149 | empt = Standard_True; |
150 | tgte = Standard_False; |
151 | oppo = Standard_False; |
152 | |
153 | switch (S1->GetType()) |
154 | { |
f48cb55d |
155 | case GeomAbs_Plane: |
156 | case GeomAbs_Cylinder: |
157 | case GeomAbs_Sphere: |
158 | case GeomAbs_Cone: |
159 | case GeomAbs_Torus: |
160 | break; |
161 | case GeomAbs_SurfaceOfExtrusion: |
162 | { |
163 | gp_Dir aDirection = S1->Direction(); |
164 | gp_Ax3 anAxis(gp::Origin(), aDirection); |
c22b52d6 |
165 | Handle(Adaptor3d_Curve) aBasisCurve = S1->BasisCurve(); |
f48cb55d |
166 | ProjLib_ProjectOnPlane Projector(anAxis); |
167 | Projector.Load(aBasisCurve, Precision::Confusion()); |
c22b52d6 |
168 | Handle(GeomAdaptor_Curve) aProjCurve = Projector.GetResult(); |
f48cb55d |
169 | Handle(Geom_Plane) aPlane = new Geom_Plane(anAxis); |
c22b52d6 |
170 | Handle(GeomAdaptor_Surface) aGAHsurf = new GeomAdaptor_Surface(aPlane); |
f48cb55d |
171 | ProjLib_ProjectedCurve aProjectedCurve(aGAHsurf, aProjCurve); |
172 | Handle(Geom2d_Curve) aPCurve; |
173 | ProjLib::MakePCurveOfType(aProjectedCurve, aPCurve); |
174 | Geom2dAdaptor_Curve AC(aPCurve, |
175 | aProjectedCurve.FirstParameter(), |
176 | aProjectedCurve.LastParameter()); |
177 | Geom2dInt_GInter Intersector(AC, |
178 | Precision::Confusion(), |
179 | Precision::Confusion()); |
180 | if (Intersector.IsDone() && Intersector.IsEmpty()) |
181 | break; |
182 | } |
b1811c1d |
183 | Standard_FALLTHROUGH |
f48cb55d |
184 | default: |
7fd59977 |
185 | { |
1d18c75e |
186 | IntPatch_PrmPrmIntersection interpp; |
714c3bfc |
187 | interpp.Perform(S1,D1,TolTang,TolArc,myFleche,myUVMaxStep); |
1d18c75e |
188 | if (interpp.IsDone()) |
189 | { |
190 | done = Standard_True; |
191 | tgte = Standard_False; |
192 | empt = interpp.IsEmpty(); |
193 | const Standard_Integer nblm = interpp.NbLines(); |
194 | for (Standard_Integer i=1; i<=nblm; i++) slin.Append(interpp.Line(i)); |
195 | } |
7fd59977 |
196 | } |
197 | break; |
198 | } |
199 | } |
200 | |
201 | ///////////////////////////////////////////////////////////////////////////// |
202 | // These several support functions provide methods which can help basic // |
203 | // algorithm to intersect infinite surfaces of the following types: // |
204 | // // |
205 | // a.) SurfaceOfExtrusion; // |
206 | // b.) SurfaceOfRevolution; // |
207 | // c.) OffsetSurface. // |
208 | // // |
209 | ///////////////////////////////////////////////////////////////////////////// |
210 | #include <TColgp_Array1OfXYZ.hxx> |
7fd59977 |
211 | #include <TColgp_SequenceOfPnt.hxx> |
212 | #include <Extrema_ExtPS.hxx> |
213 | #include <Extrema_POnSurf.hxx> |
214 | #include <Geom2d_Curve.hxx> |
215 | #include <Geom2dAPI_InterCurveCurve.hxx> |
7fd59977 |
216 | #include <Geom_Plane.hxx> |
217 | #include <ProjLib_ProjectOnPlane.hxx> |
218 | #include <GeomProjLib.hxx> |
219 | #include <ElCLib.hxx> |
220 | #include <Geom_TrimmedCurve.hxx> |
221 | #include <Geom_Surface.hxx> |
7fd59977 |
222 | #include <Geom_OffsetSurface.hxx> |
7fd59977 |
223 | #include <Geom_RectangularTrimmedSurface.hxx> |
224 | |
225 | //=============================================================== |
226 | //function: FUN_GetMinMaxXYZPnt |
227 | //=============================================================== |
c22b52d6 |
228 | static void FUN_GetMinMaxXYZPnt( const Handle(Adaptor3d_Surface)& S, |
7fd59977 |
229 | gp_Pnt& pMin, gp_Pnt& pMax ) |
230 | { |
231 | const Standard_Real DU = 0.25 * Abs(S->LastUParameter() - S->FirstUParameter()); |
232 | const Standard_Real DV = 0.25 * Abs(S->LastVParameter() - S->FirstVParameter()); |
233 | Standard_Real tMinXYZ = RealLast(); |
234 | Standard_Real tMaxXYZ = -tMinXYZ; |
235 | gp_Pnt PUV, ptMax, ptMin; |
236 | for(Standard_Real U = S->FirstUParameter(); U <= S->LastUParameter(); U += DU) |
237 | { |
238 | for(Standard_Real V = S->FirstVParameter(); V <= S->LastVParameter(); V += DV) |
1d18c75e |
239 | { |
240 | S->D0(U,V,PUV); |
7fd59977 |
241 | const Standard_Real cXYZ = PUV.XYZ().Modulus(); |
1d18c75e |
242 | if(cXYZ > tMaxXYZ) { tMaxXYZ = cXYZ; ptMax = PUV; } |
243 | if(cXYZ < tMinXYZ) { tMinXYZ = cXYZ; ptMin = PUV; } |
244 | } |
7fd59977 |
245 | } |
246 | pMin = ptMin; |
247 | pMax = ptMax; |
248 | } |
249 | //========================================================================== |
250 | //function: FUN_TrimInfSurf |
251 | //========================================================================== |
252 | static void FUN_TrimInfSurf(const gp_Pnt& Pmin, |
253 | const gp_Pnt& Pmax, |
c22b52d6 |
254 | const Handle(Adaptor3d_Surface)& InfSurf, |
7fd59977 |
255 | const Standard_Real& AlternativeTrimPrm, |
c22b52d6 |
256 | Handle(Adaptor3d_Surface)& TrimS) |
7fd59977 |
257 | { |
258 | Standard_Real TP = AlternativeTrimPrm; |
c22b52d6 |
259 | Extrema_ExtPS ext1(Pmin, *InfSurf, 1.e-7, 1.e-7); |
260 | Extrema_ExtPS ext2(Pmax, *InfSurf, 1.e-7, 1.e-7); |
7fd59977 |
261 | if(ext1.IsDone() || ext2.IsDone()) |
262 | { |
263 | Standard_Real Umax = -1.e+100, Umin = 1.e+100, Vmax = -1.e+100, Vmin = 1.e+100, cU, cV; |
264 | if(ext1.IsDone()) |
1d18c75e |
265 | { |
7fd59977 |
266 | for(Standard_Integer i = 1; i <= ext1.NbExt(); i++) |
267 | { |
1d18c75e |
268 | const Extrema_POnSurf & pons = ext1.Point(i); |
269 | pons.Parameter(cU,cV); |
270 | if(cU > Umax) Umax = cU; |
271 | if(cU < Umin) Umin = cU; |
272 | if(cV > Vmax) Vmax = cV; |
273 | if(cV < Vmin) Vmin = cV; |
7fd59977 |
274 | } |
1d18c75e |
275 | } |
7fd59977 |
276 | if(ext2.IsDone()) |
1d18c75e |
277 | { |
7fd59977 |
278 | for(Standard_Integer i = 1; i <= ext2.NbExt(); i++) |
279 | { |
280 | const Extrema_POnSurf & pons = ext2.Point(i); |
281 | pons.Parameter(cU,cV); |
282 | if(cU > Umax) Umax = cU; |
283 | if(cU < Umin) Umin = cU; |
284 | if(cV > Vmax) Vmax = cV; |
285 | if(cV < Vmin) Vmin = cV; |
286 | } |
1d18c75e |
287 | } |
7fd59977 |
288 | TP = Max(Abs(Umin),Max(Abs(Umax),Max(Abs(Vmin),Abs(Vmax)))); |
289 | } |
290 | if(TP == 0.) { TrimS = InfSurf; return; } |
291 | else |
292 | { |
293 | const Standard_Boolean Uinf = Precision::IsNegativeInfinite(InfSurf->FirstUParameter()); |
294 | const Standard_Boolean Usup = Precision::IsPositiveInfinite(InfSurf->LastUParameter()); |
295 | const Standard_Boolean Vinf = Precision::IsNegativeInfinite(InfSurf->FirstVParameter()); |
296 | const Standard_Boolean Vsup = Precision::IsPositiveInfinite(InfSurf->LastVParameter()); |
c22b52d6 |
297 | Handle(Adaptor3d_Surface) TmpSS; |
7fd59977 |
298 | Standard_Integer IsTrimed = 0; |
299 | const Standard_Real tp = 1000.0 * TP; |
300 | if(Vinf && Vsup) { TrimS = InfSurf->VTrim(-tp, tp, 1.0e-7); IsTrimed = 1; } |
301 | if(Vinf && !Vsup){ TrimS = InfSurf->VTrim(-tp, InfSurf->LastVParameter(), 1.0e-7); IsTrimed = 1; } |
302 | if(!Vinf && Vsup){ TrimS = InfSurf->VTrim(InfSurf->FirstVParameter(), tp, 1.0e-7); IsTrimed = 1; } |
303 | if(IsTrimed) |
1d18c75e |
304 | { |
305 | TmpSS = TrimS; |
306 | if(Uinf && Usup) TrimS = TmpSS->UTrim(-tp, tp, 1.0e-7); |
307 | if(Uinf && !Usup) TrimS = TmpSS->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7); |
308 | if(!Uinf && Usup) TrimS = TmpSS->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7); |
309 | } |
7fd59977 |
310 | else |
1d18c75e |
311 | { |
312 | if(Uinf && Usup) TrimS = InfSurf->UTrim(-tp, tp, 1.0e-7); |
313 | if(Uinf && !Usup) TrimS = InfSurf->UTrim(-tp, InfSurf->LastUParameter(), 1.0e-7); |
314 | if(!Uinf && Usup) TrimS = InfSurf->UTrim(InfSurf->FirstUParameter(), tp, 1.0e-7); |
315 | } |
7fd59977 |
316 | } |
317 | } |
318 | //================================================================================ |
319 | //function: FUN_GetUiso |
320 | //================================================================================ |
321 | static void FUN_GetUiso(const Handle(Geom_Surface)& GS, |
322 | const GeomAbs_SurfaceType& T, |
323 | const Standard_Real& FirstV, |
324 | const Standard_Real& LastV, |
325 | const Standard_Boolean& IsVC, |
326 | const Standard_Boolean& IsVP, |
327 | const Standard_Real& U, |
328 | Handle(Geom_Curve)& I) |
329 | { |
330 | if(T != GeomAbs_OffsetSurface) |
331 | { |
332 | Handle(Geom_Curve) gc = GS->UIso(U); |
c6541a0c |
333 | if(IsVP && (FirstV == 0.0 && LastV == (2.*M_PI))) I = gc; |
7fd59977 |
334 | else |
1d18c75e |
335 | { |
336 | Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV); |
337 | //szv:I = Handle(Geom_Curve)::DownCast(gtc); |
338 | I = gtc; |
339 | } |
7fd59977 |
340 | } |
341 | else//OffsetSurface |
342 | { |
c5f3a425 |
343 | const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (GS); |
7fd59977 |
344 | const Handle(Geom_Surface) bs = gos->BasisSurface(); |
345 | Handle(Geom_Curve) gcbs = bs->UIso(U); |
346 | GeomAdaptor_Curve gac(gcbs); |
347 | const GeomAbs_CurveType GACT = gac.GetType(); |
348 | if(IsVP || IsVC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastV - FirstV) < 1.e+5) |
1d18c75e |
349 | { |
350 | Handle(Geom_Curve) gc = gos->UIso(U); |
351 | if(IsVP && (FirstV == 0.0 && LastV == (2*M_PI))) I = gc; |
352 | else |
7fd59977 |
353 | { |
1d18c75e |
354 | Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstV,LastV); |
355 | //szv:I = Handle(Geom_Curve)::DownCast(gtc); |
356 | I = gtc; |
357 | } |
358 | } |
7fd59977 |
359 | else//Offset Line, Parab, Hyperb |
1d18c75e |
360 | { |
361 | Standard_Real VmTr, VMTr; |
362 | if(GACT != GeomAbs_Hyperbola) |
7fd59977 |
363 | { |
1d18c75e |
364 | if(FirstV >= 0. && LastV >= 0.){ VmTr = FirstV; VMTr = ((LastV - FirstV) > 1.e+4) ? (FirstV + 1.e+4) : LastV; } |
365 | else if(FirstV < 0. && LastV < 0.){ VMTr = LastV; VmTr = ((FirstV - LastV) < -1.e+4) ? (LastV - 1.e+4) : FirstV; } |
366 | else { VmTr = (FirstV < -1.e+4) ? -1.e+4 : FirstV; VMTr = (LastV > 1.e+4) ? 1.e+4 : LastV; } |
367 | } |
368 | else//Hyperbola |
369 | { |
370 | if(FirstV >= 0. && LastV >= 0.) |
371 | { |
372 | if(FirstV > 4.) return; |
373 | VmTr = FirstV; VMTr = (LastV > 4.) ? 4. : LastV; |
374 | } |
375 | else if(FirstV < 0. && LastV < 0.) |
376 | { |
377 | if(LastV < -4.) return; |
378 | VMTr = LastV; VmTr = (FirstV < -4.) ? -4. : FirstV; |
379 | } |
380 | else { VmTr = (FirstV < -4.) ? -4. : FirstV; VMTr = (LastV > 4.) ? 4. : LastV; } |
381 | } |
382 | //Make trimmed surface |
383 | Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,VmTr,VMTr,Standard_True); |
384 | I = rts->UIso(U); |
385 | } |
7fd59977 |
386 | } |
387 | } |
388 | //================================================================================ |
389 | //function: FUN_GetViso |
390 | //================================================================================ |
391 | static void FUN_GetViso(const Handle(Geom_Surface)& GS, |
392 | const GeomAbs_SurfaceType& T, |
393 | const Standard_Real& FirstU, |
394 | const Standard_Real& LastU, |
395 | const Standard_Boolean& IsUC, |
396 | const Standard_Boolean& IsUP, |
397 | const Standard_Real& V, |
398 | Handle(Geom_Curve)& I) |
399 | { |
400 | if(T != GeomAbs_OffsetSurface) |
401 | { |
402 | Handle(Geom_Curve) gc = GS->VIso(V); |
c6541a0c |
403 | if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc; |
7fd59977 |
404 | else |
1d18c75e |
405 | { |
406 | Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU); |
407 | //szv:I = Handle(Geom_Curve)::DownCast(gtc); |
408 | I = gtc; |
409 | } |
7fd59977 |
410 | } |
411 | else//OffsetSurface |
412 | { |
c5f3a425 |
413 | const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (GS); |
7fd59977 |
414 | const Handle(Geom_Surface) bs = gos->BasisSurface(); |
415 | Handle(Geom_Curve) gcbs = bs->VIso(V); |
416 | GeomAdaptor_Curve gac(gcbs); |
417 | const GeomAbs_CurveType GACT = gac.GetType(); |
418 | if(IsUP || IsUC || GACT == GeomAbs_BSplineCurve || GACT == GeomAbs_BezierCurve || Abs(LastU - FirstU) < 1.e+5) |
1d18c75e |
419 | { |
420 | Handle(Geom_Curve) gc = gos->VIso(V); |
421 | if(IsUP && (FirstU == 0.0 && LastU == (2*M_PI))) I = gc; |
422 | else |
423 | { |
424 | Handle(Geom_TrimmedCurve) gtc = new Geom_TrimmedCurve(gc,FirstU,LastU); |
425 | //szv:I = Handle(Geom_Curve)::DownCast(gtc); |
426 | I = gtc; |
427 | } |
428 | } |
7fd59977 |
429 | else//Offset Line, Parab, Hyperb |
1d18c75e |
430 | { |
431 | Standard_Real UmTr, UMTr; |
432 | if(GACT != GeomAbs_Hyperbola) |
433 | { |
434 | if(FirstU >= 0. && LastU >= 0.){ UmTr = FirstU; UMTr = ((LastU - FirstU) > 1.e+4) ? (FirstU + 1.e+4) : LastU; } |
435 | else if(FirstU < 0. && LastU < 0.){ UMTr = LastU; UmTr = ((FirstU - LastU) < -1.e+4) ? (LastU - 1.e+4) : FirstU; } |
436 | else { UmTr = (FirstU < -1.e+4) ? -1.e+4 : FirstU; UMTr = (LastU > 1.e+4) ? 1.e+4 : LastU; } |
437 | } |
438 | else//Hyperbola |
439 | { |
440 | if(FirstU >= 0. && LastU >= 0.) |
441 | { |
442 | if(FirstU > 4.) return; |
443 | UmTr = FirstU; UMTr = (LastU > 4.) ? 4. : LastU; |
444 | } |
445 | else if(FirstU < 0. && LastU < 0.) |
446 | { |
447 | if(LastU < -4.) return; |
448 | UMTr = LastU; UmTr = (FirstU < -4.) ? -4. : FirstU; |
449 | } |
450 | else { UmTr = (FirstU < -4.) ? -4. : FirstU; UMTr = (LastU > 4.) ? 4. : LastU; } |
451 | } |
452 | //Make trimmed surface |
453 | Handle(Geom_RectangularTrimmedSurface) rts = new Geom_RectangularTrimmedSurface(gos,UmTr,UMTr,Standard_True); |
454 | I = rts->VIso(V); |
455 | } |
7fd59977 |
456 | } |
457 | } |
458 | //================================================================================ |
459 | //function: FUN_PL_Intersection |
460 | //================================================================================ |
c22b52d6 |
461 | static void FUN_PL_Intersection(const Handle(Adaptor3d_Surface)& S1, |
7fd59977 |
462 | const GeomAbs_SurfaceType& T1, |
c22b52d6 |
463 | const Handle(Adaptor3d_Surface)& S2, |
7fd59977 |
464 | const GeomAbs_SurfaceType& T2, |
465 | Standard_Boolean& IsOk, |
466 | TColgp_SequenceOfPnt& SP, |
467 | gp_Vec& DV) |
468 | { |
469 | IsOk = Standard_False; |
470 | // 1. Check: both surfaces have U(V)isos - lines. |
471 | DV = gp_Vec(0.,0.,1.); |
472 | Standard_Boolean isoS1isLine[2] = {0, 0}; |
473 | Standard_Boolean isoS2isLine[2] = {0, 0}; |
474 | Handle(Geom_Curve) C1, C2; |
c22b52d6 |
475 | const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(S1.get()); |
476 | const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(S2.get()); |
7fd59977 |
477 | const Handle(Geom_Surface) gs1 = gas1.Surface(); |
478 | const Handle(Geom_Surface) gs2 = gas2.Surface(); |
479 | Standard_Real MS1[2], MS2[2]; |
480 | MS1[0] = 0.5 * (S1->LastUParameter() + S1->FirstUParameter()); |
481 | MS1[1] = 0.5 * (S1->LastVParameter() + S1->FirstVParameter()); |
482 | MS2[0] = 0.5 * (S2->LastUParameter() + S2->FirstUParameter()); |
483 | MS2[1] = 0.5 * (S2->LastVParameter() + S2->FirstVParameter()); |
484 | if(T1 == GeomAbs_SurfaceOfExtrusion) isoS1isLine[0] = Standard_True; |
485 | else if(!S1->IsVPeriodic() && !S1->IsVClosed()) { |
486 | if(T1 != GeomAbs_OffsetSurface) C1 = gs1->UIso(MS1[0]); |
487 | else { |
c5f3a425 |
488 | const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1); |
7fd59977 |
489 | const Handle(Geom_Surface) bs = gos->BasisSurface(); |
490 | C1 = bs->UIso(MS1[0]); |
491 | } |
492 | GeomAdaptor_Curve gac(C1); |
493 | if(gac.GetType() == GeomAbs_Line) isoS1isLine[0] = Standard_True; |
494 | } |
495 | if(!S1->IsUPeriodic() && !S1->IsUClosed()) { |
496 | if(T1 != GeomAbs_OffsetSurface) C1 = gs1->VIso(MS1[1]); |
497 | else { |
c5f3a425 |
498 | const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1); |
7fd59977 |
499 | const Handle(Geom_Surface) bs = gos->BasisSurface(); |
500 | C1 = bs->VIso(MS1[1]); |
501 | } |
502 | GeomAdaptor_Curve gac(C1); |
503 | if(gac.GetType() == GeomAbs_Line) isoS1isLine[1] = Standard_True; |
504 | } |
505 | if(T2 == GeomAbs_SurfaceOfExtrusion) isoS2isLine[0] = Standard_True; |
506 | else if(!S2->IsVPeriodic() && !S2->IsVClosed()) { |
507 | if(T2 != GeomAbs_OffsetSurface) C2 = gs2->UIso(MS2[0]); |
508 | else { |
c5f3a425 |
509 | const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2); |
7fd59977 |
510 | const Handle(Geom_Surface) bs = gos->BasisSurface(); |
511 | C2 = bs->UIso(MS2[0]); |
512 | } |
513 | GeomAdaptor_Curve gac(C2); |
514 | if(gac.GetType() == GeomAbs_Line) isoS2isLine[0] = Standard_True; |
515 | } |
516 | if(!S2->IsUPeriodic() && !S2->IsUClosed()) { |
517 | if(T2 != GeomAbs_OffsetSurface) C2 = gs2->VIso(MS2[1]); |
518 | else { |
c5f3a425 |
519 | const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2); |
7fd59977 |
520 | const Handle(Geom_Surface) bs = gos->BasisSurface(); |
521 | C2 = bs->VIso(MS2[1]); |
522 | } |
523 | GeomAdaptor_Curve gac(C2); |
524 | if(gac.GetType() == GeomAbs_Line) isoS2isLine[1] = Standard_True; |
525 | } |
526 | Standard_Boolean IsBothLines = ((isoS1isLine[0] || isoS1isLine[1]) && |
527 | (isoS2isLine[0] || isoS2isLine[1])); |
528 | if(!IsBothLines){ |
529 | return; |
530 | } |
531 | // 2. Check: Uiso lines of both surfaces are collinear. |
532 | gp_Pnt puvS1, puvS2; |
533 | gp_Vec derS1[2], derS2[2]; |
534 | S1->D1(MS1[0], MS1[1], puvS1, derS1[0], derS1[1]); |
535 | S2->D1(MS2[0], MS2[1], puvS2, derS2[0], derS2[1]); |
536 | C1.Nullify(); C2.Nullify(); |
537 | Standard_Integer iso = 0; |
538 | if(isoS1isLine[0] && isoS2isLine[0] && |
539 | derS1[1].IsParallel(derS2[1],Precision::Angular())) { |
540 | iso = 1; |
541 | FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(), |
542 | S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1); |
543 | FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(), |
544 | S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2); |
545 | } |
546 | else if(isoS1isLine[0] && isoS2isLine[1] && |
547 | derS1[1].IsParallel(derS2[0],Precision::Angular())) { |
548 | iso = 1; |
549 | FUN_GetViso(gs1,T1,S1->FirstUParameter(),S1->LastUParameter(), |
550 | S1->IsUClosed(),S1->IsUPeriodic(),MS1[1],C1); |
551 | FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(), |
552 | S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2); |
553 | } |
554 | else if(isoS1isLine[1] && isoS2isLine[0] && |
555 | derS1[0].IsParallel(derS2[1],Precision::Angular())) { |
556 | iso = 0; |
557 | FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(), |
558 | S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1); |
559 | FUN_GetViso(gs2,T2,S2->FirstUParameter(),S2->LastUParameter(), |
560 | S2->IsUClosed(),S2->IsUPeriodic(),MS2[1],C2); |
561 | } |
562 | else if(isoS1isLine[1] && isoS2isLine[1] && |
563 | derS1[0].IsParallel(derS2[0],Precision::Angular())) { |
564 | iso = 0; |
565 | FUN_GetUiso(gs1,T1,S1->FirstVParameter(),S1->LastVParameter(), |
566 | S1->IsVClosed(),S1->IsVPeriodic(),MS1[0],C1); |
567 | FUN_GetUiso(gs2,T2,S2->FirstVParameter(),S2->LastVParameter(), |
568 | S2->IsVClosed(),S2->IsVPeriodic(),MS2[0],C2); |
569 | } |
570 | else { |
571 | IsOk = Standard_False; |
572 | return; |
573 | } |
574 | IsOk = Standard_True; |
575 | // 3. Make intersections of V(U)isos |
576 | if(C1.IsNull() || C2.IsNull()) return; |
577 | DV = derS1[iso]; |
578 | Handle(Geom_Plane) GPln = new Geom_Plane(gp_Pln(puvS1,gp_Dir(DV))); |
579 | Handle(Geom_Curve) C1Prj = |
580 | GeomProjLib::ProjectOnPlane(C1,GPln,gp_Dir(DV),Standard_True); |
581 | Handle(Geom_Curve) C2Prj = |
582 | GeomProjLib::ProjectOnPlane(C2,GPln,gp_Dir(DV),Standard_True); |
583 | if(C1Prj.IsNull() || C2Prj.IsNull()) return; |
a9dde4a3 |
584 | Handle(Geom2d_Curve) C1Prj2d = GeomProjLib::Curve2d (C1Prj,GPln); |
585 | Handle(Geom2d_Curve) C2Prj2d = GeomProjLib::Curve2d (C2Prj,GPln); |
7fd59977 |
586 | Geom2dAPI_InterCurveCurve ICC(C1Prj2d,C2Prj2d,1.0e-7); |
587 | if(ICC.NbPoints() > 0 ) |
588 | { |
589 | for(Standard_Integer ip = 1; ip <= ICC.NbPoints(); ip++) |
1d18c75e |
590 | { |
591 | gp_Pnt2d P = ICC.Point(ip); |
592 | gp_Pnt P3d = ElCLib::To3d(gp_Ax2(puvS1,gp_Dir(DV)),P); |
593 | SP.Append(P3d); |
594 | } |
7fd59977 |
595 | } |
596 | } |
597 | //================================================================================ |
598 | //function: FUN_NewFirstLast |
599 | //================================================================================ |
600 | static void FUN_NewFirstLast(const GeomAbs_CurveType& ga_ct, |
601 | const Standard_Real& Fst, |
602 | const Standard_Real& Lst, |
603 | const Standard_Real& TrVal, |
604 | Standard_Real& NewFst, |
605 | Standard_Real& NewLst, |
606 | Standard_Boolean& NeedTr) |
607 | { |
608 | NewFst = Fst; NewLst = Lst; NeedTr = Standard_False; |
609 | switch (ga_ct) |
610 | { |
611 | case GeomAbs_Line: |
612 | case GeomAbs_Parabola: |
613 | { |
614 | if(Abs(Lst - Fst) > TrVal) |
1d18c75e |
615 | { |
616 | if(Fst >= 0. && Lst >= 0.) |
7fd59977 |
617 | { |
1d18c75e |
618 | NewFst = Fst; |
619 | NewLst = ((Fst + TrVal) < Lst) ? (Fst + TrVal) : Lst; |
620 | } |
621 | if(Fst < 0. && Lst < 0.) |
622 | { |
623 | NewLst = Lst; |
624 | NewFst = ((Lst - TrVal) > Fst) ? (Lst - TrVal) : Fst; |
625 | } |
626 | else |
627 | { |
628 | NewFst = (Fst < -TrVal) ? -TrVal : Fst; |
629 | NewLst = (Lst > TrVal) ? TrVal : Lst; |
630 | } |
631 | NeedTr = Standard_True; |
632 | } |
633 | break; |
7fd59977 |
634 | } |
1d18c75e |
635 | case GeomAbs_Hyperbola: |
7fd59977 |
636 | { |
637 | if(Abs(Lst - Fst) > 10.) |
1d18c75e |
638 | { |
639 | if(Fst >= 0. && Lst >= 0.) |
640 | { |
641 | if(Fst > 4.) return; |
642 | NewFst = Fst; |
643 | NewLst = (Lst > 4.) ? 4. : Lst; |
644 | } |
645 | if(Fst < 0. && Lst < 0.) |
646 | { |
647 | if(Lst < -4.) return; |
648 | NewLst = Lst; |
649 | NewFst = (Fst < -4.) ? -4. : Fst; |
650 | } |
651 | else |
652 | { |
653 | NewFst = (Fst < -4.) ? -4. : Fst; |
654 | NewLst = (Lst > 4.) ? 4. : Lst; |
655 | } |
656 | NeedTr = Standard_True; |
657 | } |
7fd59977 |
658 | break; |
659 | } |
1d18c75e |
660 | default: |
566f8441 |
661 | break; |
7fd59977 |
662 | } |
663 | } |
664 | //================================================================================ |
665 | //function: FUN_TrimBothSurf |
1d18c75e |
666 | //================================================================================ |
c22b52d6 |
667 | static void FUN_TrimBothSurf(const Handle(Adaptor3d_Surface)& S1, |
7fd59977 |
668 | const GeomAbs_SurfaceType& T1, |
c22b52d6 |
669 | const Handle(Adaptor3d_Surface)& S2, |
7fd59977 |
670 | const GeomAbs_SurfaceType& T2, |
671 | const Standard_Real& TV, |
c22b52d6 |
672 | Handle(Adaptor3d_Surface)& NS1, |
673 | Handle(Adaptor3d_Surface)& NS2) |
7fd59977 |
674 | { |
c22b52d6 |
675 | const GeomAdaptor_Surface & gas1 = *(GeomAdaptor_Surface*)(S1.get()); |
676 | const GeomAdaptor_Surface & gas2 = *(GeomAdaptor_Surface*)(S2.get()); |
7fd59977 |
677 | const Handle(Geom_Surface) gs1 = gas1.Surface(); |
678 | const Handle(Geom_Surface) gs2 = gas2.Surface(); |
679 | const Standard_Real UM1 = 0.5 * (S1->LastUParameter() + S1->FirstUParameter()); |
680 | const Standard_Real UM2 = 0.5 * (S2->LastUParameter() + S2->FirstUParameter()); |
681 | const Standard_Real VM1 = 0.5 * (S1->LastVParameter() + S1->FirstVParameter()); |
682 | const Standard_Real VM2 = 0.5 * (S2->LastVParameter() + S2->FirstVParameter()); |
683 | Handle(Geom_Curve) visoS1, visoS2, uisoS1, uisoS2; |
684 | if(T1 != GeomAbs_OffsetSurface){ visoS1 = gs1->VIso(VM1); uisoS1 = gs1->UIso(UM1); } |
685 | else |
686 | { |
c5f3a425 |
687 | const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs1); |
7fd59977 |
688 | const Handle(Geom_Surface) bs = gos->BasisSurface(); |
689 | visoS1 = bs->VIso(VM1); uisoS1 = bs->UIso(UM1); |
690 | } |
691 | if(T2 != GeomAbs_OffsetSurface){ visoS2 = gs2->VIso(VM2); uisoS2 = gs2->UIso(UM2); } |
692 | else |
693 | { |
c5f3a425 |
694 | const Handle(Geom_OffsetSurface) gos = Handle(Geom_OffsetSurface)::DownCast (gs2); |
7fd59977 |
695 | const Handle(Geom_Surface) bs = gos->BasisSurface(); |
696 | visoS2 = bs->VIso(VM2); uisoS2 = bs->UIso(UM2); |
697 | } |
698 | if(uisoS1.IsNull() || uisoS2.IsNull() || visoS1.IsNull() || visoS2.IsNull()){ NS1 = S1; NS2 = S2; return; } |
699 | GeomAdaptor_Curve gau1(uisoS1); |
700 | GeomAdaptor_Curve gav1(visoS1); |
701 | GeomAdaptor_Curve gau2(uisoS2); |
702 | GeomAdaptor_Curve gav2(visoS2); |
703 | GeomAbs_CurveType GA_U1 = gau1.GetType(); |
704 | GeomAbs_CurveType GA_V1 = gav1.GetType(); |
705 | GeomAbs_CurveType GA_U2 = gau2.GetType(); |
706 | GeomAbs_CurveType GA_V2 = gav2.GetType(); |
707 | Standard_Boolean TrmU1 = Standard_False; |
708 | Standard_Boolean TrmV1 = Standard_False; |
709 | Standard_Boolean TrmU2 = Standard_False; |
710 | Standard_Boolean TrmV2 = Standard_False; |
711 | Standard_Real V1S1,V2S1,U1S1,U2S1, V1S2,V2S2,U1S2,U2S2; |
712 | FUN_NewFirstLast(GA_U1,S1->FirstVParameter(),S1->LastVParameter(),TV,V1S1,V2S1,TrmV1); |
713 | FUN_NewFirstLast(GA_V1,S1->FirstUParameter(),S1->LastUParameter(),TV,U1S1,U2S1,TrmU1); |
714 | FUN_NewFirstLast(GA_U2,S2->FirstVParameter(),S2->LastVParameter(),TV,V1S2,V2S2,TrmV2); |
715 | FUN_NewFirstLast(GA_V2,S2->FirstUParameter(),S2->LastUParameter(),TV,U1S2,U2S2,TrmU2); |
716 | if(TrmV1) NS1 = S1->VTrim(V1S1, V2S1, 1.0e-7); |
717 | if(TrmV2) NS2 = S2->VTrim(V1S2, V2S2, 1.0e-7); |
718 | if(TrmU1) |
719 | { |
720 | if(TrmV1) |
1d18c75e |
721 | { |
c22b52d6 |
722 | Handle(Adaptor3d_Surface) TS = NS1; |
1d18c75e |
723 | NS1 = TS->UTrim(U1S1, U2S1, 1.0e-7); |
724 | } |
7fd59977 |
725 | else NS1 = S1->UTrim(U1S1, U2S1, 1.0e-7); |
726 | } |
727 | if(TrmU2) |
728 | { |
729 | if(TrmV2) |
1d18c75e |
730 | { |
c22b52d6 |
731 | Handle(Adaptor3d_Surface) TS = NS2; |
1d18c75e |
732 | NS2 = TS->UTrim(U1S2, U2S2, 1.0e-7); |
733 | } |
7fd59977 |
734 | else NS2 = S2->UTrim(U1S2, U2S2, 1.0e-7); |
735 | } |
736 | } |
737 | |
738 | //======================================================================= |
739 | //function : Perform |
740 | //purpose : |
741 | //======================================================================= |
c22b52d6 |
742 | void IntPatch_Intersection::Perform(const Handle(Adaptor3d_Surface)& theS1, |
788cbaf4 |
743 | const Handle(Adaptor3d_TopolTool)& theD1, |
c22b52d6 |
744 | const Handle(Adaptor3d_Surface)& theS2, |
788cbaf4 |
745 | const Handle(Adaptor3d_TopolTool)& theD2, |
7fd59977 |
746 | const Standard_Real TolArc, |
788cbaf4 |
747 | const Standard_Real TolTang, |
d4b867e6 |
748 | const Standard_Boolean isGeomInt, |
4e14c88f |
749 | const Standard_Boolean theIsReqToKeepRLine, |
750 | const Standard_Boolean theIsReqToPostWLProc) |
788cbaf4 |
751 | { |
7fd59977 |
752 | myTolArc = TolArc; |
753 | myTolTang = TolTang; |
788cbaf4 |
754 | if(myFleche <= Precision::PConfusion()) |
755 | myFleche = 0.01; |
756 | if(myUVMaxStep <= Precision::PConfusion()) |
757 | myUVMaxStep = 0.01; |
758 | |
7fd59977 |
759 | done = Standard_False; |
760 | spnt.Clear(); |
761 | slin.Clear(); |
762 | empt = Standard_True; |
763 | tgte = Standard_False; |
764 | oppo = Standard_False; |
765 | |
788cbaf4 |
766 | GeomAbs_SurfaceType typs1 = theS1->GetType(); |
767 | GeomAbs_SurfaceType typs2 = theS2->GetType(); |
7fd59977 |
768 | |
18d25b93 |
769 | //treatment of the cases with cone or torus |
7fd59977 |
770 | Standard_Boolean TreatAsBiParametric = Standard_False; |
1d18c75e |
771 | Standard_Integer bGeomGeom = 0; |
18d25b93 |
772 | // |
773 | if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone || |
774 | typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) { |
775 | gp_Ax1 aCTAx, aGeomAx; |
776 | GeomAbs_SurfaceType aCTType; |
777 | Standard_Boolean bToCheck; |
778 | // |
c22b52d6 |
779 | const Handle(Adaptor3d_Surface)& aCTSurf = |
18d25b93 |
780 | (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2; |
c22b52d6 |
781 | const Handle(Adaptor3d_Surface)& aGeomSurf = |
18d25b93 |
782 | (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1; |
783 | // |
784 | aCTType = aCTSurf->GetType(); |
785 | bToCheck = Standard_False; |
786 | // |
1d18c75e |
787 | if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) { |
788 | const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ? |
789 | aCTSurf->Cone() : aGeomSurf->Cone(); |
790 | Standard_Real a1 = Abs(aCon1.SemiAngle()); |
18d25b93 |
791 | bToCheck = (a1 < 0.02) || (a1 > 1.55); |
1d18c75e |
792 | // |
18d25b93 |
793 | if (typs1 == typs2) { |
1d18c75e |
794 | const gp_Cone aCon2 = aGeomSurf->Cone(); |
795 | Standard_Real a2 = Abs(aCon2.SemiAngle()); |
18d25b93 |
796 | bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55); |
797 | // |
798 | if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic |
18d25b93 |
799 | const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis(); |
800 | if (A1.IsParallel(A2,Precision::Angular())) { |
801 | const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex(); |
802 | const gp_Pln Plan1( Apex1, A1.Direction() ); |
803 | if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) { |
804 | bToCheck = Standard_False; |
18d25b93 |
805 | } |
788cbaf4 |
806 | } |
807 | } |
7fd59977 |
808 | } |
18d25b93 |
809 | // |
1d18c75e |
810 | TreatAsBiParametric = bToCheck; |
811 | if (aCTType == GeomAbs_Cone) { |
812 | aCTAx = aCon1.Axis(); |
813 | } |
7fd59977 |
814 | } |
1d18c75e |
815 | // |
816 | if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) { |
817 | const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ? |
818 | aCTSurf->Torus() : aGeomSurf->Torus(); |
819 | bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius(); |
820 | if (typs1 == typs2) { |
821 | const gp_Torus aTor2 = aGeomSurf->Torus(); |
822 | bToCheck = aTor2.MajorRadius() > aTor2.MinorRadius(); |
823 | } |
824 | // |
825 | if (aCTType == GeomAbs_Torus) { |
826 | aCTAx = aTor1.Axis(); |
18d25b93 |
827 | } |
18d25b93 |
828 | } |
829 | // |
830 | if (bToCheck) { |
831 | const gp_Lin aL1(aCTAx); |
832 | // |
833 | switch (aGeomSurf->GetType()) { |
834 | case GeomAbs_Plane: { |
835 | aGeomAx = aGeomSurf->Plane().Axis(); |
836 | if (aCTType == GeomAbs_Cone) { |
1d18c75e |
837 | bGeomGeom = 1; |
18d25b93 |
838 | if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) { |
839 | Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction())); |
840 | if(ps < 0.015) { |
1d18c75e |
841 | bGeomGeom = 0; |
18d25b93 |
842 | } |
788cbaf4 |
843 | } |
844 | } |
18d25b93 |
845 | else { |
846 | if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) || |
847 | (aCTAx.IsNormal(aGeomAx, Precision::Angular()) && |
848 | (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) { |
1d18c75e |
849 | bGeomGeom = 1; |
18d25b93 |
850 | } |
851 | } |
852 | bToCheck = Standard_False; |
853 | break; |
7fd59977 |
854 | } |
18d25b93 |
855 | case GeomAbs_Sphere: { |
856 | if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) { |
1d18c75e |
857 | bGeomGeom = 1; |
18d25b93 |
858 | } |
859 | bToCheck = Standard_False; |
860 | break; |
7fd59977 |
861 | } |
18d25b93 |
862 | case GeomAbs_Cylinder: |
863 | aGeomAx = aGeomSurf->Cylinder().Axis(); |
864 | break; |
865 | case GeomAbs_Cone: |
866 | aGeomAx = aGeomSurf->Cone().Axis(); |
867 | break; |
868 | case GeomAbs_Torus: |
869 | aGeomAx = aGeomSurf->Torus().Axis(); |
870 | break; |
871 | default: |
872 | bToCheck = Standard_False; |
873 | break; |
874 | } |
875 | // |
876 | if (bToCheck) { |
877 | if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) && |
878 | (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) { |
1d18c75e |
879 | bGeomGeom = 1; |
788cbaf4 |
880 | } |
7fd59977 |
881 | } |
18d25b93 |
882 | // |
1d18c75e |
883 | if (bGeomGeom == 1) { |
884 | TreatAsBiParametric = Standard_False; |
18d25b93 |
885 | } |
886 | } |
887 | } |
888 | // |
788cbaf4 |
889 | |
890 | if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) { |
bf0ba813 |
891 | TreatAsBiParametric= Standard_False; |
892 | } |
7fd59977 |
893 | |
894 | // Modified by skv - Mon Sep 26 14:58:30 2005 Begin |
895 | // if(TreatAsBiParametric) { typs1 = typs2 = GeomAbs_BezierSurface; } |
788cbaf4 |
896 | if(TreatAsBiParametric) |
897 | { |
7fd59977 |
898 | if (typs1 == GeomAbs_Cone && typs2 == GeomAbs_Plane) |
899 | typs1 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector |
900 | else if (typs1 == GeomAbs_Plane && typs2 == GeomAbs_Cone) |
901 | typs2 = GeomAbs_BezierSurface; // Using Imp-Prm Intersector |
902 | else { |
903 | // Using Prm-Prm Intersector |
904 | typs1 = GeomAbs_BezierSurface; |
905 | typs2 = GeomAbs_BezierSurface; |
906 | } |
907 | } |
908 | // Modified by skv - Mon Sep 26 14:58:30 2005 End |
909 | |
910 | // Surface type definition |
911 | Standard_Integer ts1 = 0; |
912 | switch (typs1) |
913 | { |
914 | case GeomAbs_Plane: |
915 | case GeomAbs_Cylinder: |
916 | case GeomAbs_Sphere: |
917 | case GeomAbs_Cone: ts1 = 1; break; |
1d18c75e |
918 | case GeomAbs_Torus: ts1 = bGeomGeom; break; |
7fd59977 |
919 | default: break; |
920 | } |
788cbaf4 |
921 | |
7fd59977 |
922 | Standard_Integer ts2 = 0; |
923 | switch (typs2) |
924 | { |
925 | case GeomAbs_Plane: |
926 | case GeomAbs_Cylinder: |
927 | case GeomAbs_Sphere: |
928 | case GeomAbs_Cone: ts2 = 1; break; |
1d18c75e |
929 | case GeomAbs_Torus: ts2 = bGeomGeom; break; |
7fd59977 |
930 | default: break; |
931 | } |
7eed5d29 |
932 | // |
933 | // treatment of the cases with torus and any other geom surface |
7eed5d29 |
934 | // |
7fd59977 |
935 | // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom> |
936 | // 2. ts1 != ts2 <Geom-Param> |
937 | // 3. ts1 == ts2 == 0 <Param-Param> |
938 | |
939 | // Geom - Geom |
940 | if(ts1 == ts2 && ts1 == 1) |
941 | { |
788cbaf4 |
942 | IntSurf_ListOfPntOn2S ListOfPnts; |
943 | ListOfPnts.Clear(); |
944 | if(isGeomInt) |
945 | { |
7797eb38 |
946 | GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, |
947 | ListOfPnts, typs1, typs2, theIsReqToKeepRLine); |
788cbaf4 |
948 | } |
949 | else |
950 | { |
02effd35 |
951 | ParamParamPerfom(theS1, theD1, theS2, theD2, |
7797eb38 |
952 | TolArc, TolTang, ListOfPnts, typs1, typs2); |
788cbaf4 |
953 | } |
7fd59977 |
954 | } |
788cbaf4 |
955 | |
7fd59977 |
956 | // Geom - Param |
957 | if(ts1 != ts2) |
958 | { |
788cbaf4 |
959 | GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2); |
7fd59977 |
960 | } |
788cbaf4 |
961 | |
7fd59977 |
962 | // Param - Param |
963 | if(ts1 == ts2 && ts1 == 0) |
964 | { |
788cbaf4 |
965 | IntSurf_ListOfPntOn2S ListOfPnts; |
966 | ListOfPnts.Clear(); |
967 | |
02effd35 |
968 | ParamParamPerfom(theS1, theD1, theS2, theD2, TolArc, |
7797eb38 |
969 | TolTang, ListOfPnts, typs1, typs2); |
7fd59977 |
970 | } |
4e14c88f |
971 | |
972 | if(!theIsReqToPostWLProc) |
973 | return; |
974 | |
975 | for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++) |
976 | { |
977 | Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i)); |
978 | |
979 | if(aWL.IsNull()) |
980 | continue; |
981 | |
e146ef9a |
982 | if (!aWL->IsPurgingAllowed()) |
983 | continue; |
984 | |
5185b161 |
985 | Handle(IntPatch_WLine) aRW = |
7797eb38 |
986 | IntPatch_WLineTool::ComputePurgedWLine(aWL, theS1, theS2, theD1, theD2); |
4e14c88f |
987 | |
988 | if(aRW.IsNull()) |
989 | continue; |
990 | |
991 | slin.InsertAfter(i, aRW); |
992 | slin.Remove(i); |
993 | } |
7fd59977 |
994 | } |
18d25b93 |
995 | |
7fd59977 |
996 | //======================================================================= |
997 | //function : Perform |
998 | //purpose : |
999 | //======================================================================= |
c22b52d6 |
1000 | void IntPatch_Intersection::Perform(const Handle(Adaptor3d_Surface)& theS1, |
788cbaf4 |
1001 | const Handle(Adaptor3d_TopolTool)& theD1, |
c22b52d6 |
1002 | const Handle(Adaptor3d_Surface)& theS2, |
788cbaf4 |
1003 | const Handle(Adaptor3d_TopolTool)& theD2, |
7fd59977 |
1004 | const Standard_Real TolArc, |
1005 | const Standard_Real TolTang, |
1006 | IntSurf_ListOfPntOn2S& ListOfPnts, |
4e14c88f |
1007 | const Standard_Boolean isGeomInt, |
1008 | const Standard_Boolean theIsReqToKeepRLine, |
1009 | const Standard_Boolean theIsReqToPostWLProc) |
7fd59977 |
1010 | { |
1011 | myTolArc = TolArc; |
1012 | myTolTang = TolTang; |
788cbaf4 |
1013 | if(myFleche <= Precision::PConfusion()) |
1014 | myFleche = 0.01; |
1015 | if(myUVMaxStep <= Precision::PConfusion()) |
1016 | myUVMaxStep = 0.01; |
7fd59977 |
1017 | done = Standard_False; |
1018 | spnt.Clear(); |
1019 | slin.Clear(); |
1020 | empt = Standard_True; |
1021 | tgte = Standard_False; |
1022 | oppo = Standard_False; |
1023 | |
788cbaf4 |
1024 | GeomAbs_SurfaceType typs1 = theS1->GetType(); |
1025 | GeomAbs_SurfaceType typs2 = theS2->GetType(); |
18d25b93 |
1026 | // |
1027 | //treatment of the cases with cone or torus |
7fd59977 |
1028 | Standard_Boolean TreatAsBiParametric = Standard_False; |
1d18c75e |
1029 | Standard_Integer bGeomGeom = 0; |
18d25b93 |
1030 | // |
1031 | if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone || |
1032 | typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) { |
1033 | gp_Ax1 aCTAx, aGeomAx; |
1034 | GeomAbs_SurfaceType aCTType; |
1035 | Standard_Boolean bToCheck; |
1036 | // |
c22b52d6 |
1037 | const Handle(Adaptor3d_Surface)& aCTSurf = |
18d25b93 |
1038 | (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS1 : theS2; |
c22b52d6 |
1039 | const Handle(Adaptor3d_Surface)& aGeomSurf = |
18d25b93 |
1040 | (typs1 == GeomAbs_Cone || typs1 == GeomAbs_Torus) ? theS2 : theS1; |
1041 | // |
1042 | aCTType = aCTSurf->GetType(); |
1043 | bToCheck = Standard_False; |
1044 | // |
1d18c75e |
1045 | if (typs1 == GeomAbs_Cone || typs2 == GeomAbs_Cone) { |
1046 | const gp_Cone aCon1 = (aCTType == GeomAbs_Cone) ? |
1047 | aCTSurf->Cone() : aGeomSurf->Cone(); |
1048 | Standard_Real a1 = Abs(aCon1.SemiAngle()); |
18d25b93 |
1049 | bToCheck = (a1 < 0.02) || (a1 > 1.55); |
1d18c75e |
1050 | // |
18d25b93 |
1051 | if (typs1 == typs2) { |
1d18c75e |
1052 | const gp_Cone aCon2 = aGeomSurf->Cone(); |
1053 | Standard_Real a2 = Abs(aCon2.SemiAngle()); |
18d25b93 |
1054 | bToCheck = bToCheck || (a2 < 0.02) || (a2 > 1.55); |
1055 | // |
1056 | if (a1 > 1.55 && a2 > 1.55) {//quasi-planes: if same domain, treat as canonic |
18d25b93 |
1057 | const gp_Ax1 A1 = aCon1.Axis(), A2 = aCon2.Axis(); |
1058 | if (A1.IsParallel(A2,Precision::Angular())) { |
1059 | const gp_Pnt Apex1 = aCon1.Apex(), Apex2 = aCon2.Apex(); |
1060 | const gp_Pln Plan1( Apex1, A1.Direction() ); |
1061 | if (Plan1.Distance( Apex2 ) <= Precision::Confusion()) { |
1062 | bToCheck = Standard_False; |
18d25b93 |
1063 | } |
788cbaf4 |
1064 | } |
1065 | } |
7fd59977 |
1066 | } |
18d25b93 |
1067 | // |
1d18c75e |
1068 | TreatAsBiParametric = bToCheck; |
1069 | if (aCTType == GeomAbs_Cone) { |
1070 | aCTAx = aCon1.Axis(); |
1071 | } |
788cbaf4 |
1072 | } |
1d18c75e |
1073 | // |
1074 | if (typs1 == GeomAbs_Torus || typs2 == GeomAbs_Torus) { |
1075 | const gp_Torus aTor1 = (aCTType == GeomAbs_Torus) ? |
1076 | aCTSurf->Torus() : aGeomSurf->Torus(); |
1077 | bToCheck = aTor1.MajorRadius() > aTor1.MinorRadius(); |
1078 | if (typs1 == typs2) { |
1079 | const gp_Torus aTor2 = aGeomSurf->Torus(); |
83f7dbeb |
1080 | bToCheck = (bToCheck && (aTor2.MajorRadius() > aTor2.MinorRadius())) || |
1081 | (Abs(aTor1.MajorRadius() - aTor2.MajorRadius()) < TolTang && |
1082 | Abs(aTor1.MinorRadius() - aTor2.MinorRadius()) < TolTang); |
1d18c75e |
1083 | } |
1084 | // |
1085 | if (aCTType == GeomAbs_Torus) { |
1086 | aCTAx = aTor1.Axis(); |
18d25b93 |
1087 | } |
18d25b93 |
1088 | } |
1089 | // |
1090 | if (bToCheck) { |
1091 | const gp_Lin aL1(aCTAx); |
1092 | // |
1093 | switch (aGeomSurf->GetType()) { |
1094 | case GeomAbs_Plane: { |
1095 | aGeomAx = aGeomSurf->Plane().Axis(); |
1096 | if (aCTType == GeomAbs_Cone) { |
1d18c75e |
1097 | bGeomGeom = 1; |
18d25b93 |
1098 | if (Abs(aCTSurf->Cone().SemiAngle()) < 0.02) { |
1099 | Standard_Real ps = Abs(aCTAx.Direction().Dot(aGeomAx.Direction())); |
1100 | if(ps < 0.015) { |
1d18c75e |
1101 | bGeomGeom = 0; |
18d25b93 |
1102 | } |
788cbaf4 |
1103 | } |
1104 | } |
18d25b93 |
1105 | else { |
1106 | if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) || |
1107 | (aCTAx.IsNormal(aGeomAx, Precision::Angular()) && |
1108 | (aGeomSurf->Plane().Distance(aCTAx.Location()) < Precision::Confusion()))) { |
1d18c75e |
1109 | bGeomGeom = 1; |
18d25b93 |
1110 | } |
1111 | } |
1112 | bToCheck = Standard_False; |
1113 | break; |
7fd59977 |
1114 | } |
18d25b93 |
1115 | case GeomAbs_Sphere: { |
1116 | if (aL1.Distance(aGeomSurf->Sphere().Location()) < Precision::Confusion()) { |
1d18c75e |
1117 | bGeomGeom = 1; |
18d25b93 |
1118 | } |
1119 | bToCheck = Standard_False; |
1120 | break; |
7fd59977 |
1121 | } |
18d25b93 |
1122 | case GeomAbs_Cylinder: |
1123 | aGeomAx = aGeomSurf->Cylinder().Axis(); |
1124 | break; |
1125 | case GeomAbs_Cone: |
1126 | aGeomAx = aGeomSurf->Cone().Axis(); |
1127 | break; |
1128 | case GeomAbs_Torus: |
1129 | aGeomAx = aGeomSurf->Torus().Axis(); |
1130 | break; |
1131 | default: |
1132 | bToCheck = Standard_False; |
1133 | break; |
1134 | } |
1135 | // |
1136 | if (bToCheck) { |
1137 | if (aCTAx.IsParallel(aGeomAx, Precision::Angular()) && |
1138 | (aL1.Distance(aGeomAx.Location()) <= Precision::Confusion())) { |
1d18c75e |
1139 | bGeomGeom = 1; |
788cbaf4 |
1140 | } |
7fd59977 |
1141 | } |
18d25b93 |
1142 | // |
1d18c75e |
1143 | if (bGeomGeom == 1) { |
1144 | TreatAsBiParametric = Standard_False; |
18d25b93 |
1145 | } |
1146 | } |
1147 | } |
1148 | // |
7fd59977 |
1149 | |
788cbaf4 |
1150 | if(theD1->DomainIsInfinite() || theD2->DomainIsInfinite()) { |
bf0ba813 |
1151 | TreatAsBiParametric= Standard_False; |
1152 | } |
788cbaf4 |
1153 | |
1154 | if(TreatAsBiParametric) |
1155 | { |
1156 | // Using Prm-Prm Intersector |
1157 | typs1 = GeomAbs_BezierSurface; |
1158 | typs2 = GeomAbs_BezierSurface; |
bf0ba813 |
1159 | } |
7fd59977 |
1160 | |
1161 | // Surface type definition |
1162 | Standard_Integer ts1 = 0; |
1163 | switch (typs1) |
1164 | { |
1165 | case GeomAbs_Plane: |
1166 | case GeomAbs_Cylinder: |
1167 | case GeomAbs_Sphere: |
1168 | case GeomAbs_Cone: ts1 = 1; break; |
1d18c75e |
1169 | case GeomAbs_Torus: ts1 = bGeomGeom; break; |
7fd59977 |
1170 | default: break; |
1171 | } |
788cbaf4 |
1172 | |
7fd59977 |
1173 | Standard_Integer ts2 = 0; |
1174 | switch (typs2) |
1175 | { |
1176 | case GeomAbs_Plane: |
1177 | case GeomAbs_Cylinder: |
1178 | case GeomAbs_Sphere: |
1179 | case GeomAbs_Cone: ts2 = 1; break; |
1d18c75e |
1180 | case GeomAbs_Torus: ts2 = bGeomGeom; break; |
7fd59977 |
1181 | default: break; |
1182 | } |
7eed5d29 |
1183 | // |
7fd59977 |
1184 | // Possible intersection types: 1. ts1 == ts2 == 1 <Geom-Geom> |
1185 | // 2. ts1 != ts2 <Geom-Param> |
1186 | // 3. ts1 == ts2 == 0 <Param-Param> |
1187 | |
788cbaf4 |
1188 | if(!isGeomInt) |
7fd59977 |
1189 | { |
02effd35 |
1190 | ParamParamPerfom(theS1, theD1, theS2, theD2, |
7797eb38 |
1191 | TolArc, TolTang, ListOfPnts, typs1, typs2); |
7fd59977 |
1192 | } |
788cbaf4 |
1193 | else if(ts1 != ts2) |
1194 | { |
1195 | GeomParamPerfom(theS1, theD1, theS2, theD2, ts1 == 0, typs1, typs2); |
1196 | } |
1197 | else if (ts1 == 0) |
1198 | { |
02effd35 |
1199 | ParamParamPerfom(theS1, theD1, theS2, theD2, |
7797eb38 |
1200 | TolArc, TolTang, ListOfPnts, typs1, typs2); |
788cbaf4 |
1201 | } |
1202 | else if(ts1 == 1) |
1203 | { |
7797eb38 |
1204 | GeomGeomPerfom(theS1, theD1, theS2, theD2, TolArc, TolTang, |
1205 | ListOfPnts, typs1, typs2, theIsReqToKeepRLine); |
788cbaf4 |
1206 | } |
4e14c88f |
1207 | |
1208 | if(!theIsReqToPostWLProc) |
1209 | return; |
1210 | |
1211 | for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++) |
1212 | { |
1213 | Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i)); |
1214 | |
1215 | if(aWL.IsNull()) |
1216 | continue; |
1217 | |
716037dd |
1218 | if(!aWL->IsPurgingAllowed()) |
1219 | continue; |
1220 | |
5185b161 |
1221 | Handle(IntPatch_WLine) aRW = |
7797eb38 |
1222 | IntPatch_WLineTool::ComputePurgedWLine(aWL, theS1, theS2, theD1, theD2); |
4e14c88f |
1223 | |
1224 | if(aRW.IsNull()) |
1225 | continue; |
1226 | |
1227 | slin.InsertAfter(i, aRW); |
1228 | slin.Remove(i); |
1229 | } |
788cbaf4 |
1230 | } |
1231 | |
1232 | //======================================================================= |
1233 | //function : ParamParamPerfom |
1234 | //purpose : |
1235 | //======================================================================= |
c22b52d6 |
1236 | void IntPatch_Intersection::ParamParamPerfom(const Handle(Adaptor3d_Surface)& theS1, |
788cbaf4 |
1237 | const Handle(Adaptor3d_TopolTool)& theD1, |
c22b52d6 |
1238 | const Handle(Adaptor3d_Surface)& theS2, |
788cbaf4 |
1239 | const Handle(Adaptor3d_TopolTool)& theD2, |
1240 | const Standard_Real TolArc, |
1241 | const Standard_Real TolTang, |
1242 | IntSurf_ListOfPntOn2S& ListOfPnts, |
788cbaf4 |
1243 | const GeomAbs_SurfaceType typs1, |
1244 | const GeomAbs_SurfaceType typs2) |
1245 | { |
1246 | IntPatch_PrmPrmIntersection interpp; |
9eee5ab7 |
1247 | // |
788cbaf4 |
1248 | if(!theD1->DomainIsInfinite() && !theD2->DomainIsInfinite()) |
7fd59977 |
1249 | { |
788cbaf4 |
1250 | Standard_Boolean ClearFlag = Standard_True; |
1251 | if(!ListOfPnts.IsEmpty()) |
1252 | { |
9eee5ab7 |
1253 | interpp.Perform(theS1,theD1,theS2,theD2,TolTang,TolArc,myFleche, myUVMaxStep, ListOfPnts); |
788cbaf4 |
1254 | ClearFlag = Standard_False; |
7fd59977 |
1255 | } |
9eee5ab7 |
1256 | interpp.Perform(theS1,theD1,theS2,theD2,TolTang,TolArc,myFleche, myUVMaxStep,ClearFlag); |
7fd59977 |
1257 | } |
788cbaf4 |
1258 | else if((theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite())) |
7fd59977 |
1259 | { |
788cbaf4 |
1260 | gp_Pnt pMaxXYZ, pMinXYZ; |
1261 | if(theD1->DomainIsInfinite()) |
1262 | { |
1263 | FUN_GetMinMaxXYZPnt( theS2, pMinXYZ, pMaxXYZ ); |
1264 | const Standard_Real MU = Max(Abs(theS2->FirstUParameter()),Abs(theS2->LastUParameter())); |
1265 | const Standard_Real MV = Max(Abs(theS2->FirstVParameter()),Abs(theS2->LastVParameter())); |
1266 | const Standard_Real AP = Max(MU, MV); |
c22b52d6 |
1267 | Handle(Adaptor3d_Surface) SS; |
788cbaf4 |
1268 | FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS1, AP, SS); |
9eee5ab7 |
1269 | interpp.Perform(SS,theD1,theS2,theD2,TolTang,TolArc,myFleche, myUVMaxStep); |
788cbaf4 |
1270 | } |
1271 | else |
1272 | { |
1273 | FUN_GetMinMaxXYZPnt( theS1, pMinXYZ, pMaxXYZ ); |
1274 | const Standard_Real MU = Max(Abs(theS1->FirstUParameter()),Abs(theS1->LastUParameter())); |
1275 | const Standard_Real MV = Max(Abs(theS1->FirstVParameter()),Abs(theS1->LastVParameter())); |
1276 | const Standard_Real AP = Max(MU, MV); |
c22b52d6 |
1277 | Handle(Adaptor3d_Surface) SS; |
788cbaf4 |
1278 | FUN_TrimInfSurf(pMinXYZ, pMaxXYZ, theS2, AP, SS); |
9eee5ab7 |
1279 | interpp.Perform(theS1, theD1, SS, theD2,TolTang, TolArc,myFleche, myUVMaxStep); |
788cbaf4 |
1280 | } |
1281 | }//(theD1->DomainIsInfinite()) ^ (theD2->DomainIsInfinite()) |
1282 | else |
1283 | { |
1284 | if(typs1 == GeomAbs_OtherSurface || typs2 == GeomAbs_OtherSurface) |
1285 | { |
1286 | done = Standard_False; |
1287 | return; |
1288 | } |
1289 | |
1290 | Standard_Boolean IsPLInt = Standard_False; |
1291 | TColgp_SequenceOfPnt sop; |
1292 | gp_Vec v; |
1293 | FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v); |
1294 | |
1295 | if(IsPLInt) |
1296 | { |
1297 | if(sop.Length() > 0) |
1298 | { |
1299 | for(Standard_Integer ip = 1; ip <= sop.Length(); ip++) |
1300 | { |
1301 | gp_Lin lin(sop.Value(ip),gp_Dir(v)); |
a9dde4a3 |
1302 | Handle(IntPatch_Line) gl = new IntPatch_GLine(lin,Standard_False); |
1303 | slin.Append(gl); |
788cbaf4 |
1304 | } |
1305 | |
1306 | done = Standard_True; |
7fd59977 |
1307 | } |
788cbaf4 |
1308 | else |
1309 | done = Standard_False; |
1310 | |
1311 | return; |
1312 | }// 'COLLINEAR LINES' |
1313 | else |
1314 | { |
c22b52d6 |
1315 | Handle(Adaptor3d_Surface) nS1 = theS1; |
1316 | Handle(Adaptor3d_Surface) nS2 = theS2; |
788cbaf4 |
1317 | FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+8,nS1,nS2); |
9eee5ab7 |
1318 | interpp.Perform(nS1,theD1,nS2,theD2,TolTang,TolArc,myFleche, myUVMaxStep); |
788cbaf4 |
1319 | }// 'NON - COLLINEAR LINES' |
1320 | }// both domains are infinite |
1321 | |
1322 | if (interpp.IsDone()) |
1323 | { |
1324 | done = Standard_True; |
1325 | tgte = Standard_False; |
1326 | empt = interpp.IsEmpty(); |
1327 | |
1328 | for(Standard_Integer i = 1; i <= interpp.NbLines(); i++) |
1329 | { |
1330 | if(interpp.Line(i)->ArcType() != IntPatch_Walking) |
1331 | slin.Append(interpp.Line(i)); |
1332 | } |
1333 | |
1334 | for (Standard_Integer i = 1; i <= interpp.NbLines(); i++) |
1335 | { |
1336 | if(interpp.Line(i)->ArcType() == IntPatch_Walking) |
1337 | slin.Append(interpp.Line(i)); |
1338 | } |
1339 | } |
1340 | } |
1341 | |
1342 | //======================================================================= |
1343 | ////function : GeomGeomPerfom |
1344 | //purpose : |
1345 | //======================================================================= |
c22b52d6 |
1346 | void IntPatch_Intersection::GeomGeomPerfom(const Handle(Adaptor3d_Surface)& theS1, |
788cbaf4 |
1347 | const Handle(Adaptor3d_TopolTool)& theD1, |
c22b52d6 |
1348 | const Handle(Adaptor3d_Surface)& theS2, |
788cbaf4 |
1349 | const Handle(Adaptor3d_TopolTool)& theD2, |
1350 | const Standard_Real TolArc, |
1351 | const Standard_Real TolTang, |
1352 | IntSurf_ListOfPntOn2S& ListOfPnts, |
464cd2fb |
1353 | const GeomAbs_SurfaceType theTyps1, |
1354 | const GeomAbs_SurfaceType theTyps2, |
d4b867e6 |
1355 | const Standard_Boolean theIsReqToKeepRLine) |
788cbaf4 |
1356 | { |
d4b867e6 |
1357 | IntPatch_ImpImpIntersection interii(theS1,theD1,theS2,theD2, |
1358 | myTolArc,myTolTang, theIsReqToKeepRLine); |
e2e0498b |
1359 | |
1360 | if (!interii.IsDone()) |
788cbaf4 |
1361 | { |
e2e0498b |
1362 | done = Standard_False; |
1363 | ParamParamPerfom(theS1, theD1, theS2, theD2, |
7797eb38 |
1364 | TolArc, TolTang, ListOfPnts, theTyps1, theTyps2); |
e2e0498b |
1365 | return; |
1366 | } |
788cbaf4 |
1367 | |
e2e0498b |
1368 | done = (interii.GetStatus() == IntPatch_ImpImpIntersection::IntStatus_OK); |
1369 | empt = interii.IsEmpty(); |
eee615ad |
1370 | |
e2e0498b |
1371 | if(empt) |
1372 | { |
1373 | return; |
1374 | } |
7eed5d29 |
1375 | |
e2e0498b |
1376 | const Standard_Integer aNbPointsInALine = 200; |
788cbaf4 |
1377 | |
e2e0498b |
1378 | tgte = interii.TangentFaces(); |
1379 | if (tgte) |
1380 | oppo = interii.OppositeFaces(); |
788cbaf4 |
1381 | |
e2e0498b |
1382 | Standard_Boolean isWLExist = Standard_False; |
1383 | IntPatch_ALineToWLine AToW(theS1, theS2, aNbPointsInALine); |
d30895f5 |
1384 | |
e2e0498b |
1385 | for (Standard_Integer i = 1; i <= interii.NbLines(); i++) |
1386 | { |
1387 | const Handle(IntPatch_Line)& line = interii.Line(i); |
1388 | if (line->ArcType() == IntPatch_Analytic) |
1389 | { |
1390 | isWLExist = Standard_True; |
1391 | AToW.MakeWLine(Handle(IntPatch_ALine)::DownCast(line), slin); |
1392 | } |
1393 | else |
1394 | { |
1395 | if (line->ArcType() == IntPatch_Walking) |
d30895f5 |
1396 | { |
e2e0498b |
1397 | Handle(IntPatch_WLine)::DownCast(line)->EnablePurging(Standard_False); |
eee615ad |
1398 | } |
1399 | |
e2e0498b |
1400 | if((line->ArcType() != IntPatch_Restriction) || theIsReqToKeepRLine) |
1401 | slin.Append(line); |
788cbaf4 |
1402 | } |
1403 | } |
e2e0498b |
1404 | |
1405 | for (Standard_Integer i = 1; i <= interii.NbPnts(); i++) |
1406 | { |
1407 | spnt.Append(interii.Point(i)); |
1408 | } |
1409 | |
1410 | if((theTyps1 == GeomAbs_Cylinder) && (theTyps2 == GeomAbs_Cylinder)) |
1411 | { |
261b7d9e |
1412 | IntPatch_WLineTool::JoinWLines(slin, spnt, theS1, theS2, TolTang); |
e2e0498b |
1413 | } |
1414 | |
1415 | if(isWLExist) |
1416 | { |
1417 | Bnd_Box2d aBx1, aBx2; |
1418 | const Standard_Real aU1F = theS1->FirstUParameter(), |
1419 | aU1L = theS1->LastUParameter(), |
1420 | aV1F = theS1->FirstVParameter(), |
1421 | aV1L = theS1->LastVParameter(), |
1422 | aU2F = theS2->FirstUParameter(), |
1423 | aU2L = theS2->LastUParameter(), |
1424 | aV2F = theS2->FirstVParameter(), |
1425 | aV2L = theS2->LastVParameter(); |
1426 | aBx1.Add(gp_Pnt2d(aU1F, aV1F)); |
1427 | aBx1.Add(gp_Pnt2d(aU1L, aV1F)); |
1428 | aBx1.Add(gp_Pnt2d(aU1L, aV1L)); |
1429 | aBx1.Add(gp_Pnt2d(aU1F, aV1L)); |
1430 | aBx2.Add(gp_Pnt2d(aU2F, aV2F)); |
1431 | aBx2.Add(gp_Pnt2d(aU2L, aV2F)); |
1432 | aBx2.Add(gp_Pnt2d(aU2L, aV2L)); |
1433 | aBx2.Add(gp_Pnt2d(aU2F, aV2L)); |
1434 | |
1435 | aBx1.Enlarge(Precision::PConfusion()); |
1436 | aBx2.Enlarge(Precision::PConfusion()); |
1437 | |
1438 | const Standard_Real |
1439 | anArrOfPeriod[4] = {theS1->IsUPeriodic()? theS1->UPeriod() : 0.0, |
1440 | theS1->IsVPeriodic()? theS1->VPeriod() : 0.0, |
1441 | theS2->IsUPeriodic()? theS2->UPeriod() : 0.0, |
1442 | theS2->IsVPeriodic()? theS2->VPeriod() : 0.0}; |
3306fdd9 |
1443 | |
1444 | NCollection_List<gp_Pnt> aListOfCriticalPoints; |
1445 | |
1446 | if (theS1->GetType() == GeomAbs_Cone) |
1447 | { |
1448 | aListOfCriticalPoints.Append(theS1->Cone().Apex()); |
1449 | } |
1450 | else if (theS1->GetType() == GeomAbs_Sphere) |
1451 | { |
1452 | aListOfCriticalPoints.Append(theS1->Value(0.0, M_PI_2)); |
1453 | aListOfCriticalPoints.Append(theS1->Value(0.0, -M_PI_2)); |
1454 | } |
1455 | |
1456 | if (theS2->GetType() == GeomAbs_Cone) |
1457 | { |
1458 | aListOfCriticalPoints.Append(theS2->Cone().Apex()); |
1459 | } |
1460 | else if (theS2->GetType() == GeomAbs_Sphere) |
1461 | { |
1462 | aListOfCriticalPoints.Append(theS2->Value(0.0, M_PI_2)); |
1463 | aListOfCriticalPoints.Append(theS2->Value(0.0, -M_PI_2)); |
1464 | } |
1465 | |
e2e0498b |
1466 | IntPatch_WLineTool::ExtendTwoWLines(slin, theS1, theS2, TolTang, |
3306fdd9 |
1467 | anArrOfPeriod, aBx1, aBx2, |
1468 | aListOfCriticalPoints); |
e2e0498b |
1469 | } |
788cbaf4 |
1470 | } |
1471 | |
1472 | //======================================================================= |
ecc4f148 |
1473 | //function : GeomParamPerfom |
788cbaf4 |
1474 | //purpose : |
1475 | //======================================================================= |
ecc4f148 |
1476 | void IntPatch_Intersection:: |
c22b52d6 |
1477 | GeomParamPerfom(const Handle(Adaptor3d_Surface)& theS1, |
ecc4f148 |
1478 | const Handle(Adaptor3d_TopolTool)& theD1, |
c22b52d6 |
1479 | const Handle(Adaptor3d_Surface)& theS2, |
ecc4f148 |
1480 | const Handle(Adaptor3d_TopolTool)& theD2, |
1481 | const Standard_Boolean isNotAnalitical, |
1482 | const GeomAbs_SurfaceType typs1, |
1483 | const GeomAbs_SurfaceType typs2) |
788cbaf4 |
1484 | { |
1485 | IntPatch_ImpPrmIntersection interip; |
1486 | if (myIsStartPnt) |
1487 | { |
1488 | if (isNotAnalitical/*ts1 == 0*/) |
1489 | interip.SetStartPoint(myU1Start,myV1Start); |
1490 | else |
1491 | interip.SetStartPoint(myU2Start,myV2Start); |
1492 | } |
1493 | |
1494 | if(theD1->DomainIsInfinite() && theD2->DomainIsInfinite()) |
1495 | { |
1496 | Standard_Boolean IsPLInt = Standard_False; |
1497 | TColgp_SequenceOfPnt sop; |
1498 | gp_Vec v; |
1499 | FUN_PL_Intersection(theS1,typs1,theS2,typs2,IsPLInt,sop,v); |
1500 | |
1501 | if(IsPLInt) |
1502 | { |
1503 | if(sop.Length() > 0) |
1504 | { |
1505 | for(Standard_Integer ip = 1; ip <= sop.Length(); ip++) |
1506 | { |
1507 | gp_Lin lin(sop.Value(ip),gp_Dir(v)); |
a9dde4a3 |
1508 | Handle(IntPatch_Line) gl = new IntPatch_GLine(lin,Standard_False); |
1509 | slin.Append(gl); |
788cbaf4 |
1510 | } |
1511 | |
1512 | done = Standard_True; |
1513 | } |
1514 | else |
1515 | done = Standard_False; |
1516 | |
1517 | return; |
1518 | } |
1519 | else |
1520 | { |
c22b52d6 |
1521 | Handle(Adaptor3d_Surface) nS1 = theS1; |
1522 | Handle(Adaptor3d_Surface) nS2 = theS2; |
788cbaf4 |
1523 | FUN_TrimBothSurf(theS1,typs1,theS2,typs2,1.e+5,nS1,nS2); |
1524 | interip.Perform(nS1,theD1,nS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep); |
1525 | } |
1526 | } |
1527 | else |
1528 | interip.Perform(theS1,theD1,theS2,theD2,myTolArc,myTolTang,myFleche,myUVMaxStep); |
1529 | |
1530 | if (interip.IsDone()) |
1531 | { |
1532 | done = Standard_True; |
1533 | empt = interip.IsEmpty(); |
1534 | |
1535 | if (!empt) |
1536 | { |
b92f3572 |
1537 | const Standard_Integer aNbLines = interip.NbLines(); |
1538 | for(Standard_Integer i = 1; i <= aNbLines; i++) |
788cbaf4 |
1539 | { |
1540 | if(interip.Line(i)->ArcType() != IntPatch_Walking) |
1541 | slin.Append(interip.Line(i)); |
1542 | } |
1543 | |
b92f3572 |
1544 | for(Standard_Integer i = 1; i <= aNbLines; i++) |
788cbaf4 |
1545 | { |
1546 | if(interip.Line(i)->ArcType() == IntPatch_Walking) |
1547 | slin.Append(interip.Line(i)); |
1548 | } |
1549 | |
1550 | for (Standard_Integer i = 1; i <= interip.NbPnts(); i++) |
1551 | spnt.Append(interip.Point(i)); |
1552 | } |
7fd59977 |
1553 | } |
1554 | } |
1555 | |
c22b52d6 |
1556 | void IntPatch_Intersection::Perform(const Handle(Adaptor3d_Surface)& S1, |
7fd59977 |
1557 | const Handle(Adaptor3d_TopolTool)& D1, |
c22b52d6 |
1558 | const Handle(Adaptor3d_Surface)& S2, |
7fd59977 |
1559 | const Handle(Adaptor3d_TopolTool)& D2, |
1560 | const Standard_Real U1, |
1561 | const Standard_Real V1, |
1562 | const Standard_Real U2, |
1563 | const Standard_Real V2, |
1564 | const Standard_Real TolArc, |
1565 | const Standard_Real TolTang) |
1566 | { |
1567 | myTolArc = TolArc; |
1568 | myTolTang = TolTang; |
1569 | if(myFleche == 0.0) { |
ff1f0c9a |
1570 | #ifdef OCCT_DEBUG |
04232180 |
1571 | //std::cout<<" -- IntPatch_Intersection::myFleche fixe par defaut a 0.01 --"<<std::endl; |
1572 | //std::cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<std::endl; |
7fd59977 |
1573 | #endif |
1574 | myFleche = 0.01; |
1575 | } |
1576 | if(myUVMaxStep==0.0) { |
ff1f0c9a |
1577 | #ifdef OCCT_DEBUG |
04232180 |
1578 | //std::cout<<" -- IntPatch_Intersection::myUVMaxStep fixe par defaut a 0.01 --"<<std::endl; |
1579 | //std::cout<<" -- Utiliser la Methode SetTolerances( ... ) "<<std::endl; |
7fd59977 |
1580 | #endif |
1581 | myUVMaxStep = 0.01; |
1582 | } |
1583 | |
1584 | done = Standard_False; |
1585 | spnt.Clear(); |
1586 | slin.Clear(); |
1587 | |
1588 | empt = Standard_True; |
1589 | tgte = Standard_False; |
1590 | oppo = Standard_False; |
1591 | |
1592 | const GeomAbs_SurfaceType typs1 = S1->GetType(); |
1593 | const GeomAbs_SurfaceType typs2 = S2->GetType(); |
1594 | |
1595 | if( typs1==GeomAbs_Plane |
1596 | || typs1==GeomAbs_Cylinder |
1597 | || typs1==GeomAbs_Sphere |
1598 | || typs1==GeomAbs_Cone |
1599 | || typs2==GeomAbs_Plane |
1600 | || typs2==GeomAbs_Cylinder |
1601 | || typs2==GeomAbs_Sphere |
1602 | || typs2==GeomAbs_Cone) |
1603 | { |
1604 | myIsStartPnt = Standard_True; |
1605 | myU1Start = U1; myV1Start = V1; myU2Start = U2; myV2Start = V2; |
1606 | Perform(S1,D1,S2,D2,TolArc,TolTang); |
1607 | myIsStartPnt = Standard_False; |
1608 | } |
1609 | else |
1610 | { |
1611 | IntPatch_PrmPrmIntersection interpp; |
714c3bfc |
1612 | interpp.Perform(S1,D1,S2,D2,U1,V1,U2,V2,TolTang,TolArc,myFleche,myUVMaxStep); |
7fd59977 |
1613 | if (interpp.IsDone()) |
1d18c75e |
1614 | { |
7fd59977 |
1615 | done = Standard_True; |
1616 | tgte = Standard_False; |
1617 | empt = interpp.IsEmpty(); |
1618 | const Standard_Integer nblm = interpp.NbLines(); |
1619 | Standard_Integer i = 1; |
1620 | for (; i<=nblm; i++) slin.Append(interpp.Line(i)); |
1621 | } |
1622 | } |
4e14c88f |
1623 | |
1624 | for(Standard_Integer i = slin.Lower(); i <= slin.Upper(); i++) |
1625 | { |
1626 | Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(slin.Value(i)); |
1627 | |
1628 | if(aWL.IsNull()) |
1629 | continue; |
1630 | |
e146ef9a |
1631 | if (!aWL->IsPurgingAllowed()) |
1632 | continue; |
1633 | |
5185b161 |
1634 | Handle(IntPatch_WLine) aRW = |
7797eb38 |
1635 | IntPatch_WLineTool::ComputePurgedWLine(aWL, S1, S2, D1, D2); |
4e14c88f |
1636 | |
1637 | if(aRW.IsNull()) |
1638 | continue; |
1639 | |
1640 | slin.InsertAfter(i, aRW); |
1641 | slin.Remove(i); |
1642 | } |
7fd59977 |
1643 | } |
4e14c88f |
1644 | |
1645 | #ifdef DUMPOFIntPatch_Intersection |
1646 | |
c22b52d6 |
1647 | void IntPatch_Intersection__MAJ_R(Handle(Adaptor2d_Curve2d) *R1, |
1648 | Handle(Adaptor2d_Curve2d) *, |
4e14c88f |
1649 | int *NR1, |
1d18c75e |
1650 | int *, |
4e14c88f |
1651 | Standard_Integer nbR1, |
1d18c75e |
1652 | Standard_Integer , |
4e14c88f |
1653 | const IntPatch_Point& VTX) |
7fd59977 |
1654 | { |
4e14c88f |
1655 | |
7fd59977 |
1656 | if(VTX.IsOnDomS1()) { |
1657 | |
857ffd5e |
1658 | //-- long unsigned ptr= *((long unsigned *)(((Handle(Standard_Transient) *)(&(VTX.ArcOnS1()))))); |
7fd59977 |
1659 | for(Standard_Integer i=0; i<nbR1;i++) { |
1660 | if(VTX.ArcOnS1()==R1[i]) { |
1d18c75e |
1661 | NR1[i]++; |
1662 | printf("\n ******************************"); |
1663 | return; |
7fd59977 |
1664 | } |
1665 | } |
1666 | printf("\n R Pas trouvee (IntPatch)\n"); |
1667 | |
1668 | } |
7fd59977 |
1669 | } |
4e14c88f |
1670 | #endif |
7fd59977 |
1671 | |
4e14c88f |
1672 | void IntPatch_Intersection::Dump(const Standard_Integer /*Mode*/, |
c22b52d6 |
1673 | const Handle(Adaptor3d_Surface)& /*S1*/, |
4e14c88f |
1674 | const Handle(Adaptor3d_TopolTool)& /*D1*/, |
c22b52d6 |
1675 | const Handle(Adaptor3d_Surface)& /*S2*/, |
4e14c88f |
1676 | const Handle(Adaptor3d_TopolTool)& /*D2*/) const |
7fd59977 |
1677 | { |
4e14c88f |
1678 | #ifdef DUMPOFIntPatch_Intersection |
1679 | const int MAXR = 200; |
7fd59977 |
1680 | //-- ---------------------------------------------------------------------- |
1681 | //-- construction de la liste des restrictions & vertex |
1682 | //-- |
1683 | int NR1[MAXR],NR2[MAXR]; |
c22b52d6 |
1684 | Handle(Adaptor2d_Curve2d) R1[MAXR],R2[MAXR]; |
7fd59977 |
1685 | Standard_Integer nbR1=0,nbR2=0; |
1686 | for(D1->Init();D1->More() && nbR1<MAXR; D1->Next()) { |
1687 | R1[nbR1]=D1->Value(); |
1688 | NR1[nbR1]=0; |
1689 | nbR1++; |
1690 | } |
4e14c88f |
1691 | for(D2->Init();D2->More() && nbR2<MAXR; D2->Next()) { |
7fd59977 |
1692 | R2[nbR2]=D2->Value(); |
1693 | NR2[nbR2]=0; |
1694 | nbR2++; |
1695 | } |
1696 | |
566f8441 |
1697 | printf("\nDUMP_INT: ----empt:%2ud tgte:%2ud oppo:%2ud ---------------------------------",empt,tgte,empt); |
4e14c88f |
1698 | Standard_Integer i,nbr1,nbr2,nbgl,nbgc,nbge,nbgp,nbgh,nbl,nbr,nbg,nbw,nba; |
7fd59977 |
1699 | nbl=nbr=nbg=nbw=nba=nbgl=nbge=nbr1=nbr2=nbgc=nbgp=nbgh=0; |
1700 | nbl=NbLines(); |
1701 | for(i=1;i<=nbl;i++) { |
1702 | const Handle(IntPatch_Line)& line=Line(i); |
1703 | const IntPatch_IType IType=line->ArcType(); |
1704 | if(IType == IntPatch_Walking) nbw++; |
1705 | else if(IType == IntPatch_Restriction) { |
1706 | nbr++; |
a1eb3afd |
1707 | Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (line)); |
7fd59977 |
1708 | if(rlin->IsArcOnS1()) nbr1++; |
1709 | if(rlin->IsArcOnS2()) nbr2++; |
1710 | } |
1711 | else if(IType == IntPatch_Analytic) nba++; |
1d18c75e |
1712 | else { |
1713 | nbg++; |
1714 | if(IType == IntPatch_Lin) nbgl++; |
1715 | else if(IType == IntPatch_Circle) nbgc++; |
1716 | else if(IType == IntPatch_Parabola) nbgp++; |
1717 | else if(IType == IntPatch_Hyperbola) nbgh++; |
1718 | else if(IType == IntPatch_Ellipse) nbge++; |
1719 | } |
7fd59977 |
1720 | } |
1721 | |
1722 | |
1723 | printf("\nDUMP_INT:Lines:%2d Wlin:%2d Restr:%2d(On1:%2d On2:%2d) Ana:%2d Geom:%2d(L:%2d C:%2d E:%2d H:%2d P:%2d)", |
1d18c75e |
1724 | nbl,nbw,nbr,nbr1,nbr2,nba,nbg,nbgl,nbgc,nbge,nbgh,nbgp); |
7fd59977 |
1725 | |
1726 | IntPatch_LineConstructor LineConstructor(2); |
1727 | |
1728 | Standard_Integer nbllc=0; |
1729 | nbw=nbr=nbg=nba=0; |
1730 | Standard_Integer nbva,nbvw,nbvr,nbvg; |
1731 | nbva=nbvr=nbvw=nbvg=0; |
1732 | for (j=1; j<=nbl; j++) { |
1733 | Standard_Integer v,nbvtx; |
1734 | const Handle(IntPatch_Line)& intersLinej = Line(j); |
1735 | Standard_Integer NbLines; |
1736 | LineConstructor.Perform(SequenceOfLine(),intersLinej,S1,D1,S2,D2,1e-7); |
1737 | NbLines = LineConstructor.NbLines(); |
1738 | |
1739 | for(Standard_Integer k=1;k<=NbLines;k++) { |
1740 | nbllc++; |
1741 | const Handle(IntPatch_Line)& LineK = LineConstructor.Line(k); |
1742 | if (LineK->ArcType() == IntPatch_Analytic) { |
a1eb3afd |
1743 | Handle(IntPatch_ALine) alin (Handle(IntPatch_ALine)::DownCast (LineK)); |
1d18c75e |
1744 | nbvtx=alin->NbVertex(); |
1745 | nbva+=nbvtx; nba++; |
1746 | for(v=1;v<=nbvtx;v++) { |
1747 | IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,alin->Vertex(v)); |
1748 | } |
7fd59977 |
1749 | } |
1750 | else if (LineK->ArcType() == IntPatch_Restriction) { |
a1eb3afd |
1751 | Handle(IntPatch_RLine) rlin (Handle(IntPatch_RLine)::DownCast (LineK)); |
1d18c75e |
1752 | nbvtx=rlin->NbVertex(); |
1753 | nbvr+=nbvtx; nbr++; |
1754 | for(v=1;v<=nbvtx;v++) { |
1755 | IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,rlin->Vertex(v)); |
1756 | } |
7fd59977 |
1757 | } |
1758 | else if (LineK->ArcType() == IntPatch_Walking) { |
a1eb3afd |
1759 | Handle(IntPatch_WLine) wlin (Handle(IntPatch_WLine)::DownCast (LineK)); |
1d18c75e |
1760 | nbvtx=wlin->NbVertex(); |
1761 | nbvw+=nbvtx; nbw++; |
1762 | for(v=1;v<=nbvtx;v++) { |
1763 | IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,wlin->Vertex(v)); |
1764 | } |
7fd59977 |
1765 | } |
1766 | else { |
a1eb3afd |
1767 | Handle(IntPatch_GLine) glin (Handle(IntPatch_GLine)::DownCast (LineK)); |
1d18c75e |
1768 | nbvtx=glin->NbVertex(); |
1769 | nbvg+=nbvtx; nbg++; |
1770 | for(v=1;v<=nbvtx;v++) { |
1771 | IntPatch_Intersection__MAJ_R(R1,R2,NR1,NR2,nbR1,nbR2,glin->Vertex(v)); |
1772 | } |
7fd59977 |
1773 | } |
1774 | } |
1775 | } |
1776 | printf("\nDUMP_LC :Lines:%2d WLin:%2d Restr:%2d Ana:%2d Geom:%2d", |
1d18c75e |
1777 | nbllc,nbw,nbr,nba,nbg); |
7fd59977 |
1778 | printf("\nDUMP_LC :vtx :%2d r:%2d :%2d :%2d", |
1d18c75e |
1779 | nbvw,nbvr,nbva,nbvg); |
7fd59977 |
1780 | |
4e14c88f |
1781 | printf("\n"); |
7fd59977 |
1782 | |
4e14c88f |
1783 | #endif |
7fd59977 |
1784 | } |
9eee5ab7 |
1785 | |
1786 | //======================================================================= |
1787 | //function : CheckSingularPoints |
1788 | //purpose : |
1789 | //======================================================================= |
1790 | Standard_Boolean IntPatch_Intersection::CheckSingularPoints( |
1791 | const Handle(Adaptor3d_Surface)& theS1, |
1792 | const Handle(Adaptor3d_TopolTool)& theD1, |
1793 | const Handle(Adaptor3d_Surface)& theS2, |
1794 | Standard_Real& theDist) |
1795 | { |
1796 | theDist = Precision::Infinite(); |
1797 | Standard_Boolean isSingular = Standard_False; |
1798 | if (theS1 == theS2) |
1799 | { |
1800 | return isSingular; |
1801 | } |
1802 | // |
1803 | const Standard_Integer aNbBndPnts = 5; |
1804 | const Standard_Real aTol = Precision::Confusion(); |
1805 | Standard_Integer i; |
1806 | theD1->Init(); |
1807 | Standard_Boolean isU = Standard_True; |
1808 | for (; theD1->More(); theD1->Next()) |
1809 | { |
1810 | Handle(Adaptor2d_Curve2d) aBnd = theD1->Value(); |
1811 | Standard_Real pinf = aBnd->FirstParameter(), psup = aBnd->LastParameter(); |
1812 | if (Precision::IsNegativeInfinite(pinf) || Precision::IsPositiveInfinite(psup)) |
1813 | { |
1814 | continue; |
1815 | } |
1816 | Standard_Real t, dt = (psup - pinf) / (aNbBndPnts - 1); |
1817 | gp_Pnt2d aP1; |
1818 | gp_Vec2d aDir; |
1819 | aBnd->D1((pinf + psup) / 2., aP1, aDir); |
1820 | if (Abs(aDir.X()) > Abs(aDir.Y())) |
1821 | isU = Standard_True; |
1822 | else |
1823 | isU = Standard_False; |
1824 | gp_Pnt aPP1; |
1825 | gp_Vec aDU, aDV; |
1826 | Standard_Real aD1NormMax = 0.; |
1827 | gp_XYZ aPmid(0., 0., 0.); |
1828 | Standard_Integer aNb = 0; |
1829 | for (t = pinf; t <= psup; t += dt) |
1830 | { |
1831 | aP1 = aBnd->Value(t); |
1832 | theS1->D1(aP1.X(), aP1.Y(), aPP1, aDU, aDV); |
1833 | if (isU) |
1834 | aD1NormMax = Max(aD1NormMax, aDU.Magnitude()); |
1835 | else |
1836 | aD1NormMax = Max(aD1NormMax, aDV.Magnitude()); |
1837 | |
1838 | aPmid += aPP1.XYZ(); |
1839 | aNb++; |
1840 | |
1841 | if (aD1NormMax > aTol) |
1842 | break; |
1843 | } |
1844 | |
1845 | if (aD1NormMax <= aTol) |
1846 | { |
1847 | //Singular point aPP1; |
1848 | aPmid /= aNb; |
1849 | aPP1.SetXYZ(aPmid); |
1850 | Standard_Real aTolU = Precision::PConfusion(), aTolV = Precision::PConfusion(); |
1851 | Extrema_ExtPS aProj(aPP1, *theS2.get(), aTolU, aTolV, Extrema_ExtFlag_MIN); |
1852 | |
1853 | if (aProj.IsDone()) |
1854 | { |
1855 | Standard_Integer aNbExt = aProj.NbExt(); |
1856 | for (i = 1; i <= aNbExt; ++i) |
1857 | { |
1858 | theDist = Min(theDist, aProj.SquareDistance(i)); |
1859 | } |
1860 | } |
1861 | |
1862 | } |
1863 | } |
1864 | if (!Precision::IsInfinite(theDist)) |
1865 | { |
1866 | theDist = Sqrt(theDist); |
1867 | isSingular = Standard_True; |
1868 | } |
1869 | |
1870 | return isSingular; |
1871 | |
1872 | } |
1873 | //======================================================================= |
1874 | //function : DefineUVMaxStep |
1875 | //purpose : |
1876 | //======================================================================= |
1877 | Standard_Real IntPatch_Intersection::DefineUVMaxStep( |
1878 | const Handle(Adaptor3d_Surface)& theS1, |
1879 | const Handle(Adaptor3d_TopolTool)& theD1, |
1880 | const Handle(Adaptor3d_Surface)& theS2, |
1881 | const Handle(Adaptor3d_TopolTool)& theD2) |
1882 | { |
1883 | Standard_Real anUVMaxStep = 0.001; |
1884 | Standard_Real aDistToSing1 = Precision::Infinite(); |
1885 | Standard_Real aDistToSing2 = Precision::Infinite(); |
1886 | const Standard_Real aTolMin = Precision::Confusion(), aTolMax = 1.e-5; |
1887 | if (theS1 != theS2) |
1888 | { |
1889 | Standard_Boolean isSing1 = CheckSingularPoints(theS1, theD1, theS2, aDistToSing1); |
1890 | if (isSing1) |
1891 | { |
1892 | if (aDistToSing1 > aTolMin && aDistToSing1 < aTolMax) |
1893 | { |
1894 | anUVMaxStep = 0.0001; |
1895 | } |
1896 | else |
1897 | { |
1898 | isSing1 = Standard_False; |
1899 | } |
1900 | } |
1901 | if (!isSing1) |
1902 | { |
1903 | Standard_Boolean isSing2 = CheckSingularPoints(theS2, theD2, theS1, aDistToSing2); |
1904 | if (isSing2) |
1905 | { |
1906 | if (aDistToSing2 > aTolMin && aDistToSing2 < aTolMax) |
1907 | { |
1908 | anUVMaxStep = 0.0001; |
1909 | } |
1910 | } |
1911 | } |
1912 | } |
1913 | return anUVMaxStep; |
1914 | } |
1915 | |
5ae6f08c |
1916 | //======================================================================= |
1917 | //function : splitCone |
1918 | //purpose : Splits cone by the apex |
1919 | //======================================================================= |
1920 | static void splitCone( |
1921 | const Handle(Adaptor3d_Surface)& theS, |
1922 | const Handle(Adaptor3d_TopolTool)& theD, |
1923 | const Standard_Real theTol, |
1924 | NCollection_Vector< Handle(Adaptor3d_Surface)>& theVecHS) |
1925 | { |
1926 | if (theS->GetType() != GeomAbs_Cone) |
1927 | { |
1928 | throw Standard_NoSuchObject("IntPatch_Intersection : Surface is not Cone"); |
1929 | } |
1930 | |
1931 | gp_Cone aCone = theS->Cone(); |
1932 | |
1933 | Standard_Real aU0, aV0; |
1934 | Adaptor3d_TopolTool::GetConeApexParam (aCone, aU0, aV0); |
1935 | |
1936 | TopAbs_State aState = theD->Classify (gp_Pnt2d (aU0, aV0), theTol); |
1937 | |
1938 | if (aState == TopAbs_IN || aState == TopAbs_ON) |
1939 | { |
1940 | const Handle(Adaptor3d_Surface) aHSDn = theS->VTrim (theS->FirstVParameter(), aV0, Precision::PConfusion()); |
1941 | const Handle(Adaptor3d_Surface) aHSUp = theS->VTrim (aV0, theS->LastVParameter(), Precision::PConfusion()); |
1942 | |
1943 | theVecHS.Append (aHSDn); |
1944 | theVecHS.Append (aHSUp); |
1945 | } |
1946 | else |
1947 | { |
1948 | theVecHS.Append (theS); |
1949 | } |
1950 | } |
1951 | |
1952 | //======================================================================= |
1953 | //function : PrepareSurfaces |
1954 | //purpose : Prepares surfaces for intersection |
1955 | //======================================================================= |
1956 | void IntPatch_Intersection::PrepareSurfaces( |
1957 | const Handle(Adaptor3d_Surface)& theS1, |
1958 | const Handle(Adaptor3d_TopolTool)& theD1, |
1959 | const Handle(Adaptor3d_Surface)& theS2, |
1960 | const Handle(Adaptor3d_TopolTool)& theD2, |
1961 | const Standard_Real theTol, |
1962 | NCollection_Vector< Handle(Adaptor3d_Surface)>& theVecHS1, |
1963 | NCollection_Vector< Handle(Adaptor3d_Surface)>& theVecHS2) |
1964 | { |
1965 | if ((theS1->GetType() == GeomAbs_Cone) && (Abs (M_PI / 2. - Abs (theS1->Cone().SemiAngle())) < theTol)) |
1966 | { |
1967 | splitCone (theS1, theD1, theTol, theVecHS1); |
1968 | } |
1969 | else |
1970 | { |
1971 | theVecHS1.Append (theS1); |
1972 | } |
1973 | |
1974 | if ((theS2->GetType() == GeomAbs_Cone) && (Abs (M_PI / 2. - Abs (theS2->Cone().SemiAngle())) < theTol)) |
1975 | { |
1976 | splitCone (theS2, theD2, theTol, theVecHS2); |
1977 | } |
1978 | else |
1979 | { |
1980 | theVecHS2.Append (theS2); |
1981 | } |
1982 | } |
1983 | |
1984 | |