Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYTerrainGraphic.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 
24 #include "TYTerrainGraphic.h"
26 
27 #define IMG(id) OLocalizator::getPicture("TYTerrainGraphic", (id))
28 
30 {
31  _pPolygon = new TYPolygon();
32 
34  _pPolyLineGraphic->setElement(pElement);
35 
36  _pTex = new OGLTexture2D();
37 }
38 
39 void TYTerrainGraphic::update(bool force /*=false*/)
40 {
42 }
43 
44 void TYTerrainGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursif /*=true*/)
45 {
46  TYElementGraphic* pTYElementGraphic = _pPolygon->getGraphicObject();
47  childs.push_back(pTYElementGraphic);
48  if (recursif)
49  {
50  pTYElementGraphic->getChilds(childs, recursif);
51  }
52 
53  pTYElementGraphic = _pPolyLineGraphic;
54  childs.push_back(pTYElementGraphic);
55  if (recursif)
56  {
57  pTYElementGraphic->getChilds(childs, recursif);
58  }
59 }
60 
62 {
64  boundingBox.Enlarge(_pPolygon->getGraphicObject()->boundingBox());
66  return boundingBox;
67 }
68 
70 {
71  if (!_visible)
72  {
73  return;
74  }
75 
76  TYElementGraphic::display(renderContext);
77 
78  TYTabPoint tabpoints = getElement()->getListPoints();
79 
80  // Ajout d'un offset pour eviter le flickering avec l'altimetrie
81  for (unsigned int i = 0; i < tabpoints.size(); i++)
82  {
83  tabpoints[i]._z += 0.05;
84  }
85 
86  _pPolygon->setPoints(tabpoints);
87 
88  // XXX There should be no reason to set flag modified to true in display method
89  // Try to delete the statement below
90  // See issue https://gitlab.com/tympan/code_tympan/-/issues/762
92  _pPolyLineGraphic->setTabPoint(tabpoints);
93 
94  if (renderContext.type == TYRenderType::Picking)
95  {
96  TYPickingTable::addElement(getElement());
97  glPushName((GLuint)(TYPickingTable::getIndex()));
98  }
99 
101  _pPolygon->getGraphicObject()->setBoundingBoxVisible(_highlight);
102 
103  glColor4fv(getElement()->getColor());
104  _pPolyLineGraphic->display(renderContext);
105 
106  glColor4fv(getElement()->getColor());
107  bindTexture();
108  _pPolygon->getGraphicObject()->display(renderContext);
109 
110  if (renderContext.type == TYRenderType::Picking)
111  {
112  glPopName();
113  }
114 }
115 
117 {
118  // Desactive le texturing.
119  _pPolygon->getGraphicObject()->setTexture(false);
120 
121  // Si le sol est de type vegetation...
122  if (getElement()->isUsingVegetation())
123  {
124  // On active le texturing.
125  _pPolygon->getGraphicObject()->setTexture();
126 
127  double r = getElement()->getSol()->getResistivite();
128 
129  // On charge la texture qui va bien.
130  if (r >= 5.0 && r < 20.0)
131  {
132  _pTex->load(IMG("id_terrain_0").toLatin1().data());
133  }
134  else if (r >= 20.0 && r < 50.0)
135  {
136  _pTex->load(IMG("id_terrain_1").toLatin1().data());
137  }
138  else if (r >= 50.0 && r < 100.0)
139  {
140  _pTex->load(IMG("id_terrain_2").toLatin1().data());
141  }
142  else if (r >= 100.0 && r < 200.0)
143  {
144  _pTex->load(IMG("id_terrain_3").toLatin1().data());
145  }
146  else if (r >= 200.0 && r < 500.0)
147  {
148  _pTex->load(IMG("id_terrain_4").toLatin1().data());
149  }
150  else if (r >= 500.0 && r < 1000.0)
151  {
152  _pTex->load(IMG("id_terrain_5").toLatin1().data());
153  }
154  else if (r >= 1000.0 && r < 5000.0)
155  {
156  _pTex->load(IMG("id_terrain_6").toLatin1().data());
157  }
158  else if (r >= 5000.0 && r < 10000.0)
159  {
160  _pTex->load(IMG("id_terrain_7").toLatin1().data());
161  }
162  else if (r >= 10000.0 && r < 20000.0)
163  {
164  _pTex->load(IMG("id_terrain_8").toLatin1().data());
165  }
166  else if (r >= 20000.0)
167  {
168  _pTex->load(IMG("id_terrain_9").toLatin1().data());
169  }
170 
171  // On met la couleur en blanc pour etre sur qu'il n'y a pas de melange de couleur.
172  glColor4fv(OColor::WHITE);
173 
174  // On applique la texture.
175  _pTex->bind();
176  }
177 }
QColor getColor
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
Definition: TYDefines.h:340
list< TYElementGraphic * > TYListPtrTYElementGraphic
List de pointeur de TYElement.
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.
#define IMG(id)
Representation graphique d'un terrain (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
static const OColor WHITE
Definition: color.h:93
bool load(const char *filename)
virtual void bind()
Definition: OGLTexture.cpp:32
classe graphique pour un element de base
bool _visible
Inique si l'element est visible.
void setModified(bool modified=true)
OBox boundingBox() const
void setBoundingBoxVisible(bool state=true)
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)
virtual void display(TYRenderContext &renderContext)
void setElement(TYElement *pElt)
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 display(TYRenderContext &renderContext)
void setPoints(const TYTabPoint &pts)
Definition: TYPolygon.cpp:389
const TYRenderType type
LPTYPolyLineGraphic _pPolyLineGraphic
LPOGLTexture2D _pTex
virtual void display(TYRenderContext &renderContext)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual void update(bool force=false)
TYTerrainGraphic(TYTerrain *pElement)
LPTYPolygon _pPolygon
virtual OBox computeBoundingBox() const