Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSourcePonctuelleGraphic.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
25 
27 static const float SourceGraphicDefaultSize = 0.1f;
29 static const float SourceGraphicTypeUserSize = 2.0f;
30 
32  : TYElementGraphic(pElement)
33 {
34  setSize();
35 }
36 
38 
39 void TYSourcePonctuelleGraphic::update(bool force /*=false*/)
40 {
42 }
43 
45 {
46  float defaultSize = SourceGraphicDefaultSize;
47 
48 #if TY_USE_IHM
49  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "SrcPonctDefaultGraphicSize"))
50  {
51  defaultSize = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "SrcPonctDefaultGraphicSize");
52  }
53  else
54  {
55  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "SrcPonctDefaultGraphicSize", defaultSize);
56  }
57 #endif
58 
59  float UserSrcSize = SourceGraphicTypeUserSize;
60 
61 #if TY_USE_IHM
62  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "UserSrcPonctGraphicSize"))
63  {
64  UserSrcSize = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "UserSrcPonctGraphicSize");
65  }
66  else
67  {
68  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "UserSrcPonctGraphicSize", UserSrcSize);
69  }
70 #endif
71 
73  {
74  _size = UserSrcSize;
75  }
76  else
77  {
78  _size = defaultSize;
79  }
80 }
81 
83 {
84  OBox reset;
85  _boundingBox = reset;
86 
87  LPTYPoint pPt = getElement()->getPos();
88  _boundingBox.Enlarge((float)(pPt->_x - _size / 2), (float)(pPt->_y - _size / 2),
89  (float)(pPt->_z - _size / 2));
90  _boundingBox.Enlarge((float)(pPt->_x + _size / 2), (float)(pPt->_y + _size / 2),
91  (float)(pPt->_z + _size / 2));
92  if (getElement()->getType() == TYSourcePonctuelle::TypeUser)
93  {
94  // Vecteur Orientation
95  getElement()->getOrientation().normalize();
96  OVector3D vec = OVector3D(*pPt) + (getElement()->getOrientation());
97  _boundingBox.Enlarge((float)(pPt->_x), (float)(pPt->_y), (float)(pPt->_z)); // inutile...
98  _boundingBox.Enlarge((float)(vec._x), (float)(vec._y), (float)(vec._z));
99  }
100 }
101 
102 void TYSourcePonctuelleGraphic::display(TYElement* pModelerElement /*= nullptr*/, GLenum mode /*= GL_RENDER*/)
103 {
104  if (!getElement()->isInCurrentCalcul())
105  {
106  return;
107  }
108 
109  setSize();
110 
111  LPTYPoint pPt = getElement()->getPos();
112 
113  // Couleur de l'objet.
114  OColor color = getElement()->getColor();
115 
116  int object = getElement()->getObject();
117 
118  if (_highlight && _visible)
119  {
120  OColor tmpColor;
121  glGetFloatv(GL_CURRENT_COLOR, tmpColor);
122  if (_bFirstDisp)
123  {
125  _bFirstDisp = false;
126  }
128  if (mode == GL_COMPILE)
129  {
130  drawName(pModelerElement);
131  }
132  // Modification de la couleur en GL_CURRENT_COLOR si _highlight.
133  glColor3fv(tmpColor);
134  }
135 
136  if (_visible)
137  {
138  if (mode == GL_SELECT)
139  {
140  TYPickingTable::addElement(getElement());
141  glPushName((GLuint)(TYPickingTable::getIndex()));
142  }
143 
144  // Fixe la couleur a l'objet.
145  glColor3fv(color);
146 
147  switch (object)
148  {
150  drawCube(pPt);
151  break;
153  drawPyramid(pPt);
154  break;
156  drawSphere(pPt);
157  break;
159  drawStar(pPt);
160  break;
161  default:
162  break;
163  }
164 
165  if (getElement()->getType() == TYSourcePonctuelle::TypeUser)
166  {
167  // Vecteur Orientation
168  getElement()->getOrientation().normalize();
169  OVector3D vec = OVector3D(*pPt) + (getElement()->getOrientation());
170 
171  glBegin(GL_LINES);
172  glColor3fv(color);
173  glVertex3f(pPt->_x, pPt->_y, pPt->_z);
174  glVertex3f((vec._x + _size / 2), (vec._y + _size / 2), (vec._z + _size / 2));
175  glEnd();
176  }
177 
178  if (mode == GL_SELECT)
179  {
180  glPopName();
181  }
182  // Calcul du volume englobant pour le fit:
184  }
185 }
186 
188 {
189  glBegin(GL_QUADS);
190 
191  glNormal3f(0.0f, 1.0f, 0.0f);
192  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
193  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
194  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
195  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
196 
197  glNormal3f(0.0f, -1.0f, 0.0f);
198  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
199  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
200  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
201  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
202 
203  glNormal3f(0.0f, 0.0f, 1.0f);
204  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
205  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
206  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
207  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
208 
209  glNormal3f(0.0f, 0.0f, -1.0f);
210  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
211  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
212  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
213  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
214 
215  glNormal3f(-1.0f, 0.0f, 0.0f);
216  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
217  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
218  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
219  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
220 
221  glNormal3f(1.0f, 0.0f, 0.0f);
222  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
223  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
224  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z + _size / 2);
225  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
226 
227  glEnd();
228 }
229 
231 {
232  glBegin(GL_TRIANGLES);
233 
234  glNormal3f(0.0f, -1.0f, 0.5f);
235  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
236  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
237  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
238 
239  glNormal3f(1.0f, 0.0f, 0.5f);
240  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
241  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
242  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
243 
244  glNormal3f(0.0f, 1.0f, 0.5f);
245  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
246  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
247  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
248 
249  glNormal3f(-1.0f, 0.0f, 0.5f);
250  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
251  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
252  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
253 
254  glEnd();
255 
256  glBegin(GL_QUADS);
257 
258  glNormal3f(0.0f, 0.0f, -1.0f);
259  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
260  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
261  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
262  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
263 
264  glEnd();
265 }
266 
268 {
269  GLUquadricObj* qobj = gluNewQuadric();
270  glTranslatef(pPt->_x, pPt->_y, pPt->_z);
271  gluSphere(qobj, _size / 2.0f, 20, 20);
272  glTranslatef(-pPt->_x, -pPt->_y, -pPt->_z);
273  gluDeleteQuadric(qobj);
274 }
275 
277 {
278  glBegin(GL_TRIANGLES);
279 
280  // Up pyramid
281  glNormal3f(0.0f, -1.0f, 0.5f);
282  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
283  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
284  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
285 
286  glNormal3f(1.0f, 0.0f, 0.5f);
287  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
288  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
289  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
290 
291  glNormal3f(0.0f, 1.0f, 0.5f);
292  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
293  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
294  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
295 
296  glNormal3f(-1.0f, 0.0f, 0.5f);
297  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
298  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
299  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
300 
301  // Right pyramid
302  glNormal3f(0.5f, -1.0f, 0.0f);
303  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
304  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
305  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
306 
307  glNormal3f(0.5f, 0.0f, -1.0f);
308  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
309  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
310  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
311 
312  glNormal3f(0.5f, 1.0f, 0.0f);
313  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
314  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
315  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
316 
317  glNormal3f(0.5f, 0.0f, 1.0f);
318  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
319  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
320  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
321 
322  // Down pyramid
323  glNormal3f(0.0f, 1.0f, 0.5f);
324  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
325  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
326  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
327 
328  glNormal3f(-1.0f, 0.0f, 0.5f);
329  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
330  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
331  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
332 
333  glNormal3f(0.0f, -1.0f, 0.5f);
334  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
335  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
336  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
337 
338  glNormal3f(1.0f, 0.0f, 0.5f);
339  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
340  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
341  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
342 
343  // Left pyramid
344  glNormal3f(0.5f, 1.0f, 0.0f);
345  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
346  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
347  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
348 
349  glNormal3f(0.5f, 0.0f, 1.0f);
350  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
351  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
352  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
353 
354  glNormal3f(0.5f, -1.0f, 0.0f);
355  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
356  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
357  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
358 
359  glNormal3f(0.5f, 0.0f, -1.0f);
360  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
361  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
362  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
363 
364  // Back pyramid
365  glNormal3f(0.0f, 0.5f, 1.0f);
366  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
367  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
368  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
369 
370  glNormal3f(1.0f, 0.5f, 0.0f);
371  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
372  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
373  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
374 
375  glNormal3f(0.0f, 0.5f, -1.0f);
376  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
377  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
378  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
379 
380  glNormal3f(-1.0f, 0.5f, 0.0f);
381  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
382  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
383  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
384 
385  // Front pyramid
386  glNormal3f(0.0f, 0.5f, -1.0f);
387  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
388  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
389  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
390 
391  glNormal3f(-1.0f, 0.5f, 0.0f);
392  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
393  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
394  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
395 
396  glNormal3f(0.0f, 0.5f, 1.0f);
397  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
398  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
399  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
400 
401  glNormal3f(1.0f, 0.5f, 0.0f);
402  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
403  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
404  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
405 
406  glEnd();
407 }
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:52
Gestion de la table de correspondance indice/element pour le picking (fichier header)
Representation graphique d'une source ponctuelle (fichier header)
The box class.
Definition: 3d.h:1294
virtual void Enlarge(const OPoint3D &pt)
Enlarge the box with the point if the point is outside the box.
Definition: 3d.cpp:1614
Definition: color.h:31
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
The 3D vector class.
Definition: 3d.h:298
classe graphique pour un element de base
void drawName(TYElement *pModelerElement=nullptr)
static OBox _globalBoundingBox
bool _visible
Inique si l'element est visible.
bool _highlight
Indique si le highlight est active pour cet element.
virtual void update(bool force=false)
TYElement * _pElement
L'element metier auquel cet element graphique metier est associe.
static int getIndex()
static void addElement(TYElement *pElt)
virtual void update(bool force=false)
Mise a jour.
void drawPyramid(TYPoint *pPt) const
float _size
Taille de la source.
virtual void display(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
virtual void computeBoundingBox()
calcul de la boite englobante
TYSourcePonctuelleGraphic(TYSourcePonctuelle *pElement)
void drawSphere(TYPoint *pPt) const