1 #include <Standard_NotImplemented.hxx>
2 #include <math_Vector.hxx>
4 #include <gp_Pnt2d.hxx>
5 #include <gp_Vec2d.hxx>
9 #include <TColStd_Array1OfReal.hxx>
10 #include <Precision.hxx>
13 void operator=(const math_Vector&){}
15 HMath_Vector(){ pvec = 0;}
16 HMath_Vector(math_Vector* pv){ pvec = pv;}
17 ~HMath_Vector(){ if(pvec != 0) delete pvec;}
18 void operator=(math_Vector* pv){ if(pvec != pv && pvec != 0) delete pvec; pvec = pv;}
19 Standard_Real& operator()(Standard_Integer i){ return (*pvec).operator()(i);}
20 const Standard_Real& operator()(Standard_Integer i) const{ return (*pvec).operator()(i);}
21 const math_Vector* operator->() const{ return pvec;}
22 math_Vector* operator->(){ return pvec;}
23 math_Vector* Init(Standard_Real v, Standard_Integer i = 0, Standard_Integer iEnd = 0){
24 if(pvec == 0) return pvec;
25 if(iEnd - i == 0) pvec->Init(v);
26 else for(; i <= iEnd; i++) pvec->operator()(i) = v;
31 //Minimal value of interval's range for computation | minimal value of "dim" | ...
32 static Standard_Real EPS_PARAM = Precision::Angular(), EPS_DIM = 1.E-30, ERROR_ALGEBR_RATIO = 2.0/3.0;
33 //Maximum of GaussPoints on a subinterval and maximum of subintervals
34 static Standard_Integer GPM = math::GaussPointsMax(), SUBS_POWER = 32, SM = SUBS_POWER*GPM + 1;
35 static Standard_Boolean IS_MIN_DIM = 1; // if the value equal 0 error of algorithm calculted by static moments
37 static math_Vector LGaussP0(1,GPM), LGaussW0(1,GPM),
38 LGaussP1(1,RealToInt(Ceiling(ERROR_ALGEBR_RATIO*GPM))), LGaussW1(1,RealToInt(Ceiling(ERROR_ALGEBR_RATIO*GPM)));
39 static HMath_Vector L1 = new math_Vector(1,SM), L2 = new math_Vector(1,SM),
40 DimL = new math_Vector(1,SM), ErrL = new math_Vector(1,SM), ErrUL = new math_Vector(1,SM,0.0),
41 IxL = new math_Vector(1,SM), IyL = new math_Vector(1,SM), IzL = new math_Vector(1,SM),
42 IxxL = new math_Vector(1,SM), IyyL = new math_Vector(1,SM), IzzL = new math_Vector(1,SM),
43 IxyL = new math_Vector(1,SM), IxzL = new math_Vector(1,SM), IyzL = new math_Vector(1,SM);
45 static math_Vector* LGaussP[] = {&LGaussP0,&LGaussP1};
46 static math_Vector* LGaussW[] = {&LGaussW0,&LGaussW1};
48 static math_Vector UGaussP0(1,GPM), UGaussW0(1,GPM),
49 UGaussP1(1,RealToInt(Ceiling(ERROR_ALGEBR_RATIO*GPM))), UGaussW1(1,RealToInt(Ceiling(ERROR_ALGEBR_RATIO*GPM)));
50 static HMath_Vector U1 = new math_Vector(1,SM), U2 = new math_Vector(1,SM),
51 DimU = new math_Vector(1,SM), ErrU = new math_Vector(1,SM,0.0),
52 IxU = new math_Vector(1,SM), IyU = new math_Vector(1,SM), IzU = new math_Vector(1,SM),
53 IxxU = new math_Vector(1,SM), IyyU = new math_Vector(1,SM), IzzU = new math_Vector(1,SM),
54 IxyU = new math_Vector(1,SM), IxzU = new math_Vector(1,SM), IyzU = new math_Vector(1,SM);
56 static math_Vector* UGaussP[] = {&UGaussP0,&UGaussP1};
57 static math_Vector* UGaussW[] = {&UGaussW0,&UGaussW1};
59 static Standard_Integer FillIntervalBounds(Standard_Real A, Standard_Real B, const TColStd_Array1OfReal& Knots,
60 HMath_Vector& VA, HMath_Vector& VB)
62 Standard_Integer i = 1, iEnd = Knots.Upper(), j = 1, k = 1;
64 for(; i <= iEnd; i++){
65 Standard_Real kn = Knots(i);
67 if(kn < B) VA(j++) = VB(k++) = kn; else break;
73 static inline Standard_Integer MaxSubs(Standard_Integer n, Standard_Integer coeff = SUBS_POWER){
74 return n = IntegerLast()/coeff < n? IntegerLast(): n*coeff + 1;
77 static Standard_Integer LFillIntervalBounds(Standard_Real A, Standard_Real B, const TColStd_Array1OfReal& Knots,
78 const Standard_Integer NumSubs)
80 Standard_Integer iEnd = Knots.Upper(), jEnd = L1->Upper();
82 // Modified by Sergey KHROMOV - Wed Mar 26 11:22:50 2003
83 iEnd = Max(iEnd, MaxSubs(iEnd-1,NumSubs));
85 // iEnd = MaxSubs(iEnd-1,NumSubs);
86 // Modified by Sergey KHROMOV - Wed Mar 26 11:22:51 2003
87 L1 = new math_Vector(1,iEnd); L2 = new math_Vector(1,iEnd);
88 DimL = new math_Vector(1,iEnd); ErrL = new math_Vector(1,iEnd,0.0); ErrUL = new math_Vector(1,iEnd,0.0);
89 IxL = new math_Vector(1,iEnd); IyL = new math_Vector(1,iEnd); IzL = new math_Vector(1,iEnd);
90 IxxL = new math_Vector(1,iEnd); IyyL = new math_Vector(1,iEnd); IzzL = new math_Vector(1,iEnd);
91 IxyL = new math_Vector(1,iEnd); IxzL = new math_Vector(1,iEnd); IyzL = new math_Vector(1,iEnd);
93 return FillIntervalBounds(A, B, Knots, L1, L2);
96 static Standard_Integer UFillIntervalBounds(Standard_Real A, Standard_Real B, const TColStd_Array1OfReal& Knots,
97 const Standard_Integer NumSubs)
99 Standard_Integer iEnd = Knots.Upper(), jEnd = U1->Upper();
101 // Modified by Sergey KHROMOV - Wed Mar 26 11:22:50 2003
102 iEnd = Max(iEnd, MaxSubs(iEnd-1,NumSubs));
104 // iEnd = MaxSubs(iEnd-1,NumSubs);
105 // Modified by Sergey KHROMOV - Wed Mar 26 11:22:51 2003
106 U1 = new math_Vector(1,iEnd); U2 = new math_Vector(1,iEnd);
107 DimU = new math_Vector(1,iEnd); ErrU = new math_Vector(1,iEnd,0.0);
108 IxU = new math_Vector(1,iEnd); IyU = new math_Vector(1,iEnd); IzU = new math_Vector(1,iEnd);
109 IxxU = new math_Vector(1,iEnd); IyyU = new math_Vector(1,iEnd); IzzU = new math_Vector(1,iEnd);
110 IxyU = new math_Vector(1,iEnd); IxzU = new math_Vector(1,iEnd); IyzU = new math_Vector(1,iEnd);
112 return FillIntervalBounds(A, B, Knots, U1, U2);
115 static Standard_Real CCompute(Face& S, Domain& D, const Standard_Boolean ByPoint, const Standard_Real Coeff[],
116 const gp_Pnt& loc, Standard_Real& Dim, gp_Pnt& g, gp_Mat& inertia,
117 const Standard_Real EpsDim,
118 const Standard_Boolean isErrorCalculation, const Standard_Boolean isVerifyComputation)
120 Standard_Boolean isNaturalRestriction = S.NaturalRestriction();
122 Standard_Integer NumSubs = SUBS_POWER;
123 Standard_Boolean isMinDim = IS_MIN_DIM;
125 Standard_Real Ix, Iy, Iz, Ixx, Iyy, Izz, Ixy, Ixz, Iyz;
126 Dim = Ix = Iy = Iz = Ixx = Iyy = Izz = Ixy = Ixz = Iyz = 0.0;
127 //boundary curve parametrization
128 Standard_Real l1, l2, lm, lr, l;
129 //Face parametrization in U and V direction
130 Standard_Real BV1, BV2, v;
131 Standard_Real BU1, BU2, u1, u2, um, ur, u;
132 S.Bounds (BU1, BU2, BV1, BV2); u1 = BU1;
133 //location point used to compute the inertia
134 Standard_Real xloc, yloc, zloc;
135 loc.Coord (xloc, yloc, zloc);
136 //location point used to compute the inertiard (xloc, yloc, zloc);
137 //Jacobien (x, y, z) -> (u, v) = ||n||
138 Standard_Real xn, yn, zn, s, ds, dDim;
139 Standard_Real x, y, z, xi, px, py, pz, yi, zi, d1, d2, d3;
143 //On the boundary curve u-v
146 Standard_Real Dul; // Dul = Du / Dl
147 Standard_Real CDim[2], CIx, CIy, CIz, CIxx[2], CIyy[2], CIzz[2], CIxy, CIxz, CIyz;
148 Standard_Real LocDim[2], LocIx[2], LocIy[2], LocIz[2], LocIxx[2], LocIyy[2], LocIzz[2], LocIxy[2], LocIxz[2], LocIyz[2];
150 Standard_Integer iD = 0, NbLSubs, iLS, iLSubEnd, iGL, iGLEnd, NbLGaussP[2], LRange[2], iL, kL, kLEnd, IL, JL;
151 Standard_Integer i, NbUSubs, iUS, iUSubEnd, iGU, iGUEnd, NbUGaussP[2], URange[2], iU, kU, kUEnd, IU, JU;
152 Standard_Integer UMaxSubs, LMaxSubs;
154 Standard_Real ErrorU, ErrorL, ErrorLMax = 0.0, Eps=0.0, EpsL=0.0, EpsU=0.0;
155 iGLEnd = isErrorCalculation? 2: 1;
157 for(i = 0; i < 2; i++) {
170 NbUGaussP[0] = S.SIntOrder(EpsDim);
171 NbUGaussP[1] = RealToInt(Ceiling(ERROR_ALGEBR_RATIO*NbUGaussP[0]));
172 math::GaussPoints(NbUGaussP[0],UGaussP0); math::GaussWeights(NbUGaussP[0],UGaussW0);
173 math::GaussPoints(NbUGaussP[1],UGaussP1); math::GaussWeights(NbUGaussP[1],UGaussW1);
175 NbUSubs = S.SUIntSubs();
176 TColStd_Array1OfReal UKnots(1,NbUSubs+1);
179 while (isNaturalRestriction || D.More()) {
180 if(isNaturalRestriction){
181 NbLGaussP[0] = Min(2*NbUGaussP[0],math::GaussPointsMax());
183 S.Load(D.Value()); ++iD;
184 NbLGaussP[0] = S.LIntOrder(EpsDim);
186 NbLGaussP[1] = RealToInt(Ceiling(ERROR_ALGEBR_RATIO*NbLGaussP[0]));
187 math::GaussPoints(NbLGaussP[0],LGaussP0); math::GaussWeights(NbLGaussP[0],LGaussW0);
188 math::GaussPoints(NbLGaussP[1],LGaussP1); math::GaussWeights(NbLGaussP[1],LGaussW1);
190 NbLSubs = isNaturalRestriction? S.SVIntSubs(): S.LIntSubs();
191 TColStd_Array1OfReal LKnots(1,NbLSubs+1);
192 if(isNaturalRestriction){
197 l1 = S.FirstParameter(); l2 = S.LastParameter();
201 //OCC503(apo): if(Abs(l2-l1) < EPS_PARAM) continue;
202 if(Abs(l2-l1) > EPS_PARAM) {
203 iLSubEnd = LFillIntervalBounds(l1, l2, LKnots, NumSubs);
204 LMaxSubs = MaxSubs(iLSubEnd);
205 //-- exception avoiding
206 if(LMaxSubs > SM) LMaxSubs = SM;
207 DimL.Init(0.0,1,LMaxSubs); ErrL.Init(0.0,1,LMaxSubs); ErrUL.Init(0.0,1,LMaxSubs);
210 LRange[0] = IL = ErrL->Max(); LRange[1] = JL;
211 L1(JL) = (L1(IL) + L2(IL))/2.0; L2(JL) = L2(IL); L2(IL) = L1(JL);
212 }else LRange[0] = IL = JL;
213 if(JL == LMaxSubs || Abs(L2(JL) - L1(JL)) < EPS_PARAM)
215 DimL(JL) = ErrL(JL) = IxL(JL) = IyL(JL) = IzL(JL) =
216 IxxL(JL) = IyyL(JL) = IzzL(JL) = IxyL(JL) = IxzL(JL) = IyzL(JL) = 0.0;
219 EpsL = ErrorL; Eps = EpsL/0.9;
223 for(kL=0; kL < kLEnd; kL++){
225 lm = 0.5*(L2(iLS) + L1(iLS));
226 lr = 0.5*(L2(iLS) - L1(iLS));
227 CIx = CIy = CIz = CIxy = CIxz = CIyz = 0.0;
228 for(iGL=0; iGL < iGLEnd; iGL++){//
229 CDim[iGL] = CIxx[iGL] = CIyy[iGL] = CIzz[iGL] = 0.0;
230 for(iL=1; iL<=NbLGaussP[iGL]; iL++){
231 l = lm + lr*(*LGaussP[iGL])(iL);
232 if(isNaturalRestriction){
233 v = l; u2 = BU2; Dul = (*LGaussW[iGL])(iL);
235 S.D12d (l, Puv, Vuv);
236 Dul = Vuv.Y()*(*LGaussW[iGL])(iL); // Dul = Du / Dl
237 if(Abs(Dul) < EPS_PARAM) continue;
238 v = Puv.Y(); u2 = Puv.X();
239 //Check on cause out off bounds of value current parameter
240 if(v < BV1) v = BV1; else if(v > BV2) v = BV2;
241 if(u2 < BU1) u2 = BU1; else if(u2 > BU2) u2 = BU2;
245 if(Abs(u2-u1) < EPS_PARAM) continue;
246 iUSubEnd = UFillIntervalBounds(u1, u2, UKnots, NumSubs);
247 UMaxSubs = MaxSubs(iUSubEnd);
248 //-- exception avoiding
249 if(UMaxSubs > SM) UMaxSubs = SM;
250 DimU.Init(0.0,1,UMaxSubs); ErrU.Init(0.0,1,UMaxSubs); ErrorU = 0.0;
253 URange[0] = IU = ErrU->Max(); URange[1] = JU;
254 U1(JU) = (U1(IU)+U2(IU))/2.0; U2(JU) = U2(IU); U2(IU) = U1(JU);
255 }else URange[0] = IU = JU;
256 if(JU == UMaxSubs || Abs(U2(JU) - U1(JU)) < EPS_PARAM)
258 DimU(JU) = ErrU(JU) = IxU(JU) = IyU(JU) = IzU(JU) =
259 IxxU(JU) = IyyU(JU) = IzzU(JU) = IxyU(JU) = IxzU(JU) = IyzU(JU) = 0.0;
262 EpsU = ErrorU; Eps = EpsU*Abs((u2-u1)*Dul)/0.1; EpsL = 0.9*Eps;
266 for(kU=0; kU < kUEnd; kU++){
268 um = 0.5*(U2(iUS) + U1(iUS));
269 ur = 0.5*(U2(iUS) - U1(iUS));
270 iGUEnd = iGLEnd - iGL;
271 for(iGU=0; iGU < iGUEnd; iGU++){//
273 LocIxx[iGU] = LocIyy[iGU] = LocIzz[iGU] =
274 LocIx[iGU] = LocIy[iGU] = LocIz[iGU] =
275 LocIxy[iGU] = LocIxz[iGU] = LocIyz[iGU] = 0.0;
276 for(iU=1; iU<=NbUGaussP[iGU]; iU++){
277 u = um + ur*(*UGaussP[iGU])(iU);
278 S.Normal(u, v, Ps, VNor);
279 VNor.Coord(xn, yn, zn);
281 x -= xloc; y -= yloc; z -= zloc;
282 xn *= (*UGaussW[iGU])(iU);
283 yn *= (*UGaussW[iGU])(iU);
284 zn *= (*UGaussW[iGU])(iU);
286 //volume of elementary cone
287 dDim = (x*xn+y*yn+z*zn)/3.0;
288 //coordinates of cone's center mass
289 px = 0.75*x; py = 0.75*y; pz = 0.75*z;
291 //if(iGU > 0) continue;
292 LocIx[iGU] += px*dDim;
293 LocIy[iGU] += py*dDim;
294 LocIz[iGU] += pz*dDim;
295 x -= Coeff[0]; y -= Coeff[1]; z -= Coeff[2];
297 LocIxy[iGU] -= x*y*dDim;
298 LocIyz[iGU] -= y*z*dDim;
299 LocIxz[iGU] -= x*z*dDim;
300 xi = x*x; yi = y*y; zi = z*z;
301 LocIxx[iGU] += (yi+zi)*dDim;
302 LocIyy[iGU] += (xi+zi)*dDim;
303 LocIzz[iGU] += (xi+yi)*dDim;
305 s = xn*Coeff[0] + yn*Coeff[1] + zn*Coeff[2];
306 d1 = Coeff[0]*x + Coeff[1]*y + Coeff[2]*z - Coeff[3];
311 //if(iGU > 0) continue;
312 LocIx[iGU] += (x - Coeff[0]*d1/2.0) * ds;
313 LocIy[iGU] += (y - Coeff[1]*d1/2.0) * ds;
314 LocIz[iGU] += (z - Coeff[2]*d1/2.0) * ds;
315 px = x-Coeff[0]*d1; py = y-Coeff[1]*d1; pz = z-Coeff[2]*d1;
316 xi = px*px*d1 + px*Coeff[0]*d2 + Coeff[0]*Coeff[0]*d3;
317 yi = py*py*d1 + py*Coeff[1]*d2 + Coeff[1]*Coeff[1]*d3;
318 zi = pz*pz*d1 + pz*Coeff[2]*d2 + Coeff[2]*Coeff[2]*d3;
319 LocIxx[iGU] += (yi+zi)*s;
320 LocIyy[iGU] += (xi+zi)*s;
321 LocIzz[iGU] += (xi+yi)*s;
323 xi = py*pz*d1 + py*Coeff[2]*d2 + pz*Coeff[1]*d2 + Coeff[1]*Coeff[2]*d3;
324 yi = px*pz*d1 + pz*Coeff[0]*d2 + px*Coeff[2]*d2 + Coeff[0]*Coeff[2]*d3;
325 zi = px*py*d1 + px*Coeff[1]*d2 + py*Coeff[0]*d2 + Coeff[0]*Coeff[1]*d3;
326 LocIxy[iGU] -= zi*s; LocIyz[iGU] -= xi*s; LocIxz[iGU] -= yi*s;
330 DimU(iUS) = LocDim[0]*ur;
331 IxxU(iUS) = LocIxx[0]*ur; IyyU(iUS) = LocIyy[0]*ur; IzzU(iUS) = LocIzz[0]*ur;
332 if(iGL > 0) continue;
333 LocDim[1] = Abs(LocDim[1]-LocDim[0]);
334 LocIxx[1] = Abs(LocIxx[1]-LocIxx[0]);
335 LocIyy[1] = Abs(LocIyy[1]-LocIyy[0]);
336 LocIzz[1] = Abs(LocIzz[1]-LocIzz[0]);
337 ErrU(iUS) = isMinDim? LocDim[1]*ur: (LocIxx[1] + LocIyy[1] + LocIzz[1])*ur;
338 IxU(iUS) = LocIx[0]*ur; IyU(iUS) = LocIy[0]*ur; IzU(iUS) = LocIz[0]*ur;
339 IxyU(iUS) = LocIxy[0]*ur; IxzU(iUS) = LocIxz[0]*ur; IyzU(iUS) = LocIyz[0]*ur;
341 if(JU == iUSubEnd) kUEnd = 2;
343 Standard_Integer imax = ErrU->Max();
344 if(imax > 0) ErrorU = ErrU(imax);
347 }while((ErrorU - EpsU > 0.0 && EpsU != 0.0) || kUEnd == 1);
348 for(i=1; i<=JU; i++) {
349 CDim[iGL] += DimU(i)*Dul;
350 CIxx[iGL] += IxxU(i)*Dul; CIyy[iGL] += IyyU(i)*Dul; CIzz[iGL] += IzzU(i)*Dul;
352 if(iGL > 0) continue;
353 ErrUL(iLS) = ErrorU*Abs((u2-u1)*Dul);
354 for(i=1; i<=JU; i++){
355 CIx += IxU(i)*Dul; CIy += IyU(i)*Dul; CIz += IzU(i)*Dul;
356 //CIxx += IxxU(i)*Dul; CIyy += IyyU(i)*Dul; CIzz += IzzU(i)*Dul;
357 CIxy += IxyU(i)*Dul; CIxz += IxzU(i)*Dul; CIyz += IyzU(i)*Dul;
361 DimL(iLS) = CDim[0]*lr;
362 IxxL(iLS) = CIxx[0]*lr; IyyL(iLS) = CIyy[0]*lr; IzzL(iLS) = CIzz[0]*lr;
364 //ErrL(iLS) = Abs(CDim[1]-CDim[0])*lr + ErrUL(iLS);
365 CDim[1] = Abs(CDim[1]-CDim[0]);
366 CIxx[1] = Abs(CIxx[1]-CIxx[0]); CIyy[1] = Abs(CIyy[1]-CIyy[0]); CIzz[1] = Abs(CIzz[1]-CIzz[0]);
368 ErrL(iLS) = (isMinDim? CDim[1]: (CIxx[1] + CIyy[1] + CIzz[1]))*lr + ErrorU;
370 IxL(iLS) = CIx*lr; IyL(iLS) = CIy*lr; IzL(iLS) = CIz*lr;
371 //IxxL(iLS) = CIxx*lr; IyyL(iLS) = CIyy*lr; IzzL(iLS) = CIzz*lr;
372 IxyL(iLS) = CIxy*lr; IxzL(iLS) = CIxz*lr; IyzL(iLS) = CIyz*lr;
374 // Calculate/correct epsilon of computation by current value of Dim
375 //That is need for not spend time for
378 Standard_Real DDim = 0.0, DIxx = 0.0, DIyy = 0.0, DIzz = 0.0;
379 for(i=1; i<=JL; i++) {
381 DIxx += IxxL(i); DIyy += IyyL(i); DIzz += IzzL(i);
383 DDim = isMinDim? Abs(DDim): Abs(DIxx) + Abs(DIyy) + Abs(DIzz);
384 DDim = Abs(DDim*EpsDim);
386 Eps = DDim; EpsL = 0.9*Eps;
390 Standard_Integer imax = ErrL->Max();
391 if(imax > 0) ErrorL = ErrL(imax);
394 }while((ErrorL - EpsL > 0.0 && isVerifyComputation) || kLEnd == 1);
395 for(i=1; i<=JL; i++){
397 Ix += IxL(i); Iy += IyL(i); Iz += IzL(i);
398 Ixx += IxxL(i); Iyy += IyyL(i); Izz += IzzL(i);
399 Ixy += IxyL(i); Ixz += IxzL(i); Iyz += IyzL(i);
401 ErrorLMax = Max(ErrorLMax, ErrorL);
403 if(isNaturalRestriction) break;
406 if(Abs(Dim) >= EPS_DIM){
408 Ix = Coeff[0] + Ix/Dim;
409 Iy = Coeff[1] + Iy/Dim;
410 Iz = Coeff[2] + Iz/Dim;
416 g.SetCoord (Ix, Iy, Iz);
419 g.SetCoord(0.,0.,0.);
421 inertia.SetCols (gp_XYZ (Ixx, Ixy, Ixz),
422 gp_XYZ (Ixy, Iyy, Iyz),
423 gp_XYZ (Ixz, Iyz, Izz));
425 Eps = Dim != 0.0? ErrorLMax/(isMinDim? Abs(Dim): (Abs(Ixx) + Abs(Iyy) + Abs(Izz))): 0.0;
430 static Standard_Real Compute(Face& S, const Standard_Boolean ByPoint, const Standard_Real Coeff[],
431 const gp_Pnt& loc, Standard_Real& Dim, gp_Pnt& g, gp_Mat& inertia, Standard_Real EpsDim)
433 Standard_Boolean isErrorCalculation = 0.0 > EpsDim || EpsDim < 0.001? 1: 0;
434 Standard_Boolean isVerifyComputation = 0.0 < EpsDim && EpsDim < 0.001? 1: 0;
435 EpsDim = Abs(EpsDim);
437 return CCompute(S,D,ByPoint,Coeff,loc,Dim,g,inertia,EpsDim,isErrorCalculation,isVerifyComputation);
440 static Standard_Real Compute(Face& S, Domain& D, const Standard_Boolean ByPoint, const Standard_Real Coeff[],
441 const gp_Pnt& loc, Standard_Real& Dim, gp_Pnt& g, gp_Mat& inertia, Standard_Real EpsDim)
443 Standard_Boolean isErrorCalculation = 0.0 > EpsDim || EpsDim < 0.001? 1: 0;
444 Standard_Boolean isVerifyComputation = 0.0 < EpsDim && EpsDim < 0.001? 1: 0;
445 EpsDim = Abs(EpsDim);
446 return CCompute(S,D,ByPoint,Coeff,loc,Dim,g,inertia,EpsDim,isErrorCalculation,isVerifyComputation);
449 static void Compute(const Face& S,
450 const Standard_Boolean ByPoint,
451 const Standard_Real Coeff[],
460 Standard_Real dvi, dv;
461 Standard_Real ur, um, u, vr, vm, v;
462 Standard_Real x, y, z, xn, yn, zn, xi, yi, zi;
463 // Standard_Real x, y, z, xn, yn, zn, xi, yi, zi, xyz;
464 Standard_Real px,py,pz,s,d1,d2,d3;
465 Standard_Real Ixi, Iyi, Izi, Ixxi, Iyyi, Izzi, Ixyi, Ixzi, Iyzi;
466 Standard_Real xloc, yloc, zloc;
467 Standard_Real Ix, Iy, Iz, Ixx, Iyy, Izz, Ixy, Ixz, Iyz;
469 Volu = Ix = Iy = Iz = Ixx = Iyy = Izz = Ixy = Ixz = Iyz = 0.0;
470 Loc.Coord (xloc, yloc, zloc);
472 Standard_Real LowerU, UpperU, LowerV, UpperV;
473 S.Bounds ( LowerU, UpperU, LowerV, UpperV);
474 Standard_Integer UOrder = Min(S.UIntegrationOrder (),
475 math::GaussPointsMax());
476 Standard_Integer VOrder = Min(S.VIntegrationOrder (),
477 math::GaussPointsMax());
479 Standard_Integer i, j;
480 math_Vector GaussPU (1, UOrder); //gauss points and weights
481 math_Vector GaussWU (1, UOrder);
482 math_Vector GaussPV (1, VOrder);
483 math_Vector GaussWV (1, VOrder);
485 math::GaussPoints (UOrder,GaussPU);
486 math::GaussWeights (UOrder,GaussWU);
487 math::GaussPoints (VOrder,GaussPV);
488 math::GaussWeights (VOrder,GaussWV);
490 um = 0.5 * (UpperU + LowerU);
491 vm = 0.5 * (UpperV + LowerV);
492 ur = 0.5 * (UpperU - LowerU);
493 vr = 0.5 * (UpperV - LowerV);
495 for (j = 1; j <= VOrder; j++) {
496 v = vm + vr * GaussPV (j);
497 dvi = Ixi = Iyi = Izi = Ixxi = Iyyi = Izzi = Ixyi = Ixzi = Iyzi = 0.0;
499 for (i = 1; i <= UOrder; i++) {
500 u = um + ur * GaussPU (i);
501 S.Normal (u, v, P, VNor);
502 VNor.Coord (xn, yn, zn);
504 x -= xloc; y -= yloc; z -= zloc;
505 xn *= GaussWU (i); yn *= GaussWU (i); zn *= GaussWU (i);
507 ///////////////////// ///////////////////////
508 // OFV code // // Initial code //
509 ///////////////////// ///////////////////////
511 dv = (x*xn+y*yn+z*zn)/3.0; //xyz = x * y * z;
512 dvi += dv; //Ixyi += zn * xyz;
513 Ixi += 0.75*x*dv; //Iyzi += xn * xyz;
514 Iyi += 0.75*y*dv; //Ixzi += yn * xyz;
515 Izi += 0.75*z*dv; //xi = x * x * x * xn / 3.0;
516 x -= Coeff[0]; //yi = y * y * y * yn / 3.0;
517 y -= Coeff[1]; //zi = z * z * z * zn / 3.0;
518 z -= Coeff[2]; //Ixxi += (yi + zi);
519 dv *= 3.0/5.0; //Iyyi += (xi + zi);
520 Ixyi -= x*y*dv; //Izzi += (xi + yi);
521 Iyzi -= y*z*dv; //x -= Coeff[0];
522 Ixzi -= x*z*dv; //y -= Coeff[1];
523 xi = x*x; //z -= Coeff[2];
524 yi = y*y; //dv = x * xn + y * yn + z * zn;
525 zi = z*z; //dvi += dv;
526 Ixxi += (yi + zi)*dv; //Ixi += x * dv;
527 Iyyi += (xi + zi)*dv; //Iyi += y * dv;
528 Izzi += (xi + yi)*dv; //Izi += z * dv;
531 s = xn * Coeff[0] + yn * Coeff[1] + zn * Coeff[2];
532 d1 = Coeff[0] * x + Coeff[1] * y + Coeff[2] * z - Coeff[3];
537 Ixi += (x - (Coeff[0] * d1 / 2.0)) * dv;
538 Iyi += (y - (Coeff[1] * d1 / 2.0)) * dv;
539 Izi += (z - (Coeff[2] * d1 / 2.0)) * dv;
540 px = x - Coeff[0] * d1;
541 py = y - Coeff[1] * d1;
542 pz = z - Coeff[2] * d1;
543 xi = px * px * d1 + px * Coeff[0]* d2 + Coeff[0] * Coeff[0] * d3;
544 yi = py * py * d1 + py * Coeff[1] * d2 + Coeff[1] * Coeff[1] * d3;
545 zi = pz * pz * d1 + pz * Coeff[2] * d2 + Coeff[2] * Coeff[2] * d3;
546 Ixxi += (yi + zi) * s;
547 Iyyi += (xi + zi) * s;
548 Izzi += (xi + yi) * s;
550 xi = (py * pz * d1) + (py * Coeff[2] * d2) + (pz * Coeff[1] * d2) + (Coeff[1] * Coeff[2] * d3);
551 yi = (px * pz * d1) + (pz * Coeff[0] * d2) + (px * Coeff[2] * d2) + (Coeff[0] * Coeff[2] * d3);
552 zi = (px * py * d1) + (px * Coeff[1] * d2) + (py * Coeff[0] * d2) + (Coeff[0] * Coeff[1] * d3);
558 Volu += dvi * GaussWV (j);
559 Ix += Ixi * GaussWV (j);
560 Iy += Iyi * GaussWV (j);
561 Iz += Izi * GaussWV (j);
562 Ixx += Ixxi * GaussWV (j);
563 Iyy += Iyyi * GaussWV (j);
564 Izz += Izzi * GaussWV (j);
565 Ixy += Ixyi * GaussWV (j);
566 Ixz += Ixzi * GaussWV (j);
567 Iyz += Iyzi * GaussWV (j);
576 if (Abs(Volu) >= EPS_DIM ) {
578 Ix = Coeff[0] + Ix/Volu;
579 Iy = Coeff[1] + Iy/Volu;
580 Iz = Coeff[2] + Iz/Volu;
589 G.SetCoord (Ix, Iy, Iz);
592 G.SetCoord(0.,0.,0.);
595 Inertia.SetCols (gp_XYZ (Ixx, Ixy, Ixz),
596 gp_XYZ (Ixy, Iyy, Iyz),
597 gp_XYZ (Ixz, Iyz, Izz));
601 // Last modified by OFV 5.2001:
602 // 1). surface and edge integration order is equal now
603 // 2). "by point" works now rathre correctly (it looks so...)
604 static void Compute(Face& S, Domain& D, const Standard_Boolean ByPoint, const Standard_Real Coeff[],
605 const gp_Pnt& Loc, Standard_Real& Volu, gp_Pnt& G, gp_Mat& Inertia)
608 Standard_Real x, y, z, xi, yi, zi, l1, l2, lm, lr, l, v1, v2, v, u1, u2, um, ur, u, ds, Dul, xloc, yloc, zloc;
609 Standard_Real LocVolu, LocIx, LocIy, LocIz, LocIxx, LocIyy, LocIzz, LocIxy, LocIxz, LocIyz;
610 Standard_Real CVolu, CIx, CIy, CIz, CIxx, CIyy, CIzz, CIxy, CIxz, CIyz, Ix, Iy, Iz, Ixx, Iyy, Izz, Ixy, Ixz, Iyz;
611 Standard_Real xn, yn, zn, px, py, pz, s, d1, d2, d3, dSigma;
612 Standard_Integer i, j, vio, sio, max, NbGaussgp_Pnts;
619 Loc.Coord (xloc, yloc, zloc);
620 Volu = Ix = Iy = Iz = Ixx = Iyy = Izz = Ixy = Ixz = Iyz = 0.0;
621 S.Bounds (u1, u2, v1, v2);
622 Standard_Real _u2 = u2; //OCC104
623 vio = S.VIntegrationOrder ();
628 sio = S.IntegrationOrder ();
630 NbGaussgp_Pnts = Min(max,math::GaussPointsMax());
632 math_Vector GaussP (1, NbGaussgp_Pnts);
633 math_Vector GaussW (1, NbGaussgp_Pnts);
634 math::GaussPoints (NbGaussgp_Pnts,GaussP);
635 math::GaussWeights (NbGaussgp_Pnts,GaussW);
637 CVolu = CIx = CIy = CIz = CIxx = CIyy = CIzz = CIxy = CIxz = CIyz = 0.0;
638 l1 = S.FirstParameter();
639 l2 = S.LastParameter();
640 lm = 0.5 * (l2 + l1);
641 lr = 0.5 * (l2 - l1);
643 for (i=1; i<=NbGaussgp_Pnts; i++)
645 l = lm + lr * GaussP(i);
646 S.D12d (l, Puv, Vuv);
653 u2 = u2 < u1? u1: u2;
654 u2 = u2 > _u2? _u2: u2;
656 Dul = Vuv.Y() * GaussW(i);
657 um = 0.5 * (u2 + u1);
658 ur = 0.5 * (u2 - u1);
659 LocVolu = LocIx = LocIy = LocIz = LocIxx = LocIyy = LocIzz = LocIxy = LocIxz = LocIyz = 0.0;
661 for (j=1; j<=NbGaussgp_Pnts; j++)
663 u = um + ur * GaussP(j);
664 S.Normal (u, v, Ps, VNor);
665 VNor.Coord (xn, yn, zn);
670 xn = xn * Dul * GaussW(j);
671 yn = yn * Dul * GaussW(j);
672 zn = zn * Dul * GaussW(j);
675 dSigma = (x*xn+y*yn+z*zn)/3.0;
677 LocIx += 0.75*x*dSigma;
678 LocIy += 0.75*y*dSigma;
679 LocIz += 0.75*z*dSigma;
684 LocIxy -= x*y*dSigma;
685 LocIyz -= y*z*dSigma;
686 LocIxz -= x*z*dSigma;
690 LocIxx += (yi + zi)*dSigma;
691 LocIyy += (xi + zi)*dSigma;
692 LocIzz += (xi + yi)*dSigma;
696 s = xn * Coeff[0] + yn * Coeff[1] + zn * Coeff[2];
697 d1 = Coeff[0] * x + Coeff[1] * y + Coeff[2] * z;
702 LocIx += (x - Coeff[0] * d1 / 2.0) * ds;
703 LocIy += (y - Coeff[1] * d1 / 2.0) * ds;
704 LocIz += (z - Coeff[2] * d1 / 2.0) * ds;
705 px = x - Coeff[0] * d1;
706 py = y - Coeff[1] * d1;
707 pz = z - Coeff[2] * d1;
708 xi = (px * px * d1) + (px * Coeff[0]* d2) + (Coeff[0] * Coeff[0] * d3);
709 yi = (py * py * d1) + (py * Coeff[1] * d2) + (Coeff[1] * Coeff[1] * d3);
710 zi = pz * pz * d1 + pz * Coeff[2] * d2 + (Coeff[2] * Coeff[2] * d3);
711 LocIxx += (yi + zi) * s;
712 LocIyy += (xi + zi) * s;
713 LocIzz += (xi + yi) * s;
715 xi = (py * pz * d1) + (py * Coeff[2] * d2) + (pz * Coeff[1] * d2) + (Coeff[1] * Coeff[2] * d3);
716 yi = (px * pz * d1) + (pz * Coeff[0] * d2) + (px * Coeff[2] * d2) + (Coeff[0] * Coeff[2] * d3);
717 zi = (px * py * d1) + (px * Coeff[1] * d2) + (py * Coeff[0] * d2) + (Coeff[0] * Coeff[1] * d3);
723 CVolu += LocVolu * ur;
747 if(Abs(Volu) >= EPS_DIM)
751 Ix = Coeff[0] + Ix/Volu;
752 Iy = Coeff[1] + Iy/Volu;
753 Iz = Coeff[2] + Iz/Volu;
761 G.SetCoord (Ix, Iy, Iz);
766 G.SetCoord(0.,0.,0.);
769 Inertia.SetCols (gp_XYZ (Ixx, Ixy, Ixz),
770 gp_XYZ (Ixy, Iyy, Iyz),
771 gp_XYZ (Ixz, Iyz, Izz));
775 GProp_VGProps::GProp_VGProps(){}
777 GProp_VGProps::GProp_VGProps(Face& S, const gp_Pnt& VLocation, const Standard_Real Eps){
778 SetLocation(VLocation);
782 GProp_VGProps::GProp_VGProps(Face& S, Domain& D, const gp_Pnt& VLocation, const Standard_Real Eps){
783 SetLocation(VLocation);
787 GProp_VGProps::GProp_VGProps(Face& S, Domain& D, const gp_Pnt& VLocation){
788 SetLocation(VLocation);
792 GProp_VGProps::GProp_VGProps(const Face& S, const gp_Pnt& VLocation){
793 SetLocation(VLocation);
797 GProp_VGProps::GProp_VGProps(Face& S, const gp_Pnt& O, const gp_Pnt& VLocation, const Standard_Real Eps){
798 SetLocation(VLocation);
802 GProp_VGProps::GProp_VGProps(Face& S, Domain& D, const gp_Pnt& O, const gp_Pnt& VLocation, const Standard_Real Eps){
803 SetLocation(VLocation);
807 GProp_VGProps::GProp_VGProps(const Face& S, const gp_Pnt& O, const gp_Pnt& VLocation){
808 SetLocation(VLocation);
812 GProp_VGProps::GProp_VGProps(Face& S, Domain& D, const gp_Pnt& O, const gp_Pnt& VLocation){
813 SetLocation(VLocation);
817 GProp_VGProps::GProp_VGProps(Face& S, const gp_Pln& Pl, const gp_Pnt& VLocation, const Standard_Real Eps){
818 SetLocation(VLocation);
822 GProp_VGProps::GProp_VGProps(Face& S, Domain& D, const gp_Pln& Pl, const gp_Pnt& VLocation, const Standard_Real Eps){
823 SetLocation(VLocation);
827 GProp_VGProps::GProp_VGProps(const Face& S, const gp_Pln& Pl, const gp_Pnt& VLocation){
828 SetLocation(VLocation);
832 GProp_VGProps::GProp_VGProps(Face& S, Domain& D, const gp_Pln& Pl, const gp_Pnt& VLocation){
833 SetLocation(VLocation);
837 void GProp_VGProps::SetLocation(const gp_Pnt& VLocation){
841 Standard_Real GProp_VGProps::Perform(Face& S, const Standard_Real Eps){
842 Standard_Real Coeff[] = {0., 0., 0.};
843 return myEpsilon = Compute(S,Standard_True,Coeff,loc,dim,g,inertia,Eps);
846 Standard_Real GProp_VGProps::Perform(Face& S, Domain& D, const Standard_Real Eps){
847 Standard_Real Coeff[] = {0., 0., 0.};
848 return myEpsilon = Compute(S,D,Standard_True,Coeff,loc,dim,g,inertia,Eps);
851 void GProp_VGProps::Perform(const Face& S){
852 Standard_Real Coeff[] = {0., 0., 0.};
853 Compute(S,Standard_True,Coeff,loc,dim,g,inertia);
858 void GProp_VGProps::Perform(Face& S, Domain& D){
859 Standard_Real Coeff[] = {0., 0., 0.};
860 Compute(S,D,Standard_True,Coeff,loc,dim,g,inertia);
865 Standard_Real GProp_VGProps::Perform(Face& S, const gp_Pnt& O, const Standard_Real Eps){
866 Standard_Real xloc, yloc, zloc;
867 loc.Coord(xloc, yloc, zloc);
868 Standard_Real Coeff[3];
869 O.Coord (Coeff[0], Coeff[1], Coeff[2]);
870 Coeff[0] -= xloc; Coeff[1] -= yloc; Coeff[2] -= zloc;
871 return myEpsilon = Compute(S,Standard_True,Coeff,loc,dim,g,inertia,Eps);
874 Standard_Real GProp_VGProps::Perform(Face& S, Domain& D, const gp_Pnt& O, const Standard_Real Eps){
875 Standard_Real xloc, yloc, zloc;
876 loc.Coord(xloc, yloc, zloc);
877 Standard_Real Coeff[3];
878 O.Coord (Coeff[0], Coeff[1], Coeff[2]);
879 Coeff[0] -= xloc; Coeff[1] -= yloc; Coeff[2] -= zloc;
880 return myEpsilon = Compute(S,D,Standard_True,Coeff,loc,dim,g,inertia,Eps);
883 void GProp_VGProps::Perform(const Face& S, const gp_Pnt& O){
884 Standard_Real xloc, yloc, zloc;
885 loc.Coord(xloc, yloc, zloc);
886 Standard_Real Coeff[3];
887 O.Coord (Coeff[0], Coeff[1], Coeff[2]);
888 Coeff[0] -= xloc; Coeff[1] -= yloc; Coeff[2] -= zloc;
889 Compute(S,Standard_True,Coeff,loc,dim,g,inertia);
894 void GProp_VGProps::Perform(Face& S, Domain& D, const gp_Pnt& O){
895 Standard_Real xloc, yloc, zloc;
896 loc.Coord(xloc, yloc, zloc);
897 Standard_Real Coeff[3];
898 O.Coord (Coeff[0], Coeff[1], Coeff[2]);
899 Coeff[0] -= xloc; Coeff[1] -= yloc; Coeff[2] -= zloc;
900 Compute(S,D,Standard_True,Coeff,loc,dim,g,inertia);
905 Standard_Real GProp_VGProps::Perform(Face& S, const gp_Pln& Pl, const Standard_Real Eps){
906 Standard_Real xloc, yloc, zloc;
907 loc.Coord (xloc, yloc, zloc);
908 Standard_Real Coeff[4];
909 Pl.Coefficients (Coeff[0], Coeff[1],Coeff[2],Coeff[3]);
910 Coeff[3] = Coeff[3] - Coeff[0]*xloc - Coeff[1]*yloc - Coeff[2]*zloc;
911 return myEpsilon = Compute(S,Standard_False,Coeff,loc,dim,g,inertia,Eps);
914 Standard_Real GProp_VGProps::Perform(Face& S, Domain& D, const gp_Pln& Pl, const Standard_Real Eps){
915 Standard_Real xloc, yloc, zloc;
916 loc.Coord (xloc, yloc, zloc);
917 Standard_Real Coeff[4];
918 Pl.Coefficients (Coeff[0], Coeff[1],Coeff[2],Coeff[3]);
919 Coeff[3] = Coeff[3] - Coeff[0]*xloc - Coeff[1]*yloc - Coeff[2]*zloc;
920 return myEpsilon = Compute(S,D,Standard_False,Coeff,loc,dim,g,inertia,Eps);
923 void GProp_VGProps::Perform(const Face& S, const gp_Pln& Pl){
924 Standard_Real xloc, yloc, zloc;
925 loc.Coord (xloc, yloc, zloc);
926 Standard_Real Coeff[4];
927 Pl.Coefficients (Coeff[0], Coeff[1],Coeff[2],Coeff[3]);
928 Coeff[3] = Coeff[3] - Coeff[0]*xloc - Coeff[1]*yloc - Coeff[2]*zloc;
929 Compute(S,Standard_False,Coeff,loc,dim,g,inertia);
934 void GProp_VGProps::Perform(Face& S, Domain& D, const gp_Pln& Pl){
935 Standard_Real xloc, yloc, zloc;
936 loc.Coord (xloc, yloc, zloc);
937 Standard_Real Coeff[4];
938 Pl.Coefficients (Coeff[0], Coeff[1],Coeff[2],Coeff[3]);
939 Coeff[3] = Coeff[3] - Coeff[0]*xloc - Coeff[1]*yloc - Coeff[2]*zloc;
940 Compute(S,D,Standard_False,Coeff,loc,dim,g,inertia);
945 Standard_Real GProp_VGProps::GetEpsilon(){