b311480e |
1 | // Created on: 1997-11-21 |
2 | // Created by: Philippe MANGIN |
3 | // Copyright (c) 1997-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 | |
0797d9d3 |
17 | #ifndef OCCT_DEBUG |
7fd59977 |
18 | #define No_Standard_RangeError |
19 | #define No_Standard_OutOfRange |
20 | #define No_Standard_DimensionError |
21 | #endif |
22 | |
23 | |
42cf5bc1 |
24 | #include <GeomFill_LocationLaw.hxx> |
25 | #include <GeomFill_SectionLaw.hxx> |
26 | #include <GeomFill_SweepFunction.hxx> |
7fd59977 |
27 | #include <GeomLib.hxx> |
42cf5bc1 |
28 | #include <gp_Pnt.hxx> |
7fd59977 |
29 | #include <Precision.hxx> |
42cf5bc1 |
30 | #include <Standard_OutOfRange.hxx> |
31 | #include <Standard_Type.hxx> |
32 | #include <TColStd_SequenceOfReal.hxx> |
7fd59977 |
33 | |
92efcf78 |
34 | IMPLEMENT_STANDARD_RTTIEXT(GeomFill_SweepFunction,Approx_SweepFunction) |
35 | |
7fd59977 |
36 | //======================================================================= |
37 | //function : GeomFill_SweepFunction |
38 | //purpose : |
39 | //======================================================================= |
40 | GeomFill_SweepFunction:: |
41 | GeomFill_SweepFunction(const Handle(GeomFill_SectionLaw)& Section, |
42 | const Handle(GeomFill_LocationLaw)& Location, |
43 | const Standard_Real FirstParameter, |
44 | const Standard_Real FirstParameterOnS, |
45 | const Standard_Real RatioParameterOnS) |
46 | { |
47 | myLoc = Location; |
48 | mySec = Section; |
49 | myf = FirstParameter; |
50 | myfOnS = FirstParameterOnS; |
51 | myRatio = RatioParameterOnS; |
52 | } |
53 | |
54 | //======================================================================= |
55 | //function : D0 |
56 | //purpose : |
57 | //======================================================================= |
58 | Standard_Boolean GeomFill_SweepFunction::D0(const Standard_Real Param, |
59 | const Standard_Real, |
60 | const Standard_Real, |
61 | TColgp_Array1OfPnt& Poles, |
62 | TColgp_Array1OfPnt2d& Poles2d, |
63 | TColStd_Array1OfReal& Weigths) |
64 | { |
65 | Standard_Integer ii, L; |
66 | Standard_Boolean Ok; |
67 | Standard_Real T = myfOnS + (Param - myf) * myRatio; |
68 | L = Poles.Length(); |
69 | |
70 | Ok = myLoc->D0(Param, M, V, Poles2d); |
71 | if (!Ok) return Ok; |
72 | Ok = mySec->D0(T, Poles, Weigths); |
73 | if (!Ok) return Ok; |
74 | |
75 | for (ii=1; ii<=L; ii++) { |
76 | gp_XYZ& aux = Poles(ii).ChangeCoord(); |
77 | aux *= M; |
78 | aux += V.XYZ(); |
79 | } |
80 | return Standard_True; |
81 | } |
82 | |
83 | //======================================================================= |
84 | //function : D1 |
85 | //purpose : |
86 | //======================================================================= |
87 | Standard_Boolean GeomFill_SweepFunction::D1(const Standard_Real Param, |
88 | const Standard_Real, |
89 | const Standard_Real, |
90 | TColgp_Array1OfPnt& Poles, |
91 | TColgp_Array1OfVec& DPoles, |
92 | TColgp_Array1OfPnt2d& Poles2d, |
93 | TColgp_Array1OfVec2d& DPoles2d, |
94 | TColStd_Array1OfReal& Weigths, |
95 | TColStd_Array1OfReal& DWeigths) |
96 | { |
97 | Standard_Integer ii, L; |
98 | Standard_Boolean Ok; |
99 | Standard_Real T = myfOnS + (Param - myf) * myRatio; |
100 | gp_XYZ PPrim; |
101 | L = Poles.Length(); |
102 | |
103 | Ok = myLoc->D1(Param, M, V, DM, DV, Poles2d, DPoles2d); |
104 | if (!Ok) return Ok; |
105 | Ok = mySec->D1(T, Poles, DPoles, Weigths, DWeigths); |
106 | if (!Ok) return Ok; |
107 | |
108 | for (ii=1; ii<=L; ii++) { |
109 | PPrim = DPoles(ii).XYZ(); |
110 | gp_XYZ& P = Poles(ii).ChangeCoord(); |
111 | PPrim *= myRatio; |
112 | DWeigths(ii) *= myRatio; |
113 | PPrim *= M; |
114 | PPrim += DM*P; |
115 | PPrim += DV.XYZ(); |
116 | DPoles(ii).SetXYZ(PPrim); |
117 | |
118 | P *= M; |
119 | P += V.XYZ(); |
120 | } |
121 | return Standard_True; |
122 | } |
123 | |
124 | //======================================================================= |
125 | //function : D2 |
126 | //purpose : |
127 | //======================================================================= |
128 | Standard_Boolean GeomFill_SweepFunction::D2(const Standard_Real Param, |
129 | const Standard_Real, |
130 | const Standard_Real , |
131 | TColgp_Array1OfPnt& Poles, |
132 | TColgp_Array1OfVec& DPoles, |
133 | TColgp_Array1OfVec& D2Poles, |
134 | TColgp_Array1OfPnt2d& Poles2d, |
135 | TColgp_Array1OfVec2d& DPoles2d, |
136 | TColgp_Array1OfVec2d& D2Poles2d, |
137 | TColStd_Array1OfReal& Weigths, |
138 | TColStd_Array1OfReal& DWeigths, |
139 | TColStd_Array1OfReal& D2Weigths) |
140 | { |
141 | Standard_Integer ii, L; |
142 | Standard_Boolean Ok; |
143 | Standard_Real T = myfOnS + (Param - myf) * myRatio; |
144 | Standard_Real squareratio = myRatio*myRatio; |
145 | L = Poles.Length(); |
146 | |
147 | Ok = myLoc->D2(Param, M, V, DM, DV, D2M, D2V, |
148 | Poles2d, DPoles2d, D2Poles2d); |
149 | if (!Ok) return Ok; |
150 | Ok = mySec->D2(T, Poles, DPoles, D2Poles, |
151 | Weigths, DWeigths, D2Weigths); |
152 | if (!Ok) return Ok; |
153 | |
154 | for (ii=1; ii<=L; ii++) { |
155 | gp_XYZ PSecn = D2Poles(ii).XYZ(); |
156 | gp_XYZ PPrim = DPoles(ii).XYZ(); |
157 | PPrim *= myRatio; |
158 | DWeigths(ii) *= myRatio; |
159 | PSecn *= squareratio; |
160 | D2Weigths(ii) *= squareratio; |
161 | gp_XYZ& P = Poles(ii).ChangeCoord(); |
162 | |
163 | PSecn *= M; |
164 | PSecn += 2*(DM*PPrim); |
165 | PSecn += D2M*P; |
166 | PSecn += D2V.XYZ(); |
167 | D2Poles(ii).SetXYZ(PSecn); |
168 | |
169 | PPrim *= M; |
170 | PPrim += DM*P; |
171 | PPrim += DV.XYZ(); |
172 | DPoles(ii).SetXYZ(PPrim); |
173 | |
174 | P *= M; |
175 | P += V.XYZ(); |
176 | } |
177 | return Standard_True; |
178 | } |
179 | |
180 | //======================================================================= |
181 | //function : Nb2dCurves |
182 | //purpose : |
183 | //======================================================================= |
184 | Standard_Integer GeomFill_SweepFunction::Nb2dCurves() const |
185 | { |
186 | return myLoc->Nb2dCurves(); |
187 | } |
188 | |
189 | //======================================================================= |
190 | //function : SectionShape |
191 | //purpose : |
192 | //======================================================================= |
193 | void GeomFill_SweepFunction::SectionShape(Standard_Integer& NbPoles, |
194 | Standard_Integer& NbKnots, |
195 | Standard_Integer& Degree) const |
196 | { |
197 | mySec->SectionShape(NbPoles, NbKnots, Degree); |
198 | } |
199 | |
200 | //======================================================================= |
201 | //function : Knots |
202 | //purpose : |
203 | //======================================================================= |
204 | void GeomFill_SweepFunction::Knots(TColStd_Array1OfReal& TKnots) const |
205 | { |
206 | mySec->Knots(TKnots); |
207 | } |
208 | |
209 | //======================================================================= |
210 | //function : Mults |
211 | //purpose : |
212 | //======================================================================= |
213 | void GeomFill_SweepFunction::Mults(TColStd_Array1OfInteger& TMults) const |
214 | { |
215 | mySec->Mults(TMults); |
216 | } |
217 | |
218 | //======================================================================= |
219 | //function : IsRational |
220 | //purpose : |
221 | //======================================================================= |
222 | Standard_Boolean GeomFill_SweepFunction::IsRational() const |
223 | { |
224 | return mySec->IsRational(); |
225 | } |
226 | |
227 | //======================================================================= |
228 | //function : NbIntervals |
229 | //purpose : |
230 | //======================================================================= |
231 | Standard_Integer GeomFill_SweepFunction::NbIntervals(const GeomAbs_Shape S) const |
232 | { |
233 | Standard_Integer Nb_Sec, Nb_Loc; |
234 | Nb_Sec = mySec->NbIntervals(S); |
235 | Nb_Loc = myLoc->NbIntervals(S); |
236 | |
237 | if (Nb_Sec==1) { |
238 | return Nb_Loc; |
239 | } |
240 | else if (Nb_Loc==1) { |
241 | return Nb_Sec; |
242 | } |
243 | |
244 | TColStd_Array1OfReal IntS(1, Nb_Sec+1); |
245 | TColStd_Array1OfReal IntL(1, Nb_Loc+1); |
246 | TColStd_SequenceOfReal Inter; |
247 | Standard_Real T; |
248 | Standard_Integer ii; |
249 | mySec->Intervals(IntS, S); |
250 | for (ii=1; ii<=Nb_Sec+1; ii++) { |
251 | T = (IntS(ii) - myfOnS) / myRatio + myf; |
252 | IntS(ii) = T; |
253 | } |
254 | myLoc->Intervals(IntL, S); |
255 | |
256 | GeomLib::FuseIntervals( IntS, IntL, Inter, Precision::PConfusion()*0.99); |
257 | return Inter.Length()-1; |
258 | } |
259 | |
260 | //======================================================================= |
261 | //function : Intervals |
262 | //purpose : |
263 | //======================================================================= |
264 | void GeomFill_SweepFunction::Intervals(TColStd_Array1OfReal& T,const GeomAbs_Shape S) const |
265 | { |
266 | Standard_Integer Nb_Sec, Nb_Loc, ii; |
267 | Nb_Sec = mySec->NbIntervals(S); |
268 | Nb_Loc = myLoc->NbIntervals(S); |
269 | |
270 | if (Nb_Sec==1) { |
271 | myLoc->Intervals(T, S); |
272 | return; |
273 | } |
274 | else if (Nb_Loc==1) { |
275 | Standard_Real t; |
276 | mySec->Intervals(T, S); |
277 | for (ii=1; ii<=Nb_Sec+1; ii++) { |
278 | t = (T(ii) - myfOnS) / myRatio + myf; |
279 | T(ii) = t; |
280 | } |
281 | return; |
282 | } |
283 | |
284 | TColStd_Array1OfReal IntS(1, Nb_Sec+1); |
285 | TColStd_Array1OfReal IntL(1, Nb_Loc+1); |
286 | TColStd_SequenceOfReal Inter; |
287 | Standard_Real t; |
288 | |
289 | mySec->Intervals(IntS, S); |
290 | for (ii=1; ii<=Nb_Sec+1; ii++) { |
291 | t = (IntS(ii) - myfOnS) / myRatio + myf; |
292 | IntS(ii) = t; |
293 | } |
294 | myLoc->Intervals(IntL, S); |
295 | |
296 | GeomLib::FuseIntervals(IntS, IntL, Inter, Precision::PConfusion()*0.99); |
297 | for (ii=1; ii<=Inter.Length(); ii++) |
298 | T(ii) = Inter(ii); |
299 | } |
300 | |
301 | //======================================================================= |
302 | //function : SetInterval |
303 | //purpose : |
304 | //======================================================================= |
305 | void GeomFill_SweepFunction::SetInterval(const Standard_Real First, |
306 | const Standard_Real Last) |
307 | { |
308 | Standard_Real uf, ul; |
309 | myLoc->SetInterval(First, Last); |
310 | uf = myf + (First - myf) * myRatio; |
311 | ul = myf + (Last - myf) * myRatio; |
312 | mySec->SetInterval(uf, ul); |
313 | } |
314 | |
315 | //======================================================================= |
316 | //function : |
317 | //purpose : |
318 | //======================================================================= |
319 | void GeomFill_SweepFunction::GetTolerance(const Standard_Real BoundTol, |
320 | const Standard_Real SurfTol, |
321 | const Standard_Real AngleTol, |
322 | TColStd_Array1OfReal& Tol3d) const |
323 | { |
324 | mySec->GetTolerance( BoundTol, SurfTol, AngleTol, Tol3d); |
325 | } |
326 | |
327 | |
328 | //======================================================================= |
329 | //function : Resolution |
330 | //purpose : |
331 | //======================================================================= |
332 | void GeomFill_SweepFunction::Resolution(const Standard_Integer Index, |
333 | const Standard_Real Tol, |
334 | Standard_Real& TolU, |
335 | Standard_Real& TolV)const |
336 | { |
337 | myLoc->Resolution(Index, Tol, TolU, TolV); |
338 | } |
339 | |
340 | //======================================================================= |
341 | //function : |
342 | //purpose : |
343 | //======================================================================= |
344 | void GeomFill_SweepFunction::SetTolerance(const Standard_Real Tol3d, |
345 | const Standard_Real Tol2d) |
346 | { |
347 | mySec->SetTolerance(Tol3d, Tol2d); |
348 | myLoc->SetTolerance(Tol3d, Tol2d); |
349 | } |
350 | |
351 | //======================================================================= |
352 | //function : |
353 | //purpose : |
354 | //======================================================================= |
355 | gp_Pnt GeomFill_SweepFunction::BarycentreOfSurf() const |
356 | { |
357 | gp_Pnt Bary; |
358 | gp_Vec Translate; |
75259fc5 |
359 | gp_Mat aM; |
7fd59977 |
360 | |
361 | Bary = mySec->BarycentreOfSurf(); |
75259fc5 |
362 | myLoc->GetAverageLaw(aM, Translate); |
363 | Bary.ChangeCoord() *= aM; |
7fd59977 |
364 | Bary.ChangeCoord() += Translate.XYZ(); |
365 | |
366 | return Bary; |
367 | } |
368 | |
369 | //======================================================================= |
370 | //function : |
371 | //purpose : |
372 | //======================================================================= |
373 | Standard_Real GeomFill_SweepFunction::MaximalSection() const |
374 | { |
375 | Standard_Real L = mySec->MaximalSection(); |
376 | L *= myLoc->GetMaximalNorm(); |
377 | return L; |
378 | } |
379 | |
380 | //======================================================================= |
381 | //function : |
382 | //purpose : |
383 | //======================================================================= |
384 | void GeomFill_SweepFunction::GetMinimalWeight(TColStd_Array1OfReal& Weigths) const |
385 | { |
386 | mySec->GetMinimalWeight(Weigths); |
387 | } |
388 | |
389 | |
390 | |
391 | |
392 | |
393 | |
394 | |
395 | |
396 | |
397 | |
398 | |
399 | |
400 | |