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