0024774: Convertation of the generic classes to the non-generic. Part 8
[occt.git] / src / BRepGProp / BRepGProp_Cinert.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
424cd6bb 15#include <BRepGProp_Cinert.ixx>
7fd59977 16
424cd6bb 17#include <math.hxx>
7fd59977 18#include <TColStd_Array1OfReal.hxx>
424cd6bb 19#include <BRepGProp_EdgeTool.hxx>
7fd59977 20
424cd6bb 21BRepGProp_Cinert::BRepGProp_Cinert(){}
7fd59977 22
424cd6bb 23void BRepGProp_Cinert::SetLocation(const gp_Pnt& CLocation)
7fd59977 24{
25 loc = CLocation;
26}
27
424cd6bb 28void BRepGProp_Cinert::Perform (const BRepAdaptor_Curve& C)
7fd59977 29{
30
31 Standard_Real Ix, Iy, Iz, Ixx, Iyy, Izz, Ixy, Ixz, Iyz;
32 dim = Ix = Iy = Iz = Ixx = Iyy = Izz = Ixy = Ixz = Iyz = 0.0;
33
424cd6bb 34 Standard_Real Lower = BRepGProp_EdgeTool::FirstParameter (C);
35 Standard_Real Upper = BRepGProp_EdgeTool::LastParameter (C);
36 Standard_Integer Order = Min(BRepGProp_EdgeTool::IntegrationOrder (C),
37 math::GaussPointsMax());
38
7fd59977 39 gp_Pnt P; //value on the curve
40 gp_Vec V1; //first derivative on the curve
41 Standard_Real ds; //curvilign abscissae
42 Standard_Real ur, um, u;
43 Standard_Real x, y, z;
44 Standard_Real xloc, yloc, zloc;
45
46 math_Vector GaussP (1, Order);
47 math_Vector GaussW (1, Order);
424cd6bb 48
7fd59977 49 //Recuperation des points de Gauss dans le fichier GaussPoints.
50 math::GaussPoints (Order,GaussP);
51 math::GaussWeights (Order,GaussW);
52
53 // modified by NIZHNY-MKK Thu Jun 9 12:13:21 2005.BEGIN
424cd6bb 54 Standard_Integer nbIntervals = BRepGProp_EdgeTool::NbIntervals(C, GeomAbs_CN);
7fd59977 55 Standard_Boolean bHasIntervals = (nbIntervals > 1);
56 TColStd_Array1OfReal TI(1, nbIntervals + 1);
57
58 if(bHasIntervals) {
424cd6bb 59 BRepGProp_EdgeTool::Intervals(C, TI, GeomAbs_CN);
7fd59977 60 }
61 else {
62 nbIntervals = 1;
63 }
64 Standard_Integer nIndex = 0;
65 Standard_Real UU1 = Min(Lower, Upper);
66 Standard_Real UU2 = Max(Lower, Upper);
424cd6bb 67
7fd59977 68 for(nIndex = 1; nIndex <= nbIntervals; nIndex++) {
69 if(bHasIntervals) {
70 Lower = Max(TI(nIndex), UU1);
71 Upper = Min(TI(nIndex+1), UU2);
72 }
73 else {
74 Lower = UU1;
75 Upper = UU2;
76 }
77
78 Standard_Real dimLocal, IxLocal, IyLocal, IzLocal, IxxLocal, IyyLocal, IzzLocal, IxyLocal, IxzLocal, IyzLocal;
79 dimLocal = IxLocal = IyLocal = IzLocal = IxxLocal = IyyLocal = IzzLocal = IxyLocal = IxzLocal = IyzLocal = 0.0;
424cd6bb 80 // modified by NIZHNY-MKK Thu Jun 9 12:13:32 2005.END
7fd59977 81
82 loc.Coord (xloc, yloc, zloc);
83
84 Standard_Integer i;
85
86 // Calcul des integrales aux points de gauss :
87 um = 0.5 * (Upper + Lower);
88 ur = 0.5 * (Upper - Lower);
89
90 for (i = 1; i <= Order; i++) {
91 u = um + ur * GaussP (i);
424cd6bb 92 BRepGProp_EdgeTool::D1 (C,u, P, V1);
7fd59977 93 ds = V1.Magnitude();
94 P.Coord (x, y, z);
95 x -= xloc;
96 y -= yloc;
97 z -= zloc;
98 ds *= GaussW (i);
99 dimLocal += ds;
100 IxLocal += x * ds;
101 IyLocal += y * ds;
102 IzLocal += z * ds;
103 IxyLocal += x * y * ds;
104 IyzLocal += y * z * ds;
105 IxzLocal += x * z * ds;
106 x *= x;
107 y *= y;
108 z *= z;
109 IxxLocal += (y + z) * ds;
110 IyyLocal += (x + z) * ds;
111 IzzLocal += (x + y) * ds;
112 }
113 // modified by NIZHNY-MKK Thu Jun 9 12:13:47 2005.BEGIN
114 dimLocal *= ur;
115 IxLocal *= ur;
116 IyLocal *= ur;
117 IzLocal *= ur;
118 IxxLocal *= ur;
119 IyyLocal *= ur;
120 IzzLocal *= ur;
121 IxyLocal *= ur;
122 IxzLocal *= ur;
123 IyzLocal *= ur;
124
125 dim += dimLocal;
126 Ix += IxLocal;
127 Iy += IyLocal;
128 Iz += IzLocal;
129 Ixx += IxxLocal;
130 Iyy += IyyLocal;
131 Izz += IzzLocal;
132 Ixy += IxyLocal;
133 Ixz += IxzLocal;
134 Iyz += IyzLocal;
135 }
136 // modified by NIZHNY-MKK Thu Jun 9 12:13:55 2005.END
137
138 inertia = gp_Mat (gp_XYZ (Ixx, -Ixy, -Ixz),
424cd6bb 139 gp_XYZ (-Ixy, Iyy, -Iyz),
140 gp_XYZ (-Ixz, -Iyz, Izz));
7fd59977 141
142 if (Abs(dim) < gp::Resolution())
143 g = P;
144 else
145 g.SetCoord (Ix/dim, Iy/dim, Iz/dim);
146}
147
148
424cd6bb 149BRepGProp_Cinert::BRepGProp_Cinert (const BRepAdaptor_Curve& C,
150 const gp_Pnt& CLocation)
7fd59977 151{
152 SetLocation(CLocation);
153 Perform(C);
154}