1 // Created on: 1993-12-15
2 // Created by: Isabelle GRIGNON
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor2d_Curve2d.hxx>
19 #include <Adaptor3d_Surface.hxx>
20 #include <Adaptor3d_TopolTool.hxx>
21 #include <AppBlend_Approx.hxx>
22 #include <Blend_CurvPointFuncInv.hxx>
23 #include <Blend_FuncInv.hxx>
24 #include <Blend_Function.hxx>
25 #include <Blend_RstRstFunction.hxx>
26 #include <Blend_SurfCurvFuncInv.hxx>
27 #include <Blend_SurfPointFuncInv.hxx>
28 #include <Blend_SurfRstFunction.hxx>
29 #include <BRep_Tool.hxx>
30 #include <BRepAdaptor_Curve.hxx>
31 #include <BRepAdaptor_Curve2d.hxx>
32 #include <BRepAdaptor_Surface.hxx>
33 #include <BRepBlend_Line.hxx>
34 #include <BRepLib_MakeFace.hxx>
35 #include <BRepLProp_SLProps.hxx>
36 #include <BRepTools.hxx>
37 #include <BRepTools_WireExplorer.hxx>
38 #include <BRepTopAdaptor_TopolTool.hxx>
40 #include <ChFi3d_Builder.hxx>
41 #include <ChFi3d_Builder_0.hxx>
42 #include <ChFiDS_ChamfSpine.hxx>
43 #include <ChFiDS_CommonPoint.hxx>
44 #include <ChFiDS_ElSpine.hxx>
45 #include <ChFiDS_ErrorStatus.hxx>
46 #include <ChFiDS_FaceInterference.hxx>
47 #include <ChFiDS_FilSpine.hxx>
48 #include <ChFiDS_HData.hxx>
49 #include <ChFiDS_ElSpine.hxx>
50 #include <ChFiDS_ListIteratorOfListOfHElSpine.hxx>
51 #include <ChFiDS_ListOfHElSpine.hxx>
52 #include <ChFiDS_SequenceOfSurfData.hxx>
53 #include <ChFiDS_Spine.hxx>
54 #include <ChFiDS_State.hxx>
55 #include <ChFiDS_Stripe.hxx>
56 #include <ChFiDS_SurfData.hxx>
57 #include <ChFiKPart_ComputeData.hxx>
59 #include <Extrema_ExtPC.hxx>
60 #include <Extrema_ExtPS.hxx>
61 #include <Extrema_LocateExtPC.hxx>
62 #include <Extrema_POnCurv.hxx>
63 #include <Geom2d_Curve.hxx>
64 #include <Geom_BSplineCurve.hxx>
65 #include <Geom_BSplineSurface.hxx>
66 #include <Geom_Line.hxx>
67 #include <Geom_Plane.hxx>
68 #include <Geom_Surface.hxx>
69 #include <GeomAdaptor_Curve.hxx>
70 #include <GeomAdaptor_Surface.hxx>
71 #include <GeomAdaptor_Surface.hxx>
72 #include <GeomAPI_ProjectPointOnCurve.hxx>
75 #include <gp_Pnt2d.hxx>
78 #include <math_Vector.hxx>
79 #include <Precision.hxx>
80 #include <Standard_ConstructionError.hxx>
81 #include <Standard_NoSuchObject.hxx>
82 #include <Standard_NotImplemented.hxx>
83 #include <Standard_OutOfRange.hxx>
84 #include <TColgp_Array1OfPnt.hxx>
85 #include <TColgp_Array1OfVec.hxx>
86 #include <TColStd_Array1OfInteger.hxx>
87 #include <TColStd_Array1OfReal.hxx>
88 #include <TColStd_ListOfInteger.hxx>
90 #include <TopAbs_Orientation.hxx>
91 #include <TopAbs_ShapeEnum.hxx>
93 #include <TopExp_Explorer.hxx>
95 #include <TopoDS_Edge.hxx>
96 #include <TopoDS_Face.hxx>
97 #include <TopoDS_Shape.hxx>
98 #include <TopoDS_Vertex.hxx>
99 #include <TopoDS_Wire.hxx>
100 #include <TopOpeBRepBuild_HBuilder.hxx>
101 #include <TopOpeBRepDS_HDataStructure.hxx>
102 #include <TopTools_ListIteratorOfListOfShape.hxx>
106 #include <DrawTrSurf.hxx>
108 #include <OSD_Chronometer.hxx>
109 extern Standard_Real t_perfsetofkpart,t_perfsetofkgen,t_makextremities,t_performsurf,t_startsol;
110 extern Standard_Boolean ChFi3d_GettraceCHRON();
111 extern void ChFi3d_InitChron(OSD_Chronometer& ch);
112 extern void ChFi3d_ResultChron(OSD_Chronometer & ch, Standard_Real& time);
116 //===================================================================
117 // Definition by a plane
119 // It is considered that P1 and P2 are points associated to commonpoints compoint1 and
120 // compoint2, while E1 and E2 are edges containing P1 and P2.
121 // The plane containing three directions D12 T1 T2 ou D12 represente la direction formee
122 // par les points P1 et P2, T1 la tangente de E1 en P1 et T2 la tangente de
123 // E2 en P2 is found (if exists).
124 // Then fillet HConge is intersected by this plane
125 // to find associated curve 3d C3d and the curve 2d.
127 //====================================================================
128 static void ChFi3d_CoupeParPlan (const ChFiDS_CommonPoint & compoint1,
129 const ChFiDS_CommonPoint & compoint2,
130 Handle(GeomAdaptor_Surface)& HConge,
131 const gp_Pnt2d & UV1,
132 const gp_Pnt2d & UV2,
133 const Standard_Real tol3d,
134 const Standard_Real tol2d,
135 Handle(Geom_Curve) &C3d,
136 Handle(Geom2d_Curve) &pcurve,
137 Standard_Real & tolreached,
138 Standard_Real & Pardeb,
139 Standard_Real & Parfin,
140 Standard_Boolean & plane)
141 { plane=Standard_True;
142 if(compoint1.IsOnArc() && compoint2.IsOnArc() ) {
144 BRepAdaptor_Curve BCurv1(compoint1.Arc());
145 BRepAdaptor_Curve BCurv2(compoint2.Arc());
146 Standard_Real parE1,parE2;
147 parE1=compoint1.ParameterOnArc();
148 parE2=compoint2.ParameterOnArc();
150 BCurv1.D1(parE1,P1,t1);
151 BCurv2.D1(parE2,P2,t2);
154 gp_Vec v12(P2.X()-P1.X(),P2.Y()-P1.Y(),P2.Z()-P1.Z());
156 gp_Dir nor =tgt1.Crossed(d12);
157 Handle (Geom_Plane) Plan=new Geom_Plane(P1,nor);
159 scal=Abs(nor.Dot(tgt2));
161 Handle(GeomAdaptor_Surface) HPlan=new GeomAdaptor_Surface(Plan);
162 Handle(Geom2d_Curve) C2dint2;
163 TColStd_Array1OfReal Pdeb(1,4),Pfin(1,4);
164 GeomAdaptor_Surface AS(Plan);
165 Extrema_ExtPS ext(P1,AS,1.e-3,1.e-3);
166 Extrema_ExtPS ext1 (P2,AS,1.e-3,1.e-3);
168 ext.Point(1).Parameter(u1,v1);
169 Pdeb(1)= UV1.X();Pdeb(2) = UV1.Y();
170 Pdeb(3)= u1;Pdeb(4) =v1;
171 ext1.Point(1).Parameter(u1,v1);
172 Pfin(1)= UV2.X();Pfin(2) = UV2.Y();
173 Pfin(3)= u1;Pfin(4) = v1;
174 if (ChFi3d_ComputeCurves(HConge,HPlan,Pdeb,Pfin,C3d,
175 pcurve,C2dint2,tol3d,tol2d,tolreached)){
176 Pardeb=C3d->FirstParameter();
177 Parfin=C3d->LastParameter();
179 else plane=Standard_False;
181 else plane=Standard_False;
183 else plane=Standard_False;
185 //=======================================================================
186 //function : SortieTangente
188 //=======================================================================
190 static Standard_Boolean SortieTangente(const ChFiDS_CommonPoint& CP,
191 const TopoDS_Face& /*F*/,
192 const Handle(ChFiDS_SurfData)& /*SD*/,
193 const Standard_Integer /*OnS*/,
194 const Standard_Real TolAngular)
196 if(!CP.HasVector()) return Standard_False;
199 Handle(Geom_Curve) C;
200 Standard_Real Uf, Ul;
201 C = BRep_Tool::Curve(CP.Arc(),Uf,Ul);
202 C->D1(CP.ParameterOnArc(), P, Darc);
204 return Dsurf.IsParallel(Darc, TolAngular);
207 //=======================================================================
208 //function : BonVoisin
210 //=======================================================================
212 static Standard_Boolean BonVoisin(const gp_Pnt& Point,
213 Handle(BRepAdaptor_Surface)& HS,
215 Handle(GeomAdaptor_Surface)& plane,
216 const TopoDS_Edge& cured,
219 const ChFiDS_Map& EFMap,
220 const Standard_Real tolesp)
222 Standard_Boolean bonvoisin = 1;
223 Standard_Real winter, Uf, Ul;
224 gp_Pnt papp = HS->Value(XDep, YDep);
225 Standard_Real dist = RealLast();
226 Handle(BRepAdaptor_Curve) hc = new BRepAdaptor_Curve();
227 Handle(Geom2d_Curve) PC;
228 Standard_Boolean found = 0;
231 for(Ex.Init(F,TopAbs_EDGE); Ex.More(); Ex.Next()){
232 const TopoDS_Edge& ecur = TopoDS::Edge(Ex.Current());
233 if(!ecur.IsSame(cured)){
234 hc->Initialize(ecur);
235 Standard_Real tolc = hc->Resolution(tolesp);
236 if(ChFi3d_InterPlaneEdge(plane,hc,winter,1,tolc)){
237 gp_Pnt np = hc->Value(winter);
238 Standard_Real ndist = np.SquareDistance(papp);
240 TopTools_ListIteratorOfListOfShape It;
242 Standard_Boolean isclosed = BRep_Tool::IsClosed(ecur, F);
243 Standard_Boolean isreallyclosed =
244 BRepTools::IsReallyClosed(ecur, F);
245 for(It.Initialize(EFMap(ecur));It.More();It.Next()){
246 ff = TopoDS::Face(It.Value());
247 Standard_Boolean issame = ff.IsSame(F);
248 // Modified by Sergey KHROMOV - Fri Dec 21 17:12:48 2001 Begin
249 // Standard_Boolean istg =
250 // BRep_Tool::Continuity(ecur,ff,F) != GeomAbs_C0;
251 Standard_Boolean istg = ChFi3d::IsTangentFaces(ecur,ff,F);
252 // Modified by Sergey KHROMOV - Fri Dec 21 17:12:51 2001 End
253 if((!issame || (issame && isreallyclosed)) && istg) {
255 TopoDS_Edge newe = ecur;
256 newe.Orientation(TopAbs_FORWARD);
259 if(isclosed && !isreallyclosed){
260 TopoDS_Face fff = ff;
261 fff.Orientation(TopAbs_FORWARD);
263 for(Ex2.Init(fff,TopAbs_EDGE);
264 Ex2.More(); Ex2.Next()){
265 if(newe.IsSame(Ex2.Current())){
266 newe = TopoDS::Edge(Ex2.Current());
267 PC = BRep_Tool::CurveOnSurface(newe,fff,Uf,Ul);
272 else PC = BRep_Tool::CurveOnSurface(newe,ff,Uf,Ul);
273 PC->Value(winter).Coord(XDep,YDep);
275 gp_Pnt spt; gp_Vec sdu,sdv,nors;
276 HS->D1(XDep, YDep, spt, sdu, sdv);
277 nors = sdu.Crossed(sdv);
278 gp_Pnt cpt; gp_Vec cd;
279 hc->D1(winter,cpt,cd);
280 gp_Vec vref(Point, cpt);
281 TopoDS_Face fff = ff;
282 fff.Orientation(TopAbs_FORWARD);
283 if(vref.Dot(nors.Crossed(cd)) < 0.){
284 newe.Orientation(TopAbs_REVERSED);
286 PC = BRep_Tool::CurveOnSurface(newe,fff,Uf,Ul);
287 PC->Value(winter).Coord(XDep, YDep);
296 if(!found) bonvoisin = 0;
300 //=======================================================================
301 //function : Projection
302 //purpose : Projects a point on a curve
303 //=======================================================================
305 static Standard_Boolean Projection(Extrema_ExtPC& PExt,
307 const Adaptor3d_Curve& C,
311 Standard_Real Dist2, daux2;
312 Dist2 = C.Value(W).SquareDistance(P);
314 // It is checked if it is not already a solution
315 if (Dist2 < Tol * Tol)
316 return Standard_True;
318 Standard_Boolean Ok = Standard_False;
320 // On essai une resolution initialise
321 Extrema_LocateExtPC ext(P,C,W,Tol/10);
323 daux2 = C.Value(ext.Point().Parameter()).SquareDistance(P);
325 W = ext.Point().Parameter();
328 if (Dist2 < Tol * Tol)
329 return Standard_True;
335 if ( PExt.IsDone() ) {
336 for (Standard_Integer ii=1; ii<= PExt.NbExt(); ii++) {
337 if (PExt.SquareDistance(ii) < Dist2) {
338 Dist2 = PExt.SquareDistance(ii);
339 W = PExt.Point(ii).Parameter();
347 //=======================================================================
350 //=======================================================================
352 static void TgtKP(const Handle(ChFiDS_SurfData)& CD,
353 const Handle(ChFiDS_Spine)& Spine,
354 const Standard_Integer iedge,
355 const Standard_Boolean isfirst,
359 Standard_Real wtg = CD->InterferenceOnS1().Parameter(isfirst);
360 const BRepAdaptor_Curve& bc = Spine->CurrentElementarySpine(iedge);
361 if(Spine->Edges(iedge).Orientation() == TopAbs_FORWARD)
362 bc.D1(wtg+bc.FirstParameter(),ped,ded);
364 bc.D1(-wtg+bc.LastParameter(),ped,ded);
370 //=======================================================================
372 //purpose : Checks if a vector belongs to a Face
373 //=======================================================================
375 Standard_Boolean IsInput(const gp_Vec& Vec,
376 const TopoDS_Vertex& Ve,
377 const TopoDS_Face& Fa)
379 TopExp_Explorer FaceExp(Fa, TopAbs_WIRE);
380 BRepTools_WireExplorer WireExp;
381 Standard_Integer Trouve = 0;
384 TopoDS_Vertex Vf, Vl;
388 // Find edges and compute 3D vectors
389 for ( ; (FaceExp.More() && (Trouve<2)); FaceExp.Next()) {
390 W = TopoDS::Wire(FaceExp.Current());
391 for (Trouve=0, WireExp.Init(W) ;
392 WireExp.More() && (Trouve<2); WireExp.Next()) {
393 E = TopoDS::Edge(WireExp.Current());
394 TopExp::Vertices(E, Vf, Vl);
396 BRepAdaptor_Curve Cb(E);
397 Cb.D1(BRep_Tool::Parameter(Ve, E), Point, Vec3d[Trouve]);
400 else if (Vl.IsSame(Ve)) {
401 BRepAdaptor_Curve Cb(E);
402 Cb.D1(BRep_Tool::Parameter(Ve, E), Point, Vec3d[Trouve]);
403 Vec3d[Trouve].Reverse();
408 if (Trouve < 2) return Standard_False;
409 // Calculate the normal and the angles in the associated vector plane
411 Normal = Vec3d[0] ^ Vec3d[1];
412 if (Normal.SquareMagnitude() < Precision::Confusion()) {//Colinear case
413 return (Vec.IsParallel(Vec3d[0],Precision::Confusion()));
416 Standard_Real amin, amax;
417 amax = Vec3d[1].AngleWithRef(Vec3d[0], Normal);
424 // Projection of the vector
425 gp_Ax3 Axe(Point, Normal, Vec3d[0]);
427 Transf.SetTransformation (Axe);
428 gp_XYZ coord = Vec.XYZ();
429 Transf.Transforms(coord);
432 Transf.Transforms(coord);
433 gp_Vec theProj(coord);
436 Standard_Real Angle = theProj.AngleWithRef(Vec3d[0], Normal);
437 return ( (Angle >= amin) && (Angle<=amax));
440 //=======================================================================
442 //purpose : Find a neighbor G1 by an edge
443 //=======================================================================
445 Standard_Boolean IsG1(const ChFiDS_Map& TheMap,
446 const TopoDS_Edge& E,
447 const TopoDS_Face& FRef,
450 TopTools_ListIteratorOfListOfShape It;
451 // Find a neighbor of E different from FRef (general case).
452 for(It.Initialize(TheMap(E));It.More();It.Next()) {
453 if (!TopoDS::Face(It.Value()).IsSame(FRef)) {
454 FVoi = TopoDS::Face(It.Value());
455 // Modified by Sergey KHROMOV - Fri Dec 21 17:09:32 2001 Begin
456 // if (BRep_Tool::Continuity(E,FRef,FVoi) != GeomAbs_C0) {
457 if (ChFi3d::IsTangentFaces(E,FRef,FVoi)) {
458 // Modified by Sergey KHROMOV - Fri Dec 21 17:09:33 2001 End
459 return Standard_True;
463 // If is was not found it is checked if E is a cutting edge,
464 // in which case FVoi = FRef is returned (less frequent case).
466 Standard_Boolean orset = Standard_False;
467 TopAbs_Orientation orient = TopAbs_FORWARD ;
469 for(Ex.Init(FRef,TopAbs_EDGE); Ex.More(); Ex.Next()){
470 ed = TopoDS::Edge(Ex.Current());
472 if(!orset){ orient = ed.Orientation(); orset = Standard_True; }
473 else if(ed.Orientation() == TopAbs::Reverse(orient)){
475 // Modified by Sergey KHROMOV - Fri Dec 21 17:15:12 2001 Begin
476 // if (BRep_Tool::Continuity(E,FRef,FRef) >= GeomAbs_G1) {
477 if (ChFi3d::IsTangentFaces(E,FRef,FRef)) {
478 // Modified by Sergey KHROMOV - Fri Dec 21 17:15:16 2001 End
479 return Standard_True;
481 return Standard_False;
485 return Standard_False;
488 //=======================================================================
489 //function : SearchFaceOnV
490 //purpose : Finds the output face(s) of the path by a vertex
491 // The following criteria should be followed
492 // -1 : The face shares regular edges with FRef
493 // (too hard condition that should be reconsidered)
494 // -2 : The vector starting in CommonPoint "belongs" to the face
495 //========================================================================
496 static Standard_Integer SearchFaceOnV(const ChFiDS_CommonPoint& Pc,
497 const TopoDS_Face& FRef,
498 const ChFiDS_Map& VEMap,
499 const ChFiDS_Map& EFMap,
503 // it is checked that it leaves the current face.
504 Standard_Boolean FindFace = IsInput(Pc.Vector(), Pc.Vertex(), FRef);
506 FindFace = IsInput(Pc.Vector().Reversed(), Pc.Vertex(), FRef);
508 // If it does not leave, it is finished
513 Standard_Integer Num = 0;
514 Standard_Boolean Trouve;
515 TopTools_ListIteratorOfListOfShape ItE, ItF;
519 for(ItE.Initialize(VEMap(Pc.Vertex()));
520 ItE.More() && (Num < 2); ItE.Next()) {
521 E = TopoDS::Edge(ItE.Value());
522 for(ItF.Initialize(EFMap(E)), Trouve=Standard_False;
523 ItF.More()&&(!Trouve); ItF.Next()) {
524 if (TopoDS::Face(ItF.Value()).IsSame(FRef)) {
525 Trouve = Standard_True;
528 if (Trouve) Trouve = IsG1(EFMap, E, FRef, FVoi);
529 if (Trouve) Trouve = IsInput(Pc.Vector(), Pc.Vertex(), FVoi);
531 if (Num == 0) F1 = FVoi;
539 //=======================================================================
540 //function : ChangeTransition
541 //purpose : Changes the transition of the second common Point, when the surface
542 // does not cross the arc
543 // As it is supposed that the support Faces are the same, it is enough
544 // to examine the cas of cutting edges.
545 //========================================================================
546 static void ChangeTransition(const ChFiDS_CommonPoint& Precedant,
547 ChFiDS_CommonPoint& Courant,
548 Standard_Integer FaceIndex,
549 const Handle(TopOpeBRepDS_HDataStructure)& DS)
551 Standard_Boolean tochange = Standard_True;
553 const TopoDS_Face& F = TopoDS::Face(DS->Shape(FaceIndex));
554 const TopoDS_Edge& Arc = Precedant.Arc();
555 Handle(Geom2d_Curve) PCurve1, PCurve2;
556 PCurve1 = BRep_Tool::CurveOnSurface(Arc, F, f, l);
557 TopoDS_Shape aLocalShape = Arc.Reversed();
558 PCurve2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShape), F, f, l);
559 // PCurve2 = BRep_Tool::CurveOnSurface(TopoDS::Edge(Arc.Reversed()), F, f, l);
560 if (PCurve1 != PCurve2) {
561 // This is a cutting edge, it is necessary to make a small Geometric test
564 BRepAdaptor_Curve AC(Arc);
565 AC.D1(Precedant.ParameterOnArc(), P, tgarc);
566 tochange = tgarc.IsParallel(Precedant.Vector(), Precision::Confusion());
570 Courant.SetArc(Precision::Confusion(),
572 Precedant.ParameterOnArc(),
573 TopAbs::Reverse(Precedant.TransitionOnArc()));
577 //=======================================================================
578 //function : CallPerformSurf
579 //purpose : Encapsulates call to PerformSurf/SimulSurf
580 //========================================================================
582 void ChFi3d_Builder::
583 CallPerformSurf(Handle(ChFiDS_Stripe)& Stripe,
584 const Standard_Boolean Simul,
585 ChFiDS_SequenceOfSurfData& SeqSD,
586 Handle(ChFiDS_SurfData)& SD,
587 const Handle(ChFiDS_ElSpine)& HGuide,
588 const Handle(ChFiDS_Spine)& Spine,
589 const Handle(BRepAdaptor_Surface)& HS1,
590 const Handle(BRepAdaptor_Surface)& HS3,
593 const Handle(Adaptor3d_TopolTool)& It1,
594 const Handle(BRepAdaptor_Surface)& HS2,
595 const Handle(BRepAdaptor_Surface)& HS4,
598 const Handle(Adaptor3d_TopolTool)& It2,
599 const Standard_Real MaxStep,
600 const Standard_Real Fleche,
601 const Standard_Real /*TolGuide*/,
602 Standard_Real& First,
604 const Standard_Boolean Inside,
605 const Standard_Boolean /*Appro*/,
606 const Standard_Boolean forward,
607 const Standard_Boolean RecOnS1,
608 const Standard_Boolean RecOnS2,
610 Standard_Integer& intf,
611 Standard_Integer& intl,
612 Handle(BRepAdaptor_Surface)& Surf1,
613 Handle(BRepAdaptor_Surface)& Surf2)
618 Handle(BRepAdaptor_Surface) HSon1, HSon2;
621 // Definition of the domain of path It1, It2
622 It1->Initialize((const Handle(Adaptor3d_Surface)&)HSon1);
623 It2->Initialize((const Handle(Adaptor3d_Surface)&)HSon2);
626 TopAbs_Orientation Or1 = HS1->Face().Orientation();
627 TopAbs_Orientation Or2 = HS2->Face().Orientation();
628 Standard_Integer Choix =
629 ChFi3d::NextSide(Or1,Or2,
630 Stripe->OrientationOnFace1(),
631 Stripe->OrientationOnFace2(),
633 Soldep(1) = pp1.X(); Soldep(2) = pp1.Y();
634 Soldep(3) = pp2.X(); Soldep(4) = pp2.Y();
636 Standard_Real thef = First, thel = Last;
637 Standard_Boolean isdone;
640 isdone = SimulSurf(SD,HGuide,Spine,Choix,HS1,It1,HS2,It2,tolesp,First,Last,
641 Inside,Inside,forward,RecOnS1,RecOnS2,Soldep,intf,intl);
646 ChFi3d_InitChron(ch1);//initial perform for PerformSurf
649 isdone = PerformSurf(SeqSD,HGuide,Spine,Choix,HS1,It1,HS2,It2,
650 MaxStep,Fleche,tolesp,
651 First,Last,Inside,Inside,forward,
652 RecOnS1,RecOnS2,Soldep,intf,intl);
654 ChFi3d_ResultChron(ch1,t_performsurf);// result perf for PerformSurf
662 Standard_Boolean reprise = Standard_False;
663 if (! HS3.IsNull()) {
665 It1->Initialize((const Handle(Adaptor3d_Surface)&)HS3);
666 Or1 = HS3->Face().Orientation();
667 Soldep(1) = pp3.X(); Soldep(2) = pp3.Y();
668 reprise = Standard_True;
670 else if (! HS4.IsNull()) {
672 It2->Initialize((const Handle(Adaptor3d_Surface)&)HS4);
673 Or2 = HS4->Face().Orientation();
674 Soldep(3) = pp4.X(); Soldep(4) = pp4.Y();
675 reprise = Standard_True;
679 Choix = ChFi3d::NextSide(Or1,Or2,
680 Stripe->OrientationOnFace1(),
681 Stripe->OrientationOnFace2(),
684 isdone = SimulSurf(SD,HGuide,Spine,Choix,HSon1,It1,HSon2,It2,
686 Inside,Inside,forward,RecOnS1,RecOnS2,
692 ChFi3d_InitChron(ch1);//init perf for PerformSurf
695 isdone = PerformSurf(SeqSD,HGuide,Spine,Choix,HSon1,It1,HSon2,It2,
696 MaxStep,Fleche,tolesp,
697 First,Last,Inside,Inside,forward,
698 RecOnS1,RecOnS2,Soldep,intf,intl);
700 ChFi3d_ResultChron(ch1,t_performsurf);// result perf for PerformSurf
709 //=======================================================================
710 //function : StripeOrientation
711 //purpose : Calculates the reference orientation determining the
712 // concave face for construction of the fillet.
713 //=======================================================================
715 Standard_Boolean ChFi3d_Builder::StripeOrientations
716 (const Handle(ChFiDS_Spine)& Spine,
717 TopAbs_Orientation& Or1,
718 TopAbs_Orientation& Or2,
719 Standard_Integer& ChoixConge) const
721 //TopTools_ListIteratorOfListOfShape It;
722 BRepAdaptor_Surface Sb1,Sb2;
723 TopAbs_Orientation Of1,Of2;
725 TopoDS_Edge anEdge = Spine->Edges(1);
726 TopoDS_Face FirstFace = TopoDS::Face(myEdgeFirstFace(anEdge));
727 ChFi3d_conexfaces(anEdge,ff1,ff2,myEFMap);
728 if (ff2.IsSame(FirstFace))
729 { TopoDS_Face TmpFace = ff1; ff1 = ff2; ff2 = TmpFace; }
730 Of1 = ff1.Orientation();
731 ff1.Orientation(TopAbs_FORWARD);
733 Of2 = ff2.Orientation();
734 ff2.Orientation(TopAbs_FORWARD);
737 ChoixConge = ChFi3d::ConcaveSide(Sb1,Sb2,Spine->Edges(1),
739 Or1 = TopAbs::Compose(Or1,Of1);
740 Or2 = TopAbs::Compose(Or2,Of2);
741 return Standard_True;
745 //=======================================================================
746 //function : ConexFaces
748 //=======================================================================
750 void ChFi3d_Builder::ConexFaces (const Handle(ChFiDS_Spine)& Spine,
751 const Standard_Integer IEdge,
752 Handle(BRepAdaptor_Surface)& HS1,
753 Handle(BRepAdaptor_Surface)& HS2) const
755 if(HS1.IsNull()) HS1 = new BRepAdaptor_Surface ();
756 if(HS2.IsNull()) HS2 = new BRepAdaptor_Surface ();
757 BRepAdaptor_Surface& Sb1 = *HS1;
758 BRepAdaptor_Surface& Sb2 = *HS2;
761 TopoDS_Edge anEdge = Spine->Edges(IEdge);
762 ChFi3d_conexfaces(Spine->Edges(IEdge),ff1,ff2,myEFMap);
764 TopoDS_Face FirstFace = TopoDS::Face(myEdgeFirstFace(anEdge));
765 if (ff2.IsSame(FirstFace))
766 { TopoDS_Face TmpFace = ff1; ff1 = ff2; ff2 = TmpFace; }
772 //=======================================================================
773 //function : StartSol
774 //purpose : Calculates a starting solution :
775 // - one starts by parsing about ten points on the spine,
776 // - in case of fail one finds the solution on neighbor faces;
777 // section plane of edges of the adjacent face
778 // and identication of the face by connection to that edge.
779 //=======================================================================
781 void ChFi3d_Builder::StartSol(const Handle(ChFiDS_Stripe)& Stripe,
782 const Handle(ChFiDS_ElSpine)& HGuide,
783 Handle(BRepAdaptor_Surface)& HS1,
784 Handle(BRepAdaptor_Surface)& HS2,
785 Handle(BRepTopAdaptor_TopolTool)& I1,
786 Handle(BRepTopAdaptor_TopolTool)& I2,
789 Standard_Real& First) const
791 Handle(ChFiDS_Spine)& Spine = Stripe->ChangeSpine();
792 ChFiDS_ElSpine& els = *HGuide;
793 Standard_Integer nbed = Spine->NbEdges();
794 Standard_Integer nbessaimax = 3*nbed;
795 if (nbessaimax < 10) nbessaimax = 10;
796 Standard_Real unsurnbessaimax = 1./nbessaimax;
797 Standard_Real wf = 0.9981 * Spine->FirstParameter(1) +
798 0.0019 * Spine->LastParameter(1);
799 Standard_Real wl = 0.9973 * Spine->LastParameter(nbed) +
800 0.0027 * Spine->FirstParameter(nbed);
802 Standard_Real TolE = 1.0e-7;
803 BRepAdaptor_Surface AS;
805 Standard_Integer nbessai;
806 Standard_Integer iedge = 0;
807 Standard_Integer RC = Stripe->Choix();
812 TopAbs_Orientation Or1,Or2;
813 Standard_Integer Choix = 0;
814 math_Vector SolDep(1,4);
815 Handle(Geom2d_Curve) PC;
818 Spine->FirstParameter(1),
819 Spine->LastParameter(nbed),
820 Precision::Confusion());
821 TopAbs_State Pos1,Pos2;
822 for(nbessai = 0; nbessai <= nbessaimax; nbessai++){
823 Standard_Real t = nbessai*unsurnbessaimax;
824 Standard_Real w = wf * (1. -t) + wl * t;
825 Standard_Integer ie = Spine->Index(w);
828 cured = Spine->Edges(iedge);
829 TolE = BRep_Tool::Tolerance(cured);
830 ConexFaces(Spine,iedge,HS1,HS2);
833 Or1 = f1.Orientation();
834 Or2 = f2.Orientation();
835 Choix = ChFi3d::NextSide(Or1,Or2,
836 Stripe->OrientationOnFace1(),
837 Stripe->OrientationOnFace2(),
841 Standard_Real woned,Uf,Ul, ResU, ResV;
842 Spine->Parameter(iedge,w,woned,Standard_True);
843 cured.Orientation(TopAbs_FORWARD);
844 TopoDS_Face f1forward = f1, f2forward = f2;
845 f1forward.Orientation(TopAbs_FORWARD);
846 f2forward.Orientation(TopAbs_FORWARD);
847 PC = BRep_Tool::CurveOnSurface(cured,f1forward,Uf,Ul);
848 I1->Initialize((const Handle(Adaptor3d_Surface)&)HS1);
849 PC->D1(woned, P1, derive);
850 // There are points on the border, and internal points are found
851 if (derive.Magnitude() > Precision::PConfusion()) {
853 derive.Rotate(M_PI/2);
855 ResU = AS.UResolution(TolE);
856 ResV = AS.VResolution(TolE);
857 derive *= 2*(Abs(derive.X())*ResU + Abs(derive.Y())*ResV);
858 P2d = P1.Translated(derive);
859 if (I1->Classify(P2d, Min(ResU, ResV), 0)== TopAbs_IN) {
863 P2d = P1.Translated(-derive);
864 if (I1->Classify(P2d, Min(ResU, ResV), 0)== TopAbs_IN) {
869 if(f1.IsSame(f2)) cured.Orientation(TopAbs_REVERSED);
870 PC = BRep_Tool::CurveOnSurface(cured,f2forward,Uf,Ul);
871 P2 = PC->Value(woned);
872 const Handle(Adaptor3d_Surface)& HSon2 = HS2; // to avoid ambiguity
873 I2->Initialize(HSon2);
875 SolDep(1) = P1.X(); SolDep(2) = P1.Y();
876 SolDep(3) = P2.X(); SolDep(4) = P2.Y();
877 const BRepAdaptor_Curve& Ced = Spine->CurrentElementarySpine(iedge);
878 gp_Pnt pnt = Ced.Value(woned);
880 if (Projection(PExt, pnt, els, w, tolesp) &&
881 PerformFirstSection(Spine,HGuide,Choix,HS1,HS2,
882 I1,I2,w,SolDep,Pos1,Pos2)) {
883 P1.SetCoord(SolDep(1),SolDep(2));
884 P2.SetCoord(SolDep(3),SolDep(4));
889 // No solution was found for the faces adjacent to the trajectory.
890 // Now one tries the neighbor faces.
892 for(nbessai = 0; nbessai <= nbessaimax; nbessai++){
893 Standard_Real t = nbessai*unsurnbessaimax;
894 Standard_Real w = wf * (1. -t) + wl * t;
895 iedge = Spine->Index(w);
896 cured = Spine->Edges(iedge);
897 ConexFaces(Spine,iedge,HS1,HS2);
900 Or1 = f1.Orientation();
901 Or2 = f2.Orientation();
902 Choix = ChFi3d::NextSide(Or1,Or2,
903 Stripe->OrientationOnFace1(),
904 Stripe->OrientationOnFace2(),
906 Standard_Real woned,Uf,Ul;
907 Spine->Parameter(iedge,w,woned,Standard_True);
908 TopoDS_Face f1forward = f1, f2forward = f2;
909 f1forward.Orientation(TopAbs_FORWARD);
910 f2forward.Orientation(TopAbs_FORWARD);
911 PC = BRep_Tool::CurveOnSurface(cured,f1forward,Uf,Ul);
912 P1 = PC->Value(woned);
913 PC = BRep_Tool::CurveOnSurface(cured,f2forward,Uf,Ul);
914 P2 = PC->Value(woned);
915 const Handle(Adaptor3d_Surface)& HSon1 = HS1; // to avoid ambiguity
916 const Handle(Adaptor3d_Surface)& HSon2 = HS2; // to avoid ambiguity
917 I1->Initialize(HSon1);
918 I2->Initialize(HSon2);
919 SolDep(1) = P1.X(); SolDep(2) = P1.Y();
920 SolDep(3) = P2.X(); SolDep(4) = P2.Y();
921 const BRepAdaptor_Curve& Ced = Spine->CurrentElementarySpine(iedge);
922 gp_Pnt pnt = Ced.Value(woned);
923 // Extrema_LocateExtPC ext(pnt,els,w,1.e-8);
925 // w = ext.Point().Parameter();
926 if (Projection(PExt, pnt, els, w, tolesp)) {
927 PerformFirstSection(Spine,HGuide,Choix,HS1,HS2,
928 I1,I2,w,SolDep,Pos1,Pos2);
932 Handle(Geom_Plane) pl = new Geom_Plane(P,V);
933 Handle(GeomAdaptor_Surface) plane = new GeomAdaptor_Surface(pl);
935 Standard_Boolean bonvoisin = 1, found = 0;
936 Standard_Integer NbChangement;
937 for (NbChangement = 1; bonvoisin && (!found) && (NbChangement < 5);
939 if(Pos1 != TopAbs_IN){
940 bonvoisin = BonVoisin(P, HS1, f1, plane, cured,
941 SolDep(1),SolDep(2), myEFMap, tolesp);
943 if(Pos2 != TopAbs_IN && bonvoisin){
944 bonvoisin = BonVoisin(P, HS2, f2, plane, cured,
945 SolDep(3),SolDep(4), myEFMap, tolesp);
950 Or1 = f1.Orientation();
951 Or2 = f2.Orientation();
952 Choix = ChFi3d::NextSide(Or1,Or2,
953 Stripe->OrientationOnFace1(),
954 Stripe->OrientationOnFace2(),
956 const Handle(Adaptor3d_Surface)& HSon1new = HS1; // to avoid ambiguity
957 const Handle(Adaptor3d_Surface)& HSon2new = HS2; // to avoid ambiguity
958 I1->Initialize(HSon1new);
959 I2->Initialize(HSon2new);
960 if(PerformFirstSection(Spine,HGuide,Choix,HS1,HS2,
961 I1,I2,w,SolDep,Pos1,Pos2)){
962 P1.SetCoord(SolDep(1),SolDep(2));
963 P2.SetCoord(SolDep(3),SolDep(4));
965 found = Standard_True;
972 Spine->SetErrorStatus(ChFiDS_StartsolFailure);
973 throw Standard_Failure("StartSol echec");
976 //=======================================================================
977 //function : ChFi3d_BuildPlane
979 //=======================================================================
981 static void ChFi3d_BuildPlane (TopOpeBRepDS_DataStructure& DStr,
982 Handle(BRepAdaptor_Surface)& HS,
984 const Handle(ChFiDS_SurfData)& SD,
985 const Standard_Boolean isfirst,
986 const Standard_Integer ons)
988 Handle(Geom2d_Curve) Hc;
989 TopoDS_Face F = TopoDS::Face(DStr.Shape(SD->Index(ons)));
994 if (SD->Vertex(isfirst,ons).IsOnArc()){
995 Hc = BRep_Tool::CurveOnSurface
996 (SD->Vertex(isfirst,ons).Arc(),F,u,v);
997 Hc->Value(SD->Vertex(isfirst,ons).ParameterOnArc()).Coord(u,v);
998 BRepLProp_SLProps theProp (*HS, u, v, 1, 1.e-12);
999 if (theProp.IsNormalDefined()) {
1000 P = theProp.Value();
1001 Handle(Geom_Plane) Pln = new Geom_Plane(P, theProp.Normal());
1002 TopoDS_Face NewF = BRepLib_MakeFace(Pln, Precision::Confusion());
1003 NewF.Orientation(F.Orientation());
1004 pons.SetCoord(0.,0.);
1005 HS->Initialize(NewF);
1006 return; // everything is good !
1009 throw Standard_Failure("ChFi3d_BuildPlane : echec .");
1012 //=======================================================================
1013 //function : StartSol
1014 //purpose : If the commonpoint is not OnArc the input face
1015 // is returned and 2D point is updated,
1017 // if it is detached the input face
1018 // is returned and 2D point is updated,
1020 // either there is a neighbor tangent face and it is returned
1021 // with recalculated 2D point
1022 // or if there is no face
1023 // if the reference arc is Vref (extremity of the spine)
1024 // this is the end and the input face is returned
1025 // otherwise this is an obstacle and HC is updated.
1026 //=======================================================================
1029 ChFi3d_Builder::StartSol(const Handle(ChFiDS_Spine)& Spine,
1030 Handle(BRepAdaptor_Surface)& HS, // New face
1031 gp_Pnt2d& pons,// " Localization
1032 Handle(BRepAdaptor_Curve2d)& HC, // Representation of the obstacle
1034 const Handle(ChFiDS_SurfData)& SD,
1035 const Standard_Boolean isfirst,
1036 const Standard_Integer ons,
1037 Handle(BRepAdaptor_Surface)& HSref, // The other representation
1038 Handle(BRepAdaptor_Curve2d)& HCref, // of the obstacle
1039 Standard_Boolean& RecP,
1040 Standard_Boolean& RecS,
1041 Standard_Boolean& RecRst,
1042 Standard_Boolean& c1obstacle,
1043 Handle(BRepAdaptor_Surface)& HSBis, // Face of support
1044 gp_Pnt2d& PBis, // and its point
1045 const Standard_Boolean decroch,
1046 const TopoDS_Vertex& Vref) const
1048 RecRst = RecS = RecP = c1obstacle = 0;
1049 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
1050 TopoDS_Face Fv,Fref;
1052 Handle(Geom2d_Curve) pc;
1053 Standard_Real Uf,Ul;
1055 TopoDS_Face F = TopoDS::Face(DStr.Shape(SD->Index(ons)));
1056 if(!HSref.IsNull()) Fref = HSref->Face();
1057 const ChFiDS_CommonPoint& CP = SD->Vertex(isfirst,ons);
1061 Standard_Integer notons;
1062 if (ons == 1) notons = 2;
1064 const ChFiDS_CommonPoint& CPbis = SD->Vertex(isfirst,notons);
1065 if (CPbis.IsOnArc()) { // It is checked if it is not the extension zone
1066 // In case CP is not at the end of surfdata and it is not necessary to take it into account
1067 // except for separate cases (ie pointus) ...
1068 //ts and tns were earlier CP.Parameter() and CPbis.Parameter, but sometimes they had no values.
1069 Standard_Real ts=SD->Interference(ons).Parameter(isfirst), tns=SD->Interference(notons).Parameter(isfirst);
1070 Standard_Boolean isExtend;
1071 // Arbitrary test (to precise)
1072 if (isfirst) isExtend = (ts-tns > 100*tolesp);
1073 else isExtend = (tns-ts > 100*tolesp);
1074 if (isExtend && !CP.Point().IsEqual(CPbis.Point(), 0) ) {
1075 // the state is preserved and False is returned (extension by the expected plane).
1077 pc = SD->Interference(ons).PCurveOnFace();
1078 // The 2nd point is given by its trace on the support surface
1079 RecS = Standard_False;
1080 pons = pc->Value(tns);
1081 return Standard_False;
1086 if (CP.IsVertex() && !HC.IsNull() && !decroch){
1087 //The edge is changed, the parameter is updated and
1088 //eventually the support face and(or) the reference face.
1089 TopoDS_Vertex VCP = CP.Vertex();
1090 TopoDS_Edge EHC = HC->Edge();
1091 //One starts by searching in Fref another edge referencing VCP.
1092 TopExp_Explorer ex1,ex2;
1093 TopoDS_Edge newedge, edgereg;
1094 TopoDS_Face bidface = Fref, facereg;
1095 bidface.Orientation(TopAbs_FORWARD);
1096 for(ex1.Init(bidface,TopAbs_EDGE); ex1.More(); ex1.Next()){
1097 const TopoDS_Edge& cured = TopoDS::Edge(ex1.Current());
1098 Standard_Boolean found = 0;
1099 if(!cured.IsSame(EHC)){
1100 for(ex2.Init(cured,TopAbs_VERTEX); ex2.More() && !found; ex2.Next()){
1101 if(ex2.Current().IsSame(VCP)){
1102 if(IsG1(myEFMap,cured,Fref,Fv)){
1115 if(newedge.IsNull()){
1116 //It is checked if EHC is not a closed edge.
1117 TopoDS_Vertex V1,V2;
1118 TopExp::Vertices(EHC,V1,V2);
1121 Standard_Real w1 = BRep_Tool::Parameter(V1,EHC);
1122 Standard_Real w2 = BRep_Tool::Parameter(V2,EHC);
1123 const ChFiDS_FaceInterference& fi = SD->Interference(ons);
1124 const Handle(Geom2d_Curve)& pcf = fi.PCurveOnFace();
1125 Standard_Real ww = fi.Parameter(isfirst);
1128 if(!pcf.IsNull()) pww = pcf->Value(ww);
1129 else pww = SD->Get2dPoints(isfirst,ons);
1130 gp_Pnt2d p1 = HC->Value(w1);
1131 gp_Pnt2d p2 = HC->Value(w2);
1133 if(p1.Distance(pww) > p2.Distance(pww)){
1141 RecP = c1obstacle = 1;
1144 else if(!edgereg.IsNull()){
1145 // the reference edge and face are changed.
1147 HSref->Initialize(Fref);
1148 for(ex1.Init(facereg,TopAbs_EDGE); ex1.More() && newedge.IsNull(); ex1.Next()){
1149 const TopoDS_Edge& cured = TopoDS::Edge(ex1.Current());
1150 if(!cured.IsSame(edgereg)){
1151 for(ex2.Init(cured,TopAbs_VERTEX); ex2.More(); ex2.Next()){
1152 if(ex2.Current().IsSame(VCP)){
1153 if(!IsG1(myEFMap,cured,Fref,Fv)){
1162 // it is necessary to find the new support face of the fillet :
1163 // connected to FRef along the newedge.
1164 if(newedge.IsNull()) {
1165 throw Standard_Failure("StartSol : chain is not possible, new obstacle not found");
1167 if(IsG1(myEFMap,newedge,Fref,Fv)){
1168 throw Standard_Failure("StartSol : chain is not possible, config non processed");
1170 else if(Fv.IsNull()){
1171 throw Standard_Failure("StartSol : chain is not possible, new obstacle not found");
1175 W = BRep_Tool::Parameter(VCP,newedge);
1176 HCref->Initialize(newedge,Fref);
1177 TopoDS_Face newface = Fv;
1178 newface.Orientation(TopAbs_FORWARD);
1180 for(ex.Init(newface,TopAbs_EDGE); ex.More(); ex.Next()){
1181 if(ex.Current().IsSame(newedge)){
1182 newedge = TopoDS::Edge(ex.Current());
1186 HC->Initialize(newedge,Fv);
1187 pons = HC->Value(W);
1189 RecP = c1obstacle = 1;
1191 } // End of Case Vertex && Obstacle
1193 else if (CP.IsOnArc() && !HC.IsNull() && !decroch){
1194 //Nothing is changed, the parameter is only updated.
1195 W = CP.ParameterOnArc();
1203 const TopoDS_Edge& E = CP.Arc();
1205 HS->Initialize(Fref);
1206 W = CP.ParameterOnArc();
1207 pc = BRep_Tool::CurveOnSurface(E,Fref,Uf,Ul);
1208 pons = pc->Value(W);
1212 if (SearchFace(Spine,CP,F,Fv)){
1215 if (CP.IsVertex()) {
1216 // One goes directly by the Vertex
1217 Standard_Integer Nb;
1219 // And it is checked that there are no other candidates
1220 Nb = SearchFaceOnV(CP, F, myVEMap, myEFMap, Fv, aux);
1222 pons = BRep_Tool::Parameters(CP.Vertex(), Fv);
1225 HSBis = new (BRepAdaptor_Surface)(aux);
1226 PBis = BRep_Tool::Parameters(CP.Vertex(), aux);
1230 // otherwise one passes by the arc...
1232 Fv.Orientation(TopAbs_FORWARD);
1233 TopoDS_Edge newedge;
1235 for(ex.Init(Fv,TopAbs_EDGE); ex.More(); ex.Next()){
1236 if(ex.Current().IsSame(E)){
1237 newedge = TopoDS::Edge(ex.Current());
1241 //gp_Vec Varc, VSurf;
1242 // In cas of Tangent output, the current face becomes the support face
1243 if (SortieTangente(CP, F, SD, ons, 0.1)) {
1244 pc = BRep_Tool::CurveOnSurface(CP.Arc(),F,Uf,Ul);
1245 HSBis = new (BRepAdaptor_Surface)(F);
1246 PBis = pc->Value(CP.ParameterOnArc());
1250 pc = BRep_Tool::CurveOnSurface(newedge,Fv,Uf,Ul);
1253 TopoDS_Edge newedge = E;
1255 Fv.Orientation(TopAbs_FORWARD);
1256 pc = BRep_Tool::CurveOnSurface(newedge,Fv,Uf,Ul);
1258 pons = pc->Value(CP.ParameterOnArc());
1261 else if(!Fv.IsNull()){
1265 for(ex.Init(E,TopAbs_VERTEX); ex.More(); ex.Next()){
1266 if(ex.Current().IsSame(Vref)){
1274 HSref->Initialize(F);
1275 W = CP.ParameterOnArc();
1276 HC = new BRepAdaptor_Curve2d();
1277 TopoDS_Edge newedge;
1278 TopoDS_Face newface = Fv;
1279 newface.Orientation(TopAbs_FORWARD);
1281 for(ex.Init(newface,TopAbs_EDGE); ex.More(); ex.Next()){
1282 if(ex.Current().IsSame(E)){
1283 newedge = TopoDS::Edge(ex.Current());
1287 HC->Initialize(newedge,Fv);
1288 pons = HC->Value(W);
1289 HCref->Initialize(E,F);
1290 if(CP.IsVertex()) RecP = 1;
1296 W = CP.ParameterOnArc();
1297 pc = BRep_Tool::CurveOnSurface(E,F,Uf,Ul);
1298 pons = pc->Value(W);
1299 return Standard_False;
1302 else{ // there is no neighbor face, the state is preserved and False is returned.
1304 W = CP.ParameterOnArc();
1305 pc = BRep_Tool::CurveOnSurface(E,F,Uf,Ul);
1306 pons = pc->Value(W);
1307 return Standard_False;
1312 const ChFiDS_FaceInterference& FI = SD->Interference(ons);
1313 if(FI.PCurveOnFace().IsNull()) pons = SD->Get2dPoints(isfirst,ons);
1314 else pons = FI.PCurveOnFace()->Value(FI.Parameter(isfirst));
1316 return Standard_True;
1319 //=======================================================================
1320 //function : SearchFace
1322 //=======================================================================
1324 Standard_Boolean ChFi3d_Builder::SearchFace
1325 (const Handle(ChFiDS_Spine)& Spine,
1326 const ChFiDS_CommonPoint& Pc,
1327 const TopoDS_Face& FRef,
1328 TopoDS_Face& FVoi) const
1330 Standard_Boolean Trouve = Standard_False;
1331 if (! Pc.IsOnArc()) return Standard_False;
1335 // attention it is necessary to analyze all faces that turn around of the vertex
1337 std::cout<<"Commonpoint on vertex, the process hangs up"<<std::endl;
1339 if (Pc.HasVector()) { //General processing
1341 Standard_Integer nb_faces;
1342 nb_faces = SearchFaceOnV(Pc, FRef, myVEMap, myEFMap, FVoi, Fbis);
1343 return ( nb_faces > 0);
1345 else { // Processing using the spine
1346 Standard_Boolean FindFace=Standard_False;
1349 Spine->D1(Pc.Parameter(), Point, VecSpine);
1351 // It is checked if one leaves from the current face.
1352 FindFace = IsInput(VecSpine, Pc.Vertex(), FRef);
1355 FindFace = IsInput(VecSpine, Pc.Vertex(), FRef);
1357 // If one does not leave, it is ended
1360 return Standard_True;
1363 // Otherwise one finds the next among shared Faces
1364 // by a common edge G1
1365 TopTools_ListIteratorOfListOfShape ItE, ItF;
1366 for(ItE.Initialize(myVEMap(Pc.Vertex()));
1367 ItE.More() && (!FindFace); ItE.Next()) {
1368 E = TopoDS::Edge(ItE.Value());
1369 Trouve=Standard_False;
1370 for(ItF.Initialize(myEFMap(E));//, Trouve=Standard_False; 15.11.99 SVV
1371 ItF.More()&&(!Trouve); ItF.Next()) {
1372 if (TopoDS::Face(ItF.Value()).IsSame(FRef)) {
1373 Trouve = Standard_True;
1376 if (Trouve) FindFace = IsG1(myEFMap, E, FRef, FVoi);
1378 FindFace = Standard_False;
1379 if (Spine.IsNull()) {
1380 //La Spine peut etre nulle (ThreeCorner)
1382 std::cout << "FindFace sur vertex avec spine nulle! QUEZAKO ?" << std::endl;
1384 return Standard_False;
1387 // It is checked if the selected face actually possesses edges of the spine
1388 // containing the vertex on its front
1389 // This processing should go only if the Vertex belongs to the spine
1390 // This is a single case, for other vertexes it is required to do other things
1391 Trouve=Standard_False;
1392 for (Standard_Integer IE=1;//, Trouve=Standard_False; 15.11.99 SVV
1393 (IE<=Spine->NbEdges()) && (!Trouve); IE++) {
1394 E = Spine->Edges(IE);
1395 if ( (TopExp::FirstVertex(E).IsSame(Pc.Vertex()))
1396 ||(TopExp::LastVertex(E) .IsSame(Pc.Vertex())) ) {
1397 for(ItF.Initialize(myEFMap(E)), Trouve=Standard_False;
1398 ItF.More()&&(!Trouve); ItF.Next()) {
1399 if (TopoDS::Face(ItF.Value()).IsSame(FVoi)) {
1400 Trouve = Standard_True;
1411 return IsG1(myEFMap, Pc.Arc(), FRef, FVoi);
1413 return Standard_False;
1417 //=======================================================================
1418 //function : ChFi3d_SingularExtremity
1419 //purpose : load the vertex in the DS and calculate the pcurve
1420 // for an extremity in case of singular freeboundary
1421 // or periodic and singular at the cut.
1422 //=======================================================================
1423 static void ChFi3d_SingularExtremity( Handle(ChFiDS_Stripe)& stripe,
1424 TopOpeBRepDS_DataStructure& DStr,
1425 const TopoDS_Vertex& Vtx,
1426 const Standard_Real tol3d,
1427 const Standard_Real tol2d)
1429 Handle(ChFiDS_SurfData) Fd;
1430 Standard_Real tolreached;
1431 Standard_Real Pardeb, Parfin;
1432 gp_Pnt2d VOnS1, VOnS2;
1433 Handle(Geom_Curve) C3d;
1434 Handle(Geom2d_Curve) PCurv;
1435 TopOpeBRepDS_Curve Crv;
1436 // SurfData and its CommonPoints,
1437 Standard_Integer Ivtx, Icurv;
1438 Standard_Boolean isfirst;
1440 if (stripe->Spine()->IsPeriodic()) {
1441 isfirst = Standard_True;
1442 Fd = stripe->SetOfSurfData()->Sequence().First();
1445 Standard_Integer sens;
1446 Standard_Integer num = ChFi3d_IndexOfSurfData(Vtx,stripe,sens);
1447 Fd = stripe->SetOfSurfData()->Sequence().Value(num);
1448 isfirst = (sens == 1);
1451 const ChFiDS_CommonPoint& CV1 = Fd->Vertex(isfirst,1);
1452 const ChFiDS_CommonPoint& CV2 = Fd->Vertex(isfirst,2);
1453 // Is it always degenerated ?
1454 if ( CV1.Point().IsEqual( CV2.Point(), 0) ) {
1455 Ivtx = ChFi3d_IndexPointInDS(CV1, DStr);
1457 VOnS1 = Fd->InterferenceOnS1().PCurveOnSurf()->
1458 Value(Fd->InterferenceOnS1().FirstParameter());
1459 VOnS2 = Fd->InterferenceOnS2().PCurveOnSurf()->
1460 Value(Fd->InterferenceOnS2().FirstParameter());
1463 VOnS1 = Fd->InterferenceOnS1().PCurveOnSurf()->
1464 Value(Fd->InterferenceOnS1().LastParameter());
1465 VOnS2 = Fd->InterferenceOnS2().PCurveOnSurf()->
1466 Value(Fd->InterferenceOnS2().LastParameter());
1469 ChFi3d_ComputeArete(CV1, VOnS1,
1471 DStr.Surface(Fd->Surf()).Surface(),
1473 Pardeb,Parfin, tol3d, tol2d, tolreached,0);
1474 Crv = TopOpeBRepDS_Curve(C3d,tolreached);
1475 Icurv = DStr.AddCurve(Crv);
1477 stripe->SetCurve(Icurv, isfirst);
1478 stripe->SetParameters(isfirst, Pardeb,Parfin);
1479 stripe->ChangePCurve(isfirst) = PCurv;
1480 stripe->SetIndexPoint(Ivtx, isfirst, 1);
1481 stripe->SetIndexPoint(Ivtx, isfirst, 2);
1483 if (stripe->Spine()->IsPeriodic()) {
1484 // periodic case : The operation is renewed
1485 // the curve 3d is not shared.
1486 // 2 degenerated edges coinciding in 3d
1487 isfirst = Standard_False;
1488 Fd = stripe->SetOfSurfData()->Sequence().Last();
1489 VOnS1 = Fd->InterferenceOnS1().PCurveOnSurf()->
1490 Value(Fd->InterferenceOnS1().LastParameter());
1491 VOnS2 = Fd->InterferenceOnS2().PCurveOnSurf()->
1492 Value(Fd->InterferenceOnS2().LastParameter());
1494 ChFi3d_ComputeArete(CV1, VOnS1,
1496 DStr.Surface(Fd->Surf()).Surface(),
1498 Pardeb,Parfin, tol3d, tol2d, tolreached,0);
1499 Crv = TopOpeBRepDS_Curve(C3d,tolreached);
1500 Icurv = DStr.AddCurve(Crv);
1502 stripe->SetCurve(Icurv, isfirst);
1503 stripe->SetParameters(isfirst, Pardeb,Parfin);
1504 stripe->ChangePCurve(isfirst) = PCurv;
1505 stripe->SetIndexPoint(Ivtx, isfirst, 1);
1506 stripe->SetIndexPoint(Ivtx, isfirst, 2);
1511 //=======================================================================
1512 //function : ChFi3d_MakeExtremities
1513 //purpose : calculate Curves3d and pcurves of extremities in
1514 // periodic and freeboundary cases.
1515 //=======================================================================
1516 static Standard_Boolean IsFree(const TopoDS_Shape& E,
1517 const ChFiDS_Map& EFMap)
1519 if(!EFMap.Contains(E)) return 0;
1520 TopTools_ListIteratorOfListOfShape It;
1522 for(It.Initialize(EFMap(E)); It.More(); It.Next()){
1523 if(Fref.IsNull()) Fref = It.Value();
1524 else if(!Fref.IsSame(It.Value())) return 0;
1529 static void ChFi3d_MakeExtremities(Handle(ChFiDS_Stripe)& Stripe,
1530 TopOpeBRepDS_DataStructure& DStr,
1531 const ChFiDS_Map& EFMap,
1532 const Standard_Real tol3d,
1533 const Standard_Real tol2d)
1535 Handle(ChFiDS_Spine)& sp = Stripe->ChangeSpine();
1536 Standard_Real Pardeb,Parfin;
1537 Handle(Geom_Curve) C3d;
1538 Standard_Real tolreached;
1539 if(sp->IsPeriodic()){
1541 const Handle(ChFiDS_SurfData)&
1542 SDF = Stripe->SetOfSurfData()->Sequence().First();
1543 const ChFiDS_CommonPoint& CV1 = SDF->VertexFirstOnS1();
1544 const ChFiDS_CommonPoint& CV2 = SDF->VertexFirstOnS2();
1545 if ( !CV1.Point().IsEqual(CV2.Point(), 0) ) {
1546 ChFi3d_ComputeArete(CV1,
1547 SDF->InterferenceOnS1().PCurveOnSurf()->
1548 Value(SDF->InterferenceOnS1().FirstParameter()),
1550 SDF->InterferenceOnS2().PCurveOnSurf()->
1551 Value(SDF->InterferenceOnS2().FirstParameter()),
1552 DStr.Surface(SDF->Surf()).Surface(),C3d,
1553 Stripe->ChangeFirstPCurve(),Pardeb,Parfin,
1554 tol3d,tol2d,tolreached,0);
1555 TopOpeBRepDS_Curve Crv(C3d,tolreached);
1556 Stripe->ChangeFirstCurve(DStr.AddCurve(Crv));
1557 Stripe->ChangeFirstParameters(Pardeb,Parfin);
1558 Stripe->ChangeIndexFirstPointOnS1
1559 (ChFi3d_IndexPointInDS(SDF->VertexFirstOnS1(),DStr));
1560 Stripe->ChangeIndexFirstPointOnS2
1561 (ChFi3d_IndexPointInDS(SDF->VertexFirstOnS2(),DStr));
1562 Standard_Integer ICurv = Stripe->FirstCurve();
1563 Stripe->ChangeLastParameters(Pardeb,Parfin);
1564 Stripe->ChangeLastCurve(ICurv);
1565 Stripe->ChangeIndexLastPointOnS1(Stripe->IndexFirstPointOnS1());
1566 Stripe->ChangeIndexLastPointOnS2(Stripe->IndexFirstPointOnS2());
1568 const Handle(ChFiDS_SurfData)&
1569 SDL = Stripe->SetOfSurfData()->Sequence().Last();
1572 ChFi3d_ComputePCurv(C3d,
1573 SDL->InterferenceOnS1().PCurveOnSurf()->
1574 Value(SDL->InterferenceOnS1().LastParameter()),
1575 SDL->InterferenceOnS2().PCurveOnSurf()->
1576 Value(SDL->InterferenceOnS2().LastParameter()),
1577 Stripe->ChangeLastPCurve(),
1578 DStr.Surface(SDL->Surf()).Surface(),
1579 Pardeb,Parfin,tol3d,tolreached);
1580 Standard_Real oldtol = DStr.ChangeCurve(ICurv).Tolerance();
1581 DStr.ChangeCurve(ICurv).Tolerance(Max(oldtol,tolreached));
1583 ChFi3d_EnlargeBox(CV1.Arc(),EFMap(CV1.Arc()),CV1.ParameterOnArc(),b1);
1587 ChFi3d_EnlargeBox(CV2.Arc(),EFMap(CV2.Arc()),CV2.ParameterOnArc(),b2);
1589 ChFi3d_EnlargeBox(DStr,Stripe,SDF,b1,b2,1);
1590 ChFi3d_EnlargeBox(DStr,Stripe,SDL,b1,b2,0);
1591 if (!CV1.IsVertex())
1592 ChFi3d_SetPointTolerance(DStr,b1,Stripe->IndexFirstPointOnS1());
1593 if (!CV2.IsVertex())
1594 ChFi3d_SetPointTolerance(DStr,b2,Stripe->IndexFirstPointOnS2());
1597 // Case of the single extremity
1598 if (CV1.IsVertex()) {
1599 ChFi3d_SingularExtremity(Stripe, DStr, CV1.Vertex(), tol3d, tol2d);
1602 else { std::cout << "MakeExtremities : Singularity out of Vertex !!" << std::endl; }
1608 const Handle(ChFiDS_SurfData)&
1609 SDdeb = Stripe->SetOfSurfData()->Sequence().First();
1611 const ChFiDS_CommonPoint& cpdeb1 = SDdeb->VertexFirstOnS1();
1612 const ChFiDS_CommonPoint& cpdeb2 = SDdeb->VertexFirstOnS2();
1613 Standard_Boolean freedeb = sp->FirstStatus() == ChFiDS_FreeBoundary;
1614 if(!freedeb && cpdeb1.IsOnArc() && cpdeb2.IsOnArc()){
1615 freedeb = (IsFree(cpdeb1.Arc(),EFMap) && IsFree(cpdeb2.Arc(),EFMap));
1618 sp->SetFirstStatus(ChFiDS_FreeBoundary);
1620 if ( !cpdeb1.Point().IsEqual(cpdeb2.Point(), 0) ) {
1621 Standard_Boolean plane;
1623 UV1=SDdeb->InterferenceOnS1().PCurveOnSurf()->
1624 Value(SDdeb->InterferenceOnS1().FirstParameter());
1625 UV2=SDdeb->InterferenceOnS2().PCurveOnSurf()->
1626 Value(SDdeb->InterferenceOnS2().FirstParameter());
1627 // The intersection of the fillet by a plane is attempted
1629 Handle(GeomAdaptor_Surface) HConge=ChFi3d_BoundSurf(DStr,SDdeb,1,2);
1630 ChFi3d_CoupeParPlan(cpdeb1,cpdeb2,HConge,UV1,UV2,
1631 tol3d,tol2d,C3d,Stripe->ChangeFirstPCurve(),tolreached,
1632 Pardeb,Parfin,plane);
1634 ChFi3d_ComputeArete(cpdeb1,
1635 SDdeb->InterferenceOnS1().PCurveOnSurf()->
1636 Value(SDdeb->InterferenceOnS1().FirstParameter()),
1638 SDdeb->InterferenceOnS2().PCurveOnSurf()->
1639 Value(SDdeb->InterferenceOnS2().FirstParameter()),
1640 DStr.Surface(SDdeb->Surf()).Surface(),C3d,
1641 Stripe->ChangeFirstPCurve(),Pardeb,Parfin,
1642 tol3d,tol2d,tolreached,0);
1643 TopOpeBRepDS_Curve Crv(C3d,tolreached);
1644 Stripe->ChangeFirstCurve(DStr.AddCurve(Crv));
1645 Stripe->ChangeFirstParameters(Pardeb,Parfin);
1646 Stripe->ChangeIndexFirstPointOnS1
1647 (ChFi3d_IndexPointInDS(SDdeb->VertexFirstOnS1(),DStr));
1648 Stripe->ChangeIndexFirstPointOnS2
1649 (ChFi3d_IndexPointInDS(SDdeb->VertexFirstOnS2(),DStr));
1650 if(cpdeb1.IsOnArc()){
1651 ChFi3d_EnlargeBox(cpdeb1.Arc(),EFMap(cpdeb1.Arc()),cpdeb1.ParameterOnArc(),b1);
1653 if(cpdeb2.IsOnArc()){
1654 ChFi3d_EnlargeBox(cpdeb2.Arc(),EFMap(cpdeb2.Arc()),cpdeb2.ParameterOnArc(),b2);
1656 ChFi3d_EnlargeBox(DStr,Stripe,SDdeb,b1,b2,1);
1657 if (!cpdeb1.IsVertex())
1658 ChFi3d_SetPointTolerance(DStr,b1,Stripe->IndexFirstPointOnS1());
1659 if (!cpdeb2.IsVertex())
1660 ChFi3d_SetPointTolerance(DStr,b2,Stripe->IndexFirstPointOnS2());
1662 else { // Case of a singular extremity
1663 if (cpdeb1.IsVertex()) {
1664 ChFi3d_SingularExtremity(Stripe, DStr, cpdeb1.Vertex(), tol3d, tol2d);
1667 else { std::cout << "MakeExtremities : Singularity out of Vertex !!" << std::endl; }
1671 const Handle(ChFiDS_SurfData)&
1672 SDfin = Stripe->SetOfSurfData()->Sequence().Last();
1673 const ChFiDS_CommonPoint& cpfin1 = SDfin->VertexLastOnS1();
1674 const ChFiDS_CommonPoint& cpfin2 = SDfin->VertexLastOnS2();
1675 Standard_Boolean freefin = sp->LastStatus() == ChFiDS_FreeBoundary;
1676 if(!freefin && cpfin1.IsOnArc() && cpfin2.IsOnArc()){
1677 freefin = (IsFree(cpfin1.Arc(),EFMap) && IsFree(cpfin2.Arc(),EFMap));
1680 sp->SetLastStatus(ChFiDS_FreeBoundary);
1682 if ( !cpfin1.Point().IsEqual(cpfin2.Point(), 0) ) {
1683 Standard_Boolean plane;
1685 UV1=SDfin->InterferenceOnS1().PCurveOnSurf()->
1686 Value(SDfin->InterferenceOnS1().LastParameter());
1687 UV2=SDfin->InterferenceOnS2().PCurveOnSurf()->
1688 Value(SDfin->InterferenceOnS2().LastParameter());
1689 // Intersection of the fillet by a plane is attempted
1691 Handle(GeomAdaptor_Surface) HConge=ChFi3d_BoundSurf(DStr,SDfin,1,2);
1692 ChFi3d_CoupeParPlan(cpfin1,cpfin2,HConge,UV1,UV2,
1693 tol3d,tol2d,C3d,Stripe->ChangeLastPCurve(),tolreached,
1694 Pardeb,Parfin,plane);
1696 ChFi3d_ComputeArete(cpfin1,
1697 SDfin->InterferenceOnS1().PCurveOnSurf()->
1698 Value(SDfin->InterferenceOnS1().LastParameter()),
1700 SDfin->InterferenceOnS2().PCurveOnSurf()->
1701 Value(SDfin->InterferenceOnS2().LastParameter()),
1702 DStr.Surface(SDfin->Surf()).Surface(),C3d,
1703 Stripe->ChangeLastPCurve(),Pardeb,Parfin,
1704 tol3d,tol2d,tolreached,0);
1705 TopOpeBRepDS_Curve Crv(C3d,tolreached);
1706 Stripe->ChangeLastCurve(DStr.AddCurve(Crv));
1707 Stripe->ChangeLastParameters(Pardeb,Parfin);
1708 Stripe->ChangeIndexLastPointOnS1
1709 (ChFi3d_IndexPointInDS(SDfin->VertexLastOnS1(),DStr));
1710 Stripe->ChangeIndexLastPointOnS2
1711 (ChFi3d_IndexPointInDS(SDfin->VertexLastOnS2(),DStr));
1712 if(cpfin1.IsOnArc()){
1713 ChFi3d_EnlargeBox(cpfin1.Arc(),EFMap(cpfin1.Arc()),cpfin1.ParameterOnArc(),b1);
1715 if(cpfin2.IsOnArc()){
1716 ChFi3d_EnlargeBox(cpfin2.Arc(),EFMap(cpfin2.Arc()),cpfin2.ParameterOnArc(),b2);
1718 ChFi3d_EnlargeBox(DStr,Stripe,SDfin,b1,b2,0);
1719 if (!cpfin1.IsVertex())
1720 ChFi3d_SetPointTolerance(DStr,b1,Stripe->IndexLastPointOnS1());
1721 if (!cpfin2.IsVertex())
1722 ChFi3d_SetPointTolerance(DStr,b2,Stripe->IndexLastPointOnS2());
1724 else { // Case of the single extremity
1725 if (cpfin1.IsVertex()) {
1726 ChFi3d_SingularExtremity(Stripe, DStr, cpfin1.Vertex(), tol3d, tol2d);
1729 else { std::cout << "MakeExtremities : Singularity out of Vertex !!" << std::endl; }
1735 //=======================================================================
1736 //function : ChFi3d_Purge
1738 //=======================================================================
1740 static void ChFi3d_Purge (Handle(ChFiDS_Stripe)& Stripe,
1741 Handle(ChFiDS_SurfData)& SD,
1742 const ChFiDS_CommonPoint& VRef,
1743 const Standard_Boolean isfirst,
1744 const Standard_Integer ons,
1745 Standard_Integer& intf,
1746 Standard_Integer& intl)
1748 if (isfirst) intf = 1; else intl = 1; // End.
1749 Standard_Integer opp = 3-ons;
1750 if (!SD->Vertex(isfirst,opp).IsOnArc() ||
1751 SD->TwistOnS1() || SD->TwistOnS2() ) {
1753 std::cout<<"ChFi3d_Purge : No output on extension."<<std::endl;
1755 ChFiDS_SequenceOfSurfData& Seq =
1756 Stripe->ChangeSetOfSurfData()->ChangeSequence();
1757 if(isfirst) Seq.Remove(1);
1758 else Seq.Remove(Seq.Length());
1761 if (ons == 1) SD->ChangeIndexOfS1(0);
1762 else SD->ChangeIndexOfS2(0);
1764 SD->ChangeVertex(!isfirst,ons) = VRef;
1765 SD->ChangeVertex(isfirst,ons) = VRef;
1767 ChFiDS_FaceInterference& fi = SD->ChangeInterference(ons);
1768 if(isfirst) fi.SetFirstParameter(fi.LastParameter());
1769 else fi.SetLastParameter(fi.FirstParameter());
1773 //=======================================================================
1774 //function : InsertAfter
1775 //purpose : insert Item after ref in Seq. If ref is null, the item is
1776 // inserted at the beginning.
1777 //=======================================================================
1779 static void InsertAfter (Handle(ChFiDS_Stripe)& Stripe,
1780 Handle(ChFiDS_SurfData)& Ref,
1781 Handle(ChFiDS_SurfData)& Item)
1784 throw Standard_Failure("InsertAfter : twice the same surfdata.");
1786 ChFiDS_SequenceOfSurfData& Seq =
1787 Stripe->ChangeSetOfSurfData()->ChangeSequence();
1789 if (Seq.IsEmpty() || Ref.IsNull()) {
1792 for (Standard_Integer i = 1; i <= Seq.Length(); i++) {
1793 if (Seq.Value(i) == Ref) {
1794 Seq.InsertAfter(i,Item);
1800 //=======================================================================
1801 //function : RemoveSD
1803 //=======================================================================
1805 static void RemoveSD (Handle(ChFiDS_Stripe)& Stripe,
1806 Handle(ChFiDS_SurfData)& Prev,
1807 Handle(ChFiDS_SurfData)& Next)
1809 ChFiDS_SequenceOfSurfData& Seq =
1810 Stripe->ChangeSetOfSurfData()->ChangeSequence();
1811 if(Seq.IsEmpty()) return;
1812 Standard_Integer iprev = 0, inext = 0;
1813 for (Standard_Integer i = 1; i <= Seq.Length(); i++) {
1814 if (Seq.Value(i) == Prev) iprev = i + 1;
1815 if (Seq.Value(i) == Next) { inext = i - 1; break; }
1817 if(Prev.IsNull()) iprev = 1;
1818 if(Next.IsNull()) inext = Seq.Length();
1819 if(iprev <= inext) Seq.Remove(iprev,inext);
1822 //=======================================================================
1823 //function : InsertBefore
1824 //purpose : Insert item before ref in Seq. If ref is null, the item is
1825 // inserted in the queue.
1826 //=======================================================================
1828 static void InsertBefore (Handle(ChFiDS_Stripe)& Stripe,
1829 Handle(ChFiDS_SurfData)& Ref,
1830 Handle(ChFiDS_SurfData)& Item)
1833 throw Standard_Failure("InsertBefore : twice the same surfdata.");
1835 ChFiDS_SequenceOfSurfData& Seq =
1836 Stripe->ChangeSetOfSurfData()->ChangeSequence();
1838 if (Seq.IsEmpty() || Ref.IsNull()) {
1841 for (Standard_Integer i = 1; i <= Seq.Length(); i++) {
1842 if (Seq.Value(i) == Ref) {
1843 Seq.InsertBefore(i,Item);
1850 //=======================================================================
1851 //function : PerformSetOfSurfOnElSpine
1853 //=======================================================================
1855 void ChFi3d_Builder::PerformSetOfSurfOnElSpine
1856 (const Handle(ChFiDS_ElSpine)& HGuide,
1857 Handle(ChFiDS_Stripe)& Stripe,
1858 Handle(BRepTopAdaptor_TopolTool)& It1,
1859 Handle(BRepTopAdaptor_TopolTool)& It2,
1860 const Standard_Boolean Simul)
1863 OSD_Chronometer ch1;
1869 //( HGuide->Curve() ).D1(HGuide->FirstParameter(),ptgui,d1gui);
1871 ChFiDS_ElSpine& Guide = *HGuide;
1873 Handle(ChFiDS_ElSpine) OffsetHGuide;
1874 Handle(ChFiDS_Spine)& Spine = Stripe->ChangeSpine();
1875 if (Spine->Mode() == ChFiDS_ConstThroatWithPenetrationChamfer)
1877 ChFiDS_ListOfHElSpine& ll = Spine->ChangeElSpines();
1878 ChFiDS_ListOfHElSpine& ll_offset = Spine->ChangeOffsetElSpines();
1879 ChFiDS_ListIteratorOfListOfHElSpine ILES(ll), ILES_offset(ll_offset);
1880 for ( ; ILES.More(); ILES.Next(),ILES_offset.Next())
1882 const Handle(ChFiDS_ElSpine)& aHElSpine = ILES.Value();
1883 if (aHElSpine == HGuide)
1884 OffsetHGuide = ILES_offset.Value();
1888 Standard_Real wf = Guide.FirstParameter();
1889 Standard_Real wl = Guide.LastParameter();
1890 Standard_Real locfleche = (wl - wf) * fleche;
1891 Standard_Real wfsav = wf, wlsav = wl;
1892 if (!Guide.IsPeriodic())
1894 //Now the ElSpine is artificially extended to help rsnld.
1895 Standard_Real prab = 0.01;
1896 Guide.FirstParameter(wf-prab*(wl-wf));
1897 Guide.LastParameter (wl+prab*(wl-wf));
1898 if (!OffsetHGuide.IsNull())
1900 OffsetHGuide->FirstParameter(wf-prab*(wl-wf));
1901 OffsetHGuide->LastParameter (wl+prab*(wl-wf));
1904 //Handle(ChFiDS_Spine)& Spine = Stripe->ChangeSpine();
1905 Standard_Integer ii, nbed = Spine->NbEdges();
1906 Standard_Real lastedlastp = Spine->LastParameter(nbed);
1908 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
1910 Handle(ChFiDS_SurfData) ref = Guide.Previous();
1911 Handle(ChFiDS_SurfData) refbis, SD;
1912 Handle(ChFiDS_SurfData) raf = Guide.Next();
1913 RemoveSD(Stripe,ref,raf);
1915 Handle(BRepAdaptor_Surface) HS1 = new BRepAdaptor_Surface();
1916 Handle(BRepAdaptor_Surface) HS2 = new BRepAdaptor_Surface();
1917 Handle(BRepAdaptor_Surface) HS3, HS4;
1918 Handle(BRepAdaptor_Surface) HSref1 = new BRepAdaptor_Surface();
1919 Handle(BRepAdaptor_Surface) HSref2 = new BRepAdaptor_Surface();
1920 Handle(BRepAdaptor_Curve2d) HC1,HC2;
1921 Handle(BRepAdaptor_Curve2d) HCref1 = new BRepAdaptor_Curve2d();
1922 Handle(BRepAdaptor_Curve2d) HCref2 = new BRepAdaptor_Curve2d();
1923 Standard_Boolean decroch1 = Standard_False, decroch2 = Standard_False;
1924 Standard_Boolean RecP1 = Standard_False, RecS1 = Standard_False, RecRst1 = Standard_False, obstacleon1 = Standard_False;
1925 Standard_Boolean RecP2 = Standard_False, RecS2 = Standard_False, RecRst2 = Standard_False, obstacleon2 = Standard_False;
1926 gp_Pnt2d pp1,pp2,pp3,pp4;
1927 Standard_Real w1 = 0.,w2 = 0.;
1928 math_Vector Soldep(1,4);
1929 math_Vector SoldepCS(1,3);
1930 math_Vector SoldepCC(1,2);
1932 // Restore a neighboring KPart.
1933 // If no neighbor calculation start point.
1934 Standard_Boolean forward = Standard_True;
1935 Standard_Boolean Inside = Standard_False;
1936 Standard_Real First = wf;
1937 Standard_Real Last = wl;
1938 Standard_Boolean Ok1 = 1,Ok2 = 1;
1939 // Restore the next KPart if it exists
1941 if(ref.IsNull() && raf.IsNull()){
1942 //sinon solution approchee.
1943 Inside = Standard_True;
1946 ChFi3d_InitChron(ch1);// init perf for StartSol
1949 StartSol(Stripe,HGuide,HS1,HS2,It1,It2,pp1,pp2,First);
1952 ChFi3d_ResultChron(ch1,t_startsol); // result perf for StartSol
1956 if(Guide.IsPeriodic()) {
1957 Last = First - Guide.Period();
1958 Guide.SaveFirstParameter();
1959 Guide.FirstParameter(Last);
1960 Guide.SaveLastParameter();
1961 Guide.LastParameter (First * 1.1);//Extension to help rsnld.
1962 if (!OffsetHGuide.IsNull())
1964 OffsetHGuide->SaveFirstParameter();
1965 OffsetHGuide->FirstParameter(Last);
1966 OffsetHGuide->SaveLastParameter();
1967 OffsetHGuide->LastParameter (First * 1.1);//Extension to help rsnld.
1972 if(!Spine->IsPeriodic() && (wl - lastedlastp > -tolesp)){
1973 Vref = Spine->LastVertex();
1976 if(!Spine->IsPeriodic() && (wf < tolesp)){
1977 Vref = Spine->FirstVertex();
1980 forward = Standard_False;
1981 First = wl; Last = Guide.FirstParameter();
1985 ChFi3d_InitChron(ch1);// init perf for startsol
1989 Ok1 = StartSol(Spine,HS1,pp1,HC1,w1,ref,!forward,1,
1990 HSref1,HCref1,RecP1,RecS1,RecRst1,obstacleon1,
1991 HS3,pp3,decroch1,Vref);
1992 Ok2 = StartSol(Spine,HS2,pp2,HC2,w2,ref,!forward,2,
1993 HSref2,HCref2, RecP2,RecS2,RecRst2,obstacleon2,
1994 HS4,pp4,decroch2,Vref);
1999 ChFi3d_ResultChron(ch1,t_startsol); // result perf for startsol
2003 if(Ok1 == 1 && Ok2 == 1) {
2006 Guide.FirstParameter(wf);
2007 if (!OffsetHGuide.IsNull())
2008 OffsetHGuide->FirstParameter(wf);
2012 Guide.LastParameter(wl);
2013 if (!OffsetHGuide.IsNull())
2014 OffsetHGuide->LastParameter(wl);
2018 Standard_Boolean fini = Standard_False;
2019 Standard_Boolean complete = Inside;
2020 if(!Guide.IsPeriodic()){
2021 Standard_Integer indf = Spine->Index(wf);
2022 Standard_Integer indl = Spine->Index(wl,0);
2023 if(Spine->IsPeriodic() && (indl < indf)) indl += nbed;
2026 // No Max at the touch : 20 points by edge at average without
2027 // counting the extensions.
2029 Standard_Real bidf = wf, bidl = wl;
2030 if(!Spine->IsPeriodic()) {
2032 bidl = Min(wl,Spine->LastParameter(Spine->NbEdges()));
2033 // PMN 20/07/98 : Attention in case if there is only extension
2034 if ((bidl-bidf) < 0.01 * Spine->LastParameter(Spine->NbEdges())) {
2039 Standard_Real MaxStep = (bidl-bidf)*0.05/nbed;
2040 Standard_Real Firstsov = 0.;
2041 Standard_Integer intf = 0, intl = 0;
2043 // are these the ends (no extension on periodic).
2045 if(!Spine->IsPeriodic()){
2046 if(wf < tolesp && (complete == Inside)){
2047 if(Spine->FirstStatus() == ChFiDS_OnSame) intf = 2;
2050 if(Spine->IsTangencyExtremity(Standard_True)){
2052 Guide.FirstParameter(wfsav);
2053 if (!OffsetHGuide.IsNull())
2054 OffsetHGuide->FirstParameter(wfsav);
2056 if(wl - lastedlastp > -tolesp){
2057 if(Spine->LastStatus() == ChFiDS_OnSame) intl = 2;
2060 if(Spine->IsTangencyExtremity(Standard_False)){
2062 Guide.LastParameter(wlsav);
2063 if (!OffsetHGuide.IsNull())
2064 OffsetHGuide->LastParameter(wlsav);
2067 if(intf && !forward) Vref = Spine->FirstVertex();
2068 if(intl && forward) Vref = Spine->LastVertex();
2072 ChFi3d_InitChron(ch1);// init perf for StartSol
2075 Ok1 = StartSol(Spine,HS1,pp1,HC1,w1,ref,!forward,1,
2076 HSref1,HCref1, RecP1,RecS1,RecRst1,obstacleon1,
2077 HS3,pp3,decroch1,Vref);
2078 Ok2 = StartSol(Spine,HS2,pp2,HC2,w2,ref,!forward,2,
2079 HSref2,HCref2, RecP2,RecS2,RecRst2,obstacleon2,
2080 HS4,pp4,decroch2,Vref);
2083 ChFi3d_ResultChron(ch1,t_startsol); // result perf for StartSol
2088 // No more connected faces. Construction of the tangent plane to continue the path
2089 // till the output on the other face.
2090 if ((!Ok1 && HC1.IsNull()) || (!Ok2 && HC2.IsNull())) {
2091 if ((intf && !forward) || (intl && forward)) {
2092 if (!Ok1) ChFi3d_BuildPlane (DStr,HS1,pp1,ref,!forward,1);
2093 if (!Ok2) ChFi3d_BuildPlane (DStr,HS2,pp2,ref,!forward,2);
2095 else if(intl) intl = 5;
2098 Guide.FirstParameter(wf);
2099 if (!OffsetHGuide.IsNull())
2100 OffsetHGuide->FirstParameter(wf);
2104 Guide.LastParameter(wl);
2105 if (!OffsetHGuide.IsNull())
2106 OffsetHGuide->LastParameter(wl);
2109 else throw Standard_Failure("PerformSetOfSurfOnElSpine : Chaining is impossible.");
2112 // Definition of the domain of patch It1, It2
2113 const Handle(Adaptor3d_Surface)& HSon1 = HS1; // to avoid ambiguity
2114 const Handle(Adaptor3d_Surface)& HSon2 = HS2; // to avoid ambiguity
2115 It1->Initialize(HSon1);
2116 It2->Initialize(HSon2);
2118 // Calculate one (several if singularity) SurfaData
2119 SD = new ChFiDS_SurfData();
2120 ChFiDS_SequenceOfSurfData SeqSD;
2123 if(obstacleon1 && obstacleon2){
2124 TopAbs_Orientation Or1 = HSref1->Face().Orientation();
2125 TopAbs_Orientation Or2 = HSref2->Face().Orientation();
2126 Standard_Integer Choix = ChFi3d::NextSide(Or1,Or2,
2127 Stripe->OrientationOnFace1(),
2128 Stripe->OrientationOnFace2(),
2132 // Calculate the criterion of Choice edge / edge
2133 if (Choix%2 == 0) Choix = 4;
2136 SoldepCC(1) = w1; SoldepCC(2) = w2;
2138 SimulSurf(SD,HGuide,Spine,Choix,
2139 HS1,It1,HC1,HSref1,HCref1,decroch1,Or1,
2140 HS2,It2,HC2,HSref2,HCref2,decroch2,Or2,
2141 locfleche,tolesp,First,Last,Inside,Inside,forward,
2142 RecP1,RecRst1,RecP2,RecRst2,SoldepCC);
2146 ChFi3d_InitChron(ch1); // init perf for PerformSurf
2148 PerformSurf(SeqSD,HGuide,Spine,Choix,
2149 HS1,It1,HC1,HSref1,HCref1,decroch1,Or1,
2150 HS2,It2,HC2,HSref2,HCref2,decroch2,Or2,
2151 MaxStep,locfleche,tolesp,First,Last,Inside,Inside,forward,
2152 RecP1,RecRst1,RecP2,RecRst2,SoldepCC);
2154 ChFi3d_ResultChron(ch1,t_performsurf); //result perf for PerformSurf
2157 SD->ChangeIndexOfS1(DStr.AddShape(HS1->Face()));
2158 SD->ChangeIndexOfS2(DStr.AddShape(HS2->Face()));
2160 else if (obstacleon1){
2161 TopAbs_Orientation Or1 = HSref1->Face().Orientation();
2162 TopAbs_Orientation Or2 = HS2->Face().Orientation();
2163 Standard_Integer Choix = ChFi3d::NextSide(Or1,Or2,
2164 Stripe->OrientationOnFace1(),
2165 Stripe->OrientationOnFace2(),
2167 if(Choix%2 == 1) Choix++;
2169 SoldepCS(3) = w1; SoldepCS(1) = pp2.X(); SoldepCS(2) = pp2.Y();
2171 SimulSurf(SD,HGuide,Spine,Choix,HS1,It1,HC1,HSref1,HCref1,decroch1,
2172 HS2,It2,Or2,locfleche,tolesp,First,Last,
2173 Inside,Inside,forward,RecP1,RecS2,RecRst1,SoldepCS);
2177 ChFi3d_InitChron(ch1); // init perf for PerformSurf
2179 PerformSurf(SeqSD,HGuide,Spine,Choix,HS1,It1,HC1,HSref1,HCref1,decroch1,
2180 HS2,It2,Or2,MaxStep,locfleche,tolesp,First,Last,
2181 Inside,Inside,forward,RecP1,RecS2,RecRst1,SoldepCS);
2183 ChFi3d_ResultChron(ch1,t_performsurf);//result perf for PerformSurf
2186 SD->ChangeIndexOfS1(DStr.AddShape(HS1->Face()));
2187 SD->ChangeIndexOfS2(DStr.AddShape(HS2->Face()));
2190 else if (obstacleon2){
2191 TopAbs_Orientation Or1 = HS1->Face().Orientation();
2192 TopAbs_Orientation Or2 = HSref2->Face().Orientation();
2193 Standard_Integer Choix = ChFi3d::NextSide(Or1,Or2,
2194 Stripe->OrientationOnFace1(),
2195 Stripe->OrientationOnFace2(),
2197 SoldepCS(3) = w2; SoldepCS(1) = pp1.X(); SoldepCS(2) = pp1.Y();
2199 SimulSurf(SD,HGuide,Spine,Choix,HS1,It1,Or1,
2200 HS2,It2,HC2,HSref2,HCref2,decroch2,locfleche,tolesp,
2201 First,Last,Inside,Inside,forward,RecP2,RecS1,RecRst2,SoldepCS);
2205 ChFi3d_InitChron(ch1); // init perf for PerformSurf
2207 PerformSurf(SeqSD,HGuide,Spine,Choix,HS1,It1,Or1,
2208 HS2,It2,HC2,HSref2,HCref2,decroch2,MaxStep,locfleche,tolesp,
2209 First,Last,Inside,Inside,forward,RecP2,RecS1,RecRst2,SoldepCS);
2211 ChFi3d_ResultChron(ch1,t_performsurf); //result perf for PerformSurf
2214 SD->ChangeIndexOfS1(DStr.AddShape(HS1->Face()));
2215 SD->ChangeIndexOfS2(DStr.AddShape(HS2->Face()));
2219 const Handle(Adaptor3d_TopolTool)& aTT1 = It1; // to avoid ambiguity
2220 const Handle(Adaptor3d_TopolTool)& aTT2 = It2; // to avoid ambiguity
2221 CallPerformSurf(Stripe, Simul, SeqSD, SD,
2223 HS1, HS3, pp1, pp3, aTT1,
2224 HS2, HS4, pp2, pp4, aTT2,
2225 MaxStep,locfleche,tolesp,
2226 First,Last,Inside,Inside,forward,
2227 RecS1,RecS2,Soldep,intf,intl,
2229 decroch1 = decroch2 = 0;
2232 if(!done) { // Case of fail
2233 if ((!Ok1 && !obstacleon1) || (!Ok2 && !obstacleon2)) {
2234 //Fail in a part of extension is not serious
2236 done = Standard_True;
2237 Inside = Standard_False;
2238 if (forward) intl = 1;
2241 else { // Otherwise invalidation of the stripe.
2242 Spine->SetErrorStatus(ChFiDS_WalkingFailure);
2243 throw Standard_Failure("CallPerformSurf : Path failed!");
2250 for (ii=1; ii<=SeqSD.Length(); ii++) {
2252 SD->ChangeIndexOfS1(DStr.AddShape(HS1->Face()));
2253 if(obstacleon1) SD->SetIndexOfC1(DStr.AddShape(HC1->Edge()));
2254 SD->ChangeIndexOfS2(DStr.AddShape(HS2->Face()));
2255 if(obstacleon2) SD->SetIndexOfC2(DStr.AddShape(HC2->Edge()));
2256 InsertAfter (Stripe, refbis, SD);
2261 for (ii=SeqSD.Length(); ii>=1; ii--) {
2263 SD->ChangeIndexOfS1(DStr.AddShape(HS1->Face()));
2264 if(obstacleon1) SD->SetIndexOfC1(DStr.AddShape(HC1->Edge()));
2265 SD->ChangeIndexOfS2(DStr.AddShape(HS2->Face()));
2266 if(obstacleon2) SD->SetIndexOfC2(DStr.AddShape(HC2->Edge()));
2267 InsertBefore(Stripe,refbis,SD);
2272 if (!Ok1 && !obstacleon1)
2273 // clean infos on the plane of extension.
2274 ChFi3d_Purge (Stripe,SD,ref->Vertex(!forward,1),!forward,1,intf,intl);
2276 if (!Ok2 && !obstacleon2)
2277 // clean infos on the plane of extension.
2278 ChFi3d_Purge (Stripe,SD,ref->Vertex(!forward,2),!forward,2,intf,intl);
2280 // The end. The reference is changed.
2284 if(Inside){// There are starting solutions for the next.
2285 Inside = Standard_False;
2287 if(Guide.IsPeriodic()) {
2288 complete = Standard_False;
2289 wf = Guide.FirstParameter();
2290 wl = Guide.LastParameter();
2294 fini = ((wl - Last) <= 10.*tolesp ||
2295 (intl && !(obstacleon1 || obstacleon2))); //General case
2297 if (!fini && Guide.IsPeriodic() &&
2298 ((wl - Last)< Guide.Period()*1.e-3)) {
2299 // It is tested if reframing of extremes is done at the same edge
2301 Handle(ChFiDS_SurfData) thefirst, thelast;
2302 thefirst = Stripe->SetOfSurfData()->Sequence().First();
2303 thelast = Stripe->SetOfSurfData()->Sequence().Last();
2305 if (thefirst->VertexFirstOnS1().IsOnArc() &&
2306 thelast->VertexLastOnS1().IsOnArc())
2307 fini = thefirst->VertexFirstOnS1().Arc().IsSame
2308 (thelast->VertexLastOnS1().Arc());
2310 thefirst->VertexFirstOnS2().IsOnArc() &&
2311 thelast->VertexLastOnS2().IsOnArc())
2312 fini = thefirst->VertexFirstOnS2().Arc().IsSame
2313 (thelast->VertexLastOnS2().Arc());
2316 return; //It is ended!
2319 if(fini && complete) {
2320 // restart in the opposite direction.
2321 ref = Stripe->SetOfSurfData()->Sequence().First();
2322 forward = Standard_False;
2323 fini = Standard_False;
2332 fini = ((First - wf) <= 10.*tolesp ||
2333 (intf && !(obstacleon1 || obstacleon2)));
2334 complete = Standard_False;
2338 // The initial state is restored
2339 if(!Guide.IsPeriodic()){
2340 Guide.FirstParameter(wfsav);
2341 Guide.LastParameter (wlsav);
2342 if (!OffsetHGuide.IsNull())
2344 OffsetHGuide->FirstParameter(wfsav);
2345 OffsetHGuide->LastParameter (wlsav);
2351 //=======================================================================
2352 //function : PerformSetOfKPart
2354 //=======================================================================
2356 void ChFi3d_Builder::PerformSetOfKPart(Handle(ChFiDS_Stripe)& Stripe,
2357 const Standard_Boolean Simul)
2359 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
2360 Handle(ChFiDS_Spine)& Spine = Stripe->ChangeSpine();
2361 Handle(BRepAdaptor_Surface) HS1,HS2;
2362 TopAbs_Orientation Or1,Or2,RefOr1,RefOr2;
2363 Standard_Integer RefChoix;
2365 // initialization of the stripe.
2367 Handle(ChFiDS_HData)& HData = Stripe->ChangeSetOfSurfData();
2368 HData = new ChFiDS_HData();
2369 ChFiDS_SequenceOfSurfData& SeqSurf = HData->ChangeSequence();
2371 StripeOrientations(Spine,RefOr1,RefOr2,RefChoix);
2372 Stripe->OrientationOnFace1(RefOr1);
2373 Stripe->OrientationOnFace2(RefOr2);
2374 Stripe->Choix(RefChoix);
2376 Handle(BRepTopAdaptor_TopolTool) It1 = new BRepTopAdaptor_TopolTool();
2377 Handle(BRepTopAdaptor_TopolTool) It2 = new BRepTopAdaptor_TopolTool();
2379 Standard_Real WFirst,WLast = 0.;
2380 gp_Vec TFirst,TLast,TEndPeriodic;
2381 gp_Pnt PFirst,PLast,PEndPeriodic;
2382 Standard_Boolean intf = Standard_False, intl = Standard_False;
2384 ChFiDS_ElSpine anElSpine, anOffsetElSpine;
2385 Handle(ChFiDS_ElSpine) CurrentHE = new ChFiDS_ElSpine(anElSpine);
2386 Handle(ChFiDS_ElSpine) CurrentOffsetHE = new ChFiDS_ElSpine(anOffsetElSpine);
2387 Spine->D1(Spine->FirstParameter(),PFirst,TFirst);
2388 CurrentHE->FirstParameter(Spine->FirstParameter());
2389 CurrentHE->SetFirstPointAndTgt(PFirst,TFirst);
2390 CurrentOffsetHE->FirstParameter(Spine->FirstParameter());
2391 CurrentOffsetHE->SetFirstPointAndTgt(PFirst,TFirst);
2393 Standard_Boolean YaKPart = Standard_False;
2394 Standard_Integer iedgelastkpart = 0;
2396 Standard_Real WStartPeriodic = 0.;
2397 Standard_Real WEndPeriodic = Spine->LastParameter(Spine->NbEdges());
2398 Spine->D1(WEndPeriodic,PEndPeriodic,TEndPeriodic);
2400 // Construction of particular cases.
2402 for (Standard_Integer iedge = 1; iedge <= Spine->NbEdges(); iedge++){
2404 ConexFaces(Spine,iedge,HS1,HS2);
2406 if (ChFi3d_KParticular (Spine, iedge, *HS1, *HS2)) {
2407 intf = ((iedge == 1) && !Spine->IsPeriodic());
2408 intl = ((iedge == Spine->NbEdges()) && !Spine->IsPeriodic());
2409 Or1 = HS1->Face().Orientation();
2410 Or2 = HS2->Face().Orientation();
2411 ChFi3d::NextSide(Or1,Or2,RefOr1,RefOr2,RefChoix);
2412 const Handle(Adaptor3d_Surface)& HSon1 = HS1; // to avoid ambiguity
2413 const Handle(Adaptor3d_Surface)& HSon2 = HS2; // to avoid ambiguity
2414 It1->Initialize(HSon1);
2415 It2->Initialize(HSon2);
2417 Handle(ChFiDS_SurfData) SD = new ChFiDS_SurfData();
2418 ChFiDS_SequenceOfSurfData LSD;
2420 if(!ChFiKPart_ComputeData::Compute(DStr,SD,HS1,HS2,Or1,Or2,Spine,iedge)){
2422 std::cout<<"failed calculation KPart"<<std::endl;
2425 else if(!SplitKPart(SD,LSD,Spine,iedge,HS1,It1,HS2,It2,intf,intl)){
2427 std::cout<<"failed calculation KPart"<<std::endl;
2431 else iedgelastkpart = iedge;
2432 if(Spine->IsPeriodic()){//debug provisory for SD that arrive in desorder.
2433 Standard_Integer nbsd = LSD.Length();
2434 Standard_Real period = Spine->Period();
2435 Standard_Real wfp = WStartPeriodic, wlp = WEndPeriodic;
2436 // modified by NIZHNY-EAP Thu Nov 25 12:57:53 1999 ___BEGIN___
2437 if(!YaKPart && nbsd>0){
2439 // modified by NIZHNY-EAP Thu Nov 25 12:57:57 1999 ___END___
2440 Handle(ChFiDS_SurfData) firstSD = LSD.ChangeValue(1);
2441 Standard_Real wwf = firstSD->FirstSpineParam();
2442 Standard_Real wwl = firstSD->LastSpineParam();
2443 wwf = ChFi3d_InPeriod(wwf,wfp,wlp,tolesp);
2444 wwl = ChFi3d_InPeriod(wwl,wfp,wlp,tolesp);
2445 if (wwl <= wwf + tolesp) wwl += period;
2449 for(Standard_Integer j = 1; j < nbsd; j++){
2450 Handle(ChFiDS_SurfData) jSD = LSD.Value(j);
2451 for(Standard_Integer k = j+1; k <= nbsd; k++){
2452 Handle(ChFiDS_SurfData) kSD = LSD.Value(k);
2453 Standard_Real jwf = jSD->FirstSpineParam();
2454 jwf = ChFi3d_InPeriod(jwf,wfp,wlp,tolesp);
2455 Standard_Real kwf = kSD->FirstSpineParam();
2456 kwf = ChFi3d_InPeriod(kwf,wfp,wlp,tolesp);
2458 LSD.SetValue(j,kSD);
2459 LSD.SetValue(k,jSD);
2464 TColStd_ListOfInteger li;
2465 for(Standard_Integer j = 1; j <= LSD.Length(); j++){
2466 Handle(ChFiDS_SurfData)& curSD = LSD.ChangeValue(j);
2467 if(Simul) SimulKPart(curSD);
2468 SeqSurf.Append(curSD);
2469 if(!Simul) li.Append(curSD->Surf());
2470 WFirst = LSD.Value(j)->FirstSpineParam();
2471 WLast = LSD.Value(j)->LastSpineParam();
2472 if(Spine->IsPeriodic()){
2473 WFirst = ChFi3d_InPeriod(WFirst,WStartPeriodic,WEndPeriodic,tolesp);
2474 WLast = ChFi3d_InPeriod(WLast ,WStartPeriodic,WEndPeriodic,tolesp);
2475 if (WLast <= WFirst + tolesp) WLast+= Spine->Period();
2477 TgtKP(LSD.Value(j),Spine,iedge,1,PFirst,TFirst);
2478 TgtKP(LSD.Value(j),Spine,iedge,0,PLast,TLast);
2480 // Determine the sections to approximate
2482 if(Spine->IsPeriodic()){
2483 WStartPeriodic = WFirst;
2484 WEndPeriodic = WStartPeriodic + Spine->Period();
2485 WLast = ElCLib::InPeriod(WLast,WStartPeriodic,WEndPeriodic);
2486 if (WLast <= WFirst + tolesp) WLast+= Spine->Period();
2487 PEndPeriodic = PFirst;
2488 TEndPeriodic = TFirst;
2489 Spine->SetFirstParameter(WStartPeriodic);
2490 Spine->SetLastParameter(WEndPeriodic);
2492 else if(!intf || (iedge > 1)){
2493 // start section -> first KPart
2494 // update of extension.
2495 Spine->SetFirstTgt(Min(0.,WFirst));
2496 CurrentHE->LastParameter (WFirst);
2497 CurrentHE->SetLastPointAndTgt(PFirst,TFirst);
2498 Spine->AppendElSpine(CurrentHE);
2499 CurrentHE->ChangeNext() = LSD.Value(j);
2500 CurrentHE = new ChFiDS_ElSpine();
2502 CurrentOffsetHE->LastParameter (WFirst);
2503 CurrentOffsetHE->SetLastPointAndTgt(PFirst,TFirst);
2504 Spine->AppendOffsetElSpine(CurrentOffsetHE);
2505 CurrentOffsetHE->ChangeNext() = LSD.Value(j);
2506 CurrentOffsetHE = new ChFiDS_ElSpine();
2508 CurrentHE->FirstParameter(WLast);
2509 CurrentHE->SetFirstPointAndTgt(PLast,TLast);
2510 CurrentHE->ChangePrevious() = LSD.Value(j);
2511 CurrentOffsetHE->FirstParameter(WLast);
2512 CurrentOffsetHE->SetFirstPointAndTgt(PLast,TLast);
2513 CurrentOffsetHE->ChangePrevious() = LSD.Value(j);
2514 YaKPart = Standard_True;
2517 if (WFirst - CurrentHE->FirstParameter() > tolesp) {
2518 // section between two KPart
2519 CurrentHE->LastParameter(WFirst);
2520 CurrentHE->SetLastPointAndTgt(PFirst,TFirst);
2521 Spine->AppendElSpine(CurrentHE);
2522 CurrentHE->ChangeNext() = LSD.Value(j);
2523 CurrentHE = new ChFiDS_ElSpine();
2525 CurrentOffsetHE->LastParameter(WFirst);
2526 CurrentOffsetHE->SetLastPointAndTgt(PFirst,TFirst);
2527 Spine->AppendOffsetElSpine(CurrentOffsetHE);
2528 CurrentOffsetHE->ChangeNext() = LSD.Value(j);
2529 CurrentOffsetHE = new ChFiDS_ElSpine();
2531 CurrentHE->FirstParameter(WLast);
2532 CurrentHE->SetFirstPointAndTgt(PLast,TLast);
2533 CurrentHE->ChangePrevious() = LSD.Value(j);
2534 CurrentOffsetHE->FirstParameter(WLast);
2535 CurrentOffsetHE->SetFirstPointAndTgt(PLast,TLast);
2536 CurrentOffsetHE->ChangePrevious() = LSD.Value(j);
2539 if(!li.IsEmpty()) myEVIMap.Bind(Spine->Edges(iedge),li);
2543 if (!intl || (iedgelastkpart < Spine->NbEdges())) {
2544 // section last KPart(or start of the spine) -> End of the spine.
2545 // update of the extension.
2547 if(Spine->IsPeriodic()){
2548 if(WEndPeriodic - WLast > tolesp){
2549 CurrentHE->LastParameter(WEndPeriodic);
2550 CurrentHE->SetLastPointAndTgt(PEndPeriodic,TEndPeriodic);
2551 if(!YaKPart) CurrentHE->SetPeriodic(Standard_True);
2552 Spine->AppendElSpine(CurrentHE);
2554 CurrentOffsetHE->LastParameter(WEndPeriodic);
2555 CurrentOffsetHE->SetLastPointAndTgt(PEndPeriodic,TEndPeriodic);
2556 if(!YaKPart) CurrentOffsetHE->SetPeriodic(Standard_True);
2557 Spine->AppendOffsetElSpine(CurrentOffsetHE);
2561 Spine->D1(Spine->LastParameter(),PLast,TLast);
2562 Spine->SetLastTgt(Max(Spine->LastParameter(Spine->NbEdges()),
2564 if (Spine->LastParameter() - WLast > tolesp) {
2565 CurrentHE->LastParameter(Spine->LastParameter());
2566 CurrentHE->SetLastPointAndTgt(PLast,TLast);
2567 Spine->AppendElSpine(CurrentHE);
2569 CurrentOffsetHE->LastParameter(Spine->LastParameter());
2570 CurrentOffsetHE->SetLastPointAndTgt(PLast,TLast);
2571 Spine->AppendOffsetElSpine(CurrentOffsetHE);
2576 ChFiDS_ListOfHElSpine& ll = Spine->ChangeElSpines();
2577 ChFiDS_ListIteratorOfListOfHElSpine ILES(ll);
2578 for ( ; ILES.More(); ILES.Next()) {
2580 if(ChFi3d_GettraceCHRON()) elspine.Start();
2582 ChFi3d_PerformElSpine(ILES.Value(),Spine,myConti,tolesp);
2584 if(ChFi3d_GettraceCHRON()) { elspine.Stop(); }
2587 if (Spine->Mode() == ChFiDS_ConstThroatWithPenetrationChamfer)
2589 ChFiDS_ListOfHElSpine& offsetll = Spine->ChangeOffsetElSpines();
2590 for (ILES.Initialize(offsetll); ILES.More(); ILES.Next())
2591 ChFi3d_PerformElSpine(ILES.Value(),Spine,myConti,tolesp,Standard_True);
2593 Spine->SplitDone(Standard_True);
2596 static Standard_Real ChFi3d_BoxDiag(const Bnd_Box& box)
2598 Standard_Real a,b,c,d,e,f;
2599 box.Get(a,b,c,d,e,f);
2602 Standard_Real diag = sqrt(d + e + f);
2606 //=======================================================================
2607 //function : PerformSetOfKGen
2609 //=======================================================================
2611 void ChFi3d_Builder::PerformSetOfKGen(Handle(ChFiDS_Stripe)& Stripe,
2612 const Standard_Boolean Simul)
2614 Handle(BRepTopAdaptor_TopolTool) It1 = new BRepTopAdaptor_TopolTool();
2615 Handle(BRepTopAdaptor_TopolTool) It2 = new BRepTopAdaptor_TopolTool();
2616 Handle(ChFiDS_Spine)& Spine = Stripe->ChangeSpine();
2617 ChFiDS_ListOfHElSpine& ll = Spine->ChangeElSpines();
2618 ChFiDS_ListIteratorOfListOfHElSpine ILES(ll);
2619 for ( ; ILES.More(); ILES.Next()) {
2621 if(ChFi3d_GettraceCHRON()) { chemine.Start(); }
2623 PerformSetOfSurfOnElSpine(ILES.Value(),Stripe,It1,It2,Simul);
2625 if(ChFi3d_GettraceCHRON()) chemine.Stop();
2629 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
2630 Handle(ChFiDS_HData)& HData = Stripe->ChangeSetOfSurfData();
2631 ChFiDS_SequenceOfSurfData& SeqSurf = HData->ChangeSequence();
2632 Standard_Integer len = SeqSurf.Length();
2633 Standard_Integer last = len, i;
2634 Standard_Boolean periodic = Spine->IsPeriodic();
2635 if(periodic) last++;
2636 // It is attempted to reprocess the squares that bore.
2637 for(i = 1; i <= len; i++){
2638 Handle(ChFiDS_SurfData)& cursd = SeqSurf.ChangeValue(i);
2639 Standard_Boolean tw1 = cursd->TwistOnS1();
2640 Standard_Boolean tw2 = cursd->TwistOnS2();
2641 Handle(ChFiDS_SurfData) prevsd, nextsd;
2642 Standard_Integer iprev = i-1;
2644 if(periodic) iprev = len;
2646 Standard_Integer inext = i + 1;
2648 if(periodic) inext = 1;
2652 // For the moment only the surfaces where the twist is
2653 // detected at the path are corrected, it is necessary to control
2654 // more subtly the ugly traces (size, curvature, inflexion... )
2655 if(!tw1 && !tw2) continue;
2657 // It is decided (fairly at random) if the extended surface is ready for the filling.
2658 ChFiDS_FaceInterference& intf1 = cursd->ChangeInterferenceOnS1();
2659 ChFiDS_FaceInterference& intf2 = cursd->ChangeInterferenceOnS2();
2660 Standard_Integer cursurf1 = cursd->IndexOfS1();
2661 Standard_Integer cursurf2 = cursd->IndexOfS2();
2662 ChFiDS_CommonPoint& cpd1 = cursd->ChangeVertexFirstOnS1();
2663 ChFiDS_CommonPoint& cpd2 = cursd->ChangeVertexFirstOnS2();
2664 ChFiDS_CommonPoint& cpf1 = cursd->ChangeVertexLastOnS1();
2665 ChFiDS_CommonPoint& cpf2 = cursd->ChangeVertexLastOnS2();
2666 const gp_Pnt& pd1 = cpd1.Point();
2667 const gp_Pnt& pd2 = cpd2.Point();
2668 const gp_Pnt& pf1 = cpf1.Point();
2669 const gp_Pnt& pf2 = cpf2.Point();
2670 Standard_Real ddeb = pd1.Distance(pd2);
2671 Standard_Real dfin = pf1.Distance(pf2);
2672 Standard_Real don1 = pd1.Distance(pf1);
2673 Standard_Real don2 = pd2.Distance(pf2);
2674 Standard_Boolean possibleon1 = (don1 < 2*(ddeb + dfin));
2675 Standard_Boolean possibleon2 = (don2 < 2*(ddeb + dfin));
2676 if((tw1 && !possibleon1) || (tw2 && !possibleon2)) {
2677 Spine->SetErrorStatus(ChFiDS_TwistedSurface);
2678 throw Standard_Failure("adjustment by reprocessing the non-written points");
2681 // It is checked if there are presentable neighbors
2682 Standard_Boolean yaprevon1 = 0, yaprevon2 = 0;
2683 Standard_Boolean samesurfon1 = 0, samesurfon2 = 0;
2685 prevsd = SeqSurf.ChangeValue(iprev);
2686 yaprevon1 = !prevsd->TwistOnS1();
2687 samesurfon1 = (prevsd->IndexOfS1() == cursurf1);
2688 yaprevon2 = !prevsd->TwistOnS2();
2689 samesurfon2 = (prevsd->IndexOfS2() == cursurf2);
2691 Standard_Boolean yanexton1 = 0, yanexton2 = 0;
2693 nextsd = SeqSurf.ChangeValue(inext);
2694 yanexton1 = !nextsd->TwistOnS1();
2695 if(samesurfon1) samesurfon1 = (nextsd->IndexOfS1() == cursurf1);
2696 yanexton2 = !nextsd->TwistOnS2();
2697 if(samesurfon2) samesurfon2 = (nextsd->IndexOfS2() == cursurf2);
2699 // A contour of filling is constructed
2700 Handle(Geom2d_Curve) PC1 = intf1.PCurveOnFace();
2701 Handle(Geom2d_Curve) PC2 = intf2.PCurveOnFace();
2702 Handle(BRepAdaptor_Surface) S1 = new BRepAdaptor_Surface();
2703 TopoDS_Face F1 = TopoDS::Face(DStr.Shape(cursurf1));
2705 Handle(BRepAdaptor_Surface) S2 = new BRepAdaptor_Surface();
2706 TopoDS_Face F2 = TopoDS::Face(DStr.Shape(cursurf2));
2708 Handle(GeomFill_Boundary) Bdeb,Bfin,Bon1,Bon2;
2709 Standard_Boolean pointuon1 = 0, pointuon2 = 0;
2711 if(!yaprevon1 || !yanexton1){
2712 Spine->SetErrorStatus(ChFiDS_TwistedSurface);
2713 throw Standard_Failure("adjustment by reprocessing the non-written points: no neighbor");
2715 ChFiDS_FaceInterference& previntf1 = prevsd->ChangeInterferenceOnS1();
2716 ChFiDS_FaceInterference& nextintf1 = nextsd->ChangeInterferenceOnS1();
2717 Standard_Real prevpar1 = previntf1.LastParameter();
2718 Standard_Real nextpar1 = nextintf1.FirstParameter();
2720 // It is checked if it is possible to intersect traces of neighbors
2721 // to create a sharp end.
2722 Handle(Geom2d_Curve) pcprev1 = previntf1.PCurveOnFace();
2723 Handle(Geom2d_Curve) pcnext1 = nextintf1.PCurveOnFace();
2724 Standard_Real nprevpar1,nnextpar1;
2726 // Modified by Sergey KHROMOV - Wed Feb 5 12:03:17 2003 Begin
2727 // if(ChFi3d_IntTraces(prevsd,prevpar1,nprevpar1,1,1,
2728 // nextsd,nextpar1,nnextpar1,1,-1,p2d)){
2729 if(ChFi3d_IntTraces(prevsd,prevpar1,nprevpar1,1,1,
2730 nextsd,nextpar1,nnextpar1,1,-1,p2d,
2731 Standard_False, Standard_True)){
2732 // Modified by Sergey KHROMOV - Wed Feb 5 12:03:17 2003 End
2733 previntf1.SetLastParameter(nprevpar1);
2734 nextintf1.SetFirstParameter(nnextpar1);
2739 gp_Pnt2d pdeb1,pfin1;
2740 gp_Vec2d vdeb1,vfin1;
2741 pcprev1->D1(prevpar1,pdeb1,vdeb1);
2742 pcnext1->D1(nextpar1,pfin1,vfin1);
2743 Bon1 = ChFi3d_mkbound(S1,PC1,-1,pdeb1,vdeb1,1,
2744 pfin1,vfin1,tolesp,2.e-4);
2748 //here the base is on 3D tangents of neighbors.
2749 const Handle(Geom_Curve)& c3dprev1 =
2750 DStr.Curve(previntf1.LineIndex()).Curve();
2751 const Handle(Geom_Curve)& c3dnext1 =
2752 DStr.Curve(nextintf1.LineIndex()).Curve();
2753 gp_Pnt Pdeb1, Pfin1;
2754 gp_Vec Vdeb1, Vfin1;
2755 c3dprev1->D1(prevpar1,Pdeb1,Vdeb1);
2756 c3dnext1->D1(nextpar1,Pfin1,Vfin1);
2757 gp_Pnt2d pdeb1,pfin1;
2758 Standard_Real pardeb1 = intf1.FirstParameter();
2759 Standard_Real parfin1 = intf1.LastParameter();
2760 pdeb1 = PC1->Value(pardeb1);
2761 pfin1 = PC1->Value(parfin1);
2762 Bon1 = ChFi3d_mkbound(S1,PC1,-1,pdeb1,Vdeb1,1,
2763 pfin1,Vfin1,tolesp,2.e-4);
2767 Bon1 = ChFi3d_mkbound(S1,PC1,tolesp,2.e-4);
2770 if(!yaprevon2 || !yanexton2){
2771 throw Standard_Failure("adjustment by reprocessing the non-written points: no neighbor");
2773 ChFiDS_FaceInterference& previntf2 = prevsd->ChangeInterferenceOnS2();
2774 ChFiDS_FaceInterference& nextintf2 = nextsd->ChangeInterferenceOnS2();
2775 Standard_Real prevpar2 = previntf2.LastParameter();
2776 Standard_Real nextpar2 = nextintf2.FirstParameter();
2778 // It is checked if it is possible to intersect traces of neighbors
2779 // to create a sharp end.
2780 Handle(Geom2d_Curve) pcprev2 = previntf2.PCurveOnFace();
2781 Handle(Geom2d_Curve) pcnext2 = nextintf2.PCurveOnFace();
2782 Standard_Real nprevpar2,nnextpar2;
2784 // Modified by Sergey KHROMOV - Wed Feb 5 12:03:17 2003 Begin
2785 // if(ChFi3d_IntTraces(prevsd,prevpar2,nprevpar2,2,1,
2786 // nextsd,nextpar2,nnextpar2,2,-1,p2d)){
2787 if(ChFi3d_IntTraces(prevsd,prevpar2,nprevpar2,2,1,
2788 nextsd,nextpar2,nnextpar2,2,-1,p2d,
2789 Standard_False, Standard_True)){
2790 // Modified by Sergey KHROMOV - Wed Feb 5 12:03:17 2003 End
2791 previntf2.SetLastParameter(nprevpar2);
2792 nextintf2.SetFirstParameter(nnextpar2);
2797 gp_Pnt2d pdeb2,pfin2;
2798 gp_Vec2d vdeb2,vfin2;
2799 pcprev2->D1(prevpar2,pdeb2,vdeb2);
2800 pcnext2->D1(nextpar2,pfin2,vfin2);
2801 Bon2 = ChFi3d_mkbound(S2,PC2,-1,pdeb2,vdeb2,1,
2802 pfin2,vfin2,tolesp,2.e-4);
2806 //here the base is on 3D tangents of neighbors.
2807 const Handle(Geom_Curve)& c3dprev2 =
2808 DStr.Curve(previntf2.LineIndex()).Curve();
2809 const Handle(Geom_Curve)& c3dnext2 =
2810 DStr.Curve(nextintf2.LineIndex()).Curve();
2811 gp_Pnt Pdeb2, Pfin2;
2812 gp_Vec Vdeb2, Vfin2;
2813 c3dprev2->D1(prevpar2,Pdeb2,Vdeb2);
2814 c3dnext2->D1(nextpar2,Pfin2,Vfin2);
2815 gp_Pnt2d pdeb2,pfin2;
2816 Standard_Real pardeb2 = intf2.FirstParameter();
2817 Standard_Real parfin2 = intf2.LastParameter();
2818 pdeb2 = PC2->Value(pardeb2);
2819 pfin2 = PC2->Value(parfin2);
2820 Bon2 = ChFi3d_mkbound(S2,PC2,-1,pdeb2,Vdeb2,1,
2821 pfin2,Vfin2,tolesp,2.e-4);
2825 Bon2 = ChFi3d_mkbound(S2,PC2,tolesp,2.e-4);
2827 // The parameters of neighbor traces are updated, so
2828 // straight lines uv are pulled.
2829 const Handle(Geom_Surface)&
2830 sprev = DStr.Surface(prevsd->Surf()).Surface();
2831 const Handle(Geom_Surface)&
2832 snext = DStr.Surface(nextsd->Surf()).Surface();
2833 ChFiDS_FaceInterference& previntf1 = prevsd->ChangeInterferenceOnS1();
2834 ChFiDS_FaceInterference& nextintf1 = nextsd->ChangeInterferenceOnS1();
2835 ChFiDS_FaceInterference& previntf2 = prevsd->ChangeInterferenceOnS2();
2836 ChFiDS_FaceInterference& nextintf2 = nextsd->ChangeInterferenceOnS2();
2837 Handle(Geom2d_Curve) pcsprev1 = previntf1.PCurveOnSurf();
2838 Handle(Geom2d_Curve) pcsnext1 = nextintf1.PCurveOnSurf();
2839 Standard_Real prevpar1 = previntf1.LastParameter();
2840 Standard_Real nextpar1 = nextintf1.FirstParameter();
2841 Handle(Geom2d_Curve) pcsprev2 = previntf2.PCurveOnSurf();
2842 Handle(Geom2d_Curve) pcsnext2 = nextintf2.PCurveOnSurf();
2843 Standard_Real prevpar2 = previntf2.LastParameter();
2844 Standard_Real nextpar2 = nextintf2.FirstParameter();
2845 gp_Pnt2d pdebs1 = pcsprev1->Value(prevpar1);
2846 gp_Pnt2d pdebs2 = pcsprev2->Value(prevpar2);
2847 gp_Pnt2d pfins1 = pcsnext1->Value(nextpar1);
2848 gp_Pnt2d pfins2 = pcsnext2->Value(nextpar2);
2849 Bdeb = ChFi3d_mkbound(sprev,pdebs1,pdebs2,tolesp,2.e-4);
2850 Bfin = ChFi3d_mkbound(snext,pfins1,pfins2,tolesp,2.e-4);
2852 GeomFill_ConstrainedFilling fil(11,20);
2853 if(pointuon1) fil.Init(Bon2,Bfin,Bdeb,1);
2854 else if(pointuon2) fil.Init(Bon1,Bfin,Bdeb,1);
2855 else fil.Init(Bon1,Bfin,Bon2,Bdeb,1);
2857 ChFi3d_ReparamPcurv(0.,1.,PC1);
2858 ChFi3d_ReparamPcurv(0.,1.,PC2);
2859 Handle(Geom_Surface) newsurf = fil.Surface();
2863 char* pops = "newsurf";
2864 DrawTrSurf::Set(pops,newsurf);
2868 newsurf->VReverse(); // we return to direction 1 from 2;
2869 done = CompleteData(cursd,newsurf,S1,PC1,S2,PC2,
2870 F2.Orientation(),0,0,0,0,0);
2871 cursd->ChangeIndexOfS1(0);
2874 done = CompleteData(cursd,newsurf,S1,PC1,S2,PC2,
2875 F1.Orientation(),1,0,0,0,0);
2876 if(pointuon2) cursd->ChangeIndexOfS2(0);
2879 prevsd->ChangeVertexLastOnS1().SetPoint(cpd1.Point());
2880 nextsd->ChangeVertexFirstOnS1().SetPoint(cpf1.Point());
2883 prevsd->ChangeVertexLastOnS2().SetPoint(cpd2.Point());
2884 nextsd->ChangeVertexFirstOnS2().SetPoint(cpf2.Point());
2887 // The tolerance of points is updated.
2888 for(i = 1; i < last; i++){
2889 Standard_Integer j = i%len + 1;
2890 Standard_Integer curs1, curs2;
2891 Standard_Integer nexts1, nexts2;
2892 Handle(ChFiDS_SurfData)& cursd = SeqSurf.ChangeValue(i);
2893 Handle(ChFiDS_SurfData)& nextsd = SeqSurf.ChangeValue(j);
2894 ChFiDS_CommonPoint& curp1 = cursd->ChangeVertexLastOnS1();
2895 ChFiDS_CommonPoint& nextp1 = nextsd->ChangeVertexFirstOnS1();
2896 if (cursd->IsOnCurve1()) curs1 = cursd->IndexOfC1();
2897 else curs1 = cursd->IndexOfS1();
2898 if (cursd->IsOnCurve2()) curs2 = cursd->IndexOfC2();
2899 else curs2 = cursd->IndexOfS2();
2900 Standard_Real tol1 = Max(curp1.Tolerance(),nextp1.Tolerance());
2901 ChFiDS_CommonPoint& curp2 = cursd->ChangeVertexLastOnS2();
2902 ChFiDS_CommonPoint& nextp2 = nextsd->ChangeVertexFirstOnS2();
2903 Standard_Real tol2 = Max(curp2.Tolerance(),nextp2.Tolerance());
2904 if (nextsd->IsOnCurve1()) nexts1 = nextsd->IndexOfC1();
2905 else nexts1 = nextsd->IndexOfS1();
2906 if (nextsd->IsOnCurve2()) nexts2 = nextsd->IndexOfC2();
2907 else nexts2 = nextsd->IndexOfS2();
2909 if(!curp1.IsOnArc() && nextp1.IsOnArc()){
2911 if ( (curs1 == nexts1) && !nextsd->IsOnCurve1())
2912 // Case when it is not possible to pass along the border without leaving
2913 ChangeTransition(nextp1, curp1, nexts1, myDS);
2915 else if(curp1.IsOnArc() && !nextp1.IsOnArc()) {
2917 if ( (curs1 == nexts1) && !cursd->IsOnCurve1())
2918 ChangeTransition(curp1, nextp1, curs1, myDS);
2921 if(!curp2.IsOnArc() && nextp2.IsOnArc()) {
2923 if ( (curs2 == nexts2) && !nextsd->IsOnCurve2())
2924 ChangeTransition(nextp2, curp2, curs2, myDS);
2926 else if(curp2.IsOnArc() && !nextp2.IsOnArc()){
2928 if ( (curs2 == nexts2) && !cursd->IsOnCurve2())
2929 ChangeTransition(curp2, nextp2, curs2, myDS);
2932 curp1.SetTolerance(tol1); nextp1.SetTolerance(tol1);
2933 curp2.SetTolerance(tol2); nextp2.SetTolerance(tol2);
2936 if(curp1.IsOnArc()){
2937 ChFi3d_EnlargeBox(curp1.Arc(),myEFMap(curp1.Arc()),curp1.ParameterOnArc(),b1);
2939 if(curp2.IsOnArc()){
2940 ChFi3d_EnlargeBox(curp2.Arc(),myEFMap(curp2.Arc()),curp2.ParameterOnArc(),b2);
2942 Handle(ChFiDS_Stripe) bidst;
2943 ChFi3d_EnlargeBox(DStr,bidst,cursd,b1,b2,0);
2944 ChFi3d_EnlargeBox(DStr,bidst,nextsd,b1,b2,1);
2945 tol1 = ChFi3d_BoxDiag(b1);
2946 tol2 = ChFi3d_BoxDiag(b2);
2947 curp1.SetTolerance(tol1); nextp1.SetTolerance(tol1);
2948 curp2.SetTolerance(tol2); nextp2.SetTolerance(tol2);
2950 // The connections edge/new faces are updated.
2951 for (ILES.Initialize(ll) ; ILES.More(); ILES.Next()) {
2952 const Handle(ChFiDS_ElSpine)& curhels = ILES.Value();
2953 Standard_Real WF = curhels->FirstParameter();
2954 Standard_Real WL = curhels->LastParameter();
2955 Standard_Integer IF,IL;
2956 Standard_Real nwf = WF, nwl = WL;
2957 Standard_Real period = 0.;
2958 Standard_Integer nbed = Spine->NbEdges();
2960 period = Spine->Period();
2961 nwf = ElCLib::InPeriod(WF,-tolesp,period-tolesp);
2962 IF = Spine->Index(nwf,1);
2963 nwl = ElCLib::InPeriod(WL,tolesp,period+tolesp);
2964 IL = Spine->Index(nwl,0);
2965 if(nwl<nwf+tolesp) IL += nbed;
2968 IF = Spine->Index(WF,1);
2969 IL = Spine->Index(WL,0);
2973 Standard_Integer IFloc = IF;
2974 if(periodic) IFloc = (IF - 1)%nbed + 1;
2975 const TopoDS_Edge& Ej = Spine->Edges(IFloc);
2976 for(i = 1; i <= len; i++){
2977 Handle(ChFiDS_SurfData)& cursd = SeqSurf.ChangeValue(i);
2978 Standard_Real fp = cursd->FirstSpineParam();
2979 Standard_Real lp = cursd->LastSpineParam();
2980 if(lp < WF+tolesp || fp > WL-tolesp) continue;
2981 if(!myEVIMap.IsBound(Ej)) {
2982 TColStd_ListOfInteger li;
2983 myEVIMap.Bind(Ej,li);
2985 myEVIMap.ChangeFind(Ej).Append(cursd->Surf());
2989 TColStd_Array1OfReal wv(IF,IL - 1);
2991 std::cout<<"length of the trajectory : "<<(WL-WF)<<std::endl;
2993 for(i = IF; i < IL; i++){
2994 Standard_Integer iloc = i;
2995 if(periodic) iloc = (i - 1)%nbed + 1;
2996 Standard_Real wi = Spine->LastParameter(iloc);
2997 if(periodic) wi = ElCLib::InPeriod(wi,WF,WF+period);
2998 gp_Pnt pv = Spine->Value(wi);
3000 gp_Pnt pelsapp = curhels->Value(wi);
3001 Standard_Real distinit = pv.Distance(pelsapp);
3002 std::cout<<"distance psp/papp : "<<distinit<<std::endl;
3004 Extrema_LocateExtPC ext(pv,*curhels,wi,1.e-8);
3007 wv(i) = ext.Point().Parameter();
3011 std::cout<<"fail of projection vertex ElSpine!!!"<<std::endl;
3015 for(i = 1; i <= len; i++){
3016 Handle(ChFiDS_SurfData)& cursd = SeqSurf.ChangeValue(i);
3017 Standard_Real fp = cursd->FirstSpineParam();
3018 Standard_Real lp = cursd->LastSpineParam();
3020 Standard_Integer jf = 0, jl = 0;
3021 if(lp < WF+tolesp || fp > WL-tolesp) continue;
3022 for(j = IF; j < IL; j++){
3024 if(fp < wv(j) - tolesp) break;
3026 for(j = IF; j < IL; j++){
3028 if(lp < wv(j) + tolesp) break;
3030 for(j = jf; j <= jl; j++){
3031 Standard_Integer jloc = j;
3032 if(periodic) jloc = (j - 1)%nbed + 1;
3033 const TopoDS_Edge& Ej = Spine->Edges(jloc);
3034 if(!myEVIMap.IsBound(Ej)) {
3035 TColStd_ListOfInteger li;
3036 myEVIMap.Bind(Ej,li);
3038 myEVIMap.ChangeFind(Ej).Append(cursd->Surf());
3046 //=======================================================================
3047 //function : PerformSetOfSurf
3049 //=======================================================================
3051 void ChFi3d_Builder::PerformSetOfSurf(Handle(ChFiDS_Stripe)& Stripe,
3052 const Standard_Boolean Simul)
3054 TopOpeBRepDS_DataStructure& DStr = myDS->ChangeDS();
3058 ChFi3d_InitChron(ch);// init perf for PerformSetOfKPart
3061 const Handle(ChFiDS_Spine)& sp = Stripe->Spine();
3062 Standard_Integer SI = ChFi3d_SolidIndex(sp,DStr,myESoMap,myEShMap);
3063 Stripe->SetSolidIndex(SI);
3064 if(!sp->SplitDone()) PerformSetOfKPart(Stripe,Simul);
3067 ChFi3d_ResultChron(ch ,t_perfsetofkpart); // result perf PerformSetOfKPart(
3068 ChFi3d_InitChron(ch); // init perf for PerformSetOfKGen
3071 PerformSetOfKGen(Stripe,Simul);
3074 ChFi3d_ResultChron(ch, t_perfsetofkgen);//result perf PerformSetOfKGen
3075 ChFi3d_InitChron(ch); // init perf for ChFi3d_MakeExtremities
3078 if(!Simul) ChFi3d_MakeExtremities(Stripe,DStr,myEFMap,tolesp,tol2d);
3081 ChFi3d_ResultChron(ch, t_makextremities); // result perf t_makextremities