OCC22311 A regression was found: face obtained from 2D offset of a wire is invalid
[occt.git] / src / BRepFill / BRepFill_ApproxSeewing.cxx
CommitLineData
7fd59977 1// File: BRepFill_ApproxSeewing.cxx
2// Created: Fri Sep 22 08:44:29 1995
3// Author: Bruno DUMORTIER
4// <dub@fuegox>
5
6
7#include <BRepFill_ApproxSeewing.ixx>
8
9#include <AppParCurves_MultiCurve.hxx>
10#include <AppDef_Compute.hxx>
11#include <AppDef_MultiLine.hxx>
12#include <AppDef_MultiPointConstraint.hxx>
13#include <BSplCLib.hxx>
14#include <PLib.hxx>
15#include <Geom_BSplineCurve.hxx>
16#include <Geom2d_BSplineCurve.hxx>
17#include <TColgp_Array1OfPnt.hxx>
18#include <TColgp_Array1OfPnt2d.hxx>
19#include <TColStd_Array1OfReal.hxx>
20#include <TColStd_Array1OfInteger.hxx>
21
22
23//=======================================================================
24//function : BRepFill_ApproxSeewing
25//purpose :
26//=======================================================================
27
28BRepFill_ApproxSeewing::BRepFill_ApproxSeewing()
29:myIsDone(Standard_False)
30{
31}
32
33
34//=======================================================================
35//function : BRepFill_ApproxSeewing
36//purpose :
37//=======================================================================
38
39BRepFill_ApproxSeewing::BRepFill_ApproxSeewing(const BRepFill_MultiLine& ML)
40:myIsDone(Standard_False)
41{
42 Perform(ML);
43}
44
45
46//=======================================================================
47//function : Perform
48//purpose :
49//=======================================================================
50
51void BRepFill_ApproxSeewing::Perform(const BRepFill_MultiLine& ML)
52{
53 myML = ML;
54
55 // evaluate the approximative length of the 3dCurve
56 Standard_Integer i;
57 Standard_Real Length = 0.;
58 Standard_Real U1 = myML.FirstParameter();
59 Standard_Real U2 = myML.LastParameter();
60 Standard_Integer NbPoints = 50;
61 Standard_Real Dist, dU = (U2 - U1) / ( 2*NbPoints - 1);
62
63 TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param
64 gp_Pnt P1, P2;
65 P1 = myML.Value(U1);
66
67 for ( i = 0; i < 2*NbPoints ; i++) {
68 P2 = myML.Value(U1 + i*dU);
69 Dist = P1.Distance(P2);
70 Length += Dist;
71 LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU));
72 P1 = P2;
73 }
74
75 // On cherche a mettre NbPoints dans la curve.
76 // on met les points environ a Length/NbPoints.
77
78 AppDef_MultiLine MLS ( NbPoints);
79 AppDef_MultiPointConstraint MP ( 1, 2);
80 gp_Pnt P3d;
81 gp_Pnt2d PF1,PF2;
82
83 ML.Value3dOnF1OnF2(U1,P3d,PF1,PF2);
84 MP.SetPoint (1, P3d);
85 MP.SetPoint2d(2, PF1);
86 MP.SetPoint2d(3, PF2);
87 MLS.SetValue (1, MP);
88
89 Standard_Real DCorde = Length / ( NbPoints - 1);
90 Standard_Real Corde = DCorde;
91 Standard_Integer Index = 1;
92 Standard_Real U, Alpha;
93 for ( i = 2; i < NbPoints; i++) {
94 while ( LP(Index).X() < Corde) Index ++;
95 Alpha = (Corde - LP(Index-1).X()) / (LP(Index).X() - LP(Index-1).X());
96 U = LP(Index-1).Y() + Alpha * ( LP(Index).Y() - LP(Index-1).Y());
97 AppDef_MultiPointConstraint MPC( 1, 2);
98 ML.Value3dOnF1OnF2(U,P3d,PF1,PF2);
99 MPC.SetPoint (1, P3d);
100 MPC.SetPoint2d(2, PF1);
101 MPC.SetPoint2d(3, PF2);
102 MLS.SetValue (i, MPC);
103 Corde = i*DCorde;
104 }
105 AppDef_MultiPointConstraint MPE( 1, 2);
106 ML.Value3dOnF1OnF2(U2,P3d,PF1,PF2);
107 MPE.SetPoint (1, P3d);
108 MPE.SetPoint2d(2, PF1);
109 MPE.SetPoint2d(3, PF2);
110 MLS.SetValue (NbPoints, MPE);
111
112 AppDef_Compute Fit(MLS);
113
114 Standard_Integer NbCurves = Fit.NbMultiCurves();
115// Standard_Integer MaxDeg = 0;
116
117 if ( NbCurves == 0) {
118#ifdef DEBUG_EVOLVED
119 cout << " TrimSurfaceTool : Approx echoue, on met les polygones" << endl;
120#endif
121
122 TColStd_Array1OfReal Knots(1,NbPoints);
123 TColStd_Array1OfInteger Mults(1,NbPoints);
124 Mults.Init(1);
125 Mults(1) = Mults(NbPoints) = 2;
126 TColgp_Array1OfPnt P (1,NbPoints);
127 TColgp_Array1OfPnt2d P1(1,NbPoints);
128 TColgp_Array1OfPnt2d P2(1,NbPoints);
129
130 Standard_Real Uf = ML.FirstParameter();
131 Standard_Real Ul = ML.LastParameter();
132 Standard_Real dU = (Ul-Uf)/(NbPoints-1);
133 AppDef_MultiPointConstraint MPC;
134 for ( i = 1; i<= NbPoints-1; i++) {
135 MPC = MLS.Value(i);
136 U = Uf + (i-1) * dU;
137 P (i) = MPC.Point(1);
138 P1(i) = MPC.Point2d(2);
139 P2(i) = MPC.Point2d(3);
140 Knots(i) = U;
141 }
142 // eval the last point on Ul
143 MPC = MLS.Value(NbPoints);
144 P (NbPoints) = MPC.Point(1);
145 P1(NbPoints) = MPC.Point2d(2);
146 P2(NbPoints) = MPC.Point2d(3);
147 Knots(NbPoints) = Ul;
148
149 myCurve = new Geom_BSplineCurve ( P , Knots, Mults, 1);
150 myPCurve1 = new Geom2d_BSplineCurve( P1, Knots, Mults, 1);
151 myPCurve2 = new Geom2d_BSplineCurve( P2, Knots, Mults, 1);
152
153 myIsDone = Standard_True;
154
155 return;
156 }
157
158 // Les approx sont a priori OK.
159
160 const AppParCurves_MultiBSpCurve& MBSp =
161 Fit.SplineValue();
162 Standard_Integer NbPoles = MBSp.NbPoles();
163 TColgp_Array1OfPnt Poles (1 , NbPoles);
164 TColgp_Array1OfPnt2d Poles2d1(1 , NbPoles);
165 TColgp_Array1OfPnt2d Poles2d2(1 , NbPoles);
166
167 MBSp.Curve(1, Poles);
168 MBSp.Curve(2, Poles2d1);
169 MBSp.Curve(3, Poles2d2);
170
171 const TColStd_Array1OfReal& Knots = MBSp.Knots();
172 const TColStd_Array1OfInteger& Mults = MBSp.Multiplicities();
173 Standard_Integer Degree = MBSp.Degree();
174
175 myCurve = new Geom_BSplineCurve (Poles, Knots,Mults,Degree);
176 myPCurve1 = new Geom2d_BSplineCurve(Poles2d1,Knots,Mults,Degree);
177 myPCurve2 = new Geom2d_BSplineCurve(Poles2d2,Knots,Mults,Degree);
178
179 myIsDone = Standard_True;
180}
181
182
183//=======================================================================
184//function : IsDone
185//purpose :
186//=======================================================================
187
188Standard_Boolean BRepFill_ApproxSeewing::IsDone() const
189{
190 return myIsDone;
191}
192
193
194//=======================================================================
195//function : Handle_Geom_Curve&
196//purpose :
197//=======================================================================
198
199const Handle(Geom_Curve)& BRepFill_ApproxSeewing::Curve() const
200{
201 StdFail_NotDone_Raise_if( !myIsDone,
202 "BRepFill_ApproxSeewing::Curve");
203 return myCurve;
204}
205
206
207//=======================================================================
208//function : Handle_Geom2d_Curve&
209//purpose :
210//=======================================================================
211
212const Handle(Geom2d_Curve)& BRepFill_ApproxSeewing::CurveOnF1() const
213{
214 StdFail_NotDone_Raise_if( !myIsDone,
215 "BRepFill_ApproxSeewing::CurveOnF1");
216 return myPCurve1;
217}
218
219
220//=======================================================================
221//function : Handle_Geom2d_Curve&
222//purpose :
223//=======================================================================
224
225const Handle(Geom2d_Curve)& BRepFill_ApproxSeewing::CurveOnF2() const
226{
227 StdFail_NotDone_Raise_if( !myIsDone,
228 "BRepFill_ApproxSeewing::CurveOnF2");
229 return myPCurve2;
230}
231
232