Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-12-16 |
2 | // Created by: Isabelle GRIGNON | |
3 | // Copyright (c) 1993-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | |
22 | // modified by ofv - Thu Feb 26 11:18:16 2004 OCC5246 | |
23 | // Modified by skv - Fri Oct 24 14:24:47 2003 OCC4077 | |
24 | // Modified by skv - Mon Jun 16 15:50:44 2003 OCC615 | |
25 | ||
26 | #include <ChFi3d.hxx> | |
27 | #include <Precision.hxx> | |
28 | ||
29 | #include <Standard_NotImplemented.hxx> | |
30 | #include <Standard_ConstructionError.hxx> | |
31 | ||
32 | #include <gp.hxx> | |
33 | #include <gp_Circ.hxx> | |
34 | #include <gp_Elips.hxx> | |
35 | #include <gp_Lin.hxx> | |
36 | #include <gp_Pnt.hxx> | |
37 | #include <gp_Pnt2d.hxx> | |
38 | #include <gp_Lin2d.hxx> | |
39 | #include <ElCLib.hxx> | |
40 | #include <ElSLib.hxx> | |
41 | #include <BSplCLib.hxx> | |
42 | #include <GeomLib.hxx> | |
43 | ||
44 | #include <TColgp_Array1OfPnt2d.hxx> | |
45 | #include <TColgp_Array1OfPnt.hxx> | |
46 | #include <TColgp_Array1OfXYZ.hxx> | |
47 | #include <TColStd_Array1OfInteger.hxx> | |
48 | #include <TColStd_Array1OfReal.hxx> | |
49 | ||
50 | #include <Geom_TrimmedCurve.hxx> | |
51 | #include <Geom_BSplineCurve.hxx> | |
52 | #include <Geom_Surface.hxx> | |
53 | #include <Geom_CylindricalSurface.hxx> | |
54 | #include <Geom_RectangularTrimmedSurface.hxx> | |
55 | #include <Geom_Plane.hxx> | |
56 | #include <Geom_Line.hxx> | |
57 | #include <Geom_Circle.hxx> | |
58 | #include <Geom_Ellipse.hxx> | |
59 | #include <Geom2d_BezierCurve.hxx> | |
60 | #include <Geom2d_BSplineCurve.hxx> | |
61 | #include <Geom2d_Line.hxx> | |
62 | #include <Geom2d_Circle.hxx> | |
63 | #include <Geom2d_Ellipse.hxx> | |
64 | #include <Geom2d_Hyperbola.hxx> | |
65 | #include <Geom2d_Parabola.hxx> | |
66 | #include <Geom2d_TrimmedCurve.hxx> | |
67 | #include <Geom2d_Line.hxx> | |
68 | #include <Geom2d_OffsetCurve.hxx> | |
69 | #include <Geom2dAdaptor_Curve.hxx> | |
70 | #include <Geom2dAdaptor_HCurve.hxx> | |
71 | #include <Adaptor3d_TopolTool.hxx> | |
72 | #include <Adaptor3d_CurveOnSurface.hxx> | |
73 | #include <Adaptor3d_HCurveOnSurface.hxx> | |
74 | #include <GeomAdaptor_HSurface.hxx> | |
75 | ||
76 | #include <FairCurve_Batten.hxx> | |
77 | #include <FairCurve_AnalysisCode.hxx> | |
78 | #include <Convert_ParameterisationType.hxx> | |
79 | #include <GeomConvert_CompCurveToBSplineCurve.hxx> | |
80 | #include <GeomConvert.hxx> | |
81 | #include <GeomLib_Interpolate.hxx> | |
82 | #include <GeomAPI_ProjectPointOnSurf.hxx> | |
83 | #include <GeomAPI_ProjectPointOnCurve.hxx> | |
84 | #include <GC_MakeCircle.hxx> | |
85 | #include <BRepAdaptor_Curve.hxx> | |
86 | #include <BRepAdaptor_HCurve.hxx> | |
87 | #include <BRepAdaptor_HCurve2d.hxx> | |
88 | #include <BRepAdaptor_Surface.hxx> | |
89 | #include <BRepTopAdaptor_HVertex.hxx> | |
90 | ||
91 | #include <BRep_Tool.hxx> | |
92 | #include <BRep_Builder.hxx> | |
93 | #include <BRepTools.hxx> | |
94 | #include <BRepTools_WireExplorer.hxx> | |
95 | #include <BRepLib.hxx> | |
96 | #include <BRepLib_MakeEdge.hxx> | |
97 | #include <BRepLib_MakeWire.hxx> | |
98 | #include <BRepLib_MakeFace.hxx> | |
99 | ||
100 | #include <TopAbs.hxx> | |
101 | #include <TopoDS_Shape.hxx> | |
102 | #include <TopoDS_Edge.hxx> | |
103 | #include <TopoDS_Vertex.hxx> | |
104 | #include <TopoDS_Wire.hxx> | |
105 | #include <TopoDS_Face.hxx> | |
106 | #include <TopExp.hxx> | |
107 | #include <TopExp_Explorer.hxx> | |
108 | #include <TopTools_Array1OfShape.hxx> | |
109 | ||
110 | ||
111 | #include <GeomAbs_Shape.hxx> | |
112 | #include <Bnd_Box2d.hxx> | |
113 | ||
114 | //#include <math_FunctionSample.hxx> | |
115 | //#include <math_FunctionAllRoots.hxx> | |
116 | #include <GCPnts_AbscissaPoint.hxx> | |
117 | ||
118 | #include <IntCurveSurface_TheQuadCurvFuncOfTheQuadCurvExactHInter.hxx> | |
119 | #include <IntCurveSurface_HInter.hxx> | |
120 | #include <IntCurveSurface_IntersectionPoint.hxx> | |
121 | #include <IntSurf_Quadric.hxx> | |
122 | #include <IntSurf_PntOn2S.hxx> | |
123 | #include <IntSurf_LineOn2S.hxx> | |
124 | #include <IntAna_QuadQuadGeo.hxx> | |
125 | #include <IntAna2d_AnaIntersection.hxx> | |
126 | #include <IntRes2d_IntersectionPoint.hxx> | |
127 | #include <IntPatch_ThePWalkingInter.hxx> | |
128 | #include <IntPatch_WLine.hxx> | |
129 | #include <Geom2dInt_GInter.hxx> | |
130 | #include <GeomInt_WLApprox.hxx> | |
131 | #include <GeomInt_IntSS.hxx> | |
132 | #include <AppParCurves_MultiBSpCurve.hxx> | |
133 | #include <Approx_SameParameter.hxx> | |
134 | ||
135 | #include <TopAbs.hxx> | |
136 | #include <TopoDS_Shape.hxx> | |
137 | #include <TopoDS_Edge.hxx> | |
138 | #include <TopExp.hxx> | |
139 | ||
140 | #include <TopOpeBRepDS.hxx> | |
141 | #include <TopOpeBRepDS_Surface.hxx> | |
142 | #include <TopOpeBRepDS_Point.hxx> | |
143 | #include <TopOpeBRepDS_SolidSurfaceInterference.hxx> | |
144 | #include <TopOpeBRepDS_CurvePointInterference.hxx> | |
145 | #include <TopOpeBRepDS_ListOfInterference.hxx> | |
146 | #include <TopOpeBRepDS_InterferenceIterator.hxx> | |
147 | #include <ProjLib_ProjectedCurve.hxx> | |
148 | ||
149 | #include <BRepBlend_PointOnRst.hxx> | |
150 | ||
151 | #include <ChFiDS_HData.hxx> | |
152 | #include <ChFiDS_SurfData.hxx> | |
153 | #include <ChFiDS_FaceInterference.hxx> | |
154 | #include <ChFiDS_Spine.hxx> | |
155 | #include <ChFiDS_FilSpine.hxx> | |
156 | #include <ChFiDS_SequenceOfSurfData.hxx> | |
157 | #include <ChFiDS_Regul.hxx> | |
158 | #include <Law_Function.hxx> | |
159 | #include <Law_Composite.hxx> | |
160 | #include <GeomAPI_PointsToBSpline.hxx> | |
161 | #include <GeomLProp_CLProps.hxx> | |
162 | ||
163 | #include <ChFi3d_Builder_0.hxx> | |
164 | ||
7fd59977 | 165 | #ifdef DEB |
166 | #include <OSD_Chronometer.hxx> | |
167 | extern Standard_Boolean ChFi3d_GetcontextFORCEBLEND(); | |
168 | extern Standard_Boolean ChFi3d_GettraceDRAWINT(); | |
169 | extern Standard_Boolean ChFi3d_GettraceDRAWENLARGE(); | |
170 | extern Standard_Boolean ChFi3d_GettraceDRAWSPINE(); | |
171 | extern Standard_Real t_sameparam, t_batten; | |
172 | extern void ChFi3d_SettraceDRAWINT(const Standard_Boolean b); | |
173 | extern void ChFi3d_SettraceDRAWSPINE(const Standard_Boolean b); | |
174 | extern void ChFi3d_InitChron(OSD_Chronometer& ch); | |
175 | extern void ChFi3d_ResultChron(OSD_Chronometer & ch,Standard_Real& time); | |
176 | #endif | |
177 | ||
178 | #include <stdio.h> | |
179 | ||
180 | #include <GeomAdaptor_HCurve.hxx> | |
181 | #include <BRepAdaptor_HSurface.hxx> | |
182 | ||
065bb8b0 | 183 | //======================================================================= |
184 | //function : ChFi3d_InPeriod | |
185 | //purpose : | |
186 | //======================================================================= | |
7fd59977 | 187 | Standard_Real ChFi3d_InPeriod(const Standard_Real U, |
188 | const Standard_Real UFirst, | |
189 | const Standard_Real ULast, | |
190 | const Standard_Real Eps) | |
191 | { | |
192 | const Standard_Real period = ULast - UFirst; | |
193 | Standard_Real u = U; | |
194 | while (Eps < (UFirst-u)) u += period; | |
195 | while (Eps > (ULast -u)) u -= period; | |
196 | if ( u < UFirst) u = UFirst; | |
197 | return u; | |
198 | } | |
7fd59977 | 199 | //======================================================================= |
81bba717 | 200 | //function : Box |
201 | //purpose : Calculation of min/max uv of the fillet to intersect. | |
7fd59977 | 202 | //======================================================================= |
7fd59977 | 203 | void ChFi3d_Boite(const gp_Pnt2d& p1,const gp_Pnt2d& p2, |
204 | Standard_Real& mu,Standard_Real& Mu, | |
205 | Standard_Real& mv,Standard_Real& Mv) | |
206 | { | |
207 | mu = Min(p1.X(),p2.X()); Mu = Max(p1.X(),p2.X()); | |
208 | mv = Min(p1.Y(),p2.Y()); Mv = Max(p1.Y(),p2.Y()); | |
209 | } | |
7fd59977 | 210 | //======================================================================= |
81bba717 | 211 | //function : Box |
212 | //purpose : Calculation of min/max uv of the fillet to intersect. | |
7fd59977 | 213 | //======================================================================= |
7fd59977 | 214 | void ChFi3d_Boite(const gp_Pnt2d& p1,const gp_Pnt2d& p2, |
215 | const gp_Pnt2d& p3,const gp_Pnt2d& p4, | |
216 | Standard_Real& Du,Standard_Real& Dv, | |
217 | Standard_Real& mu,Standard_Real& Mu, | |
218 | Standard_Real& mv,Standard_Real& Mv) | |
219 | { | |
220 | Standard_Real a,b; | |
221 | a = Min(p1.X(),p2.X()); b = Min(p3.X(),p4.X()); mu = Min(a,b); | |
222 | a = Max(p1.X(),p2.X()); b = Max(p3.X(),p4.X()); Mu = Max(a,b); | |
223 | a = Min(p1.Y(),p2.Y()); b = Min(p3.Y(),p4.Y()); mv = Min(a,b); | |
224 | a = Max(p1.Y(),p2.Y()); b = Max(p3.Y(),p4.Y()); Mv = Max(a,b); | |
225 | Du = Mu - mu; | |
226 | Dv = Mv - mv; | |
227 | } | |
7fd59977 | 228 | //======================================================================= |
81bba717 | 229 | //function : EnlargeBox and its friends. |
7fd59977 | 230 | //purpose : |
231 | //======================================================================= | |
7fd59977 | 232 | static Handle(Adaptor3d_HSurface) Geometry(TopOpeBRepDS_DataStructure& DStr, |
233 | const Standard_Integer ind) | |
234 | { | |
235 | if(ind == 0) return Handle(Adaptor3d_HSurface)(); | |
236 | if(ind > 0) { | |
237 | TopoDS_Face F = TopoDS::Face(DStr.Shape(ind)); | |
238 | if(F.IsNull()) return Handle(Adaptor3d_HSurface)(); | |
239 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(); | |
240 | HS->ChangeSurface().Initialize(F,0); | |
241 | return HS; | |
242 | } | |
243 | else{ | |
244 | Handle(Geom_Surface) S = DStr.Surface(-ind).Surface(); | |
245 | if(S.IsNull()) return Handle(Adaptor3d_HSurface)(); | |
246 | return new GeomAdaptor_HSurface(S); | |
247 | } | |
248 | } | |
065bb8b0 | 249 | //======================================================================= |
250 | //function : ChFi3d_SetPointTolerance | |
251 | //purpose : | |
252 | //======================================================================= | |
7fd59977 | 253 | void ChFi3d_SetPointTolerance(TopOpeBRepDS_DataStructure& DStr, |
254 | const Bnd_Box& box, | |
255 | const Standard_Integer IP) | |
256 | { | |
257 | Standard_Real a,b,c,d,e,f,vtol; | |
258 | box.Get(a,b,c,d,e,f); | |
259 | d-=a; e-=b; f-=c; | |
260 | d*=d; e*=e; f*=f; | |
065bb8b0 | 261 | vtol = sqrt(d + e + f) * 1.5;// on prend un petit rab. |
7fd59977 | 262 | DStr.ChangePoint(IP).Tolerance(vtol); |
263 | } | |
065bb8b0 | 264 | //======================================================================= |
265 | //function : ChFi3d_EnlargeBox | |
266 | //purpose : | |
267 | //======================================================================= | |
7fd59977 | 268 | void ChFi3d_EnlargeBox(const Handle(Geom_Curve)& C, |
269 | const Standard_Real wd, | |
270 | const Standard_Real wf, | |
271 | Bnd_Box& box1, | |
272 | Bnd_Box& box2) | |
273 | { | |
274 | box1.Add(C->Value(wd)); | |
275 | box2.Add(C->Value(wf)); | |
276 | } | |
065bb8b0 | 277 | //======================================================================= |
278 | //function : ChFi3d_EnlargeBox | |
279 | //purpose : | |
280 | //======================================================================= | |
7fd59977 | 281 | void ChFi3d_EnlargeBox(const Handle(Adaptor3d_HSurface)& S, |
282 | const Handle(Geom2d_Curve)& PC, | |
283 | const Standard_Real wd, | |
284 | const Standard_Real wf, | |
285 | Bnd_Box& box1, | |
286 | Bnd_Box& box2) | |
287 | { | |
288 | Standard_Real u,v; | |
289 | PC->Value(wd).Coord(u,v); | |
290 | box1.Add(S->Value(u,v)); | |
291 | PC->Value(wf).Coord(u,v); | |
292 | box2.Add(S->Value(u,v)); | |
293 | } | |
065bb8b0 | 294 | //======================================================================= |
295 | //function : ChFi3d_EnlargeBox | |
296 | //purpose : | |
297 | //======================================================================= | |
7fd59977 | 298 | void ChFi3d_EnlargeBox(const TopoDS_Edge& E, |
299 | const TopTools_ListOfShape& LF, | |
300 | const Standard_Real w, | |
301 | Bnd_Box& box) | |
302 | ||
303 | { | |
304 | BRepAdaptor_Curve BC(E); | |
305 | box.Add(BC.Value(w)); | |
306 | TopTools_ListIteratorOfListOfShape It; | |
307 | for(It.Initialize(LF); It.More(); It.Next()) { | |
308 | TopoDS_Face F = TopoDS::Face(It.Value()); | |
309 | if(!F.IsNull()) { | |
310 | BC.Initialize(E,F); | |
311 | box.Add(BC.Value(w)); | |
312 | } | |
313 | } | |
314 | } | |
065bb8b0 | 315 | //======================================================================= |
316 | //function : ChFi3d_EnlargeBox | |
317 | //purpose : | |
318 | //======================================================================= | |
7fd59977 | 319 | void ChFi3d_EnlargeBox(TopOpeBRepDS_DataStructure& DStr, |
320 | const Handle(ChFiDS_Stripe)& st, | |
321 | const Handle(ChFiDS_SurfData)& sd, | |
322 | Bnd_Box& b1, | |
323 | Bnd_Box& b2, | |
324 | const Standard_Boolean isfirst) | |
325 | { | |
326 | Standard_Real u,v; | |
327 | const ChFiDS_CommonPoint& cp1 = sd->Vertex(isfirst,1); | |
328 | const ChFiDS_CommonPoint& cp2 = sd->Vertex(isfirst,2); | |
329 | b1.Add(cp1.Point()); | |
330 | b2.Add(cp2.Point()); | |
331 | const ChFiDS_FaceInterference& fi1 = sd->InterferenceOnS1(); | |
332 | const ChFiDS_FaceInterference& fi2 = sd->InterferenceOnS2(); | |
333 | const Handle(Geom_Surface)& S = DStr.Surface(sd->Surf()).Surface(); | |
334 | const Handle(Geom2d_Curve)& pcs1 = fi1.PCurveOnSurf(); | |
335 | const Handle(Geom2d_Curve)& pcs2 = fi2.PCurveOnSurf(); | |
336 | const Handle(Geom_Curve)& c3d1 = DStr.Curve(fi1.LineIndex()).Curve(); | |
337 | const Handle(Geom_Curve)& c3d2 = DStr.Curve(fi2.LineIndex()).Curve(); | |
338 | Handle(Adaptor3d_HSurface) F1 = Geometry(DStr,sd->IndexOfS1()); | |
339 | Handle(Adaptor3d_HSurface) F2 = Geometry(DStr,sd->IndexOfS2()); | |
340 | Standard_Real p1 = fi1.Parameter(isfirst); | |
341 | if(!c3d1.IsNull()) b1.Add(c3d1->Value(p1)); | |
342 | if(!pcs1.IsNull()) { | |
343 | pcs1->Value(p1).Coord(u,v); | |
344 | b1.Add(S->Value(u,v)); | |
345 | } | |
346 | if(!F1.IsNull()) { | |
347 | const Handle(Geom2d_Curve)& pcf1 = fi1.PCurveOnFace(); | |
348 | if(!pcf1.IsNull()) { | |
349 | pcf1->Value(p1).Coord(u,v); | |
350 | b1.Add(F1->Value(u,v)); | |
351 | } | |
352 | } | |
353 | Standard_Real p2 = fi2.Parameter(isfirst); | |
354 | if(!c3d2.IsNull()) b2.Add(c3d2->Value(p2)); | |
355 | if(!pcs2.IsNull()) { | |
356 | pcs2->Value(p2).Coord(u,v); | |
357 | b2.Add(S->Value(u,v)); | |
358 | } | |
359 | if(!F2.IsNull()) { | |
360 | const Handle(Geom2d_Curve)& pcf2 = fi2.PCurveOnFace(); | |
361 | if(!pcf2.IsNull()) { | |
362 | pcf2->Value(p2).Coord(u,v); | |
363 | b2.Add(F2->Value(u,v)); | |
364 | } | |
365 | } | |
366 | if(!st.IsNull()) { | |
367 | const Handle(Geom_Curve)& c3d = DStr.Curve(st->Curve(isfirst)).Curve(); | |
368 | const Handle(Geom2d_Curve)& c2d = st->PCurve(isfirst); | |
369 | if(st->Orientation(isfirst) == TopAbs_FORWARD) st->Parameters(isfirst,p1,p2); | |
370 | else st->Parameters(isfirst,p2,p1); | |
371 | if(!c3d.IsNull()) { | |
372 | b1.Add(c3d->Value(p1)); | |
373 | b2.Add(c3d->Value(p2)); | |
374 | } | |
375 | if(!c2d.IsNull()) { | |
376 | c2d->Value(p1).Coord(u,v); | |
377 | b1.Add(S->Value(u,v)); | |
378 | c2d->Value(p2).Coord(u,v); | |
379 | b2.Add(S->Value(u,v)); | |
380 | } | |
381 | } | |
382 | } | |
7fd59977 | 383 | //======================================================================= |
384 | //function : conexfaces | |
385 | //purpose : | |
386 | //======================================================================= | |
7fd59977 | 387 | void ChFi3d_conexfaces(const TopoDS_Edge& E, |
388 | TopoDS_Face& F1, | |
389 | TopoDS_Face& F2, | |
390 | const ChFiDS_Map& EFMap) | |
391 | { | |
392 | TopTools_ListIteratorOfListOfShape It; | |
393 | F1.Nullify(); | |
394 | F2.Nullify(); | |
395 | for(It.Initialize(EFMap(E));It.More();It.Next()) { | |
396 | if (F1.IsNull()) { | |
397 | F1 = TopoDS::Face(It.Value()); | |
398 | } | |
399 | else { | |
400 | F2 = TopoDS::Face(It.Value()); | |
401 | if(!F2.IsSame(F1) || BRep_Tool::IsClosed(E,F1)) { | |
402 | break; | |
403 | } | |
404 | else F2.Nullify(); | |
405 | } | |
406 | } | |
407 | } | |
7fd59977 | 408 | //======================================================================= |
409 | //function : EdgeState | |
81bba717 | 410 | //purpose : check concavities for the tops with 3 edges. |
7fd59977 | 411 | //======================================================================= |
7fd59977 | 412 | ChFiDS_State ChFi3d_EdgeState(TopoDS_Edge* E, |
413 | const ChFiDS_Map& EFMap) | |
414 | { | |
415 | ChFiDS_State sst; | |
416 | Standard_Integer i,j; | |
417 | TopoDS_Face F[3]; | |
418 | TopoDS_Face F1,F2,F3,F4,F5,F6; | |
419 | ChFi3d_conexfaces(E[0],F1,F2,EFMap); | |
420 | ChFi3d_conexfaces(E[1],F3,F4,EFMap); | |
421 | ChFi3d_conexfaces(E[2],F5,F6,EFMap); | |
422 | if(F1.IsSame(F2)) { | |
423 | F[0] = F[1] = F1; | |
424 | if(F1.IsSame(F3)) F[2] = F4; | |
425 | else F[2] = F3; | |
426 | } | |
427 | else if(F3.IsSame(F4)) { | |
428 | F[0] = F[2] = F3; | |
429 | if(F3.IsSame(F1)) F[1] = F2; | |
430 | else F[1] = F1; | |
431 | } | |
432 | else if(F5.IsSame(F6)) { | |
433 | F[1] = F[2] = F5; | |
434 | if(F5.IsSame(F1)) F[0] = F2; | |
435 | else F[0] = F1; | |
436 | } | |
437 | else{ | |
438 | if(F1.IsSame(F3) || F1.IsSame(F4)) F[0] = F1; | |
439 | else F[0] = F2; | |
440 | if(F3.IsSame(F[0])) F[2] = F4; | |
441 | else F[2] = F3; | |
442 | if(F5.IsSame(F[2])) F[1] = F6; | |
443 | else F[1] = F5; | |
444 | ||
445 | } | |
446 | ||
447 | if(F[0].IsNull() || F[1].IsNull() || F[2].IsNull()) sst = ChFiDS_FreeBoundary; | |
448 | else{ | |
449 | TopAbs_Orientation o01,o02,o11,o12,o21,o22; | |
450 | i=ChFi3d::ConcaveSide(F[0],F[1],E[0],o01,o02); | |
451 | i=ChFi3d::ConcaveSide(F[0],F[2],E[1],o11,o12); | |
452 | j=ChFi3d::ConcaveSide(F[1],F[2],E[2],o21,o22); | |
453 | if(o01==o11 && o02==o21 && o12==o22) sst = ChFiDS_AllSame; | |
454 | else if(o12==o22 || i ==10 || j ==10) sst = ChFiDS_OnDiff; | |
455 | else sst = ChFiDS_OnSame; | |
456 | } | |
457 | return sst; | |
458 | } | |
7fd59977 | 459 | //======================================================================= |
460 | //function : evalconti | |
81bba717 | 461 | //purpose : Method very fast to code regularities CN. It is necessary to |
462 | // refine the processing. | |
7fd59977 | 463 | //======================================================================= |
7fd59977 | 464 | GeomAbs_Shape ChFi3d_evalconti(const TopoDS_Edge& /*E*/, |
465 | const TopoDS_Face& F1, | |
466 | const TopoDS_Face& F2) | |
467 | { | |
468 | GeomAbs_Shape cont = GeomAbs_G1; | |
469 | if(!F1.IsSame(F2)) return cont; | |
470 | TopoDS_Face F = F1; | |
471 | F.Orientation(TopAbs_FORWARD); | |
472 | BRepAdaptor_Surface S(F,Standard_False); | |
473 | GeomAbs_SurfaceType typ = S.GetType(); | |
474 | if(typ != GeomAbs_Cone && | |
475 | typ != GeomAbs_Sphere && | |
476 | typ != GeomAbs_Torus) return cont; | |
477 | return GeomAbs_CN; | |
478 | } | |
065bb8b0 | 479 | //modified by NIZNHY-PKV Wed Dec 15 11:22:35 2010f |
7fd59977 | 480 | //======================================================================= |
481 | //function : KParticular | |
482 | //purpose : | |
483 | //======================================================================= | |
065bb8b0 | 484 | Standard_Boolean ChFi3d_KParticular (const Handle(ChFiDS_Spine)& Spine, |
485 | const Standard_Integer IE, | |
486 | const BRepAdaptor_Surface& S1, | |
487 | const BRepAdaptor_Surface& S2) | |
7fd59977 | 488 | { |
065bb8b0 | 489 | Standard_Boolean bRet; |
490 | // | |
491 | bRet=Standard_True; | |
492 | // | |
7fd59977 | 493 | Handle(ChFiDS_FilSpine) fs = Handle(ChFiDS_FilSpine)::DownCast(Spine); |
065bb8b0 | 494 | if(!fs.IsNull() && !fs->IsConstant(IE)) { |
495 | return !bRet; | |
496 | } | |
497 | // | |
498 | Standard_Boolean bIsPlane1, bIsPlane2; | |
499 | Standard_Real aPA; | |
500 | GeomAbs_CurveType aCT; | |
501 | GeomAbs_SurfaceType aST1, aST2; | |
502 | // | |
503 | aST1=S1.GetType(); | |
504 | aST2=S2.GetType(); | |
505 | bIsPlane1=(aST1==GeomAbs_Plane); | |
506 | bIsPlane2=(aST2==GeomAbs_Plane); | |
507 | if (!(bIsPlane1 || bIsPlane2)) { | |
508 | return !bRet; | |
509 | } | |
510 | // | |
511 | const BRepAdaptor_Surface& aS1=(bIsPlane1)? S1 : S2; | |
512 | const BRepAdaptor_Surface& aS2=(bIsPlane1)? S2 : S1; | |
513 | aST1=aS1.GetType(); | |
514 | aST2=aS2.GetType(); | |
515 | // | |
516 | if (!(aST2==GeomAbs_Plane || aST2==GeomAbs_Cylinder || aST2==GeomAbs_Cone)) { | |
517 | return !bRet; | |
518 | } | |
519 | // | |
7fd59977 | 520 | const BRepAdaptor_Curve& bc = Spine->CurrentElementarySpine(IE); |
065bb8b0 | 521 | aCT = bc.GetType(); |
522 | if (!(aCT==GeomAbs_Line || aCT==GeomAbs_Circle)) { | |
523 | return !bRet; | |
524 | } | |
525 | // | |
526 | aPA=Precision::Angular(); | |
527 | // | |
528 | if (aST2==GeomAbs_Plane){ | |
529 | if (aCT==GeomAbs_Line) { | |
530 | return bRet; | |
7fd59977 | 531 | } |
065bb8b0 | 532 | } |
533 | else if (aST2==GeomAbs_Cylinder) { | |
534 | const gp_Dir& aD1=aS1.Plane().Axis().Direction(); | |
535 | const gp_Dir& aD2=aS2.Cylinder().Axis().Direction(); | |
536 | // | |
537 | if (aCT==GeomAbs_Line && aD1.IsNormal(aD2, aPA)) { | |
538 | return bRet; | |
7fd59977 | 539 | } |
065bb8b0 | 540 | else if (aCT==GeomAbs_Circle && aD1.IsParallel(aD2, aPA)) { |
541 | return bRet; | |
7fd59977 | 542 | } |
7fd59977 | 543 | } |
065bb8b0 | 544 | else if(aST2==GeomAbs_Cone) { |
545 | const gp_Dir& aD1=aS1.Plane().Axis().Direction(); | |
546 | const gp_Dir& aD2=aS2.Cone().Axis().Direction(); | |
547 | if (aCT == GeomAbs_Circle && aD1.IsParallel(aD2, aPA)) { | |
548 | return bRet; | |
549 | } | |
550 | } | |
551 | return !bRet; | |
7fd59977 | 552 | } |
065bb8b0 | 553 | //modified by NIZNHY-PKV Wed Dec 15 11:22:43 2010t |
7fd59977 | 554 | //======================================================================= |
555 | //function : BoundFac | |
81bba717 | 556 | //purpose : Resize the limits of surface adjacent to the given box |
557 | // Useful for intersections with known extremities. | |
7fd59977 | 558 | //======================================================================= |
7fd59977 | 559 | void ChFi3d_BoundFac(BRepAdaptor_Surface& S, |
560 | const Standard_Real uumin, | |
561 | const Standard_Real uumax, | |
562 | const Standard_Real vvmin, | |
563 | const Standard_Real vvmax, | |
564 | const Standard_Boolean checknaturalbounds) | |
565 | { | |
566 | ChFi3d_BoundSrf(S.ChangeSurface(), uumin,uumax,vvmin,vvmax,checknaturalbounds); | |
567 | } | |
568 | //======================================================================= | |
569 | //function : ChFi3d_BoundSrf | |
81bba717 | 570 | //purpose : Resize the limits of surface adjacent to the given box |
571 | // Useful for intersections with known extremities. | |
7fd59977 | 572 | //======================================================================= |
7fd59977 | 573 | void ChFi3d_BoundSrf(GeomAdaptor_Surface& S, |
574 | const Standard_Real uumin, | |
575 | const Standard_Real uumax, | |
576 | const Standard_Real vvmin, | |
577 | const Standard_Real vvmax, | |
578 | const Standard_Boolean checknaturalbounds) | |
579 | { | |
580 | Standard_Real umin = uumin, umax = uumax, vmin = vvmin, vmax = vvmax; | |
581 | Handle(Geom_Surface) surface = S.Surface(); | |
582 | Handle(Geom_RectangularTrimmedSurface) | |
583 | trs = Handle(Geom_RectangularTrimmedSurface)::DownCast(surface); | |
584 | if(!trs.IsNull()) surface = trs->BasisSurface(); | |
585 | Standard_Real u1,u2,v1,v2; | |
586 | surface->Bounds(u1,u2,v1,v2); | |
587 | Standard_Real peru=0, perv=0; | |
588 | if(surface->IsUPeriodic()) { | |
589 | peru = surface->UPeriod(); | |
7fd59977 | 590 | } |
591 | if(surface->IsVPeriodic()) { | |
592 | perv = surface->VPeriod(); | |
7fd59977 | 593 | } |
594 | Standard_Real Stepu = umax - umin; | |
595 | Standard_Real Stepv = vmax - vmin; | |
596 | ||
81bba717 | 597 | //It is supposed that box uv is not null in at least |
598 | //one direction. | |
7fd59977 | 599 | Standard_Real scalu = S.UResolution(1.); |
600 | Standard_Real scalv = S.VResolution(1.); | |
601 | ||
602 | Standard_Real step3du = Stepu/scalu; | |
603 | Standard_Real step3dv = Stepv/scalv; | |
604 | ||
605 | if(step3du > step3dv) Stepv = step3du*scalv; | |
606 | if(step3dv > step3du) Stepu = step3dv*scalu; | |
607 | ||
608 | if (peru > 0) Stepu = 0.1 * (peru - (umax - umin)); | |
609 | if (perv > 0) Stepv = 0.1 * (perv - (vmax - vmin)); | |
610 | ||
611 | Standard_Real uu1 = umin - Stepu; | |
612 | Standard_Real uu2 = umax + Stepu; | |
613 | Standard_Real vv1 = vmin - Stepv; | |
614 | Standard_Real vv2 = vmax + Stepv; | |
615 | if(checknaturalbounds) { | |
616 | if(!S.IsUPeriodic()) {uu1 = Max(uu1,u1); uu2 = Min(uu2,u2);} | |
617 | if(!S.IsVPeriodic()) {vv1 = Max(vv1,v1); vv2 = Min(vv2,v2);} | |
618 | } | |
619 | S.Load(surface,uu1,uu2,vv1,vv2); | |
620 | } | |
7fd59977 | 621 | //======================================================================= |
622 | //function : ChFi3d_InterPlaneEdge | |
623 | //purpose : | |
624 | //======================================================================= | |
7fd59977 | 625 | Standard_Boolean ChFi3d_InterPlaneEdge (Handle(Adaptor3d_HSurface)& Plan, |
626 | Handle(Adaptor3d_HCurve)& C, | |
627 | Standard_Real& W, | |
628 | const Standard_Boolean Sens, | |
629 | const Standard_Real tolc) | |
630 | { | |
631 | IntCurveSurface_HInter Intersection; | |
632 | Standard_Integer isol = 0, nbp ,iip; | |
633 | Standard_Real uf = C->FirstParameter(),ul = C->LastParameter(); | |
634 | Standard_Real CW; | |
635 | ||
636 | Intersection.Perform(C,Plan); | |
637 | ||
638 | if(Intersection.IsDone()) { | |
639 | nbp = Intersection.NbPoints(); | |
640 | for (iip = 1; iip <= nbp; iip++) { | |
641 | CW = Intersection.Point(iip).W(); | |
642 | if(C->IsPeriodic()) | |
643 | CW = ElCLib::InPeriod(CW,uf-tolc,uf-tolc+C->Period()); | |
644 | if(uf - tolc <= CW && ul + tolc >= CW) { | |
645 | if (isol == 0) { | |
646 | isol = iip; W = CW; | |
647 | } | |
648 | else { | |
065bb8b0 | 649 | if ( Sens && CW < W) { |
650 | W = CW; isol = iip; | |
651 | } | |
652 | else if (!Sens && CW > W) { | |
653 | W = CW; isol = iip; | |
654 | } | |
7fd59977 | 655 | } |
656 | } | |
657 | } | |
658 | } | |
659 | if(isol == 0) return Standard_False; | |
660 | return Standard_True; | |
661 | } | |
7fd59977 | 662 | //======================================================================= |
663 | //function : ExtrSpineCarac | |
664 | //purpose : | |
665 | //======================================================================= | |
7fd59977 | 666 | void ChFi3d_ExtrSpineCarac(const TopOpeBRepDS_DataStructure& DStr, |
667 | const Handle(ChFiDS_Stripe)& cd, | |
668 | const Standard_Integer i, | |
669 | const Standard_Real p, | |
670 | const Standard_Integer jf, | |
671 | const Standard_Integer sens, | |
672 | gp_Pnt& P, | |
673 | gp_Vec& V, | |
81bba717 | 674 | Standard_Real& R) //check if it is necessary to add D1,D2 and DR |
7fd59977 | 675 | { |
81bba717 | 676 | // Attention for approximated surfaces it is assumed that e |
677 | // the parameters of the pcurve are the same as of | |
678 | // elspine used for its construction. | |
7fd59977 | 679 | const Handle(Geom_Surface)& fffil = |
680 | DStr.Surface(cd->SetOfSurfData()->Value(i)->Surf()).Surface(); | |
681 | gp_Pnt2d pp = cd->SetOfSurfData()->Value(i)->Interference(jf). | |
682 | PCurveOnSurf()->Value(p); | |
683 | GeomAdaptor_Surface gs(fffil); | |
684 | P = fffil->Value(pp.X(),pp.Y()); | |
685 | gp_Pnt Pbid; gp_Vec Vbid; | |
686 | switch (gs.GetType()) { | |
687 | case GeomAbs_Cylinder : | |
688 | { | |
689 | gp_Cylinder cyl = gs.Cylinder(); | |
690 | R = cyl.Radius(); | |
691 | ElSLib::D1(pp.X(),pp.Y(),cyl,Pbid,Vbid,V); | |
692 | } | |
693 | break; | |
694 | case GeomAbs_Torus : | |
695 | { | |
696 | gp_Torus tor = gs.Torus(); | |
697 | R = tor.MinorRadius(); | |
698 | ElSLib::D1(pp.X(),pp.Y(),tor,Pbid,V,Vbid); | |
699 | } | |
700 | break; | |
701 | default: | |
702 | { Standard_Integer nbelspine; | |
703 | const Handle(ChFiDS_Spine)& sp = cd->Spine(); | |
704 | Handle(ChFiDS_FilSpine) fsp = Handle(ChFiDS_FilSpine)::DownCast(sp); | |
705 | nbelspine=sp->NbEdges(); | |
706 | Handle(ChFiDS_HElSpine) hels; | |
707 | if (nbelspine==1) hels = sp->ElSpine(1); | |
708 | else hels = sp->ElSpine(p); | |
709 | if(fsp->IsConstant()) { R = fsp->Radius(); } | |
710 | else { R = fsp->Law(hels)->Value(p); } | |
711 | hels->D1(p,Pbid,V); | |
712 | } | |
713 | break; | |
714 | } | |
715 | V.Normalize(); | |
716 | if(sens == 1) V.Reverse(); | |
717 | } | |
7fd59977 | 718 | //======================================================================= |
719 | //function : ChFi3d_CircularSpine | |
81bba717 | 720 | //purpose : Calculate a cicular guideline for the corner created from |
721 | // tangent points and vectors calculated at the extremities | |
722 | // of guidelines of start and end fillets. | |
7fd59977 | 723 | //======================================================================= |
724 | Handle(Geom_Circle) ChFi3d_CircularSpine(Standard_Real& WFirst, | |
725 | Standard_Real& WLast, | |
726 | const gp_Pnt& Pdeb, | |
727 | const gp_Vec& Vdeb, | |
728 | const gp_Pnt& Pfin, | |
729 | const gp_Vec& Vfin, | |
730 | const Standard_Real rad) | |
731 | { | |
732 | gp_Circ ccc; | |
733 | gp_Pln Pl1(Pdeb,gp_Dir(Vdeb)),Pl2(Pfin,gp_Dir(Vfin)); | |
734 | IntAna_QuadQuadGeo LInt (Pl1,Pl2,Precision::Angular(), | |
735 | Precision::Confusion()); | |
736 | gp_Lin li; | |
737 | if (LInt.IsDone()) { | |
738 | li = LInt.Line(1); | |
739 | gp_Pnt cendeb = ElCLib::Value(ElCLib::Parameter(li,Pdeb),li); | |
740 | gp_Pnt cenfin = ElCLib::Value(ElCLib::Parameter(li,Pfin),li); | |
741 | gp_Vec vvdeb(cendeb,Pdeb); | |
742 | gp_Vec vvfin(cenfin,Pfin); | |
743 | gp_Dir dddeb(vvdeb); | |
744 | gp_Dir ddfin(vvfin); | |
745 | if(Vdeb.Crossed(vvdeb).Dot(Vfin.Crossed(vvfin)) > 0.) { | |
746 | return Handle(Geom_Circle)(); | |
747 | } | |
748 | gp_Ax2 circax2(cendeb,dddeb^ddfin,dddeb); | |
749 | ccc.SetPosition(circax2); | |
750 | ccc.SetRadius(rad); | |
751 | WFirst = 0.; | |
752 | WLast = dddeb.Angle(ddfin); | |
753 | return new Geom_Circle(ccc); | |
754 | } | |
065bb8b0 | 755 | |
7fd59977 | 756 | return Handle(Geom_Circle)(); |
757 | } | |
7fd59977 | 758 | //======================================================================= |
759 | //function : ChFi3d_Spine | |
81bba717 | 760 | //purpose : Calculates the poles of the guideline for the corner from |
761 | // tangent points and vectors calculated at the extremities of | |
762 | // guidelines of start and end fillets. | |
7fd59977 | 763 | //======================================================================= |
7fd59977 | 764 | Handle(Geom_BezierCurve) ChFi3d_Spine(const gp_Pnt& pd, |
765 | gp_Vec& vd, | |
766 | const gp_Pnt& pf, | |
767 | gp_Vec& vf, | |
768 | const Standard_Real R) | |
769 | { | |
770 | TColgp_Array1OfPnt pol(1,4); | |
c6541a0c | 771 | const Standard_Real fac = 0.5 * tan((M_PI-vd.Angle(vf)) * 0.5); |
7fd59977 | 772 | pol(1) = pd; |
773 | vd.Multiply(fac*R); | |
774 | pol(2).SetCoord(pd.X()+vd.X(),pd.Y()+vd.Y(),pd.Z()+vd.Z()); | |
775 | pol(4) = pf; | |
776 | vf.Multiply(fac*R); | |
777 | pol(3).SetCoord(pf.X()+vf.X(),pf.Y()+vf.Y(),pf.Z()+vf.Z()); | |
778 | return new Geom_BezierCurve(pol); | |
779 | } | |
7fd59977 | 780 | //======================================================================= |
781 | //function : IsInFront | |
81bba717 | 782 | //purpose : Checks if surfdata i1 and i2 are face to face |
7fd59977 | 783 | //======================================================================= |
7fd59977 | 784 | Standard_Boolean ChFi3d_IsInFront(TopOpeBRepDS_DataStructure& DStr, |
785 | const Handle(ChFiDS_Stripe)& cd1, | |
786 | const Handle(ChFiDS_Stripe)& cd2, | |
787 | const Standard_Integer i1, | |
788 | const Standard_Integer i2, | |
789 | const Standard_Integer sens1, | |
790 | const Standard_Integer sens2, | |
791 | Standard_Real& p1, | |
792 | Standard_Real& p2, | |
793 | TopoDS_Face& face, | |
794 | Standard_Boolean& sameside, | |
795 | Standard_Integer& jf1, | |
796 | Standard_Integer& jf2, | |
797 | Standard_Boolean& visavis, | |
798 | const TopoDS_Vertex& Vtx, | |
799 | const Standard_Boolean Check2dDistance, | |
800 | const Standard_Boolean enlarge) | |
801 | { | |
802 | Standard_Boolean isf1 = (sens1 == 1), isf2 = (sens2 == 1); | |
803 | const Handle(ChFiDS_SurfData)& fd1 = cd1->SetOfSurfData()->Value(i1); | |
804 | const Handle(ChFiDS_SurfData)& fd2 = cd2->SetOfSurfData()->Value(i2); | |
805 | ||
806 | TopAbs_Orientation Or,OrSave1,OrSave2,OrFace1,OrFace2; | |
807 | visavis = Standard_False; | |
808 | Standard_Real u1 = 0.,u2 = 0.; | |
809 | Standard_Boolean ss = 0,ok = 0; | |
810 | Standard_Integer j1 = 0,j2 = 0; | |
811 | TopoDS_Face ff; | |
812 | if(fd1->IndexOfS1() == fd2->IndexOfS1()) { | |
813 | jf1 = 1; jf2 = 1; | |
814 | face = TopoDS::Face(DStr.Shape(fd1->Index(jf1))); | |
815 | OrSave1 = cd1->Orientation(jf1); | |
816 | Or = OrFace1 = face.Orientation(); | |
817 | OrSave2 = cd2->Orientation(jf2); | |
818 | OrFace2 = DStr.Shape(fd2->Index(jf2)).Orientation(); | |
819 | visavis = Standard_True; | |
820 | sameside = ChFi3d::SameSide(Or,OrSave1,OrSave2,OrFace1,OrFace2); | |
81bba717 | 821 | // The parameters of the other side are not used for orientation. This would raise problems |
7fd59977 | 822 | Standard_Integer kf1 = jf1, kf2 = jf2; |
823 | Standard_Real pref1 = fd1->Interference(kf1).Parameter(isf1); | |
824 | Standard_Real pref2 = fd2->Interference(kf2).Parameter(isf2); | |
825 | gp_Pnt2d P2d; | |
826 | if (Check2dDistance) | |
827 | P2d = BRep_Tool::Parameters( Vtx, face ); | |
828 | if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,fd2,pref2,p2,jf2,sens2,P2d,Check2dDistance,enlarge)) { | |
829 | u1 = p1; u2 = p2; ss = sameside; j1 = jf1; j2 = jf2; ff = face; | |
830 | ok = 1; | |
831 | } | |
832 | } | |
833 | if(fd1->IndexOfS2() == fd2->IndexOfS1()) { | |
834 | jf1 = 2; jf2 = 1; | |
835 | face = TopoDS::Face(DStr.Shape(fd1->Index(jf1))); | |
836 | OrSave1 = cd1->Orientation(jf1); | |
837 | Or = OrFace1 = face.Orientation(); | |
838 | OrSave2 = cd2->Orientation(jf2); | |
839 | OrFace2 = DStr.Shape(fd2->Index(jf2)).Orientation(); | |
840 | visavis = Standard_True; | |
841 | sameside = ChFi3d::SameSide(Or,OrSave1,OrSave2,OrFace1,OrFace2); | |
81bba717 | 842 | // The parameters of the other side are not used for orientation. This would raise problems |
7fd59977 | 843 | Standard_Integer kf1 = jf1, kf2 = jf2; |
844 | Standard_Real pref1 = fd1->Interference(kf1).Parameter(isf1); | |
845 | Standard_Real pref2 = fd2->Interference(kf2).Parameter(isf2); | |
846 | gp_Pnt2d P2d; | |
847 | if (Check2dDistance) | |
848 | P2d = BRep_Tool::Parameters( Vtx, face ); | |
849 | if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,fd2,pref2,p2,jf2,sens2,P2d,Check2dDistance,enlarge)) { | |
850 | Standard_Boolean restore = | |
851 | ok && ((j1 == jf1 && sens1*(p1 - u1) > 0.) || | |
852 | (j2 == jf2 && sens2*(p2 - u2) > 0.)); | |
853 | ok = 1; | |
854 | if(restore) { | |
855 | p1 = u1; p2 = u2; sameside = ss; jf1 = j1; jf2 = j2; face = ff; | |
856 | } | |
857 | else { | |
858 | u1 = p1; u2 = p2; ss = sameside; j1 = jf1; j2 = jf2; ff = face; | |
859 | } | |
860 | } | |
81bba717 | 861 | //the re-initialization is added in case p1,... take wrong values |
7fd59977 | 862 | else if (ok) { |
863 | p1 = u1; p2 = u2; sameside = ss; jf1 = j1; jf2 = j2; face = ff; | |
864 | } | |
865 | } | |
866 | if(fd1->IndexOfS1() == fd2->IndexOfS2()) { | |
867 | jf1 = 1; jf2 = 2; | |
868 | face = TopoDS::Face(DStr.Shape(fd1->Index(jf1))); | |
869 | OrSave1 = cd1->Orientation(jf1); | |
870 | Or = OrFace1 = face.Orientation(); | |
871 | OrSave2 = cd2->Orientation(jf2); | |
872 | OrFace2 = DStr.Shape(fd2->Index(jf2)).Orientation(); | |
873 | visavis = Standard_True; | |
874 | sameside = ChFi3d::SameSide(Or,OrSave1,OrSave2,OrFace1,OrFace2); | |
81bba717 | 875 | // The parameters of the other side are not used for orientation. |
7fd59977 | 876 | Standard_Integer kf1 = jf1, kf2 = jf2; |
877 | Standard_Real pref1 = fd1->Interference(kf1).Parameter(isf1); | |
878 | Standard_Real pref2 = fd2->Interference(kf2).Parameter(isf2); | |
879 | gp_Pnt2d P2d; | |
880 | if (Check2dDistance) | |
881 | P2d = BRep_Tool::Parameters( Vtx, face ); | |
882 | if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,fd2,pref2,p2,jf2,sens2,P2d,Check2dDistance,enlarge)) { | |
883 | Standard_Boolean restore = | |
884 | ok && ((j1 == jf1 && sens1*(p1 - u1) > 0.) || | |
885 | (j2 == jf2 && sens2*(p2 - u2) > 0.)); | |
886 | ok = 1; | |
887 | if(restore) { | |
888 | p1 = u1; p2 = u2; sameside = ss; jf1 = j1; jf2 = j2; face = ff; | |
889 | } | |
890 | else { | |
891 | u1 = p1; u2 = p2; ss = sameside; j1 = jf1; j2 = jf2; ff = face; | |
892 | } | |
893 | } | |
81bba717 | 894 | //the re-initialization is added in case p1,... take wrong values |
7fd59977 | 895 | else if (ok) { |
896 | p1 = u1; p2 = u2; sameside = ss; jf1 = j1; jf2 = j2; face = ff; | |
897 | } | |
898 | } | |
899 | if(fd1->IndexOfS2() == fd2->IndexOfS2()) { | |
900 | jf1 = 2; jf2 = 2; | |
901 | face = TopoDS::Face(DStr.Shape(fd1->Index(jf1))); | |
902 | OrSave1 = cd1->Orientation(jf1); | |
903 | Or = OrFace1 = face.Orientation(); | |
904 | OrSave2 = cd2->Orientation(jf2); | |
905 | OrFace2 = DStr.Shape(fd2->Index(jf2)).Orientation(); | |
906 | visavis = Standard_True; | |
907 | sameside = ChFi3d::SameSide(Or,OrSave1,OrSave2,OrFace1,OrFace2); | |
81bba717 | 908 | // The parameters of the other side are not used for orientation. |
7fd59977 | 909 | Standard_Integer kf1 = jf1, kf2 = jf2; |
910 | Standard_Real pref1 = fd1->Interference(kf1).Parameter(isf1); | |
911 | Standard_Real pref2 = fd2->Interference(kf2).Parameter(isf2); | |
912 | gp_Pnt2d P2d; | |
913 | if (Check2dDistance) | |
914 | P2d = BRep_Tool::Parameters( Vtx, face ); | |
915 | if(ChFi3d_IntTraces(fd1,pref1,p1,jf1,sens1,fd2,pref2,p2,jf2,sens2,P2d,Check2dDistance,enlarge)) { | |
916 | Standard_Boolean restore = | |
917 | ok && ((j1 == jf1 && sens1*(p1 - u1) > 0.) || | |
918 | (j2 == jf2 && sens2*(p2 - u2) > 0.)); | |
919 | ok = 1; | |
920 | if(restore) { | |
921 | p1 = u1; p2 = u2; sameside = ss; jf1 = j1; jf2 = j2; face = ff; | |
922 | } | |
923 | else { | |
924 | u1 = p1; u2 = p2; ss = sameside; j1 = jf1; j2 = jf2; ff = face; | |
925 | } | |
926 | } | |
81bba717 | 927 | //the re-initialization is added in case p1,... take wrong values |
7fd59977 | 928 | else if (ok) { |
929 | p1 = u1; p2 = u2; sameside = ss; jf1 = j1; jf2 = j2; face = ff; | |
930 | } | |
931 | } | |
932 | return ok; | |
7fd59977 | 933 | } |
065bb8b0 | 934 | //======================================================================= |
935 | //function : recadre | |
936 | //purpose : | |
937 | //======================================================================= | |
7fd59977 | 938 | static Standard_Real recadre(const Standard_Real p, |
939 | const Standard_Real ref, | |
940 | const Standard_Integer sens, | |
941 | const Standard_Real first, | |
942 | const Standard_Real last) | |
943 | { | |
944 | const Standard_Real pp = p + (sens > 0 ? (first - last) : (last - first)); | |
945 | return ((Abs(pp - ref) < Abs(p - ref))? pp : p); | |
946 | } | |
065bb8b0 | 947 | //======================================================================= |
948 | //function : ChFi3d_IntTraces | |
949 | //purpose : | |
950 | //======================================================================= | |
7fd59977 | 951 | Standard_Boolean ChFi3d_IntTraces(const Handle(ChFiDS_SurfData)& fd1, |
952 | const Standard_Real pref1, | |
953 | Standard_Real& p1, | |
954 | const Standard_Integer jf1, | |
955 | const Standard_Integer sens1, | |
956 | const Handle(ChFiDS_SurfData)& fd2, | |
957 | const Standard_Real pref2, | |
958 | Standard_Real& p2, | |
959 | const Standard_Integer jf2, | |
960 | const Standard_Integer sens2, | |
961 | const gp_Pnt2d& RefP2d, | |
962 | const Standard_Boolean Check2dDistance, | |
963 | const Standard_Boolean enlarge) | |
964 | { | |
965 | Geom2dAdaptor_Curve C1; | |
966 | Geom2dAdaptor_Curve C2; | |
81bba717 | 967 | // pcurves are enlarged to be sure that there is intersection |
968 | // additionally all periodic curves are taken and points on | |
969 | // them are filtered using a specific criterion. | |
7fd59977 | 970 | |
971 | Standard_Real first,last,delta = 0.; | |
972 | first = fd1->Interference(jf1).FirstParameter(); | |
973 | last = fd1->Interference(jf1).LastParameter(); | |
974 | if ((last-first) < Precision::PConfusion()) | |
975 | return Standard_False; | |
976 | if(enlarge) delta = Min(0.1,0.05*(last-first)); | |
977 | Handle(Geom2d_Curve) pcf1 = fd1->Interference(jf1).PCurveOnFace(); | |
978 | if(pcf1.IsNull()) return Standard_False; | |
979 | Standard_Boolean isper1 = pcf1->IsPeriodic(); | |
980 | if(isper1) { | |
981 | Handle(Geom2d_TrimmedCurve) tr1 = Handle(Geom2d_TrimmedCurve)::DownCast(pcf1); | |
982 | if(!tr1.IsNull()) pcf1 = tr1->BasisCurve(); | |
983 | C1.Load(pcf1); | |
984 | } | |
985 | else C1.Load(pcf1,first-delta,last+delta); | |
986 | Standard_Real first1 = pcf1->FirstParameter(), last1 = pcf1->LastParameter(); | |
987 | ||
988 | first = fd2->Interference(jf2).FirstParameter(); | |
989 | last = fd2->Interference(jf2).LastParameter(); | |
990 | if ((last-first) < Precision::PConfusion()) | |
991 | return Standard_False; | |
992 | if(enlarge) delta = Min(0.1,0.05*(last-first)); | |
993 | Handle(Geom2d_Curve) pcf2 = fd2->Interference(jf2).PCurveOnFace(); | |
994 | if(pcf2.IsNull()) return Standard_False; | |
995 | Standard_Boolean isper2 = pcf2->IsPeriodic(); | |
996 | if(isper2) { | |
997 | Handle(Geom2d_TrimmedCurve) tr2 = Handle(Geom2d_TrimmedCurve)::DownCast(pcf2); | |
998 | if(!tr2.IsNull()) pcf2 = tr2->BasisCurve(); | |
999 | C2.Load(pcf2); | |
1000 | } | |
1001 | else C2.Load(fd2->Interference(jf2).PCurveOnFace(),first-delta,last+delta); | |
1002 | Standard_Real first2 = pcf2->FirstParameter(), last2 = pcf2->LastParameter(); | |
1003 | ||
1004 | IntRes2d_IntersectionPoint int2d; | |
1005 | Geom2dInt_GInter Intersection; | |
1006 | Standard_Integer nbpt,nbseg; | |
1007 | gp_Pnt2d p2d; | |
1008 | if(fd1->Interference(jf1).PCurveOnFace() == fd2->Interference(jf2).PCurveOnFace()) { | |
1009 | Intersection.Perform(C1, | |
1010 | Precision::PIntersection(), | |
1011 | Precision::PIntersection()); | |
1012 | } | |
1013 | else{ | |
1014 | Intersection.Perform(C1,C2, | |
1015 | Precision::PIntersection(), | |
1016 | Precision::PIntersection()); | |
1017 | } | |
1018 | if (Intersection.IsDone()) { | |
1019 | if (!Intersection.IsEmpty()) { | |
1020 | nbseg = Intersection.NbSegments(); | |
1021 | if ( nbseg > 0 ) { | |
7fd59977 | 1022 | } |
1023 | nbpt = Intersection.NbPoints(); | |
1024 | if ( nbpt >= 1 ) { | |
81bba717 | 1025 | // The criteria sets to filter the found points in a strict way |
1026 | // are missing. Two different criterions chosen somewhat randomly | |
1027 | // are used : | |
1028 | // - periodic curves : closest to the border. | |
1029 | // - non-periodic curves : the closest to the left of 2 curves | |
1030 | // modulo sens1 and sens2 | |
7fd59977 | 1031 | int2d = Intersection.Point(1); |
1032 | p2d = int2d.Value(); | |
1033 | p1 = int2d.ParamOnFirst(); | |
1034 | p2 = int2d.ParamOnSecond(); | |
1035 | if(isper1) p1 = recadre(p1,pref1,sens1,first1,last1); | |
1036 | if(isper2) p2 = recadre(p2,pref2,sens2,first2,last2); | |
1037 | for(Standard_Integer i = 2; i<=nbpt; i++) { | |
1038 | int2d = Intersection.Point(i); | |
1039 | if(isper1) { | |
1040 | Standard_Real pp1 = int2d.ParamOnFirst(); | |
1041 | pp1 = recadre(pp1,pref1,sens1,first1,last1); | |
1042 | if((Abs(pp1 - pref1) < Abs(p1 - pref1))) { | |
1043 | p1 = pp1; | |
1044 | p2 = int2d.ParamOnSecond(); | |
1045 | p2d = int2d.Value(); | |
1046 | } | |
065bb8b0 | 1047 | // Modified by skv - Mon Jun 16 15:51:21 2003 OCC615 Begin |
7fd59977 | 1048 | else if (Check2dDistance && |
1049 | RefP2d.Distance(int2d.Value()) < RefP2d.Distance(p2d)) { | |
1050 | Standard_Real pp2 = int2d.ParamOnSecond(); | |
1051 | ||
1052 | if(isper2) | |
1053 | pp2 = recadre(pp2,pref2,sens2,first2,last2); | |
1054 | ||
1055 | p1 = pp1; | |
1056 | p2 = pp2; | |
1057 | p2d = int2d.Value(); | |
1058 | } | |
065bb8b0 | 1059 | // Modified by skv - Mon Jun 16 15:51:22 2003 OCC615 End |
7fd59977 | 1060 | } |
1061 | else if(isper2) { | |
1062 | Standard_Real pp2 = int2d.ParamOnSecond(); | |
1063 | pp2 = recadre(pp2,pref2,sens2,first2,last2); | |
1064 | if((Abs(pp2 - pref2) < Abs(p2 - pref2))) { | |
1065 | p2 = pp2; | |
1066 | p1 = int2d.ParamOnFirst(); | |
1067 | p2d = int2d.Value(); | |
1068 | } | |
065bb8b0 | 1069 | // Modified by skv - Mon Jun 16 15:51:21 2003 OCC615 Begin |
7fd59977 | 1070 | else if (Check2dDistance && |
1071 | RefP2d.Distance(int2d.Value()) < RefP2d.Distance(p2d)) { | |
1072 | Standard_Real pp1 = int2d.ParamOnFirst(); | |
1073 | ||
1074 | if(isper1) | |
1075 | pp1 = recadre(pp1,pref1,sens1,first1,last1); | |
1076 | ||
1077 | p1 = pp1; | |
1078 | p2 = pp2; | |
1079 | p2d = int2d.Value(); | |
1080 | } | |
065bb8b0 | 1081 | // Modified by skv - Mon Jun 16 15:51:22 2003 OCC615 End |
7fd59977 | 1082 | } |
1083 | else if(((int2d.ParamOnFirst() - p1)*sens1 < 0.) && | |
1084 | ((int2d.ParamOnSecond() - p2)*sens2 < 0.)) { | |
1085 | p1 = int2d.ParamOnFirst(); | |
1086 | p2 = int2d.ParamOnSecond(); | |
1087 | p2d = int2d.Value(); | |
1088 | } | |
1089 | else if((Abs(int2d.ParamOnFirst() - pref1) < Abs(p1 - pref1)) && | |
1090 | (Abs(int2d.ParamOnSecond() - pref2) < Abs(p2 - pref2))) { | |
1091 | p1 = int2d.ParamOnFirst(); | |
1092 | p2 = int2d.ParamOnSecond(); | |
1093 | p2d = int2d.Value(); | |
1094 | } | |
1095 | else if (Check2dDistance && RefP2d.Distance(int2d.Value()) < RefP2d.Distance(p2d)) | |
1096 | { | |
1097 | p1 = int2d.ParamOnFirst(); | |
1098 | p2 = int2d.ParamOnSecond(); | |
1099 | p2d = int2d.Value(); | |
1100 | } | |
1101 | } | |
1102 | return Standard_True; | |
1103 | } | |
1104 | return Standard_False; | |
1105 | } | |
1106 | else { return Standard_False; } | |
1107 | } | |
1108 | else { return Standard_False; } | |
1109 | } | |
7fd59977 | 1110 | //======================================================================= |
1111 | //function : Coefficient | |
1112 | //purpose : | |
1113 | //======================================================================= | |
1114 | void ChFi3d_Coefficient(const gp_Vec& V3d, | |
1115 | const gp_Vec& D1u, | |
1116 | const gp_Vec& D1v, | |
1117 | Standard_Real& DU, | |
1118 | Standard_Real& DV) | |
1119 | { | |
1120 | const Standard_Real AA = D1u.SquareMagnitude(); | |
1121 | const Standard_Real BB = D1u.Dot(D1v); | |
1122 | const Standard_Real CC = D1v.SquareMagnitude(); | |
1123 | const Standard_Real DD = D1u.Dot(V3d); | |
1124 | const Standard_Real EE = D1v.Dot(V3d); | |
1125 | const Standard_Real Delta = AA*CC-BB*BB; | |
1126 | DU = (DD*CC-EE*BB)/Delta; | |
1127 | DV = (AA*EE-BB*DD)/Delta; | |
1128 | } | |
7fd59977 | 1129 | //======================================================================= |
1130 | //function : ReparamPcurv | |
1131 | //purpose : Dans le cas ou la pcurve est une BSpline on verifie | |
1132 | // ses parametres et on la reparametre eventuellement. | |
1133 | //======================================================================= | |
7fd59977 | 1134 | void ChFi3d_ReparamPcurv(const Standard_Real Uf, |
1135 | const Standard_Real Ul, | |
1136 | Handle(Geom2d_Curve)& Pcurv) | |
1137 | { | |
1138 | if(Pcurv.IsNull()) return; | |
1139 | Standard_Real upcf = Pcurv->FirstParameter(); | |
1140 | Standard_Real upcl = Pcurv->LastParameter(); | |
1141 | Handle(Geom2d_Curve) basis = Pcurv; | |
1142 | Handle(Geom2d_TrimmedCurve) trpc = Handle(Geom2d_TrimmedCurve)::DownCast(Pcurv); | |
1143 | if(!trpc.IsNull()) basis = trpc->BasisCurve(); | |
1144 | Handle(Geom2d_BSplineCurve) pc = Handle(Geom2d_BSplineCurve)::DownCast(basis); | |
1145 | if(pc.IsNull()) return; | |
1146 | if(Abs(upcf - pc->FirstParameter()) > Precision::PConfusion() || | |
1147 | Abs(upcl - pc->LastParameter()) > Precision::PConfusion()) { | |
1148 | pc->Segment(upcf,upcl); | |
1149 | } | |
1150 | if(Abs(Uf - pc->FirstParameter()) > Precision::PConfusion() || | |
1151 | Abs(Ul - pc->LastParameter()) > Precision::PConfusion()) { | |
1152 | TColgp_Array1OfPnt2d pol(1,pc->NbPoles()); | |
1153 | pc->Poles(pol); | |
1154 | TColStd_Array1OfReal kn(1,pc->NbKnots()); | |
1155 | pc->Knots(kn); | |
1156 | TColStd_Array1OfInteger mu(1,pc->NbKnots()); | |
1157 | pc->Multiplicities(mu); | |
1158 | Standard_Integer deg = pc->Degree(); | |
1159 | BSplCLib::Reparametrize(Uf,Ul,kn); | |
1160 | pc = new Geom2d_BSplineCurve(pol,kn,mu,deg); | |
1161 | } | |
1162 | Pcurv = pc; | |
1163 | } | |
7fd59977 | 1164 | //======================================================================= |
1165 | //function : ProjectPCurv | |
81bba717 | 1166 | //purpose : Calculation of the pcurve corresponding to a line of intersection |
1167 | // 3d. Should be called only in analytic cases. | |
7fd59977 | 1168 | //======================================================================= |
7fd59977 | 1169 | void ChFi3d_ProjectPCurv(const Handle(Adaptor3d_HCurve)& HCg, |
1170 | const Handle(Adaptor3d_HSurface)& HSg, | |
1171 | Handle(Geom2d_Curve)& Pcurv, | |
1172 | const Standard_Real tol, | |
1173 | Standard_Real& tolreached) | |
1174 | { | |
1175 | if (HSg->GetType() != GeomAbs_BezierSurface && | |
1176 | HSg->GetType() != GeomAbs_BSplineSurface) { | |
1177 | ||
1178 | ProjLib_ProjectedCurve Projc (HSg,HCg,tol); | |
1179 | tolreached = Projc.GetTolerance(); | |
1180 | switch (Projc.GetType()) { | |
1181 | case GeomAbs_Line : | |
1182 | { | |
1183 | Pcurv = new Geom2d_Line(Projc.Line()); | |
1184 | } | |
1185 | break; | |
1186 | case GeomAbs_Circle : | |
1187 | { | |
1188 | Pcurv = new Geom2d_Circle(Projc.Circle()); | |
1189 | } | |
1190 | break; | |
1191 | case GeomAbs_Ellipse : | |
1192 | { | |
1193 | Pcurv = new Geom2d_Ellipse(Projc.Ellipse()); | |
1194 | } | |
1195 | break; | |
1196 | case GeomAbs_Hyperbola : | |
1197 | { | |
1198 | Pcurv = new Geom2d_Hyperbola(Projc.Hyperbola()); | |
1199 | } | |
1200 | break; | |
1201 | case GeomAbs_Parabola : | |
1202 | { | |
1203 | Pcurv = new Geom2d_Parabola(Projc.Parabola()); | |
1204 | } | |
1205 | break; | |
1206 | case GeomAbs_BezierCurve : | |
1207 | { | |
1208 | Pcurv = Projc.Bezier(); | |
1209 | } | |
1210 | break; | |
1211 | case GeomAbs_BSplineCurve : | |
1212 | { | |
1213 | Pcurv = Projc.BSpline(); | |
1214 | } | |
1215 | break; | |
1216 | default: | |
1217 | Standard_NotImplemented::Raise("echec approximation de la pcurve "); | |
1218 | } | |
1219 | } | |
1220 | } | |
7fd59977 | 1221 | //======================================================================= |
1222 | //function : CheckSameParameter | |
81bba717 | 1223 | //purpose : Controls a posteriori that sameparameter worked well |
7fd59977 | 1224 | //======================================================================= |
065bb8b0 | 1225 | Standard_Boolean ChFi3d_CheckSameParameter (const Handle(Adaptor3d_HCurve)& C3d, |
1226 | Handle(Geom2d_Curve)& Pcurv, | |
1227 | const Handle(Adaptor3d_HSurface)& S, | |
1228 | const Standard_Real tol3d, | |
1229 | Standard_Real& tolreached) | |
7fd59977 | 1230 | { |
1231 | tolreached = 0.; | |
1232 | Standard_Real f = C3d->FirstParameter(); | |
1233 | Standard_Real l = C3d->LastParameter(); | |
1234 | Standard_Integer nbp = 45; | |
1235 | Standard_Real step = 1./(nbp -1); | |
1236 | for(Standard_Integer i = 0; i < nbp; i++) { | |
1237 | Standard_Real t,u,v; | |
1238 | t = step * i; | |
1239 | t = (1-t) * f + t * l; | |
1240 | Pcurv->Value(t).Coord(u,v); | |
1241 | gp_Pnt pS = S->Value(u,v); | |
1242 | gp_Pnt pC = C3d->Value(t); | |
1243 | Standard_Real d2 = pS.SquareDistance(pC); | |
1244 | tolreached = Max(tolreached,d2); | |
1245 | } | |
1246 | tolreached = sqrt(tolreached); | |
1247 | if(tolreached > tol3d) { | |
1248 | tolreached *= 2.; | |
1249 | return Standard_False; | |
1250 | } | |
1251 | tolreached *= 2.; | |
1252 | tolreached = Max(tolreached,Precision::Confusion()); | |
1253 | return Standard_True; | |
1254 | } | |
7fd59977 | 1255 | //======================================================================= |
1256 | //function : SameParameter | |
81bba717 | 1257 | //purpose : Encapsulation of Sameparameter |
7fd59977 | 1258 | //======================================================================= |
7fd59977 | 1259 | Standard_Boolean ChFi3d_SameParameter(const Handle(Adaptor3d_HCurve)& C3d, |
1260 | Handle(Geom2d_Curve)& Pcurv, | |
1261 | const Handle(Adaptor3d_HSurface)& S, | |
1262 | const Standard_Real tol3d, | |
1263 | Standard_Real& tolreached) | |
1264 | { | |
1265 | if(ChFi3d_CheckSameParameter(C3d,Pcurv,S,tol3d,tolreached)) return Standard_True; | |
1266 | Approx_SameParameter sp(C3d,Pcurv,S,tol3d); | |
1267 | if(sp.IsDone() && !sp.IsSameParameter()) Pcurv = sp.Curve2d(); | |
1268 | else if(!sp.IsDone() && !sp.IsSameParameter()) { | |
7fd59977 | 1269 | return Standard_False; |
1270 | } | |
1271 | tolreached = sp.TolReached(); | |
7fd59977 | 1272 | return Standard_True; |
1273 | } | |
7fd59977 | 1274 | //======================================================================= |
1275 | //function : SameParameter | |
1276 | //purpose : Encapsulation de Sameparameter | |
1277 | //======================================================================= | |
7fd59977 | 1278 | Standard_Boolean ChFi3d_SameParameter(const Handle(Geom_Curve)& C3d, |
1279 | Handle(Geom2d_Curve)& Pcurv, | |
1280 | const Handle(Geom_Surface)& S, | |
1281 | const Standard_Real Pardeb, | |
1282 | const Standard_Real Parfin, | |
1283 | const Standard_Real tol3d, | |
1284 | Standard_Real& tolreached) | |
1285 | { | |
1286 | /*szv:static*/ Handle(GeomAdaptor_HSurface) hs(new GeomAdaptor_HSurface(S)); | |
1287 | /*szv:static*/ Handle(GeomAdaptor_HCurve) hc(new GeomAdaptor_HCurve(C3d,Pardeb,Parfin)); | |
1288 | return ChFi3d_SameParameter(hc,Pcurv,hs,tol3d,tolreached); | |
1289 | } | |
7fd59977 | 1290 | //======================================================================= |
1291 | //function : ComputePCurv | |
81bba717 | 1292 | //purpose : Calculates a straight line in form of BSpline |
1293 | // to guarantee the same range and parameters as of the | |
1294 | // reference 3D curve. | |
7fd59977 | 1295 | //======================================================================= |
7fd59977 | 1296 | void ChFi3d_ComputePCurv(const Handle(Adaptor3d_HCurve)& C3d, |
1297 | const gp_Pnt2d& UV1, | |
1298 | const gp_Pnt2d& UV2, | |
1299 | Handle(Geom2d_Curve)& Pcurv, | |
1300 | const Handle(Adaptor3d_HSurface)& S, | |
1301 | const Standard_Real Pardeb, | |
1302 | const Standard_Real Parfin, | |
1303 | const Standard_Real tol3d, | |
1304 | Standard_Real& tolreached, | |
1305 | const Standard_Boolean reverse) | |
1306 | { | |
1307 | ChFi3d_ComputePCurv(UV1,UV2,Pcurv,Pardeb,Parfin,reverse); | |
7fd59977 | 1308 | ChFi3d_SameParameter(C3d,Pcurv,S,tol3d,tolreached); |
7fd59977 | 1309 | } |
7fd59977 | 1310 | //======================================================================= |
1311 | //function : ComputePCurv | |
81bba717 | 1312 | //purpose : Calculates a straight line in form of BSpline |
1313 | // to guarantee the same range and parameters as of the | |
1314 | // reference 3D curve. | |
7fd59977 | 1315 | //======================================================================= |
7fd59977 | 1316 | void ChFi3d_ComputePCurv(const Handle(Geom_Curve)& C3d, |
1317 | const gp_Pnt2d& UV1, | |
1318 | const gp_Pnt2d& UV2, | |
1319 | Handle(Geom2d_Curve)& Pcurv, | |
1320 | const Handle(Geom_Surface)& S, | |
1321 | const Standard_Real Pardeb, | |
1322 | const Standard_Real Parfin, | |
1323 | const Standard_Real tol3d, | |
1324 | Standard_Real& tolreached, | |
1325 | const Standard_Boolean reverse) | |
1326 | { | |
1327 | /*szv:static*/ Handle(GeomAdaptor_HSurface) hs(new GeomAdaptor_HSurface(S)); | |
1328 | /*szv:static*/ Handle(GeomAdaptor_HCurve) hc(new GeomAdaptor_HCurve(C3d,Pardeb,Parfin)); | |
1329 | ChFi3d_ComputePCurv(hc,UV1,UV2,Pcurv,hs,Pardeb,Parfin,tol3d,tolreached,reverse); | |
1330 | } | |
7fd59977 | 1331 | //======================================================================= |
1332 | //function : ComputePCurv | |
81bba717 | 1333 | //purpose : Calculates a straight line in form of BSpline |
1334 | // to guarantee the same range. | |
7fd59977 | 1335 | //======================================================================= |
7fd59977 | 1336 | void ChFi3d_ComputePCurv(const gp_Pnt2d& UV1, |
1337 | const gp_Pnt2d& UV2, | |
1338 | Handle(Geom2d_Curve)& Pcurv, | |
1339 | const Standard_Real Pardeb, | |
1340 | const Standard_Real Parfin, | |
1341 | const Standard_Boolean reverse) | |
1342 | { | |
1343 | const Standard_Real tol = Precision::PConfusion(); | |
1344 | gp_Pnt2d p1,p2; | |
1345 | if (!reverse) { | |
1346 | p1 = UV1; | |
1347 | p2 = UV2; | |
1348 | } | |
1349 | else { | |
1350 | p1 = UV2; | |
1351 | p2 = UV1; | |
1352 | } | |
1353 | ||
1354 | if (Abs(p1.X()-p2.X()) <= tol && | |
1355 | Abs((p2.Y()-p1.Y())-(Parfin-Pardeb)) <= tol) { | |
1356 | gp_Pnt2d ppp(p1.X(),p1.Y()-Pardeb); | |
1357 | Pcurv = new Geom2d_Line(ppp,gp::DY2d()); | |
1358 | } | |
1359 | else if (Abs(p1.X()-p2.X()) <= tol && | |
1360 | Abs((p1.Y()-p2.Y())-(Parfin-Pardeb)) <= tol) { | |
1361 | gp_Pnt2d ppp(p1.X(),p1.Y()+Pardeb); | |
1362 | Pcurv = new Geom2d_Line(ppp,gp::DY2d().Reversed()); | |
1363 | } | |
1364 | else if (Abs(p1.Y()-p2.Y()) <= tol && | |
1365 | Abs((p2.X()-p1.X())-(Parfin-Pardeb)) <= tol) { | |
1366 | gp_Pnt2d ppp(p1.X()-Pardeb,p1.Y()); | |
1367 | Pcurv = new Geom2d_Line(ppp,gp::DX2d()); | |
1368 | } | |
1369 | else if (Abs(p1.Y()-p2.Y()) <= tol && | |
1370 | Abs((p1.X()-p2.X())-(Parfin-Pardeb)) <= tol) { | |
1371 | gp_Pnt2d ppp(p1.X()+Pardeb,p1.Y()); | |
1372 | Pcurv = new Geom2d_Line(ppp,gp::DX2d().Reversed()); | |
1373 | } | |
1374 | else{ | |
1375 | TColgp_Array1OfPnt2d p(1,2); | |
1376 | TColStd_Array1OfReal k(1,2); | |
1377 | TColStd_Array1OfInteger m(1,2); | |
1378 | m.Init(2); | |
1379 | k(1) = Pardeb; | |
1380 | k(2) = Parfin; | |
1381 | p(1) = p1; | |
1382 | p(2) = p2; | |
1383 | Pcurv = new Geom2d_BSplineCurve(p,k,m,1); | |
1384 | } | |
1385 | Pcurv = new Geom2d_TrimmedCurve(Pcurv,Pardeb,Parfin); | |
1386 | } | |
065bb8b0 | 1387 | //======================================================================= |
1388 | //function : ChFi3d_mkbound | |
1389 | //purpose : | |
1390 | //======================================================================= | |
7fd59977 | 1391 | Handle(GeomFill_Boundary) ChFi3d_mkbound(const Handle(Adaptor3d_HSurface)& Fac, |
1392 | Handle(Geom2d_Curve)& curv, | |
1393 | const Standard_Integer sens1, | |
1394 | const gp_Pnt2d& pfac1, | |
1395 | const gp_Vec2d& vfac1, | |
1396 | const Standard_Integer sens2, | |
1397 | const gp_Pnt2d& pfac2, | |
1398 | const gp_Vec2d& vfac2, | |
1399 | const Standard_Real t3d, | |
1400 | const Standard_Real ta) | |
1401 | { | |
1402 | gp_Dir2d v1(vfac1); | |
1403 | if(sens1 == 1) v1.Reverse(); | |
1404 | gp_Dir2d v2(vfac2); | |
1405 | if(sens2 == 1) v2.Reverse(); | |
1406 | curv = ChFi3d_BuildPCurve(Fac,pfac1,v1,pfac2,v2,Standard_False); | |
1407 | return ChFi3d_mkbound(Fac,curv,t3d,ta); | |
1408 | } | |
065bb8b0 | 1409 | //======================================================================= |
1410 | //function : ChFi3d_mkbound | |
1411 | //purpose : | |
1412 | //======================================================================= | |
7fd59977 | 1413 | Handle(GeomFill_Boundary) ChFi3d_mkbound(const Handle(Adaptor3d_HSurface)& Surf, |
1414 | Handle(Geom2d_Curve)& curv, | |
1415 | const Standard_Integer sens1, | |
1416 | const gp_Pnt2d& p1, | |
1417 | gp_Vec& v1, | |
1418 | const Standard_Integer sens2, | |
1419 | const gp_Pnt2d& p2, | |
1420 | gp_Vec& v2, | |
1421 | const Standard_Real t3d, | |
1422 | const Standard_Real ta) | |
1423 | { | |
1424 | if(sens1 == 1) v1.Reverse(); | |
1425 | if(sens2 == 1) v2.Reverse(); | |
1426 | curv = ChFi3d_BuildPCurve(Surf,p1,v1,p2,v2); | |
1427 | return ChFi3d_mkbound(Surf,curv,t3d,ta); | |
1428 | } | |
065bb8b0 | 1429 | //======================================================================= |
1430 | //function : ChFi3d_mkbound | |
1431 | //purpose : | |
1432 | //======================================================================= | |
7fd59977 | 1433 | Handle(GeomFill_Boundary) ChFi3d_mkbound(const Handle(Geom_Surface)& s, |
1434 | const gp_Pnt2d& p1, | |
1435 | const gp_Pnt2d& p2, | |
1436 | const Standard_Real t3d, | |
1437 | const Standard_Real ta, | |
1438 | const Standard_Boolean isfreeboundary) | |
1439 | { | |
1440 | Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(s); | |
1441 | return ChFi3d_mkbound(HS,p1,p2,t3d,ta,isfreeboundary); | |
1442 | } | |
065bb8b0 | 1443 | //======================================================================= |
1444 | //function : ChFi3d_mkbound | |
1445 | //purpose : | |
1446 | //======================================================================= | |
7fd59977 | 1447 | Handle(GeomFill_Boundary) ChFi3d_mkbound(const Handle(Adaptor3d_HSurface)& HS, |
1448 | const gp_Pnt2d& p1, | |
1449 | const gp_Pnt2d& p2, | |
1450 | const Standard_Real t3d, | |
1451 | const Standard_Real ta, | |
1452 | const Standard_Boolean isfreeboundary) | |
1453 | { | |
1454 | TColgp_Array1OfPnt2d pol(1,2); | |
1455 | pol(1)=p1; | |
1456 | pol(2)=p2; | |
1457 | Handle(Geom2d_Curve) curv = new Geom2d_BezierCurve(pol); | |
1458 | return ChFi3d_mkbound(HS,curv,t3d,ta,isfreeboundary); | |
1459 | } | |
065bb8b0 | 1460 | //======================================================================= |
1461 | //function : ChFi3d_mkbound | |
1462 | //purpose : | |
1463 | //======================================================================= | |
7fd59977 | 1464 | Handle(GeomFill_Boundary) ChFi3d_mkbound(const Handle(Adaptor3d_HSurface)& HS, |
1465 | const Handle(Geom2d_Curve)& curv, | |
1466 | const Standard_Real t3d, | |
1467 | const Standard_Real ta, | |
1468 | const Standard_Boolean isfreeboundary) | |
1469 | { | |
1470 | Handle(Geom2dAdaptor_HCurve) HC = new Geom2dAdaptor_HCurve(curv); | |
1471 | Adaptor3d_CurveOnSurface COnS(HC,HS); | |
1472 | if (isfreeboundary) { | |
1473 | Handle(Adaptor3d_HCurveOnSurface) HCOnS = new Adaptor3d_HCurveOnSurface(COnS); | |
1474 | return new GeomFill_SimpleBound(HCOnS,t3d,ta); | |
1475 | } | |
1476 | return new GeomFill_BoundWithSurf(COnS,t3d,ta); | |
1477 | } | |
065bb8b0 | 1478 | //======================================================================= |
1479 | //function : ChFi3d_mkbound | |
1480 | //purpose : | |
1481 | //======================================================================= | |
7fd59977 | 1482 | Handle(GeomFill_Boundary) ChFi3d_mkbound(const Handle(Adaptor3d_HSurface)& Fac, |
1483 | Handle(Geom2d_Curve)& curv, | |
1484 | const gp_Pnt2d& p1, | |
1485 | const gp_Pnt2d& p2, | |
1486 | const Standard_Real t3d, | |
1487 | const Standard_Real ta, | |
1488 | const Standard_Boolean isfreeboundary) | |
1489 | { | |
1490 | TColgp_Array1OfPnt2d pol(1,2); | |
1491 | pol(1)=p1; | |
1492 | pol(2)=p2; | |
1493 | curv = new Geom2d_BezierCurve(pol); | |
1494 | return ChFi3d_mkbound(Fac,curv,t3d,ta,isfreeboundary); | |
1495 | } | |
065bb8b0 | 1496 | //======================================================================= |
1497 | //function : ChFi3d_BuildPCurve | |
1498 | //purpose : | |
1499 | //======================================================================= | |
7fd59977 | 1500 | Handle(Geom2d_Curve) ChFi3d_BuildPCurve(const gp_Pnt2d& p1, |
1501 | gp_Dir2d& d1, | |
1502 | const gp_Pnt2d& p2, | |
1503 | gp_Dir2d& d2, | |
1504 | const Standard_Boolean redresse) | |
1505 | { | |
1506 | gp_Vec2d vref(p1,p2); | |
1507 | gp_Dir2d dref(vref); | |
1508 | Standard_Real mref = vref.Magnitude(); | |
1509 | if(redresse) { | |
1510 | if(d1.Dot(dref) < 0.) d1.Reverse(); | |
1511 | if(d2.Dot(dref) > 0.) d2.Reverse(); | |
1512 | } | |
1513 | //On fait une cubique a la mords moi le noeud | |
1514 | TColgp_Array1OfPnt2d pol(1,4); | |
1515 | pol(1)=p1; | |
1516 | pol(4)=p2; | |
1517 | Standard_Real Lambda1 = Max(Abs(d2.Dot(d1)),Abs(dref.Dot(d1))); | |
1518 | Lambda1 = Max(0.5*mref*Lambda1,1.e-5); | |
1519 | pol(2) = gp_Pnt2d(p1.XY()+Lambda1*d1.XY()); | |
1520 | Standard_Real Lambda2 = Max(Abs(d1.Dot(d2)),Abs(dref.Dot(d2))); | |
1521 | Lambda2 = Max(0.5*mref*Lambda2,1.e-5); | |
1522 | pol(3)=gp_Pnt2d(p2.XY()+Lambda2*d2.XY()); | |
1523 | return new Geom2d_BezierCurve(pol); | |
7fd59977 | 1524 | } |
065bb8b0 | 1525 | //======================================================================= |
1526 | //function : ChFi3d_BuildPCurve | |
1527 | //purpose : | |
1528 | //======================================================================= | |
7fd59977 | 1529 | Handle(Geom2d_Curve) ChFi3d_BuildPCurve(const Handle(Adaptor3d_HSurface)& Surf, |
1530 | const gp_Pnt2d& p1, | |
1531 | const gp_Vec2d& v1, | |
1532 | const gp_Pnt2d& p2, | |
1533 | const gp_Vec2d& v2, | |
1534 | const Standard_Boolean redresse) | |
1535 | { | |
1536 | gp_Pnt2d pp1 = p1, pp2 = p2; | |
1537 | gp_Vec2d vv1 = v1, vv2 = v2; | |
1538 | const Standard_Real ures = Surf->UResolution(1.); | |
1539 | const Standard_Real vres = Surf->VResolution(1.); | |
1540 | const Standard_Real invures = 1./ures; | |
1541 | const Standard_Real invvres = 1./vres; | |
1542 | pp1.SetX(invures*pp1.X()); pp1.SetY(invvres*pp1.Y()); | |
1543 | pp2.SetX(invures*pp2.X()); pp2.SetY(invvres*pp2.Y()); | |
1544 | vv1.SetX(invures*vv1.X()); vv1.SetY(invvres*vv1.Y()); | |
1545 | vv2.SetX(invures*vv2.X()); vv2.SetY(invvres*vv2.Y()); | |
1546 | gp_Dir2d d1(vv1), d2(vv2); | |
1547 | Handle(Geom2d_Curve) g2dc = ChFi3d_BuildPCurve(pp1,d1,pp2,d2,redresse); | |
1548 | Handle(Geom2d_BezierCurve) pc = Handle(Geom2d_BezierCurve)::DownCast(g2dc); | |
1549 | const Standard_Integer nbp = pc->NbPoles(); | |
1550 | for(Standard_Integer ip = 1; ip <= nbp; ip++) { | |
1551 | gp_Pnt2d pol = pc->Pole(ip); | |
1552 | pol.SetX(ures*pol.X()); pol.SetY(vres*pol.Y()); | |
1553 | pc->SetPole(ip,pol); | |
1554 | } | |
1555 | return pc; | |
1556 | } | |
065bb8b0 | 1557 | //======================================================================= |
1558 | //function : ChFi3d_BuildPCurve | |
1559 | //purpose : | |
1560 | //======================================================================= | |
7fd59977 | 1561 | Handle(Geom2d_Curve) ChFi3d_BuildPCurve(const Handle(Adaptor3d_HSurface)& Surf, |
1562 | const gp_Pnt2d& p1, | |
1563 | const gp_Vec& v1, | |
1564 | const gp_Pnt2d& p2, | |
1565 | const gp_Vec& v2, | |
1566 | const Standard_Boolean redresse) | |
1567 | { | |
1568 | gp_Vec D1u,D1v; | |
1569 | gp_Pnt PP1,PP2; | |
1570 | Standard_Real DU,DV; | |
1571 | Surf->D1(p1.X(),p1.Y(),PP1,D1u,D1v); | |
1572 | ChFi3d_Coefficient(v1,D1u,D1v,DU,DV); | |
1573 | gp_Vec2d vv1(DU,DV); | |
1574 | Surf->D1(p2.X(),p2.Y(),PP2,D1u,D1v); | |
1575 | ChFi3d_Coefficient(v2,D1u,D1v,DU,DV); | |
1576 | gp_Vec2d vv2(DU,DV); | |
1577 | gp_Vec Vref(PP1,PP2); | |
1578 | if(redresse) { | |
1579 | if(Vref.Dot(v1) < 0.) vv1.Reverse(); | |
1580 | if(Vref.Dot(v2) > 0.) vv2.Reverse(); | |
1581 | } | |
1582 | return ChFi3d_BuildPCurve(Surf,p1,vv1,p2,vv2,0); | |
1583 | } | |
7fd59977 | 1584 | //======================================================================= |
1585 | //function : ComputeArete | |
1586 | //purpose : | |
81bba717 | 1587 | // to fill with s.d. a fillet with pcurves constructed as follows |
1588 | // firstpoint on S1 -------------edge:curve3d/pcurves--->lastpoint on S1 | |
7fd59977 | 1589 | // | | |
1590 | // | | | |
1591 | // | | | |
81bba717 | 1592 | // edge:curve 3d/pcurves fillet edge |
1593 | // | attention it is necessary to test orientation of the fillet before| | |
1594 | // | determining the transitions pcurves/fillet | | |
7fd59977 | 1595 | // | | |
1596 | // \/ \/ | |
1597 | // firstpoint sur S2 -------------edge:courbe3d/pcurves--->lastpoint sur S2 | |
1598 | // | |
1599 | //======================================================================= | |
7fd59977 | 1600 | void ChFi3d_ComputeArete(const ChFiDS_CommonPoint& P1, |
1601 | const gp_Pnt2d& UV1, | |
1602 | const ChFiDS_CommonPoint& P2, | |
1603 | const gp_Pnt2d& UV2, | |
1604 | const Handle(Geom_Surface)& Surf, | |
1605 | Handle(Geom_Curve)& C3d, | |
1606 | Handle(Geom2d_Curve)& Pcurv, | |
1607 | Standard_Real& Pardeb, | |
1608 | Standard_Real& Parfin, | |
1609 | const Standard_Real tol3d, | |
1610 | const Standard_Real tol2d, | |
1611 | Standard_Real& tolreached, | |
1612 | const Standard_Integer IFlag) | |
1613 | // IFlag=0 pcurve et courbe 3d | |
1614 | // IFlag>0 pcurve (parametrage impose si IFlag=2) | |
1615 | { | |
1616 | /*szv:static*/ Handle(GeomAdaptor_HSurface) hs(new GeomAdaptor_HSurface()); | |
1617 | /*szv:static*/ Handle(GeomAdaptor_HCurve) hc(new GeomAdaptor_HCurve()); | |
1618 | ||
1619 | tolreached = tol3d; | |
1620 | ||
1621 | if (Abs(UV1.X()-UV2.X()) <= tol2d) { | |
1622 | if (IFlag == 0) { | |
1623 | Pardeb = UV1.Y(); | |
1624 | Parfin = UV2.Y(); | |
1625 | C3d = Surf->UIso(UV1.X()); | |
1626 | if(Pardeb > Parfin) { | |
1627 | Pardeb = C3d->ReversedParameter(Pardeb); | |
1628 | Parfin = C3d->ReversedParameter(Parfin); | |
1629 | C3d->Reverse(); | |
1630 | } | |
1631 | Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(C3d); | |
1632 | if(!tc.IsNull()) { | |
1633 | C3d = tc->BasisCurve(); | |
1634 | if (C3d->IsPeriodic()) { | |
1635 | ElCLib::AdjustPeriodic(C3d->FirstParameter(),C3d->LastParameter(), | |
1636 | tol2d,Pardeb,Parfin); | |
1637 | } | |
1638 | } | |
1639 | } | |
1640 | if(IFlag != 1) { | |
1641 | hs->ChangeSurface().Load(Surf); | |
1642 | hc->ChangeCurve().Load(C3d,Pardeb,Parfin); | |
1643 | ChFi3d_ComputePCurv(hc,UV1,UV2,Pcurv,hs,Pardeb,Parfin,tol3d,tolreached,Standard_False); | |
1644 | } | |
1645 | else{ | |
1646 | Pcurv = new Geom2d_Line(UV1,gp_Vec2d(UV1,UV2)); | |
1647 | } | |
1648 | } | |
1649 | else if (Abs(UV1.Y()-UV2.Y())<=tol2d) { | |
1650 | //iso v | |
1651 | if (IFlag == 0) { | |
1652 | Pardeb = UV1.X(); | |
1653 | Parfin = UV2.X(); | |
1654 | C3d = Surf->VIso(UV1.Y()); | |
1655 | if(Pardeb > Parfin) { | |
1656 | Pardeb = C3d->ReversedParameter(Pardeb); | |
1657 | Parfin = C3d->ReversedParameter(Parfin); | |
1658 | C3d->Reverse(); | |
1659 | } | |
1660 | Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(C3d); | |
1661 | if(!tc.IsNull()) { | |
1662 | C3d = tc->BasisCurve(); | |
1663 | if (C3d->IsPeriodic()) { | |
1664 | ElCLib::AdjustPeriodic(C3d->FirstParameter(),C3d->LastParameter(), | |
1665 | tol2d,Pardeb,Parfin); | |
1666 | } | |
1667 | } | |
1668 | } | |
1669 | if(IFlag != 1) { | |
1670 | hs->ChangeSurface().Load(Surf); | |
1671 | hc->ChangeCurve().Load(C3d,Pardeb,Parfin); | |
1672 | ChFi3d_ComputePCurv(hc,UV1,UV2,Pcurv,hs,Pardeb,Parfin,tol3d,tolreached,Standard_False); | |
1673 | } | |
1674 | else{ | |
1675 | Pcurv = new Geom2d_Line(UV1,gp_Vec2d(UV1,UV2)); | |
1676 | } | |
1677 | } | |
1678 | else if (IFlag == 0) { | |
1679 | ||
1680 | if (P1.IsVertex() || P2.IsVertex() || !P1.IsOnArc() || !P2.IsOnArc()) { | |
81bba717 | 1681 | // A straight line is constructed to avoid |
1682 | // arc and tangent. | |
7fd59977 | 1683 | TColgp_Array1OfPnt2d qoles(1,2); |
1684 | qoles(1)=UV1; | |
1685 | qoles(2)=UV2; | |
1686 | Pcurv = new Geom2d_BezierCurve(qoles); | |
1687 | } | |
1688 | else { | |
1689 | BRepAdaptor_Curve C1(P1.Arc()); | |
1690 | gp_Pnt Pp; | |
1691 | gp_Vec Vv1; | |
1692 | C1.D1(P1.ParameterOnArc(),Pp,Vv1); | |
1693 | C1.Initialize(P2.Arc()); | |
1694 | gp_Vec Vv2; | |
1695 | C1.D1(P2.ParameterOnArc(),Pp,Vv2); | |
1696 | hs->ChangeSurface().Load(Surf); | |
1697 | Pcurv = ChFi3d_BuildPCurve(hs,UV1,Vv1,UV2,Vv2,Standard_True); | |
81bba717 | 1698 | // There are some cases when PCurve constructed in this way |
1699 | // leaves the surface, in particular if it results from an | |
1700 | // extension. A posteriori checking is required and if | |
1701 | // the curve leaves the surface it is replaced by straight line UV1 UV2 | |
1702 | // non regarding the tangency with neighboring arcs! | |
7fd59977 | 1703 | Bnd_Box2d bs; |
1704 | Standard_Real umin,umax,vmin,vmax; | |
1705 | Surf->Bounds(umin,umax,vmin,vmax); | |
1706 | bs.Update(umin,vmin,umax,vmax); | |
1707 | Standard_Boolean aIN = Standard_True; | |
1708 | for(Standard_Integer ii = 1; ii <= 4 && aIN; ii++) { | |
1709 | if(bs.IsOut((*((Handle_Geom2d_BezierCurve*) &Pcurv))->Pole(ii))) { | |
1710 | aIN = Standard_False; | |
1711 | TColgp_Array1OfPnt2d qoles(1,2); | |
1712 | qoles(1)=UV1; | |
1713 | qoles(2)=UV2; | |
1714 | Pcurv = new Geom2d_BezierCurve(qoles); | |
1715 | } | |
1716 | } | |
1717 | } | |
1718 | Geom2dAdaptor_Curve AC(Pcurv); | |
1719 | Handle(Geom2dAdaptor_HCurve) AHC = | |
1720 | new Geom2dAdaptor_HCurve(AC); | |
1721 | GeomAdaptor_Surface AS(Surf); | |
1722 | Handle(GeomAdaptor_HSurface) AHS = | |
1723 | new GeomAdaptor_HSurface(AS); | |
1724 | Adaptor3d_CurveOnSurface Cs(AHC,AHS); | |
1725 | Pardeb = Cs.FirstParameter(); | |
1726 | Parfin = Cs.LastParameter(); | |
1727 | Standard_Real avtol; | |
1728 | GeomLib::BuildCurve3d(tol3d,Cs,Pardeb,Parfin,C3d,tolreached,avtol); | |
1729 | } | |
1730 | else { | |
1731 | hs->ChangeSurface().Load(Surf); | |
1732 | hc->ChangeCurve().Load(C3d,Pardeb,Parfin); | |
1733 | ChFi3d_ProjectPCurv(hc,hs,Pcurv,tol3d,tolreached); | |
1734 | gp_Pnt2d p2d = Pcurv->Value(Pardeb); | |
1735 | if(!UV1.IsEqual(p2d,Precision::PConfusion())) { | |
1736 | gp_Vec2d v2d(p2d,UV1); | |
1737 | Pcurv->Translate(v2d); | |
1738 | } | |
1739 | } | |
1740 | } | |
7fd59977 | 1741 | //======================================================================= |
1742 | //function : FilCurveInDS | |
1743 | //purpose : | |
1744 | //======================================================================= | |
7fd59977 | 1745 | Handle(TopOpeBRepDS_SurfaceCurveInterference) ChFi3d_FilCurveInDS |
1746 | (const Standard_Integer Icurv, | |
1747 | const Standard_Integer Isurf, | |
1748 | const Handle(Geom2d_Curve)& Pcurv, | |
1749 | const TopAbs_Orientation Et) | |
1750 | { | |
1751 | Handle(TopOpeBRepDS_SurfaceCurveInterference) SC1; | |
1752 | SC1 = new TopOpeBRepDS_SurfaceCurveInterference(TopOpeBRepDS_Transition(Et), | |
1753 | TopOpeBRepDS_SURFACE, | |
1754 | Isurf,TopOpeBRepDS_CURVE,Icurv, | |
1755 | Pcurv); | |
1756 | return SC1; | |
1757 | } | |
7fd59977 | 1758 | //======================================================================= |
1759 | //function : TrsfTrans | |
1760 | //purpose : | |
1761 | // | |
1762 | //======================================================================= | |
1763 | TopAbs_Orientation ChFi3d_TrsfTrans(const IntSurf_TypeTrans T1) | |
1764 | { | |
065bb8b0 | 1765 | switch (T1) { |
7fd59977 | 1766 | case IntSurf_In: return TopAbs_FORWARD; |
1767 | case IntSurf_Out: return TopAbs_REVERSED; | |
566f8441 | 1768 | default: |
1769 | break; | |
7fd59977 | 1770 | } |
1771 | return TopAbs_INTERNAL; | |
1772 | } | |
7fd59977 | 1773 | //======================================================================= |
1774 | //function : FilCommonPoint | |
81bba717 | 1775 | //purpose : Loading of the common point |
1776 | // management of the case when it happens on already existing vertex. | |
7fd59977 | 1777 | //======================================================================= |
7fd59977 | 1778 | Standard_EXPORT void ChFi3d_FilCommonPoint(const BRepBlend_Extremity& SP, |
1779 | const IntSurf_TypeTrans TransLine, | |
1780 | const Standard_Boolean Start, | |
1781 | ChFiDS_CommonPoint& CP, | |
1782 | const Standard_Real Tol) | |
1783 | { | |
1784 | // BRep_Tool Outil; | |
1785 | Standard_Real Dist, maxtol = Max(Tol,CP.Tolerance()); | |
1786 | ||
81bba717 | 1787 | CP.SetPoint(SP.Value()); // One starts with the point and the vector |
7fd59977 | 1788 | if (SP.HasTangent()) { |
1789 | if (Start) { | |
81bba717 | 1790 | CP.SetVector(SP.Tangent().Reversed()); // The tangent is oriented to the exit |
7fd59977 | 1791 | } |
1792 | else { | |
1793 | CP.SetVector(SP.Tangent()); | |
1794 | } | |
1795 | } | |
1796 | ||
81bba717 | 1797 | CP.SetParameter(SP.ParameterOnGuide()); // and the parameter of the spine |
7fd59977 | 1798 | |
81bba717 | 1799 | if (SP.IsVertex()) { // the Vertex is loaded if required |
1800 | // (inside of a face) | |
7fd59977 | 1801 | TopoDS_Vertex V = |
1802 | Handle(BRepTopAdaptor_HVertex)::DownCast(SP.Vertex())->Vertex(); | |
1803 | ||
1804 | CP.SetVertex(V); | |
1805 | Dist = (SP.Value()).Distance(BRep_Tool::Pnt(V)); | |
1806 | //// modified by jgv, 18.09.02 for OCC571 //// | |
1807 | //maxtol += Dist; | |
1808 | maxtol = Max( Dist, maxtol ); | |
1809 | ////////////////////////////////////////////// | |
1810 | CP.SetPoint(BRep_Tool::Pnt(V)); | |
1811 | ||
81bba717 | 1812 | //the sequence of arcs the information is known by thee vertex (ancestor) |
1813 | //in this case the transitions are not computed, it is done by this program | |
7fd59977 | 1814 | } |
1815 | ||
81bba717 | 1816 | if (SP.NbPointOnRst() != 0) { // An arc, and/or a vertex is loaded |
7fd59977 | 1817 | |
1818 | const BRepBlend_PointOnRst& PR = SP.PointOnRst(1); | |
1819 | Handle(BRepAdaptor_HCurve2d) | |
1820 | Harc = Handle(BRepAdaptor_HCurve2d)::DownCast(PR.Arc()); | |
1821 | if(!Harc.IsNull()) { | |
1822 | ||
1823 | Standard_Real DistF, DistL, LeParamAmoi; | |
1824 | Standard_Integer Index_min; | |
1825 | TopoDS_Edge E = Harc->ChangeCurve2d().Edge(); | |
1826 | ||
1827 | TopoDS_Vertex V[2]; | |
1828 | TopExp::Vertices(E, V[0], V[1]); | |
1829 | ||
1830 | DistF = (SP.Value()).Distance(BRep_Tool::Pnt(V[0])); | |
1831 | DistL = (SP.Value()).Distance(BRep_Tool::Pnt(V[1])); | |
1832 | if (DistF<DistL) { Index_min = 0; | |
1833 | Dist = DistF; } | |
1834 | else { Index_min = 1; | |
1835 | Dist = DistL; } | |
1836 | ||
1837 | if (Dist <= maxtol + BRep_Tool::Tolerance(V[Index_min]) ) { | |
81bba717 | 1838 | // a prexisting vertex has been met |
1839 | CP.SetVertex(V[Index_min]); //the old vertex is loaded | |
7fd59977 | 1840 | CP.SetPoint( BRep_Tool::Pnt(V[Index_min]) ); |
1841 | maxtol = Max(BRep_Tool::Tolerance(V[Index_min]),maxtol); | |
1842 | //// modified by jgv, 18.09.02 for OCC571 //// | |
1843 | //maxtol += Dist; | |
1844 | maxtol = Max( Dist, maxtol ); | |
1845 | ////////////////////////////////////////////// | |
1846 | LeParamAmoi = BRep_Tool::Parameter(V[Index_min], E); | |
1847 | } | |
81bba717 | 1848 | else { // Creation of an arc only |
7fd59977 | 1849 | maxtol = Max(BRep_Tool::Tolerance(E),maxtol); |
1850 | maxtol = Max(SP.Tolerance(),maxtol); | |
1851 | LeParamAmoi = PR.ParameterOnArc(); | |
1852 | } | |
1853 | ||
81bba717 | 1854 | // Definition of the arc |
7fd59977 | 1855 | TopAbs_Orientation Tr; |
1856 | TopAbs_Orientation Or = E.Orientation(); | |
1857 | if (Start) { | |
1858 | Tr = TopAbs::Reverse(TopAbs::Compose(ChFi3d_TrsfTrans(TransLine),Or)); | |
1859 | } | |
1860 | else { | |
1861 | Tr = TopAbs::Compose(ChFi3d_TrsfTrans(TransLine),Or); | |
1862 | } | |
1863 | CP.SetArc(maxtol, E, LeParamAmoi, Tr); | |
1864 | } | |
1865 | } | |
81bba717 | 1866 | CP.SetTolerance(maxtol); // Finally, the tolerance. |
7fd59977 | 1867 | } |
1868 | ||
1869 | //======================================================================= | |
1870 | //function : SolidIndex | |
1871 | //purpose : | |
1872 | //======================================================================= | |
7fd59977 | 1873 | Standard_Integer ChFi3d_SolidIndex(const Handle(ChFiDS_Spine)& sp, |
1874 | TopOpeBRepDS_DataStructure& DStr, | |
1875 | ChFiDS_Map& MapESo, | |
1876 | ChFiDS_Map& MapESh) | |
1877 | { | |
1878 | if(sp.IsNull() || sp->NbEdges() == 0) | |
1879 | Standard_Failure::Raise("SolidIndex : Spine incomplete"); | |
1880 | TopoDS_Shape edref= sp->Edges(1); | |
1881 | TopoDS_Shape shellousolid; | |
1882 | if(!MapESo(edref).IsEmpty()) shellousolid = MapESo(edref).First(); | |
1883 | else shellousolid = MapESh(edref).First(); | |
1884 | const Standard_Integer solidindex = DStr.AddShape(shellousolid); | |
1885 | return solidindex; | |
1886 | } | |
7fd59977 | 1887 | //======================================================================= |
1888 | //function : IndexPointInDS | |
1889 | //purpose : | |
1890 | //======================================================================= | |
7fd59977 | 1891 | Standard_Integer ChFi3d_IndexPointInDS(const ChFiDS_CommonPoint& P1, |
1892 | TopOpeBRepDS_DataStructure& DStr) | |
1893 | { | |
1894 | if (P1.IsVertex()) { | |
1895 | // ---------------------------------> !*!*!* | |
81bba717 | 1896 | // Attention : it is necessary ti implement a mechanism |
1897 | // controlling tolerance. | |
7fd59977 | 1898 | BRep_Builder B; |
1899 | B.UpdateVertex(P1.Vertex(), P1.Point(), P1.Tolerance()); | |
1900 | return DStr.AddShape(P1.Vertex()); | |
1901 | } | |
1902 | return DStr.AddPoint(TopOpeBRepDS_Point(P1.Point(),P1.Tolerance())); | |
1903 | } | |
7fd59977 | 1904 | //======================================================================= |
1905 | //function : FilPointInDS | |
1906 | //purpose : | |
1907 | //======================================================================= | |
065bb8b0 | 1908 | Handle(TopOpeBRepDS_CurvePointInterference) |
1909 | ChFi3d_FilPointInDS(const TopAbs_Orientation Et, | |
1910 | const Standard_Integer Ic, | |
1911 | const Standard_Integer Ip, | |
1912 | const Standard_Real Par, | |
1913 | const Standard_Boolean IsVertex) | |
7fd59977 | 1914 | { |
1915 | Handle(TopOpeBRepDS_CurvePointInterference) CP1; | |
1916 | if (IsVertex) | |
1917 | CP1 = new TopOpeBRepDS_CurvePointInterference (TopOpeBRepDS_Transition(Et), | |
1918 | TopOpeBRepDS_CURVE,Ic, | |
1919 | TopOpeBRepDS_VERTEX,Ip,Par); | |
1920 | else | |
1921 | CP1 = new TopOpeBRepDS_CurvePointInterference (TopOpeBRepDS_Transition(Et), | |
1922 | TopOpeBRepDS_CURVE,Ic, | |
1923 | TopOpeBRepDS_POINT,Ip,Par); | |
1924 | return CP1; | |
1925 | } | |
7fd59977 | 1926 | //======================================================================= |
1927 | //function : FilVertexInDS | |
1928 | //purpose : | |
1929 | //======================================================================= | |
065bb8b0 | 1930 | Handle(TopOpeBRepDS_CurvePointInterference) |
1931 | ChFi3d_FilVertexInDS(const TopAbs_Orientation Et, | |
1932 | const Standard_Integer Ic, | |
1933 | const Standard_Integer Ip, | |
1934 | const Standard_Real Par) | |
7fd59977 | 1935 | { |
1936 | ||
1937 | Handle(TopOpeBRepDS_CurvePointInterference) CP1 = new | |
1938 | TopOpeBRepDS_CurvePointInterference (TopOpeBRepDS_Transition(Et), | |
1939 | TopOpeBRepDS_CURVE,Ic, | |
1940 | TopOpeBRepDS_VERTEX,Ip,Par); | |
1941 | return CP1; | |
1942 | } | |
7fd59977 | 1943 | //======================================================================= |
1944 | //function : Orientation | |
81bba717 | 1945 | //purpose : returns the orientation of the interference (the first found |
1946 | // in the list). | |
7fd59977 | 1947 | //======================================================================= |
1948 | ||
065bb8b0 | 1949 | static Standard_Boolean |
1950 | ChFi3d_Orientation(const TopOpeBRepDS_ListOfInterference& LI, | |
1951 | const Standard_Integer igros, | |
1952 | const Standard_Integer ipetit, | |
1953 | TopAbs_Orientation& Or, | |
1954 | const Standard_Boolean isvertex = Standard_False, | |
1955 | const Standard_Boolean aprendre = Standard_False) | |
7fd59977 | 1956 | { |
81bba717 | 1957 | //In case, when it is necessary to insert a point/vertex, it should be |
1958 | //known if this is a point or a vertex, because their index can be the same. | |
7fd59977 | 1959 | TopOpeBRepDS_Kind typepetit; |
1960 | if (isvertex) | |
1961 | typepetit = TopOpeBRepDS_VERTEX; | |
1962 | else | |
1963 | typepetit = TopOpeBRepDS_POINT; | |
1964 | TopOpeBRepDS_ListIteratorOfListOfInterference itLI(LI); | |
1965 | for (; itLI.More(); itLI.Next() ) { | |
1966 | const Handle(TopOpeBRepDS_Interference)& cur = itLI.Value(); | |
1967 | TopOpeBRepDS_Kind GK; | |
1968 | TopOpeBRepDS_Kind SK; | |
1969 | Standard_Integer S; | |
1970 | Standard_Integer G; | |
1971 | cur->GKGSKS(GK,G,SK,S); | |
1972 | if (aprendre) { | |
1973 | if ( S == igros && G == ipetit && GK == typepetit) { | |
1974 | Or = cur->Transition().Orientation(TopAbs_IN); | |
1975 | return Standard_True; | |
1976 | } | |
1977 | } | |
1978 | else { | |
1979 | if ( S == igros && G == ipetit) { | |
1980 | Or = cur->Transition().Orientation(TopAbs_IN); | |
1981 | return Standard_True; | |
1982 | } | |
1983 | } | |
1984 | } | |
1985 | return Standard_False; | |
1986 | } | |
1987 | ||
065bb8b0 | 1988 | //======================================================================= |
7fd59977 | 1989 | //function : Contains |
81bba717 | 1990 | //purpose : Check if the interference does not already exist. |
1991 | //==================================================================== | |
1992 | ||
1993 | static Standard_Boolean ChFi3d_Contains | |
1994 | (const TopOpeBRepDS_ListOfInterference& LI, | |
1995 | const Standard_Integer igros, | |
1996 | const Standard_Integer ipetit, | |
1997 | const Standard_Boolean isvertex = Standard_False, | |
1998 | const Standard_Boolean aprendre = Standard_False) | |
7fd59977 | 1999 | { |
2000 | TopAbs_Orientation bidOr; | |
2001 | return ChFi3d_Orientation(LI,igros,ipetit,bidOr,isvertex,aprendre); | |
2002 | } | |
065bb8b0 | 2003 | //======================================================================= |
2004 | //function : QueryAddVertexInEdge | |
2005 | //purpose : | |
2006 | //======================================================================= | |
2007 | static void QueryAddVertexInEdge(TopOpeBRepDS_ListOfInterference& LI, | |
2008 | const Standard_Integer IC, | |
2009 | const Standard_Integer IV, | |
2010 | const Standard_Real par, | |
2011 | const TopAbs_Orientation Or) | |
7fd59977 | 2012 | { |
2013 | TopOpeBRepDS_ListIteratorOfListOfInterference it(LI); | |
2014 | for (; it.More(); it.Next() ) { | |
2015 | const Handle(TopOpeBRepDS_Interference)& cur = it.Value(); | |
2016 | const Handle(TopOpeBRepDS_CurvePointInterference)& cpi = | |
2017 | Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(cur); | |
2018 | if(!cpi.IsNull()) { | |
2019 | Standard_Integer newIV = cpi->Geometry(); | |
2020 | TopOpeBRepDS_Kind kv = cpi->GeometryType(); | |
2021 | TopAbs_Orientation newOr = cpi->Transition().Orientation(TopAbs_IN); | |
2022 | Standard_Real newpar = cpi->Parameter(); | |
2023 | if(IV == newIV && kv == TopOpeBRepDS_VERTEX && | |
2024 | Or == newOr && Abs(par - newpar) < 1.e-10) { | |
2025 | return; | |
2026 | } | |
2027 | } | |
2028 | } | |
2029 | Handle(TopOpeBRepDS_CurvePointInterference) interf = | |
2030 | ChFi3d_FilVertexInDS(Or,IC,IV,par); | |
2031 | LI.Append(interf); | |
2032 | } | |
2033 | ||
065bb8b0 | 2034 | //======================================================================= |
2035 | //function : CutEdge | |
2036 | //purpose : | |
2037 | //======================================================================= | |
7fd59977 | 2038 | static void CutEdge(const TopoDS_Vertex& V, |
2039 | const Handle(ChFiDS_SurfData)& SD, | |
2040 | TopOpeBRepDS_DataStructure& DStr, | |
065bb8b0 | 2041 | const Standard_Boolean , |
7fd59977 | 2042 | const Standard_Integer ons) |
2043 | { | |
2044 | if(!SD->IsOnCurve(ons)) return; | |
2045 | Standard_Integer IC = SD->IndexOfC(ons); | |
2046 | Standard_Integer IV = DStr.AddShape(V); | |
2047 | TopOpeBRepDS_ListOfInterference& LI = DStr.ChangeShapeInterferences(IC); | |
2048 | TopoDS_Edge E = TopoDS::Edge(DStr.Shape(IC)); | |
2049 | E.Orientation(TopAbs_FORWARD); | |
2050 | TopExp_Explorer ex; | |
2051 | ||
81bba717 | 2052 | // process them checking that it has not been done already. |
7fd59977 | 2053 | for(ex.Init(E,TopAbs_VERTEX);ex.More();ex.Next()) { |
2054 | const TopoDS_Vertex& vv = TopoDS::Vertex(ex.Current()); | |
2055 | if(vv.IsSame(V)) { | |
2056 | TopAbs_Orientation Or = TopAbs::Reverse(vv.Orientation()); | |
2057 | Standard_Real par = BRep_Tool::Parameter(vv,E); | |
2058 | QueryAddVertexInEdge(LI,IC,IV,par,Or); | |
2059 | } | |
2060 | } | |
2061 | } | |
7fd59977 | 2062 | //======================================================================= |
2063 | //function : findIndexPoint | |
2064 | //purpose : returns in <ipon> index of point bounding a courve interfering | |
2065 | // with <Fd> and coinciding with last common point on <OnS> face | |
2066 | //======================================================================= | |
065bb8b0 | 2067 | static Standard_Boolean |
2068 | findIndexPoint(const TopOpeBRepDS_DataStructure& DStr, | |
2069 | const Handle(ChFiDS_SurfData)& Fd, | |
2070 | const Standard_Integer OnS, | |
2071 | Standard_Integer& ipoin) | |
7fd59977 | 2072 | { |
2073 | ipoin = 0; | |
2074 | gp_Pnt P = Fd->Vertex(Standard_False,OnS).Point(); | |
2075 | ||
2076 | TopOpeBRepDS_ListIteratorOfListOfInterference SCIIt, CPIIt; | |
2077 | ||
2078 | SCIIt.Initialize (DStr.SurfaceInterferences(Fd->Surf())); | |
2079 | for (; SCIIt.More(); SCIIt.Next()) { | |
2080 | Handle(TopOpeBRepDS_SurfaceCurveInterference) SCI = | |
2081 | Handle(TopOpeBRepDS_SurfaceCurveInterference)::DownCast(SCIIt.Value()); | |
2082 | if (SCI.IsNull()) continue; | |
2083 | CPIIt.Initialize (DStr.CurveInterferences(SCI->Geometry())); | |
2084 | for (; CPIIt.More(); CPIIt.Next()) { | |
2085 | Handle(TopOpeBRepDS_CurvePointInterference) CPI = | |
2086 | Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(CPIIt.Value()); | |
2087 | if (CPI.IsNull()) continue; | |
2088 | Standard_Integer iPoint = CPI->Geometry(); | |
2089 | TopOpeBRepDS_Point tp = DStr.Point(iPoint); | |
2090 | if (P.IsEqual(tp.Point(), tp.Tolerance())) { | |
2091 | ipoin = iPoint; | |
2092 | return Standard_True; | |
2093 | } | |
2094 | } | |
2095 | } | |
2096 | return Standard_False; | |
2097 | } | |
7fd59977 | 2098 | //======================================================================= |
2099 | //function : FilDS | |
2100 | //purpose : | |
2101 | //======================================================================= | |
7fd59977 | 2102 | void ChFi3d_FilDS(const Standard_Integer SolidIndex, |
2103 | const Handle(ChFiDS_Stripe)& CorDat, | |
2104 | TopOpeBRepDS_DataStructure& DStr, | |
2105 | ChFiDS_Regularities& reglist, | |
2106 | const Standard_Real tol3d, | |
2107 | const Standard_Real tol2d) | |
2108 | { | |
2109 | // BRep_Tool Outil; | |
2110 | TopExp_Explorer ex; | |
2111 | Handle(ChFiDS_Spine) spine = CorDat->Spine(); | |
2112 | Standard_Boolean Closed = Standard_False; | |
2113 | Standard_Boolean Degene = 0, isVertex1 = 0, isVertex2 = 0, Singulier_en_Bout = 0; | |
2114 | if(!spine.IsNull()) { | |
2115 | Closed = spine->IsPeriodic(); | |
2116 | } | |
2117 | const ChFiDS_SequenceOfSurfData& SeqFil = | |
2118 | CorDat->SetOfSurfData()->Sequence(); | |
2119 | Standard_Integer Ipoin1 = CorDat->IndexFirstPointOnS1(); | |
2120 | Standard_Integer Ipoin2 = CorDat->IndexFirstPointOnS2(); | |
2121 | Standard_Integer NumEdge = 1; | |
2122 | TopoDS_Vertex BoutdeVtx; | |
2123 | Standard_Integer Icurv = 0; | |
2124 | Standard_Integer Iarc1 = 0,Iarc2 = 0; | |
2125 | TopAbs_Orientation trafil1 = TopAbs_FORWARD, trafil2 = TopAbs_FORWARD; | |
2126 | Standard_Integer IcFil1,IcFil2,Isurf,Ishape1,Ishape2; | |
1d47d8d0 | 2127 | Standard_Real Pardeb = 0.,Parfin = 0.; |
7fd59977 | 2128 | TopAbs_Orientation ET1; |
2129 | Handle(TopOpeBRepDS_CurvePointInterference) Interfp1,Interfp2; | |
2130 | Handle(TopOpeBRepDS_SurfaceCurveInterference) Interfc1,Interfc2; | |
2131 | Handle(TopOpeBRepDS_SurfaceCurveInterference) Interfc3,Interfc4; | |
2132 | Handle(TopOpeBRepDS_CurvePointInterference) Interfp3,Interfp4; | |
2133 | Handle(TopOpeBRepDS_CurvePointInterference) Interfp5,Interfp6; | |
2134 | TopoDS_Face F; | |
2135 | Handle(Geom2d_Curve) PCurv; | |
2136 | TopOpeBRepDS_Curve Crv; | |
2137 | ||
2138 | TopOpeBRepDS_ListOfInterference& SolidInterfs = | |
2139 | DStr.ChangeShapeInterferences(SolidIndex); | |
2140 | ||
81bba717 | 2141 | ChFiDS_Regul regcout; // for closed and tangent CD |
2142 | ChFiDS_Regul regfilfil; // for connections Surf/Surf | |
7fd59977 | 2143 | |
2144 | ChFiDS_CommonPoint V3; | |
2145 | ChFiDS_CommonPoint V4; | |
2146 | ||
2147 | // Nullify degenerated ChFi/Faces interferences, eap occ293 | |
2148 | Standard_Integer j; | |
2149 | if (SeqFil.Length() > 1) { | |
2150 | for (j=1; j<=SeqFil.Length(); j++) { | |
2151 | Handle(ChFiDS_SurfData) Fd = SeqFil(j); | |
2152 | Standard_Integer onS; | |
2153 | for (onS=1; onS<=2; onS++) { | |
2154 | const ChFiDS_FaceInterference& Fi = Fd->Interference(onS); | |
2155 | IcFil1 = Fi.LineIndex(); | |
2156 | if (!IcFil1) continue; | |
2157 | Standard_Real FiLen = Abs(Fi.FirstParameter()-Fi.LastParameter()); | |
2158 | if (FiLen > Precision::PConfusion()) continue; | |
2159 | TopOpeBRepDS_Curve& cc = DStr.ChangeCurve(IcFil1); | |
2160 | cc.ChangeCurve().Nullify(); | |
065bb8b0 | 2161 | |
7fd59977 | 2162 | // care of CommonPoint, eap occ354 |
2163 | if (j!=1 && j!=SeqFil.Length()) continue; | |
2164 | Standard_Boolean isfirst = (j==1); | |
2165 | Standard_Integer i = isfirst ? j+1 : j-1; | |
2166 | ChFiDS_CommonPoint& CP1 = SeqFil(i)->ChangeVertex(isfirst,onS); | |
2167 | if (Fd->Vertex(isfirst,onS).IsOnArc() && CP1.IsOnArc()) { | |
2168 | ChFiDS_CommonPoint& CP2 = Fd->ChangeVertex(!isfirst,onS); | |
2169 | CP1.Reset(); | |
2170 | CP1.SetPoint(CP2.Point()); | |
2171 | CP2.Reset(); | |
2172 | CP2.SetPoint(CP1.Point()); | |
2173 | } | |
2174 | } | |
2175 | } | |
2176 | } | |
2177 | ||
2178 | for (j=1; j<=SeqFil.Length(); j++) { | |
2179 | ||
2180 | const Handle(ChFiDS_SurfData)& Fd = SeqFil(j); | |
2181 | Isurf= Fd->Surf(); | |
2182 | Ishape1 = Fd->IndexOfS1(); | |
2183 | Ishape2 = Fd->IndexOfS2(); | |
2184 | ||
2185 | // eap, Apr 29 2002, occ 293 | |
2186 | // now IsInDS() returns nb of surfaces at end being in DS; | |
2187 | // vars showing which end is in DS | |
2188 | Standard_Boolean isInDS1 = Standard_False, isInDS2 = Standard_False; | |
2189 | if (j <= CorDat->IsInDS(Standard_True)) { | |
2190 | isInDS1 = Standard_True; | |
2191 | isInDS2 = (j+1 <= CorDat->IsInDS(Standard_True)); | |
2192 | } | |
2193 | if (SeqFil.Length()-j < CorDat->IsInDS(Standard_False)) { | |
2194 | isInDS2 = Standard_True; | |
2195 | isInDS1 = isInDS1 || SeqFil.Length()-j+1 < CorDat->IsInDS(Standard_False); | |
2196 | } | |
2197 | ||
81bba717 | 2198 | // creation of SolidSurfaceInterference |
7fd59977 | 2199 | |
2200 | Handle(TopOpeBRepDS_SolidSurfaceInterference) | |
2201 | SSI = new TopOpeBRepDS_SolidSurfaceInterference | |
2202 | (TopOpeBRepDS_Transition(Fd->Orientation()), | |
2203 | TopOpeBRepDS_SOLID, | |
2204 | SolidIndex, | |
2205 | TopOpeBRepDS_SURFACE, | |
2206 | Isurf); | |
2207 | ||
2208 | SolidInterfs.Append(SSI); | |
2209 | ||
2210 | const ChFiDS_FaceInterference& Fi1 = Fd->InterferenceOnS1(); | |
2211 | const ChFiDS_FaceInterference& Fi2 = Fd->InterferenceOnS2(); | |
2212 | const ChFiDS_CommonPoint& V1 = Fd->VertexFirstOnS1(); | |
2213 | const ChFiDS_CommonPoint& V2 = Fd->VertexFirstOnS2(); | |
2214 | ||
81bba717 | 2215 | // Processing to manage double interferences |
7fd59977 | 2216 | if (j>1) { |
2217 | if (V1.IsOnArc() && V3.IsOnArc() && V1.Arc().IsSame(V3.Arc())) { | |
81bba717 | 2218 | //Iarc1 is initialized |
7fd59977 | 2219 | //Iarc1 = DStr.AddShape(V1.Arc()); |
2220 | if (ChFi3d_Contains(DStr.ShapeInterferences(Iarc1),Iarc1,Ipoin1) && | |
2221 | (V1.TransitionOnArc() != V3.TransitionOnArc()) ) { | |
2222 | Interfp1= ChFi3d_FilPointInDS(V1.TransitionOnArc(),Iarc1,Ipoin1, | |
2223 | V1.ParameterOnArc()); | |
2224 | DStr.ChangeShapeInterferences(V1.Arc()).Append(Interfp1); | |
2225 | } | |
2226 | } | |
2227 | ||
2228 | if (V2.IsOnArc() && V4.IsOnArc() && V2.Arc().IsSame(V4.Arc())) { | |
81bba717 | 2229 | //Iarc2 is initialized |
7fd59977 | 2230 | //Iarc2 = DStr.AddShape(V2.Arc()); |
2231 | if ( ChFi3d_Contains(DStr.ShapeInterferences(Iarc2),Iarc2,Ipoin2) && | |
2232 | (V2.TransitionOnArc() != V4.TransitionOnArc()) ) { | |
2233 | Interfp2= ChFi3d_FilPointInDS(V2.TransitionOnArc(),Iarc2,Ipoin2, | |
2234 | V2.ParameterOnArc()); | |
2235 | DStr.ChangeShapeInterferences(V2.Arc()).Append(Interfp2); | |
2236 | } | |
2237 | } | |
2238 | } | |
2239 | ||
2240 | V3 = Fd->VertexLastOnS1(); | |
2241 | V4 = Fd->VertexLastOnS2(); | |
2242 | ||
2243 | if(Ishape1 != 0) { | |
2244 | if(Ishape1 > 0) { | |
2245 | trafil1 = DStr.Shape(Ishape1).Orientation(); | |
2246 | } | |
2247 | else{ | |
2248 | ChFi3d_Orientation(SolidInterfs,SolidIndex,-Ishape1,trafil1); | |
2249 | } | |
2250 | trafil1 = TopAbs::Compose(trafil1,Fd->Orientation()); | |
2251 | trafil1 = TopAbs::Compose(TopAbs::Reverse(Fi1.Transition()),trafil1); | |
2252 | trafil2 = TopAbs::Reverse(trafil1); | |
2253 | } | |
2254 | else{ | |
2255 | if(Ishape2 > 0) { | |
2256 | trafil2 = DStr.Shape(Ishape2).Orientation(); | |
2257 | } | |
2258 | else{ | |
2259 | ChFi3d_Orientation(SolidInterfs,SolidIndex,-Ishape2,trafil2); | |
2260 | } | |
2261 | trafil2 = TopAbs::Compose(trafil2,Fd->Orientation()); | |
2262 | trafil2 = TopAbs::Compose(TopAbs::Reverse(Fi2.Transition()),trafil2); | |
2263 | trafil1 = TopAbs::Reverse(trafil2); | |
2264 | } | |
2265 | ||
2266 | ET1 = TopAbs::Reverse(trafil1); | |
2267 | ||
81bba717 | 2268 | // A small paragraph to process contacts of edges, which touch |
2269 | // a vertex of the obstacle. | |
7fd59977 | 2270 | if(V1.IsVertex() && Fd->IsOnCurve1()) { |
2271 | const TopoDS_Vertex& vv1 = V1.Vertex(); | |
2272 | CutEdge(vv1,Fd,DStr,1,1); | |
2273 | } | |
2274 | if(V2.IsVertex() && Fd->IsOnCurve2()) { | |
2275 | const TopoDS_Vertex& vv2 = V2.Vertex(); | |
2276 | CutEdge(vv2,Fd,DStr,1,2); | |
2277 | } | |
2278 | if(V3.IsVertex() && Fd->IsOnCurve1()) { | |
2279 | const TopoDS_Vertex& vv3 = V3.Vertex(); | |
2280 | CutEdge(vv3,Fd,DStr,0,1); | |
2281 | } | |
2282 | if(V4.IsVertex() && Fd->IsOnCurve2()) { | |
2283 | const TopoDS_Vertex& vv4 = V4.Vertex(); | |
2284 | CutEdge(vv4,Fd,DStr,0,2); | |
2285 | } | |
2286 | ||
2287 | if (j == 1) { | |
2288 | isVertex1 = V1.IsVertex(); | |
2289 | isVertex2 = V2.IsVertex(); | |
2290 | Singulier_en_Bout = (V1.Point().IsEqual(V2.Point(), 0)); | |
2291 | ||
2292 | if (Singulier_en_Bout) { | |
065bb8b0 | 2293 | // Queue de Billard |
7fd59977 | 2294 | if ((!V1.IsVertex()) || (!V2.IsVertex())) { |
065bb8b0 | 2295 | |
7fd59977 | 2296 | } |
2297 | else { | |
81bba717 | 2298 | isVertex1 = isVertex2 = Standard_True; //caution... |
2299 | // The edge is removed from spine starting on this vertex. | |
7fd59977 | 2300 | TopoDS_Edge Arcspine = spine->Edges(1); |
2301 | BoutdeVtx = V1.Vertex(); | |
2302 | Standard_Integer IArcspine = DStr.AddShape(Arcspine); | |
2303 | Standard_Integer IVtx = CorDat->IndexFirstPointOnS1(); | |
065bb8b0 | 2304 | |
2305 | TopAbs_Orientation OVtx = TopAbs_FORWARD;; | |
2306 | ||
7fd59977 | 2307 | for(ex.Init(Arcspine.Oriented(TopAbs_FORWARD),TopAbs_VERTEX); |
2308 | ex.More(); ex.Next()) { | |
2309 | if(BoutdeVtx.IsSame(ex.Current())) { | |
2310 | OVtx = ex.Current().Orientation(); | |
2311 | break; | |
2312 | } | |
2313 | } | |
2314 | OVtx = TopAbs::Reverse(OVtx); | |
2315 | Standard_Real parVtx = BRep_Tool::Parameter(BoutdeVtx,Arcspine); | |
2316 | Handle(TopOpeBRepDS_CurvePointInterference) | |
2317 | interfv = ChFi3d_FilVertexInDS(OVtx,IArcspine,IVtx,parVtx); | |
2318 | DStr.ChangeShapeInterferences(IArcspine).Append(interfv); | |
2319 | } | |
2320 | } | |
2321 | else { | |
2322 | if (V1.IsOnArc()) { | |
2323 | Iarc1 = DStr.AddShape(V1.Arc()); | |
2324 | if ( !ChFi3d_Contains(DStr.ShapeInterferences(Iarc1),Iarc1,Ipoin1) ) { | |
2325 | Interfp1= ChFi3d_FilPointInDS(V1.TransitionOnArc(),Iarc1,Ipoin1, | |
2326 | V1.ParameterOnArc(), isVertex1); | |
2327 | DStr.ChangeShapeInterferences(V1.Arc()).Append(Interfp1); | |
2328 | } | |
2329 | } | |
2330 | ||
2331 | if (V2.IsOnArc()) { | |
2332 | Iarc2 = DStr.AddShape(V2.Arc()); | |
2333 | if ( !ChFi3d_Contains(DStr.ShapeInterferences(Iarc2),Iarc2,Ipoin2) ) { | |
2334 | Interfp2= ChFi3d_FilPointInDS(V2.TransitionOnArc(),Iarc2,Ipoin2, | |
2335 | V2.ParameterOnArc(),isVertex2); | |
2336 | DStr.ChangeShapeInterferences(V2.Arc()).Append(Interfp2); | |
2337 | } | |
2338 | } | |
2339 | } | |
2340 | ||
2341 | if (!isInDS1) { | |
2342 | ET1 = TopAbs::Compose(ET1,CorDat->FirstPCurveOrientation()); | |
2343 | Icurv = CorDat->FirstCurve(); | |
2344 | if(Closed && !Singulier_en_Bout) { | |
2345 | regcout.SetCurve(Icurv); | |
2346 | regcout.SetS1(Isurf,Standard_False); | |
2347 | } | |
2348 | PCurv = CorDat->FirstPCurve(); | |
2349 | CorDat->FirstParameters(Pardeb,Parfin); | |
2350 | ||
2351 | TopOpeBRepDS_ListOfInterference& Li = DStr.ChangeCurveInterferences(Icurv); | |
2352 | if (Li.IsEmpty()) { | |
2353 | if(CorDat->FirstPCurveOrientation()==TopAbs_REVERSED) { | |
2354 | Interfp1=ChFi3d_FilPointInDS | |
2355 | (TopAbs_REVERSED,Icurv,Ipoin1,Parfin,isVertex1); | |
2356 | Interfp2=ChFi3d_FilPointInDS | |
2357 | (TopAbs_FORWARD,Icurv,Ipoin2,Pardeb,isVertex2); | |
2358 | } | |
2359 | else{ | |
2360 | Interfp1=ChFi3d_FilPointInDS | |
2361 | (TopAbs_FORWARD,Icurv,Ipoin1,Pardeb,isVertex1); | |
2362 | Interfp2=ChFi3d_FilPointInDS | |
2363 | (TopAbs_REVERSED,Icurv,Ipoin2,Parfin,isVertex2); | |
2364 | } | |
2365 | Li.Append(Interfp1); | |
2366 | Li.Append(Interfp2); | |
2367 | } | |
2368 | Interfc1= ChFi3d_FilCurveInDS (Icurv,Isurf,PCurv,ET1); | |
2369 | DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc1); | |
2370 | if (Ipoin1 == Ipoin2) { | |
2371 | TopOpeBRepDS_Curve& TCurv = DStr.ChangeCurve(Icurv); | |
2372 | TCurv.ChangeCurve().Nullify(); | |
2373 | Handle(TopOpeBRepDS_Interference) bidinterf; | |
2374 | TCurv.SetSCI(Interfc1,bidinterf); | |
2375 | } | |
2376 | } | |
81bba717 | 2377 | } // End of the Initial Processing (j==1) |
7fd59977 | 2378 | else { |
81bba717 | 2379 | // ---- Interference between Fillets ------ |
7fd59977 | 2380 | |
2381 | if (!isInDS1) {// eap, Apr 29 2002, occ 293 | |
2382 | ||
2383 | if (Degene && isVertex1) { | |
81bba717 | 2384 | // The edge is removed from the spine starting on this vertex. |
2385 | NumEdge++; // The previous edge of the vertex has already been found. | |
7fd59977 | 2386 | TopoDS_Edge Arcspine = spine->Edges(NumEdge); |
2387 | Standard_Integer IArcspine = DStr.AddShape(Arcspine); | |
2388 | Standard_Integer IVtx = DStr.AddShape(BoutdeVtx); | |
7fd59977 | 2389 | TopAbs_Orientation OVtx = TopAbs_FORWARD; |
7fd59977 | 2390 | for(ex.Init(Arcspine.Oriented(TopAbs_FORWARD),TopAbs_VERTEX); |
2391 | ex.More(); ex.Next()) { | |
2392 | if(BoutdeVtx.IsSame(ex.Current())) { | |
2393 | OVtx = ex.Current().Orientation(); | |
2394 | break; | |
2395 | } | |
2396 | } | |
2397 | OVtx = TopAbs::Reverse(OVtx); | |
2398 | Standard_Real parVtx = BRep_Tool::Parameter(BoutdeVtx,Arcspine); | |
2399 | Handle(TopOpeBRepDS_CurvePointInterference) | |
2400 | interfv = ChFi3d_FilVertexInDS(OVtx,IArcspine,IVtx,parVtx); | |
2401 | DStr.ChangeShapeInterferences(IArcspine).Append(interfv); | |
81bba717 | 2402 | } // End of the removal |
7fd59977 | 2403 | |
2404 | gp_Pnt2d UV1 = Fd->InterferenceOnS1().PCurveOnSurf()-> | |
2405 | Value(Fd->InterferenceOnS1().FirstParameter()); | |
2406 | gp_Pnt2d UV2 = Fd->InterferenceOnS2().PCurveOnSurf()-> | |
2407 | Value(Fd->InterferenceOnS2().FirstParameter()); | |
2408 | TopOpeBRepDS_Curve& TCurv = DStr.ChangeCurve(Icurv); | |
2409 | if (Degene) { | |
81bba717 | 2410 | // pcurve is associated via SCI to TopOpeBRepDSCurve. |
7fd59977 | 2411 | ChFi3d_ComputePCurv(UV1,UV2,PCurv,Pardeb,Parfin); |
2412 | Interfc1= ChFi3d_FilCurveInDS (Icurv,Isurf,PCurv,ET1); | |
2413 | DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc1); | |
2414 | TCurv.ChangeCurve().Nullify(); | |
2415 | Handle(TopOpeBRepDS_Interference) bidinterf; | |
2416 | TCurv.SetSCI(Interfc1,bidinterf); | |
2417 | } | |
2418 | else { | |
2419 | regfilfil.SetS2(Isurf,Standard_False); | |
2420 | reglist.Append(regfilfil); | |
2421 | Standard_Real tolreached; | |
2422 | ChFi3d_ComputePCurv(TCurv.ChangeCurve(),UV1,UV2,PCurv, | |
2423 | DStr.Surface(Fd->Surf()).Surface(), | |
2424 | Pardeb,Parfin,tol3d,tolreached); | |
2425 | TCurv.Tolerance(Max(TCurv.Tolerance(),tolreached)); | |
2426 | Interfc1= ChFi3d_FilCurveInDS (Icurv,Isurf,PCurv,ET1); | |
2427 | DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc1); | |
2428 | } | |
2429 | } | |
81bba717 | 2430 | } // End of Interference between fillets |
7fd59977 | 2431 | |
81bba717 | 2432 | // ---- Interference Fillets / Faces |
7fd59977 | 2433 | IcFil1 = Fi1.LineIndex(); |
2434 | ||
2435 | if (IcFil1!=0 ) { | |
2436 | Interfc3= ChFi3d_FilCurveInDS (IcFil1,Isurf, | |
2437 | Fi1.PCurveOnSurf(),trafil1); | |
2438 | DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc3); | |
2439 | Ishape1 = Fd->IndexOfS1(); | |
81bba717 | 2440 | // Case of degenerated edge : pcurve is associated via SCI |
2441 | // to TopOpeBRepDSCurve. | |
7fd59977 | 2442 | TopOpeBRepDS_Curve& cc = DStr.ChangeCurve(IcFil1); |
2443 | if(cc.Curve().IsNull()) { | |
2444 | Handle(TopOpeBRepDS_Interference) bidinterf; | |
2445 | cc.SetSCI(Interfc3,bidinterf); | |
2446 | } | |
2447 | else{ | |
2448 | ChFiDS_Regul regon1; | |
2449 | regon1.SetCurve(IcFil1); | |
2450 | regon1.SetS1(Isurf,Standard_False); | |
2451 | if ( Ishape1 < 0 ) { | |
2452 | Ishape1 = -Ishape1; | |
2453 | regon1.SetS2(Ishape1,Standard_False); | |
2454 | Interfc1=ChFi3d_FilCurveInDS(IcFil1,Ishape1,Fi1.PCurveOnFace(), | |
2455 | Fi1.Transition()); | |
2456 | DStr.ChangeSurfaceInterferences(Ishape1).Append(Interfc1); | |
2457 | } | |
2458 | else if ( Ishape1 > 0 ) { | |
2459 | regon1.SetS2(Ishape1,Standard_True); | |
2460 | Interfc1=ChFi3d_FilCurveInDS(IcFil1,Ishape1,Fi1.PCurveOnFace(), | |
2461 | Fi1.Transition()); | |
2462 | DStr.ChangeShapeInterferences(Ishape1).Append(Interfc1); | |
2463 | } | |
2464 | reglist.Append(regon1); | |
2465 | } | |
81bba717 | 2466 | // Indice and type of the point at End |
7fd59977 | 2467 | Standard_Integer ipoin; |
2468 | Standard_Boolean isVertex = Fd->VertexLastOnS1().IsVertex(); | |
2469 | if (j == SeqFil.Length()) ipoin = CorDat->IndexLastPointOnS1(); | |
2470 | else if ( j == (SeqFil.Length()-1) && /*Closed &&*/ | |
2471 | (DStr.Curve(SeqFil.Last()->InterferenceOnS1(). | |
2472 | LineIndex()).Curve().IsNull())) { | |
2473 | if (Closed) { | |
2474 | ipoin = CorDat->IndexFirstPointOnS1(); | |
2475 | isVertex = SeqFil(1)->VertexFirstOnS1().IsVertex(); | |
2476 | } else { | |
2477 | ipoin = CorDat->IndexLastPointOnS1(); | |
2478 | isVertex = SeqFil.Last()->VertexLastOnS1().IsVertex(); | |
2479 | } | |
2480 | } | |
2481 | else if(DStr.Curve(IcFil1).Curve().IsNull()) {// Rotation !! | |
2482 | ipoin = Ipoin1; | |
2483 | isVertex = isVertex1; | |
2484 | } | |
2485 | else if ( ((j==1) || (j== SeqFil.Length()-1)) && | |
2486 | ( (Fd->VertexLastOnS1().Point().IsEqual( | |
2487 | SeqFil(1)->VertexFirstOnS1().Point(), 1.e-7)) || | |
2488 | (Fd->VertexLastOnS1().Point().IsEqual( | |
2489 | SeqFil(SeqFil.Length())->VertexLastOnS1().Point(), 1.e-7))) ) | |
81bba717 | 2490 | // Case of SurfData cut in "Triangular" way. |
7fd59977 | 2491 | ipoin=CorDat->IndexLastPointOnS1(); |
2492 | ||
2493 | // eap, Apr 29 2002, occ 293 | |
2494 | else if (isInDS2 && findIndexPoint(DStr, Fd, 1, ipoin)) { | |
065bb8b0 | 2495 | |
7fd59977 | 2496 | } |
2497 | else ipoin = ChFi3d_IndexPointInDS(Fd->VertexLastOnS1(),DStr); | |
2498 | ||
2499 | TopOpeBRepDS_ListOfInterference& Li = DStr.ChangeCurveInterferences(IcFil1); | |
065bb8b0 | 2500 | |
7fd59977 | 2501 | if (!ChFi3d_Contains(Li,IcFil1,Ipoin1)) { |
2502 | ||
2503 | Interfp1 = ChFi3d_FilPointInDS(TopAbs_FORWARD,IcFil1,Ipoin1, | |
2504 | Fi1.FirstParameter(),isVertex1); | |
2505 | DStr.ChangeCurveInterferences(IcFil1).Append(Interfp1); | |
2506 | } | |
2507 | if (ipoin == Ipoin1 || !ChFi3d_Contains(Li,IcFil1,ipoin)) { | |
2508 | Interfp3 = ChFi3d_FilPointInDS(TopAbs_REVERSED,IcFil1,ipoin, | |
2509 | Fi1.LastParameter(), isVertex); | |
2510 | DStr.ChangeCurveInterferences(IcFil1).Append(Interfp3); | |
2511 | } | |
2512 | Ipoin1 = ipoin; | |
2513 | isVertex1 = isVertex; | |
2514 | } | |
2515 | ||
2516 | IcFil2 = Fi2.LineIndex(); | |
2517 | if (IcFil2!=0) { | |
2518 | Interfc4=ChFi3d_FilCurveInDS(IcFil2,Isurf, | |
2519 | Fi2.PCurveOnSurf(),trafil2); | |
2520 | DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc4); | |
2521 | Ishape2 = Fd->IndexOfS2(); | |
81bba717 | 2522 | // Case of degenerated edge : pcurve is associated via SCI |
2523 | // to TopOpeBRepDSCurve. | |
7fd59977 | 2524 | TopOpeBRepDS_Curve& cc = DStr.ChangeCurve(IcFil2); |
2525 | if(cc.Curve().IsNull()) { | |
2526 | Handle(TopOpeBRepDS_Interference) bidinterf; | |
2527 | cc.SetSCI(Interfc4,bidinterf); | |
2528 | } | |
2529 | else{ | |
2530 | ChFiDS_Regul regon2; | |
2531 | regon2.SetCurve(IcFil2); | |
2532 | regon2.SetS1(Isurf,Standard_False); | |
2533 | if ( Ishape2 < 0 ) { | |
2534 | Ishape2 = -Ishape2; | |
2535 | regon2.SetS2(Ishape2,Standard_False); | |
2536 | Interfc2=ChFi3d_FilCurveInDS(IcFil2,Ishape2,Fi2.PCurveOnFace(), | |
2537 | Fi2.Transition()); | |
2538 | DStr.ChangeSurfaceInterferences(Ishape2).Append(Interfc2); | |
2539 | } | |
2540 | else if ( Ishape2 > 0 ) { | |
2541 | regon2.SetS2(Ishape2,Standard_True); | |
2542 | Interfc2=ChFi3d_FilCurveInDS(IcFil2,Ishape2,Fi2.PCurveOnFace(), | |
2543 | Fi2.Transition()); | |
2544 | DStr.ChangeShapeInterferences(Ishape2).Append(Interfc2); | |
2545 | } | |
2546 | reglist.Append(regon2); | |
2547 | } | |
81bba717 | 2548 | // Indice and type of the point in End |
7fd59977 | 2549 | Standard_Integer ipoin; |
2550 | Standard_Boolean isVertex = Fd->VertexLastOnS2().IsVertex(); | |
2551 | if (j == SeqFil.Length() ) ipoin = CorDat->IndexLastPointOnS2(); | |
2552 | else if ( j == (SeqFil.Length()-1) && /*Closed &&*/ | |
2553 | (DStr.Curve(SeqFil.Last()->InterferenceOnS2(). | |
2554 | LineIndex()).Curve().IsNull())) { | |
2555 | if (Closed) { | |
2556 | ipoin = CorDat->IndexFirstPointOnS2(); | |
2557 | isVertex = SeqFil(1)->VertexFirstOnS2().IsVertex(); | |
2558 | } else { | |
2559 | ipoin = CorDat->IndexLastPointOnS2(); | |
2560 | isVertex = SeqFil.Last()->VertexLastOnS2().IsVertex(); | |
2561 | } | |
2562 | } | |
2563 | else if(DStr.Curve(IcFil2).Curve().IsNull()) { // Rotation !! | |
2564 | ipoin = Ipoin2; | |
2565 | isVertex = isVertex2; | |
2566 | } | |
2567 | else if(Fd->VertexLastOnS2().Point().IsEqual( | |
81bba717 | 2568 | Fd->VertexLastOnS1().Point(), 0) ) { //Pinch !! |
7fd59977 | 2569 | ipoin = Ipoin1; |
2570 | isVertex = isVertex1; | |
2571 | } | |
2572 | else if ( ((j==1) || (j==SeqFil.Length()-1)) && | |
2573 | ( (Fd->VertexLastOnS2().Point().IsEqual( | |
2574 | SeqFil(1)->VertexFirstOnS2().Point(), 1.e-7)) || | |
2575 | (Fd->VertexLastOnS2().Point().IsEqual( | |
2576 | SeqFil(SeqFil.Length())->VertexLastOnS2().Point(), 1.e-7))) ) | |
81bba717 | 2577 | // Case of SurfData cut in "Triangular" way. |
7fd59977 | 2578 | ipoin=CorDat->IndexLastPointOnS2(); |
2579 | ||
2580 | // eap, Apr 29 2002, occ 293 | |
2581 | else if (isInDS2 && findIndexPoint(DStr, Fd, 2, ipoin)) { | |
065bb8b0 | 2582 | |
7fd59977 | 2583 | } |
2584 | else ipoin = ChFi3d_IndexPointInDS(Fd->VertexLastOnS2(),DStr); | |
2585 | ||
2586 | TopOpeBRepDS_ListOfInterference& Li = DStr.ChangeCurveInterferences(IcFil2); | |
065bb8b0 | 2587 | |
7fd59977 | 2588 | if (!ChFi3d_Contains(Li,IcFil2,Ipoin2)) { |
2589 | Interfp2 = ChFi3d_FilPointInDS(TopAbs_FORWARD,IcFil2,Ipoin2, | |
2590 | Fi2.FirstParameter(), isVertex2); | |
2591 | DStr.ChangeCurveInterferences(IcFil2).Append(Interfp2); | |
2592 | } | |
2593 | if (ipoin == Ipoin2 || !ChFi3d_Contains(Li,IcFil2,ipoin)) { | |
2594 | Interfp4= ChFi3d_FilPointInDS(TopAbs_REVERSED,IcFil2,ipoin, | |
2595 | Fi2.LastParameter(), isVertex ); | |
2596 | DStr.ChangeCurveInterferences(IcFil2).Append(Interfp4); | |
2597 | } | |
2598 | Ipoin2 = ipoin; | |
2599 | isVertex2 = isVertex; | |
2600 | } | |
2601 | ||
2602 | ET1 = trafil1; | |
2603 | if (j == SeqFil.Length()) { | |
2604 | if (!isInDS2) { | |
2605 | Icurv = CorDat->LastCurve(); | |
2606 | if(Closed && !Singulier_en_Bout && (Ipoin1!=Ipoin2)) { | |
2607 | regcout.SetS2(Isurf,Standard_False); | |
2608 | reglist.Append(regcout); | |
2609 | } | |
2610 | PCurv = CorDat->LastPCurve(); | |
2611 | ET1 = TopAbs::Compose(ET1,CorDat->LastPCurveOrientation()); | |
2612 | CorDat->LastParameters(Pardeb,Parfin); | |
2613 | TopOpeBRepDS_ListOfInterference& Li = DStr.ChangeCurveInterferences(Icurv); | |
2614 | if (Li.IsEmpty()) { | |
2615 | if(CorDat->LastPCurveOrientation()==TopAbs_REVERSED) { | |
2616 | Interfp5=ChFi3d_FilPointInDS | |
2617 | (TopAbs_REVERSED,Icurv,Ipoin1,Parfin, isVertex1); | |
2618 | Interfp6=ChFi3d_FilPointInDS | |
2619 | (TopAbs_FORWARD,Icurv,Ipoin2,Pardeb, isVertex2); | |
2620 | } | |
2621 | else{ | |
2622 | Interfp5=ChFi3d_FilPointInDS | |
2623 | (TopAbs_FORWARD,Icurv,Ipoin1,Pardeb, isVertex1); | |
2624 | Interfp6=ChFi3d_FilPointInDS | |
2625 | (TopAbs_REVERSED,Icurv,Ipoin2,Parfin, isVertex2); | |
2626 | } | |
2627 | Li.Append(Interfp5); | |
2628 | Li.Append(Interfp6); | |
2629 | } | |
2630 | Interfc1= ChFi3d_FilCurveInDS(Icurv,Isurf,PCurv,ET1); | |
2631 | DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc1); | |
2632 | if (Ipoin1 == Ipoin2) { | |
2633 | TopOpeBRepDS_Curve& TCurv = DStr.ChangeCurve(Icurv); | |
2634 | TCurv.ChangeCurve().Nullify(); | |
2635 | Handle(TopOpeBRepDS_Interference) bidinterf; | |
2636 | TCurv.SetSCI( Interfc1, bidinterf); | |
2637 | // bidinterf = TCurv.GetSCI1(); | |
2638 | // TCurv.SetSCI(bidinterf, Interfc1); | |
2639 | } | |
2640 | } | |
2641 | } | |
2642 | else { | |
2643 | // Degene = (Fd->VertexLastOnS1().Point().IsEqual( | |
2644 | // Fd->VertexLastOnS2().Point(), 0) ); | |
2645 | ||
2646 | // eap, Apr 29 2002, occ 293 | |
2647 | if (!isInDS2) { | |
2648 | ||
2649 | Handle(Geom_Curve) C3d; | |
2650 | Standard_Real tolreached; | |
2651 | ChFi3d_ComputeArete(Fd->VertexLastOnS1(), | |
2652 | Fd->InterferenceOnS1().PCurveOnSurf()-> | |
2653 | Value(Fd->InterferenceOnS1().LastParameter()), | |
2654 | Fd->VertexLastOnS2(), | |
2655 | Fd->InterferenceOnS2().PCurveOnSurf()-> | |
2656 | Value(Fd->InterferenceOnS2().LastParameter()), | |
2657 | DStr.Surface(Fd->Surf()).Surface(),C3d,PCurv, | |
2658 | Pardeb,Parfin,tol3d,tol2d,tolreached,0); | |
2659 | Crv = TopOpeBRepDS_Curve(C3d,tolreached); | |
2660 | Icurv = DStr.AddCurve(Crv); | |
2661 | regfilfil.SetCurve(Icurv); | |
2662 | regfilfil.SetS1(Isurf,Standard_False); | |
2663 | Interfp5 = ChFi3d_FilPointInDS(TopAbs_FORWARD,Icurv,Ipoin1,Pardeb, isVertex1); | |
2664 | DStr.ChangeCurveInterferences(Icurv).Append(Interfp5); | |
2665 | Interfp6= ChFi3d_FilPointInDS(TopAbs_REVERSED,Icurv,Ipoin2,Parfin, isVertex2); | |
2666 | DStr.ChangeCurveInterferences(Icurv).Append(Interfp6); | |
2667 | Interfc1= ChFi3d_FilCurveInDS(Icurv,Isurf,PCurv,ET1); | |
2668 | DStr.ChangeSurfaceInterferences(Isurf).Append(Interfc1); | |
2669 | } | |
2670 | } | |
2671 | ||
2672 | Degene = V3.Point().IsEqual(V4.Point(), 0); | |
2673 | ||
81bba717 | 2674 | // Processing of degenerated case |
7fd59977 | 2675 | if (Degene) { |
065bb8b0 | 2676 | // Queue de Billard |
7fd59977 | 2677 | Standard_Boolean Vertex = (V3.IsVertex()) && (V4.IsVertex()); |
2678 | if (!Vertex) { | |
065bb8b0 | 2679 | |
7fd59977 | 2680 | } |
2681 | else { | |
81bba717 | 2682 | // The edge of the spine starting on this vertex is removed. |
7fd59977 | 2683 | Standard_Boolean Trouve = Standard_False; |
2684 | TopoDS_Edge Arcspine; | |
7fd59977 | 2685 | TopAbs_Orientation OVtx = TopAbs_FORWARD; |
7fd59977 | 2686 | BoutdeVtx = V3.Vertex(); |
2687 | ||
2688 | while (NumEdge<= spine->NbEdges() && !Trouve) { | |
2689 | Arcspine = spine->Edges(NumEdge); | |
2690 | for(ex.Init(Arcspine.Oriented(TopAbs_FORWARD),TopAbs_VERTEX); | |
2691 | ex.More() && (!Trouve); ex.Next()) { | |
2692 | if(BoutdeVtx.IsSame(ex.Current())) { | |
2693 | OVtx = ex.Current().Orientation(); | |
2694 | if (Closed && (NumEdge == 1)) | |
2695 | Trouve = (spine->NbEdges() == 1); | |
2696 | else Trouve = Standard_True; | |
2697 | } | |
2698 | } | |
81bba717 | 2699 | if (!Trouve) NumEdge++; // Go to the next edge |
7fd59977 | 2700 | } |
2701 | Standard_Integer IArcspine = DStr.AddShape(Arcspine); | |
2702 | Standard_Integer IVtx; | |
2703 | if (j == SeqFil.Length()) { | |
2704 | IVtx = CorDat->IndexLastPointOnS1(); | |
2705 | } | |
2706 | else { IVtx = DStr.AddShape(BoutdeVtx); } | |
2707 | OVtx = TopAbs::Reverse(OVtx); | |
2708 | Standard_Real parVtx = BRep_Tool::Parameter(BoutdeVtx,Arcspine); | |
2709 | Handle(TopOpeBRepDS_CurvePointInterference) | |
2710 | interfv = ChFi3d_FilVertexInDS(OVtx,IArcspine,IVtx,parVtx); | |
2711 | DStr.ChangeShapeInterferences(IArcspine).Append(interfv); | |
2712 | } | |
81bba717 | 2713 | } // end of degenerated case |
7fd59977 | 2714 | else if (!(Closed && j == SeqFil.Length())) { |
81bba717 | 2715 | // Processing of interference Point / Edges |
7fd59977 | 2716 | if (V3.IsOnArc()) { |
2717 | if(!(V3.IsVertex() && Fd->IsOnCurve1())) { | |
2718 | Iarc1 = DStr.AddShape(V3.Arc()); | |
2719 | if ( !ChFi3d_Contains(DStr.ShapeInterferences(Iarc1),Iarc1,Ipoin1,V3.IsVertex(),Standard_True) ) { | |
2720 | Handle(TopOpeBRepDS_CurvePointInterference) Interfpp = | |
2721 | ChFi3d_FilPointInDS(V3.TransitionOnArc(), | |
2722 | Iarc1,Ipoin1,V3.ParameterOnArc(), V3.IsVertex()); | |
2723 | DStr.ChangeShapeInterferences(V3.Arc()).Append(Interfpp); | |
2724 | } | |
2725 | } | |
2726 | } | |
2727 | ||
2728 | if (V4.IsOnArc()) { | |
2729 | if(!(V4.IsVertex() && Fd->IsOnCurve2())) { | |
2730 | Iarc2 = DStr.AddShape(V4.Arc()); | |
2731 | if ( !ChFi3d_Contains(DStr.ShapeInterferences(Iarc2),Iarc2,Ipoin2,V4.IsVertex(),Standard_True) ) { | |
2732 | Handle(TopOpeBRepDS_CurvePointInterference) Intfpp= | |
2733 | ChFi3d_FilPointInDS(V4.TransitionOnArc(), | |
2734 | Iarc2,Ipoin2,V4.ParameterOnArc(), V4.IsVertex()); | |
2735 | DStr.ChangeShapeInterferences(V4.Arc()).Append(Intfpp); | |
2736 | } | |
2737 | } | |
2738 | } | |
2739 | } | |
2740 | } | |
2741 | } | |
7fd59977 | 2742 | //======================================================================= |
2743 | //function : StripeEdgeInter | |
2744 | //purpose : This function examines two stripes for an intersection | |
2745 | // between curves of interference with faces. If the intersection | |
2746 | // exists, it will cause bad result, so it's better to quit. | |
2747 | //remark : If someone somewhen computes the interference between stripes, | |
2748 | // this function will become useless. | |
2749 | //author : akm, 06/02/02. Against bug OCC119. | |
2750 | //======================================================================= | |
7fd59977 | 2751 | void ChFi3d_StripeEdgeInter (const Handle(ChFiDS_Stripe)& theStripe1, |
2752 | const Handle(ChFiDS_Stripe)& theStripe2, | |
2753 | TopOpeBRepDS_DataStructure& /*DStr*/, | |
2754 | const Standard_Real tol2d) | |
2755 | { | |
2756 | // Do not check the stripeshaving common corner points | |
2757 | for (Standard_Integer iSur1=1; iSur1<=2; iSur1++) | |
2758 | for (Standard_Integer iSur2=1; iSur2<=2; iSur2++) | |
2759 | if (theStripe1->IndexPoint(0,iSur1)==theStripe2->IndexPoint(0,iSur2) || | |
2760 | theStripe1->IndexPoint(0,iSur1)==theStripe2->IndexPoint(1,iSur2) || | |
2761 | theStripe1->IndexPoint(1,iSur1)==theStripe2->IndexPoint(0,iSur2) || | |
2762 | theStripe1->IndexPoint(1,iSur1)==theStripe2->IndexPoint(1,iSur2)) | |
2763 | return; | |
2764 | ||
2765 | Handle(ChFiDS_HData) aSurDat1 = theStripe1->SetOfSurfData(); | |
2766 | Handle(ChFiDS_HData) aSurDat2 = theStripe2->SetOfSurfData(); | |
2767 | ||
2768 | Geom2dInt_GInter anIntersector; | |
2769 | Standard_Integer iPart1, iPart2; | |
2770 | Standard_Integer Ishape11, Ishape12, Ishape21, Ishape22; | |
2771 | // Loop on parts of the first stripe | |
2772 | for (iPart1=1; iPart1<=aSurDat1->Length(); iPart1++) | |
2773 | { | |
2774 | Handle(ChFiDS_SurfData) aDat1 = aSurDat1->Value(iPart1); | |
2775 | Ishape11 = aDat1->IndexOfS1(); | |
2776 | Ishape12 = aDat1->IndexOfS2(); | |
2777 | // Loop on parts of the second stripe | |
2778 | for (iPart2=1; iPart2<=aSurDat2->Length(); iPart2++) | |
2779 | { | |
2780 | Handle(ChFiDS_SurfData) aDat2 = aSurDat2->Value(iPart2); | |
2781 | Ishape21 = aDat2->IndexOfS1(); | |
2782 | Ishape22 = aDat2->IndexOfS2(); | |
2783 | ||
2784 | // Find those FaceInterferences able to intersect | |
2785 | ChFiDS_FaceInterference aFI1, aFI2; | |
2786 | if (Ishape11 == Ishape21) | |
2787 | { | |
2788 | aFI1 = aDat1->InterferenceOnS1(); | |
2789 | aFI2 = aDat2->InterferenceOnS1(); | |
2790 | } | |
2791 | else if (Ishape11 == Ishape22) | |
2792 | { | |
2793 | aFI1 = aDat1->InterferenceOnS1(); | |
2794 | aFI2 = aDat2->InterferenceOnS2(); | |
2795 | } | |
2796 | else if (Ishape12 == Ishape21) | |
2797 | { | |
2798 | aFI1 = aDat1->InterferenceOnS2(); | |
2799 | aFI2 = aDat2->InterferenceOnS1(); | |
2800 | } | |
2801 | else if (Ishape12 == Ishape22) | |
2802 | { | |
2803 | aFI1 = aDat1->InterferenceOnS2(); | |
2804 | aFI2 = aDat2->InterferenceOnS2(); | |
2805 | } | |
2806 | else | |
2807 | { | |
2808 | // No common faces | |
2809 | continue; | |
2810 | } | |
2811 | ||
2812 | if (IsEqual (aFI1.FirstParameter(),aFI1.LastParameter()) || | |
2813 | IsEqual (aFI2.FirstParameter(),aFI2.LastParameter()) || | |
2814 | aFI1.PCurveOnFace().IsNull() || | |
2815 | aFI2.PCurveOnFace().IsNull()) | |
2816 | // Do not waste time on degenerates | |
2817 | continue; | |
2818 | // Examine for intersections | |
2819 | Geom2dAdaptor_Curve aPCurve1 (aFI1.PCurveOnFace(), | |
2820 | aFI1.FirstParameter(), | |
2821 | aFI1.LastParameter()); | |
2822 | Geom2dAdaptor_Curve aPCurve2 (aFI2.PCurveOnFace(), | |
2823 | aFI2.FirstParameter(), | |
2824 | aFI2.LastParameter()); | |
2825 | anIntersector.Perform (aPCurve1, | |
2826 | aPCurve2, | |
2827 | tol2d, | |
2828 | Precision::PConfusion()); | |
2829 | if (anIntersector.NbSegments() > 0 || | |
2830 | anIntersector.NbPoints() > 0) | |
2831 | StdFail_NotDone::Raise ("StripeEdgeInter : fillets have too big radiuses"); | |
2832 | } | |
2833 | } | |
2834 | } | |
2835 | ||
2836 | //======================================================================= | |
2837 | //function : IndexOfSurfData | |
2838 | //purpose : | |
2839 | //======================================================================= | |
7fd59977 | 2840 | Standard_Integer ChFi3d_IndexOfSurfData(const TopoDS_Vertex& V1, |
2841 | const Handle(ChFiDS_Stripe)& CD, | |
2842 | Standard_Integer& sens) | |
2843 | { | |
2844 | Handle(ChFiDS_Spine) spine = CD->Spine(); | |
2845 | Standard_Integer Index = 0; | |
2846 | sens = 1; | |
2847 | TopoDS_Vertex Vref; | |
2848 | const TopoDS_Edge& E = spine->Edges(1); | |
2849 | if (E.Orientation() == TopAbs_REVERSED) Vref = TopExp::LastVertex(E); | |
2850 | else Vref = TopExp::FirstVertex(E); | |
2851 | if (Vref.IsSame(V1)) Index =1; | |
2852 | else { | |
2853 | const TopoDS_Edge& E1 = spine->Edges(spine->NbEdges()); | |
2854 | if (E1.Orientation() == TopAbs_REVERSED) Vref = TopExp::FirstVertex(E1); | |
2855 | else Vref = TopExp::LastVertex(E1); | |
2856 | sens = -1; | |
2857 | if(CD->SetOfSurfData().IsNull()) return 0; | |
2858 | else if (Vref.IsSame(V1)) Index = CD->SetOfSurfData()->Length(); | |
2859 | else Standard_ConstructionError::Raise(""); | |
2860 | } | |
2861 | return Index; | |
2862 | } | |
7fd59977 | 2863 | //======================================================================= |
2864 | //function : EdgeFromV1 | |
2865 | //purpose : | |
2866 | //======================================================================= | |
2867 | ||
2868 | TopoDS_Edge ChFi3d_EdgeFromV1(const TopoDS_Vertex& V1, | |
2869 | const Handle(ChFiDS_Stripe)& CD, | |
2870 | Standard_Integer& sens) | |
2871 | { | |
2872 | Handle(ChFiDS_Spine) spine = CD->Spine(); | |
2873 | sens = 1; | |
2874 | TopoDS_Vertex Vref; | |
2875 | const TopoDS_Edge& E = spine->Edges(1); | |
2876 | if (E.Orientation() == TopAbs_REVERSED) Vref = TopExp::LastVertex(E); | |
2877 | else Vref = TopExp::FirstVertex(E); | |
2878 | if (Vref.IsSame(V1)) return E; | |
2879 | else | |
2880 | { | |
2881 | const TopoDS_Edge& E1 = spine->Edges(spine->NbEdges()); | |
2882 | if (E1.Orientation() == TopAbs_REVERSED) Vref = TopExp::FirstVertex(E1); | |
2883 | else Vref = TopExp::LastVertex(E1); | |
2884 | sens = -1; | |
2885 | if (Vref.IsSame(V1)) return E1; | |
2886 | else Standard_ConstructionError::Raise(""); | |
2887 | } | |
2888 | return E; | |
2889 | } | |
7fd59977 | 2890 | //======================================================================= |
2891 | //function : ConvTol2dToTol3d | |
065bb8b0 | 2892 | //purpose : Comme son nom l indique. |
7fd59977 | 2893 | //======================================================================= |
2894 | ||
2895 | Standard_Real ChFi3d_ConvTol2dToTol3d(const Handle(Adaptor3d_HSurface)& S, | |
2896 | const Standard_Real tol2d) | |
2897 | { | |
2898 | Standard_Real ures = S->UResolution(1.e-7); | |
2899 | Standard_Real vres = S->VResolution(1.e-7); | |
2900 | Standard_Real uresto3d = 1.e-7*tol2d/ures; | |
2901 | Standard_Real vresto3d = 1.e-7*tol2d/vres; | |
2902 | return Max(uresto3d,vresto3d); | |
2903 | } | |
7fd59977 | 2904 | //======================================================================= |
2905 | //function : EvalTolReached | |
81bba717 | 2906 | //purpose : The function above is too hard because |
2907 | // parametrization of surfaces is not homogenous. | |
7fd59977 | 2908 | //======================================================================= |
2909 | ||
2910 | Standard_Real ChFi3d_EvalTolReached(const Handle(Adaptor3d_HSurface)& S1, | |
2911 | const Handle(Geom2d_Curve)& pc1, | |
2912 | const Handle(Adaptor3d_HSurface)& S2, | |
2913 | const Handle(Geom2d_Curve)& pc2, | |
2914 | const Handle(Geom_Curve)& C) | |
2915 | { | |
2916 | Standard_Real distmax = 0.; | |
2917 | ||
2918 | Standard_Real f = C->FirstParameter(); | |
2919 | Standard_Real l = C->LastParameter(); | |
2920 | Standard_Integer nbp = 45; | |
2921 | Standard_Real step = 1./(nbp -1); | |
2922 | for(Standard_Integer i = 0; i < nbp; i++) { | |
2923 | Standard_Real t,u,v; | |
2924 | t = step * i; | |
2925 | t = (1-t) * f + t * l; | |
2926 | pc1->Value(t).Coord(u,v); | |
2927 | gp_Pnt pS1 = S1->Value(u,v); | |
2928 | pc2->Value(t).Coord(u,v); | |
2929 | gp_Pnt pS2 = S2->Value(u,v); | |
2930 | gp_Pnt pC = C->Value(t); | |
2931 | Standard_Real d = pS1.SquareDistance(pC); | |
2932 | if(d>distmax) distmax = d; | |
2933 | d = pS2.SquareDistance(pC); | |
2934 | if(d>distmax) distmax = d; | |
2935 | d = pS1.SquareDistance(pS2); | |
2936 | if(d>distmax) distmax = d; | |
2937 | } | |
2938 | distmax = 1.5*sqrt(distmax); | |
2939 | distmax = Max(distmax, Precision::Confusion()); | |
2940 | return distmax; | |
2941 | } | |
2942 | ||
2943 | //======================================================================= | |
2944 | //function : trsfsurf | |
2945 | //purpose : | |
2946 | //======================================================================= | |
7fd59977 | 2947 | Handle(Geom_Surface) trsfsurf(const Handle(Adaptor3d_HSurface)& HS, |
2948 | Handle(Adaptor3d_TopolTool)& /*dom*/) | |
2949 | { | |
065bb8b0 | 2950 | //Pour l utilisation des domaines voir avec BUBUCH!! |
7fd59977 | 2951 | Handle(Geom_Surface) res; |
2952 | Handle(BRepAdaptor_HSurface) hbs = Handle(BRepAdaptor_HSurface)::DownCast(HS); | |
2953 | Handle(GeomAdaptor_HSurface) hgs = Handle(GeomAdaptor_HSurface)::DownCast(HS); | |
2954 | if(!hbs.IsNull()) { | |
2955 | res = hbs->ChangeSurface().Surface().Surface(); | |
2956 | gp_Trsf trsf = hbs->ChangeSurface().Trsf(); | |
2957 | res = Handle(Geom_Surface)::DownCast(res->Transformed(trsf)); | |
2958 | } | |
2959 | else if(!hgs.IsNull()) { | |
2960 | res = hgs->ChangeSurface().Surface(); | |
2961 | } | |
2962 | Handle(Geom_RectangularTrimmedSurface) | |
2963 | tr = Handle(Geom_RectangularTrimmedSurface)::DownCast(res); | |
2964 | if(!tr.IsNull()) res = tr->BasisSurface(); | |
2965 | ||
2966 | Standard_Real U1 = HS->FirstUParameter(), U2 = HS->LastUParameter(); | |
2967 | Standard_Real V1 = HS->FirstVParameter(), V2 = HS->LastVParameter(); | |
2968 | if(!res.IsNull()) { | |
81bba717 | 2969 | // Protection against Construction Errors |
7fd59977 | 2970 | Standard_Real u1, u2, v1, v2; |
2971 | res->Bounds( u1, u2, v1, v2); | |
2972 | if (!res->IsUPeriodic()) { | |
2973 | if (U1 < u1) U1 = u1; | |
2974 | if (U2 > u2) U2 = u2; | |
2975 | } | |
2976 | if (!res->IsVPeriodic()) { | |
2977 | if (V1 < v1) V1 = v1; | |
2978 | if (V2 > v2) V2 = v2; | |
2979 | } | |
2980 | res = new Geom_RectangularTrimmedSurface(res,U1,U2,V1,V2); | |
2981 | } | |
2982 | // Handle(GeomAdaptor_HSurface) temp = new GeomAdaptor_HSurface(res,U1,U2,V1,V2); | |
2983 | // dom = new Adaptor3d_TopolTool(temp); | |
2984 | return res; | |
2985 | } | |
7fd59977 | 2986 | //======================================================================= |
2987 | //function : CurveCleaner | |
81bba717 | 2988 | //purpose : Makes a BSpline as much continued as possible |
2989 | // at a given tolerance | |
7fd59977 | 2990 | //======================================================================= |
2991 | static void CurveCleaner(Handle(Geom_BSplineCurve)& BS, | |
2992 | const Standard_Real Tol, | |
2993 | const Standard_Integer MultMin) | |
2994 | ||
2995 | { | |
2996 | Standard_Real tol = Tol; | |
2997 | Standard_Integer Mult, ii; | |
2998 | const Standard_Integer NbK=BS->NbKnots(); | |
2999 | ||
3000 | for (Mult = BS->Degree(); Mult > MultMin; Mult--) { | |
81bba717 | 3001 | tol *= 0.5; // Progressive reduction |
7fd59977 | 3002 | for (ii=NbK; ii>1; ii--) { |
3003 | if (BS->Multiplicity(ii) == Mult) | |
3004 | BS->RemoveKnot(ii, Mult-1, tol); | |
3005 | } | |
3006 | } | |
3007 | } | |
7fd59977 | 3008 | //======================================================================= |
3009 | //function : ComputeCurves | |
81bba717 | 3010 | //purpose : Calculates intersection between two HSurfaces. |
3011 | // It is necessary to know the extremities of intersection and | |
3012 | // the surfaces should be processed at input | |
3013 | // to fit as good as possible (neither too close nor too far) | |
3014 | // the points of beginning and end of the intersection. | |
3015 | // The analytic intersections are processed separately. | |
3016 | // <wholeCurv> means that the resulting curve is restricted by | |
7fd59977 | 3017 | // boundaries of input surfaces (eap 30 May occ354) |
3018 | //======================================================================= | |
7fd59977 | 3019 | Standard_Boolean ChFi3d_ComputeCurves(Handle(Adaptor3d_HSurface)& S1, |
3020 | Handle(Adaptor3d_HSurface)& S2, | |
3021 | const TColStd_Array1OfReal& Pardeb, | |
3022 | const TColStd_Array1OfReal& Parfin, | |
3023 | Handle(Geom_Curve)& C3d, | |
3024 | Handle(Geom2d_Curve)& Pc1, | |
3025 | Handle(Geom2d_Curve)& Pc2, | |
3026 | const Standard_Real tol3d, | |
3027 | const Standard_Real tol2d, | |
3028 | Standard_Real& tolreached, | |
3029 | const Standard_Boolean wholeCurv) | |
3030 | { | |
3031 | Standard_Real Step = 0.1; | |
3032 | ||
3033 | gp_Pnt pdeb1 = S1->Value(Pardeb(1),Pardeb(2)); | |
3034 | gp_Pnt pfin1 = S1->Value(Parfin(1),Parfin(2)); | |
3035 | gp_Pnt pdeb2 = S2->Value(Pardeb(3),Pardeb(4)); | |
3036 | gp_Pnt pfin2 = S2->Value(Parfin(3),Parfin(4)); | |
3037 | ||
81bba717 | 3038 | Standard_Real distrefdeb = pdeb1.Distance(pdeb2);//checks the worthiness |
3039 | Standard_Real distreffin = pfin1.Distance(pfin2);//of input data | |
7fd59977 | 3040 | if(distrefdeb < tol3d) distrefdeb = tol3d; |
3041 | if(distreffin < tol3d) distreffin = tol3d; | |
3042 | ||
3043 | gp_Pnt pdeb,pfin; | |
3044 | pdeb.SetXYZ(0.5*(pdeb1.XYZ()+pdeb2.XYZ())); | |
3045 | pfin.SetXYZ(0.5*(pfin1.XYZ()+pfin2.XYZ())); | |
3046 | ||
3047 | Standard_Real distref = 0.005*pdeb.Distance(pfin); | |
3048 | if(distref < distrefdeb) distref = distrefdeb; | |
3049 | if(distref < distreffin) distref = distreffin; | |
3050 | ||
81bba717 | 3051 | //Some analytic cases are processed separately. |
3052 | //To reorientate the result of the analythic intersection, | |
3053 | //it is stated that the beginning of the tangent should be | |
3054 | //in the direction of the start/end line. | |
7fd59977 | 3055 | gp_Vec Vint, Vref(pdeb,pfin); |
3056 | gp_Pnt Pbid; | |
1d47d8d0 | 3057 | Standard_Real Udeb = 0.,Ufin = 0.; |
7fd59977 | 3058 | Standard_Real tolr1,tolr2; |
3059 | tolr1 = tolr2 = tolreached = tol3d; | |
3060 | if((S1->GetType() == GeomAbs_Cylinder && S2->GetType() == GeomAbs_Plane)|| | |
3061 | (S1->GetType() == GeomAbs_Plane && S2->GetType() == GeomAbs_Cylinder)) { | |
3062 | gp_Pln pl; | |
3063 | gp_Cylinder cyl; | |
3064 | if(S1->GetType() == GeomAbs_Plane) { | |
3065 | pl = S1->Plane(); | |
3066 | cyl = S2->Cylinder(); | |
3067 | } | |
3068 | else{ | |
3069 | pl = S2->Plane(); | |
3070 | cyl = S1->Cylinder(); | |
3071 | } | |
3072 | IntAna_QuadQuadGeo ImpKK(pl,cyl,Precision::Angular(),tol3d); | |
788cbaf4 | 3073 | Standard_Boolean isIntDone = ImpKK.IsDone(); |
3074 | ||
3075 | if(ImpKK.TypeInter() == IntAna_Ellipse) | |
3076 | { | |
3077 | const gp_Elips anEl = ImpKK.Ellipse(1); | |
3078 | const Standard_Real aMajorR = anEl.MajorRadius(); | |
3079 | const Standard_Real aMinorR = anEl.MinorRadius(); | |
3080 | isIntDone = (aMajorR < 100000.0 * aMinorR); | |
3081 | } | |
3082 | ||
3083 | if (isIntDone) { | |
7fd59977 | 3084 | Standard_Boolean c1line = 0; |
3085 | switch (ImpKK.TypeInter()) { | |
3086 | case IntAna_Line: | |
3087 | { | |
3088 | c1line = 1; | |
3089 | Standard_Integer nbsol = ImpKK.NbSolutions(); | |
3090 | gp_Lin C1; | |
3091 | for(Standard_Integer ilin = 1; ilin <= nbsol; ilin++) { | |
3092 | C1 = ImpKK.Line(ilin); | |
3093 | Udeb = ElCLib::Parameter(C1,pdeb); | |
3094 | gp_Pnt ptest = ElCLib::Value(Udeb,C1); | |
3095 | if(ptest.Distance(pdeb) < tol3d) break; | |
3096 | } | |
3097 | Ufin = ElCLib::Parameter(C1,pfin); | |
3098 | C3d = new Geom_Line(C1); | |
3099 | ElCLib::D1(Udeb,C1,Pbid,Vint); | |
3100 | } | |
3101 | break; | |
3102 | case IntAna_Circle: | |
3103 | { | |
3104 | gp_Circ C1 = ImpKK.Circle(1); | |
3105 | C3d = new Geom_Circle(C1); | |
3106 | Udeb = ElCLib::Parameter(C1,pdeb); | |
3107 | Ufin = ElCLib::Parameter(C1,pfin); | |
3108 | ElCLib::D1(Udeb,C1,Pbid,Vint); | |
3109 | } | |
3110 | break; | |
3111 | case IntAna_Ellipse: | |
3112 | { | |
3113 | gp_Elips C1 = ImpKK.Ellipse(1); | |
3114 | C3d = new Geom_Ellipse(C1); | |
3115 | Udeb = ElCLib::Parameter(C1,pdeb); | |
3116 | Ufin = ElCLib::Parameter(C1,pfin); | |
3117 | ElCLib::D1(Udeb,C1,Pbid,Vint); | |
3118 | } | |
3119 | break; | |
3120 | default: | |
3121 | break; | |
3122 | } | |
3123 | if (Vint.Dot(Vref)<0) { | |
3124 | C3d->Reverse(); | |
3125 | if(c1line) { | |
3126 | Udeb = -Udeb; | |
3127 | Ufin = -Ufin; | |
3128 | } | |
3129 | else{ | |
c6541a0c D |
3130 | Udeb = 2*M_PI - Udeb; |
3131 | Ufin = 2*M_PI - Ufin; | |
7fd59977 | 3132 | } |
3133 | } | |
c6541a0c | 3134 | if(!c1line) ElCLib::AdjustPeriodic(0.,2*M_PI,Precision::Angular(),Udeb,Ufin); |
7fd59977 | 3135 | Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(); |
3136 | HC->ChangeCurve().Load(C3d,Udeb,Ufin); | |
3137 | ChFi3d_ProjectPCurv(HC,S1,Pc1,tol3d,tolr1); | |
3138 | if(S1->GetType() == GeomAbs_Cylinder) { | |
3139 | Standard_Real x,y; | |
3140 | Pc1->Value(Udeb).Coord(x,y); | |
3141 | x = Pardeb(1) - x; | |
3142 | y = Pardeb(2) - y; | |
3143 | if(Abs(x) >= tol2d || Abs(y) >= tol2d) Pc1->Translate(gp_Vec2d(x,y)); | |
3144 | } | |
3145 | ChFi3d_ProjectPCurv(HC,S2,Pc2,tol3d,tolr2); | |
3146 | if(S2->GetType() == GeomAbs_Cylinder) { | |
3147 | Standard_Real x,y; | |
3148 | Pc2->Value(Udeb).Coord(x,y); | |
3149 | x = Pardeb(3) - x; | |
3150 | y = Pardeb(4) - y; | |
3151 | if(Abs(x) >= tol2d || Abs(y) >= tol2d) Pc2->Translate(gp_Vec2d(x,y)); | |
3152 | } | |
3153 | C3d = new Geom_TrimmedCurve(C3d,Udeb,Ufin); | |
3154 | tolreached = 1.5*Max(tolr1,tolr2); | |
3155 | tolreached = Min(tolreached,ChFi3d_EvalTolReached(S1,Pc1,S2,Pc2,C3d)); | |
3156 | return Standard_True; | |
3157 | } | |
3158 | } | |
3159 | else if(S1->GetType() == GeomAbs_Plane && S2->GetType() == GeomAbs_Plane) { | |
3160 | IntAna_QuadQuadGeo LInt(S1->Plane(),S2->Plane(),Precision::Angular(),tol3d); | |
3161 | if (LInt.IsDone()) { | |
3162 | gp_Lin L = LInt.Line(1); | |
3163 | C3d = new Geom_Line(L); | |
3164 | Udeb = ElCLib::Parameter(L,pdeb); | |
3165 | Ufin = ElCLib::Parameter(L,pfin); | |
3166 | ElCLib::D1(Udeb,L,Pbid,Vint); | |
3167 | if (Vint.Dot(Vref)<0) { | |
3168 | C3d->Reverse(); | |
3169 | Udeb = - Udeb; | |
3170 | Ufin = - Ufin; | |
3171 | } | |
3172 | Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(); | |
3173 | HC->ChangeCurve().Load(C3d,Udeb,Ufin); | |
3174 | ChFi3d_ProjectPCurv(HC,S1,Pc1,tol3d,tolr1); | |
3175 | ChFi3d_ProjectPCurv(HC,S2,Pc2,tol3d,tolr2); | |
3176 | C3d = new Geom_TrimmedCurve(C3d,Udeb,Ufin); | |
3177 | return Standard_True; | |
3178 | } | |
3179 | } | |
3180 | else { | |
81bba717 | 3181 | // here GeomInt is approached. |
7fd59977 | 3182 | Handle(Adaptor3d_TopolTool) dom1,dom2; |
3183 | Handle(Geom_Surface) gs1 = trsfsurf(S1,dom1); | |
3184 | Handle(Geom_Surface) gs2 = trsfsurf(S2,dom2); | |
3185 | Standard_Integer nbl ; | |
3186 | if(!gs1.IsNull() && !gs2.IsNull()) { | |
3187 | GeomInt_IntSS inter; | |
3188 | // Modified by skv - Fri Oct 24 14:24:47 2003 OCC4077 Begin | |
3189 | // Standard_Real tolap = 1.e-7;//car l approx de la wline est faite dans [0,1] | |
3190 | // Set the lowest tolerance which is used in new boolean operations. | |
3191 | Standard_Real tolap = 2.e-7; | |
3192 | // Modified by skv - Fri Oct 24 14:24:48 2003 OCC4077 End | |
3193 | inter.Perform(gs1,gs2,tolap,1,1,1); | |
3194 | if(inter.IsDone()) { | |
3195 | nbl = inter.NbLines(); | |
3196 | #if defined(IRIX) || defined(__sgi) | |
3197 | if(nbl==0) { | |
3198 | ||
81bba717 | 3199 | // solution of adjustment for SGI |
3200 | // if the intersection of gs1 with gs2 doesnot worke | |
3201 | // then the intersection of gs2 with gs1 is attempted. | |
7fd59977 | 3202 | |
3203 | inter.Perform(gs2,gs1,tolap,1,1,1); | |
3204 | // inter.Perform(gs2,dom2,gs1,dom1,tolap,1,1,1); | |
3205 | if(!inter.IsDone()) return Standard_False; | |
3206 | nbl = inter.NbLines(); | |
3207 | ||
81bba717 | 3208 | // if GeomInt does not make the intersection the solution of adjustment |
3209 | // is not attempted | |
7fd59977 | 3210 | if (nbl==0) return Standard_False; |
3211 | } | |
3212 | #endif | |
3213 | GeomAPI_ProjectPointOnCurve proj; | |
3214 | for(Standard_Integer ilin = 1; ilin <= nbl; ilin++) { | |
3215 | if(inter.HasLineOnS1(ilin) && inter.HasLineOnS2(ilin)) { | |
3216 | C3d = inter.Line(ilin); | |
3217 | Pc1 = inter.LineOnS1(ilin); | |
3218 | Pc2 = inter.LineOnS2(ilin); | |
3219 | gp_Pnt ptestdeb, ptestfin; | |
3220 | Standard_Real Uf=0., Ul=0.; | |
3221 | if (wholeCurv) { | |
3222 | Uf = C3d->FirstParameter(); | |
3223 | Ul = C3d->LastParameter(); | |
3224 | ptestdeb = C3d->Value(Uf); | |
3225 | ptestfin = C3d->Value(Ul); | |
3226 | } | |
3227 | else { | |
3228 | // find end parameters | |
3229 | Standard_Boolean failedF, failedL; | |
3230 | failedF = failedL = Standard_False; | |
3231 | proj.Init( pdeb1, C3d); | |
3232 | if (proj.NbPoints()==0 && distrefdeb > Precision::Confusion()) | |
3233 | proj.Perform( pdeb2 ); | |
3234 | if (proj.NbPoints()==0) | |
3235 | failedF = Standard_True; | |
3236 | else | |
3237 | Uf = proj.LowerDistanceParameter(); | |
3238 | proj.Perform( pfin1 ); | |
3239 | if (proj.NbPoints()==0 && distreffin > Precision::Confusion()) | |
3240 | proj.Perform( pfin2 ); | |
3241 | if (proj.NbPoints()==0) | |
3242 | failedL = Standard_True; | |
3243 | else | |
3244 | Ul = proj.LowerDistanceParameter(); | |
3245 | ||
3246 | if (failedF && failedL) { | |
3247 | Uf = C3d->FirstParameter(); | |
3248 | Ul = C3d->LastParameter(); | |
3249 | } | |
3250 | else if (failedF || failedL) { | |
3251 | // select right end parameter | |
3252 | Standard_Real Uok = failedF ? Ul : Uf; | |
3253 | Standard_Real U1 = C3d->FirstParameter(), U2 = C3d->LastParameter(); | |
3254 | Uok = Abs(Uok-U1) > Abs(Uok-U2) ? U1 : U2; | |
3255 | if (failedF) Uf = Uok; | |
3256 | else Ul = Uok; | |
3257 | } | |
3258 | else { // both projected, but where? | |
3259 | if (Uf == Ul) continue; | |
3260 | } | |
3261 | ptestdeb = C3d->Value(Uf); | |
3262 | ptestfin = C3d->Value(Ul); | |
3263 | if (C3d->IsPeriodic() && !(failedF && failedL)) { | |
3264 | // assure the same order of ends, otherwise TrimmedCurve will take | |
3265 | // the other part of C3d | |
3266 | gp_Pnt Ptmp; | |
3267 | gp_Vec DirOld, DirNew(ptestdeb,ptestfin); | |
3268 | C3d->D1(Uf, Ptmp, DirOld); | |
3269 | if (DirOld * DirNew < 0) { | |
3270 | Standard_Real Utmp = Uf; Uf = Ul; Ul = Utmp; | |
3271 | Ptmp = ptestdeb; ptestdeb = ptestfin; ptestfin = Ptmp; | |
3272 | } | |
3273 | } | |
3274 | } | |
3275 | C3d = new Geom_TrimmedCurve(C3d,Uf,Ul); | |
3276 | Pc1 = new Geom2d_TrimmedCurve(Pc1,Uf,Ul); | |
3277 | Pc2 = new Geom2d_TrimmedCurve(Pc2,Uf,Ul); | |
81bba717 | 3278 | //is it necesary to invert ? |
7fd59977 | 3279 | Standard_Real distdeb = ptestdeb.Distance(pdeb); |
3280 | Standard_Real distfin = ptestfin.Distance(pfin); | |
3281 | if(distdeb > distref || distfin > distref) { | |
3282 | C3d->Reverse(); | |
3283 | Pc1->Reverse(); | |
3284 | Pc2->Reverse(); | |
3285 | ptestdeb = C3d->Value(C3d->FirstParameter()); | |
3286 | ptestfin = C3d->Value(C3d->LastParameter()); | |
3287 | distdeb = ptestdeb.Distance(pdeb); | |
3288 | distfin = ptestfin.Distance(pfin); | |
3289 | } | |
3290 | if(distdeb < distref && distfin < distref) { | |
3291 | Uf = C3d->FirstParameter(); | |
3292 | Ul = C3d->LastParameter(); | |
3293 | ChFi3d_ReparamPcurv(Uf,Ul,Pc1); | |
3294 | ChFi3d_ReparamPcurv(Uf,Ul,Pc2); | |
3295 | Standard_Real x,y; | |
3296 | Pc1->Value(Uf).Coord(x,y); | |
3297 | x = Pardeb(1) - x; | |
3298 | y = Pardeb(2) - y; | |
3299 | if(Abs(x) > tol2d || Abs(y) > tol2d) Pc1->Translate(gp_Vec2d(x,y)); | |
3300 | Pc2->Value(Uf).Coord(x,y); | |
3301 | x = Pardeb(3) - x; | |
3302 | y = Pardeb(4) - y; | |
3303 | if(Abs(x) > tol2d || Abs(y) > tol2d) Pc2->Translate(gp_Vec2d(x,y)); | |
3304 | tolreached = ChFi3d_EvalTolReached(S1,Pc1,S2,Pc2,C3d); | |
3305 | return Standard_True; | |
3306 | } | |
3307 | } | |
3308 | } | |
3309 | } | |
3310 | } | |
3311 | } | |
7fd59977 | 3312 | |
81bba717 | 3313 | // At this stage : |
3314 | // classic intersections have failed, the path is approached in vain. | |
7fd59977 | 3315 | // Standard_Real Step = 0.1; |
302f96fb | 3316 | for(;;) { |
81bba717 | 3317 | //Attention the parameters of arrow for the path and |
3318 | //the tolerance for the approximation can't be taken as those of the | |
3319 | //Builder, so they are reestimated as much as possible. | |
7fd59977 | 3320 | Standard_Real fleche = 1.e-3 * pdeb.Distance(pfin); |
3321 | Standard_Real tolap = 1.e-7; | |
3322 | IntPatch_ThePWalkingInter | |
3323 | IntKK(S1,S2,tol3d,tol3d,fleche,Step); | |
3324 | ||
81bba717 | 3325 | //The extremities of the intersection (Pardeb,Parfin) are known, |
3326 | //one tries to find the start point at the | |
3327 | //middle to avoid obstacles on the path. | |
7fd59977 | 3328 | Standard_Boolean depok = Standard_False; |
3329 | IntSurf_PntOn2S pintdep; | |
3330 | TColStd_Array1OfReal depart(1,4); | |
3331 | for(Standard_Integer ipdep = 2; ipdep <= 7 && !depok; ipdep++) { | |
3332 | Standard_Real alpha = 0.1 * ipdep; | |
3333 | Standard_Real unmoinsalpha = 1. - alpha; | |
3334 | depart(1) = alpha*Pardeb(1) + unmoinsalpha*Parfin(1); | |
3335 | depart(2) = alpha*Pardeb(2) + unmoinsalpha*Parfin(2); | |
3336 | depart(3) = alpha*Pardeb(3) + unmoinsalpha*Parfin(3); | |
3337 | depart(4) = alpha*Pardeb(4) + unmoinsalpha*Parfin(4); | |
3338 | depok = IntKK.PerformFirstPoint(depart,pintdep); | |
3339 | } | |
3340 | if(!depok) { | |
7fd59977 | 3341 | return Standard_False; |
3342 | } | |
3343 | pintdep.Parameters(depart(1),depart(2),depart(3),depart(4)); | |
3344 | IntKK.Perform(depart); | |
3345 | if (!IntKK.IsDone()) return Standard_False; | |
3346 | if (IntKK.NbPoints() <= 30) { | |
3347 | Step *= 0.5; | |
3348 | if (Step <= 0.0001) { | |
7fd59977 | 3349 | return Standard_False; |
3350 | } | |
3351 | } | |
3352 | else{ | |
81bba717 | 3353 | // At this stage there is a presentable LineOn2S, it is truncated |
3354 | // between the points closest to known extremites | |
3355 | // in fact there is a WLine and the approximation is launched. | |
3356 | // Then the result is corrected to get proper start and end points. | |
7fd59977 | 3357 | const Handle(IntSurf_LineOn2S)& L2S = IntKK.Line(); |
3358 | ||
3359 | gp_Pnt codeb1 = S1->Value(Pardeb(1),Pardeb(2)); | |
3360 | gp_Pnt codeb2 = S2->Value(Pardeb(3),Pardeb(4)); | |
3361 | Standard_Real tol1 = Max(codeb1.Distance(codeb2),tol3d); | |
3362 | Standard_Boolean bondeb = (tol1 == tol3d); | |
3363 | gp_Pnt pntd(0.5*(codeb1.Coord() + codeb2.Coord())); | |
3364 | ||
3365 | gp_Pnt cofin1 = S1->Value(Parfin(1),Parfin(2)); | |
3366 | gp_Pnt cofin2 = S2->Value(Parfin(3),Parfin(4)); | |
3367 | Standard_Real tol2 = Max(cofin1.Distance(cofin2),tol3d); | |
3368 | Standard_Boolean bonfin = (tol2 == tol3d); | |
3369 | gp_Pnt pntf(0.5*(cofin1.Coord() + cofin2.Coord())); | |
3370 | ||
3371 | Standard_Integer nbp = L2S->NbPoints(), i; | |
3372 | Standard_Real ddeb = Precision::Infinite(); | |
3373 | Standard_Real dfin = Precision::Infinite(); | |
3374 | Standard_Real dd; | |
7fd59977 | 3375 | Standard_Integer indd = 0, indf = 0; |
7fd59977 | 3376 | for(i = 1; i <= nbp; i++) { |
3377 | dd = L2S->Value(i).Value().Distance(pntd); | |
3378 | if(dd < ddeb) { ddeb = dd; indd = i;} | |
3379 | dd = L2S->Value(i).Value().Distance(pntf); | |
3380 | if(dd < dfin) { dfin = dd; indf = i;} | |
3381 | } | |
3382 | if(indd > indf) { | |
3383 | L2S->Reverse(); | |
3384 | indd = nbp - indd + 1; | |
3385 | indf = nbp - indf + 1; | |
3386 | } | |
3387 | for (i = 1; i < indd; i++) { L2S->RemovePoint(1); nbp--; indf--; } | |
3388 | for (i = indf + 1; i <= nbp; i++) { L2S->RemovePoint(indf + 1); } | |
3389 | nbp = indf; | |
3390 | if(nbp==1) return Standard_False; | |
81bba717 | 3391 | //The extremities are inserted in the line if the extremity points on it |
3392 | //are too far and if pardeb and parfin are good. | |
7fd59977 | 3393 | if(ddeb >= tol3d && bondeb) { |
3394 | IntSurf_PntOn2S p1 = L2S->Value(1); | |
3395 | IntSurf_PntOn2S p2 = L2S->Value(2); | |
3396 | ||
3397 | gp_Vec v1(pntd,p1.Value()); | |
3398 | gp_Vec v2(p1.Value(),p2.Value()); | |
3399 | gp_Vec v3(pntd,p2.Value()); | |
3400 | p1.SetValue(pntd,Pardeb(1),Pardeb(2),Pardeb(3),Pardeb(4)); | |
3401 | if(v1.Dot(v3) < 0) { | |
3402 | if(v3.Magnitude() < 0.2*v2.Magnitude()) { | |
3403 | L2S->RemovePoint(1); | |
3404 | nbp--; | |
3405 | } | |
3406 | L2S->Value(1,p1); | |
3407 | } | |
3408 | else if(v1.Magnitude() > 0.2*v2.Magnitude()) { | |
3409 | L2S->InsertBefore(1,p1); | |
3410 | nbp++; | |
3411 | } | |
3412 | else{ | |
3413 | L2S->Value(1,p1); | |
3414 | } | |
3415 | ddeb = 0.; | |
3416 | } | |
3417 | if(dfin >= tol3d && bonfin) { | |
3418 | IntSurf_PntOn2S p1 = L2S->Value(nbp); | |
3419 | IntSurf_PntOn2S p2 = L2S->Value(nbp - 1); | |
3420 | gp_Vec v1(pntf,p1.Value()); | |
3421 | gp_Vec v2(p1.Value(),p2.Value()); | |
3422 | gp_Vec v3(pntf,p2.Value()); | |
3423 | p1.SetValue(pntf,Parfin(1),Parfin(2),Parfin(3),Parfin(4)); | |
3424 | if(v1.Dot(v3) < 0) { | |
3425 | if(v3.Magnitude() < 0.2*v2.Magnitude()) { | |
3426 | L2S->RemovePoint(nbp); | |
3427 | nbp--; | |
3428 | } | |
3429 | L2S->Value(nbp,p1); | |
3430 | } | |
3431 | else if(v1.Magnitude() > 0.2*v2.Magnitude()) { | |
3432 | L2S->Add(p1); | |
3433 | nbp++; | |
3434 | } | |
3435 | else{ | |
3436 | L2S->Value(nbp,p1); | |
3437 | } | |
3438 | dfin = 0.; | |
3439 | } | |
065bb8b0 | 3440 | // |
3441 | Handle(IntPatch_WLine) WL = new IntPatch_WLine(L2S,Standard_False); | |
7fd59977 | 3442 | |
3443 | GeomInt_WLApprox approx; | |
3444 | approx.SetParameters(tolap,tol2d,4,8,0,1); | |
81bba717 | 3445 | // manage here the approximations that are not useful on planes! |
7fd59977 | 3446 | approx.Perform(S1,S2,WL, |
3447 | Standard_True,Standard_True,Standard_True, | |
3448 | 1,nbp); | |
3449 | if(!approx.IsDone()) return Standard_False; | |
3450 | // tolreached = approx.TolReached3d(); | |
3451 | // Standard_Real tolr2d = approx.TolReached2d(); | |
3452 | // tolreached = Max(tolreached,ChFi3d_ConvTol2dToTol3d(S1,tolr2d)); | |
3453 | // tolreached = Max(tolreached,ChFi3d_ConvTol2dToTol3d(S2,tolr2d)); | |
3454 | const AppParCurves_MultiBSpCurve& mbs = approx.Value(1); | |
3455 | Standard_Integer nbpol = mbs.NbPoles(); | |
3456 | TColgp_Array1OfPnt pol3d(1,nbpol); | |
3457 | mbs.Curve(1,pol3d); | |
3458 | TColgp_Array1OfPnt2d pol2d1(1,nbpol); | |
3459 | mbs.Curve(2,pol2d1); | |
3460 | TColgp_Array1OfPnt2d pol2d2(1,nbpol); | |
3461 | mbs.Curve(3,pol2d2); | |
81bba717 | 3462 | // The extremities of the intersection are reset on known points. |
7fd59977 | 3463 | if(ddeb >= tol1) { |
3464 | pol3d(1) = pntd; | |
3465 | pol2d1(1).SetCoord(Pardeb(1),Pardeb(2)); | |
3466 | pol2d2(1).SetCoord(Pardeb(3),Pardeb(4)); | |
3467 | // tolreached = Max(tolreached,ddeb); | |
3468 | } | |
3469 | ||
3470 | if(dfin >= tol2) { | |
3471 | pol3d(nbpol) = pntf; | |
3472 | pol2d1(nbpol).SetCoord(Parfin(1),Parfin(2)); | |
3473 | pol2d2(nbpol).SetCoord(Parfin(3),Parfin(4)); | |
3474 | // tolreached = Max(tolreached,dfin); | |
3475 | } | |
3476 | const TColStd_Array1OfReal& knots = mbs.Knots(); | |
3477 | const TColStd_Array1OfInteger& mults = mbs.Multiplicities(); | |
3478 | Standard_Integer deg = mbs.Degree(); | |
3479 | C3d = new Geom_BSplineCurve(pol3d,knots,mults,deg); | |
3480 | Pc1 = new Geom2d_BSplineCurve(pol2d1,knots,mults,deg); | |
3481 | Pc2 = new Geom2d_BSplineCurve(pol2d2,knots,mults,deg); | |
3482 | tolreached = ChFi3d_EvalTolReached(S1,Pc1,S2,Pc2,C3d); | |
3483 | return Standard_True; | |
3484 | } | |
3485 | } | |
3486 | } | |
3487 | ||
3488 | //======================================================================= | |
3489 | //function : IntCS | |
81bba717 | 3490 | //purpose : Fast calculation of the intersection curve surface. |
7fd59977 | 3491 | // |
3492 | //======================================================================= | |
3493 | ||
3494 | Standard_Boolean ChFi3d_IntCS(Handle(Adaptor3d_HSurface)& S, | |
3495 | Handle(Adaptor3d_HCurve)& C, | |
3496 | gp_Pnt2d& p2dS, | |
3497 | Standard_Real& wc) | |
3498 | { | |
3499 | IntCurveSurface_HInter Intersection; | |
3500 | ||
3501 | Standard_Real uf = C->FirstParameter(), ul = C->LastParameter(); | |
3502 | Standard_Real u1 = S->FirstUParameter(), u2 = S->LastUParameter(); | |
3503 | Standard_Real v1 = S->FirstVParameter(), v2 = S->LastVParameter(); | |
3504 | IntCurveSurface_IntersectionPoint pint; | |
3505 | Intersection.Perform(C,S); | |
3506 | Standard_Boolean keepfirst = (wc < -1.e100), keeplast = (wc > 1.e100); | |
7fd59977 | 3507 | Standard_Real temp = 0.; |
7fd59977 | 3508 | if(keepfirst) temp = 1.e100; |
3509 | if(keeplast) temp = -1.e100; | |
3510 | Standard_Real dist = 2.e100; | |
3511 | if(Intersection.IsDone()) { | |
3512 | Standard_Integer nbp = Intersection.NbPoints(),i,isol = 0; | |
3513 | for (i = 1; i <= nbp; i++) { | |
3514 | pint = Intersection.Point(i); | |
3515 | Standard_Real up = pint.U(); | |
3516 | Standard_Real vp = pint.V(); | |
3517 | if(S->IsUPeriodic()) up = ChFi3d_InPeriod(up,u1,u1+S->UPeriod(),1.e-8); | |
3518 | if(S->IsVPeriodic()) vp = ChFi3d_InPeriod(vp,v1,v1+S->VPeriod(),1.e-8); | |
3519 | if(uf <= pint.W() && ul >= pint.W() && | |
3520 | u1 <= up && u2 >= up && | |
3521 | v1 <= vp && v2 >= vp) { | |
3522 | if(keepfirst && pint.W() < temp) { | |
3523 | temp = pint.W(); | |
3524 | isol = i; | |
3525 | } | |
3526 | else if(keeplast && pint.W() > temp) { | |
3527 | temp = pint.W(); | |
3528 | isol = i; | |
3529 | } | |
3530 | else if(Abs(pint.W() - wc) < dist) { | |
3531 | dist = Abs(pint.W() - wc); | |
3532 | isol = i; | |
3533 | } | |
3534 | } | |
3535 | } | |
3536 | if(isol == 0) return Standard_False; | |
3537 | pint = Intersection.Point(isol); | |
3538 | Standard_Real up = pint.U(); | |
3539 | Standard_Real vp = pint.V(); | |
3540 | if(S->IsUPeriodic()) up = ChFi3d_InPeriod(up,u1,u1+S->UPeriod(),1.e-8); | |
3541 | if(S->IsVPeriodic()) vp = ChFi3d_InPeriod(vp,v1,v1+S->VPeriod(),1.e-8); | |
3542 | p2dS.SetCoord(up,vp); | |
3543 | wc = pint.W(); | |
3544 | return Standard_True; | |
3545 | } | |
3546 | return Standard_False; | |
3547 | } | |
3548 | ||
3549 | //======================================================================= | |
3550 | //function : ComputesIntPC | |
81bba717 | 3551 | //purpose : Intersection of two PCurves of type FaceInterference |
3552 | // the parameters of the pcurves at the solution point are | |
7fd59977 | 3553 | // UInt1,UInt2 |
3554 | //======================================================================= | |
3555 | ||
3556 | void ChFi3d_ComputesIntPC (const ChFiDS_FaceInterference& Fi1, | |
3557 | const ChFiDS_FaceInterference& Fi2, | |
3558 | const Handle(GeomAdaptor_HSurface)& HS1, | |
3559 | const Handle(GeomAdaptor_HSurface)& HS2, | |
3560 | Standard_Real& UInt1, | |
3561 | Standard_Real& UInt2) | |
3562 | { | |
3563 | gp_Pnt bid; | |
3564 | ChFi3d_ComputesIntPC(Fi1,Fi2,HS1,HS2,UInt1,UInt2,bid); | |
3565 | } | |
3566 | ||
065bb8b0 | 3567 | //======================================================================= |
3568 | //function : ChFi3d_ComputesIntPC | |
3569 | //purpose : | |
3570 | //======================================================================= | |
7fd59977 | 3571 | void ChFi3d_ComputesIntPC (const ChFiDS_FaceInterference& Fi1, |
3572 | const ChFiDS_FaceInterference& Fi2, | |
3573 | const Handle(GeomAdaptor_HSurface)& HS1, | |
3574 | const Handle(GeomAdaptor_HSurface)& HS2, | |
3575 | Standard_Real& UInt1, | |
3576 | Standard_Real& UInt2, | |
3577 | gp_Pnt& P) | |
3578 | { | |
81bba717 | 3579 | // Only one intersection to be carried out, however, the effort |
3580 | // is taken to check the extremities by an extrema c3d/c3d | |
3581 | // created on pcurveonsurf of fillets. | |
7fd59977 | 3582 | |
3583 | Standard_Real x,y,distref2; | |
3584 | Fi1.PCurveOnSurf()->Value(UInt1).Coord(x,y); | |
3585 | gp_Pnt p3d1 = HS1->Value(x,y); | |
3586 | Fi2.PCurveOnSurf()->Value(UInt2).Coord(x,y); | |
3587 | gp_Pnt p3d2 = HS2->Value(x,y); | |
3588 | distref2 = p3d1.SquareDistance(p3d2); | |
3589 | P.SetXYZ(0.5*(p3d1.XYZ() + p3d2.XYZ())); | |
81bba717 | 3590 | // recalculation of the extremums |
7fd59977 | 3591 | Standard_Real delt1 = |
3592 | Min(0.1,0.05*(Fi1.LastParameter() - Fi1.FirstParameter())); | |
3593 | Handle(Geom2dAdaptor_HCurve) hc2d1 = | |
3594 | new Geom2dAdaptor_HCurve(Fi1.PCurveOnSurf(),UInt1-delt1,UInt1+delt1); | |
3595 | Adaptor3d_CurveOnSurface cons1(hc2d1,HS1); | |
3596 | Standard_Real delt2 = | |
3597 | Min(0.1,0.05*(Fi2.LastParameter() - Fi2.FirstParameter())); | |
3598 | Handle(Geom2dAdaptor_HCurve) hc2d2 = | |
3599 | new Geom2dAdaptor_HCurve(Fi2.PCurveOnSurf(),UInt2-delt2,UInt2+delt2); | |
3600 | Adaptor3d_CurveOnSurface cons2(hc2d2,HS2); | |
3601 | Extrema_LocateExtCC ext(cons1,cons2,UInt1,UInt2); | |
3602 | if(ext.IsDone()) { | |
3603 | Standard_Real dist2 = ext.SquareDistance(); | |
3604 | if(dist2<distref2) { | |
3605 | Extrema_POnCurv ponc1,ponc2; | |
3606 | ext.Point(ponc1,ponc2); | |
3607 | UInt1 = ponc1.Parameter(); | |
3608 | UInt2 = ponc2.Parameter(); | |
3609 | gp_Pnt Pnt1 = ponc1.Value(); | |
3610 | gp_Pnt Pnt2 = ponc2.Value(); | |
3611 | P.SetXYZ(0.5*(Pnt1.XYZ() + Pnt2.XYZ())); | |
3612 | } | |
3613 | } | |
3614 | } | |
3615 | ||
3616 | //======================================================================= | |
3617 | //function : BoundSurf | |
3618 | //purpose : computes a GeomAdaptor_Surface from the surface of the | |
3619 | // SurfData Fd1 and trims it to allow the intersection computation | |
3620 | ||
3621 | //======================================================================= | |
7fd59977 | 3622 | Handle(GeomAdaptor_HSurface) ChFi3d_BoundSurf(TopOpeBRepDS_DataStructure& DStr, |
3623 | const Handle(ChFiDS_SurfData)& Fd1, | |
3624 | const Standard_Integer& IFaCo1, | |
3625 | const Standard_Integer& IFaArc1) | |
3626 | { | |
81bba717 | 3627 | //rmq : as in fact 2 interferences of Fd1 serve only to set limits |
3628 | // indexes IFaCo1 and IFaArc1 are not useful. | |
3629 | // They are preserver here as an option in case it will be necessary to set | |
3630 | // more restrictive limits (with intersection points as additional argument). | |
7fd59977 | 3631 | |
3632 | Handle(GeomAdaptor_HSurface) HS1 = new GeomAdaptor_HSurface(); | |
3633 | GeomAdaptor_Surface& S1 = HS1->ChangeSurface(); | |
3634 | S1.Load(DStr.Surface(Fd1->Surf()).Surface()); | |
3635 | ||
3636 | if ((IFaCo1 == 0)||(IFaArc1 == 0)) | |
3637 | return HS1; | |
3638 | ||
3639 | const ChFiDS_FaceInterference& FiCo1 = Fd1->Interference(IFaCo1); | |
3640 | const ChFiDS_FaceInterference& FiArc1 = Fd1->Interference(IFaArc1); | |
3641 | ||
3642 | Standard_Real Du,Dv,mu,Mu,mv,Mv; | |
3643 | gp_Pnt2d UVf1,UVf2,UVl1,UVl2; | |
3644 | ||
3645 | UVf1 = FiCo1.PCurveOnSurf()->Value(FiCo1.FirstParameter()); | |
3646 | UVl1 = FiCo1.PCurveOnSurf()->Value(FiCo1.LastParameter()); | |
3647 | UVf2 = FiArc1.PCurveOnSurf()->Value(FiArc1.FirstParameter()); | |
3648 | UVl2 = FiArc1.PCurveOnSurf()->Value(FiArc1.LastParameter()); | |
3649 | ChFi3d_Boite(UVf1,UVf2,UVl1,UVl2,Du,Dv,mu,Mu,mv,Mv); | |
3650 | GeomAbs_SurfaceType styp = S1.GetType(); | |
3651 | if (styp == GeomAbs_Cylinder) { | |
3652 | Dv = Max(0.5*Dv,4.*S1.Cylinder().Radius()); | |
3653 | Du = 0.; | |
3654 | S1.Load(DStr.Surface(Fd1->Surf()).Surface(), | |
3655 | mu,Mu,mv-Dv,Mv+Dv); | |
3656 | } | |
81bba717 | 3657 | //In the case of a torus or cone, it is not necessary that the bounds create a surface with period more than 2PI. |
7fd59977 | 3658 | else if (styp == GeomAbs_Torus || |
3659 | styp == GeomAbs_Cone) { | |
c6541a0c | 3660 | Du = Min(M_PI-0.5*Du,0.1*Du); |
7fd59977 | 3661 | Dv = 0.; |
3662 | S1.Load(DStr.Surface(Fd1->Surf()).Surface(), | |
3663 | mu-Du,Mu+Du,mv,Mv); | |
3664 | } | |
3665 | else if (styp == GeomAbs_Plane) { | |
3666 | Du = Max(0.5*Du,4.*Dv); | |
3667 | Dv = 0.; | |
3668 | S1.Load(DStr.Surface(Fd1->Surf()).Surface(), | |
3669 | mu-Du,Mu+Du,mv,Mv); | |
3670 | } | |
3671 | return HS1; | |
3672 | } | |
7fd59977 | 3673 | //======================================================================= |
3674 | //function : SearchPivot | |
3675 | //purpose : | |
3676 | //======================================================================= | |
3677 | Standard_Integer ChFi3d_SearchPivot(Standard_Integer* s, | |
3678 | Standard_Real u[3][3], | |
3679 | const Standard_Real t) | |
3680 | { | |
81bba717 | 3681 | // This function finds as pivot a cd the sections which of |
3682 | // do not cross on the opposite face. | |
3683 | // - probably there will be cases asymmetric to the point that | |
3684 | // none of tree fillets will match! To be SEEN. | |
3685 | // - in case when several fillets match the | |
3686 | // first one taken is not inevitably the best | |
3687 | // it should be refined by comparing the parameters on | |
3688 | // guide lines and (/or) radiuses. | |
7fd59977 | 3689 | |
3690 | Standard_Boolean bondeb,bonfin; | |
3691 | for(Standard_Integer i = 0; i <= 2; i++) { | |
3692 | if(s[(i+1)%3] == 1) {bondeb = (u[(i+1)%3][i]-u[(i+1)%3][(i+2)%3] >= -t);} | |
3693 | else {bondeb = (u[(i+1)%3][i]-u[(i+1)%3][(i+2)%3] <= t);} | |
3694 | if(s[(i+2)%3] == 1) {bonfin = (u[(i+2)%3][i]-u[(i+2)%3][(i+1)%3] >= -t);} | |
3695 | else {bonfin = (u[(i+2)%3][i]-u[(i+2)%3][(i+1)%3] <= t);} | |
3696 | if (bondeb && bonfin) { return i; } | |
3697 | } | |
3698 | return -1; | |
3699 | } | |
3700 | ||
3701 | ||
3702 | ||
3703 | //======================================================================= | |
3704 | //function : SearchFD | |
3705 | //purpose : | |
3706 | //======================================================================= | |
3707 | Standard_Boolean ChFi3d_SearchFD(TopOpeBRepDS_DataStructure& DStr, | |
3708 | const Handle(ChFiDS_Stripe)& cd1, | |
3709 | const Handle(ChFiDS_Stripe)& cd2, | |
3710 | const Standard_Integer sens1, | |
3711 | const Standard_Integer sens2, | |
3712 | Standard_Integer& i1, | |
3713 | Standard_Integer& i2, | |
3714 | Standard_Real& p1, | |
3715 | Standard_Real& p2, | |
3716 | const Standard_Integer ind1, | |
3717 | const Standard_Integer ind2, | |
3718 | TopoDS_Face& face, | |
3719 | Standard_Boolean& sameside, | |
3720 | Standard_Integer& jf1, | |
3721 | Standard_Integer& jf2) | |
3722 | { | |
3723 | Standard_Boolean found = Standard_False; | |
3724 | Standard_Integer id1 = ind1, id2 = ind2; | |
3725 | Standard_Integer if1 = ind1, if2 = ind2; | |
3726 | Standard_Integer l1 = cd1->SetOfSurfData()->Length(); | |
3727 | Standard_Integer l2 = cd2->SetOfSurfData()->Length(); | |
3728 | Standard_Integer i; | |
3729 | Standard_Boolean fini1 = Standard_False, fini2 = Standard_False; | |
3730 | Standard_Boolean visavis,visavisok = Standard_False; | |
3731 | TopoDS_Vertex Vtx; | |
3732 | while( !found ) { | |
3733 | for(i = id1; (i*sens1) <= (if1*sens1) && !found && !fini2; i = i+sens1 ) { | |
3734 | if(ChFi3d_IsInFront(DStr,cd1,cd2,i,if2,sens1,sens2,p1,p2,face,sameside,jf1,jf2,visavis,Vtx,Standard_False,0)) { | |
3735 | i1 = i; | |
3736 | i2 = if2; | |
3737 | found = Standard_True; | |
3738 | } | |
3739 | else if (visavis && !visavisok) { | |
3740 | visavisok = Standard_True; | |
3741 | i1 = i; | |
3742 | i2 = if2; | |
3743 | } | |
3744 | } | |
3745 | if(!fini1) { | |
3746 | if1 = if1 + sens1; | |
3747 | if(if1 < 1 || if1 > l1) { if1 = if1 - sens1; fini1 = Standard_True; } | |
3748 | } | |
3749 | ||
3750 | for(i = id2; (i*sens2) <= (if2*sens2) && !found && !fini1; i = i+sens2 ) { | |
3751 | if(ChFi3d_IsInFront(DStr,cd1,cd2,if1,i,sens1,sens2,p1,p2,face,sameside,jf1,jf2,visavis,Vtx,Standard_False,0)) { | |
3752 | i1 = if1; | |
3753 | i2 = i; | |
3754 | found = Standard_True; | |
3755 | } | |
3756 | else if (visavis && !visavisok) { | |
3757 | visavisok = Standard_True; | |
3758 | i1 = if1; | |
3759 | i2 = i; | |
3760 | } | |
3761 | } | |
3762 | if(!fini2) { | |
3763 | if2 = if2 + sens2; | |
3764 | if(if2 < 1 || if2 > l2) { if2 = if2 - sens2; fini2 = Standard_True; } | |
3765 | } | |
3766 | if(fini1 && fini2) break; | |
3767 | } | |
3768 | return found; | |
3769 | } | |
3770 | ||
3771 | //======================================================================= | |
3772 | //function : Parameters | |
3773 | //purpose : compute the parameters <u> and <v> of the 3d point <p3d> | |
3774 | // on the surface <S> if it's an analytic surface | |
3775 | //======================================================================= | |
3776 | ||
3777 | void ChFi3d_Parameters(const Handle(Geom_Surface)& S, | |
3778 | const gp_Pnt& p3d, | |
3779 | Standard_Real& u, | |
3780 | Standard_Real& v) | |
3781 | { | |
3782 | GeomAdaptor_Surface gas(S); | |
3783 | switch ( gas.GetType() ) { | |
3784 | case GeomAbs_Plane : | |
3785 | ElSLib::Parameters(gas.Plane(),p3d,u,v); | |
3786 | break; | |
3787 | case GeomAbs_Cylinder : | |
3788 | ElSLib::Parameters(gas.Cylinder(),p3d,u,v); | |
3789 | break; | |
3790 | case GeomAbs_Cone : | |
3791 | ElSLib::Parameters(gas.Cone(),p3d,u,v); | |
3792 | break; | |
3793 | case GeomAbs_Sphere : | |
3794 | ElSLib::Parameters(gas.Sphere(),p3d,u,v); | |
3795 | break; | |
3796 | case GeomAbs_Torus : | |
3797 | ElSLib::Parameters(gas.Torus(),p3d,u,v); | |
3798 | break; | |
3799 | case GeomAbs_BezierSurface : | |
3800 | case GeomAbs_BSplineSurface : | |
3801 | default : | |
3802 | { | |
3803 | GeomAPI_ProjectPointOnSurf tool(p3d,S); | |
3804 | if ( tool.NbPoints() != 1 ) | |
3805 | StdFail_NotDone::Raise(""); | |
3806 | else | |
3807 | tool.Parameters(1,u,v); | |
3808 | } | |
3809 | } | |
3810 | } | |
3811 | ||
3812 | //======================================================================= | |
3813 | //function : TrimCurve | |
3814 | //purpose : trims the curve <gc> between the points <FirstP> and | |
3815 | // <LastP>. The trimmed curve is <gtc> | |
3816 | //======================================================================= | |
3817 | ||
3818 | void ChFi3d_TrimCurve(const Handle(Geom_Curve)& gc, | |
3819 | const gp_Pnt& FirstP, | |
3820 | const gp_Pnt& LastP, | |
3821 | Handle(Geom_TrimmedCurve)& gtc) | |
3822 | { | |
7fd59977 | 3823 | Standard_Real uf = 0.,ul = 0.; |
7fd59977 | 3824 | GeomAdaptor_Curve gac(gc); |
3825 | switch ( gac.GetType() ) { | |
3826 | case GeomAbs_Line : | |
3827 | { | |
3828 | uf = ElCLib::Parameter(gac.Line(),FirstP); | |
3829 | ul = ElCLib::Parameter(gac.Line(),LastP); | |
3830 | } | |
3831 | break; | |
3832 | case GeomAbs_Circle : | |
3833 | { | |
3834 | uf = ElCLib::Parameter(gac.Circle(),FirstP); | |
3835 | ul = ElCLib::Parameter(gac.Circle(),LastP); | |
3836 | } | |
3837 | break; | |
3838 | case GeomAbs_Ellipse : | |
3839 | { | |
3840 | uf = ElCLib::Parameter(gac.Ellipse(),FirstP); | |
3841 | ul = ElCLib::Parameter(gac.Ellipse(),LastP); | |
3842 | } | |
3843 | break; | |
3844 | case GeomAbs_Hyperbola : | |
3845 | { | |
3846 | uf = ElCLib::Parameter(gac.Hyperbola(),FirstP); | |
3847 | ul = ElCLib::Parameter(gac.Hyperbola(),LastP); | |
3848 | } | |
3849 | break; | |
3850 | case GeomAbs_Parabola : | |
3851 | { | |
3852 | uf = ElCLib::Parameter(gac.Parabola(),FirstP); | |
3853 | ul = ElCLib::Parameter(gac.Parabola(),LastP); | |
3854 | } | |
3855 | break; | |
3856 | default : | |
3857 | { | |
3858 | GeomAPI_ProjectPointOnCurve tool(FirstP,gc); | |
3859 | if ( tool.NbPoints() != 1 ) | |
3860 | StdFail_NotDone::Raise(""); | |
3861 | else | |
3862 | uf = tool.Parameter(1); | |
3863 | tool.Init(LastP,gc); | |
3864 | if ( tool.NbPoints() != 1 ) | |
3865 | StdFail_NotDone::Raise(""); | |
3866 | else | |
3867 | ul = tool.Parameter(1); | |
3868 | } | |
3869 | } | |
3870 | gtc = new Geom_TrimmedCurve(gc,uf,ul); | |
3871 | } | |
3872 | ||
065bb8b0 | 3873 | |
3874 | ||
7fd59977 | 3875 | //======================================================================= |
065bb8b0 | 3876 | //function : GoodExt |
7fd59977 | 3877 | //purpose : |
3878 | //======================================================================= | |
7fd59977 | 3879 | static Standard_Boolean GoodExt(const Handle(Geom_Curve)& C, |
3880 | const gp_Vec& V, | |
3881 | const Standard_Real f, | |
3882 | const Standard_Real l, | |
3883 | const Standard_Real a) | |
3884 | { | |
3885 | for(Standard_Integer i = 0; i < 6; i++) { | |
3886 | gp_Pnt d0; gp_Vec d1; | |
3887 | const Standard_Real t = i * 0.2; | |
3888 | C->D1(((1-t)*f+t*l),d0,d1); | |
3889 | const Standard_Real ang = d1.Angle(V); | |
3890 | const Standard_Real angref = a*t + 0.002; | |
3891 | if(ang > angref) return Standard_False; | |
3892 | } | |
3893 | return Standard_True; | |
3894 | } | |
065bb8b0 | 3895 | //======================================================================= |
3896 | //function : PerformElSpine | |
3897 | //purpose : | |
3898 | //======================================================================= | |
3899 | Standard_EXPORT | |
3900 | void ChFi3d_PerformElSpine(Handle(ChFiDS_HElSpine)& HES, | |
3901 | Handle(ChFiDS_Spine)& Spine, | |
3902 | const GeomAbs_Shape continuity, | |
3903 | const Standard_Real tol) | |
7fd59977 | 3904 | { |
81bba717 | 3905 | |
065bb8b0 | 3906 | Standard_Boolean periodic, Bof, checkdeb, cepadur,bIsSmooth; |
3907 | Standard_Integer IEdge,IF,IL,nbed, iToApproxByC2; | |
1d47d8d0 | 3908 | Standard_Real WF, WL, Wrefdeb, Wreffin,nwf,nwl,period,pared = 0.,tolpared; |
065bb8b0 | 3909 | Standard_Real First, Last, epsV, urefdeb, tolrac; |
3910 | GeomAbs_Shape aContinuity; | |
3911 | gp_Pnt PDeb, PFin, Bout; | |
3912 | gp_Vec VrefDeb, VrefFin; | |
3913 | Handle(Geom_Curve) Cv; | |
3914 | Handle(Geom_BoundedCurve) TC; | |
3915 | Handle(Geom_BSplineCurve) BS, BSpline; | |
3916 | TopoDS_Edge E, Eold; | |
3917 | TopoDS_Vertex V; | |
3918 | // | |
3919 | ChFiDS_ElSpine& ES = HES->ChangeCurve(); | |
3920 | WF = ES.FirstParameter(); | |
3921 | WL = ES.LastParameter(); | |
3922 | Wrefdeb = WF; | |
3923 | Wreffin = WL; | |
3924 | nwf = WF; | |
3925 | nwl = WL; | |
3926 | nbed = Spine->NbEdges(); | |
3927 | periodic = Spine->IsPeriodic(); | |
7fd59977 | 3928 | if(periodic) { |
3929 | period = Spine->Period(); | |
3930 | nwf = ElCLib::InPeriod(WF,-tol,period-tol); | |
3931 | IF = Spine->Index(nwf,1); | |
3932 | nwl = ElCLib::InPeriod(WL,tol,period+tol); | |
3933 | IL = Spine->Index(nwl,0); | |
3934 | if(nwl<nwf+tol) IL += nbed; | |
3935 | } | |
3936 | else{ | |
3937 | IF = Spine->Index(WF,1); | |
3938 | IL = Spine->Index(WL,0); | |
3939 | Wrefdeb = Max(Spine->FirstParameter(IF),WF); | |
3940 | Wreffin = Min(Spine->LastParameter(IL),WL); | |
3941 | } | |
065bb8b0 | 3942 | // |
7fd59977 | 3943 | Spine->D1(WF,PDeb,VrefDeb); |
3944 | Spine->D1(WL,PFin,VrefFin); | |
3945 | VrefDeb.Normalize(); | |
3946 | VrefFin.Normalize(); | |
065bb8b0 | 3947 | // |
7fd59977 | 3948 | TColgp_Array1OfPnt ExtrapPole(1, 5); |
3949 | TColgp_Array1OfPnt ExtraCoeffs(1, 5); | |
3950 | TColgp_Array1OfXYZ Cont(1,5); | |
065bb8b0 | 3951 | // Attention on segmente eventuellement la premiere et la |
3952 | // derniere arete. | |
3953 | // Traitment de la premiere arete | |
3954 | cepadur = 0; | |
3955 | E=Spine->Edges(IF); | |
3956 | Bof=BRepLib::BuildCurve3d(E); | |
7fd59977 | 3957 | const BRepAdaptor_Curve& edc = Spine->CurrentElementarySpine(IF); |
3958 | tolpared = edc.Resolution(tol); | |
065bb8b0 | 3959 | Cv = BRep_Tool::Curve(E, First, Last); |
3960 | urefdeb = Spine->FirstParameter(IF); | |
3961 | checkdeb = (nwf > urefdeb); | |
3962 | if(checkdeb) { | |
3963 | Spine->Parameter(IF,nwf,pared,0); | |
3964 | } | |
3965 | // | |
7fd59977 | 3966 | if(E.Orientation() == TopAbs_REVERSED) { |
3967 | Standard_Real sov = First; | |
3968 | First = Cv->ReversedParameter(Last); | |
3969 | Last = Cv->ReversedParameter(sov); | |
065bb8b0 | 3970 | if(checkdeb) { |
3971 | pared = Cv->ReversedParameter(pared); | |
3972 | } | |
3973 | else{ | |
3974 | pared = First; | |
3975 | } | |
3976 | if(First < pared) { | |
3977 | First = pared; | |
3978 | } | |
7fd59977 | 3979 | if(IL == IF) { |
3980 | Standard_Real ureffin = Spine->LastParameter(IL); | |
3981 | Standard_Boolean checkfin = (nwl < ureffin); | |
3982 | if(checkfin) { | |
3983 | Spine->Parameter(IL,nwl,pared,0); | |
3984 | pared = Cv->ReversedParameter(pared); | |
3985 | } | |
065bb8b0 | 3986 | else { |
3987 | pared = Last; | |
3988 | } | |
3989 | if(pared < Last) { | |
3990 | Last = pared; | |
3991 | } | |
7fd59977 | 3992 | } |
3993 | Cv = Cv->Reversed(); | |
065bb8b0 | 3994 | }//if(E.Orientation() == TopAbs_REVERSED) |
3995 | else {//#1 | |
3996 | if(!checkdeb) { | |
3997 | pared = First; | |
3998 | } | |
3999 | if(First < pared) { | |
4000 | First = pared; | |
4001 | } | |
7fd59977 | 4002 | if(IL == IF) { |
4003 | Standard_Real ureffin = Spine->LastParameter(IL); | |
4004 | Standard_Boolean checkfin = (nwl < ureffin); | |
065bb8b0 | 4005 | if(checkfin) { |
4006 | Spine->Parameter(IL,nwl,pared,0); | |
4007 | } | |
4008 | else { | |
4009 | pared = Last; | |
4010 | } | |
4011 | if(pared < Last) { | |
4012 | Last = pared; | |
4013 | } | |
7fd59977 | 4014 | } |
065bb8b0 | 4015 | }// else {//#1 |
4016 | // | |
4017 | if(Abs(Last-First) < tolpared) { | |
4018 | cepadur = 1; | |
7fd59977 | 4019 | } |
065bb8b0 | 4020 | // |
4021 | //Petite veru pour les cas ou un KPart a bouffe l arete | |
4022 | //sans parvenir a terminer. On tire une droite. | |
7fd59977 | 4023 | if(cepadur) { |
4024 | Handle(Geom_Line) L; | |
4025 | gp_Pnt ptemp; gp_Vec vtemp; | |
4026 | if(WL < Spine->FirstParameter(1) + tol) { | |
4027 | ES.LastPointAndTgt(ptemp,vtemp); | |
4028 | gp_Dir d(vtemp); | |
4029 | gp_Pnt olin; | |
4030 | olin.ChangeCoord().SetLinearForm(-WL,d.XYZ(),PFin.XYZ()); | |
4031 | L = new Geom_Line(olin,d); | |
4032 | ES.SetCurve(L); | |
4033 | } | |
4034 | else if(WF > Spine->LastParameter(nbed) - tol) { | |
4035 | ES.FirstPointAndTgt(ptemp,vtemp); | |
4036 | gp_Dir d(vtemp); | |
4037 | gp_Pnt olin; | |
4038 | olin.ChangeCoord().SetLinearForm(-WF,d.XYZ(),PDeb.XYZ()); | |
4039 | L = new Geom_Line(olin,d); | |
4040 | ES.SetCurve(L); | |
4041 | } | |
065bb8b0 | 4042 | return;// => |
7fd59977 | 4043 | } |
065bb8b0 | 4044 | // |
4045 | TC = new (Geom_TrimmedCurve)(Cv, First, Last); | |
4046 | BS=GeomConvert::CurveToBSplineCurve(TC); | |
7fd59977 | 4047 | CurveCleaner(BS, Abs(WL-WF)*1.e-4, 0); |
065bb8b0 | 4048 | // |
7fd59977 | 4049 | //Smoothing of the curve |
065bb8b0 | 4050 | iToApproxByC2=0; |
4051 | aContinuity=TC->Continuity(); | |
4052 | bIsSmooth=ChFi3d_IsSmooth(TC); | |
4053 | if (aContinuity < GeomAbs_C2 && !bIsSmooth) { | |
4054 | ++iToApproxByC2; | |
4055 | BS = ChFi3d_ApproxByC2(TC); | |
4056 | TC=BS; | |
4057 | } | |
4058 | // | |
4059 | // Concatenation des aretes suivantes | |
7fd59977 | 4060 | GeomConvert_CompCurveToBSplineCurve Concat( TC, Convert_QuasiAngular ); |
065bb8b0 | 4061 | // |
7fd59977 | 4062 | Eold = E; |
065bb8b0 | 4063 | for (IEdge=IF+1; IEdge<=IL; ++IEdge) { |
7fd59977 | 4064 | Standard_Integer iloc = IEdge; |
065bb8b0 | 4065 | if(periodic) { |
4066 | iloc = (IEdge - 1)%nbed + 1; | |
4067 | } | |
4068 | // | |
7fd59977 | 4069 | E = Spine->Edges(iloc); |
065bb8b0 | 4070 | if (BRep_Tool::Degenerated(E)) { |
4071 | continue; | |
4072 | } | |
4073 | // | |
4074 | epsV = tol; | |
4075 | Bof = TopExp::CommonVertex(Eold, E, V); | |
4076 | if (Bof) { | |
4077 | epsV = BRep_Tool::Tolerance(V); | |
4078 | } | |
4079 | // | |
4080 | Bof = BRepLib::BuildCurve3d(E); | |
4081 | if (!Bof) { | |
4082 | Standard_ConstructionError::Raise("PerformElSpine : BuildCurve3d error"); | |
4083 | } | |
4084 | // | |
4085 | Cv = BRep_Tool::Curve(E, First, Last); | |
4086 | if(IEdge == IL) { | |
4087 | Standard_Real ureffin = Spine->LastParameter(iloc); | |
4088 | Standard_Boolean checkfin = (nwl < ureffin); | |
4089 | if(checkfin) { | |
4090 | Spine->Parameter(iloc,nwl,pared,0); | |
7fd59977 | 4091 | } |
065bb8b0 | 4092 | else { |
4093 | pared = Last; | |
4094 | } | |
4095 | if(E.Orientation() == TopAbs_REVERSED) { | |
4096 | Standard_Real sov = First; | |
4097 | First = Cv->ReversedParameter(Last); | |
4098 | Last = Cv->ReversedParameter(sov); | |
4099 | if(checkfin) { | |
4100 | pared = Cv->ReversedParameter(pared); | |
81bba717 | 4101 | } |
065bb8b0 | 4102 | else{ |
4103 | pared = Last; | |
4104 | } | |
4105 | Cv = Cv->Reversed(); | |
7fd59977 | 4106 | } |
065bb8b0 | 4107 | if(pared < Last) { |
4108 | Last = pared; | |
81bba717 | 4109 | } |
e520f87c | 4110 | } |
065bb8b0 | 4111 | // |
4112 | TC = new (Geom_TrimmedCurve)(Cv, First, Last); | |
4113 | BS = GeomConvert::CurveToBSplineCurve(TC); | |
4114 | CurveCleaner(BS, Abs(WL-WF)*1.e-4, 0); | |
4115 | // | |
4116 | //Smoothing of the curve | |
4117 | aContinuity=TC->Continuity(); | |
4118 | bIsSmooth=ChFi3d_IsSmooth(TC); | |
4119 | if (aContinuity < GeomAbs_C2 && !bIsSmooth) { | |
4120 | ++iToApproxByC2; | |
4121 | BS = ChFi3d_ApproxByC2( TC ); | |
4122 | TC = BS; | |
4123 | } | |
4124 | // | |
4125 | tolrac = Min(tol, epsV); | |
4126 | Bof = Concat.Add( TC, 2.*tolrac, Standard_True ); | |
4127 | // si l'ajout ne s'est pas bien passe on essai d'augmenter la tolerance | |
4128 | if (!Bof) { | |
4129 | Bof = Concat.Add( TC, 2.*epsV, Standard_True ); | |
4130 | } | |
4131 | if (!Bof) { | |
4132 | Bof = Concat.Add( TC, 200.*epsV, Standard_True ); | |
4133 | if (!Bof) { | |
4134 | Standard_ConstructionError::Raise("PerformElSpine: spine merged error"); | |
4135 | } | |
4136 | } | |
7fd59977 | 4137 | Eold = E; |
065bb8b0 | 4138 | }// for (IEdge=IF+1; IEdge<=IL; ++IEdge) { |
4139 | // | |
4140 | // On a la portion d elspine calculee sans prolongements sur la partie | |
4141 | // valide des aretes du chemin. | |
7fd59977 | 4142 | BSpline = Concat.BSplineCurve(); |
81bba717 | 4143 | // There is a reparametrisation to maximally connect the abscissas of edges. |
7fd59977 | 4144 | TColStd_Array1OfReal BSNoeuds (1, BSpline->NbKnots()); |
4145 | BSpline->Knots(BSNoeuds); | |
4146 | BSplCLib::Reparametrize (Wrefdeb, Wreffin, BSNoeuds); | |
4147 | BSpline->SetKnots(BSNoeuds); | |
065bb8b0 | 4148 | // |
4149 | // Traitement des Extremites | |
4150 | Standard_Integer caredeb, carefin; | |
4151 | Standard_Real LocalWL, LocalWF, Angle; | |
7fd59977 | 4152 | GeomAdaptor_Curve gacurve; |
7fd59977 | 4153 | Handle(Geom_BSplineCurve) newc; |
065bb8b0 | 4154 | // |
4155 | caredeb = 0; | |
4156 | carefin = 0; | |
c6541a0c | 4157 | Angle = M_PI*0.75; |
065bb8b0 | 4158 | LocalWL = WL; |
4159 | LocalWF = WF; | |
7fd59977 | 4160 | if (!ES.IsPeriodic() && !PDeb.IsEqual(BSpline->Pole(1), tol) ) { |
065bb8b0 | 4161 | // Prolongement C3 au debut |
4162 | // afin d'eviter des pts d'inflexions dans la partie utile de la | |
4163 | // spine le prolongement se fait jusqu'a un point eloigne. | |
4164 | if(BSpline->IsRational()) { | |
4165 | caredeb = 1; | |
4166 | } | |
4167 | // | |
7fd59977 | 4168 | Standard_Real rabdist = Wrefdeb - WF; |
4169 | Bout = PDeb.Translated(-20*rabdist * VrefDeb); | |
4170 | Standard_Boolean goodext = 0; | |
4171 | for(Standard_Integer icont = 3; icont>=1 && !goodext; icont--) { | |
4172 | newc = BSpline; | |
4173 | GeomLib::ExtendCurveToPoint( newc, Bout, icont, Standard_False); | |
4174 | gacurve.Load(newc); | |
4175 | GCPnts_AbscissaPoint GCP(gacurve,-rabdist,Wrefdeb,WF); | |
4176 | if(GCP.IsDone()) { | |
4177 | WF = GCP.Parameter(); | |
4178 | goodext = GoodExt(newc,VrefDeb,Wrefdeb,WF,Angle); | |
4179 | } | |
4180 | } | |
065bb8b0 | 4181 | if(caredeb) { |
4182 | caredeb = newc->NbKnots() - BSpline->NbKnots(); | |
4183 | } | |
7fd59977 | 4184 | BSpline = newc; |
4185 | LocalWF = BSpline->FirstParameter(); | |
4186 | } | |
065bb8b0 | 4187 | // |
7fd59977 | 4188 | if (!ES.IsPeriodic() && !PFin.IsEqual(BSpline->Pole(BSpline->NbPoles()), tol) ) { |
065bb8b0 | 4189 | // Prolongement C3 en fin |
4190 | if(BSpline->IsRational()) { | |
4191 | carefin = 1; | |
4192 | } | |
7fd59977 | 4193 | Standard_Real rabdist = WL - Wreffin; |
4194 | Bout = PFin.Translated(20*rabdist * VrefFin); | |
4195 | Standard_Boolean goodext = 0; | |
4196 | for(Standard_Integer icont = 3; icont>=1 && !goodext; icont--) { | |
4197 | newc = BSpline; | |
4198 | GeomLib::ExtendCurveToPoint( newc, Bout, icont, Standard_True); | |
4199 | gacurve.Load(newc); | |
4200 | GCPnts_AbscissaPoint GCP(gacurve,rabdist,Wreffin,WL); | |
4201 | if(GCP.IsDone()) { | |
4202 | WL = GCP.Parameter(); | |
4203 | goodext = GoodExt(newc, VrefFin, Wreffin,WL,Angle); | |
4204 | } | |
4205 | } | |
065bb8b0 | 4206 | if(carefin) { |
4207 | carefin = newc->NbKnots() - BSpline->NbKnots(); | |
4208 | } | |
7fd59977 | 4209 | BSpline = newc; |
4210 | LocalWL = BSpline->LastParameter(); | |
4211 | } | |
065bb8b0 | 4212 | // |
4213 | //Reparametrisation et segmentation sur le domaine de la Spine. | |
4214 | if(Abs(BSpline->FirstParameter() - WF)<tol) { | |
4215 | WF = BSpline->FirstParameter(); | |
4216 | } | |
4217 | if(Abs(BSpline->LastParameter() - WL)<tol) { | |
4218 | WL = BSpline->LastParameter(); | |
4219 | } | |
4220 | // | |
4221 | if ( (LocalWF<WF) || (LocalWL>WL)) { // pour eviter des pb avec segment! | |
7fd59977 | 4222 | BSpline->Segment(WF, WL); |
4223 | ES.FirstParameter(WF); | |
4224 | ES.LastParameter(WL); | |
4225 | } | |
065bb8b0 | 4226 | // |
7fd59977 | 4227 | if (BSpline->IsRational()) { |
4228 | Handle(Geom_BSplineCurve) C1; | |
4229 | C1 = Handle(Geom_BSplineCurve)::DownCast(BSpline->Copy()); | |
4230 | GeomConvert::C0BSplineToC1BSplineCurve(C1, tol, 0.1); | |
065bb8b0 | 4231 | // Il faut s'assurer que l'origine n'a pas bouge (cts21158) |
4232 | if (C1->FirstParameter() == BSpline->FirstParameter()) { | |
4233 | BSpline = C1; | |
4234 | } | |
7fd59977 | 4235 | else { |
065bb8b0 | 4236 | //cout << "Attention : Echec de C0BSplineToC1 !" << endl; |
7fd59977 | 4237 | } |
4238 | } | |
065bb8b0 | 4239 | // |
4240 | Standard_Integer fk, lk, MultMax, ii; | |
4241 | // Deformation eventuelle pour rendre la spine C2. | |
4242 | // ou C3 pour des approx C2 | |
4243 | if((caredeb || carefin) && BSpline->Degree() < 8) { | |
4244 | BSpline->IncreaseDegree(8); | |
4245 | } | |
4246 | // | |
4247 | fk = 2; | |
4248 | lk = BSpline->NbKnots()-1; | |
4249 | if(BSpline->IsPeriodic()) { | |
4250 | fk = 1; | |
4251 | } | |
4252 | if(caredeb) { | |
4253 | fk += caredeb; | |
4254 | } | |
4255 | if(carefin) { | |
4256 | lk -= carefin; | |
4257 | } | |
4258 | // | |
7fd59977 | 4259 | if (continuity == GeomAbs_C3) { |
065bb8b0 | 4260 | if (BSpline->Degree() < 7) { |
4261 | BSpline->IncreaseDegree(7); | |
4262 | } | |
7fd59977 | 4263 | MultMax = BSpline->Degree() - 3; |
4264 | } | |
4265 | else { | |
065bb8b0 | 4266 | if (BSpline->Degree() < 5) { |
4267 | BSpline->IncreaseDegree(5); | |
4268 | } | |
7fd59977 | 4269 | MultMax = BSpline->Degree() - 2; |
4270 | } | |
81bba717 | 4271 | // correction C2 or C3 (if possible) |
7fd59977 | 4272 | CurveCleaner(BSpline, Abs(WL-WF)*1.e-4, 1); |
4273 | CurveCleaner(BSpline, Abs(WL-WF)*1.e-2, MultMax); | |
4274 | Standard_Integer MultMin = Max(BSpline->Degree() - 4, 1); | |
4275 | for (ii = fk; ii <= lk; ii++) { | |
4276 | if( BSpline->Multiplicity(ii) > MultMax ) { | |
4277 | Bof = BSpline->RemoveKnot(ii, MultMax, Abs(WL-WF)/10); | |
4278 | } | |
81bba717 | 4279 | // See C4 |
7fd59977 | 4280 | if( BSpline->Multiplicity(ii) > MultMin ) { |
4281 | Bof = BSpline->RemoveKnot(ii, MultMin, Abs(WL-WF)*1.e-4); | |
4282 | } | |
4283 | } | |
81bba717 | 4284 | // elspine periodic => BSpline Periodic |
7fd59977 | 4285 | if(ES.IsPeriodic()) { |
4286 | if(!BSpline->IsPeriodic()) { | |
4287 | BSpline->SetPeriodic(); | |
065bb8b0 | 4288 | //modified by NIZNHY-PKV Fri Dec 10 12:20:22 2010ft |
4289 | if (iToApproxByC2) { | |
4290 | Bof = BSpline->RemoveKnot(1, MultMax, Abs(WL-WF)/10); | |
4291 | } | |
4292 | //Bof = BSpline->RemoveKnot(1, MultMax, Abs(WL-WF)/10); | |
4293 | //modified by NIZNHY-PKV Mon Dec 13 14:12:54 2010t | |
7fd59977 | 4294 | } |
4295 | } | |
4296 | else { | |
81bba717 | 4297 | // Otherwise is it necessary to move the poles to adapt |
4298 | // them to new tangents ? | |
7fd59977 | 4299 | Standard_Boolean adjust = Standard_False; |
4300 | gp_Pnt P1, P2; | |
4301 | gp_Vec V1, V2; | |
4302 | BSpline->D1(WF, P1, V1); | |
4303 | V1.Normalize(); | |
4304 | ES.FirstPointAndTgt(PDeb,VrefDeb); | |
4305 | Standard_Real scaldeb = VrefDeb.Dot(V1); | |
4306 | Standard_Real disdeb = PDeb.Distance(P1); | |
81bba717 | 4307 | if((Abs(WF-LocalWF) < 1.e-12) && |
4308 | ((scaldeb <= 0.9999999) || | |
4309 | disdeb >= tol)) { | |
4310 | // Yes if there was no extension and the tangent is not the good one. | |
7fd59977 | 4311 | adjust = Standard_True; |
4312 | } | |
4313 | BSpline->D1(WL, P2, V2); | |
4314 | V2.Normalize(); | |
4315 | ES.LastPointAndTgt(PFin,VrefFin); | |
4316 | Standard_Real scalfin = VrefFin.Dot(V2); | |
4317 | Standard_Real disfin = PFin.Distance(P2); | |
4318 | if((Abs(WL-LocalWL) < 1.e-12) && | |
81bba717 | 4319 | ((scalfin <= 0.9999999)|| |
4320 | disfin >= tol)) { | |
4321 | // the same at the end | |
7fd59977 | 4322 | adjust = Standard_True; |
4323 | } | |
065bb8b0 | 4324 | if(adjust) { |
4325 | GeomLib::AdjustExtremity(BSpline, PDeb, PFin, VrefDeb, VrefFin); | |
4326 | } | |
7fd59977 | 4327 | } |
4328 | ||
065bb8b0 | 4329 | // Le Resultat |
7fd59977 | 4330 | ES.SetCurve(BSpline); |
7fd59977 | 4331 | } |
4332 | ||
4333 | //======================================================================= | |
4334 | //function : cherche_face1 | |
81bba717 | 4335 | //purpose : find face F different from F1 in the map. |
4336 | // The map contains two faces adjacent to an edge | |
7fd59977 | 4337 | //======================================================================= |
4338 | void ChFi3d_cherche_face1 (const TopTools_ListOfShape & map, | |
4339 | const TopoDS_Face & F1, | |
4340 | TopoDS_Face & F) | |
4341 | { | |
4342 | TopoDS_Face Fcur; | |
4343 | Standard_Boolean trouve=Standard_False; | |
4344 | TopTools_ListIteratorOfListOfShape It; | |
4345 | for (It.Initialize(map);It.More()&&!trouve;It.Next()) { | |
4346 | Fcur=TopoDS::Face (It.Value()); | |
4347 | if (!Fcur.IsSame(F1)) { | |
4348 | F=Fcur;trouve=Standard_True;} | |
4349 | } | |
4350 | } | |
4351 | //======================================================================= | |
4352 | //function : cherche_element | |
81bba717 | 4353 | //purpose : find edge E of F1 other than E1 and containing vertex V |
4354 | // Vtx is the other vertex of E | |
7fd59977 | 4355 | //======================================================================= |
7fd59977 | 4356 | void ChFi3d_cherche_element(const TopoDS_Vertex & V, |
4357 | const TopoDS_Edge & E1, | |
4358 | const TopoDS_Face & F1, | |
4359 | TopoDS_Edge & E , | |
4360 | TopoDS_Vertex & Vtx ) | |
4361 | { | |
4362 | Standard_Integer ie; | |
4363 | TopoDS_Vertex V1,V2; | |
4364 | Standard_Boolean trouve=Standard_False; | |
4365 | TopoDS_Edge Ecur; | |
4366 | TopTools_IndexedMapOfShape MapE; | |
4367 | TopExp::MapShapes( F1,TopAbs_EDGE,MapE); | |
4368 | for ( ie=1; ie<= MapE.Extent()&& !trouve; ie++) { | |
4369 | Ecur = TopoDS::Edge (MapE(ie)); | |
4370 | if (!Ecur.IsSame(E1)) { | |
4371 | TopTools_IndexedMapOfShape MapV; | |
4372 | TopExp::MapShapes(Ecur, TopAbs_VERTEX, MapV); | |
4373 | if (MapV.Extent()==2) { | |
4374 | V1 = TopoDS::Vertex (MapV(1)); | |
4375 | V2 = TopoDS::Vertex (MapV(2)); | |
4376 | if (V1.IsSame(V)) { | |
4377 | Vtx=V2; | |
4378 | E=Ecur; | |
4379 | trouve=Standard_True; | |
4380 | } | |
4381 | else if (V2.IsSame(V)) { | |
4382 | Vtx=V1; | |
4383 | E=Ecur; | |
4384 | trouve=Standard_True; | |
4385 | } | |
4386 | } | |
4387 | } | |
4388 | } | |
4389 | } | |
4390 | //======================================================================= | |
4391 | //function : cherche_edge | |
81bba717 | 4392 | //purpose : find edge E of F1 other than the list of edges E1 and |
4393 | // containing vertex V Vtx is the other vertex of E. | |
7fd59977 | 4394 | //======================================================================= |
7fd59977 | 4395 | void ChFi3d_cherche_edge(const TopoDS_Vertex & V, |
4396 | const TopTools_Array1OfShape & E1, | |
4397 | const TopoDS_Face & F1, | |
4398 | TopoDS_Edge & E , | |
4399 | TopoDS_Vertex & Vtx ) | |
4400 | { | |
4401 | Standard_Integer ie,i; | |
4402 | TopoDS_Vertex V1,V2; | |
4403 | Standard_Boolean trouve=Standard_False; | |
4404 | TopoDS_Edge Ecur; | |
4405 | Standard_Boolean same; | |
4406 | TopTools_IndexedMapOfShape MapE; | |
4407 | TopExp::MapShapes( F1,TopAbs_EDGE,MapE); | |
4408 | for ( ie=1; ie<= MapE.Extent()&& !trouve; ie++) { | |
4409 | Ecur=TopoDS::Edge (MapE(ie)); | |
4410 | same=Standard_False; | |
4411 | for (i=E1.Lower();i<=E1.Upper() ;i++) { | |
4412 | if (Ecur.IsSame(E1.Value(i))) same=Standard_True; | |
4413 | } | |
4414 | if (!same) { | |
4415 | TopTools_IndexedMapOfShape MapV; | |
4416 | TopExp::MapShapes(Ecur, TopAbs_VERTEX, MapV); | |
4417 | if (MapV.Extent()==2) { | |
4418 | V1 = TopoDS::Vertex (MapV(1)); | |
4419 | V2 = TopoDS::Vertex (MapV(2)); | |
4420 | if (V1.IsSame(V)) { | |
4421 | Vtx=V2; | |
4422 | E=Ecur; | |
4423 | trouve=Standard_True; | |
4424 | } | |
4425 | else if (V2.IsSame(V)) { | |
4426 | Vtx=V1; | |
4427 | E=Ecur; | |
4428 | trouve=Standard_True; | |
4429 | } | |
4430 | } | |
4431 | } | |
4432 | } | |
4433 | } | |
4434 | ||
4435 | //======================================================================= | |
4436 | //function : nbface | |
81bba717 | 4437 | //purpose : calculates the number of faces common to a vertex |
7fd59977 | 4438 | // |
4439 | //======================================================================= | |
4440 | Standard_Integer ChFi3d_nbface (const TopTools_ListOfShape & mapVF ) | |
4441 | { Standard_Integer nface=0; | |
4442 | TopTools_ListIteratorOfListOfShape ItF,JtF; | |
4443 | Standard_Integer fj = 0; | |
4444 | for (ItF.Initialize(mapVF); ItF.More(); ItF.Next()) { | |
4445 | fj++; | |
4446 | Standard_Integer kf = 1; | |
4447 | const TopoDS_Shape& cur = ItF.Value(); | |
4448 | for (JtF.Initialize(mapVF); JtF.More( )&&(kf<fj); JtF.Next(), kf++) { | |
4449 | if(cur.IsSame(JtF.Value())) break; | |
4450 | } | |
4451 | if(kf == fj) nface++; | |
4452 | } | |
4453 | return nface; | |
4454 | } | |
4455 | ||
4456 | //======================================================================= | |
4457 | //function : edge_common_faces | |
81bba717 | 4458 | //purpose : determines two faces sharing an edge. |
4459 | // F1 = F2 if there is an edge to parce | |
7fd59977 | 4460 | //======================================================================= |
7fd59977 | 4461 | void ChFi3d_edge_common_faces (const TopTools_ListOfShape & mapEF, |
4462 | TopoDS_Face & F1, | |
4463 | TopoDS_Face & F2) | |
4464 | { TopTools_ListIteratorOfListOfShape It; | |
4465 | TopoDS_Face F; | |
4466 | Standard_Boolean trouve; | |
4467 | It.Initialize(mapEF); | |
4468 | F1=TopoDS::Face(It.Value()); | |
4469 | trouve=Standard_False; | |
4470 | for(It.Initialize(mapEF);It.More()&&!trouve;It.Next()) { | |
4471 | F=TopoDS::Face (It.Value()); | |
4472 | if (!F.IsSame(F1)) { | |
4473 | F2=F;trouve=Standard_True; | |
4474 | } | |
4475 | } | |
4476 | if (!trouve) F2=F1; | |
4477 | } | |
4478 | ||
4479 | /***********************************************************/ | |
81bba717 | 4480 | // gives the angle between edges E1 and E2 . Vtx is the |
4481 | // vertex common to the edges | |
7fd59977 | 4482 | /************************************************************/ |
4483 | Standard_Real ChFi3d_AngleEdge (const TopoDS_Vertex & Vtx, | |
4484 | const TopoDS_Edge& E1, | |
4485 | const TopoDS_Edge & E2) | |
4486 | { Standard_Real angle; | |
4487 | BRepAdaptor_Curve BCurv1(E1); | |
4488 | BRepAdaptor_Curve BCurv2(E2); | |
4489 | Standard_Real parE1,parE2; | |
4490 | gp_Vec dir1,dir2 ; | |
4491 | gp_Pnt P1,P2 ; | |
4492 | parE1=BRep_Tool::Parameter(Vtx,E1); | |
4493 | parE2=BRep_Tool::Parameter(Vtx,E2); | |
4494 | BCurv1.D1(parE1,P1,dir1); | |
4495 | BCurv2.D1(parE2,P2,dir2); | |
4496 | if (!Vtx.IsSame(TopExp::FirstVertex(E1))) dir1.Reverse(); | |
4497 | if (!Vtx.IsSame(TopExp::FirstVertex(E2))) dir2.Reverse(); | |
4498 | angle=Abs(dir1.Angle(dir2)); | |
4499 | return angle; | |
4500 | } | |
4501 | ||
4502 | //================================================================== | |
4503 | // ChercheBordsLibres | |
81bba717 | 4504 | // determines if vertex V1 has edges on free borders |
4505 | // edgelibre1 and edgelibre2 . | |
4506 | // It is supposed that a top can have only 2 edges on free borders | |
7fd59977 | 4507 | //=================================================================== |
4508 | void ChFi3d_ChercheBordsLibres(const ChFiDS_Map & myVEMap, | |
4509 | const TopoDS_Vertex & V1, | |
4510 | Standard_Boolean & bordlibre, | |
4511 | TopoDS_Edge & edgelibre1, | |
4512 | TopoDS_Edge & edgelibre2) | |
4513 | { | |
4514 | bordlibre=Standard_False; | |
4515 | TopTools_ListIteratorOfListOfShape ItE,ItE1; | |
4516 | Standard_Integer nboccur; | |
4517 | for (ItE.Initialize(myVEMap(V1)); ItE.More()&&!bordlibre; ItE.Next()) { | |
4518 | nboccur=0; | |
4519 | const TopoDS_Edge& cur = TopoDS::Edge(ItE.Value()); | |
4520 | if (!BRep_Tool::Degenerated(cur)) { | |
4521 | for (ItE1.Initialize(myVEMap(V1)); ItE1.More(); ItE1.Next()) { | |
4522 | const TopoDS_Edge& cur1 = TopoDS::Edge(ItE1.Value()); | |
4523 | if (cur1.IsSame(cur)) nboccur++; | |
4524 | } | |
4525 | } | |
4526 | if (nboccur==1) { | |
4527 | edgelibre1=cur; | |
4528 | bordlibre=Standard_True; | |
4529 | } | |
4530 | } | |
4531 | if (bordlibre) { | |
4532 | bordlibre=Standard_False; | |
4533 | for (ItE.Initialize(myVEMap(V1)); ItE.More()&&!bordlibre; ItE.Next()) { | |
4534 | nboccur=0; | |
4535 | const TopoDS_Edge& cur = TopoDS::Edge(ItE.Value()); | |
4536 | if (!BRep_Tool::Degenerated(cur)&&!cur.IsSame(edgelibre1)) { | |
4537 | for (ItE1.Initialize(myVEMap(V1)); ItE1.More(); ItE1.Next()) { | |
4538 | const TopoDS_Edge& cur1 = TopoDS::Edge(ItE1.Value()); | |
4539 | if (cur1.IsSame(cur)) nboccur++; | |
4540 | } | |
4541 | } | |
4542 | if (nboccur==1) { | |
4543 | edgelibre2=cur; | |
4544 | bordlibre=Standard_True; | |
4545 | } | |
4546 | } | |
4547 | } | |
4548 | } | |
4549 | ||
4550 | //======================================================================= | |
4551 | //function : NbNotDegeneratedEdges | |
81bba717 | 4552 | //purpose : calculate the number of non-degenerated edges of Map VEMap(Vtx) |
4553 | // Attention the edges of junctions are taken into account twice | |
7fd59977 | 4554 | //======================================================================= |
4555 | Standard_Integer ChFi3d_NbNotDegeneratedEdges (const TopoDS_Vertex& Vtx, | |
4556 | const ChFiDS_Map& VEMap) | |
4557 | { | |
4558 | TopTools_ListIteratorOfListOfShape ItE; | |
4559 | Standard_Integer nba=VEMap(Vtx).Extent(); | |
4560 | for (ItE.Initialize(VEMap(Vtx)); ItE.More(); ItE.Next()) { | |
4561 | const TopoDS_Edge& cur = TopoDS::Edge(ItE.Value()); | |
4562 | if (BRep_Tool::Degenerated(cur)) nba--; | |
4563 | } | |
4564 | return nba; | |
4565 | } | |
4566 | ||
4567 | //======================================================================= | |
4568 | //function : NumberOfEdges | |
81bba717 | 4569 | //purpose : calculate the number of edges arriving to the top Vtx |
4570 | // degenerated edges are not taken into account. | |
7fd59977 | 4571 | //======================================================================= |
4572 | Standard_Integer ChFi3d_NumberOfEdges(const TopoDS_Vertex& Vtx, | |
4573 | const ChFiDS_Map& VEMap) | |
4574 | { | |
4575 | Standard_Integer nba; | |
4576 | Standard_Boolean bordlibre; | |
4577 | TopoDS_Edge edgelibre1,edgelibre2; | |
4578 | nba=ChFi3d_NbNotDegeneratedEdges(Vtx, VEMap); | |
4579 | ChFi3d_ChercheBordsLibres(VEMap,Vtx,bordlibre,edgelibre1,edgelibre2); | |
4580 | if (bordlibre) nba=(nba-2)/2 +2; | |
4581 | else nba=nba/2; | |
4582 | return nba; | |
4583 | } | |
81bba717 | 4584 | //===================================================== |
4585 | // function cherche_vertex | |
4586 | // finds common vertex between two edges | |
4587 | //===================================================== | |
4588 | ||
7fd59977 | 4589 | void ChFi3d_cherche_vertex (const TopoDS_Edge & E1, |
4590 | const TopoDS_Edge & E2, | |
4591 | TopoDS_Vertex & vertex, | |
4592 | Standard_Boolean & trouve) | |
4593 | { Standard_Integer i,j; | |
4594 | TopoDS_Vertex Vcur1,Vcur2; | |
4595 | trouve=Standard_False; | |
4596 | TopTools_IndexedMapOfShape MapV1,MapV2; | |
4597 | TopExp::MapShapes( E1,TopAbs_VERTEX,MapV1); | |
4598 | TopExp::MapShapes( E2,TopAbs_VERTEX,MapV2); | |
4599 | for ( i=1; i<= MapV1.Extent()&&!trouve; i++) { | |
4600 | TopoDS_Shape alocalshape = TopoDS_Shape (MapV1(i)); | |
4601 | Vcur1=TopoDS::Vertex(alocalshape); | |
4602 | // Vcur1=TopoDS::Vertex(TopoDS_Shape (MapV1(i))); | |
4603 | for ( j=1; j<= MapV2.Extent()&&!trouve; j++) { | |
4604 | TopoDS_Shape aLocalShape = TopoDS_Shape (MapV2(j)); | |
4605 | Vcur2=TopoDS::Vertex(aLocalShape); | |
4606 | // Vcur2=TopoDS::Vertex(TopoDS_Shape (MapV2(j))); | |
4607 | if (Vcur2.IsSame(Vcur1)) { | |
4608 | vertex=Vcur1;trouve=Standard_True; | |
4609 | } | |
4610 | } | |
4611 | } | |
4612 | } | |
065bb8b0 | 4613 | //======================================================================= |
4614 | //function : ChFi3d_Couture | |
4615 | //purpose : determine si F a une arete de couture | |
4616 | //======================================================================= | |
7fd59977 | 4617 | void ChFi3d_Couture( const TopoDS_Face & F, |
4618 | Standard_Boolean & couture, | |
4619 | TopoDS_Edge & edgecouture) | |
4620 | { TopoDS_Edge Ecur; | |
4621 | couture=Standard_False; | |
4622 | TopTools_IndexedMapOfShape MapE1; | |
4623 | TopExp::MapShapes( F,TopAbs_EDGE,MapE1); | |
4624 | TopLoc_Location Loc; | |
4625 | Handle(Geom_Surface) Surf =BRep_Tool::Surface(F,Loc); | |
4626 | for ( Standard_Integer i=1; i<= MapE1.Extent()&&!couture; i++) { | |
4627 | TopoDS_Shape aLocalShape = TopoDS_Shape (MapE1(i)); | |
4628 | Ecur=TopoDS::Edge(aLocalShape); | |
4629 | // Ecur=TopoDS::Edge(TopoDS_Shape (MapE1(i))); | |
4630 | if (BRep_Tool::IsClosed(Ecur,Surf,Loc)) { | |
4631 | couture=Standard_True; | |
4632 | edgecouture=Ecur; | |
4633 | } | |
4634 | } | |
4635 | } | |
4636 | ||
065bb8b0 | 4637 | //======================================================================= |
4638 | //function : ChFi3d_CoutureOnVertex | |
4639 | //purpose : | |
4640 | //======================================================================= | |
7fd59977 | 4641 | void ChFi3d_CoutureOnVertex( const TopoDS_Face & F, |
4642 | const TopoDS_Vertex & V, | |
4643 | Standard_Boolean & couture, | |
4644 | TopoDS_Edge & edgecouture) | |
4645 | { TopoDS_Edge Ecur; | |
4646 | couture = Standard_False; | |
4647 | TopTools_IndexedMapOfShape MapE1; | |
4648 | TopExp::MapShapes( F,TopAbs_EDGE,MapE1); | |
4649 | TopLoc_Location Loc; | |
4650 | Handle(Geom_Surface) Surf = BRep_Tool::Surface(F,Loc); | |
4651 | for ( Standard_Integer i=1; i <= MapE1.Extent(); i++) { | |
4652 | TopoDS_Shape aLocalShape = TopoDS_Shape (MapE1(i)); | |
4653 | Ecur=TopoDS::Edge(aLocalShape); | |
4654 | // Ecur=TopoDS::Edge(TopoDS_Shape (MapE1(i))); | |
4655 | if (BRep_Tool::IsClosed(Ecur,Surf,Loc)) { | |
4656 | TopoDS_Vertex Vf, Vl; | |
4657 | TopExp::Vertices( Ecur, Vf, Vl ); | |
4658 | if (Vf.IsSame(V) || Vl.IsSame(V)) | |
4659 | { | |
4660 | couture = Standard_True; | |
4661 | edgecouture = Ecur; | |
4662 | break; | |
4663 | } | |
4664 | } | |
4665 | } | |
4666 | } | |
065bb8b0 | 4667 | //======================================================================= |
4668 | //function : ChFi3d_IsPseudoSeam | |
4669 | //purpose : | |
4670 | //======================================================================= | |
7fd59977 | 4671 | Standard_Boolean ChFi3d_IsPseudoSeam( const TopoDS_Edge& E, |
065bb8b0 | 4672 | const TopoDS_Face& F ) |
7fd59977 | 4673 | { |
4674 | if (! BRep_Tool::IsClosed( E, F )) | |
4675 | return Standard_False; | |
4676 | ||
4677 | Standard_Boolean NeighborSeamFound = Standard_False; | |
4678 | TopoDS_Vertex Vf, Vl, V1, V2; | |
4679 | TopExp::Vertices( E, Vf, Vl ); | |
4680 | TopExp_Explorer Explo( F, TopAbs_EDGE ); | |
4681 | for (; Explo.More(); Explo.Next()) | |
4682 | { | |
4683 | TopoDS_Edge Ecur = TopoDS::Edge( Explo.Current() ); | |
4684 | if (! Ecur.IsSame(E)) | |
4685 | { | |
4686 | TopExp::Vertices( Ecur, V1, V2 ); | |
4687 | if ((V1.IsSame(Vf) || V1.IsSame(Vl) || V2.IsSame(Vf) || V2.IsSame(Vl)) && | |
4688 | BRepTools::IsReallyClosed( Ecur, F )) | |
4689 | { | |
4690 | NeighborSeamFound = Standard_True; | |
4691 | break; | |
4692 | } | |
4693 | } | |
4694 | } | |
4695 | return NeighborSeamFound; | |
4696 | } | |
4697 | ||
065bb8b0 | 4698 | //======================================================================= |
4699 | //function : ChFi3d_ApproxByC2 | |
4700 | //purpose : | |
4701 | //======================================================================= | |
7fd59977 | 4702 | Handle(Geom_BSplineCurve) ChFi3d_ApproxByC2( const Handle(Geom_Curve)& C ) |
4703 | { | |
4704 | Standard_Real First = C->FirstParameter(), Last = C->LastParameter(); | |
4705 | Standard_Integer NbPoints = 101; | |
4706 | ||
4707 | TColgp_Array1OfPnt Points( 1, NbPoints ); | |
4708 | Standard_Real delta = (Last - First) / (NbPoints-1); | |
4709 | for (Standard_Integer i = 1; i <= NbPoints-1; i++) | |
4710 | Points(i) = C->Value(First + (i-1)*delta); | |
4711 | Points(NbPoints) = C->Value(Last); | |
4712 | ||
4713 | GeomAPI_PointsToBSpline Approx( Points , Approx_ChordLength, 3, 8, GeomAbs_C2, 1.000001e-3); | |
4714 | Handle(Geom_BSplineCurve) BS = Approx.Curve(); | |
4715 | return BS; | |
4716 | } | |
065bb8b0 | 4717 | //======================================================================= |
4718 | //function : ChFi3d_IsSmooth | |
4719 | //purpose : | |
4720 | //======================================================================= | |
7fd59977 | 4721 | Standard_Boolean ChFi3d_IsSmooth( const Handle(Geom_Curve)& C ) |
4722 | { | |
4723 | GeomAdaptor_Curve GAC( C ); | |
4724 | ||
4725 | Standard_Integer ii; | |
4726 | Standard_Integer intrv, nbintv = GAC.NbIntervals(GeomAbs_CN); | |
4727 | TColStd_Array1OfReal TI(1,nbintv+1); | |
4728 | GAC.Intervals(TI,GeomAbs_CN); | |
4729 | Standard_Real Resolution = gp::Resolution(), Curvature; | |
4730 | GeomLProp_CLProps LProp(C, 2, Resolution); | |
4731 | gp_Pnt P1, P2; | |
4732 | Standard_Integer Discretisation = 30; | |
4733 | ||
7fd59977 | 4734 | gp_Vec PrevVec; |
4735 | Standard_Boolean prevVecFound = Standard_False; | |
4736 | Standard_Integer intrvFound = 0; | |
4737 | for( intrv = 1; intrv <= nbintv; intrv++) { | |
4738 | Standard_Real t = TI(intrv); | |
4739 | Standard_Real step = (TI(intrv+1) - t) / Discretisation; | |
4740 | for (ii = 1; ii <= Discretisation; ii++) { | |
4741 | LProp.SetParameter(t); | |
4742 | if (!LProp.IsTangentDefined()) | |
4743 | return Standard_False; | |
4744 | Curvature = Abs(LProp.Curvature()); | |
4745 | if (Curvature > Resolution) { | |
4746 | C->D0(t, P1); | |
4747 | LProp.CentreOfCurvature(P2); | |
4748 | PrevVec = gp_Vec(P1, P2); | |
4749 | prevVecFound = Standard_True; | |
4750 | break; | |
4751 | } | |
4752 | t += step; | |
4753 | } | |
4754 | if( prevVecFound ) { | |
4755 | intrvFound = intrv; | |
4756 | break; | |
4757 | } | |
4758 | } | |
4759 | ||
4760 | if( !prevVecFound ) | |
4761 | return Standard_True; | |
4762 | ||
4763 | //for (intrv = 1; intrv <= nbintv; intrv++) { | |
4764 | for (intrv = intrvFound; intrv <= nbintv; intrv++) { | |
4765 | Standard_Real t = TI(intrv); | |
4766 | Standard_Real step = (TI(intrv+1) - t) / Discretisation; | |
4767 | for (ii = 1; ii <= Discretisation; ii++) | |
4768 | { | |
4769 | LProp.SetParameter(t); | |
4770 | if (!LProp.IsTangentDefined()) | |
4771 | return Standard_False; | |
4772 | Curvature = Abs(LProp.Curvature()); | |
4773 | if (Curvature > Resolution) | |
4774 | { | |
4775 | C->D0(t, P1); | |
4776 | LProp.CentreOfCurvature(P2); | |
4777 | gp_Vec Vec(P1, P2); | |
4778 | Standard_Real Angle = PrevVec.Angle( Vec ); | |
c6541a0c | 4779 | if (Angle > M_PI/3.) |
7fd59977 | 4780 | return Standard_False; |
4781 | Standard_Real Ratio = Vec.Magnitude() / PrevVec.Magnitude(); | |
4782 | if (Ratio < 1.) | |
4783 | Ratio = 1. / Ratio; | |
4784 | if (Ratio > 2. && (intrv != nbintv || ii != Discretisation)) | |
4785 | return Standard_False; | |
4786 | PrevVec = Vec; | |
4787 | } | |
4788 | t += step; | |
4789 | } | |
4790 | } | |
4791 | ||
4792 | return Standard_True; | |
4793 | } |