0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / BRepGProp / BRepGProp_Vinert.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <BRepGProp_Domain.hxx>
17 #include <BRepGProp_Face.hxx>
18 #include <BRepGProp_Gauss.hxx>
19 #include <BRepGProp_Vinert.hxx>
20 #include <gp_Pln.hxx>
21 #include <gp_Pnt.hxx>
22
23 //=======================================================================
24 //function : BRepGProp_Vinert
25 //purpose  : Constructor
26 //=======================================================================
27 BRepGProp_Vinert::BRepGProp_Vinert()
28 {
29 }
30
31 //=======================================================================
32 //function : BRepGProp_Vinert
33 //purpose  : 
34 //=======================================================================
35 BRepGProp_Vinert::BRepGProp_Vinert(BRepGProp_Face&     theSurface,
36                                    const gp_Pnt&       theLocation,
37                                    const Standard_Real theEps)
38 {
39   SetLocation(theLocation);
40   Perform(theSurface, theEps);
41 }
42
43 //=======================================================================
44 //function : BRepGProp_Vinert
45 //purpose  : 
46 //=======================================================================
47 BRepGProp_Vinert::BRepGProp_Vinert(BRepGProp_Face&     theSurface,
48                                    BRepGProp_Domain&   theDomain,
49                                    const gp_Pnt&       theLocation,
50                                    const Standard_Real theEps)
51 {
52   SetLocation(theLocation);
53   Perform(theSurface, theDomain, theEps);
54 }
55
56 //=======================================================================
57 //function : BRepGProp_Vinert
58 //purpose  : 
59 //=======================================================================
60 BRepGProp_Vinert::BRepGProp_Vinert(BRepGProp_Face&   theSurface,
61                                    BRepGProp_Domain& theDomain,
62                                    const gp_Pnt&     theLocation)
63 {
64   SetLocation(theLocation);
65   Perform(theSurface, theDomain);
66 }
67
68 //=======================================================================
69 //function : BRepGProp_Vinert
70 //purpose  : 
71 //=======================================================================
72 BRepGProp_Vinert::BRepGProp_Vinert(const BRepGProp_Face& theSurface,
73                                    const gp_Pnt&         theLocation)
74 {
75   SetLocation(theLocation);
76   Perform(theSurface);
77 }
78
79 //=======================================================================
80 //function : BRepGProp_Vinert
81 //purpose  : 
82 //=======================================================================
83 BRepGProp_Vinert::BRepGProp_Vinert(BRepGProp_Face&     theSurface,
84                                    const gp_Pnt&       theOrigin,
85                                    const gp_Pnt&       theLocation,
86                                    const Standard_Real theEps)
87 {
88   SetLocation(theLocation);
89   Perform(theSurface, theOrigin, theEps);
90 }
91
92 //=======================================================================
93 //function : BRepGProp_Vinert
94 //purpose  : 
95 //=======================================================================
96 BRepGProp_Vinert::BRepGProp_Vinert(BRepGProp_Face&     theSurface,
97                                    BRepGProp_Domain&   theDomain,
98                                    const gp_Pnt&       theOrigin,
99                                    const gp_Pnt&       theLocation,
100                                    const Standard_Real theEps)
101 {
102   SetLocation(theLocation);
103   Perform(theSurface, theDomain, theOrigin, theEps);
104 }
105
106 //=======================================================================
107 //function : BRepGProp_Vinert
108 //purpose  : 
109 //=======================================================================
110 BRepGProp_Vinert::BRepGProp_Vinert(const BRepGProp_Face& theSurface,
111                                    const gp_Pnt&         theOrigin,
112                                    const gp_Pnt&         theLocation)
113 {
114   SetLocation(theLocation);
115   Perform(theSurface, theOrigin);
116 }
117
118 //=======================================================================
119 //function : BRepGProp_Vinert
120 //purpose  : 
121 //=======================================================================
122 BRepGProp_Vinert::BRepGProp_Vinert(BRepGProp_Face&   theSurface,
123                                    BRepGProp_Domain& theDomain,
124                                    const gp_Pnt&     theOrigin,
125                                    const gp_Pnt&     theLocation)
126 {
127   SetLocation(theLocation);
128   Perform(theSurface, theDomain, theOrigin);
129 }
130
131 //=======================================================================
132 //function : BRepGProp_Vinert
133 //purpose  : 
134 //=======================================================================
135 BRepGProp_Vinert::BRepGProp_Vinert(BRepGProp_Face&     theSurface,
136                                    const gp_Pln&       thePlane,
137                                    const gp_Pnt&       theLocation,
138                                    const Standard_Real theEps)
139 {
140   SetLocation(theLocation);
141   Perform(theSurface, thePlane, theEps);
142 }
143
144 //=======================================================================
145 //function : BRepGProp_Vinert
146 //purpose  : 
147 //=======================================================================
148 BRepGProp_Vinert::BRepGProp_Vinert(BRepGProp_Face&     theSurface,
149                                    BRepGProp_Domain&   theDomain,
150                                    const gp_Pln&       thePlane,
151                                    const gp_Pnt&       theLocation,
152                                    const Standard_Real theEps)
153 {
154   SetLocation(theLocation);
155   Perform(theSurface, theDomain, thePlane, theEps);
156 }
157
158 //=======================================================================
159 //function : BRepGProp_Vinert
160 //purpose  : 
161 //=======================================================================
162 BRepGProp_Vinert::BRepGProp_Vinert(const BRepGProp_Face& theSurface,
163                                    const gp_Pln&         thePlane,
164                                    const gp_Pnt&         theLocation)
165 {
166   SetLocation(theLocation);
167   Perform(theSurface, thePlane);
168 }
169
170 //=======================================================================
171 //function : BRepGProp_Vinert
172 //purpose  : 
173 //=======================================================================
174 BRepGProp_Vinert::BRepGProp_Vinert(BRepGProp_Face&   theSurface,
175                                    BRepGProp_Domain& theDomain,
176                                    const gp_Pln&     thePlane,
177                                    const gp_Pnt&     theLocation)
178 {
179   SetLocation(theLocation);
180   Perform(theSurface, theDomain, thePlane);
181 }
182
183 //=======================================================================
184 //function : SetLocation
185 //purpose  : 
186 //=======================================================================
187 void BRepGProp_Vinert::SetLocation(const gp_Pnt& theLocation)
188 {
189   loc = theLocation;
190 }
191
192 //=======================================================================
193 //function : Perform
194 //purpose  : 
195 //=======================================================================
196 Standard_Real BRepGProp_Vinert::Perform(BRepGProp_Face&     theSurface,
197                                         const Standard_Real theEps)
198 {
199   BRepGProp_Domain anEmptyDomain;
200   return Perform(theSurface, anEmptyDomain, theEps);
201 }
202
203 //=======================================================================
204 //function : 
205 //purpose  : 
206 //=======================================================================
207 Standard_Real BRepGProp_Vinert::Perform(BRepGProp_Face&     theSurface,
208                                         BRepGProp_Domain&   theDomain,
209                                         const Standard_Real theEps)
210 {
211   const Standard_Real aCoeff[] = {0.0, 0.0, 0.0};
212   BRepGProp_Gauss     aGauss(BRepGProp_Gauss::Vinert);
213
214   return myEpsilon =
215     aGauss.Compute(theSurface, theDomain, loc, theEps,
216                    aCoeff, Standard_True, dim, g, inertia);
217 }
218
219 //=======================================================================
220 //function : Perform
221 //purpose  : 
222 //=======================================================================
223 void BRepGProp_Vinert::Perform(const BRepGProp_Face& theSurface)
224 {
225   const Standard_Real aCoeff[] = {0.0, 0.0, 0.0};
226   BRepGProp_Gauss     aGauss(BRepGProp_Gauss::Vinert);
227
228   myEpsilon = 1.0;
229   aGauss.Compute(theSurface, loc, aCoeff, Standard_True, dim, g, inertia);
230 }
231
232 //=======================================================================
233 //function : Perform
234 //purpose  : 
235 //=======================================================================
236 void BRepGProp_Vinert::Perform(BRepGProp_Face&   theSurface,
237                                BRepGProp_Domain& theDomain)
238 {
239   const Standard_Real aCoeff[] = {0.0, 0.0, 0.0};
240   BRepGProp_Gauss     aGauss(BRepGProp_Gauss::Vinert);
241
242   myEpsilon = 1.0;
243   aGauss.Compute(theSurface, theDomain, loc, aCoeff, Standard_True, dim, g, inertia);
244 }
245
246 //=======================================================================
247 //function : Perform
248 //purpose  : 
249 //=======================================================================
250 Standard_Real BRepGProp_Vinert::Perform(BRepGProp_Face&     theSurface,
251                                         const gp_Pnt&       theOrigin,
252                                         const Standard_Real theEps)
253 {
254   BRepGProp_Domain anEmptyDomain;
255   return Perform(theSurface, anEmptyDomain, theOrigin, theEps);
256 }
257
258 //=======================================================================
259 //function : Perform
260 //purpose  : 
261 //=======================================================================
262 Standard_Real BRepGProp_Vinert::Perform(BRepGProp_Face&     theSurface,
263                                         BRepGProp_Domain&   theDomain,
264                                         const gp_Pnt&       theOrigin,
265                                         const Standard_Real theEps)
266 {
267   const Standard_Real aCoeff[] =
268   {
269     theOrigin.X() - loc.X(),
270     theOrigin.Y() - loc.Y(),
271     theOrigin.Z() - loc.Z()
272   };
273
274   BRepGProp_Gauss  aGauss(BRepGProp_Gauss::Vinert);
275
276   return myEpsilon =
277     aGauss.Compute(theSurface, theDomain, loc, theEps,
278                    aCoeff, Standard_True, dim, g, inertia);
279 }
280
281 //=======================================================================
282 //function : Perform
283 //purpose  : 
284 //=======================================================================
285 void BRepGProp_Vinert::Perform(const BRepGProp_Face& theSurface,
286                                const gp_Pnt&         theOrigin)
287 {
288   BRepGProp_Gauss     aGauss(BRepGProp_Gauss::Vinert);
289   const Standard_Real aCoeff[] =
290   {
291     theOrigin.X() - loc.X(),
292     theOrigin.Y() - loc.Y(),
293     theOrigin.Z() - loc.Z()
294   };
295
296   myEpsilon = 1.0;
297   aGauss.Compute(theSurface, loc, aCoeff, Standard_True, dim, g, inertia);
298 }
299
300 //=======================================================================
301 //function : Perform
302 //purpose  : 
303 //=======================================================================
304 void BRepGProp_Vinert::Perform(BRepGProp_Face&   theSurface,
305                                BRepGProp_Domain& theDomain,
306                                const gp_Pnt&     theOrigin)
307 {
308   BRepGProp_Gauss     aGauss(BRepGProp_Gauss::Vinert);
309   const Standard_Real aCoeff[] =
310   {
311     theOrigin.X() - loc.X(),
312     theOrigin.Y() - loc.Y(),
313     theOrigin.Z() - loc.Z()
314   };
315
316   myEpsilon = 1.0;
317   aGauss.Compute(theSurface, theDomain, loc, aCoeff, Standard_True, dim, g, inertia);
318 }
319
320 //=======================================================================
321 //function : 
322 //purpose  : 
323 //=======================================================================
324 Standard_Real BRepGProp_Vinert::Perform(BRepGProp_Face&     theSurface,
325                                         const gp_Pln&       thePlane,
326                                         const Standard_Real theEps)
327 {
328   BRepGProp_Domain anEmptyDomain;
329   return Perform(theSurface, anEmptyDomain, thePlane, theEps);
330 }
331
332 //=======================================================================
333 //function : Perform
334 //purpose  : 
335 //=======================================================================
336 Standard_Real BRepGProp_Vinert::Perform(BRepGProp_Face&     theSurface,
337                                         BRepGProp_Domain&   theDomain,
338                                         const gp_Pln&       thePlane,
339                                         const Standard_Real theEps)
340 {
341   Standard_Real aCoeff[4];
342   thePlane.Coefficients(aCoeff[0], aCoeff[1], aCoeff[2], aCoeff[3]);
343   aCoeff[3] = aCoeff[3] - aCoeff[0] * loc.X()
344                         - aCoeff[1] * loc.Y()
345                         - aCoeff[2] * loc.Z();
346
347   BRepGProp_Gauss  aGauss(BRepGProp_Gauss::Vinert);
348
349   return myEpsilon =
350     aGauss.Compute(theSurface, theDomain, loc, theEps,
351                    aCoeff, Standard_False, dim, g, inertia);
352 }
353
354 //=======================================================================
355 //function : Perform
356 //purpose  : 
357 //=======================================================================
358 void BRepGProp_Vinert::Perform(const BRepGProp_Face& theSurface,
359                                const gp_Pln&         thePlane)
360 {
361   BRepGProp_Gauss aGauss(BRepGProp_Gauss::Vinert);
362   Standard_Real   aCoeff[4];
363
364   thePlane.Coefficients  (aCoeff[0],
365                           aCoeff[1],
366                           aCoeff[2],
367                           aCoeff[3]);
368
369   aCoeff[3] = aCoeff[3] - aCoeff[0] * loc.X()
370                         - aCoeff[1] * loc.Y()
371                         - aCoeff[2] * loc.Z();
372
373   myEpsilon = 1.0;
374   aGauss.Compute(theSurface, loc, aCoeff, Standard_False, dim, g, inertia);
375 }
376
377 //=======================================================================
378 //function : Perform
379 //purpose  : 
380 //=======================================================================
381 void BRepGProp_Vinert::Perform(BRepGProp_Face&   theSurface,
382                                BRepGProp_Domain& theDomain,
383                                const gp_Pln&     thePlane)
384 {
385   BRepGProp_Gauss aGauss(BRepGProp_Gauss::Vinert);
386   Standard_Real   aCoeff[4];
387
388   thePlane.Coefficients  (aCoeff[0],
389                           aCoeff[1],
390                           aCoeff[2],
391                           aCoeff[3]);
392
393   aCoeff[3] = aCoeff[3] - aCoeff[0] * loc.X()
394                         - aCoeff[1] * loc.Y()
395                         - aCoeff[2] * loc.Z();
396
397   myEpsilon = 1.0;
398   aGauss.Compute(theSurface, theDomain, loc, aCoeff, Standard_False, dim, g, inertia);
399 }
400
401 //=======================================================================
402 //function : GetEpsilon
403 //purpose  : 
404 //=======================================================================
405 Standard_Real BRepGProp_Vinert::GetEpsilon()
406 {
407   return myEpsilon;
408 }