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.
15 #include <GProp_PGProps.ixx>
16 #include <Standard_DomainError.hxx>
17 #include <Standard_DimensionError.hxx>
26 typedef TColgp_Array1OfPnt Array1OfPnt;
27 typedef TColgp_Array2OfPnt Array2OfPnt;
28 typedef TColStd_Array1OfReal Array1OfReal;
29 typedef TColStd_Array2OfReal Array2OfReal;
33 GProp_PGProps::GProp_PGProps ()
40 void GProp_PGProps::AddPoint (const Pnt& P)
42 Standard_Real Xp, Yp, Zp;
44 Standard_Real Ixy = - Xp * Yp;
45 Standard_Real Ixz = - Xp * Zp;
46 Standard_Real Iyz = - Yp * Zp;
48 Standard_Real Ixx = Yp * Yp + Zp * Zp;
49 Standard_Real Iyy = Xp * Xp + Zp * Zp;
50 Standard_Real Izz = Xp * Xp + Yp * Yp;
51 Mat Mp (XYZ (Ixx, Ixy, Ixz), XYZ (Ixy, Iyy, Iyz), XYZ (Ixz, Iyz, Izz));
58 Standard_Real X, Y, Z;
68 inertia = inertia + Mp;
72 void GProp_PGProps::AddPoint (const gp_Pnt& P, const Standard_Real Density)
74 if (Density <= gp::Resolution()) Standard_DomainError::Raise();
75 Standard_Real Xp, Yp, Zp;
77 Standard_Real Ixy = - Xp * Yp;
78 Standard_Real Ixz = - Xp * Zp;
79 Standard_Real Iyz = - Yp * Zp;
80 Standard_Real Ixx = Yp * Yp + Zp * Zp;
81 Standard_Real Iyy = Xp * Xp + Zp * Zp;
82 Standard_Real Izz = Xp * Xp + Yp * Yp;
83 Mat Mp (XYZ (Ixx, Ixy, Ixz), XYZ (Ixy, Iyy, Iyz), XYZ (Ixz, Iyz, Izz));
86 g.SetXYZ (P.XYZ().Multiplied (Density));
87 inertia = Mp * Density;
90 Standard_Real X, Y, Z;
92 X = X * dim + Xp * Density;
93 Y = Y * dim + Yp * Density;
94 Z = Z * dim + Zp * Density;
100 inertia = inertia + Mp * Density;
104 GProp_PGProps::GProp_PGProps (const Array1OfPnt& Pnts)
106 for (Standard_Integer i = Pnts.Lower(); i <= Pnts.Upper(); i++) AddPoint(Pnts(i));
109 GProp_PGProps::GProp_PGProps (const Array2OfPnt& Pnts)
111 for (Standard_Integer j = Pnts.LowerCol(); j <= Pnts.UpperCol(); j++)
113 for (Standard_Integer i = Pnts.LowerRow(); i <= Pnts.UpperRow(); i++) AddPoint(Pnts (i, j));
117 GProp_PGProps::GProp_PGProps (const Array1OfPnt& Pnts,const Array1OfReal& Density)
119 if (Pnts.Length() != Density.Length()) Standard_DomainError::Raise();
120 Standard_Integer ip = Pnts.Lower();
121 Standard_Integer id = Density.Lower();
122 while (id <= Pnts.Upper()) {
123 Standard_Real D = Density (id);
124 if (D <= gp::Resolution()) Standard_DomainError::Raise();
125 AddPoint(Pnts (ip),D);
130 GProp_PGProps::GProp_PGProps (const Array2OfPnt& Pnts,const Array2OfReal& Density)
132 if (Pnts.ColLength() != Density.ColLength() || Pnts.RowLength() != Density.RowLength()) Standard_DomainError::Raise();
133 Standard_Integer ip = Pnts.LowerRow();
134 Standard_Integer id = Density.LowerRow();
135 Standard_Integer jp = Pnts.LowerCol();
136 Standard_Integer jd = Density.LowerCol();
137 while (jp <= Pnts.UpperCol()) {
138 while (ip <= Pnts.UpperRow()) {
139 Standard_Real D = Density (id, jd);
140 if (D <= gp::Resolution()) Standard_DomainError::Raise();
141 AddPoint(Pnts (ip, jp),D);
150 void GProp_PGProps::Barycentre(const Array1OfPnt& Pnts,
151 const Array1OfReal& Density,
155 if (Pnts.Length() != Density.Length()) Standard_DimensionError::Raise();
156 Standard_Integer ip = Pnts.Lower();
157 Standard_Integer id = Density.Lower();
159 XYZ Gxyz = Pnts (ip).XYZ();
160 Gxyz.Multiply (Mass);
161 while (ip <= Pnts.Upper()) {
162 Mass = Mass + Density (id);
163 Gxyz.Add ( (Pnts(ip).XYZ()).Multiplied (Density (id)) );
174 void GProp_PGProps::Barycentre(const Array2OfPnt& Pnts,
175 const Array2OfReal& Density,
179 if (Pnts.RowLength() != Density.RowLength() || Pnts.ColLength() != Density.ColLength()) Standard_DimensionError::Raise();
180 Standard_Integer ip = Pnts.LowerRow();
181 Standard_Integer id = Density.LowerRow();
182 Standard_Integer jp = Pnts.LowerCol();
183 Standard_Integer jd = Density.LowerCol();
185 XYZ Gxyz (0.0, 0.0, 0.0);
186 while (jp <= Pnts.UpperCol()) {
187 while (ip <= Pnts.UpperRow()) {
188 Mass = Mass + Density (id, jd);
189 Gxyz.Add ((Pnts(ip, jp).XYZ()).Multiplied (Density (id, jd)));
201 Pnt GProp_PGProps::Barycentre (const Array1OfPnt& Pnts) {
203 XYZ Gxyz = Pnts (Pnts.Lower()).XYZ();
204 for (Standard_Integer i = Pnts.Lower() + 1; i <= Pnts.Upper(); i++) {
205 Gxyz.Add (Pnts(i).XYZ());
207 Gxyz.Divide (Pnts.Length());
214 Pnt GProp_PGProps::Barycentre (const Array2OfPnt& Pnts) {
216 XYZ Gxyz (0.0, 0.0, 0.0);
217 for (Standard_Integer j = Pnts.LowerCol(); j <= Pnts.UpperCol(); j++) {
218 for (Standard_Integer i = Pnts.LowerRow(); i <= Pnts.UpperRow(); i++) {
219 Gxyz.Add (Pnts(i, j).XYZ());
222 Gxyz.Divide (Pnts.RowLength() * Pnts.ColLength());