1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and / or modify it
7 // under the terms of the GNU Lesser General Public version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <Standard_NotImplemented.hxx>
16 #include <math_Vector.hxx>
18 #include <gp_Pnt2d.hxx>
19 #include <gp_Vec2d.hxx>
23 #include <TColStd_Array1OfReal.hxx>
24 #include <Precision.hxx>
28 void operator=(const math_Vector&){}
30 HMath_Vector(){ pvec = 0;}
31 HMath_Vector(math_Vector* pv){ pvec = pv;}
32 ~HMath_Vector(){ if(pvec != 0) delete pvec;}
33 void operator=(math_Vector* pv){ if(pvec != pv && pvec != 0) delete pvec; pvec = pv;}
34 Standard_Real& operator()(Standard_Integer i){ return (*pvec).operator()(i);}
35 const Standard_Real& operator()(Standard_Integer i) const{ return (*pvec).operator()(i);}
36 const math_Vector* operator->() const{ return pvec;}
37 math_Vector* operator->(){ return pvec;}
38 math_Vector* Vector(){ return pvec;}
39 math_Vector* Init(Standard_Real v, Standard_Integer i = 0, Standard_Integer iEnd = 0){
40 if(pvec == 0) return pvec;
41 if(iEnd - i == 0) pvec->Init(v);
42 else { Standard_Integer End = (iEnd <= pvec->Upper()) ? iEnd : pvec->Upper();
43 for(; i <= End; i++) pvec->operator()(i) = v; }
48 static Standard_Real EPS_PARAM = 1.e-12;
49 static Standard_Real EPS_DIM = 1.e-20;
50 static Standard_Real ERROR_ALGEBR_RATIO = 2.0/3.0;
52 static Standard_Integer GPM = 61;
53 static Standard_Integer SUBS_POWER = 32;
54 static Standard_Integer SM = 1953;
56 static math_Vector LGaussP0(1,GPM);
57 static math_Vector LGaussW0(1,GPM);
58 static math_Vector LGaussP1(1,RealToInt(Ceiling(ERROR_ALGEBR_RATIO*GPM)));
59 static math_Vector LGaussW1(1,RealToInt(Ceiling(ERROR_ALGEBR_RATIO*GPM)));
61 static math_Vector* LGaussP[] = {&LGaussP0,&LGaussP1};
62 static math_Vector* LGaussW[] = {&LGaussW0,&LGaussW1};
64 static HMath_Vector L1 = new math_Vector(1,SM,0.0);
65 static HMath_Vector L2 = new math_Vector(1,SM,0.0);
66 static HMath_Vector DimL = new math_Vector(1,SM,0.0);
67 static HMath_Vector ErrL = new math_Vector(1,SM,0.0);
68 static HMath_Vector ErrUL = new math_Vector(1,SM,0.0);
69 static HMath_Vector IxL = new math_Vector(1,SM,0.0);
70 static HMath_Vector IyL = new math_Vector(1,SM,0.0);
71 static HMath_Vector IzL = new math_Vector(1,SM,0.0);
72 static HMath_Vector IxxL = new math_Vector(1,SM,0.0);
73 static HMath_Vector IyyL = new math_Vector(1,SM,0.0);
74 static HMath_Vector IzzL = new math_Vector(1,SM,0.0);
75 static HMath_Vector IxyL = new math_Vector(1,SM,0.0);
76 static HMath_Vector IxzL = new math_Vector(1,SM,0.0);
77 static HMath_Vector IyzL = new math_Vector(1,SM,0.0);
79 static math_Vector UGaussP0(1,GPM);
80 static math_Vector UGaussW0(1,GPM);
81 static math_Vector UGaussP1(1,RealToInt(Ceiling(ERROR_ALGEBR_RATIO*GPM)));
82 static math_Vector UGaussW1(1,RealToInt(Ceiling(ERROR_ALGEBR_RATIO*GPM)));
84 static math_Vector* UGaussP[] = {&UGaussP0,&UGaussP1};
85 static math_Vector* UGaussW[] = {&UGaussW0,&UGaussW1};
87 static HMath_Vector U1 = new math_Vector(1,SM,0.0);
88 static HMath_Vector U2 = new math_Vector(1,SM,0.0);
89 static HMath_Vector DimU = new math_Vector(1,SM,0.0);
90 static HMath_Vector ErrU = new math_Vector(1,SM,0.0);
91 static HMath_Vector IxU = new math_Vector(1,SM,0.0);
92 static HMath_Vector IyU = new math_Vector(1,SM,0.0);
93 static HMath_Vector IzU = new math_Vector(1,SM,0.0);
94 static HMath_Vector IxxU = new math_Vector(1,SM,0.0);
95 static HMath_Vector IyyU = new math_Vector(1,SM,0.0);
96 static HMath_Vector IzzU = new math_Vector(1,SM,0.0);
97 static HMath_Vector IxyU = new math_Vector(1,SM,0.0);
98 static HMath_Vector IxzU = new math_Vector(1,SM,0.0);
99 static HMath_Vector IyzU = new math_Vector(1,SM,0.0);
101 static inline Standard_Real MultiplicationInf(Standard_Real theMA, Standard_Real theMB)
103 if((theMA == 0.0) || (theMB == 0.0)) //strictly zerro (without any tolerances)
106 if(Precision::IsPositiveInfinite(theMA))
109 return -Precision::Infinite();
111 return Precision::Infinite();
114 if(Precision::IsPositiveInfinite(theMB))
117 return -Precision::Infinite();
119 return Precision::Infinite();
122 if(Precision::IsNegativeInfinite(theMA))
125 return +Precision::Infinite();
127 return -Precision::Infinite();
130 if(Precision::IsNegativeInfinite(theMB))
133 return +Precision::Infinite();
135 return -Precision::Infinite();
138 return (theMA * theMB);
141 static inline Standard_Real AdditionInf(Standard_Real theMA, Standard_Real theMB)
143 if(Precision::IsPositiveInfinite(theMA))
145 if(Precision::IsNegativeInfinite(theMB))
148 return Precision::Infinite();
151 if(Precision::IsPositiveInfinite(theMB))
153 if(Precision::IsNegativeInfinite(theMA))
156 return Precision::Infinite();
159 if(Precision::IsNegativeInfinite(theMA))
161 if(Precision::IsPositiveInfinite(theMB))
164 return -Precision::Infinite();
167 if(Precision::IsNegativeInfinite(theMB))
169 if(Precision::IsPositiveInfinite(theMA))
172 return -Precision::Infinite();
175 return (theMA + theMB);
178 static inline Standard_Real Multiplication(Standard_Real theMA, Standard_Real theMB)
180 return (theMA * theMB);
183 static inline Standard_Real Addition(Standard_Real theMA, Standard_Real theMB)
185 return (theMA + theMB);
188 static Standard_Integer FillIntervalBounds(Standard_Real A,
190 const TColStd_Array1OfReal& Knots,
194 Standard_Integer i = 1, iEnd = Knots.Upper(), j = 1, k = 1;
196 for(; i <= iEnd; i++){
197 Standard_Real kn = Knots(i);
202 VA(j++) = VB(k++) = kn;
214 static inline Standard_Integer MaxSubs(Standard_Integer n, Standard_Integer coeff = SUBS_POWER){
215 // return n = IntegerLast()/coeff < n? IntegerLast(): n*coeff + 1;
216 return Min((n * coeff + 1),SM);
219 static Standard_Integer LFillIntervalBounds(Standard_Real A,
221 const TColStd_Array1OfReal& Knots,
222 const Standard_Integer NumSubs)
224 Standard_Integer iEnd = Knots.Upper(), jEnd = L1->Upper();
226 iEnd = MaxSubs(iEnd-1,NumSubs);
227 L1 = new math_Vector(1,iEnd);
228 L2 = new math_Vector(1,iEnd);
229 DimL = new math_Vector(1,iEnd);
230 ErrL = new math_Vector(1,iEnd,0.0);
231 ErrUL = new math_Vector(1,iEnd,0.0);
232 IxL = new math_Vector(1,iEnd);
233 IyL = new math_Vector(1,iEnd);
234 IzL = new math_Vector(1,iEnd);
235 IxxL = new math_Vector(1,iEnd);
236 IyyL = new math_Vector(1,iEnd);
237 IzzL = new math_Vector(1,iEnd);
238 IxyL = new math_Vector(1,iEnd);
239 IxzL = new math_Vector(1,iEnd);
240 IyzL = new math_Vector(1,iEnd);
242 return FillIntervalBounds(A, B, Knots, L1, L2);
245 static Standard_Integer UFillIntervalBounds(Standard_Real A,
247 const TColStd_Array1OfReal& Knots,
248 const Standard_Integer NumSubs)
250 Standard_Integer iEnd = Knots.Upper(), jEnd = U1->Upper();
252 iEnd = MaxSubs(iEnd-1,NumSubs);
253 U1 = new math_Vector(1,iEnd);
254 U2 = new math_Vector(1,iEnd);
255 DimU = new math_Vector(1,iEnd);
256 ErrU = new math_Vector(1,iEnd,0.0);
257 IxU = new math_Vector(1,iEnd);
258 IyU = new math_Vector(1,iEnd);
259 IzU = new math_Vector(1,iEnd);
260 IxxU = new math_Vector(1,iEnd);
261 IyyU = new math_Vector(1,iEnd);
262 IzzU = new math_Vector(1,iEnd);
263 IxyU = new math_Vector(1,iEnd);
264 IxzU = new math_Vector(1,iEnd);
265 IyzU = new math_Vector(1,iEnd);
267 return FillIntervalBounds(A, B, Knots, U1, U2);
270 static Standard_Real CCompute(Face& S,
276 const Standard_Real EpsDim,
277 const Standard_Boolean isErrorCalculation,
278 const Standard_Boolean isVerifyComputation)
280 Standard_Real (*FuncAdd)(Standard_Real, Standard_Real);
281 Standard_Real (*FuncMul)(Standard_Real, Standard_Real);
284 FuncMul = Multiplication;
286 Standard_Boolean isNaturalRestriction = S.NaturalRestriction();
288 Standard_Integer NumSubs = SUBS_POWER;
290 Standard_Real Ix, Iy, Iz, Ixx, Iyy, Izz, Ixy, Ixz, Iyz;
291 Dim = Ix = Iy = Iz = Ixx = Iyy = Izz = Ixy = Ixz = Iyz = 0.0;
292 Standard_Real x, y, z;
293 //boundary curve parametrization
294 Standard_Real l1, l2, lm, lr, l;
295 //Face parametrization in U and V direction
296 Standard_Real BV1, BV2, v;
297 Standard_Real BU1, BU2, u1, u2, um, ur, u;
298 S.Bounds (BU1, BU2, BV1, BV2);
301 if(Precision::IsInfinite(BU1) || Precision::IsInfinite(BU2) ||
302 Precision::IsInfinite(BV1) || Precision::IsInfinite(BV2))
304 FuncAdd = AdditionInf;
305 FuncMul = MultiplicationInf;
309 //location point used to compute the inertia
310 Standard_Real xloc, yloc, zloc;
311 loc.Coord (xloc, yloc, zloc); // use member of parent class
312 //Jacobien (x, y, z) -> (u, v) = ||n||
317 //On the boundary curve u-v
320 Standard_Real Dul; // Dul = Du / Dl
321 Standard_Real CDim[2], CIx, CIy, CIz, CIxx, CIyy, CIzz, CIxy, CIxz, CIyz;
322 Standard_Real LocDim[2], LocIx, LocIy, LocIz, LocIxx, LocIyy, LocIzz, LocIxy, LocIxz, LocIyz;
324 Standard_Real ErrorU, ErrorL, ErrorLMax = 0.0, Eps=0.0, EpsL=0.0, EpsU=0.0;
326 Standard_Integer iD = 0, NbLSubs, iLS, iLSubEnd, iGL, iGLEnd, NbLGaussP[2], LRange[2], iL, kL, kLEnd, IL, JL;
327 Standard_Integer i, NbUSubs, iUS, iUSubEnd, iGU, iGUEnd, NbUGaussP[2], URange[2], iU, kU, kUEnd, IU, JU;
328 Standard_Integer UMaxSubs, LMaxSubs;
329 iGLEnd = isErrorCalculation? 2: 1;
330 for(i = 0; i < 2; i++) {
335 NbUGaussP[0] = S.SIntOrder(EpsDim);
336 NbUGaussP[1] = RealToInt(Ceiling(ERROR_ALGEBR_RATIO*NbUGaussP[0]));
337 math::GaussPoints(NbUGaussP[0],UGaussP0); math::GaussWeights(NbUGaussP[0],UGaussW0);
338 math::GaussPoints(NbUGaussP[1],UGaussP1); math::GaussWeights(NbUGaussP[1],UGaussW1);
340 NbUSubs = S.SUIntSubs();
341 TColStd_Array1OfReal UKnots(1,NbUSubs+1);
344 while (isNaturalRestriction || D.More())
346 if(isNaturalRestriction)
348 NbLGaussP[0] = Min(2*NbUGaussP[0],math::GaussPointsMax());
352 S.Load(D.Value()); ++iD;
353 NbLGaussP[0] = S.LIntOrder(EpsDim);
356 NbLGaussP[1] = RealToInt(Ceiling(ERROR_ALGEBR_RATIO*NbLGaussP[0]));
357 math::GaussPoints(NbLGaussP[0],LGaussP0); math::GaussWeights(NbLGaussP[0],LGaussW0);
358 math::GaussPoints(NbLGaussP[1],LGaussP1); math::GaussWeights(NbLGaussP[1],LGaussW1);
360 NbLSubs = isNaturalRestriction? S.SVIntSubs(): S.LIntSubs();
362 TColStd_Array1OfReal LKnots(1,NbLSubs+1);
363 if(isNaturalRestriction)
371 l1 = S.FirstParameter(); l2 = S.LastParameter();
376 //OCC503(apo): if(Abs(l2-l1) < EPS_PARAM) continue;
377 if(Abs(l2-l1) > EPS_PARAM)
379 iLSubEnd = LFillIntervalBounds(l1, l2, LKnots, NumSubs);
380 LMaxSubs = MaxSubs(iLSubEnd);
381 if(LMaxSubs > DimL.Vector()->Upper())
382 LMaxSubs = DimL.Vector()->Upper();
384 DimL.Init(0.0,1,LMaxSubs); ErrL.Init(0.0,1,LMaxSubs); ErrUL.Init(0.0,1,LMaxSubs);
389 LRange[0] = IL = ErrL->Max();
391 L1(JL) = (L1(IL) + L2(IL))/2.0;
398 if(JL == LMaxSubs || Abs(L2(JL) - L1(JL)) < EPS_PARAM)
401 DimL(JL) = ErrL(JL) = IxL(JL) = IyL(JL) = IzL(JL) =
402 IxxL(JL) = IyyL(JL) = IzzL(JL) = IxyL(JL) = IxzL(JL) = IyzL(JL) = 0.0;
405 EpsL = ErrorL; Eps = EpsL/0.9;
409 for(kL=0; kL < kLEnd; kL++)
412 lm = 0.5*(L2(iLS) + L1(iLS));
413 lr = 0.5*(L2(iLS) - L1(iLS));
414 CIx = CIy = CIz = CIxx = CIyy = CIzz = CIxy = CIxz = CIyz = 0.0;
416 for(iGL=0; iGL < iGLEnd; iGL++)
419 for(iL=1; iL<=NbLGaussP[iGL]; iL++)
421 l = lm + lr*(*LGaussP[iGL])(iL);
422 if(isNaturalRestriction)
424 v = l; u2 = BU2; Dul = (*LGaussW[iGL])(iL);
428 S.D12d (l, Puv, Vuv);
429 Dul = Vuv.Y()*(*LGaussW[iGL])(iL); // Dul = Du / Dl
430 if(Abs(Dul) < EPS_PARAM)
435 //Check on cause out off bounds of value current parameter
451 if(Abs(u2-u1) < EPS_PARAM)
454 iUSubEnd = UFillIntervalBounds(u1, u2, UKnots, NumSubs);
455 UMaxSubs = MaxSubs(iUSubEnd);
456 if(UMaxSubs > DimU.Vector()->Upper())
457 UMaxSubs = DimU.Vector()->Upper();
459 DimU.Init(0.0,1,UMaxSubs); ErrU.Init(0.0,1,UMaxSubs); ErrorU = 0.0;
464 URange[0] = IU = ErrU->Max();
466 U1(JU) = (U1(IU)+U2(IU))/2.0;
473 if(JU == UMaxSubs || Abs(U2(JU) - U1(JU)) < EPS_PARAM)
476 DimU(JU) = ErrU(JU) = IxU(JU) = IyU(JU) = IzU(JU) =
477 IxxU(JU) = IyyU(JU) = IzzU(JU) = IxyU(JU) = IxzU(JU) = IyzU(JU) = 0.0;
481 EpsU = ErrorU; Eps = EpsU*Abs((u2-u1)*Dul)/0.1; EpsL = 0.9*Eps;
485 for(kU=0; kU < kUEnd; kU++)
488 um = 0.5*(U2(iUS) + U1(iUS));
489 ur = 0.5*(U2(iUS) - U1(iUS));
490 LocIx = LocIy = LocIz = LocIxx = LocIyy = LocIzz = LocIxy = LocIxz = LocIyz = 0.0;
491 iGUEnd = iGLEnd - iGL;
492 for(iGU=0; iGU < iGUEnd; iGU++)
495 for(iU=1; iU <= NbUGaussP[iGU]; iU++)
497 u = um + ur*(*UGaussP[iGU])(iU);
498 S.Normal(u, v, Ps, VNor);
499 ds = VNor.Magnitude(); //Jacobien(x,y,z) -> (u,v)=||n||
500 ds *= (*UGaussW[iGU])(iU);
507 x = FuncAdd(x, -xloc);
508 y = FuncAdd(y, -yloc);
509 z = FuncAdd(z, -zloc);
511 const Standard_Real XdS = FuncMul(x, ds);
512 const Standard_Real YdS = FuncMul(y, ds);
513 const Standard_Real ZdS = FuncMul(z, ds);
515 LocIx = FuncAdd(LocIx, XdS);
516 LocIy = FuncAdd(LocIy, YdS);
517 LocIz = FuncAdd(LocIz, ZdS);
518 LocIxy = FuncAdd(LocIxy, FuncMul(x, YdS));
519 LocIyz = FuncAdd(LocIyz, FuncMul(y, ZdS));
520 LocIxz = FuncAdd(LocIxz, FuncMul(x, ZdS));
522 const Standard_Real XXdS = FuncMul(x, XdS);
523 const Standard_Real YYdS = FuncMul(y, YdS);
524 const Standard_Real ZZdS = FuncMul(z, ZdS);
526 LocIxx = FuncAdd(LocIxx, FuncAdd(YYdS, ZZdS));
527 LocIyy = FuncAdd(LocIyy, FuncAdd(XXdS, ZZdS));
528 LocIzz = FuncAdd(LocIzz, FuncAdd(XXdS, YYdS));
532 DimU(iUS) = FuncMul(LocDim[0],ur);
536 ErrU(iUS) = FuncMul(Abs(LocDim[1]-LocDim[0]), ur);
537 IxU(iUS) = FuncMul(LocIx, ur);
538 IyU(iUS) = FuncMul(LocIy, ur);
539 IzU(iUS) = FuncMul(LocIz, ur);
540 IxxU(iUS) = FuncMul(LocIxx, ur);
541 IyyU(iUS) = FuncMul(LocIyy, ur);
542 IzzU(iUS) = FuncMul(LocIzz, ur);
543 IxyU(iUS) = FuncMul(LocIxy, ur);
544 IxzU(iUS) = FuncMul(LocIxz, ur);
545 IyzU(iUS) = FuncMul(LocIyz, ur);
552 ErrorU = ErrU(ErrU->Max());
553 }while((ErrorU - EpsU > 0.0 && EpsU != 0.0) || kUEnd == 1);
556 CDim[iGL] = FuncAdd(CDim[iGL], FuncMul(DimU(i), Dul));
561 ErrUL(iLS) = ErrorU*Abs((u2-u1)*Dul);
564 CIx = FuncAdd(CIx, FuncMul(IxU(i), Dul));
565 CIy = FuncAdd(CIy, FuncMul(IyU(i), Dul));
566 CIz = FuncAdd(CIz, FuncMul(IzU(i), Dul));
567 CIxx = FuncAdd(CIxx, FuncMul(IxxU(i), Dul));
568 CIyy = FuncAdd(CIyy, FuncMul(IyyU(i), Dul));
569 CIzz = FuncAdd(CIzz, FuncMul(IzzU(i), Dul));
570 CIxy = FuncAdd(CIxy, FuncMul(IxyU(i), Dul));
571 CIxz = FuncAdd(CIxz, FuncMul(IxzU(i), Dul));
572 CIyz = FuncAdd(CIyz, FuncMul(IyzU(i), Dul));
577 DimL(iLS) = FuncMul(CDim[0], lr);
579 ErrL(iLS) = FuncAdd(FuncMul(Abs(CDim[1]-CDim[0]),lr), ErrUL(iLS));
581 IxL(iLS) = FuncMul(CIx, lr);
582 IyL(iLS) = FuncMul(CIy, lr);
583 IzL(iLS) = FuncMul(CIz, lr);
584 IxxL(iLS) = FuncMul(CIxx, lr);
585 IyyL(iLS) = FuncMul(CIyy, lr);
586 IzzL(iLS) = FuncMul(CIzz, lr);
587 IxyL(iLS) = FuncMul(CIxy, lr);
588 IxzL(iLS) = FuncMul(CIxz, lr);
589 IyzL(iLS) = FuncMul(CIyz, lr);
591 // Calculate/correct epsilon of computation by current value of Dim
592 //That is need for not spend time for
596 Standard_Real DDim = 0.0;
600 DDim = Abs(DDim*EpsDim);
609 ErrorL = ErrL(ErrL->Max());
610 }while((ErrorL - EpsL > 0.0 && isVerifyComputation) || kLEnd == 1);
614 Dim = FuncAdd(Dim, DimL(i));
615 Ix = FuncAdd(Ix, IxL(i));
616 Iy = FuncAdd(Iy, IyL(i));
617 Iz = FuncAdd(Iz, IzL(i));
618 Ixx = FuncAdd(Ixx, IxxL(i));
619 Iyy = FuncAdd(Iyy, IyyL(i));
620 Izz = FuncAdd(Izz, IzzL(i));
621 Ixy = FuncAdd(Ixy, IxyL(i));
622 Ixz = FuncAdd(Ixz, IxzL(i));
623 Iyz = FuncAdd(Iyz, IyzL(i));
626 ErrorLMax = Max(ErrorLMax, ErrorL);
629 if(isNaturalRestriction)
635 if(Abs(Dim) >= EPS_DIM)
640 g.SetCoord (Ix, Iy, Iz);
645 g.SetCoord (0., 0.,0.);
648 inertia = gp_Mat (gp_XYZ (Ixx, -Ixy, -Ixz),
649 gp_XYZ (-Ixy, Iyy, -Iyz),
650 gp_XYZ (-Ixz, -Iyz, Izz));
653 Eps = Dim != 0.0? ErrorLMax/Abs(Dim): 0.0;
660 static Standard_Real Compute(Face& S, const gp_Pnt& loc, Standard_Real& Dim, gp_Pnt& g, gp_Mat& inertia,
661 Standard_Real EpsDim)
663 Standard_Boolean isErrorCalculation = 0.0 > EpsDim || EpsDim < 0.001? 1: 0;
664 Standard_Boolean isVerifyComputation = 0.0 < EpsDim && EpsDim < 0.001? 1: 0;
665 EpsDim = Abs(EpsDim);
667 return CCompute(S,D,loc,Dim,g,inertia,EpsDim,isErrorCalculation,isVerifyComputation);
670 static Standard_Real Compute(Face& S, Domain& D, const gp_Pnt& loc, Standard_Real& Dim, gp_Pnt& g, gp_Mat& inertia,
671 Standard_Real EpsDim)
673 Standard_Boolean isErrorCalculation = 0.0 > EpsDim || EpsDim < 0.001? 1: 0;
674 Standard_Boolean isVerifyComputation = 0.0 < EpsDim && EpsDim < 0.001? 1: 0;
675 EpsDim = Abs(EpsDim);
676 return CCompute(S,D,loc,Dim,g,inertia,EpsDim,isErrorCalculation,isVerifyComputation);
679 static void Compute(Face& S, Domain& D, const gp_Pnt& loc, Standard_Real& dim, gp_Pnt& g, gp_Mat& inertia)
681 Standard_Real (*FuncAdd)(Standard_Real, Standard_Real);
682 Standard_Real (*FuncMul)(Standard_Real, Standard_Real);
685 FuncMul = Multiplication;
687 Standard_Real Ix, Iy, Iz, Ixx, Iyy, Izz, Ixy, Ixz, Iyz;
688 dim = Ix = Iy = Iz = Ixx = Iyy = Izz = Ixy = Ixz = Iyz = 0.0;
690 Standard_Real x, y, z;
691 Standard_Integer NbCGaussgp_Pnts = 0;
693 Standard_Real l1, l2, lm, lr, l; //boundary curve parametrization
694 Standard_Real v1, v2, vm, vr, v; //Face parametrization in v direction
695 Standard_Real u1, u2, um, ur, u;
696 Standard_Real ds; //Jacobien (x, y, z) -> (u, v) = ||n||
698 gp_Pnt P; //On the Face
701 gp_Pnt2d Puv; //On the boundary curve u-v
703 Standard_Real Dul; // Dul = Du / Dl
704 Standard_Real CArea, CIx, CIy, CIz, CIxx, CIyy, CIzz, CIxy, CIxz, CIyz;
705 Standard_Real LocArea, LocIx, LocIy, LocIz, LocIxx, LocIyy, LocIzz, LocIxy,
709 S.Bounds (u1, u2, v1, v2);
711 if(Precision::IsInfinite(u1) || Precision::IsInfinite(u2) ||
712 Precision::IsInfinite(v1) || Precision::IsInfinite(v2))
714 FuncAdd = AdditionInf;
715 FuncMul = MultiplicationInf;
719 Standard_Integer NbUGaussgp_Pnts = Min(S.UIntegrationOrder (),
720 math::GaussPointsMax());
721 Standard_Integer NbVGaussgp_Pnts = Min(S.VIntegrationOrder (),
722 math::GaussPointsMax());
724 Standard_Integer NbGaussgp_Pnts = Max(NbUGaussgp_Pnts, NbVGaussgp_Pnts);
726 //Number of Gauss points for the integration
728 math_Vector GaussSPV (1, NbGaussgp_Pnts);
729 math_Vector GaussSWV (1, NbGaussgp_Pnts);
730 math::GaussPoints (NbGaussgp_Pnts,GaussSPV);
731 math::GaussWeights (NbGaussgp_Pnts,GaussSWV);
734 //location point used to compute the inertia
735 Standard_Real xloc, yloc, zloc;
736 loc.Coord (xloc, yloc, zloc);
741 NbCGaussgp_Pnts = Min(S.IntegrationOrder (), math::GaussPointsMax());
743 math_Vector GaussCP (1, NbCGaussgp_Pnts);
744 math_Vector GaussCW (1, NbCGaussgp_Pnts);
745 math::GaussPoints (NbCGaussgp_Pnts,GaussCP);
746 math::GaussWeights (NbCGaussgp_Pnts,GaussCW);
749 CIx = CIy = CIz = CIxx = CIyy = CIzz = CIxy = CIxz = CIyz = 0.0;
750 l1 = S.FirstParameter ();
751 l2 = S.LastParameter ();
752 lm = 0.5 * (l2 + l1);
753 lr = 0.5 * (l2 - l1);
755 Puv = S.Value2d (lm);
757 Puv = S.Value2d (lr);
760 for (Standard_Integer i = 1; i <= NbCGaussgp_Pnts; i++) {
761 l = lm + lr * GaussCP (i);
767 um = 0.5 * (u2 + u1);
768 ur = 0.5 * (u2 - u1);
769 LocArea = LocIx = LocIy = LocIz = LocIxx = LocIyy = LocIzz =
770 LocIxy = LocIxz = LocIyz = 0.0;
771 for (Standard_Integer j = 1; j <= NbGaussgp_Pnts; j++) {
772 u = FuncAdd(um, FuncMul(ur, GaussSPV (j)));
773 S.Normal (u, v, P, VNor);
774 ds = VNor.Magnitude(); //normal.Magnitude
775 ds = FuncMul(ds, Dul) * GaussSWV (j);
776 LocArea = FuncAdd(LocArea, ds);
779 x = FuncAdd(x, -xloc);
780 y = FuncAdd(y, -yloc);
781 z = FuncAdd(z, -zloc);
783 const Standard_Real XdS = FuncMul(x, ds);
784 const Standard_Real YdS = FuncMul(y, ds);
785 const Standard_Real ZdS = FuncMul(z, ds);
787 LocIx = FuncAdd(LocIx, XdS);
788 LocIy = FuncAdd(LocIy, YdS);
789 LocIz = FuncAdd(LocIz, ZdS);
790 LocIxy = FuncAdd(LocIxy, FuncMul(x, YdS));
791 LocIyz = FuncAdd(LocIyz, FuncMul(y, ZdS));
792 LocIxz = FuncAdd(LocIxz, FuncMul(x, ZdS));
794 const Standard_Real XXdS = FuncMul(x, XdS);
795 const Standard_Real YYdS = FuncMul(y, YdS);
796 const Standard_Real ZZdS = FuncMul(z, ZdS);
798 LocIxx = FuncAdd(LocIxx, FuncAdd(YYdS, ZZdS));
799 LocIyy = FuncAdd(LocIyy, FuncAdd(XXdS, ZZdS));
800 LocIzz = FuncAdd(LocIzz, FuncAdd(XXdS, YYdS));
803 CArea = FuncAdd(CArea, FuncMul(LocArea, ur));
804 CIx = FuncAdd(CIx, FuncMul(LocIx, ur));
805 CIy = FuncAdd(CIy, FuncMul(LocIy, ur));
806 CIz = FuncAdd(CIz, FuncMul(LocIz, ur));
807 CIxx = FuncAdd(CIxx, FuncMul(LocIxx, ur));
808 CIyy = FuncAdd(CIyy, FuncMul(LocIyy, ur));
809 CIzz = FuncAdd(CIzz, FuncMul(LocIzz, ur));
810 CIxy = FuncAdd(CIxy, FuncMul(LocIxy, ur));
811 CIxz = FuncAdd(CIxz, FuncMul(LocIxz, ur));
812 CIyz = FuncAdd(CIyz, FuncMul(LocIyz, ur));
815 dim = FuncAdd(dim, FuncMul(CArea, lr));
816 Ix = FuncAdd(Ix, FuncMul(CIx, lr));
817 Iy = FuncAdd(Iy, FuncMul(CIy, lr));
818 Iz = FuncAdd(Iz, FuncMul(CIz, lr));
819 Ixx = FuncAdd(Ixx, FuncMul(CIxx, lr));
820 Iyy = FuncAdd(Iyy, FuncMul(CIyy, lr));
821 Izz = FuncAdd(Izz, FuncMul(CIzz, lr));
822 Ixy = FuncAdd(Ixy, FuncMul(CIxy, lr));
823 Ixz = FuncAdd(Iyz, FuncMul(CIxz, lr));
824 Iyz = FuncAdd(Ixz, FuncMul(CIyz, lr));
828 if (Abs(dim) >= EPS_DIM) {
832 g.SetCoord (Ix, Iy, Iz);
836 g.SetCoord (0., 0.,0.);
839 inertia = gp_Mat (gp_XYZ (Ixx, -Ixy, -Ixz),
840 gp_XYZ (-Ixy, Iyy, -Iyz),
841 gp_XYZ (-Ixz, -Iyz, Izz));
844 static void Compute(const Face& S,
850 Standard_Real (*FuncAdd)(Standard_Real, Standard_Real);
851 Standard_Real (*FuncMul)(Standard_Real, Standard_Real);
854 FuncMul = Multiplication;
856 Standard_Real Ix, Iy, Iz, Ixx, Iyy, Izz, Ixy, Ixz, Iyz;
857 dim = Ix = Iy = Iz = Ixx = Iyy = Izz = Ixy = Ixz = Iyz = 0.0;
859 Standard_Real LowerU, UpperU, LowerV, UpperV;
860 S.Bounds (LowerU, UpperU, LowerV, UpperV);
862 if(Precision::IsInfinite(LowerU) || Precision::IsInfinite(UpperU) ||
863 Precision::IsInfinite(LowerV) || Precision::IsInfinite(UpperV))
865 FuncAdd = AdditionInf;
866 FuncMul = MultiplicationInf;
869 Standard_Integer UOrder = Min(S.UIntegrationOrder (),
870 math::GaussPointsMax());
871 Standard_Integer VOrder = Min(S.VIntegrationOrder (),
872 math::GaussPointsMax());
875 Standard_Real dsi, ds;
876 Standard_Real ur, um, u, vr, vm, v;
877 Standard_Real x, y, z;
878 Standard_Real Ixi, Iyi, Izi, Ixxi, Iyyi, Izzi, Ixyi, Ixzi, Iyzi;
879 Standard_Real xloc, yloc, zloc;
880 loc.Coord (xloc, yloc, zloc);
882 Standard_Integer i, j;
883 math_Vector GaussPU (1, UOrder); //gauss points and weights
884 math_Vector GaussWU (1, UOrder);
885 math_Vector GaussPV (1, VOrder);
886 math_Vector GaussWV (1, VOrder);
888 //Recuperation des points de Gauss dans le fichier GaussPoints.
889 math::GaussPoints (UOrder,GaussPU);
890 math::GaussWeights (UOrder,GaussWU);
891 math::GaussPoints (VOrder,GaussPV);
892 math::GaussWeights (VOrder,GaussWV);
894 // Calcul des integrales aux points de gauss :
895 um = 0.5 * FuncAdd(UpperU, LowerU);
896 vm = 0.5 * FuncAdd(UpperV, LowerV);
897 ur = 0.5 * FuncAdd(UpperU, -LowerU);
898 vr = 0.5 * FuncAdd(UpperV, -LowerV);
900 for (j = 1; j <= VOrder; j++) {
901 v = FuncAdd(vm, FuncMul(vr, GaussPV(j)));
902 dsi = Ixi = Iyi = Izi = Ixxi = Iyyi = Izzi = Ixyi = Ixzi = Iyzi = 0.0;
904 for (i = 1; i <= UOrder; i++) {
905 u = FuncAdd(um, FuncMul(ur, GaussPU (i)));
906 S.Normal (u, v, P, VNor);
907 ds = FuncMul(VNor.Magnitude(), GaussWU (i));
910 x = FuncAdd(x, -xloc);
911 y = FuncAdd(y, -yloc);
912 z = FuncAdd(z, -zloc);
914 dsi = FuncAdd(dsi, ds);
916 const Standard_Real XdS = FuncMul(x, ds);
917 const Standard_Real YdS = FuncMul(y, ds);
918 const Standard_Real ZdS = FuncMul(z, ds);
920 Ixi = FuncAdd(Ixi, XdS);
921 Iyi = FuncAdd(Iyi, YdS);
922 Izi = FuncAdd(Izi, ZdS);
923 Ixyi = FuncAdd(Ixyi, FuncMul(x, YdS));
924 Iyzi = FuncAdd(Iyzi, FuncMul(y, ZdS));
925 Ixzi = FuncAdd(Ixzi, FuncMul(x, ZdS));
927 const Standard_Real XXdS = FuncMul(x, XdS);
928 const Standard_Real YYdS = FuncMul(y, YdS);
929 const Standard_Real ZZdS = FuncMul(z, ZdS);
931 Ixxi = FuncAdd(Ixxi, FuncAdd(YYdS, ZZdS));
932 Iyyi = FuncAdd(Iyyi, FuncAdd(XXdS, ZZdS));
933 Izzi = FuncAdd(Izzi, FuncAdd(XXdS, YYdS));
936 dim = FuncAdd(dim, FuncMul(dsi, GaussWV (j)));
937 Ix = FuncAdd(Ix, FuncMul(Ixi, GaussWV (j)));
938 Iy = FuncAdd(Iy, FuncMul(Iyi, GaussWV (j)));
939 Iz = FuncAdd(Iz, FuncMul(Izi, GaussWV (j)));
940 Ixx = FuncAdd(Ixx, FuncMul(Ixxi, GaussWV (j)));
941 Iyy = FuncAdd(Iyy, FuncMul(Iyyi, GaussWV (j)));
942 Izz = FuncAdd(Izz, FuncMul(Izzi, GaussWV (j)));
943 Ixy = FuncAdd(Ixy, FuncMul(Ixyi, GaussWV (j)));
944 Iyz = FuncAdd(Iyz, FuncMul(Iyzi, GaussWV (j)));
945 Ixz = FuncAdd(Ixz, FuncMul(Ixzi, GaussWV (j)));
948 vr = FuncMul(vr, ur);
949 Ixx = FuncMul(vr, Ixx);
950 Iyy = FuncMul(vr, Iyy);
951 Izz = FuncMul(vr, Izz);
952 Ixy = FuncMul(vr, Ixy);
953 Ixz = FuncMul(vr, Ixz);
954 Iyz = FuncMul(vr, Iyz);
956 if (Abs(dim) >= EPS_DIM)
962 g.SetCoord (Ix, Iy, Iz);
967 g.SetCoord (0.,0.,0.);
970 inertia = gp_Mat (gp_XYZ ( Ixx, -Ixy, -Ixz),
971 gp_XYZ (-Ixy, Iyy, -Iyz),
972 gp_XYZ (-Ixz, -Iyz, Izz));
975 GProp_SGProps::GProp_SGProps(){}
977 GProp_SGProps::GProp_SGProps (const Face& S,
978 const gp_Pnt& SLocation
981 SetLocation(SLocation);
985 GProp_SGProps::GProp_SGProps (Face& S,
987 const gp_Pnt& SLocation
990 SetLocation(SLocation);
994 GProp_SGProps::GProp_SGProps(Face& S, const gp_Pnt& SLocation, const Standard_Real Eps){
995 SetLocation(SLocation);
999 GProp_SGProps::GProp_SGProps(Face& S, Domain& D, const gp_Pnt& SLocation, const Standard_Real Eps){
1000 SetLocation(SLocation);
1004 void GProp_SGProps::SetLocation(const gp_Pnt& SLocation){
1008 void GProp_SGProps::Perform(const Face& S){
1009 Compute(S,loc,dim,g,inertia);
1014 void GProp_SGProps::Perform(Face& S, Domain& D){
1015 Compute(S,D,loc,dim,g,inertia);
1020 Standard_Real GProp_SGProps::Perform(Face& S, const Standard_Real Eps){
1021 return myEpsilon = Compute(S,loc,dim,g,inertia,Eps);
1024 Standard_Real GProp_SGProps::Perform(Face& S, Domain& D, const Standard_Real Eps){
1025 return myEpsilon = Compute(S,D,loc,dim,g,inertia,Eps);
1029 Standard_Real GProp_SGProps::GetEpsilon(){