b311480e |
1 | // Created on: 1995-09-22 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
7fd59977 |
18 | #include <AppDef_Compute.hxx> |
19 | #include <AppDef_MultiLine.hxx> |
20 | #include <AppDef_MultiPointConstraint.hxx> |
42cf5bc1 |
21 | #include <AppParCurves_MultiCurve.hxx> |
22 | #include <BRepFill_ApproxSeewing.hxx> |
7fd59977 |
23 | #include <BSplCLib.hxx> |
7fd59977 |
24 | #include <Geom2d_BSplineCurve.hxx> |
42cf5bc1 |
25 | #include <Geom2d_Curve.hxx> |
26 | #include <Geom_BSplineCurve.hxx> |
27 | #include <Geom_Curve.hxx> |
28 | #include <PLib.hxx> |
29 | #include <StdFail_NotDone.hxx> |
7fd59977 |
30 | #include <TColgp_Array1OfPnt.hxx> |
31 | #include <TColgp_Array1OfPnt2d.hxx> |
7fd59977 |
32 | #include <TColStd_Array1OfInteger.hxx> |
42cf5bc1 |
33 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 |
34 | |
35 | //======================================================================= |
36 | //function : BRepFill_ApproxSeewing |
37 | //purpose : |
38 | //======================================================================= |
7fd59977 |
39 | BRepFill_ApproxSeewing::BRepFill_ApproxSeewing() |
40 | :myIsDone(Standard_False) |
41 | { |
42 | } |
43 | |
44 | |
45 | //======================================================================= |
46 | //function : BRepFill_ApproxSeewing |
47 | //purpose : |
48 | //======================================================================= |
49 | |
50 | BRepFill_ApproxSeewing::BRepFill_ApproxSeewing(const BRepFill_MultiLine& ML) |
51 | :myIsDone(Standard_False) |
52 | { |
53 | Perform(ML); |
54 | } |
55 | |
56 | |
57 | //======================================================================= |
58 | //function : Perform |
59 | //purpose : |
60 | //======================================================================= |
61 | |
62 | void BRepFill_ApproxSeewing::Perform(const BRepFill_MultiLine& ML) |
63 | { |
64 | myML = ML; |
65 | |
66 | // evaluate the approximative length of the 3dCurve |
67 | Standard_Integer i; |
68 | Standard_Real Length = 0.; |
69 | Standard_Real U1 = myML.FirstParameter(); |
70 | Standard_Real U2 = myML.LastParameter(); |
71 | Standard_Integer NbPoints = 50; |
72 | Standard_Real Dist, dU = (U2 - U1) / ( 2*NbPoints - 1); |
73 | |
74 | TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param |
51740958 |
75 | gp_Pnt aPnt1, aPnt2; |
76 | aPnt1 = myML.Value(U1); |
7fd59977 |
77 | |
78 | for ( i = 0; i < 2*NbPoints ; i++) { |
51740958 |
79 | aPnt2 = myML.Value(U1 + i*dU); |
80 | Dist = aPnt1.Distance(aPnt2); |
7fd59977 |
81 | Length += Dist; |
82 | LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU)); |
51740958 |
83 | aPnt1 = aPnt2; |
7fd59977 |
84 | } |
85 | |
86 | // On cherche a mettre NbPoints dans la curve. |
87 | // on met les points environ a Length/NbPoints. |
88 | |
89 | AppDef_MultiLine MLS ( NbPoints); |
90 | AppDef_MultiPointConstraint MP ( 1, 2); |
91 | gp_Pnt P3d; |
92 | gp_Pnt2d PF1,PF2; |
93 | |
94 | ML.Value3dOnF1OnF2(U1,P3d,PF1,PF2); |
95 | MP.SetPoint (1, P3d); |
96 | MP.SetPoint2d(2, PF1); |
97 | MP.SetPoint2d(3, PF2); |
98 | MLS.SetValue (1, MP); |
df573a26 |
99 | |
100 | #ifdef DUMP_ML |
101 | i = 1; |
102 | cout << "--Point " << i << endl; |
103 | cout << "P3d: " << P3d.X() << " " << P3d.Y() << " " << P3d.Z() << endl; |
104 | cout << "P2d1;2: " << PF1.X() << " " << PF1.Y() << " ; " << PF2.X() << " " << PF2.Y() << endl; |
105 | #endif |
106 | |
7fd59977 |
107 | |
108 | Standard_Real DCorde = Length / ( NbPoints - 1); |
109 | Standard_Real Corde = DCorde; |
110 | Standard_Integer Index = 1; |
111 | Standard_Real U, Alpha; |
112 | for ( i = 2; i < NbPoints; i++) { |
113 | while ( LP(Index).X() < Corde) Index ++; |
114 | Alpha = (Corde - LP(Index-1).X()) / (LP(Index).X() - LP(Index-1).X()); |
115 | U = LP(Index-1).Y() + Alpha * ( LP(Index).Y() - LP(Index-1).Y()); |
116 | AppDef_MultiPointConstraint MPC( 1, 2); |
117 | ML.Value3dOnF1OnF2(U,P3d,PF1,PF2); |
df573a26 |
118 | #ifdef DUMP_ML |
119 | cout << "--Point " << i << endl; |
120 | cout << "P3d: " << P3d.X() << " " << P3d.Y() << " " << P3d.Z() << endl; |
121 | cout << "P2d1;2: " << PF1.X() << " " << PF1.Y() << " ; " << PF2.X() << " " << PF2.Y() << endl; |
122 | #endif |
7fd59977 |
123 | MPC.SetPoint (1, P3d); |
124 | MPC.SetPoint2d(2, PF1); |
125 | MPC.SetPoint2d(3, PF2); |
126 | MLS.SetValue (i, MPC); |
127 | Corde = i*DCorde; |
128 | } |
129 | AppDef_MultiPointConstraint MPE( 1, 2); |
130 | ML.Value3dOnF1OnF2(U2,P3d,PF1,PF2); |
df573a26 |
131 | #ifdef DUMP_ML |
132 | i = NbPoints; |
133 | cout << "--Point " << i << endl; |
134 | cout << "P3d: " << P3d.X() << " " << P3d.Y() << " " << P3d.Z() << endl; |
135 | cout << "P2d1;2: " << PF1.X() << " " << PF1.Y() << " ; " << PF2.X() << " " << PF2.Y() << endl; |
136 | #endif |
7fd59977 |
137 | MPE.SetPoint (1, P3d); |
138 | MPE.SetPoint2d(2, PF1); |
139 | MPE.SetPoint2d(3, PF2); |
140 | MLS.SetValue (NbPoints, MPE); |
df573a26 |
141 | |
7fd59977 |
142 | AppDef_Compute Fit(MLS); |
143 | |
144 | Standard_Integer NbCurves = Fit.NbMultiCurves(); |
145 | // Standard_Integer MaxDeg = 0; |
146 | |
147 | if ( NbCurves == 0) { |
0797d9d3 |
148 | #ifdef OCCT_DEBUG |
7fd59977 |
149 | cout << " TrimSurfaceTool : Approx echoue, on met les polygones" << endl; |
150 | #endif |
151 | |
152 | TColStd_Array1OfReal Knots(1,NbPoints); |
153 | TColStd_Array1OfInteger Mults(1,NbPoints); |
154 | Mults.Init(1); |
155 | Mults(1) = Mults(NbPoints) = 2; |
156 | TColgp_Array1OfPnt P (1,NbPoints); |
157 | TColgp_Array1OfPnt2d P1(1,NbPoints); |
158 | TColgp_Array1OfPnt2d P2(1,NbPoints); |
159 | |
160 | Standard_Real Uf = ML.FirstParameter(); |
161 | Standard_Real Ul = ML.LastParameter(); |
51740958 |
162 | Standard_Real dUlf = (Ul-Uf)/(NbPoints-1); |
7fd59977 |
163 | AppDef_MultiPointConstraint MPC; |
164 | for ( i = 1; i<= NbPoints-1; i++) { |
165 | MPC = MLS.Value(i); |
51740958 |
166 | U = Uf + (i-1) * dUlf; |
7fd59977 |
167 | P (i) = MPC.Point(1); |
168 | P1(i) = MPC.Point2d(2); |
169 | P2(i) = MPC.Point2d(3); |
170 | Knots(i) = U; |
171 | } |
172 | // eval the last point on Ul |
173 | MPC = MLS.Value(NbPoints); |
174 | P (NbPoints) = MPC.Point(1); |
175 | P1(NbPoints) = MPC.Point2d(2); |
176 | P2(NbPoints) = MPC.Point2d(3); |
177 | Knots(NbPoints) = Ul; |
178 | |
179 | myCurve = new Geom_BSplineCurve ( P , Knots, Mults, 1); |
180 | myPCurve1 = new Geom2d_BSplineCurve( P1, Knots, Mults, 1); |
181 | myPCurve2 = new Geom2d_BSplineCurve( P2, Knots, Mults, 1); |
182 | |
183 | myIsDone = Standard_True; |
184 | |
185 | return; |
186 | } |
187 | |
188 | // Les approx sont a priori OK. |
189 | |
190 | const AppParCurves_MultiBSpCurve& MBSp = |
191 | Fit.SplineValue(); |
192 | Standard_Integer NbPoles = MBSp.NbPoles(); |
193 | TColgp_Array1OfPnt Poles (1 , NbPoles); |
194 | TColgp_Array1OfPnt2d Poles2d1(1 , NbPoles); |
195 | TColgp_Array1OfPnt2d Poles2d2(1 , NbPoles); |
196 | |
197 | MBSp.Curve(1, Poles); |
198 | MBSp.Curve(2, Poles2d1); |
199 | MBSp.Curve(3, Poles2d2); |
200 | |
201 | const TColStd_Array1OfReal& Knots = MBSp.Knots(); |
202 | const TColStd_Array1OfInteger& Mults = MBSp.Multiplicities(); |
203 | Standard_Integer Degree = MBSp.Degree(); |
204 | |
205 | myCurve = new Geom_BSplineCurve (Poles, Knots,Mults,Degree); |
206 | myPCurve1 = new Geom2d_BSplineCurve(Poles2d1,Knots,Mults,Degree); |
207 | myPCurve2 = new Geom2d_BSplineCurve(Poles2d2,Knots,Mults,Degree); |
208 | |
209 | myIsDone = Standard_True; |
210 | } |
211 | |
212 | |
213 | //======================================================================= |
214 | //function : IsDone |
215 | //purpose : |
216 | //======================================================================= |
217 | |
218 | Standard_Boolean BRepFill_ApproxSeewing::IsDone() const |
219 | { |
220 | return myIsDone; |
221 | } |
222 | |
223 | |
224 | //======================================================================= |
857ffd5e |
225 | //function : Handle(Geom_Curve)& |
7fd59977 |
226 | //purpose : |
227 | //======================================================================= |
228 | |
229 | const Handle(Geom_Curve)& BRepFill_ApproxSeewing::Curve() const |
230 | { |
231 | StdFail_NotDone_Raise_if( !myIsDone, |
232 | "BRepFill_ApproxSeewing::Curve"); |
233 | return myCurve; |
234 | } |
235 | |
236 | |
237 | //======================================================================= |
857ffd5e |
238 | //function : Handle(Geom2d_Curve)& |
7fd59977 |
239 | //purpose : |
240 | //======================================================================= |
241 | |
242 | const Handle(Geom2d_Curve)& BRepFill_ApproxSeewing::CurveOnF1() const |
243 | { |
244 | StdFail_NotDone_Raise_if( !myIsDone, |
245 | "BRepFill_ApproxSeewing::CurveOnF1"); |
246 | return myPCurve1; |
247 | } |
248 | |
249 | |
250 | //======================================================================= |
857ffd5e |
251 | //function : Handle(Geom2d_Curve)& |
7fd59977 |
252 | //purpose : |
253 | //======================================================================= |
254 | |
255 | const Handle(Geom2d_Curve)& BRepFill_ApproxSeewing::CurveOnF2() const |
256 | { |
257 | StdFail_NotDone_Raise_if( !myIsDone, |
258 | "BRepFill_ApproxSeewing::CurveOnF2"); |
259 | return myPCurve2; |
260 | } |
261 | |
262 | |