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.
16 #include <GProp_PGProps.hxx>
17 #include <Standard_DimensionError.hxx>
18 #include <Standard_DomainError.hxx>
24 typedef TColgp_Array1OfPnt Array1OfPnt;
25 typedef TColgp_Array2OfPnt Array2OfPnt;
26 typedef TColStd_Array1OfReal Array1OfReal;
27 typedef TColStd_Array2OfReal Array2OfReal;
31 GProp_PGProps::GProp_PGProps ()
38 void GProp_PGProps::AddPoint (const Pnt& P)
40 Standard_Real Xp, Yp, Zp;
42 Standard_Real Ixy = - Xp * Yp;
43 Standard_Real Ixz = - Xp * Zp;
44 Standard_Real Iyz = - Yp * Zp;
46 Standard_Real Ixx = Yp * Yp + Zp * Zp;
47 Standard_Real Iyy = Xp * Xp + Zp * Zp;
48 Standard_Real Izz = Xp * Xp + Yp * Yp;
49 Mat Mp (XYZ (Ixx, Ixy, Ixz), XYZ (Ixy, Iyy, Iyz), XYZ (Ixz, Iyz, Izz));
56 Standard_Real X, Y, Z;
66 inertia = inertia + Mp;
70 void GProp_PGProps::AddPoint (const gp_Pnt& P, const Standard_Real Density)
72 if (Density <= gp::Resolution()) throw Standard_DomainError();
73 Standard_Real Xp, Yp, Zp;
75 Standard_Real Ixy = - Xp * Yp;
76 Standard_Real Ixz = - Xp * Zp;
77 Standard_Real Iyz = - Yp * Zp;
78 Standard_Real Ixx = Yp * Yp + Zp * Zp;
79 Standard_Real Iyy = Xp * Xp + Zp * Zp;
80 Standard_Real Izz = Xp * Xp + Yp * Yp;
81 Mat Mp (XYZ (Ixx, Ixy, Ixz), XYZ (Ixy, Iyy, Iyz), XYZ (Ixz, Iyz, Izz));
85 inertia = Mp * Density;
88 Standard_Real X, Y, Z;
90 X = X * dim + Xp * Density;
91 Y = Y * dim + Yp * Density;
92 Z = Z * dim + Zp * Density;
98 inertia = inertia + Mp * Density;
102 GProp_PGProps::GProp_PGProps (const Array1OfPnt& Pnts)
104 for (Standard_Integer i = Pnts.Lower(); i <= Pnts.Upper(); i++) AddPoint(Pnts(i));
107 GProp_PGProps::GProp_PGProps (const Array2OfPnt& Pnts)
109 for (Standard_Integer j = Pnts.LowerCol(); j <= Pnts.UpperCol(); j++)
111 for (Standard_Integer i = Pnts.LowerRow(); i <= Pnts.UpperRow(); i++) AddPoint(Pnts (i, j));
115 GProp_PGProps::GProp_PGProps (const Array1OfPnt& Pnts,const Array1OfReal& Density)
117 if (Pnts.Length() != Density.Length()) throw Standard_DomainError();
118 Standard_Integer ip = Pnts.Lower();
119 Standard_Integer id = Density.Lower();
120 while (id <= Pnts.Upper()) {
121 Standard_Real D = Density (id);
122 if (D <= gp::Resolution()) throw Standard_DomainError();
123 AddPoint(Pnts (ip),D);
128 GProp_PGProps::GProp_PGProps (const Array2OfPnt& Pnts,const Array2OfReal& Density)
130 if (Pnts.ColLength() != Density.ColLength() || Pnts.RowLength() != Density.RowLength()) throw Standard_DomainError();
131 Standard_Integer ip = Pnts.LowerRow();
132 Standard_Integer id = Density.LowerRow();
133 Standard_Integer jp = Pnts.LowerCol();
134 Standard_Integer jd = Density.LowerCol();
135 while (jp <= Pnts.UpperCol()) {
136 while (ip <= Pnts.UpperRow()) {
137 Standard_Real D = Density (id, jd);
138 if (D <= gp::Resolution()) throw Standard_DomainError();
139 AddPoint(Pnts (ip, jp),D);
148 void GProp_PGProps::Barycentre(const Array1OfPnt& Pnts,
149 const Array1OfReal& Density,
153 if (Pnts.Length() != Density.Length()) throw Standard_DimensionError();
154 Standard_Integer ip = Pnts.Lower();
155 Standard_Integer id = Density.Lower();
157 XYZ Gxyz = Pnts (ip).XYZ();
158 Gxyz.Multiply (Mass);
159 while (ip <= Pnts.Upper()) {
160 Mass = Mass + Density (id);
161 Gxyz.Add ( (Pnts(ip).XYZ()).Multiplied (Density (id)) );
172 void GProp_PGProps::Barycentre(const Array2OfPnt& Pnts,
173 const Array2OfReal& Density,
177 if (Pnts.RowLength() != Density.RowLength() || Pnts.ColLength() != Density.ColLength()) throw Standard_DimensionError();
178 Standard_Integer ip = Pnts.LowerRow();
179 Standard_Integer id = Density.LowerRow();
180 Standard_Integer jp = Pnts.LowerCol();
181 Standard_Integer jd = Density.LowerCol();
183 XYZ Gxyz (0.0, 0.0, 0.0);
184 while (jp <= Pnts.UpperCol()) {
185 while (ip <= Pnts.UpperRow()) {
186 Mass = Mass + Density (id, jd);
187 Gxyz.Add ((Pnts(ip, jp).XYZ()).Multiplied (Density (id, jd)));
199 Pnt GProp_PGProps::Barycentre (const Array1OfPnt& Pnts) {
201 XYZ Gxyz = Pnts (Pnts.Lower()).XYZ();
202 for (Standard_Integer i = Pnts.Lower() + 1; i <= Pnts.Upper(); i++) {
203 Gxyz.Add (Pnts(i).XYZ());
205 Gxyz.Divide (Pnts.Length());
212 Pnt GProp_PGProps::Barycentre (const Array2OfPnt& Pnts) {
214 XYZ Gxyz (0.0, 0.0, 0.0);
215 for (Standard_Integer j = Pnts.LowerCol(); j <= Pnts.UpperCol(); j++) {
216 for (Standard_Integer i = Pnts.LowerRow(); i <= Pnts.UpperRow(); i++) {
217 Gxyz.Add (Pnts(i, j).XYZ());
220 Gxyz.Divide (Pnts.RowLength() * Pnts.ColLength());