Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYBoundaryNoiseMapGraphic.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 
29 
30 #include <math.h>
31 
33  : TYElementGraphic(pElement)
34 {
36  _pPolyLineGraphic = new TYPolyLineGraphic(pElement->isClosed());
37  _pPolyLineGraphic->setTabPoint(getElement()->getTabPoint());
38  _pPolyLineGraphic->setElement(pElement);
39  // We don't want to render the polyline
41 
42  _paletteX = 0.8;
43  _paletteY = 0.25;
44 
45  _paletteW = 150.0;
46  _paletteH = 15.0;
47 
48  TYElementGraphic* pTYElementGraphic = getElement()->getPalette()->getGraphicObject();
49  ((TYPaletteGraphic*)pTYElementGraphic)->setWidth(_paletteW);
50  ((TYPaletteGraphic*)pTYElementGraphic)->setHeight(_paletteH);
51 
52  _panelW = 125.0;
53  _panelH = 40.0;
54 
55  pTYElementGraphic = getElement()->getPanel()->getGraphicObject();
56  ((TYPanelGraphic*)pTYElementGraphic)->setWidth(_panelW);
57  ((TYPanelGraphic*)pTYElementGraphic)->setHeight(_panelH);
58  pTYElementGraphic->setVisible(false);
59 }
60 
61 void TYBoundaryNoiseMapGraphic::update(bool force /*=false*/)
62 {
63  // Update the polyline
64  _pPolyLineGraphic = new TYPolyLineGraphic(getElement()->isClosed());
65  _pPolyLineGraphic->setElement(getElement());
66  _pPolyLineGraphic->setTabPoint(getElement()->getTabPoint());
67  // We hide the polyline
69 
70  TYBoundaryNoiseMap* boundaryNoiseMap = getElement();
71 
72  // And now... the mesh
73  boundaryNoiseMap->computeMesh(_mesh);
74 
75  // And ... the isocurve
76  boundaryNoiseMap->computeIsoCurve(_mesh, _isoCurve);
77 
78  boundaryNoiseMap->getPalette()->getGraphicObject()->update(force);
80 }
81 
82 void TYBoundaryNoiseMapGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursive /*=true*/)
83 {
84  TYElementGraphic* pTYElementGraphic = _pPolyLineGraphic;
85  childs.push_back(pTYElementGraphic);
86  if (recursive)
87  {
88  pTYElementGraphic->getChilds(childs, recursive);
89  }
90 }
91 
93 {
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 }
104 
106 {
107  displaySurface(opacity);
108  displayLines(opacity, true);
109 }
110 
111 void TYBoundaryNoiseMapGraphic::display(TYElement* pModelerElement /*= nullptr*/, GLenum mode /*= GL_RENDER*/)
112 {
113  if (_mesh.empty())
114  {
115  update();
116  }
117 
118  if (!_visible || getElement()->etat() == false)
119  {
120  return;
121  }
122 
123  if (mode == GL_SELECT)
124  {
125  TYPickingTable::addElement(getElement());
126  glPushName((GLuint)(TYPickingTable::getIndex()));
127  }
128 
129  // Default opacity
130  float opacity = 1.f;
131 #if TY_USE_IHM
132  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "MaillageOpacity"))
133  {
134  opacity = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "MaillageOpacity");
135  }
136  else
137  {
138  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "MaillageOpacity", opacity);
139  }
140 #endif // TY_USE_IHM
141 
142  switch (_Rendering)
143  {
144  case RENDER_SURF:
145  displaySurface(opacity);
146  break;
147  case RENDER_LINES:
148  displayLines(opacity);
149  break;
150  case RENDER_MIXED:
151  displayMixed(opacity);
152  break;
153  default:
154  displaySurface(opacity);
155  break;
156  }
157 
158  glColor3f(1.f, 0.f, 0.f);
159  if (mode == GL_SELECT)
160  {
161  glPopName();
162  }
163  if (_highlight)
164  {
165  if (_bFirstDisp)
166  {
168  _bFirstDisp = false;
169  }
171  displayOnHighlight(mode);
172  }
173  // Panel display
174  TYElementGraphic* pTYElementGraphic = getElement()->getPanel()->getGraphicObject();
175  TYPanelGraphic* pTYPanelGraphic = (TYPanelGraphic*)pTYElementGraphic;
176  pTYPanelGraphic->display();
177 
178  // Bounding box computation
180 }
181 
182 void TYBoundaryNoiseMapGraphic::displaySurface(float opacity) // GLenum mode = GL_RENDER
183 {
184  LPTYPalette pPalette = getElement()->getPalette();
185  size_t nbTriangles = _mesh.size();
186  glBegin(GL_TRIANGLES);
187  for (size_t i = 0; i < nbTriangles; i++)
188  {
189  const MTriangle& vtx = _mesh[i];
190  const MPoint& v1 = vtx.pts[0];
191  const MPoint& v2 = vtx.pts[1];
192  const MPoint& v3 = vtx.pts[2];
193 
194  const OColor& color0 = pPalette->getColorFromValue(v1.scalar);
195  glColor4f(color0.r, color0.g, color0.b, opacity);
196  glVertex3f(v1.pt._x, v1.pt._y, v1.pt._z);
197 
198  const OColor& color1 = pPalette->getColorFromValue(v2.scalar);
199  glColor4f(color1.r, color1.g, color1.b, opacity);
200  glVertex3f(v2.pt._x, v2.pt._y, v2.pt._z);
201 
202  const OColor& color2 = pPalette->getColorFromValue(v3.scalar);
203  glColor4f(color2.r, color2.g, color2.b, opacity);
204  glVertex3f(v3.pt._x, v3.pt._y, v3.pt._z);
205  }
206  glEnd();
207 }
208 
209 void TYBoundaryNoiseMapGraphic::displayLines(float opacity, bool invertColors)
210 {
211  float lw = NAN;
212  glGetFloatv(GL_LINE_WIDTH, &lw);
213  glLineWidth(3.0f);
214 
215  LPTYPalette pPalette = getElement()->getPalette();
216  size_t nbIsoCurve = _isoCurve.size();
217 
218  glBegin(GL_LINES);
219  for (size_t i = 0; i < nbIsoCurve; ++i)
220  {
221  const MPoint& mp = _isoCurve[i];
222  const OColor& color = pPalette->getColorFromValue(mp.scalar);
223  if (invertColors)
224  {
225  glColor4f(1.0f - color.r, 1.0f - color.g, 1.0f - color.b, opacity);
226  }
227  else
228  {
229  glColor4f(color.r, color.g, color.b, opacity);
230  }
231  glVertex3f(mp.pt._x, mp.pt._y,
232  mp.pt._z + 0.01); // 0.01 offset so that we can display the lines from top view
233  }
234  glEnd();
235 
236  glLineWidth(lw);
237 }
238 
240 {
241  // Display the graphical palette
242  TYElementGraphic* pTYElementGraphic = getElement()->getPalette()->getGraphicObject();
243  TYPaletteGraphic* pTYPaletteGraphic = (TYPaletteGraphic*)pTYElementGraphic;
244  pTYPaletteGraphic->setPosX(OSizeManager::get()->getWidth() * _paletteX);
245  pTYPaletteGraphic->setPosY(OSizeManager::get()->getHeight() * _paletteY);
246  pTYPaletteGraphic->display();
247 }
Graphical representation of the BoundaryNoiseMap entity (header file)
list< TYElementGraphic * > TYListPtrTYElementGraphic
List de pointeur de TYElement.
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:52
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)
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
OPoint3D _min
Minimal coordinates of the OBox.
Definition: 3d.h:1371
OPoint3D _max
Maximal coordinates of the OBox.
Definition: 3d.h:1372
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
static LPOSizeManager get()
enum TYBoundaryNoiseMapGraphic::RenderingMode _Rendering
double _paletteX
The position of the palette in x.
virtual void displaySurface(float opacity=1.f)
Display the surface of the mesh.
double _paletteY
The position of the palette in y.
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 void displayMixed(float opacity=1.f)
Display both the surface and the isocurve.
TYBoundaryNoiseMapGraphic(TYBoundaryNoiseMap *pElement)
Constructor.
virtual void display(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
Display the object.
std::vector< MTriangle > _mesh
The mesh.
double _panelH
The height of the panel.
double _panelW
The width of the panel.
void displayOnHighlight(int mode)
What we have to display when the entity is highlighted.
std::vector< MPoint > _isoCurve
The iso curve.
virtual void computeBoundingBox()
Compute the bounding box of 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
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)
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:564
LPTYPalette getPalette()
Get de la palette (_pPalette)
Definition: TYMaillage.h:265
Classe graphique pour representer une palette.
void setPosX(double x)
void setPosY(double y)
virtual void display(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
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(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
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)
virtual void computeBoundingBox()
TYPalette::values_type scalar
Definition: TYMaillage.h:33
OVector3D pt
Definition: TYMaillage.h:32
MPoint pts[3]
Definition: TYMaillage.h:38