7fd59977 |
1 | // File: BlendFunc_Chamfer.cxx |
2 | // Created: Wed Jun 5 09:41:42 1996 |
3 | // Author: Stagiaire Xuan Trang PHAMPHU |
4 | // Copyright: OPEN CASCADE 1996 |
5 | |
6 | // Modified : 20/08/96 PMN Ajout des methodes (Nb)Intervals et IsRationnal |
7 | // Modified : 30/12/96 PMN Ajout GetMinimalWeight, GetSectionSize; |
8 | |
9 | #include <BlendFunc_Chamfer.ixx> |
10 | |
11 | #include <BlendFunc.hxx> |
12 | #include <ElCLib.hxx> |
13 | #include <Precision.hxx> |
14 | #include <Standard_NotImplemented.hxx> |
15 | #ifdef DEB |
16 | static Standard_Boolean putsderivatives = 0; |
17 | #endif |
18 | |
19 | //======================================================================= |
20 | //function : BlendFunc_Chamfer |
21 | //purpose : |
22 | //======================================================================= |
23 | |
24 | BlendFunc_Chamfer::BlendFunc_Chamfer(const Handle(Adaptor3d_HSurface)& S1, |
25 | const Handle(Adaptor3d_HSurface)& S2, |
26 | const Handle(Adaptor3d_HCurve)& CG) : |
27 | surf1(S1),surf2(S2), |
28 | curv(CG), |
29 | distmin(RealLast()), |
30 | corde1(S1,CG),corde2(S2,CG) |
31 | { |
32 | } |
33 | |
34 | //======================================================================= |
35 | //function : NbEquations |
36 | //purpose : |
37 | //======================================================================= |
38 | |
39 | Standard_Integer BlendFunc_Chamfer::NbEquations () const |
40 | { |
41 | return 4; |
42 | } |
43 | |
44 | |
45 | //======================================================================= |
46 | //function : Set |
47 | //purpose : |
48 | //======================================================================= |
49 | |
50 | void BlendFunc_Chamfer::Set(const Standard_Real Dist1, const Standard_Real Dist2, |
51 | const Standard_Integer Choix) |
52 | { |
53 | corde1.SetDist(Dist1); |
54 | corde2.SetDist(Dist2); |
55 | choix = Choix; |
56 | } |
57 | |
58 | //======================================================================= |
59 | //function : Set |
60 | //purpose : |
61 | //======================================================================= |
62 | |
63 | void BlendFunc_Chamfer::Set(const Standard_Real Param) |
64 | { |
65 | corde1.SetParam(Param); |
66 | corde2.SetParam(Param); |
67 | } |
68 | |
69 | //======================================================================= |
70 | //function : Set |
71 | //purpose : |
72 | //======================================================================= |
73 | |
74 | void BlendFunc_Chamfer::Set(const Standard_Real First, const Standard_Real Last) |
75 | { |
76 | // corde1.SetParam(First, Last); |
77 | // corde2.SetParam(First, Last); |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : GetTolerance |
82 | //purpose : |
83 | //======================================================================= |
84 | |
85 | void BlendFunc_Chamfer::GetTolerance(math_Vector& Tolerance, const Standard_Real Tol) const |
86 | { |
87 | Tolerance(1) = surf1->UResolution(Tol); |
88 | Tolerance(2) = surf1->VResolution(Tol); |
89 | Tolerance(3) = surf2->UResolution(Tol); |
90 | Tolerance(4) = surf2->VResolution(Tol); |
91 | } |
92 | |
93 | //======================================================================= |
94 | //function : GetBounds |
95 | //purpose : |
96 | //======================================================================= |
97 | |
98 | void BlendFunc_Chamfer::GetBounds(math_Vector& InfBound, math_Vector& SupBound) const |
99 | { |
100 | InfBound(1) = surf1->FirstUParameter(); |
101 | InfBound(2) = surf1->FirstVParameter(); |
102 | InfBound(3) = surf2->FirstUParameter(); |
103 | InfBound(4) = surf2->FirstVParameter(); |
104 | SupBound(1) = surf1->LastUParameter(); |
105 | SupBound(2) = surf1->LastVParameter(); |
106 | SupBound(3) = surf2->LastUParameter(); |
107 | SupBound(4) = surf2->LastVParameter(); |
108 | |
109 | for(Standard_Integer i = 1; i <= 4; i++){ |
110 | if(!Precision::IsInfinite(InfBound(i)) && |
111 | !Precision::IsInfinite(SupBound(i))) { |
112 | const Standard_Real range = (SupBound(i) - InfBound(i)); |
113 | InfBound(i) -= range; |
114 | SupBound(i) += range; |
115 | } |
116 | } |
117 | } |
118 | |
119 | //======================================================================= |
120 | //function : IsSolution |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | Standard_Boolean BlendFunc_Chamfer::IsSolution(const math_Vector& Sol, const Standard_Real Tol) |
125 | { |
126 | math_Vector Sol1(1,2), Sol2(1,2); |
127 | |
128 | Sol1(1) = Sol(1); |
129 | Sol1(2) = Sol(2); |
130 | Sol2(1) = Sol(3); |
131 | Sol2(2) = Sol(4); |
132 | |
133 | Standard_Boolean issol = corde1.IsSolution(Sol1,Tol); |
134 | issol = issol && corde2.IsSolution(Sol2,Tol); |
135 | tol = Tol; |
136 | if (issol) |
137 | distmin = Min (distmin, corde1.PointOnS().Distance(corde2.PointOnS())); |
138 | |
139 | return issol; |
140 | } |
141 | |
142 | //======================================================================= |
143 | //function : GetMinimalDistance |
144 | //purpose : |
145 | //======================================================================= |
146 | |
147 | Standard_Real BlendFunc_Chamfer::GetMinimalDistance() const |
148 | { |
149 | return distmin; |
150 | } |
151 | |
152 | //======================================================================= |
153 | //function : Value |
154 | //purpose : |
155 | //======================================================================= |
156 | |
157 | Standard_Boolean BlendFunc_Chamfer::Value(const math_Vector& X, math_Vector& F) |
158 | { |
159 | math_Vector x(1,2), f(1,2); |
160 | |
161 | x(1) = X(1); x(2) = X(2); |
162 | corde1.Value(x,f); |
163 | F(1) = f(1); F(2) = f(2); |
164 | |
165 | x(1) = X(3); x(2) = X(4); |
166 | corde2.Value(x,f); |
167 | F(3) = f(1); F(4) = f(2); |
168 | |
169 | return Standard_True; |
170 | } |
171 | |
172 | |
173 | //======================================================================= |
174 | //function : Derivatives |
175 | //purpose : |
176 | //======================================================================= |
177 | |
178 | Standard_Boolean BlendFunc_Chamfer::Derivatives(const math_Vector& X, math_Matrix& D) |
179 | { |
180 | Standard_Integer i,j; |
181 | math_Vector x(1,2); |
182 | math_Matrix d(1,2,1,2); |
183 | |
184 | x(1) = X(1); x(2) = X(2); |
185 | corde1.Derivatives(x,d); |
186 | for( i=1; i<3; i++ ){ |
187 | for( j=1; j<3; j++ ){ |
188 | D(i,j) = d(i,j); |
189 | D(i,j+2) = 0.; |
190 | } |
191 | } |
192 | |
193 | x(1) = X(3); x(2) = X(4); |
194 | corde2.Derivatives(x,d); |
195 | for( i=1; i<3; i++ ){ |
196 | for( j=1; j<3; j++ ){ |
197 | D(i+2,j+2) = d(i,j); |
198 | D(i+2,j) = 0.; |
199 | } |
200 | } |
201 | |
202 | return Standard_True; |
203 | } |
204 | |
205 | //======================================================================= |
206 | //function : Values |
207 | //purpose : |
208 | //======================================================================= |
209 | |
210 | Standard_Boolean BlendFunc_Chamfer::Values(const math_Vector& X, math_Vector& F, math_Matrix& D) |
211 | { |
212 | Standard_Boolean val = Value(X,F); |
213 | return (val && Derivatives(X,D)); |
214 | } |
215 | |
216 | //======================================================================= |
217 | //function : PointOnS1 |
218 | //purpose : |
219 | //======================================================================= |
220 | |
221 | const gp_Pnt& BlendFunc_Chamfer::PointOnS1 () const |
222 | { |
223 | return corde1.PointOnS(); |
224 | } |
225 | |
226 | //======================================================================= |
227 | //function : PointOnS2 |
228 | //purpose : |
229 | //======================================================================= |
230 | |
231 | const gp_Pnt& BlendFunc_Chamfer::PointOnS2 () const |
232 | { |
233 | return corde2.PointOnS(); |
234 | } |
235 | |
236 | |
237 | //======================================================================= |
238 | //function : IsTangencyPoint |
239 | //purpose : |
240 | //======================================================================= |
241 | |
242 | Standard_Boolean BlendFunc_Chamfer::IsTangencyPoint () const |
243 | { |
244 | return corde1.IsTangencyPoint() && corde2.IsTangencyPoint(); |
245 | } |
246 | |
247 | //======================================================================= |
248 | //function : TangentOnS1 |
249 | //purpose : |
250 | //======================================================================= |
251 | |
252 | const gp_Vec& BlendFunc_Chamfer::TangentOnS1 () const |
253 | { |
254 | return corde1.TangentOnS(); |
255 | } |
256 | |
257 | //======================================================================= |
258 | //function : TangentOnS2 |
259 | //purpose : |
260 | //======================================================================= |
261 | |
262 | const gp_Vec& BlendFunc_Chamfer::TangentOnS2 () const |
263 | { |
264 | return corde2.TangentOnS(); |
265 | } |
266 | |
267 | //======================================================================= |
268 | //function : Tangent2dOnS1 |
269 | //purpose : |
270 | //======================================================================= |
271 | |
272 | const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS1 () const |
273 | { |
274 | return corde1.Tangent2dOnS(); |
275 | } |
276 | |
277 | //======================================================================= |
278 | //function : Tangent2dOnS2 |
279 | //purpose : |
280 | //======================================================================= |
281 | |
282 | const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS2 () const |
283 | { |
284 | return corde2.Tangent2dOnS(); |
285 | } |
286 | |
287 | //======================================================================= |
288 | //function : Tangent |
289 | //purpose : TgF,NmF et TgL,NmL les tangentes et normales respectives |
290 | // aux surfaces S1 et S2 |
291 | //======================================================================= |
292 | |
293 | void BlendFunc_Chamfer::Tangent(const Standard_Real U1, |
294 | const Standard_Real V1, |
295 | const Standard_Real U2, |
296 | const Standard_Real V2, |
297 | gp_Vec& TgF, |
298 | gp_Vec& TgL, |
299 | gp_Vec& NmF, |
300 | gp_Vec& NmL) const |
301 | { |
302 | gp_Pnt pt1,pt2,ptgui; |
303 | gp_Vec d1u1,d1v1,d1u2,d1v2; |
304 | gp_Vec nplan; |
305 | Standard_Boolean revF = Standard_False; |
306 | Standard_Boolean revL = Standard_False; |
307 | |
308 | ptgui = corde1.PointOnGuide(); |
309 | nplan = corde1.NPlan(); |
310 | surf1->D1(U1,V1,pt1,d1u1,d1v1); |
311 | NmF = d1u1.Crossed(d1v1); |
312 | |
313 | surf2->D1(U2,V2,pt2,d1u2,d1v2); |
314 | NmL = d1u2.Crossed(d1v2); |
315 | |
316 | TgF = (nplan.Crossed(NmF)).Normalized(); |
317 | TgL = (nplan.Crossed(NmL)).Normalized(); |
318 | |
319 | if( (choix == 2)||(choix == 5) ){ |
320 | revF = Standard_True; |
321 | revL = Standard_True; |
322 | } |
323 | if( (choix == 4)||(choix == 7) ) |
324 | revL = Standard_True; |
325 | if( (choix == 3)||(choix == 8) ) |
326 | revF = Standard_True; |
327 | |
328 | if( revF ) |
329 | TgF.Reverse(); |
330 | if( revL ) |
331 | TgL.Reverse(); |
332 | } |
333 | |
334 | //======================================================================= |
335 | //function : Section |
336 | //purpose : |
337 | //======================================================================= |
338 | |
339 | void BlendFunc_Chamfer::Section(const Standard_Real Param, |
340 | const Standard_Real U1, |
341 | const Standard_Real V1, |
342 | const Standard_Real U2, |
343 | const Standard_Real V2, |
344 | Standard_Real& Pdeb, |
345 | Standard_Real& Pfin, |
346 | gp_Lin& C) |
347 | { |
348 | const gp_Pnt pts1 = surf1->Value(U1,V1); |
349 | const gp_Pnt pts2 = surf2->Value(U2,V2); |
350 | const gp_Dir dir( gp_Vec(pts1,pts2) ); |
351 | |
352 | C.SetLocation(pts1); |
353 | C.SetDirection(dir); |
354 | |
355 | Pdeb = 0.; |
356 | Pfin = ElCLib::Parameter(C,pts2); |
357 | } |
358 | |
359 | //======================================================================= |
360 | //function : IsRational |
361 | //purpose : |
362 | //======================================================================= |
363 | |
364 | Standard_Boolean BlendFunc_Chamfer::IsRational() const |
365 | { |
366 | return Standard_False; |
367 | } |
368 | |
369 | //======================================================================= |
370 | //function : GetSectionSize |
371 | //purpose : Non implementee (non necessaire car non rationel) |
372 | //======================================================================= |
373 | Standard_Real BlendFunc_Chamfer::GetSectionSize() const |
374 | { |
375 | Standard_NotImplemented::Raise("BlendFunc_Chamfer::GetSectionSize()"); |
376 | return 0; |
377 | } |
378 | |
379 | //======================================================================= |
380 | //function : GetMinimalWeight |
381 | //purpose : |
382 | //======================================================================= |
383 | void BlendFunc_Chamfer::GetMinimalWeight(TColStd_Array1OfReal& Weights) const |
384 | { |
385 | Weights.Init(1); |
386 | } |
387 | |
388 | |
389 | //======================================================================= |
390 | //function : NbIntervals |
391 | //purpose : |
392 | //======================================================================= |
393 | |
394 | Standard_Integer BlendFunc_Chamfer::NbIntervals (const GeomAbs_Shape S) const |
395 | { |
396 | return curv->NbIntervals(BlendFunc::NextShape(S)); |
397 | } |
398 | |
399 | |
400 | //======================================================================= |
401 | //function : Intervals |
402 | //purpose : |
403 | //======================================================================= |
404 | |
405 | void BlendFunc_Chamfer::Intervals (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const |
406 | { |
407 | curv->Intervals(T, BlendFunc::NextShape(S)); |
408 | } |
409 | |
410 | //======================================================================= |
411 | //function : GetShape |
412 | //purpose : |
413 | //======================================================================= |
414 | |
415 | void BlendFunc_Chamfer::GetShape (Standard_Integer& NbPoles, |
416 | Standard_Integer& NbKnots, |
417 | Standard_Integer& Degree, |
418 | Standard_Integer& NbPoles2d) |
419 | { |
420 | NbPoles = 2; |
421 | NbPoles2d = 2; |
422 | NbKnots = 2; |
423 | Degree = 1; |
424 | } |
425 | |
426 | //======================================================================= |
427 | //function : GetTolerance |
428 | //purpose : Determine les Tolerance a utiliser dans les approximations. |
429 | //======================================================================= |
430 | void BlendFunc_Chamfer::GetTolerance(const Standard_Real BoundTol, |
431 | const Standard_Real SurfTol, |
432 | const Standard_Real AngleTol, |
433 | math_Vector& Tol3d, |
434 | math_Vector& Tol1D) const |
435 | { |
436 | Tol3d.Init(BoundTol); |
437 | } |
438 | |
439 | //======================================================================= |
440 | //function : Knots |
441 | //purpose : |
442 | //======================================================================= |
443 | |
444 | void BlendFunc_Chamfer::Knots(TColStd_Array1OfReal& TKnots) |
445 | { |
446 | TKnots(1) = 0.; |
447 | TKnots(2) = 1.; |
448 | } |
449 | |
450 | |
451 | //======================================================================= |
452 | //function : Mults |
453 | //purpose : |
454 | //======================================================================= |
455 | |
456 | void BlendFunc_Chamfer::Mults(TColStd_Array1OfInteger& TMults) |
457 | { |
458 | TMults(1) = 2; |
459 | TMults(2) = 2; |
460 | } |
461 | |
462 | //======================================================================= |
463 | //function : Section |
464 | //purpose : |
465 | //======================================================================= |
466 | |
467 | Standard_Boolean BlendFunc_Chamfer::Section |
468 | (const Blend_Point& P, |
469 | TColgp_Array1OfPnt& Poles, |
470 | TColgp_Array1OfVec& DPoles, |
471 | TColgp_Array1OfVec& D2Poles, |
472 | TColgp_Array1OfPnt2d& Poles2d, |
473 | TColgp_Array1OfVec2d& DPoles2d, |
474 | TColgp_Array1OfVec2d& D2Poles2d, |
475 | TColStd_Array1OfReal& Weights, |
476 | TColStd_Array1OfReal& DWeights, |
477 | TColStd_Array1OfReal& D2Weights) |
478 | { |
479 | return Standard_False; |
480 | } |
481 | |
482 | //======================================================================= |
483 | //function : Section |
484 | //purpose : |
485 | //======================================================================= |
486 | |
487 | Standard_Boolean BlendFunc_Chamfer::Section |
488 | (const Blend_Point& P, |
489 | TColgp_Array1OfPnt& Poles, |
490 | TColgp_Array1OfVec& DPoles, |
491 | TColgp_Array1OfPnt2d& Poles2d, |
492 | TColgp_Array1OfVec2d& DPoles2d, |
493 | TColStd_Array1OfReal& Weights, |
494 | TColStd_Array1OfReal& DWeights) |
495 | { |
496 | math_Vector sol(1,4),valsol(1,4),secmember(1,4); |
497 | math_Matrix gradsol(1,4,1,4); |
498 | |
499 | Standard_Real prm = P.Parameter(); |
500 | Standard_Integer low = Poles.Lower(); |
501 | Standard_Integer upp = Poles.Upper(); |
502 | Standard_Boolean istgt; |
503 | |
504 | P.ParametersOnS1(sol(1),sol(2)); |
505 | P.ParametersOnS2(sol(3),sol(4)); |
506 | |
507 | Set(prm); |
508 | |
509 | Values(sol,valsol,gradsol); |
510 | IsSolution(sol,tol); |
511 | |
512 | istgt = IsTangencyPoint(); |
513 | |
514 | Poles2d(Poles2d.Lower()).SetCoord(sol(1),sol(2)); |
515 | Poles2d(Poles2d.Upper()).SetCoord(sol(3),sol(4)); |
516 | if (!istgt) { |
517 | DPoles2d(Poles2d.Lower()).SetCoord(Tangent2dOnS1().X(), |
518 | Tangent2dOnS1().Y()); |
519 | DPoles2d(Poles2d.Upper()).SetCoord(Tangent2dOnS2().X(), |
520 | Tangent2dOnS2().Y()); |
521 | } |
522 | Poles(low) = PointOnS1(); |
523 | Poles(upp) = PointOnS2(); |
524 | Weights(low) = 1.0; |
525 | Weights(upp) = 1.0; |
526 | if (!istgt) { |
527 | DPoles(low) = TangentOnS1(); |
528 | DPoles(upp) = TangentOnS2(); |
529 | DWeights(low) = 0.0; |
530 | DWeights(upp) = 0.0; |
531 | } |
532 | |
533 | return (!istgt); |
534 | } |
535 | |
536 | //======================================================================= |
537 | //function : Section |
538 | //purpose : |
539 | //======================================================================= |
540 | |
541 | void BlendFunc_Chamfer::Section(const Blend_Point& P, |
542 | TColgp_Array1OfPnt& Poles, |
543 | TColgp_Array1OfPnt2d& Poles2d, |
544 | TColStd_Array1OfReal& Weights) |
545 | { |
546 | Standard_Real u1,v1,u2,v2,prm = P.Parameter(); |
547 | Standard_Integer low = Poles.Lower(); |
548 | Standard_Integer upp = Poles.Upper(); |
549 | math_Vector X(1,4), F(1,4); |
550 | |
551 | P.ParametersOnS1(u1,v1); |
552 | P.ParametersOnS2(u2,v2); |
553 | X(1)=u1; |
554 | X(2)=v1; |
555 | X(3)=u2; |
556 | X(4)=v2; |
557 | Poles2d(Poles2d.Lower()).SetCoord(u1,v1); |
558 | Poles2d(Poles2d.Upper()).SetCoord(u2,v2); |
559 | |
560 | Set(prm); |
561 | Value(X,F); |
562 | Poles(low) = PointOnS1(); |
563 | Poles(upp) = PointOnS2(); |
564 | Weights(low) = 1.0; |
565 | Weights(upp) = 1.0; |
566 | } |
567 | |
568 | void BlendFunc_Chamfer::Resolution(const Standard_Integer IC2d, const Standard_Real Tol, |
569 | Standard_Real& TolU, Standard_Real& TolV) const |
570 | { |
571 | if(IC2d == 1){ |
572 | TolU = surf1->UResolution(Tol); |
573 | TolV = surf1->VResolution(Tol); |
574 | } |
575 | else { |
576 | TolU = surf2->UResolution(Tol); |
577 | TolV = surf2->VResolution(Tol); |
578 | } |
579 | } |