1 // Created on: 2005-12-09
2 // Created by: Sergey KHROMOV
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BRepGProp_TFunction.ixx>
18 #include <TColStd_HArray1OfReal.hxx>
19 #include <math_KronrodSingleIntegration.hxx>
20 #include <Precision.hxx>
22 //=======================================================================
23 //function : Constructor.
25 //=======================================================================
27 BRepGProp_TFunction::BRepGProp_TFunction(const BRepGProp_Face &theSurface,
28 const gp_Pnt &theVertex,
29 const Standard_Boolean IsByPoint,
30 const Standard_Address theCoeffs,
31 const Standard_Real theUMin,
32 const Standard_Real theTolerance):
33 mySurface(theSurface),
34 myUFunction(mySurface, theVertex, IsByPoint, theCoeffs),
36 myTolerance(theTolerance),
40 myValueType(GProp_Unknown),
41 myIsByPoint(IsByPoint),
46 //=======================================================================
49 //=======================================================================
51 void BRepGProp_TFunction::Init()
58 //=======================================================================
61 //=======================================================================
63 Standard_Boolean BRepGProp_TFunction::Value(const Standard_Real X,
66 const Standard_Real tolU = 1.e-9;
71 Handle(TColStd_HArray1OfReal) anUKnots;
73 mySurface.D12d(X, aP2d, aV2d);
76 if(aUMax - myUMin < tolU)
82 mySurface.GetUKnots(myUMin, aUMax, anUKnots);
83 myUFunction.SetVParam(aP2d.Y());
85 // Compute the integral from myUMin to aUMax of myUFunction.
87 Standard_Real aCoeff = aV2d.Y();
88 //Standard_Integer aNbUIntervals = anUKnots->Length() - 1;
89 //Standard_Real aTol = myTolerance/aNbUIntervals;
90 Standard_Real aTol = myTolerance;
92 //aTol /= myNbPntOuter;
94 if (myValueType == GProp_Mass) {
97 } else if (myValueType == GProp_CenterMassX ||
98 myValueType == GProp_CenterMassY ||
99 myValueType == GProp_CenterMassZ) {
102 } else if (myValueType == GProp_InertiaXX ||
103 myValueType == GProp_InertiaYY ||
104 myValueType == GProp_InertiaZZ ||
105 myValueType == GProp_InertiaXY ||
106 myValueType == GProp_InertiaXZ ||
107 myValueType == GProp_InertiaYZ) {
111 return Standard_False;
113 Standard_Real aAbsCoeff = Abs(aCoeff);
115 if (aAbsCoeff <= Precision::Angular()) {
116 // No need to compute the integral. The value will be equal to 0.
118 return Standard_True;
120 //else if (aAbsCoeff > 10.*aTol)
121 // aTol /= aAbsCoeff;
125 Standard_Integer iU = anUKnots->Upper();
126 Standard_Integer aNbPntsStart;
127 Standard_Integer aNbMaxIter = 1000;
128 math_KronrodSingleIntegration anIntegral;
129 Standard_Real aLocalErr = 0.;
131 i = anUKnots->Lower();
134 // Epmirical criterion
135 aNbPntsStart = Min(15, mySurface.UIntegrationOrder()/(anUKnots->Length() - 1)+1);
136 aNbPntsStart = Max(5, aNbPntsStart);
139 Standard_Real aU1 = anUKnots->Value(i++);
140 Standard_Real aU2 = anUKnots->Value(i);
142 if(aU2 - aU1 < tolU) continue;
144 anIntegral.Perform(myUFunction, aU1, aU2, aNbPntsStart, aTol, aNbMaxIter);
146 if (!anIntegral.IsDone())
147 return Standard_False;
149 F += anIntegral.Value();
150 aLocalErr += anIntegral.AbsolutError();
151 //cout << " TFunction : " << anIntegral.NbIterReached() << " " << anIntegral.AbsolutError() << endl;
155 aLocalErr *= aAbsCoeff;
156 myAbsError = Max(myAbsError, aLocalErr);
158 myTolReached += aLocalErr;
160 if(Abs(F) > Epsilon(1.)) aLocalErr /= Abs(F);
162 myErrReached = Max(myErrReached, aLocalErr);
165 return Standard_True;
168 //=======================================================================
169 //function : GetStateNumber
171 //=======================================================================
173 Standard_Integer BRepGProp_TFunction::GetStateNumber()
175 //myErrReached = myTolReached;
177 //myNbPntOuter += RealToInt(0.5*myNbPntOuter);
179 //if (myNbPntOuter%2 == 0)