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 under
7 // the terms of the GNU Lesser General Public License 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.
19 #include <GProp_PGProps.hxx>
20 #include <Standard_DimensionError.hxx>
21 #include <Standard_DomainError.hxx>
27 typedef TColgp_Array1OfPnt Array1OfPnt;
28 typedef TColgp_Array2OfPnt Array2OfPnt;
29 typedef TColStd_Array1OfReal Array1OfReal;
30 typedef TColStd_Array2OfReal Array2OfReal;
34 GProp_PGProps::GProp_PGProps ()
41 void GProp_PGProps::AddPoint (const Pnt& P)
43 Standard_Real Xp, Yp, Zp;
45 Standard_Real Ixy = - Xp * Yp;
46 Standard_Real Ixz = - Xp * Zp;
47 Standard_Real Iyz = - Yp * Zp;
49 Standard_Real Ixx = Yp * Yp + Zp * Zp;
50 Standard_Real Iyy = Xp * Xp + Zp * Zp;
51 Standard_Real Izz = Xp * Xp + Yp * Yp;
52 Mat Mp (XYZ (Ixx, Ixy, Ixz), XYZ (Ixy, Iyy, Iyz), XYZ (Ixz, Iyz, Izz));
59 Standard_Real X, Y, Z;
69 inertia = inertia + Mp;
73 void GProp_PGProps::AddPoint (const gp_Pnt& P, const Standard_Real Density)
75 if (Density <= gp::Resolution()) throw Standard_DomainError();
76 Standard_Real Xp, Yp, Zp;
78 Standard_Real Ixy = - Xp * Yp;
79 Standard_Real Ixz = - Xp * Zp;
80 Standard_Real Iyz = - Yp * Zp;
81 Standard_Real Ixx = Yp * Yp + Zp * Zp;
82 Standard_Real Iyy = Xp * Xp + Zp * Zp;
83 Standard_Real Izz = Xp * Xp + Yp * Yp;
84 Mat Mp (XYZ (Ixx, Ixy, Ixz), XYZ (Ixy, Iyy, Iyz), XYZ (Ixz, Iyz, Izz));
88 inertia = Mp * Density;
91 Standard_Real X, Y, Z;
93 X = X * dim + Xp * Density;
94 Y = Y * dim + Yp * Density;
95 Z = Z * dim + Zp * Density;
100 g.SetCoord (X, Y, Z);
101 inertia = inertia + Mp * Density;
105 GProp_PGProps::GProp_PGProps (const Array1OfPnt& Pnts)
107 for (Standard_Integer i = Pnts.Lower(); i <= Pnts.Upper(); i++) AddPoint(Pnts(i));
110 GProp_PGProps::GProp_PGProps (const Array2OfPnt& Pnts)
112 for (Standard_Integer j = Pnts.LowerCol(); j <= Pnts.UpperCol(); j++)
114 for (Standard_Integer i = Pnts.LowerRow(); i <= Pnts.UpperRow(); i++) AddPoint(Pnts (i, j));
118 GProp_PGProps::GProp_PGProps (const Array1OfPnt& Pnts,const Array1OfReal& Density)
120 if (Pnts.Length() != Density.Length()) throw Standard_DomainError();
121 Standard_Integer ip = Pnts.Lower();
122 Standard_Integer id = Density.Lower();
123 while (id <= Pnts.Upper()) {
124 Standard_Real D = Density (id);
125 if (D <= gp::Resolution()) throw Standard_DomainError();
126 AddPoint(Pnts (ip),D);
131 GProp_PGProps::GProp_PGProps (const Array2OfPnt& Pnts,const Array2OfReal& Density)
133 if (Pnts.ColLength() != Density.ColLength() || Pnts.RowLength() != Density.RowLength()) throw Standard_DomainError();
134 Standard_Integer ip = Pnts.LowerRow();
135 Standard_Integer id = Density.LowerRow();
136 Standard_Integer jp = Pnts.LowerCol();
137 Standard_Integer jd = Density.LowerCol();
138 while (jp <= Pnts.UpperCol()) {
139 while (ip <= Pnts.UpperRow()) {
140 Standard_Real D = Density (id, jd);
141 if (D <= gp::Resolution()) throw Standard_DomainError();
142 AddPoint(Pnts (ip, jp),D);
151 void GProp_PGProps::Barycentre(const Array1OfPnt& Pnts,
152 const Array1OfReal& Density,
156 if (Pnts.Length() != Density.Length()) throw Standard_DimensionError();
157 Standard_Integer ip = Pnts.Lower();
158 Standard_Integer id = Density.Lower();
160 XYZ Gxyz = Pnts (ip).XYZ();
161 Gxyz.Multiply (Mass);
162 while (ip <= Pnts.Upper()) {
163 Mass = Mass + Density (id);
164 Gxyz.Add ( (Pnts(ip).XYZ()).Multiplied (Density (id)) );
175 void GProp_PGProps::Barycentre(const Array2OfPnt& Pnts,
176 const Array2OfReal& Density,
180 if (Pnts.RowLength() != Density.RowLength() || Pnts.ColLength() != Density.ColLength()) throw Standard_DimensionError();
181 Standard_Integer ip = Pnts.LowerRow();
182 Standard_Integer id = Density.LowerRow();
183 Standard_Integer jp = Pnts.LowerCol();
184 Standard_Integer jd = Density.LowerCol();
186 XYZ Gxyz (0.0, 0.0, 0.0);
187 while (jp <= Pnts.UpperCol()) {
188 while (ip <= Pnts.UpperRow()) {
189 Mass = Mass + Density (id, jd);
190 Gxyz.Add ((Pnts(ip, jp).XYZ()).Multiplied (Density (id, jd)));
202 Pnt GProp_PGProps::Barycentre (const Array1OfPnt& Pnts) {
204 XYZ Gxyz = Pnts (Pnts.Lower()).XYZ();
205 for (Standard_Integer i = Pnts.Lower() + 1; i <= Pnts.Upper(); i++) {
206 Gxyz.Add (Pnts(i).XYZ());
208 Gxyz.Divide (Pnts.Length());
215 Pnt GProp_PGProps::Barycentre (const Array2OfPnt& Pnts) {
217 XYZ Gxyz (0.0, 0.0, 0.0);
218 for (Standard_Integer j = Pnts.LowerCol(); j <= Pnts.UpperCol(); j++) {
219 for (Standard_Integer i = Pnts.LowerRow(); i <= Pnts.UpperRow(); i++) {
220 Gxyz.Add (Pnts(i, j).XYZ());
223 Gxyz.Divide (Pnts.RowLength() * Pnts.ColLength());