Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: BRepTools_NurbsConvertModification.cxx |
2 | // Created: Fri Jul 12 10:16:32 1996 | |
3 | // Author: Stagiaire Mary FABIEN | |
4 | // <fbi@animax.paris1.matra-dtv.fr> | |
5 | ||
6 | ||
7 | #include <BRepTools_NurbsConvertModification.ixx> | |
8 | ||
9 | #include <BRepTools.hxx> | |
10 | #include <Standard_NoSuchObject.hxx> | |
11 | #include <Geom_TrimmedCurve.hxx> | |
12 | #include <Geom2d_TrimmedCurve.hxx> | |
13 | #include <Geom_RectangularTrimmedSurface.hxx> | |
14 | #include <Geom_BSplineSurface.hxx> | |
15 | #include <Geom_BSplineCurve.hxx> | |
16 | #include <Geom_BezierSurface.hxx> | |
17 | #include <Geom_BezierCurve.hxx> | |
18 | #include <Geom2d_BSplineCurve.hxx> | |
19 | #include <GeomConvert.hxx> | |
20 | #include <Geom2dConvert.hxx> | |
21 | #include <Geom_Plane.hxx> | |
22 | #include <Geom_Line.hxx> | |
23 | #include <Geom2dAdaptor_Curve.hxx> | |
24 | #include <GeomAdaptor_Curve.hxx> | |
25 | #include <GeomAdaptor_Surface.hxx> | |
26 | #include <Geom2dAdaptor_HCurve.hxx> | |
27 | #include <Geom2dAdaptor_HCurve.hxx> | |
28 | #include <GeomAdaptor_HCurve.hxx> | |
29 | #include <GeomAdaptor_HSurface.hxx> | |
30 | ||
31 | #include <BSplCLib.hxx> | |
32 | #include <Approx_SameParameter.hxx> | |
33 | #include <BRep_Tool.hxx> | |
34 | #include <Extrema_LocateExtPC.hxx> | |
35 | #include <OSD_Chronometer.hxx> | |
36 | #include <gp_GTrsf2d.hxx> | |
37 | #include <gp_TrsfForm.hxx> | |
38 | #include <TopAbs.hxx> | |
39 | #include <TopoDS.hxx> | |
40 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
41 | #include <TColStd_ListIteratorOfListOfTransient.hxx> | |
42 | #include <ProjLib_ComputeApprox.hxx> | |
43 | #include <ProjLib_ComputeApproxOnPolarSurface.hxx> | |
44 | #include <ElSLib.hxx> | |
45 | #include <BSplCLib.hxx> | |
46 | #include <Geom_Circle.hxx> | |
47 | #include <Geom_Ellipse.hxx> | |
48 | #include <Geom_CylindricalSurface.hxx> | |
49 | ||
50 | #include <TColStd_Array1OfReal.hxx> | |
51 | #include <BRep_TEdge.hxx> | |
52 | #include <BRep_GCurve.hxx> | |
53 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> | |
54 | ||
55 | static void GeomLib_ChangeUBounds(Handle(Geom_BSplineSurface)& aSurface, | |
56 | const Standard_Real newU1, | |
57 | const Standard_Real newU2) | |
58 | { | |
59 | TColStd_Array1OfReal knots(1,aSurface->NbUKnots()) ; | |
60 | aSurface->UKnots(knots) ; | |
61 | BSplCLib::Reparametrize(newU1, | |
62 | newU2, | |
63 | knots) ; | |
64 | aSurface->SetUKnots(knots) ; | |
65 | } | |
66 | static void GeomLib_ChangeVBounds(Handle(Geom_BSplineSurface)& aSurface, | |
67 | const Standard_Real newV1, | |
68 | const Standard_Real newV2) | |
69 | { | |
70 | TColStd_Array1OfReal knots(1,aSurface->NbVKnots()) ; | |
71 | aSurface->VKnots(knots) ; | |
72 | BSplCLib::Reparametrize(newV1, | |
73 | newV2, | |
74 | knots) ; | |
75 | aSurface->SetVKnots(knots) ; | |
76 | } | |
77 | ||
78 | //======================================================================= | |
79 | //function : BRepTools_NurbsConvertModification | |
80 | //purpose : | |
81 | //======================================================================= | |
82 | ||
83 | BRepTools_NurbsConvertModification::BRepTools_NurbsConvertModification() | |
84 | { | |
85 | } | |
86 | ||
87 | ||
88 | ||
89 | //======================================================================= | |
90 | //function : NewSurface | |
91 | //purpose : | |
92 | //======================================================================= | |
93 | ||
94 | Standard_Boolean BRepTools_NurbsConvertModification::NewSurface | |
95 | (const TopoDS_Face& F, | |
96 | Handle(Geom_Surface)& S, | |
97 | TopLoc_Location& L, | |
98 | Standard_Real& Tol, | |
99 | Standard_Boolean& RevWires, | |
100 | Standard_Boolean& RevFace) | |
101 | { | |
102 | Standard_Real U1, U2, curvU1, curvU2, surfU1, surfU2, UTol; | |
103 | Standard_Real V1, V2, curvV1, curvV2, surfV1, surfV2, VTol; | |
104 | RevWires = Standard_False; | |
105 | RevFace = Standard_False; | |
106 | Handle(Geom_Surface) SS = BRep_Tool::Surface(F,L); | |
107 | Handle(Standard_Type) TheTypeSS = SS->DynamicType(); | |
108 | if ((TheTypeSS == STANDARD_TYPE(Geom_BSplineSurface)) || | |
109 | (TheTypeSS == STANDARD_TYPE(Geom_BezierSurface))) { | |
110 | return Standard_False; | |
111 | } | |
112 | S = SS; | |
113 | BRepTools::UVBounds(F,curvU1,curvU2,curvV1,curvV2); | |
114 | Tol = BRep_Tool::Tolerance(F); | |
115 | Standard_Real TolPar = 0.1*Tol; | |
116 | Standard_Boolean IsUp = S->IsUPeriodic(), IsVp = S->IsVPeriodic(); | |
117 | //OCC466(apo)-> | |
118 | U1 = curvU1; U2 = curvU2; | |
119 | V1 = curvV1; V2 = curvV2; | |
86eff19e J |
120 | SS->Bounds(surfU1,surfU2,surfV1,surfV2); |
121 | ||
122 | if (Abs(U1 - surfU1) <= TolPar) | |
123 | U1 = surfU1; | |
124 | if (Abs(U2 - surfU2) <= TolPar) | |
125 | U2 = surfU2; | |
126 | if (Abs(V1 - surfV1) <= TolPar) | |
127 | V1 = surfV1; | |
128 | if (Abs(V2 - surfV2) <= TolPar) | |
129 | V2 = surfV2; | |
130 | ||
7fd59977 | 131 | if(!IsUp){ |
132 | U1 = Max(surfU1,curvU1); | |
133 | U2 = Min(surfU2,curvU2); | |
134 | } | |
135 | if(!IsVp){ | |
136 | V1 = Max(surfV1,curvV1); | |
137 | V2 = Min(surfV2,curvV2); | |
138 | } | |
86eff19e J |
139 | //<-OCC466(apo) |
140 | ||
141 | if (IsUp) | |
142 | { | |
143 | Standard_Real Up = S->UPeriod(); | |
144 | if (U2 - U1 > Up) | |
145 | U2 = U1 + Up; | |
146 | } | |
147 | if (IsVp) | |
148 | { | |
149 | Standard_Real Vp = S->VPeriod(); | |
150 | if (V2 - V1 > Vp) | |
151 | V2 = V1 + Vp; | |
152 | } | |
153 | ||
154 | /* | |
7fd59977 | 155 | if(IsUp && IsVp) { |
156 | Standard_Real dU = Abs(U2 - U1), dV = Abs(V2 - V1); | |
157 | Standard_Real Up = S->UPeriod(), Vp = S->VPeriod(); | |
158 | if(Abs(dU - Up) <= TolPar && U2 <= Up) { | |
159 | if(Abs(dV - Vp) <= TolPar && V2 <= Vp) { } | |
160 | else { | |
161 | SS = new Geom_RectangularTrimmedSurface(S, V1+1e-9, V2-1e-9, Standard_False); | |
162 | } | |
163 | } | |
164 | else { | |
165 | if(Abs(dV - Vp) <= TolPar && V2 <= Vp) | |
166 | SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, Standard_True); | |
167 | else | |
168 | SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9); | |
169 | } | |
170 | } | |
171 | ||
172 | if(IsUp && !IsVp) { | |
173 | Standard_Real dU = Abs(U2 - U1); | |
174 | Standard_Real Up = S->UPeriod(); | |
175 | if(Abs(dU - Up) <= TolPar && U2 <= Up) | |
176 | SS = new Geom_RectangularTrimmedSurface(S, V1+1e-9, V2-1e-9, Standard_False); | |
177 | else | |
178 | SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9); | |
179 | } | |
180 | ||
181 | if(!IsUp && IsVp) { | |
182 | Standard_Real dV = Abs(V2 - V1); | |
183 | Standard_Real Vp = S->VPeriod(); | |
184 | if(Abs(dV - Vp) <= TolPar && V2 <= Vp) | |
185 | SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, Standard_True); | |
186 | else | |
187 | SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9); | |
188 | } | |
189 | ||
190 | if(!IsUp && !IsVp) { | |
191 | SS = new Geom_RectangularTrimmedSurface(S, U1+1e-9, U2-1e-9, V1+1e-9, V2-1e-9); | |
192 | } | |
86eff19e | 193 | */ |
7fd59977 | 194 | |
86eff19e J |
195 | if (Abs(surfU1-U1) > Tol || Abs(surfU2-U2) > Tol || |
196 | Abs(surfV1-V1) > Tol || Abs(surfV2-V2) > Tol) | |
197 | SS = new Geom_RectangularTrimmedSurface(S, U1, U2, V1, V2); | |
198 | SS->Bounds(surfU1,surfU2,surfV1,surfV2); | |
7fd59977 | 199 | |
200 | S = GeomConvert::SurfaceToBSplineSurface(SS); | |
201 | Handle(Geom_BSplineSurface) BS = Handle(Geom_BSplineSurface)::DownCast(S) ; | |
202 | BS->Resolution(Tol, UTol, VTol) ; | |
203 | ||
204 | // | |
205 | // on recadre les bornes de S sinon les anciennes PCurves sont aux fraises | |
206 | // | |
207 | ||
208 | if (Abs(curvU1-surfU1) > UTol && !BS->IsUPeriodic()) { | |
209 | GeomLib_ChangeUBounds(BS, U1,U2) ; | |
210 | } | |
211 | if (Abs(curvV1-surfV1) > VTol && !BS->IsVPeriodic()) { | |
212 | GeomLib_ChangeVBounds(BS, V1, V2) ; | |
213 | } | |
214 | ||
215 | return Standard_True; | |
216 | } | |
217 | ||
218 | static Standard_Boolean IsConvert(const TopoDS_Edge& E) | |
219 | { | |
220 | Standard_Boolean isConvert = Standard_False; | |
221 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape()); | |
222 | // iterate on pcurves | |
223 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); | |
224 | for ( ; itcr.More() && !isConvert; itcr.Next() ) { | |
225 | Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value()); | |
226 | if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue; | |
227 | Handle(Geom_Surface) aSurface = GC->Surface(); | |
228 | Handle(Geom2d_Curve) aCurve2d = GC->PCurve(); | |
229 | isConvert =((!aSurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface)) && | |
230 | !aSurface->IsKind(STANDARD_TYPE(Geom_BezierSurface))) || | |
231 | (!aCurve2d->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve)) && | |
232 | !aCurve2d->IsKind(STANDARD_TYPE(Geom2d_BezierCurve)))); | |
233 | ||
234 | } | |
235 | return isConvert; | |
236 | ||
237 | } | |
238 | ||
239 | //======================================================================= | |
240 | //function : NewCurve | |
241 | //purpose : | |
242 | //======================================================================= | |
243 | ||
244 | Standard_Boolean BRepTools_NurbsConvertModification::NewCurve | |
245 | (const TopoDS_Edge& E, | |
246 | Handle(Geom_Curve)& C, | |
247 | TopLoc_Location& L, | |
248 | Standard_Real& Tol) | |
249 | { | |
250 | ||
251 | Tol = BRep_Tool::Tolerance(E); | |
252 | if(BRep_Tool::Degenerated(E)) { | |
253 | C.Nullify(); | |
254 | L.Identity(); | |
255 | return Standard_True; | |
256 | } | |
257 | Standard_Real f, l; | |
258 | ||
259 | Handle(Geom_Curve) Caux = BRep_Tool::Curve(E, L, f, l); | |
260 | ||
261 | if ( Caux.IsNull()) { | |
262 | L.Identity(); | |
263 | return Standard_False; | |
264 | } | |
265 | Handle(Standard_Type) TheType = Caux->DynamicType(); | |
266 | if ((TheType == STANDARD_TYPE(Geom_BSplineCurve)) || | |
267 | (TheType == STANDARD_TYPE(Geom_BezierCurve))) { | |
268 | if(IsConvert(E)) { | |
269 | C = Handle(Geom_Curve)::DownCast(Caux->Copy()); | |
270 | return Standard_True; | |
271 | } | |
272 | return Standard_False; | |
273 | } | |
274 | ||
275 | C = Caux; | |
276 | ||
277 | Standard_Real TolPar = Tol *.1; | |
278 | ||
279 | if(C->IsPeriodic()) { | |
280 | Standard_Real p = C->Period(); | |
281 | Standard_Real d = Abs(l - f); | |
282 | if(Abs(d - p) <= TolPar && l <= p) {} | |
283 | else | |
284 | C = new Geom_TrimmedCurve(C, f, l); | |
285 | } | |
286 | else | |
287 | C = new Geom_TrimmedCurve(C, f, l); | |
288 | ||
289 | //modif WOK++ portage hp (fbi du 14/03/97) | |
290 | // gp_Trsf trsf(L); | |
291 | // gp_Trsf trsf = L.Transformation(); | |
292 | ||
293 | // C = GeomConvert::CurveToBSplineCurve(C,Convert_QuasiAngular); | |
294 | ||
295 | C = GeomConvert::CurveToBSplineCurve(C); | |
296 | ||
297 | Standard_Real fnew = C->FirstParameter(), lnew = C->LastParameter(), UTol; | |
298 | ||
299 | Handle(Geom_BSplineCurve) BC = Handle(Geom_BSplineCurve)::DownCast(C) ; | |
300 | ||
301 | if(!BC->IsPeriodic()) { | |
302 | BC->Resolution(Tol, UTol) ; | |
303 | if(Abs(f - fnew) > UTol || Abs(l - lnew) > UTol) { | |
304 | TColStd_Array1OfReal knots(1,BC->NbKnots()) ; | |
305 | BC->Knots(knots) ; | |
306 | BSplCLib::Reparametrize(f, l, knots) ; | |
307 | BC->SetKnots(knots) ; | |
308 | } | |
309 | } | |
310 | ||
311 | if(!myMap.Contains(Caux)) { | |
312 | myMap.Add(Caux,C); | |
313 | } | |
314 | return Standard_True ; | |
315 | } | |
316 | ||
317 | //======================================================================= | |
318 | //function : NewPoint | |
319 | //purpose : | |
320 | //======================================================================= | |
321 | ||
322 | Standard_Boolean BRepTools_NurbsConvertModification::NewPoint | |
323 | //(const TopoDS_Vertex& V, | |
324 | (const TopoDS_Vertex& , | |
325 | // gp_Pnt& P, | |
326 | gp_Pnt& , | |
327 | // Standard_Real& Tol) | |
328 | Standard_Real& ) | |
329 | { | |
330 | return Standard_False; | |
331 | } | |
332 | ||
333 | ||
334 | //======================================================================= | |
335 | //function : NewCurve2d | |
336 | //purpose : | |
337 | //======================================================================= | |
338 | ||
339 | Standard_Boolean BRepTools_NurbsConvertModification::NewCurve2d | |
340 | (const TopoDS_Edge& E, | |
341 | const TopoDS_Face& F, | |
342 | const TopoDS_Edge& newE, | |
343 | const TopoDS_Face& newF, | |
344 | Handle(Geom2d_Curve)& Curve2d, | |
345 | Standard_Real& Tol) | |
346 | { | |
347 | ||
348 | Tol = BRep_Tool::Tolerance(E); | |
349 | Standard_Real f2d,l2d; | |
350 | Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E,F,f2d,l2d); | |
351 | Standard_Real f3d,l3d; | |
352 | TopLoc_Location Loc; | |
353 | Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, Loc, f3d,l3d); | |
354 | Standard_Boolean isConvert2d = ((!C3d.IsNull() && !C3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) && | |
355 | !C3d->IsKind(STANDARD_TYPE(Geom_BezierCurve))) || | |
356 | IsConvert(E)); | |
86eff19e | 357 | |
7fd59977 | 358 | if(BRep_Tool::Degenerated(E)) { |
359 | //Curve2d = C2d; | |
360 | if(!C2d->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) | |
361 | { | |
362 | Handle(Geom2d_TrimmedCurve) aTrimC = new Geom2d_TrimmedCurve(C2d,f2d,l2d); | |
363 | C2d = aTrimC; | |
364 | } | |
365 | Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d); | |
366 | return Standard_True; | |
367 | } | |
368 | if(!BRepTools::IsReallyClosed(E,F)) { | |
369 | Handle(Standard_Type) TheTypeC2d = C2d->DynamicType(); | |
370 | ||
371 | if(TheTypeC2d == STANDARD_TYPE(Geom2d_TrimmedCurve)) { | |
372 | Handle(Geom2d_TrimmedCurve) TC = Handle(Geom2d_TrimmedCurve)::DownCast(C2d); | |
373 | C2d = TC->BasisCurve(); | |
374 | } | |
375 | ||
376 | Standard_Real fc = C2d->FirstParameter(), lc = C2d->LastParameter(); | |
377 | ||
378 | if(!C2d->IsPeriodic()) { | |
379 | if(fc - f2d > Precision::PConfusion()) f2d = fc; | |
380 | if(l2d - lc > Precision::PConfusion()) l2d = lc; | |
381 | } | |
382 | ||
383 | C2d = new Geom2d_TrimmedCurve(C2d, f2d, l2d); | |
384 | ||
385 | Geom2dAdaptor_Curve G2dAC(C2d, f2d, l2d); | |
386 | Handle(Geom2dAdaptor_HCurve) G2dAHC = new Geom2dAdaptor_HCurve(G2dAC); | |
387 | ||
388 | TopLoc_Location Loc; | |
389 | Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, Loc, f3d,l3d); | |
390 | if(!newE.IsNull()) { | |
391 | C3d = BRep_Tool::Curve(newE, f3d, l3d); | |
392 | } | |
393 | else { | |
394 | C3d = BRep_Tool::Curve(E,f3d,l3d); | |
395 | } | |
396 | GeomAdaptor_Curve G3dAC(C3d, f3d, l3d); | |
397 | Handle(GeomAdaptor_HCurve) G3dAHC = new GeomAdaptor_HCurve(G3dAC); | |
398 | ||
399 | Standard_Real Uinf, Usup, Vinf, Vsup, u = 0, v = 0; | |
400 | Handle(Geom_Surface) S = BRep_Tool::Surface(F); | |
401 | Handle(Standard_Type) myT = S->DynamicType(); | |
402 | if(myT != STANDARD_TYPE(Geom_Plane)) { | |
403 | if(newF.IsNull()) { | |
404 | Handle(Standard_Type) st = C2d->DynamicType(); | |
405 | if ((st == STANDARD_TYPE(Geom2d_BSplineCurve)) || | |
406 | (st == STANDARD_TYPE(Geom2d_BezierCurve))) { | |
407 | if(isConvert2d) { | |
408 | Curve2d = Handle(Geom2d_Curve)::DownCast(C2d->Copy()); | |
409 | return Standard_True; | |
410 | } | |
411 | return Standard_False; | |
412 | } | |
413 | } | |
414 | else { | |
415 | S = BRep_Tool::Surface(newF); | |
416 | ||
417 | } | |
418 | S->Bounds(Uinf, Usup, Vinf, Vsup); | |
86eff19e | 419 | //Uinf -= 1e-9; Usup += 1e-9; Vinf -= 1e-9; Vsup += 1e-9; |
7fd59977 | 420 | u = (Usup - Uinf)*0.1; |
421 | v = (Vsup - Vinf)*0.1; | |
422 | if(S->IsUPeriodic()) { | |
423 | Standard_Real uperiod = S->UPeriod(); | |
424 | if(uperiod < (Usup+2*u-Uinf)) { | |
425 | if(uperiod <= (Usup-Uinf)) { | |
426 | u = 0; | |
427 | } | |
428 | else { | |
429 | u = (uperiod-(Usup-Uinf))*0.5; | |
430 | } | |
431 | } | |
432 | } | |
433 | if(S->IsVPeriodic()) { | |
434 | Standard_Real vperiod = S->VPeriod(); | |
435 | if(vperiod < (Vsup+2*v-Vinf)) { | |
436 | if(vperiod <= (Vsup-Vinf)) { | |
437 | v = 0; | |
438 | } | |
439 | else { | |
440 | v = (vperiod-(Vsup-Vinf))*0.5; | |
441 | } | |
442 | } | |
443 | } | |
444 | } | |
445 | else { | |
446 | S = BRep_Tool::Surface(F);// Si S est un plan, pas de changement de parametrisation | |
447 | GeomAdaptor_Surface GAS(S); | |
448 | Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(GAS); | |
449 | ProjLib_ComputeApprox ProjOnCurve(G3dAHC,GAHS,Tol); | |
450 | if(ProjOnCurve.BSpline().IsNull()) { | |
451 | Curve2d = Geom2dConvert::CurveToBSplineCurve(ProjOnCurve.Bezier()); | |
452 | return Standard_True; | |
453 | } | |
454 | Curve2d = ProjOnCurve.BSpline(); | |
455 | return Standard_True; | |
456 | } | |
457 | GeomAdaptor_Surface GAS(S,Uinf-u,Usup+u,Vinf-v,Vsup+v); | |
458 | ||
459 | Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(GAS); | |
460 | ||
461 | ProjLib_ComputeApproxOnPolarSurface ProjOnCurve(G2dAHC,G3dAHC,GAHS,Tol); | |
462 | ||
463 | if(ProjOnCurve.IsDone()) { | |
464 | Curve2d = ProjOnCurve.BSpline(); | |
465 | ||
466 | return Standard_True; | |
467 | } | |
468 | else { | |
469 | Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d); | |
470 | return Standard_True; | |
471 | } | |
472 | } | |
473 | else { | |
474 | TopTools_ListIteratorOfListOfShape itled; | |
475 | TColStd_ListIteratorOfListOfTransient itlcu; | |
476 | ||
477 | for (itled.Initialize(myled), itlcu.Initialize(mylcu); | |
478 | itled.More(); // itlcu.More() | |
479 | itled.Next(),itlcu.Next()) { | |
480 | if (itled.Value().IsSame(E)) { | |
481 | // deja traitee | |
482 | break; | |
483 | } | |
484 | } | |
485 | if (!itled.More()) { // on stocke l`edge et la curve2d | |
486 | Handle(Geom2d_Curve) C2dBis; | |
487 | Standard_Real f3d,l3d,f2dBis,l2dBis; | |
488 | C2d = new Geom2d_TrimmedCurve(C2d, f2d, l2d); | |
489 | Geom2dAdaptor_Curve G2dAC(C2d, f2d, l2d); | |
490 | Handle(Geom2dAdaptor_HCurve) G2dAHC = new Geom2dAdaptor_HCurve(G2dAC); | |
491 | TopoDS_Edge ERevers = E; | |
492 | ERevers.Reverse(); | |
493 | // TopoDS_Edge ERevers = TopoDS::Edge(E.Reversed()); | |
494 | C2dBis = BRep_Tool::CurveOnSurface(ERevers,F,f2dBis,l2dBis); | |
495 | Handle(Standard_Type) TheTypeC2dBis = C2dBis->DynamicType(); | |
496 | C2dBis = new Geom2d_TrimmedCurve(C2dBis,f2dBis, l2dBis); | |
497 | Geom2dAdaptor_Curve G2dACBis(C2dBis, f2dBis, l2dBis); | |
498 | Handle(Geom2dAdaptor_HCurve) G2dAHCBis = new Geom2dAdaptor_HCurve(G2dACBis); | |
499 | ||
500 | TopLoc_Location Loc; | |
501 | Handle(Geom_Curve) C3d = BRep_Tool::Curve(E, f3d,l3d); | |
502 | if(C3d.IsNull()) { | |
503 | if(isConvert2d) { | |
504 | Curve2d = Handle(Geom2d_Curve)::DownCast(C2d->Copy()); | |
505 | return Standard_True; | |
506 | } | |
507 | ||
508 | return Standard_False; | |
509 | } | |
510 | if(!newE.IsNull()) { | |
511 | C3d = BRep_Tool::Curve(newE, f3d,l3d); | |
512 | } | |
513 | GeomAdaptor_Curve G3dAC(C3d, f3d, l3d); | |
514 | Handle(GeomAdaptor_HCurve) G3dAHC = new GeomAdaptor_HCurve(G3dAC); | |
515 | ||
516 | Handle(Geom_Surface) S = BRep_Tool::Surface(F); | |
517 | Handle(Standard_Type) myT = S->DynamicType(); | |
518 | if(newF.IsNull()) { | |
519 | mylcu.Append(C2dBis); | |
520 | Handle(Standard_Type) st = C2d->DynamicType(); | |
521 | if ((st == STANDARD_TYPE(Geom2d_BSplineCurve)) || | |
522 | (st == STANDARD_TYPE(Geom2d_BezierCurve))) { | |
523 | if(isConvert2d) { | |
524 | Curve2d = Handle(Geom2d_Curve)::DownCast(C2d->Copy()); | |
525 | return Standard_True; | |
526 | } | |
527 | return Standard_False; | |
528 | } | |
529 | } | |
530 | else { | |
531 | S = BRep_Tool::Surface(newF);// S est une BSplineSurface : pas besoin de la trimmed | |
532 | } | |
533 | Standard_Real Uinf, Usup, Vinf, Vsup, u = 0, v = 0; | |
534 | S->Bounds(Uinf, Usup, Vinf, Vsup); | |
86eff19e | 535 | //Uinf -= 1e-9; Usup += 1e-9; Vinf -= 1e-9; Vsup += 1e-9; |
7fd59977 | 536 | u = (Usup - Uinf)*0.1; |
537 | v = (Vsup - Vinf)*0.1; | |
538 | if(S->IsUPeriodic()) { | |
539 | Standard_Real uperiod = S->UPeriod(); | |
540 | if(uperiod < (Usup+2*u-Uinf)) | |
541 | if(uperiod <= (Usup-Uinf)) | |
542 | u = 0; | |
543 | else | |
544 | u = (uperiod-(Usup-Uinf))*0.5; | |
545 | } | |
546 | if(S->IsVPeriodic()) { | |
547 | Standard_Real vperiod = S->VPeriod(); | |
548 | if(vperiod < (Vsup+2*v-Vinf)) | |
549 | if(vperiod <= (Vsup-Vinf)) | |
550 | v = 0; | |
551 | else | |
552 | v = (vperiod-(Vsup-Vinf))*0.5; | |
553 | } | |
554 | GeomAdaptor_Surface GAS(S, Uinf-u,Usup+u,Vinf-v,Vsup+v); | |
555 | Handle(GeomAdaptor_HSurface) GAHS = new GeomAdaptor_HSurface(GAS); | |
556 | myled.Append(E); | |
557 | ||
558 | ProjLib_ComputeApproxOnPolarSurface | |
559 | ProjOnCurve(G2dAHC,G2dAHCBis,G3dAHC,GAHS,Tol); | |
560 | ||
561 | if(ProjOnCurve.IsDone()) { | |
562 | Curve2d = ProjOnCurve.BSpline(); | |
563 | mylcu.Append(ProjOnCurve.Curve2d()); | |
564 | return Standard_True; | |
565 | } | |
566 | else { | |
567 | Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d); | |
568 | mylcu.Append(C2dBis); | |
569 | return Standard_True; | |
570 | } | |
571 | } | |
572 | else { // on est au 2ieme tour | |
573 | C2d = Handle(Geom2d_Curve)::DownCast(itlcu.Value()); | |
574 | Handle(Standard_Type) st = C2d->DynamicType(); | |
575 | if (!(st == STANDARD_TYPE(Geom2d_BSplineCurve)) && | |
576 | !(st == STANDARD_TYPE(Geom2d_BezierCurve))) { | |
577 | return Standard_False; | |
578 | } | |
579 | Curve2d = Geom2dConvert::CurveToBSplineCurve(C2d); | |
580 | return Standard_True; | |
581 | } | |
582 | } | |
583 | Curve2d = C2d; | |
584 | return Standard_True; | |
585 | } | |
586 | ||
587 | //======================================================================= | |
588 | //function : NewParameter | |
589 | //purpose : | |
590 | //======================================================================= | |
591 | ||
592 | Standard_Boolean BRepTools_NurbsConvertModification::NewParameter | |
593 | (const TopoDS_Vertex& V, | |
594 | const TopoDS_Edge& E, | |
595 | Standard_Real& P, | |
596 | Standard_Real& Tol) | |
597 | { | |
598 | if(BRep_Tool::Degenerated(E)) | |
599 | return Standard_False; | |
600 | Standard_Real f, l, param = BRep_Tool::Parameter(V,E); | |
601 | TopLoc_Location L; | |
602 | ||
603 | Handle(Geom_Curve) gc = BRep_Tool::Curve(E, L, f, l); | |
604 | if(!myMap.Contains(gc)) | |
605 | return Standard_False; | |
606 | ||
607 | Handle(Geom_BSplineCurve) gcc = | |
608 | Handle(Geom_BSplineCurve)::DownCast(myMap.FindFromKey(gc)); | |
609 | ||
610 | gcc = Handle(Geom_BSplineCurve)::DownCast(gcc->Transformed(L.Transformation())); | |
611 | ||
612 | GeomAdaptor_Curve ac(gcc); | |
613 | gp_Pnt pnt = BRep_Tool::Pnt(V); | |
614 | ||
615 | Extrema_LocateExtPC proj(pnt, ac, param, f, l, Tol); | |
616 | if(proj.IsDone()) { | |
617 | Standard_Real Dist2Min = proj.SquareDistance(); | |
618 | if (Dist2Min < Tol*Tol) { | |
619 | // Standard_Real U_final_point,V_final_point; | |
620 | P = proj.Point().Parameter(); | |
621 | return Standard_True; | |
622 | } | |
623 | } | |
624 | return Standard_False; | |
625 | } | |
626 | ||
627 | //======================================================================= | |
628 | //function : Continuity | |
629 | //purpose : | |
630 | //======================================================================= | |
631 | ||
632 | GeomAbs_Shape BRepTools_NurbsConvertModification::Continuity | |
633 | (const TopoDS_Edge& E, | |
634 | const TopoDS_Face& F1, | |
635 | const TopoDS_Face& F2, | |
636 | const TopoDS_Edge&, | |
637 | const TopoDS_Face&, | |
638 | const TopoDS_Face&) | |
639 | { | |
640 | return BRep_Tool::Continuity(E,F1,F2); | |
641 | } | |
642 | ||
643 |