Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYTerrainGraphic.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 
24 #include "TYTerrainGraphic.h"
25 
26 #define IMG(id) OLocalizator::getPicture("TYTerrainGraphic", (id))
27 
29 {
30  _pPolygon = new TYPolygon();
31 
33  _pPolyLineGraphic->setElement(pElement);
34 
35  _pTex = new OGLTexture2D();
36 }
37 
38 void TYTerrainGraphic::update(bool force /*=false*/)
39 {
41 }
42 
43 void TYTerrainGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursif /*=true*/)
44 {
45  TYElementGraphic* pTYElementGraphic = _pPolygon->getGraphicObject();
46  childs.push_back(pTYElementGraphic);
47  if (recursif)
48  {
49  pTYElementGraphic->getChilds(childs, recursif);
50  }
51 
52  pTYElementGraphic = _pPolyLineGraphic;
53  childs.push_back(pTYElementGraphic);
54  if (recursif)
55  {
56  pTYElementGraphic->getChilds(childs, recursif);
57  }
58 }
59 
61 {
62  OBox reset;
63  _boundingBox = reset;
64  _pPolygon->getGraphicObject()->computeBoundingBox();
66  _boundingBox.Enlarge(_pPolygon->getGraphicObject()->GetBox());
68 }
69 
70 void TYTerrainGraphic::display(TYElement* pModelerElement /*= nullptr*/, GLenum mode /*= GL_RENDER*/)
71 {
72  if (!_visible)
73  {
74  return;
75  }
76 
77  TYElementGraphic::display(pModelerElement, mode);
78 
79  TYTabPoint tabpoints = getElement()->getListPoints();
80 
81  // Ajout d'un offset pour eviter le flickering avec l'altimetrie
82  for (unsigned int i = 0; i < tabpoints.size(); i++)
83  {
84  tabpoints[i]._z += 0.05;
85  }
86 
87  _pPolygon->setPoints(tabpoints);
88 
90  _pPolyLineGraphic->setTabPoint(tabpoints);
91 
92  if (mode == GL_SELECT)
93  {
94  TYPickingTable::addElement(getElement());
95  glPushName((GLuint)(TYPickingTable::getIndex()));
96  }
97 
99  _pPolygon->getGraphicObject()->highlight(_highlight);
100 
101  glColor4fv(getElement()->getColor());
102  _pPolyLineGraphic->display(pModelerElement, mode);
103 
104  glColor4fv(getElement()->getColor());
105  bindTexture();
106  _pPolygon->getGraphicObject()->display(pModelerElement, mode);
107 
108  if (mode == GL_SELECT)
109  {
110  glPopName();
111  }
112 }
113 
115 {
116  // Desactive le texturing.
117  _pPolygon->getGraphicObject()->setTexture(false);
118 
119  // Si le sol est de type vegetation...
120  if (getElement()->isUsingVegetation())
121  {
122  // On active le texturing.
123  _pPolygon->getGraphicObject()->setTexture();
124 
125  double r = getElement()->getSol()->getResistivite();
126 
127  // On charge la texture qui va bien.
128  if (r >= 5.0 && r < 20.0)
129  {
130  _pTex->load(IMG("id_terrain_0").toLatin1().data());
131  }
132  else if (r >= 20.0 && r < 50.0)
133  {
134  _pTex->load(IMG("id_terrain_1").toLatin1().data());
135  }
136  else if (r >= 50.0 && r < 100.0)
137  {
138  _pTex->load(IMG("id_terrain_2").toLatin1().data());
139  }
140  else if (r >= 100.0 && r < 200.0)
141  {
142  _pTex->load(IMG("id_terrain_3").toLatin1().data());
143  }
144  else if (r >= 200.0 && r < 500.0)
145  {
146  _pTex->load(IMG("id_terrain_4").toLatin1().data());
147  }
148  else if (r >= 500.0 && r < 1000.0)
149  {
150  _pTex->load(IMG("id_terrain_5").toLatin1().data());
151  }
152  else if (r >= 1000.0 && r < 5000.0)
153  {
154  _pTex->load(IMG("id_terrain_6").toLatin1().data());
155  }
156  else if (r >= 5000.0 && r < 10000.0)
157  {
158  _pTex->load(IMG("id_terrain_7").toLatin1().data());
159  }
160  else if (r >= 10000.0 && r < 20000.0)
161  {
162  _pTex->load(IMG("id_terrain_8").toLatin1().data());
163  }
164  else if (r >= 20000.0)
165  {
166  _pTex->load(IMG("id_terrain_9").toLatin1().data());
167  }
168 
169  // On met la couleur en blanc pour etre sur qu'il n'y a pas de melange de couleur.
170  glColor4fv(OColor::WHITE);
171 
172  // On applique la texture.
173  _pTex->bind();
174  }
175 }
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)
#define IMG(id)
Representation graphique d'un terrain (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
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)
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)
virtual void display(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
void highlight(bool state=true)
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()
virtual void display(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
void setPoints(const TYTabPoint &pts)
Definition: TYPolygon.cpp:389
LPTYPolyLineGraphic _pPolyLineGraphic
virtual void display(TYElement *pModelerElement=nullptr, GLenum mode=GL_RENDER)
LPOGLTexture2D _pTex
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual void update(bool force=false)
TYTerrainGraphic(TYTerrain *pElement)
LPTYPolygon _pPolygon
virtual void computeBoundingBox()