b311480e |
1 | // Created on: 1995-09-22 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1995-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | |
23 | #include <BRepFill_ApproxSeewing.ixx> |
24 | |
25 | #include <AppParCurves_MultiCurve.hxx> |
26 | #include <AppDef_Compute.hxx> |
27 | #include <AppDef_MultiLine.hxx> |
28 | #include <AppDef_MultiPointConstraint.hxx> |
29 | #include <BSplCLib.hxx> |
30 | #include <PLib.hxx> |
31 | #include <Geom_BSplineCurve.hxx> |
32 | #include <Geom2d_BSplineCurve.hxx> |
33 | #include <TColgp_Array1OfPnt.hxx> |
34 | #include <TColgp_Array1OfPnt2d.hxx> |
35 | #include <TColStd_Array1OfReal.hxx> |
36 | #include <TColStd_Array1OfInteger.hxx> |
37 | |
38 | |
39 | //======================================================================= |
40 | //function : BRepFill_ApproxSeewing |
41 | //purpose : |
42 | //======================================================================= |
43 | |
44 | BRepFill_ApproxSeewing::BRepFill_ApproxSeewing() |
45 | :myIsDone(Standard_False) |
46 | { |
47 | } |
48 | |
49 | |
50 | //======================================================================= |
51 | //function : BRepFill_ApproxSeewing |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | BRepFill_ApproxSeewing::BRepFill_ApproxSeewing(const BRepFill_MultiLine& ML) |
56 | :myIsDone(Standard_False) |
57 | { |
58 | Perform(ML); |
59 | } |
60 | |
61 | |
62 | //======================================================================= |
63 | //function : Perform |
64 | //purpose : |
65 | //======================================================================= |
66 | |
67 | void BRepFill_ApproxSeewing::Perform(const BRepFill_MultiLine& ML) |
68 | { |
69 | myML = ML; |
70 | |
71 | // evaluate the approximative length of the 3dCurve |
72 | Standard_Integer i; |
73 | Standard_Real Length = 0.; |
74 | Standard_Real U1 = myML.FirstParameter(); |
75 | Standard_Real U2 = myML.LastParameter(); |
76 | Standard_Integer NbPoints = 50; |
77 | Standard_Real Dist, dU = (U2 - U1) / ( 2*NbPoints - 1); |
78 | |
79 | TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param |
80 | gp_Pnt P1, P2; |
81 | P1 = myML.Value(U1); |
82 | |
83 | for ( i = 0; i < 2*NbPoints ; i++) { |
84 | P2 = myML.Value(U1 + i*dU); |
85 | Dist = P1.Distance(P2); |
86 | Length += Dist; |
87 | LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU)); |
88 | P1 = P2; |
89 | } |
90 | |
91 | // On cherche a mettre NbPoints dans la curve. |
92 | // on met les points environ a Length/NbPoints. |
93 | |
94 | AppDef_MultiLine MLS ( NbPoints); |
95 | AppDef_MultiPointConstraint MP ( 1, 2); |
96 | gp_Pnt P3d; |
97 | gp_Pnt2d PF1,PF2; |
98 | |
99 | ML.Value3dOnF1OnF2(U1,P3d,PF1,PF2); |
100 | MP.SetPoint (1, P3d); |
101 | MP.SetPoint2d(2, PF1); |
102 | MP.SetPoint2d(3, PF2); |
103 | MLS.SetValue (1, MP); |
104 | |
105 | Standard_Real DCorde = Length / ( NbPoints - 1); |
106 | Standard_Real Corde = DCorde; |
107 | Standard_Integer Index = 1; |
108 | Standard_Real U, Alpha; |
109 | for ( i = 2; i < NbPoints; i++) { |
110 | while ( LP(Index).X() < Corde) Index ++; |
111 | Alpha = (Corde - LP(Index-1).X()) / (LP(Index).X() - LP(Index-1).X()); |
112 | U = LP(Index-1).Y() + Alpha * ( LP(Index).Y() - LP(Index-1).Y()); |
113 | AppDef_MultiPointConstraint MPC( 1, 2); |
114 | ML.Value3dOnF1OnF2(U,P3d,PF1,PF2); |
115 | MPC.SetPoint (1, P3d); |
116 | MPC.SetPoint2d(2, PF1); |
117 | MPC.SetPoint2d(3, PF2); |
118 | MLS.SetValue (i, MPC); |
119 | Corde = i*DCorde; |
120 | } |
121 | AppDef_MultiPointConstraint MPE( 1, 2); |
122 | ML.Value3dOnF1OnF2(U2,P3d,PF1,PF2); |
123 | MPE.SetPoint (1, P3d); |
124 | MPE.SetPoint2d(2, PF1); |
125 | MPE.SetPoint2d(3, PF2); |
126 | MLS.SetValue (NbPoints, MPE); |
127 | |
128 | AppDef_Compute Fit(MLS); |
129 | |
130 | Standard_Integer NbCurves = Fit.NbMultiCurves(); |
131 | // Standard_Integer MaxDeg = 0; |
132 | |
133 | if ( NbCurves == 0) { |
134 | #ifdef DEBUG_EVOLVED |
135 | cout << " TrimSurfaceTool : Approx echoue, on met les polygones" << endl; |
136 | #endif |
137 | |
138 | TColStd_Array1OfReal Knots(1,NbPoints); |
139 | TColStd_Array1OfInteger Mults(1,NbPoints); |
140 | Mults.Init(1); |
141 | Mults(1) = Mults(NbPoints) = 2; |
142 | TColgp_Array1OfPnt P (1,NbPoints); |
143 | TColgp_Array1OfPnt2d P1(1,NbPoints); |
144 | TColgp_Array1OfPnt2d P2(1,NbPoints); |
145 | |
146 | Standard_Real Uf = ML.FirstParameter(); |
147 | Standard_Real Ul = ML.LastParameter(); |
148 | Standard_Real dU = (Ul-Uf)/(NbPoints-1); |
149 | AppDef_MultiPointConstraint MPC; |
150 | for ( i = 1; i<= NbPoints-1; i++) { |
151 | MPC = MLS.Value(i); |
152 | U = Uf + (i-1) * dU; |
153 | P (i) = MPC.Point(1); |
154 | P1(i) = MPC.Point2d(2); |
155 | P2(i) = MPC.Point2d(3); |
156 | Knots(i) = U; |
157 | } |
158 | // eval the last point on Ul |
159 | MPC = MLS.Value(NbPoints); |
160 | P (NbPoints) = MPC.Point(1); |
161 | P1(NbPoints) = MPC.Point2d(2); |
162 | P2(NbPoints) = MPC.Point2d(3); |
163 | Knots(NbPoints) = Ul; |
164 | |
165 | myCurve = new Geom_BSplineCurve ( P , Knots, Mults, 1); |
166 | myPCurve1 = new Geom2d_BSplineCurve( P1, Knots, Mults, 1); |
167 | myPCurve2 = new Geom2d_BSplineCurve( P2, Knots, Mults, 1); |
168 | |
169 | myIsDone = Standard_True; |
170 | |
171 | return; |
172 | } |
173 | |
174 | // Les approx sont a priori OK. |
175 | |
176 | const AppParCurves_MultiBSpCurve& MBSp = |
177 | Fit.SplineValue(); |
178 | Standard_Integer NbPoles = MBSp.NbPoles(); |
179 | TColgp_Array1OfPnt Poles (1 , NbPoles); |
180 | TColgp_Array1OfPnt2d Poles2d1(1 , NbPoles); |
181 | TColgp_Array1OfPnt2d Poles2d2(1 , NbPoles); |
182 | |
183 | MBSp.Curve(1, Poles); |
184 | MBSp.Curve(2, Poles2d1); |
185 | MBSp.Curve(3, Poles2d2); |
186 | |
187 | const TColStd_Array1OfReal& Knots = MBSp.Knots(); |
188 | const TColStd_Array1OfInteger& Mults = MBSp.Multiplicities(); |
189 | Standard_Integer Degree = MBSp.Degree(); |
190 | |
191 | myCurve = new Geom_BSplineCurve (Poles, Knots,Mults,Degree); |
192 | myPCurve1 = new Geom2d_BSplineCurve(Poles2d1,Knots,Mults,Degree); |
193 | myPCurve2 = new Geom2d_BSplineCurve(Poles2d2,Knots,Mults,Degree); |
194 | |
195 | myIsDone = Standard_True; |
196 | } |
197 | |
198 | |
199 | //======================================================================= |
200 | //function : IsDone |
201 | //purpose : |
202 | //======================================================================= |
203 | |
204 | Standard_Boolean BRepFill_ApproxSeewing::IsDone() const |
205 | { |
206 | return myIsDone; |
207 | } |
208 | |
209 | |
210 | //======================================================================= |
211 | //function : Handle_Geom_Curve& |
212 | //purpose : |
213 | //======================================================================= |
214 | |
215 | const Handle(Geom_Curve)& BRepFill_ApproxSeewing::Curve() const |
216 | { |
217 | StdFail_NotDone_Raise_if( !myIsDone, |
218 | "BRepFill_ApproxSeewing::Curve"); |
219 | return myCurve; |
220 | } |
221 | |
222 | |
223 | //======================================================================= |
224 | //function : Handle_Geom2d_Curve& |
225 | //purpose : |
226 | //======================================================================= |
227 | |
228 | const Handle(Geom2d_Curve)& BRepFill_ApproxSeewing::CurveOnF1() const |
229 | { |
230 | StdFail_NotDone_Raise_if( !myIsDone, |
231 | "BRepFill_ApproxSeewing::CurveOnF1"); |
232 | return myPCurve1; |
233 | } |
234 | |
235 | |
236 | //======================================================================= |
237 | //function : Handle_Geom2d_Curve& |
238 | //purpose : |
239 | //======================================================================= |
240 | |
241 | const Handle(Geom2d_Curve)& BRepFill_ApproxSeewing::CurveOnF2() const |
242 | { |
243 | StdFail_NotDone_Raise_if( !myIsDone, |
244 | "BRepFill_ApproxSeewing::CurveOnF2"); |
245 | return myPCurve2; |
246 | } |
247 | |
248 | |