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  // Update the polyline
65  _pPolyLineGraphic = new TYPolyLineGraphic(getElement()->isClosed());
66  _pPolyLineGraphic->setElement(getElement());
67  _pPolyLineGraphic->setTabPoint(getElement()->getTabPoint());
68  // We hide the polyline
70 
71  TYBoundaryNoiseMap* boundaryNoiseMap = getElement();
72 
73  // And now... the mesh
74  boundaryNoiseMap->computeMesh(_mesh);
75 
76  // And ... the isocurve
77  boundaryNoiseMap->computeIsoCurve(_mesh, _isoCurve);
78 
79  boundaryNoiseMap->getPalette()->getGraphicObject()->update(force);
81 }
82 
83 void TYBoundaryNoiseMapGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursive /*=true*/)
84 {
85  TYElementGraphic* pTYElementGraphic = _pPolyLineGraphic;
86  childs.push_back(pTYElementGraphic);
87  if (recursive)
88  {
89  pTYElementGraphic->getChilds(childs, recursive);
90  }
91 }
92 
94 {
96  double offset = getElement()->getThickness() * 0.5;
97  OPoint3D& bb_min = boundingBox._min;
98  OPoint3D& bb_max = boundingBox._max;
99  bb_min._x -= offset;
100  bb_min._y -= offset;
101  bb_max._x += offset;
102  bb_max._y += offset;
103  return boundingBox;
104 }
105 
106 void TYBoundaryNoiseMapGraphic::displayMixed(float opacity, bool antialiasing)
107 {
108  displaySurface(opacity, antialiasing);
109  displayLines(opacity, true);
110 }
111 
113 {
114  if (_mesh.empty())
115  {
116  update();
117  }
118 
119  if (!_visible || getElement()->etat() == false)
120  {
121  return;
122  }
123 
124  if (renderContext.type == TYRenderType::Picking)
125  {
126  TYPickingTable::addElement(getElement());
127  glPushName((GLuint)(TYPickingTable::getIndex()));
128  }
129 
130  // Anticr�nelage par d�faut
131  bool antialiasing = true;
132 
133  // Default opacity
134  float opacity = 1.f;
135 #if TY_USE_IHM
136  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MaillageOpacity"))
137  {
138  opacity = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "MaillageOpacity");
139  }
140  else
141  {
142  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "MaillageOpacity", opacity);
143  }
144 
145  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "Antialiasing"))
146  {
147  antialiasing = TYPreferenceManager::getBool(TYDIRPREFERENCEMANAGER, "Antialiasing");
148  }
149  else
150  {
151  TYPreferenceManager::setBool(TYDIRPREFERENCEMANAGER, "Antialiasing", antialiasing);
152  }
153 #endif // TY_USE_IHM
154 
155  switch (_Rendering)
156  {
157  case RENDER_SURF:
158  displaySurface(opacity, antialiasing);
159  break;
160  case RENDER_LINES:
161  displayLines(opacity);
162  break;
163  case RENDER_MIXED:
164  displayMixed(opacity, antialiasing);
165  break;
166  default:
167  displaySurface(opacity, antialiasing);
168  break;
169  }
170 
171  glColor3f(1.f, 0.f, 0.f);
172  if (renderContext.type == TYRenderType::Picking)
173  {
174  glPopName();
175  }
176  if (_highlight)
177  {
178  displayOnHighlight(renderContext);
179  }
180  // Panel display
181  TYElementGraphic* pTYElementGraphic = getElement()->getPanel()->getGraphicObject();
182  TYPanelGraphic* pTYPanelGraphic = (TYPanelGraphic*)pTYElementGraphic;
183  pTYPanelGraphic->display(renderContext);
184 }
185 
186 void TYBoundaryNoiseMapGraphic::displaySurface(float opacity, bool antialising) // GLenum mode = GL_RENDER
187 {
188  LPTYPalette pPalette = getElement()->getPalette();
189  size_t nbTriangles = _mesh.size();
190  OColor color0;
191 
192  if (antialising)
193  {
194  glBegin(GL_TRIANGLES);
195  for (size_t i = 0; i < nbTriangles; i++)
196  {
197  const MTriangle& vtx = _mesh[i];
198  const MPoint& v1 = vtx.pts[0];
199  const MPoint& v2 = vtx.pts[1];
200  const MPoint& v3 = vtx.pts[2];
201 
202  color0 = pPalette->getColorFromValue(v1.scalar);
203  glColor4f(color0.r, color0.g, color0.b, opacity);
204  glVertex3f(v1.pt._x, v1.pt._y, v1.pt._z);
205 
206  const OColor& color1 = pPalette->getColorFromValue(v2.scalar);
207  glColor4f(color1.r, color1.g, color1.b, opacity);
208  glVertex3f(v2.pt._x, v2.pt._y, v2.pt._z);
209 
210  const OColor& color2 = pPalette->getColorFromValue(v3.scalar);
211  glColor4f(color2.r, color2.g, color2.b, opacity);
212  glVertex3f(v3.pt._x, v3.pt._y, v3.pt._z);
213  }
214  glEnd();
215  }
216  else
217  {
218  glBegin(GL_QUADS);
219  for (size_t i = 0; i < nbTriangles; i = i + 2)
220  {
221  const MTriangle& vtx1 = _mesh[i];
222  const MTriangle& vtx2 = _mesh[i + 1];
223  const MPoint& v1 = vtx1.pts[0];
224  const MPoint& v2 = vtx1.pts[1];
225  const MPoint& v3 = vtx2.pts[2];
226  const MPoint& v4 = vtx1.pts[2];
227 
228  color0 = pPalette->getColorFromValue((v1.scalar + v2.scalar + v3.scalar + v4.scalar) * 0.25f);
229 
230  glColor4f(color0.r, color0.g, color0.b, opacity);
231  glVertex3f(v1.pt._x, v1.pt._y, v1.pt._z);
232 
233  glColor4f(color0.r, color0.g, color0.b, opacity);
234  glVertex3f(v2.pt._x, v2.pt._y, v2.pt._z);
235 
236  glColor4f(color0.r, color0.g, color0.b, opacity);
237  glVertex3f(v3.pt._x, v3.pt._y, v3.pt._z);
238 
239  glColor4f(color0.r, color0.g, color0.b, opacity);
240  glVertex3f(v4.pt._x, v4.pt._y, v4.pt._z);
241  }
242  glEnd();
243  }
244 }
245 
246 void TYBoundaryNoiseMapGraphic::displayLines(float opacity, bool invertColors)
247 {
248  float lw = NAN;
249  glGetFloatv(GL_LINE_WIDTH, &lw);
250  glLineWidth(3.0f);
251 
252  LPTYPalette pPalette = getElement()->getPalette();
253  size_t nbIsoCurve = _isoCurve.size();
254 
255  glBegin(GL_LINES);
256  for (size_t i = 0; i < nbIsoCurve; ++i)
257  {
258  const MPoint& mp = _isoCurve[i];
259  const OColor& color = pPalette->getColorFromValue(mp.scalar);
260  if (invertColors)
261  {
262  glColor4f(1.0f - color.r, 1.0f - color.g, 1.0f - color.b, opacity);
263  }
264  else
265  {
266  glColor4f(color.r, color.g, color.b, opacity);
267  }
268  glVertex3f(mp.pt._x, mp.pt._y,
269  mp.pt._z + 0.01); // 0.01 offset so that we can display the lines from top view
270  }
271  glEnd();
272 
273  glLineWidth(lw);
274 }
275 
277 {
278  // Display the graphical palette
279  TYElementGraphic* pTYElementGraphic = getElement()->getPalette()->getGraphicObject();
280  TYPaletteGraphic* pTYPaletteGraphic = (TYPaletteGraphic*)pTYElementGraphic;
281 
282  GLint viewport[4];
283  glGetIntegerv(GL_VIEWPORT, viewport);
284  unsigned int width = viewport[2];
285  unsigned int height = viewport[3];
286  pTYPaletteGraphic->setPosX(width * _paletteX);
287  pTYPaletteGraphic->setPosY(height * _paletteY);
288  pTYPaletteGraphic->display(renderContext);
289 }
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: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
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)
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)
const TYRenderType type
TYPalette::values_type scalar
Definition: TYMaillage.h:33
OVector3D pt
Definition: TYMaillage.h:32
MPoint pts[3]
Definition: TYMaillage.h:38