Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYLinearMaillageGraphic.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 
21 #include "Tympan/core/defines.h"
28 
29 #include <math.h>
30 #include "gui/gl/TYRenderContext.h"
31 #include <QtOpenGL>
32 
34 {
35  _scalarX = 0.8;
36  _scalarY = 0.25;
37 
38  _scalarW = 150.0;
39  _scalarH = 15.0;
40 
41  _panelW = 125.0;
42  _panelH = 40.0;
43 
44  TYElementGraphic* pTYElementGraphic = getElement()->getPalette()->getGraphicObject();
45  ((TYPaletteGraphic*)pTYElementGraphic)->setWidth(_scalarW);
46  ((TYPaletteGraphic*)pTYElementGraphic)->setHeight(_scalarH);
47 
48  pTYElementGraphic = getElement()->getPanel()->getGraphicObject();
49  ((TYPanelGraphic*)pTYElementGraphic)->setWidth(_panelW);
50  ((TYPanelGraphic*)pTYElementGraphic)->setHeight(_panelH);
51  pTYElementGraphic->setVisible(false);
52 }
53 
55 
56 void TYLinearMaillageGraphic::update(bool force /*=false*/)
57 {
58  TYLinearMaillage* pMaillage = getElement();
59  pMaillage->getPalette()->getGraphicObject()->update(force);
60 
62 }
63 
65 {
67  TYTabLPPointCalcul* pPtsCalcul = &getElement()->getPtsCalcul();
68  TYPointCalcul* pPtCalcul = NULL;
69  for (unsigned int i = 0; i < pPtsCalcul->size(); i++)
70  {
71  pPtCalcul = pPtsCalcul->at(i);
72  boundingBox.Enlarge((float)(pPtCalcul->_x), (float)(pPtCalcul->_y), (float)(pPtCalcul->_z));
73  }
74  return boundingBox;
75 }
76 
78 {
79  // Pas affiche si inactif
80  if (getElement()->etat() == false)
81  {
82  return;
83  }
84 
85  // Les points de ce maillage
86  TYTabLPPointCalcul* pPtsCalcul = &getElement()->getPtsCalcul();
87 
88  if (_visible)
89  {
90 
91  if (renderContext.type == TYRenderType::Picking)
92  {
93  TYPickingTable::addElement(getElement());
94  glPushName((GLuint)(TYPickingTable::getIndex()));
95  }
96 
97  float opacity = 1.0;
98 
99 #if TY_USE_IHM
100  // static const char prefName[] = "MaillageOpacity";
101 
102  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MaillageOpacity"))
103  {
104  opacity = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "MaillageOpacity");
105  }
106  else
107  {
108  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "MaillageOpacity", opacity);
109  }
110 #endif // TY_USE_IHM
111 
112  glBegin(GL_LINE_STRIP);
113  TYPointCalcul* pPtCalcul = NULL;
114  double value = 0.0;
115  for (unsigned int i = 0; i < pPtsCalcul->size(); i++)
116  {
117  pPtCalcul = pPtsCalcul->at(i);
118 
119  // Valeur du scalaire pour la color map
120  switch (getElement()->getDataType())
121  {
123  default:
124  value = pPtCalcul->getSpectre()->valGlobDBA();
125  break;
127  value = pPtCalcul->getSpectre()->valGlobDBLin();
128  break;
130  value = pPtCalcul->getSpectre()->getValueReal(getElement()->getDataFreq());
131  break;
132  }
133  const OColor& color = getElement()->getPalette()->getColorFromValue(value);
134  glColor4f(color.r, color.g, color.b, opacity);
135  glVertex3f(pPtCalcul->_x, pPtCalcul->_y, pPtCalcul->_z);
136  }
137  glEnd();
138 
139  if (renderContext.type == TYRenderType::Picking)
140  {
141  glPopName();
142  }
143 
144  // Affichage du panel
145  TYElementGraphic* pTYElementGraphic = getElement()->getPanel()->getGraphicObject();
146  TYPanelGraphic* pTYPanelGraphic = (TYPanelGraphic*)pTYElementGraphic;
147  pTYPanelGraphic->display(renderContext);
148  }
149 
150  if (_highlight)
151  {
152  GLfloat pointSize = NAN;
153  glGetFloatv(GL_POINT_SIZE, &pointSize);
154 
155  if (renderContext.pass == TYRenderPass::Overlay)
156  {
157  drawName(renderContext);
158  }
159 
160  glPointSize(pointSize);
161 
162  TYElementGraphic* pTYElementGraphic = getElement()->getPalette()->getGraphicObject();
163  TYPaletteGraphic* pTYPaletteGraphic = (TYPaletteGraphic*)pTYElementGraphic;
164 
165  GLint viewport[4];
166  glGetIntegerv(GL_VIEWPORT, viewport);
167  unsigned int width = viewport[2];
168  unsigned int height = viewport[3];
169  pTYPaletteGraphic->setPosX(width * _scalarX);
170  pTYPaletteGraphic->setPosY(height * _scalarY);
171  pTYPaletteGraphic->display(renderContext);
172  }
173 }
std::vector< LPTYPointCalcul > TYTabLPPointCalcul
Collection de pointeurs de TYPointCalcul.
Definition: TYDefines.h:358
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
Representation graphique d'un maillage lineaire (fichier header)
Representation d'une palette graphique (fichier header)
Representation graphique d'un panel d'informations (fichier header)
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.
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:31
float b
Definition: color.h:33
float r
Definition: color.h:33
float g
Definition: color.h:33
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
double valGlobDBA() const
Compute the global value dB[A] of a one-third Octave spectrum.
Definition: spectre.cpp:691
double valGlobDBLin() const
Compute the global value dB[Lin] of a one-third Octave spectrum.
Definition: spectre.cpp:679
double getValueReal(double freq)
Definition: spectre.cpp:974
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)
void setVisible(bool visible=true)
virtual void update(bool force=false)
TYLinearMaillageGraphic(TYLinearMaillage *pElement)
virtual OBox computeBoundingBox() const
virtual void display(TYRenderContext &renderContext)
Classe de definition d'un maillage lineaire.
@ ValGlobalDBLin
Definition: TYMaillage.h:299
LPTYPalette getPalette()
Get de la palette (_pPalette)
Definition: TYMaillage.h:265
Classe graphique pour representer une palette.
void setPosX(double x)
virtual void display(TYRenderContext &renderContext)
void setPosY(double y)
classe graphique pour un panel d'informations
virtual void display(TYRenderContext &renderContext)
static int getIndex()
static void addElement(TYElement *pElt)
Classe de definition d'un point de calcul.C'est une classe derivee a TYPoint avec en plus un spectrep...
Definition: TYPointCalcul.h:33
virtual LPTYSpectre getSpectre()
Get du spectre resultat d'un calcul donne.
const TYRenderType type
const TYRenderPass pass