1 // Copyright (c) 2008-2015 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Precision.hxx>
16 #include <TColStd_Array1OfReal.hxx>
17 #include <Standard_Assert.hxx>
18 #include <BRepGProp_Face.hxx>
19 #include <BRepGProp_Domain.hxx>
20 #include <BRepGProp_Gauss.hxx>
22 // If the following is defined the error of algorithm is calculated by static moments
27 // Minimal value of interval's range for computation | minimal value of "dim" | ...
28 static const Standard_Real EPS_PARAM = 1.e-12;
29 static const Standard_Real EPS_DIM = 1.e-30;
30 static const Standard_Real ERROR_ALGEBR_RATIO = 2.0 / 3.0;
32 // Maximum of GaussPoints on a subinterval and maximum of subintervals
33 static const Standard_Integer GPM = math::GaussPointsMax();
34 static const Standard_Integer SUBS_POWER = 32;
35 static const Standard_Integer SM = SUBS_POWER * GPM + 1;
37 // Auxiliary inner functions to perform arithmetic operations.
38 static Standard_Real Add(const Standard_Real theA, const Standard_Real theB)
43 static Standard_Real AddInf(const Standard_Real theA, const Standard_Real theB)
45 if (Precision::IsPositiveInfinite(theA))
47 if (Precision::IsNegativeInfinite(theB))
50 return Precision::Infinite();
53 if (Precision::IsPositiveInfinite(theB))
55 if (Precision::IsNegativeInfinite(theA))
58 return Precision::Infinite();
61 if (Precision::IsNegativeInfinite(theA))
63 if (Precision::IsPositiveInfinite(theB))
66 return -Precision::Infinite();
69 if (Precision::IsNegativeInfinite(theB))
71 if (Precision::IsPositiveInfinite(theA))
74 return -Precision::Infinite();
80 static Standard_Real Mult(const Standard_Real theA, const Standard_Real theB)
85 static Standard_Real MultInf(const Standard_Real theA, const Standard_Real theB)
87 if ((theA == 0.0) || (theB == 0.0)) //strictly zerro (without any tolerances)
90 if (Precision::IsPositiveInfinite(theA))
93 return -Precision::Infinite();
95 return Precision::Infinite();
98 if (Precision::IsPositiveInfinite(theB))
101 return -Precision::Infinite();
103 return Precision::Infinite();
106 if (Precision::IsNegativeInfinite(theA))
109 return +Precision::Infinite();
111 return -Precision::Infinite();
114 if (Precision::IsNegativeInfinite(theB))
117 return +Precision::Infinite();
119 return -Precision::Infinite();
126 //=======================================================================
127 //function : BRepGProp_Gauss::Inert::Inert
128 //purpose : Constructor
129 //=======================================================================
130 BRepGProp_Gauss::Inertia::Inertia()
144 //=======================================================================
145 //function : Inertia::Reset
146 //purpose : Zeroes all values.
147 //=======================================================================
148 void BRepGProp_Gauss::Inertia::Reset()
150 memset(reinterpret_cast<void*>(this), 0, sizeof(BRepGProp_Gauss::Inertia));
153 //=======================================================================
154 //function : BRepGProp_Gauss
155 //purpose : Constructor
156 //=======================================================================
157 BRepGProp_Gauss::BRepGProp_Gauss(const BRepGProp_GaussType theType)
164 //=======================================================================
167 //=======================================================================
168 Standard_Integer BRepGProp_Gauss::MaxSubs(const Standard_Integer theN,
169 const Standard_Integer theCoeff)
171 return IntegerLast() / theCoeff < theN ?
172 IntegerLast() : theN * theCoeff + 1;
175 //=======================================================================
178 //=======================================================================
179 void BRepGProp_Gauss::Init(NCollection_Handle<math_Vector>& theOutVec,
180 const Standard_Real theValue,
181 const Standard_Integer theFirst,
182 const Standard_Integer theLast)
184 if(theLast - theFirst == 0)
186 theOutVec->Init(theValue);
190 for (Standard_Integer i = theFirst; i <= theLast; ++i)
191 theOutVec->Value(i) = theValue;
195 //=======================================================================
196 //function : InitMass
198 //=======================================================================
199 void BRepGProp_Gauss::InitMass(const Standard_Real theValue,
200 const Standard_Integer theFirst,
201 const Standard_Integer theLast,
202 InertiaArray& theArray)
204 if (theArray.IsNull())
207 Standard_Integer aFirst = theFirst;
208 Standard_Integer aLast = theLast;
210 if (theLast - theFirst == 0)
212 aFirst = theArray->Lower();
213 aLast = theArray->Upper();
216 for (Standard_Integer i = aFirst; i <= aLast; ++i)
217 theArray->ChangeValue(i).Mass = theValue;
220 //=======================================================================
221 //function : FillIntervalBounds
223 //=======================================================================
224 Standard_Integer BRepGProp_Gauss::FillIntervalBounds(
225 const Standard_Real theA,
226 const Standard_Real theB,
227 const TColStd_Array1OfReal& theKnots,
228 const Standard_Integer theNumSubs,
229 InertiaArray& theInerts,
230 NCollection_Handle<math_Vector>& theParam1,
231 NCollection_Handle<math_Vector>& theParam2,
232 NCollection_Handle<math_Vector>& theError,
233 NCollection_Handle<math_Vector>& theCommonError)
235 const Standard_Integer aSize =
236 Max(theKnots.Upper(), MaxSubs(theKnots.Upper() - 1, theNumSubs));
238 if (aSize - 1 > theParam1->Upper())
240 theInerts = new NCollection_Array1<Inertia>(1, aSize);
241 theParam1 = new math_Vector(1, aSize);
242 theParam2 = new math_Vector(1, aSize);
243 theError = new math_Vector(1, aSize, 0.0);
245 if (theCommonError.IsNull() == Standard_False)
246 theCommonError = new math_Vector(1, aSize, 0.0);
249 Standard_Integer j = 1, k = 1;
250 theParam1->Value(j++) = theA;
252 const Standard_Integer aLength = theKnots.Upper();
253 for (Standard_Integer i = 1; i <= aLength; ++i)
255 const Standard_Real kn = theKnots(i);
260 theParam1->Value(j++) = kn;
261 theParam2->Value(k++) = kn;
268 theParam2->Value(k) = theB;
274 //=======================================================================
275 //function : computeVInertiaOfElementaryPart
277 //=======================================================================
278 void BRepGProp_Gauss::computeVInertiaOfElementaryPart(
279 const gp_Pnt& thePoint,
280 const gp_Vec& theNormal,
281 const gp_Pnt& theLocation,
282 const Standard_Real theWeight,
283 const Standard_Real theCoeff[],
284 const Standard_Boolean theIsByPoint,
285 BRepGProp_Gauss::Inertia& theOutInertia)
287 Standard_Real x = thePoint.X() - theLocation.X();
288 Standard_Real y = thePoint.Y() - theLocation.Y();
289 Standard_Real z = thePoint.Z() - theLocation.Z();
291 const Standard_Real xn = theNormal.X() * theWeight;
292 const Standard_Real yn = theNormal.Y() * theWeight;
293 const Standard_Real zn = theNormal.Z() * theWeight;
297 ///////////////////// ///////////////////////
298 // OFV code // // Initial code //
299 ///////////////////// ///////////////////////
302 Standard_Real dv = x * xn + y * yn + z * zn; //xyz = x * y * z;
303 theOutInertia.Mass += dv / 3.0; //Ixyi += zn * xyz;
304 theOutInertia.Ix += 0.25 * x * dv; //Iyzi += xn * xyz;
305 theOutInertia.Iy += 0.25 * y * dv; //Ixzi += yn * xyz;
306 theOutInertia.Iz += 0.25 * z * dv; //xi = x * x * x * xn / 3.0;
307 x -= theCoeff[0]; //yi = y * y * y * yn / 3.0;
308 y -= theCoeff[1]; //zi = z * z * z * zn / 3.0;
309 z -= theCoeff[2]; //Ixxi += (yi + zi);
310 dv *= 0.2; //Iyyi += (xi + zi);
311 theOutInertia.Ixy -= x * y * dv; //Izzi += (xi + yi);
312 theOutInertia.Iyz -= y * z * dv; //x -= Coeff[0];
313 theOutInertia.Ixz -= x * z * dv; //y -= Coeff[1];
314 x *= x; //z -= Coeff[2];
315 y *= y; //dv = x * xn + y * yn + z * zn;
317 theOutInertia.Ixx += (y + z) * dv; //Ixi += x * dv;
318 theOutInertia.Iyy += (x + z) * dv; //Iyi += y * dv;
319 theOutInertia.Izz += (x + y) * dv; //Izi += z * dv;
323 const Standard_Real s = xn * theCoeff[0] + yn * theCoeff[1] + zn * theCoeff[2];
325 Standard_Real d1 = theCoeff[0] * x + theCoeff[1] * y + theCoeff[2] * z - theCoeff[3];
326 Standard_Real d2 = d1 * d1;
327 Standard_Real d3 = d1 * d2 / 3.0;
328 Standard_Real dv = s * d1;
330 theOutInertia.Mass += dv;
331 theOutInertia.Ix += (x - (theCoeff[0] * d1 * 0.5)) * dv;
332 theOutInertia.Iy += (y - (theCoeff[1] * d1 * 0.5)) * dv;
333 theOutInertia.Iz += (z - (theCoeff[2] * d1 * 0.5)) * dv;
335 const Standard_Real px = x - theCoeff[0] * d1;
336 const Standard_Real py = y - theCoeff[1] * d1;
337 const Standard_Real pz = z - theCoeff[2] * d1;
339 x = px * px * d1 + px * theCoeff[0] * d2 + theCoeff[0] * theCoeff[0] * d3;
340 y = py * py * d1 + py * theCoeff[1] * d2 + theCoeff[1] * theCoeff[1] * d3;
341 z = pz * pz * d1 + pz * theCoeff[2] * d2 + theCoeff[2] * theCoeff[2] * d3;
343 theOutInertia.Ixx += (y + z) * s;
344 theOutInertia.Iyy += (x + z) * s;
345 theOutInertia.Izz += (x + y) * s;
348 x = (py * pz * d1) + (py * theCoeff[2] * d2) + (pz * theCoeff[1] * d2) + (theCoeff[1] * theCoeff[2] * d3);
349 y = (px * pz * d1) + (pz * theCoeff[0] * d2) + (px * theCoeff[2] * d2) + (theCoeff[0] * theCoeff[2] * d3);
350 z = (px * py * d1) + (px * theCoeff[1] * d2) + (py * theCoeff[0] * d2) + (theCoeff[0] * theCoeff[1] * d3);
352 theOutInertia.Ixy -= z * s;
353 theOutInertia.Iyz -= x * s;
354 theOutInertia.Ixz -= y * s;
358 //=======================================================================
359 //function : computeSInertiaOfElementaryPart
361 //=======================================================================
362 void BRepGProp_Gauss::computeSInertiaOfElementaryPart(
363 const gp_Pnt& thePoint,
364 const gp_Vec& theNormal,
365 const gp_Pnt& theLocation,
366 const Standard_Real theWeight,
367 BRepGProp_Gauss::Inertia& theOutInertia)
369 // ds - Jacobien (x, y, z) -> (u, v) = ||n||
370 const Standard_Real ds = mult(theNormal.Magnitude(), theWeight);
371 const Standard_Real x = add(thePoint.X(), -theLocation.X());
372 const Standard_Real y = add(thePoint.Y(), -theLocation.Y());
373 const Standard_Real z = add(thePoint.Z(), -theLocation.Z());
375 theOutInertia.Mass = add(theOutInertia.Mass, ds);
377 const Standard_Real XdS = mult(x, ds);
378 const Standard_Real YdS = mult(y, ds);
379 const Standard_Real ZdS = mult(z, ds);
381 theOutInertia.Ix = add(theOutInertia.Ix, XdS);
382 theOutInertia.Iy = add(theOutInertia.Iy, YdS);
383 theOutInertia.Iz = add(theOutInertia.Iz, ZdS);
384 theOutInertia.Ixy = add(theOutInertia.Ixy, mult(x, YdS));
385 theOutInertia.Iyz = add(theOutInertia.Iyz, mult(y, ZdS));
386 theOutInertia.Ixz = add(theOutInertia.Ixz, mult(x, ZdS));
388 const Standard_Real XXdS = mult(x, XdS);
389 const Standard_Real YYdS = mult(y, YdS);
390 const Standard_Real ZZdS = mult(z, ZdS);
392 theOutInertia.Ixx = add(theOutInertia.Ixx, add(YYdS, ZZdS));
393 theOutInertia.Iyy = add(theOutInertia.Iyy, add(XXdS, ZZdS));
394 theOutInertia.Izz = add(theOutInertia.Izz, add(XXdS, YYdS));
397 //=======================================================================
398 //function : checkBounds
400 //=======================================================================
401 void BRepGProp_Gauss::checkBounds(const Standard_Real theU1,
402 const Standard_Real theU2,
403 const Standard_Real theV1,
404 const Standard_Real theV2)
406 if (Precision::IsInfinite(theU1) || Precision::IsInfinite(theU2) ||
407 Precision::IsInfinite(theV1) || Precision::IsInfinite(theV2))
414 //=======================================================================
415 //function : addAndRestoreInertia
417 //=======================================================================
418 void BRepGProp_Gauss::addAndRestoreInertia(
419 const BRepGProp_Gauss::Inertia& theInInertia,
420 BRepGProp_Gauss::Inertia& theOutInertia)
422 theOutInertia.Mass = add(theOutInertia.Mass, theInInertia.Mass);
423 theOutInertia.Ix = add(theOutInertia.Ix, theInInertia.Ix);
424 theOutInertia.Iy = add(theOutInertia.Iy, theInInertia.Iy);
425 theOutInertia.Iz = add(theOutInertia.Iz, theInInertia.Iz);
426 theOutInertia.Ixx = add(theOutInertia.Ixx, theInInertia.Ixx);
427 theOutInertia.Iyy = add(theOutInertia.Iyy, theInInertia.Iyy);
428 theOutInertia.Izz = add(theOutInertia.Izz, theInInertia.Izz);
429 theOutInertia.Ixy = add(theOutInertia.Ixy, theInInertia.Ixy);
430 theOutInertia.Ixz = add(theOutInertia.Ixz, theInInertia.Ixz);
431 theOutInertia.Iyz = add(theOutInertia.Iyz, theInInertia.Iyz);
434 //=======================================================================
435 //function : multAndRestoreInertia
437 //=======================================================================
438 void BRepGProp_Gauss::multAndRestoreInertia(
439 const Standard_Real theValue,
440 BRepGProp_Gauss::Inertia& theInOutInertia)
442 theInOutInertia.Mass = mult(theInOutInertia.Mass, theValue);
443 theInOutInertia.Ix = mult(theInOutInertia.Ix, theValue);
444 theInOutInertia.Iy = mult(theInOutInertia.Iy, theValue);
445 theInOutInertia.Iz = mult(theInOutInertia.Iz, theValue);
446 theInOutInertia.Ixx = mult(theInOutInertia.Ixx, theValue);
447 theInOutInertia.Iyy = mult(theInOutInertia.Iyy, theValue);
448 theInOutInertia.Izz = mult(theInOutInertia.Izz, theValue);
449 theInOutInertia.Ixy = mult(theInOutInertia.Ixy, theValue);
450 theInOutInertia.Ixz = mult(theInOutInertia.Ixz, theValue);
451 theInOutInertia.Iyz = mult(theInOutInertia.Iyz, theValue);
454 //=======================================================================
457 //=======================================================================
458 void BRepGProp_Gauss::convert(const BRepGProp_Gauss::Inertia& theInertia,
459 gp_Pnt& theOutGravityCenter,
460 gp_Mat& theOutMatrixOfInertia,
461 Standard_Real& theOutMass)
463 if (Abs(theInertia.Mass) >= EPS_DIM)
465 const Standard_Real anInvMass = 1.0 / theInertia.Mass;
466 theOutGravityCenter.SetX(theInertia.Ix * anInvMass);
467 theOutGravityCenter.SetY(theInertia.Iy * anInvMass);
468 theOutGravityCenter.SetZ(theInertia.Iz * anInvMass);
470 theOutMass = theInertia.Mass;
475 theOutGravityCenter.SetCoord(0.0, 0.0, 0.0);
478 theOutMatrixOfInertia = gp_Mat(
479 gp_XYZ ( theInertia.Ixx, -theInertia.Ixy, -theInertia.Ixz),
480 gp_XYZ (-theInertia.Ixy, theInertia.Iyy, -theInertia.Iyz),
481 gp_XYZ (-theInertia.Ixz, -theInertia.Iyz, theInertia.Izz));
484 //=======================================================================
487 //=======================================================================
488 void BRepGProp_Gauss::convert(const BRepGProp_Gauss::Inertia& theInertia,
489 const Standard_Real theCoeff[],
490 const Standard_Boolean theIsByPoint,
491 gp_Pnt& theOutGravityCenter,
492 gp_Mat& theOutMatrixOfInertia,
493 Standard_Real& theOutMass)
495 convert(theInertia, theOutGravityCenter, theOutMatrixOfInertia, theOutMass);
496 if (Abs(theInertia.Mass) >= EPS_DIM && theIsByPoint)
498 const Standard_Real anInvMass = 1.0 / theInertia.Mass;
499 if (theIsByPoint == Standard_True)
501 theOutGravityCenter.SetX(theCoeff[0] + theInertia.Ix * anInvMass);
502 theOutGravityCenter.SetY(theCoeff[1] + theInertia.Iy * anInvMass);
503 theOutGravityCenter.SetZ(theCoeff[2] + theInertia.Iz * anInvMass);
507 theOutGravityCenter.SetX(theInertia.Ix * anInvMass);
508 theOutGravityCenter.SetY(theInertia.Iy * anInvMass);
509 theOutGravityCenter.SetZ(theInertia.Iz * anInvMass);
512 theOutMass = theInertia.Mass;
517 theOutGravityCenter.SetCoord(0.0, 0.0, 0.0);
520 theOutMatrixOfInertia = gp_Mat(
521 gp_XYZ (theInertia.Ixx, theInertia.Ixy, theInertia.Ixz),
522 gp_XYZ (theInertia.Ixy, theInertia.Iyy, theInertia.Iyz),
523 gp_XYZ (theInertia.Ixz, theInertia.Iyz, theInertia.Izz));
526 //=======================================================================
529 //=======================================================================
530 Standard_Real BRepGProp_Gauss::Compute(
531 BRepGProp_Face& theSurface,
532 BRepGProp_Domain& theDomain,
533 const gp_Pnt& theLocation,
534 const Standard_Real theEps,
535 const Standard_Real theCoeff[],
536 const Standard_Boolean theIsByPoint,
537 Standard_Real& theOutMass,
538 gp_Pnt& theOutGravityCenter,
539 gp_Mat& theOutInertia)
541 const Standard_Boolean isErrorCalculation =
542 ( 0.0 > theEps || theEps < 0.001 ) ? Standard_True : Standard_False;
543 const Standard_Boolean isVerifyComputation =
544 ( 0.0 < theEps && theEps < 0.001 ) ? Standard_True : Standard_False;
546 Standard_Real anEpsilon= Abs(theEps);
548 BRepGProp_Gauss::Inertia anInertia;
549 InertiaArray anInertiaL = new NCollection_Array1<Inertia>(1, SM);
550 InertiaArray anInertiaU = new NCollection_Array1<Inertia>(1, SM);
552 // Prepare Gauss points and weights
553 NCollection_Handle<math_Vector> LGaussP[2];
554 NCollection_Handle<math_Vector> LGaussW[2];
555 NCollection_Handle<math_Vector> UGaussP[2];
556 NCollection_Handle<math_Vector> UGaussW[2];
558 const Standard_Integer aNbGaussPoint =
559 RealToInt(Ceiling(ERROR_ALGEBR_RATIO * GPM));
561 LGaussP[0] = new math_Vector(1, GPM);
562 LGaussP[1] = new math_Vector(1, aNbGaussPoint);
563 LGaussW[0] = new math_Vector(1, GPM);
564 LGaussW[1] = new math_Vector(1, aNbGaussPoint);
566 UGaussP[0] = new math_Vector(1, GPM);
567 UGaussP[1] = new math_Vector(1, aNbGaussPoint);
568 UGaussW[0] = new math_Vector(1, GPM);
569 UGaussW[1] = new math_Vector(1, aNbGaussPoint);
571 NCollection_Handle<math_Vector> L1 = new math_Vector(1, SM);
572 NCollection_Handle<math_Vector> L2 = new math_Vector(1, SM);
573 NCollection_Handle<math_Vector> U1 = new math_Vector(1, SM);
574 NCollection_Handle<math_Vector> U2 = new math_Vector(1, SM);
576 NCollection_Handle<math_Vector> ErrL = new math_Vector(1, SM, 0.0);
577 NCollection_Handle<math_Vector> ErrU = new math_Vector(1, SM, 0.0);
578 NCollection_Handle<math_Vector> ErrUL = new math_Vector(1, SM, 0.0);
580 // Face parametrization in U and V direction
581 Standard_Real BV1, BV2, BU1, BU2;
582 theSurface.Bounds(BU1, BU2, BV1, BV2);
583 checkBounds(BU1, BU2, BV1, BV2);
586 const Standard_Integer NumSubs = SUBS_POWER;
587 const TopoDS_Face& aF = theSurface.GetFace();
588 const Standard_Boolean isNaturalRestriction = (aF.NbChildren () == 0); //theSurface.NaturalRestriction();
590 Standard_Real CIx, CIy, CIz, CIxy, CIxz, CIyz;
591 Standard_Real CDim[2], CIxx[2], CIyy[2], CIzz[2];
593 // Boundary curve parametrization
594 Standard_Real u1 = BU1, u2, l1, l2, lm, lr, l, v;
596 // On the boundary curve u-v
599 Standard_Real Dul; // Dul = Du / Dl
601 Standard_Integer iLS, iLSubEnd, iGL, iGLEnd, NbLGaussP[2], LRange[2], iL, kL, kLEnd, IL, JL;
602 Standard_Integer i, iUSubEnd, NbUGaussP[2], URange[2], kU, kUEnd, IU, JU;
603 Standard_Integer UMaxSubs, LMaxSubs;
605 Standard_Real ErrorU, ErrorL, ErrorLMax = 0.0, Eps = 0.0, EpsL = 0.0, EpsU = 0.0;
606 iGLEnd = isErrorCalculation ? 2 : 1;
608 NbUGaussP[0] = theSurface.SIntOrder(anEpsilon);
609 NbUGaussP[1] = RealToInt( Ceiling(ERROR_ALGEBR_RATIO * NbUGaussP[0]) );
611 math::GaussPoints (NbUGaussP[0], *UGaussP[0]);
612 math::GaussWeights(NbUGaussP[0], *UGaussW[0]);
613 math::GaussPoints (NbUGaussP[1], *UGaussP[1]);
614 math::GaussWeights(NbUGaussP[1], *UGaussW[1]);
616 const Standard_Integer aNbUSubs = theSurface.SUIntSubs();
617 TColStd_Array1OfReal UKnots(1, aNbUSubs + 1);
618 theSurface.UKnots(UKnots);
620 while (isNaturalRestriction || theDomain.More())
622 if (isNaturalRestriction)
624 NbLGaussP[0] = Min(2 * NbUGaussP[0], math::GaussPointsMax());
628 if (!theSurface.Load(theDomain.Value()))
630 return Precision::Infinite();
632 NbLGaussP[0] = theSurface.LIntOrder(anEpsilon);
635 NbLGaussP[1] = RealToInt( Ceiling(ERROR_ALGEBR_RATIO * NbLGaussP[0]) );
637 math::GaussPoints (NbLGaussP[0], *LGaussP[0]);
638 math::GaussWeights(NbLGaussP[0], *LGaussW[0]);
639 math::GaussPoints (NbLGaussP[1], *LGaussP[1]);
640 math::GaussWeights(NbLGaussP[1], *LGaussW[1]);
642 const Standard_Integer aNbLSubs =
643 isNaturalRestriction ? theSurface.SVIntSubs(): theSurface.LIntSubs();
644 TColStd_Array1OfReal LKnots(1, aNbLSubs + 1);
646 if (isNaturalRestriction)
648 theSurface.VKnots(LKnots);
654 theSurface.LKnots(LKnots);
655 l1 = theSurface.FirstParameter();
656 l2 = theSurface.LastParameter();
661 if (Abs(l2 - l1) > EPS_PARAM)
663 iLSubEnd = FillIntervalBounds(l1, l2, LKnots, NumSubs, anInertiaL, L1, L2, ErrL, ErrUL);
664 LMaxSubs = BRepGProp_Gauss::MaxSubs(iLSubEnd);
671 BRepGProp_Gauss::InitMass(0.0, 1, LMaxSubs, anInertiaL);
672 BRepGProp_Gauss::Init(ErrL, 0.0, 1, LMaxSubs);
673 BRepGProp_Gauss::Init(ErrUL, 0.0, 1, LMaxSubs);
679 LRange[0] = IL = ErrL->Max();
681 L1->Value(JL) = (L1->Value(IL) + L2->Value(IL)) * 0.5;
682 L2->Value(JL) = L2->Value(IL);
683 L2->Value(IL) = L1->Value(JL);
690 if (JL == LMaxSubs || Abs(L2->Value(JL) - L1->Value(JL)) < EPS_PARAM)
694 anInertiaL->ChangeValue(JL).Reset();
695 ErrL->Value(JL) = 0.0;
707 for (kL = 0; kL < kLEnd; kL++)
710 lm = 0.5 * (L2->Value(iLS) + L1->Value(iLS));
711 lr = 0.5 * (L2->Value(iLS) - L1->Value(iLS));
713 CIx = CIy = CIz = CIxy = CIxz = CIyz = 0.0;
715 for (iGL = 0; iGL < iGLEnd; ++iGL)
717 CDim[iGL] = CIxx[iGL] = CIyy[iGL] = CIzz[iGL] = 0.0;
719 for (iL = 1; iL <= NbLGaussP[iGL]; iL++)
721 l = lm + lr * LGaussP[iGL]->Value(iL);
722 if (isNaturalRestriction)
726 Dul = LGaussW[iGL]->Value(iL);
730 theSurface.D12d (l, Puv, Vuv);
731 Dul = Vuv.Y() * LGaussW[iGL]->Value(iL); // Dul = Du / Dl
733 if (Abs(Dul) < EPS_PARAM)
739 // Check on cause out off bounds of value current parameter
751 ErrUL->Value(iLS) = 0.0;
755 if (Abs(u2 - u1) < EPS_PARAM)
758 NCollection_Handle<math_Vector> aDummy;
759 iUSubEnd = FillIntervalBounds(u1, u2, UKnots, NumSubs, anInertiaU, U1, U2, ErrU, aDummy);
760 UMaxSubs = BRepGProp_Gauss::MaxSubs(iUSubEnd);
765 BRepGProp_Gauss::InitMass(0.0, 1, UMaxSubs, anInertiaU);
766 BRepGProp_Gauss::Init(ErrU, 0.0, 1, UMaxSubs);
773 URange[0] = IU = ErrU->Max();
776 U1->Value(JU) = (U1->Value(IU) + U2->Value(IU)) * 0.5;
777 U2->Value(JU) = U2->Value(IU);
778 U2->Value(IU) = U1->Value(JU);
783 if (JU == UMaxSubs || Abs(U2->Value(JU) - U1->Value(JU)) < EPS_PARAM)
786 ErrU->Value(JU) = 0.0;
787 anInertiaU->ChangeValue(JU).Reset();
793 Eps = 10. * EpsU * Abs((u2 - u1) * Dul);
802 for (kU = 0; kU < kUEnd; ++kU)
804 BRepGProp_Gauss::Inertia aLocal[2];
806 Standard_Integer iUS = URange[kU];
807 const Standard_Integer aLength = iGLEnd - iGL;
809 const Standard_Real um = 0.5 * (U2->Value(iUS) + U1->Value(iUS));
810 const Standard_Real ur = 0.5 * (U2->Value(iUS) - U1->Value(iUS));
812 for (Standard_Integer iGU = 0; iGU < aLength; ++iGU)
814 for (Standard_Integer iU = 1; iU <= NbUGaussP[iGU]; ++iU)
816 Standard_Real w = UGaussW[iGU]->Value(iU);
817 const Standard_Real u = um + ur * UGaussP[iGU]->Value(iU);
819 theSurface.Normal(u, v, aPoint, aNormal);
821 if (myType == Vinert)
823 computeVInertiaOfElementaryPart(
824 aPoint, aNormal, theLocation, w, theCoeff, theIsByPoint, aLocal[iGU]);
829 aLocal[iGU].Mass += (w * aNormal.Magnitude());
832 computeSInertiaOfElementaryPart(
833 aPoint, aNormal, theLocation, w, aLocal[iGU]);
839 BRepGProp_Gauss::Inertia& anUI =
840 anInertiaU->ChangeValue(iUS);
842 anUI.Mass = mult(aLocal[0].Mass, ur);
844 if (myType == Vinert)
846 anUI.Ixx = mult(aLocal[0].Ixx, ur);
847 anUI.Iyy = mult(aLocal[0].Iyy, ur);
848 anUI.Izz = mult(aLocal[0].Izz, ur);
854 Standard_Real aDMass = Abs(aLocal[1].Mass - aLocal[0].Mass);
856 if (myType == Vinert)
858 aLocal[1].Ixx = Abs(aLocal[1].Ixx - aLocal[0].Ixx);
859 aLocal[1].Iyy = Abs(aLocal[1].Iyy - aLocal[0].Iyy);
860 aLocal[1].Izz = Abs(aLocal[1].Izz - aLocal[0].Izz);
862 anUI.Ix = mult(aLocal[0].Ix, ur);
863 anUI.Iy = mult(aLocal[0].Iy, ur);
864 anUI.Iz = mult(aLocal[0].Iz, ur);
866 anUI.Ixy = mult(aLocal[0].Ixy, ur);
867 anUI.Ixz = mult(aLocal[0].Ixz, ur);
868 anUI.Iyz = mult(aLocal[0].Iyz, ur);
871 aDMass = aLocal[1].Ixx + aLocal[1].Iyy + aLocal[1].Izz;
874 ErrU->Value(iUS) = mult(aDMass, ur);
878 anUI.Ix = mult(aLocal[0].Ix, ur);
879 anUI.Iy = mult(aLocal[0].Iy, ur);
880 anUI.Iz = mult(aLocal[0].Iz, ur);
881 anUI.Ixx = mult(aLocal[0].Ixx, ur);
882 anUI.Iyy = mult(aLocal[0].Iyy, ur);
883 anUI.Izz = mult(aLocal[0].Izz, ur);
884 anUI.Ixy = mult(aLocal[0].Ixy, ur);
885 anUI.Ixz = mult(aLocal[0].Ixz, ur);
886 anUI.Iyz = mult(aLocal[0].Iyz, ur);
888 ErrU->Value(iUS) = mult(aDMass, ur);
896 ErrorU = ErrU->Value(ErrU->Max());
898 } while ( (ErrorU - EpsU > 0.0 && EpsU != 0.0) || kUEnd == 1 );
900 for (i = 1; i <= JU; ++i)
902 const BRepGProp_Gauss::Inertia& anIU =
903 anInertiaU->Value(i);
905 CDim[iGL] = add(CDim[iGL], mult(anIU.Mass, Dul));
906 CIxx[iGL] = add(CIxx[iGL], mult(anIU.Ixx, Dul));
907 CIyy[iGL] = add(CIyy[iGL], mult(anIU.Iyy, Dul));
908 CIzz[iGL] = add(CIzz[iGL], mult(anIU.Izz, Dul));
914 ErrUL->Value(iLS) = ErrorU * Abs((u2 - u1) * Dul);
916 for (i = 1; i <= JU; ++i)
918 const BRepGProp_Gauss::Inertia& anIU =
919 anInertiaU->Value(i);
921 CIx = add(CIx, mult(anIU.Ix, Dul));
922 CIy = add(CIy, mult(anIU.Iy, Dul));
923 CIz = add(CIz, mult(anIU.Iz, Dul));
925 CIxy = add(CIxy, mult(anIU.Ixy, Dul));
926 CIxz = add(CIxz, mult(anIU.Ixz, Dul));
927 CIyz = add(CIyz, mult(anIU.Iyz, Dul));
932 BRepGProp_Gauss::Inertia& aLI = anInertiaL->ChangeValue(iLS);
934 aLI.Mass = mult(CDim[0], lr);
935 aLI.Ixx = mult(CIxx[0], lr);
936 aLI.Iyy = mult(CIyy[0], lr);
937 aLI.Izz = mult(CIzz[0], lr);
941 Standard_Real aSubDim = Abs(CDim[1] - CDim[0]);
943 if (myType == Vinert)
945 ErrorU = ErrUL->Value(iLS);
947 CIxx[1] = Abs(CIxx[1] - CIxx[0]);
948 CIyy[1] = Abs(CIyy[1] - CIyy[0]);
949 CIzz[1] = Abs(CIzz[1] - CIzz[0]);
952 aSubDim = CIxx[1] + CIyy[1] + CIzz[1];
955 ErrL->Value(iLS) = add(mult(aSubDim, lr), ErrorU);
959 ErrL->Value(iLS) = add(mult(aSubDim, lr), ErrUL->Value(iLS));
963 aLI.Ix = mult(CIx, lr);
964 aLI.Iy = mult(CIy, lr);
965 aLI.Iz = mult(CIz, lr);
967 aLI.Ixy = mult(CIxy, lr);
968 aLI.Ixz = mult(CIxz, lr);
969 aLI.Iyz = mult(CIyz, lr);
973 // Calculate/correct epsilon of computation by current value of dim
974 // That is need for not spend time for
979 Standard_Real DDim = 0.0;
980 for (i = 1; i <= JL; ++i)
981 DDim += anInertiaL->Value(i).Mass;
985 if (myType == Vinert)
987 Standard_Real DIxx = 0.0, DIyy = 0.0, DIzz = 0.0;
988 for (i = 1; i <= JL; ++i)
990 const BRepGProp_Gauss::Inertia& aLocalL =
991 anInertiaL->Value(i);
998 DDim = Abs(DIxx) + Abs(DIyy) + Abs(DIzz);
1003 DDim = Abs(DDim * anEpsilon);
1013 ErrorL = ErrL->Value(ErrL->Max());
1015 } while ( (ErrorL - EpsL > 0.0 && isVerifyComputation) || kLEnd == 1 );
1017 for ( i = 1; i <= JL; i++ )
1019 addAndRestoreInertia(anInertiaL->Value(i), anInertia);
1022 ErrorLMax = Max(ErrorLMax, ErrorL);
1025 if (isNaturalRestriction)
1031 if (myType == Vinert)
1032 convert(anInertia, theCoeff, theIsByPoint, theOutGravityCenter, theOutInertia, theOutMass);
1034 convert(anInertia, theOutGravityCenter, theOutInertia, theOutMass);
1038 if (theOutMass != 0.0)
1040 Eps = ErrorLMax / Abs(theOutMass);
1044 if (myType == Vinert)
1045 Eps = ErrorLMax / (Abs(anInertia.Ixx) +
1046 Abs(anInertia.Iyy) +
1047 Abs(anInertia.Izz));
1064 //=======================================================================
1065 //function : Compute
1067 //=======================================================================
1068 Standard_Real BRepGProp_Gauss::Compute(BRepGProp_Face& theSurface,
1069 BRepGProp_Domain& theDomain,
1070 const gp_Pnt& theLocation,
1071 const Standard_Real theEps,
1072 Standard_Real& theOutMass,
1073 gp_Pnt& theOutGravityCenter,
1074 gp_Mat& theOutInertia)
1076 Standard_ASSERT_RAISE(myType == Sinert, "BRepGProp_Gauss: Incorrect type");
1078 return Compute(theSurface,
1085 theOutGravityCenter,
1089 //=======================================================================
1090 //function : Compute
1092 //=======================================================================
1093 void BRepGProp_Gauss::Compute(BRepGProp_Face& theSurface,
1094 BRepGProp_Domain& theDomain,
1095 const gp_Pnt& theLocation,
1096 Standard_Real& theOutMass,
1097 gp_Pnt& theOutGravityCenter,
1098 gp_Mat& theOutInertia)
1100 Standard_ASSERT_RAISE(myType == Sinert, "BRepGProp_Gauss: Incorrect type");
1102 Standard_Real u1, u2, v1, v2;
1103 theSurface.Bounds (u1, u2, v1, v2);
1104 checkBounds(u1, u2, v1, v2);
1106 const Standard_Integer NbUGaussgp_Pnts =
1107 Min(theSurface.UIntegrationOrder(), math::GaussPointsMax());
1109 const Standard_Integer NbVGaussgp_Pnts =
1110 Min(theSurface.VIntegrationOrder(), math::GaussPointsMax());
1112 const Standard_Integer NbGaussgp_Pnts =
1113 Max(NbUGaussgp_Pnts, NbVGaussgp_Pnts);
1115 // Number of Gauss points for the integration on the face
1116 math_Vector GaussSPV (1, NbGaussgp_Pnts);
1117 math_Vector GaussSWV (1, NbGaussgp_Pnts);
1118 math::GaussPoints (NbGaussgp_Pnts, GaussSPV);
1119 math::GaussWeights(NbGaussgp_Pnts, GaussSWV);
1121 BRepGProp_Gauss::Inertia anInertia;
1122 for (; theDomain.More(); theDomain.Next())
1124 if (!theSurface.Load(theDomain.Value()))
1129 Standard_Integer NbCGaussgp_Pnts =
1130 Min(theSurface.IntegrationOrder(), math::GaussPointsMax());
1132 NbCGaussgp_Pnts = Max(NbCGaussgp_Pnts, NbGaussgp_Pnts);
1134 math_Vector GaussCP(1, NbCGaussgp_Pnts);
1135 math_Vector GaussCW(1, NbCGaussgp_Pnts);
1136 math::GaussPoints (NbCGaussgp_Pnts, GaussCP);
1137 math::GaussWeights(NbCGaussgp_Pnts, GaussCW);
1140 const Standard_Real l1 = theSurface.FirstParameter();
1141 const Standard_Real l2 = theSurface.LastParameter ();
1142 const Standard_Real lm = 0.5 * (l2 + l1);
1143 const Standard_Real lr = 0.5 * (l2 - l1);
1145 BRepGProp_Gauss::Inertia aCInertia;
1146 for (Standard_Integer i = 1; i <= NbCGaussgp_Pnts; ++i)
1148 const Standard_Real l = lm + lr * GaussCP(i);
1152 theSurface.D12d(l, Puv, Vuv);
1154 const Standard_Real v = Puv.Y();
1157 const Standard_Real Dul = Vuv.Y() * GaussCW(i);
1158 const Standard_Real um = 0.5 * (u2 + u1);
1159 const Standard_Real ur = 0.5 * (u2 - u1);
1161 BRepGProp_Gauss::Inertia aLocalInertia;
1162 for (Standard_Integer j = 1; j <= NbGaussgp_Pnts; ++j)
1164 const Standard_Real u = add(um, mult(ur, GaussSPV(j)));
1165 const Standard_Real aWeight = Dul * GaussSWV(j);
1169 theSurface.Normal (u, v, aPoint, aNormal);
1171 computeSInertiaOfElementaryPart(aPoint, aNormal, theLocation, aWeight, aLocalInertia);
1174 multAndRestoreInertia(ur, aLocalInertia);
1175 addAndRestoreInertia (aLocalInertia, aCInertia);
1178 multAndRestoreInertia(lr, aCInertia);
1179 addAndRestoreInertia (aCInertia, anInertia);
1182 convert(anInertia, theOutGravityCenter, theOutInertia, theOutMass);
1185 //=======================================================================
1186 //function : Compute
1188 //=======================================================================
1189 void BRepGProp_Gauss::Compute(BRepGProp_Face& theSurface,
1190 BRepGProp_Domain& theDomain,
1191 const gp_Pnt& theLocation,
1192 const Standard_Real theCoeff[],
1193 const Standard_Boolean theIsByPoint,
1194 Standard_Real& theOutMass,
1195 gp_Pnt& theOutGravityCenter,
1196 gp_Mat& theOutInertia)
1198 Standard_ASSERT_RAISE(myType == Vinert, "BRepGProp_Gauss: Incorrect type");
1200 Standard_Real u1, v1, u2, v2;
1201 theSurface.Bounds (u1, u2, v1, v2);
1202 checkBounds(u1, u2, v1, v2);
1204 Standard_Real _u2 = u2; //OCC104
1206 BRepGProp_Gauss::Inertia anInertia;
1207 for (; theDomain.More(); theDomain.Next())
1209 if (!theSurface.Load(theDomain.Value()))
1214 const Standard_Integer aVNbCGaussgp_Pnts =
1215 theSurface.VIntegrationOrder();
1217 const Standard_Integer aNbGaussgp_Pnts =
1218 Min( Max(theSurface.IntegrationOrder(), aVNbCGaussgp_Pnts), math::GaussPointsMax() );
1220 math_Vector GaussP(1, aNbGaussgp_Pnts);
1221 math_Vector GaussW(1, aNbGaussgp_Pnts);
1222 math::GaussPoints (aNbGaussgp_Pnts, GaussP);
1223 math::GaussWeights(aNbGaussgp_Pnts, GaussW);
1225 const Standard_Real l1 = theSurface.FirstParameter();
1226 const Standard_Real l2 = theSurface.LastParameter();
1227 const Standard_Real lm = 0.5 * (l2 + l1);
1228 const Standard_Real lr = 0.5 * (l2 - l1);
1230 BRepGProp_Gauss::Inertia aCInertia;
1231 for (Standard_Integer i = 1; i <= aNbGaussgp_Pnts; ++i)
1233 const Standard_Real l = lm + lr * GaussP(i);
1238 theSurface.D12d(l, Puv, Vuv);
1241 u2 = Min( Max(u1, u2), _u2 ); // OCC104
1242 const Standard_Real v = Min(Max(Puv.Y(), v1), v2);
1244 const Standard_Real Dul = Vuv.Y() * GaussW(i);
1245 const Standard_Real um = 0.5 * (u2 + u1);
1246 const Standard_Real ur = 0.5 * (u2 - u1);
1248 BRepGProp_Gauss::Inertia aLocalInertia;
1249 for (Standard_Integer j = 1; j <= aNbGaussgp_Pnts; ++j)
1251 const Standard_Real u = um + ur * GaussP(j);
1252 const Standard_Real aWeight = Dul * GaussW(j);
1257 theSurface.Normal(u, v, aPoint, aNormal);
1259 computeVInertiaOfElementaryPart(
1269 multAndRestoreInertia(ur, aLocalInertia);
1270 addAndRestoreInertia (aLocalInertia, aCInertia);
1273 multAndRestoreInertia(lr, aCInertia);
1274 addAndRestoreInertia (aCInertia, anInertia);
1277 convert(anInertia, theCoeff, theIsByPoint, theOutGravityCenter, theOutInertia, theOutMass);
1280 //=======================================================================
1281 //function : Compute
1283 //=======================================================================
1284 void BRepGProp_Gauss::Compute(const BRepGProp_Face& theSurface,
1285 const gp_Pnt& theLocation,
1286 const Standard_Real theCoeff[],
1287 const Standard_Boolean theIsByPoint,
1288 Standard_Real& theOutMass,
1289 gp_Pnt& theOutGravityCenter,
1290 gp_Mat& theOutInertia)
1292 Standard_Real LowerU, UpperU, LowerV, UpperV;
1293 theSurface.Bounds(LowerU, UpperU, LowerV, UpperV);
1294 checkBounds(LowerU, UpperU, LowerV, UpperV);
1296 const Standard_Integer UOrder =
1297 Min(theSurface.UIntegrationOrder(), math::GaussPointsMax());
1298 const Standard_Integer VOrder =
1299 Min(theSurface.VIntegrationOrder(), math::GaussPointsMax());
1301 // Gauss points and weights
1302 math_Vector GaussPU(1, UOrder);
1303 math_Vector GaussWU(1, UOrder);
1304 math_Vector GaussPV(1, VOrder);
1305 math_Vector GaussWV(1, VOrder);
1307 math::GaussPoints (UOrder, GaussPU);
1308 math::GaussWeights(UOrder, GaussWU);
1309 math::GaussPoints (VOrder, GaussPV);
1310 math::GaussWeights(VOrder, GaussWV);
1312 const Standard_Real um = 0.5 * add(UpperU, LowerU);
1313 const Standard_Real vm = 0.5 * add(UpperV, LowerV);
1314 Standard_Real ur = 0.5 * add(UpperU, -LowerU);
1315 Standard_Real vr = 0.5 * add(UpperV, -LowerV);
1320 BRepGProp_Gauss::Inertia anInertia;
1321 for (Standard_Integer j = 1; j <= VOrder; ++j)
1323 BRepGProp_Gauss::Inertia anInertiaOfElementaryPart;
1324 const Standard_Real v = add(vm, mult(vr, GaussPV(j)));
1326 for (Standard_Integer i = 1; i <= UOrder; ++i)
1328 const Standard_Real aWeight = GaussWU(i);
1329 const Standard_Real u = add(um, mult(ur, GaussPU (i)));
1330 theSurface.Normal(u, v, aPoint, aNormal);
1332 if (myType == Vinert)
1334 computeVInertiaOfElementaryPart(
1341 anInertiaOfElementaryPart);
1345 computeSInertiaOfElementaryPart(
1350 anInertiaOfElementaryPart);
1354 multAndRestoreInertia(GaussWV(j), anInertiaOfElementaryPart);
1355 addAndRestoreInertia (anInertiaOfElementaryPart, anInertia);
1358 anInertia.Ixx = mult(vr, anInertia.Ixx);
1359 anInertia.Iyy = mult(vr, anInertia.Iyy);
1360 anInertia.Izz = mult(vr, anInertia.Izz);
1361 anInertia.Ixy = mult(vr, anInertia.Ixy);
1362 anInertia.Ixz = mult(vr, anInertia.Ixz);
1363 anInertia.Iyz = mult(vr, anInertia.Iyz);
1365 if (myType == Vinert)
1367 convert(anInertia, theCoeff, theIsByPoint, theOutGravityCenter, theOutInertia, theOutMass);
1371 convert(anInertia, theOutGravityCenter, theOutInertia, theOutMass);
1377 //=======================================================================
1378 //function : Compute
1380 //=======================================================================
1381 void BRepGProp_Gauss::Compute(const BRepGProp_Face& theSurface,
1382 const gp_Pnt& theLocation,
1383 Standard_Real& theOutMass,
1384 gp_Pnt& theOutGravityCenter,
1385 gp_Mat& theOutInertia)
1387 Standard_ASSERT_RAISE(myType == Sinert, "BRepGProp_Gauss: Incorrect type");
1394 theOutGravityCenter,