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