Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYBoundaryNoiseMapGraphic.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 
29 #include <QtOpenGL>
30 
31 #include <math.h>
32 
34  : TYElementGraphic(pElement)
35 {
37  _pPolyLineGraphic = new TYPolyLineGraphic(pElement->isClosed());
38  _pPolyLineGraphic->setTabPoint(getElement()->getTabPoint());
39  _pPolyLineGraphic->setElement(pElement);
40  // We don't want to render the polyline
42 
43  _paletteX = 0.8;
44  _paletteY = 0.25;
45 
46  _paletteW = 150.0;
47  _paletteH = 15.0;
48 
49  TYElementGraphic* pTYElementGraphic = getElement()->getPalette()->getGraphicObject();
50  ((TYPaletteGraphic*)pTYElementGraphic)->setWidth(_paletteW);
51  ((TYPaletteGraphic*)pTYElementGraphic)->setHeight(_paletteH);
52 
53  _panelW = 125.0;
54  _panelH = 40.0;
55 
56  pTYElementGraphic = getElement()->getPanel()->getGraphicObject();
57  ((TYPanelGraphic*)pTYElementGraphic)->setWidth(_panelW);
58  ((TYPanelGraphic*)pTYElementGraphic)->setHeight(_panelH);
59  pTYElementGraphic->setVisible(false);
60 }
61 
62 void TYBoundaryNoiseMapGraphic::update(bool force /*=false*/)
63 {
64  if (getModified() || force)
65  {
66  // Update the polyline
67  _pPolyLineGraphic = new TYPolyLineGraphic(getElement()->isClosed());
68  _pPolyLineGraphic->setElement(getElement());
69  _pPolyLineGraphic->setTabPoint(getElement()->getTabPoint());
70  // We hide the polyline
72 
73  TYBoundaryNoiseMap* boundaryNoiseMap = getElement();
74 
75  // And now... the mesh
76  boundaryNoiseMap->computeMesh(_mesh);
77 
78  // And ... the isocurve
79  boundaryNoiseMap->computeIsoCurve(_mesh, _isoCurve);
80 
81  boundaryNoiseMap->getPalette()->getGraphicObject()->update(force);
83  }
84 }
85 
86 void TYBoundaryNoiseMapGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursive /*=true*/)
87 {
88  TYElementGraphic* pTYElementGraphic = _pPolyLineGraphic;
89  childs.push_back(pTYElementGraphic);
90  if (recursive)
91  {
92  pTYElementGraphic->getChilds(childs, recursive);
93  }
94 }
95 
97 {
99  double offset = getElement()->getThickness() * 0.5;
100  OPoint3D& bb_min = boundingBox._min;
101  OPoint3D& bb_max = boundingBox._max;
102  bb_min._x -= offset;
103  bb_min._y -= offset;
104  bb_max._x += offset;
105  bb_max._y += offset;
106  return boundingBox;
107 }
108 
109 void TYBoundaryNoiseMapGraphic::displayMixed(float opacity, bool antialiasing)
110 {
111  displaySurface(opacity, antialiasing);
112  displayLines(opacity, true);
113 }
114 
116 {
117  if (_mesh.empty())
118  {
119  update();
120  }
121 
122  if (!_visible || getElement()->etat() == false)
123  {
124  return;
125  }
126 
127  if (renderContext.type == TYRenderType::Picking)
128  {
129  TYPickingTable::addElement(getElement());
130  glPushName((GLuint)(TYPickingTable::getIndex()));
131  }
132 
133  // Anticr�nelage par d�faut
134  bool antialiasing = true;
135 
136  // Default opacity
137  float opacity = 1.f;
138 #if TY_USE_IHM
139  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MaillageOpacity"))
140  {
141  opacity = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "MaillageOpacity");
142  }
143  else
144  {
145  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "MaillageOpacity", opacity);
146  }
147 
148  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "Antialiasing"))
149  {
150  antialiasing = TYPreferenceManager::getBool(TYDIRPREFERENCEMANAGER, "Antialiasing");
151  }
152  else
153  {
154  TYPreferenceManager::setBool(TYDIRPREFERENCEMANAGER, "Antialiasing", antialiasing);
155  }
156 #endif // TY_USE_IHM
157 
158  switch (_Rendering)
159  {
160  case RENDER_SURF:
161  displaySurface(opacity, antialiasing);
162  break;
163  case RENDER_LINES:
164  displayLines(opacity);
165  break;
166  case RENDER_MIXED:
167  displayMixed(opacity, antialiasing);
168  break;
169  default:
170  displaySurface(opacity, antialiasing);
171  break;
172  }
173 
174  glColor3f(1.f, 0.f, 0.f);
175  if (renderContext.type == TYRenderType::Picking)
176  {
177  glPopName();
178  }
179  if (_highlight)
180  {
181  displayOnHighlight(renderContext);
182  }
183  // Panel display
184  TYElementGraphic* pTYElementGraphic = getElement()->getPanel()->getGraphicObject();
185  TYPanelGraphic* pTYPanelGraphic = (TYPanelGraphic*)pTYElementGraphic;
186  pTYPanelGraphic->display(renderContext);
187 }
188 
189 void TYBoundaryNoiseMapGraphic::displaySurface(float opacity, bool antialising) // GLenum mode = GL_RENDER
190 {
191  LPTYPalette pPalette = getElement()->getPalette();
192  size_t nbTriangles = _mesh.size();
193  OColor color0;
194 
195  if (antialising)
196  {
197  glBegin(GL_TRIANGLES);
198  for (size_t i = 0; i < nbTriangles; i++)
199  {
200  const MTriangle& vtx = _mesh[i];
201  const MPoint& v1 = vtx.pts[0];
202  const MPoint& v2 = vtx.pts[1];
203  const MPoint& v3 = vtx.pts[2];
204 
205  color0 = pPalette->getColorFromValue(v1.scalar);
206  glColor4f(color0.r, color0.g, color0.b, opacity);
207  glVertex3f(v1.pt._x, v1.pt._y, v1.pt._z);
208 
209  const OColor& color1 = pPalette->getColorFromValue(v2.scalar);
210  glColor4f(color1.r, color1.g, color1.b, opacity);
211  glVertex3f(v2.pt._x, v2.pt._y, v2.pt._z);
212 
213  const OColor& color2 = pPalette->getColorFromValue(v3.scalar);
214  glColor4f(color2.r, color2.g, color2.b, opacity);
215  glVertex3f(v3.pt._x, v3.pt._y, v3.pt._z);
216  }
217  glEnd();
218  }
219  else
220  {
221  glBegin(GL_QUADS);
222  for (size_t i = 0; i < nbTriangles; i = i + 2)
223  {
224  const MTriangle& vtx1 = _mesh[i];
225  const MTriangle& vtx2 = _mesh[i + 1];
226  const MPoint& v1 = vtx1.pts[0];
227  const MPoint& v2 = vtx1.pts[1];
228  const MPoint& v3 = vtx2.pts[2];
229  const MPoint& v4 = vtx1.pts[2];
230 
231  color0 = pPalette->getColorFromValue((v1.scalar + v2.scalar + v3.scalar + v4.scalar) * 0.25f);
232 
233  glColor4f(color0.r, color0.g, color0.b, opacity);
234  glVertex3f(v1.pt._x, v1.pt._y, v1.pt._z);
235 
236  glColor4f(color0.r, color0.g, color0.b, opacity);
237  glVertex3f(v2.pt._x, v2.pt._y, v2.pt._z);
238 
239  glColor4f(color0.r, color0.g, color0.b, opacity);
240  glVertex3f(v3.pt._x, v3.pt._y, v3.pt._z);
241 
242  glColor4f(color0.r, color0.g, color0.b, opacity);
243  glVertex3f(v4.pt._x, v4.pt._y, v4.pt._z);
244  }
245  glEnd();
246  }
247 }
248 
249 void TYBoundaryNoiseMapGraphic::displayLines(float opacity, bool invertColors)
250 {
251  float lw = NAN;
252  glGetFloatv(GL_LINE_WIDTH, &lw);
253  glLineWidth(3.0f);
254 
255  LPTYPalette pPalette = getElement()->getPalette();
256  size_t nbIsoCurve = _isoCurve.size();
257 
258  glBegin(GL_LINES);
259  for (size_t i = 0; i < nbIsoCurve; ++i)
260  {
261  const MPoint& mp = _isoCurve[i];
262  const OColor& color = pPalette->getColorFromValue(mp.scalar);
263  if (invertColors)
264  {
265  glColor4f(1.0f - color.r, 1.0f - color.g, 1.0f - color.b, opacity);
266  }
267  else
268  {
269  glColor4f(color.r, color.g, color.b, opacity);
270  }
271  glVertex3f(mp.pt._x, mp.pt._y,
272  mp.pt._z + 0.01); // 0.01 offset so that we can display the lines from top view
273  }
274  glEnd();
275 
276  glLineWidth(lw);
277 }
278 
280 {
281  // Display the graphical palette
282  TYElementGraphic* pTYElementGraphic = getElement()->getPalette()->getGraphicObject();
283  TYPaletteGraphic* pTYPaletteGraphic = (TYPaletteGraphic*)pTYElementGraphic;
284 
285  GLint viewport[4];
286  glGetIntegerv(GL_VIEWPORT, viewport);
287  unsigned int width = viewport[2];
288  unsigned int height = viewport[3];
289  pTYPaletteGraphic->setPosX(width * _paletteX);
290  pTYPaletteGraphic->setPosY(height * _paletteY);
291  pTYPaletteGraphic->display(renderContext);
292 }
Graphical representation of the BoundaryNoiseMap entity (header file)
list< TYElementGraphic * > TYListPtrTYElementGraphic
List de pointeur de TYElement.
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
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.
The box class.
Definition: 3d.h:1346
OPoint3D _min
Minimal coordinates of the OBox.
Definition: 3d.h:1423
OPoint3D _max
Maximal coordinates of the OBox.
Definition: 3d.h:1424
Definition: color.h:36
float b
Definition: color.h:38
float r
Definition: color.h:38
float g
Definition: color.h:38
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 point class.
Definition: 3d.h:487
void displayOnHighlight(TYRenderContext &renderContext)
What we have to display when the entity is highlighted.
enum TYBoundaryNoiseMapGraphic::RenderingMode _Rendering
virtual void displaySurface(float opacity=1.f, bool antialiasing=true)
Display the surface of the mesh.
double _paletteX
The position of the palette in x.
double _paletteY
The position of the palette in y.
virtual void displayMixed(float opacity=1.f, bool antialiasing=true)
Display both the surface and the isocurve.
double _paletteW
The width of the palette.
virtual void displayLines(float opacity=1.f, bool invertColors=false)
Display the isocurve.
LPTYPolyLineGraphic _pPolyLineGraphic
The polyline rendering.
double _paletteH
The height of the palette.
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursive=true)
Set the children.
virtual void update(bool force=false)
Update the mesh and the isocurve.
virtual OBox computeBoundingBox() const
Compute the bounding box of the object.
TYBoundaryNoiseMapGraphic(TYBoundaryNoiseMap *pElement)
Constructor.
std::vector< MTriangle > _mesh
The mesh.
double _panelH
The height of the panel.
double _panelW
The width of the panel.
std::vector< MPoint > _isoCurve
The iso curve.
virtual void display(TYRenderContext &renderContext)
Display the object.
This class represents a polyline with a thickness. Acoustic receptors are sampled inside this region.
bool isClosed() const
Is polyline closed?
classe graphique pour un element de base
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)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
void setElement(TYElement *pElt)
bool getModified() const
void setVisible(bool visible=true)
void computeMesh(std::vector< MTriangle > &mesh) const
Compute the mesh.
Definition: TYMaillage.cpp:457
void computeIsoCurve(std::vector< MTriangle > &mesh, std::vector< MPoint > &isoCurve) const
Compute the isocurve.
Definition: TYMaillage.cpp:533
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)
const OColor & getColorFromValue(values_type value) const
Set de la lookup table.
Definition: TYPalette.cpp:491
classe graphique pour un panel d'informations
virtual void display(TYRenderContext &renderContext)
static int getIndex()
static void addElement(TYElement *pElt)
classe graphique pour representer une polyligne a partir d'un tableau de points.
void setTabPoint(const TYTabPoint &tabPts)
TYRenderType type
TYPalette::values_type scalar
Definition: TYMaillage.h:33
OVector3D pt
Definition: TYMaillage.h:32
MPoint pts[3]
Definition: TYMaillage.h:38