Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSourcePonctuelleGraphic.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
26 
28 static const float SourceGraphicDefaultSize = 0.1f;
30 static const float SourceGraphicTypeUserSize = 2.0f;
31 
33  : TYElementGraphic(pElement)
34 {
35  _size = SourceGraphicDefaultSize;
36 }
37 
39 
40 void TYSourcePonctuelleGraphic::update(bool force /*=false*/)
41 {
43 }
44 
46 {
47  float defaultSize = SourceGraphicDefaultSize;
48 
49 #if TY_USE_IHM
50  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "SrcPonctDefaultGraphicSize"))
51  {
52  defaultSize = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "SrcPonctDefaultGraphicSize");
53  }
54  else
55  {
56  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "SrcPonctDefaultGraphicSize", defaultSize);
57  }
58 #endif
59 
60  float UserSrcSize = SourceGraphicTypeUserSize;
61 
62 #if TY_USE_IHM
63  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "UserSrcPonctGraphicSize"))
64  {
65  UserSrcSize = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "UserSrcPonctGraphicSize");
66  }
67  else
68  {
69  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "UserSrcPonctGraphicSize", UserSrcSize);
70  }
71 #endif
72 
74  {
75  _size = UserSrcSize;
76  }
77  else
78  {
79  _size = defaultSize;
80  }
82 }
83 
85 {
87 
88  LPTYPoint pPt = getElement()->getPos();
89  boundingBox.Enlarge((float)(pPt->_x - _size / 2), (float)(pPt->_y - _size / 2),
90  (float)(pPt->_z - _size / 2));
91  boundingBox.Enlarge((float)(pPt->_x + _size / 2), (float)(pPt->_y + _size / 2),
92  (float)(pPt->_z + _size / 2));
93  if (getElement()->getType() == TYSourcePonctuelle::TypeUser)
94  {
95  // Vecteur Orientation
96  getElement()->getOrientation().normalize();
97  OVector3D vec = OVector3D(*pPt) + (getElement()->getOrientation());
98  boundingBox.Enlarge((float)(pPt->_x), (float)(pPt->_y), (float)(pPt->_z)); // inutile...
99  boundingBox.Enlarge((float)(vec._x), (float)(vec._y), (float)(vec._z));
100  }
101  return boundingBox;
102 }
103 
105 {
106  if (!getElement()->isInCurrentCalcul())
107  {
108  return;
109  }
110 
111  setSize();
112 
113  LPTYPoint pPt = getElement()->getPos();
114 
115  // Couleur de l'objet.
116  OColor color = getElement()->getColor();
117 
118  int object = getElement()->getObject();
119 
120  if (_highlight && _visible)
121  {
122  OColor tmpColor;
123  glGetFloatv(GL_CURRENT_COLOR, tmpColor);
124  if (renderContext.pass == TYRenderPass::Overlay)
125  {
126  drawName(renderContext);
127  }
128  // Modification de la couleur en GL_CURRENT_COLOR si _highlight.
129  glColor3fv(tmpColor);
130  }
131 
132  if (_visible)
133  {
134  if (renderContext.type == TYRenderType::Picking)
135  {
136  TYPickingTable::addElement(getElement());
137  glPushName((GLuint)(TYPickingTable::getIndex()));
138  }
139 
140  // Fixe la couleur a l'objet.
141  glColor3fv(color);
142 
143  switch (object)
144  {
146  drawCube(pPt);
147  break;
149  drawPyramid(pPt);
150  break;
152  drawSphere(pPt);
153  break;
155  drawStar(pPt);
156  break;
157  default:
158  break;
159  }
160 
161  if (getElement()->getType() == TYSourcePonctuelle::TypeUser)
162  {
163  // Vecteur Orientation
164  getElement()->getOrientation().normalize();
165  OVector3D vec = OVector3D(*pPt) + (getElement()->getOrientation());
166 
167  glBegin(GL_LINES);
168  glColor3fv(color);
169  glVertex3f(pPt->_x, pPt->_y, pPt->_z);
170  glVertex3f((vec._x + _size / 2), (vec._y + _size / 2), (vec._z + _size / 2));
171  glEnd();
172  }
173 
174  if (renderContext.type == TYRenderType::Picking)
175  {
176  glPopName();
177  }
178  }
179 }
180 
182 {
183  glBegin(GL_QUADS);
184 
185  glNormal3f(0.0f, 1.0f, 0.0f);
186  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
187  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
188  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
189  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z + _size / 2);
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, 0.0f, 1.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(-1.0f, 0.0f, 0.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  glEnd();
222 }
223 
225 {
226  glBegin(GL_TRIANGLES);
227 
228  glNormal3f(0.0f, -1.0f, 0.5f);
229  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
230  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
231  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
232 
233  glNormal3f(1.0f, 0.0f, 0.5f);
234  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
235  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
236  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
237 
238  glNormal3f(0.0f, 1.0f, 0.5f);
239  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
240  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
241  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
242 
243  glNormal3f(-1.0f, 0.0f, 0.5f);
244  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
245  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
246  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
247 
248  glEnd();
249 
250  glBegin(GL_QUADS);
251 
252  glNormal3f(0.0f, 0.0f, -1.0f);
253  glVertex3f(pPt->_x + _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
254  glVertex3f(pPt->_x - _size / 2, pPt->_y - _size / 2, pPt->_z - _size / 2);
255  glVertex3f(pPt->_x - _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
256  glVertex3f(pPt->_x + _size / 2, pPt->_y + _size / 2, pPt->_z - _size / 2);
257 
258  glEnd();
259 }
260 
262 {
263  GLUquadricObj* qobj = gluNewQuadric();
264  glTranslatef(pPt->_x, pPt->_y, pPt->_z);
265  gluSphere(qobj, _size / 2.0f, 20, 20);
266  glTranslatef(-pPt->_x, -pPt->_y, -pPt->_z);
267  gluDeleteQuadric(qobj);
268 }
269 
271 {
272  glBegin(GL_TRIANGLES);
273 
274  // Up pyramid
275  glNormal3f(0.0f, -1.0f, 0.5f);
276  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
277  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
278  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
279 
280  glNormal3f(1.0f, 0.0f, 0.5f);
281  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
282  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
283  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
284 
285  glNormal3f(0.0f, 1.0f, 0.5f);
286  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
287  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
288  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
289 
290  glNormal3f(-1.0f, 0.0f, 0.5f);
291  glVertex3f(pPt->_x, pPt->_y, pPt->_z + _size / 2);
292  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
293  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
294 
295  // Right pyramid
296  glNormal3f(0.5f, -1.0f, 0.0f);
297  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
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  glNormal3f(0.5f, 0.0f, -1.0f);
302  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
303  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
304  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
305 
306  glNormal3f(0.5f, 1.0f, 0.0f);
307  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
308  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
309  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
310 
311  glNormal3f(0.5f, 0.0f, 1.0f);
312  glVertex3f(pPt->_x + _size / 2, pPt->_y, pPt->_z);
313  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
314  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
315 
316  // Down pyramid
317  glNormal3f(0.0f, 1.0f, 0.5f);
318  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
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  glNormal3f(-1.0f, 0.0f, 0.5f);
323  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
324  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
325  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
326 
327  glNormal3f(0.0f, -1.0f, 0.5f);
328  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
329  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
330  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
331 
332  glNormal3f(1.0f, 0.0f, 0.5f);
333  glVertex3f(pPt->_x, pPt->_y, pPt->_z - _size / 2);
334  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
335  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
336 
337  // Left pyramid
338  glNormal3f(0.5f, 1.0f, 0.0f);
339  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
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  glNormal3f(0.5f, 0.0f, 1.0f);
344  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
345  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
346  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
347 
348  glNormal3f(0.5f, -1.0f, 0.0f);
349  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
350  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
351  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
352 
353  glNormal3f(0.5f, 0.0f, -1.0f);
354  glVertex3f(pPt->_x - _size / 2, pPt->_y, pPt->_z);
355  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
356  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
357 
358  // Back pyramid
359  glNormal3f(0.0f, 0.5f, 1.0f);
360  glVertex3f(pPt->_x, pPt->_y + _size / 2, 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  glNormal3f(1.0f, 0.5f, 0.0f);
365  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
366  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
367  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
368 
369  glNormal3f(0.0f, 0.5f, -1.0f);
370  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
371  glVertex3f(pPt->_x + _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
372  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
373 
374  glNormal3f(-1.0f, 0.5f, 0.0f);
375  glVertex3f(pPt->_x, pPt->_y + _size / 2, pPt->_z);
376  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z - _size / 6);
377  glVertex3f(pPt->_x - _size / 6, pPt->_y + _size / 6, pPt->_z + _size / 6);
378 
379  // Front pyramid
380  glNormal3f(0.0f, 0.5f, -1.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  glNormal3f(-1.0f, 0.5f, 0.0f);
386  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
387  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
388  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
389 
390  glNormal3f(0.0f, 0.5f, 1.0f);
391  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
392  glVertex3f(pPt->_x + _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
393  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
394 
395  glNormal3f(1.0f, 0.5f, 0.0f);
396  glVertex3f(pPt->_x, pPt->_y - _size / 2, pPt->_z);
397  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z - _size / 6);
398  glVertex3f(pPt->_x - _size / 6, pPt->_y - _size / 6, pPt->_z + _size / 6);
399 
400  glEnd();
401 }
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
Gestion de la table de correspondance indice/element pour le picking (fichier header)
Contexte de rendu utilisé par les fonctions d'affichage.
@ Picking
The current render is only done for picking purpose.
@ Overlay
The current render pass is for overlay elements.
Representation graphique d'une source ponctuelle (fichier header)
The box class.
Definition: 3d.h:1346
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:36
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(TYRenderContext &renderContext)
bool _visible
Inique si l'element est visible.
OBox boundingBox() const
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)
TYRenderType type
TYRenderPass pass
virtual void display(TYRenderContext &renderContext)
virtual OBox computeBoundingBox() const
calcul de la boite englobante
virtual void update(bool force=false)
Mise a jour.
void drawPyramid(TYPoint *pPt) const
float _size
Taille de la source.
TYSourcePonctuelleGraphic(TYSourcePonctuelle *pElement)
void drawSphere(TYPoint *pPt) const