0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / FairCurve / FairCurve_EnergyOfBatten.cxx
1 // Created on: 1996-02-01
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef DEB
18 #define No_Standard_RangeError
19 #define No_Standard_OutOfRange
20 #endif
21
22 #include <FairCurve_EnergyOfBatten.ixx>
23
24 #include <math_IntegerVector.hxx>
25 #include <math_GaussSetIntegration.hxx>
26 #include <TColgp_HArray1OfPnt2d.hxx>
27
28 //=======================================================================
29 FairCurve_EnergyOfBatten::FairCurve_EnergyOfBatten(const Standard_Integer BSplOrder, 
30                                                    const Handle(TColStd_HArray1OfReal)& FlatKnots,
31                                                    const Handle(TColgp_HArray1OfPnt2d)& Poles, 
32                                                    const Standard_Integer ContrOrder1, 
33                                                    const Standard_Integer ContrOrder2, 
34                                                    const FairCurve_BattenLaw& Law, 
35                                                    const Standard_Real LengthSliding, 
36                                                    const Standard_Boolean FreeSliding, 
37                                                    const Standard_Real Angle1, 
38                                                    const Standard_Real Angle2)
39 //=======================================================================
40                          : FairCurve_Energy( Poles, ContrOrder1,  ContrOrder2,
41                                              FreeSliding,  Angle1, Angle2),
42                            MyLengthSliding(LengthSliding),
43                            OriginalSliding(LengthSliding),
44                            MyBattenLaw(Law), 
45                            MyTension(BSplOrder, FlatKnots, Poles, 1, LengthSliding,  Law, FreeSliding),
46                            MySagging(BSplOrder, FlatKnots, Poles, 1, Law, FreeSliding)
47 {
48 }
49
50 //=======================================================================
51 Standard_Boolean FairCurve_EnergyOfBatten::Variable(math_Vector& X) const
52 //======================================================================= 
53 {
54  Standard_Boolean Ok;
55  Ok = FairCurve_Energy::Variable(X);
56  if (MyWithAuxValue) { X(X.Upper()) = MyLengthSliding; }
57  return Ok;
58 }  
59
60 //=======================================================================
61 void FairCurve_EnergyOfBatten::ComputePoles(const math_Vector& X)
62 //======================================================================= 
63 {
64  FairCurve_Energy::ComputePoles(X);
65  if (MyWithAuxValue) { MyLengthSliding = X(X.Upper()); }
66 }
67
68 //=======================================================================
69 Standard_Boolean FairCurve_EnergyOfBatten::Compute(const Standard_Integer DerivativeOrder, 
70                                                    math_Vector& Result)
71 //=======================================================================
72 {
73   math_Vector Debut(1, 1, 0.),  Fin(1, 1, 1.);
74   math_IntegerVector MyOrder(1, 1, 24);
75   Standard_Boolean Ok=Standard_False;
76
77 // Blindage contre les longueur de glissement trop exotique
78   MyStatus = FairCurve_OK;
79   if ( MyLengthSliding > 10*OriginalSliding ) {
80     MyStatus =  FairCurve_InfiniteSliding;
81     return Standard_False;
82 }
83
84   if ( MyLengthSliding < OriginalSliding/100  ) {
85     MyLengthSliding = OriginalSliding/100;
86   }
87
88 // Mise a jour des objets sous-fonction
89   MyTension.SetDerivativeOrder(DerivativeOrder);
90   MyTension.SetLengthSliding(MyLengthSliding);
91   MySagging.SetDerivativeOrder(DerivativeOrder);
92   MyBattenLaw.SetSliding(MyLengthSliding);
93
94 //  Integrations
95   
96   // on decoupe afin d'avoir au moins 2 points d'integration par poles
97   // 24 points de Gauss => 12 poles maximum.
98
99   Standard_Integer NbInterv = (MyPoles->Length()-1) / 12 + 1, ii;
100   Standard_Real Delta = 1./ NbInterv;
101   Result.Init(0);
102
103   for (ii=1; ii<=NbInterv; ii++) {
104     Debut(1) = (ii-1)*Delta;
105     Fin(1) = ii*Delta;
106     
107     math_GaussSetIntegration SumTension(MyTension, Debut, Fin, MyOrder); 
108     Ok = SumTension.IsDone();
109     if (!Ok) return Ok;
110
111     math_GaussSetIntegration SumSagging(MySagging, Debut, Fin, MyOrder);
112     Ok = SumSagging.IsDone();
113
114     if (Ok) { Result += SumSagging.Value() + SumTension.Value(); }
115   }
116
117   return Ok;
118 }
119