Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYTopographieGraphic.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 
25 #include "TYTopographieGraphic.h"
28 #include "gui/tools/OGLArrayMesh.h"
32 #include <memory>
33 #include <qcolor.h>
34 #include <qmatrix4x4.h>
35 #include <qvector3d.h>
36 
38  : TYElementGraphic(pElement),
39  _empriseMesh(std::make_shared<OGLPolyLineMesh>(OGLPolyLineMesh::EndType::Closed))
40 {
41  OGLSimpleMaterial empriseMaterial;
42  // Get emprise color
43  float r = 0.0f, g = 0.0f, b = 0.0f;
44 #if TY_USE_IHM // L'emprise est de la couleur par defaut des polylines
45  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "TYPolylineGraphicColorRR"))
46  {
47  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "TYPolylineGraphicColorR", r, g, b);
48  }
49 #endif
50  empriseMaterial.color = QColor(r, g, b);
51 
52  _empriseMesh->setMaterial(empriseMaterial);
53 
55 }
56 
57 void TYTopographieGraphic::update(bool force /*=false*/)
58 {
59  // Cet element est toujours actif quelque soit le calcul courant
60  if (getModified() || force)
61  {
62  getElement()->setInCurrentCalcul(true);
63 
65  }
67 }
68 
69 void TYTopographieGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursif /*=true*/)
70 {
71  TYListPtrTYElementGraphic Localchilds;
72 
73  unsigned int i = 0;
74 
75  // 1 altimetry for all the site hierarchy. From the topography, retrieve the parent
76  // site, and from this site, the root site and its altimetry.
77  TYTopographie* pTYTopographie = getElement();
78  LPTYSiteNode pParentSite = dynamic_cast<TYSiteNode*>(pTYTopographie->getParent());
79  assert(pParentSite != nullptr && "The parent of a TYTopographie element must be a TYSiteNode");
80  if (pParentSite->getRoot())
81  {
82  LPTYAltimetrie altimetrie = pParentSite->getAltimetry();
83  Localchilds.push_back(altimetrie->getGraphicObject().getRealPointer());
84  }
85 
86  // Courbes de niveau
87  TYTabCourbeNiveauGeoNode* pTabCrbNiv = &getElement()->getListCrbNiv();
88  for (i = 0; i < pTabCrbNiv->size(); i++)
89  {
90  TYCourbeNiveauGeoNode* pCrbNivGeoNode = pTabCrbNiv->operator[](i);
91  Localchilds.push_back(pCrbNivGeoNode->getGraphicObject().getRealPointer());
92  }
93 
94  // Plans d'eau
95  TYTabPlanEauGeoNode* pTabPlanEau = &getElement()->getListPlanEau();
96  for (i = 0; i < pTabPlanEau->size(); i++)
97  {
98  TYPlanEauGeoNode* pPlanEauGeoNode = pTabPlanEau->operator[](i);
99  Localchilds.push_back(pPlanEauGeoNode->getGraphicObject().getRealPointer());
100  }
101 
102  // Terrains
103  TYTabTerrainGeoNode* pTabTerrain = &getElement()->getListTerrain();
104  for (i = 0; i < pTabTerrain->size(); i++)
105  {
106  TYTerrainGeoNode* pTerrainGeoNode = pTabTerrain->operator[](i);
107  Localchilds.push_back(pTerrainGeoNode->getGraphicObject().getRealPointer());
108  }
109 
110  // Cours d'Eau
111  TYTabCoursEauGeoNode* pTabCrsEau = &getElement()->getListCrsEau();
112  for (i = 0; i < pTabCrsEau->size(); i++)
113  {
114  TYCoursEauGeoNode* pCrsEauGeoNode = pTabCrsEau->operator[](i);
115  Localchilds.push_back(pCrsEauGeoNode->getGraphicObject().getRealPointer());
116  }
117 
118  TYListPtrTYElementGraphic::iterator ite = Localchilds.begin();
119  for (i = 0; i < Localchilds.size(); i++)
120  {
121  TYElementGraphic* pTYElementGraphic = (TYElementGraphic*)(*ite);
122  childs.push_back(pTYElementGraphic);
123  if (recursif)
124  {
125  pTYElementGraphic->getChilds(childs, recursif);
126  }
127  ite++;
128  }
129 }
130 
132 {
133  unsigned int i = 0;
134 
135  TYTopographie* pTYTopographie = getElement();
136  LPTYSiteNode pParentSite = dynamic_cast<TYSiteNode*>(pTYTopographie->getParent());
137  if (pParentSite->getRoot())
138  {
139  assert(pParentSite != nullptr && "The parent of a TYTopographie element must be a TYSiteNode");
140  LPTYAltimetrie altimetrie = pParentSite->getAltimetry();
141  LPTYElementGraphic ElementGraphic = altimetrie->getGraphicObject();
142  ElementGraphic->display(renderContext);
143  }
144 
145  // Plans d'eau
146  TYTabPlanEauGeoNode* pTabPlanEau = &getElement()->getListPlanEau();
147  TYPlanEauGeoNode* pPlanEauGeoNode = NULL;
148  for (i = 0; i < pTabPlanEau->size(); i++)
149  {
150  pPlanEauGeoNode = pTabPlanEau->operator[](i);
151  pPlanEauGeoNode->getGraphicObject()->display(renderContext);
152  }
153 
154  // Terrains
155  TYTabTerrainGeoNode* pTabTerrain = &getElement()->getListTerrain();
156  TYTerrainGeoNode* pTerrainGeoNode = NULL;
157  for (i = 0; i < pTabTerrain->size(); i++)
158  {
159  pTerrainGeoNode = pTabTerrain->operator[](i);
160  pTerrainGeoNode->getGraphicObject()->display(renderContext);
161  }
162 
163  // Cours d'Eau
164  TYTabCoursEauGeoNode* pTabCrsEau = &getElement()->getListCrsEau();
165  TYCoursEauGeoNode* pCrsEauGeoNode = NULL;
166  for (i = 0; i < pTabCrsEau->size(); i++)
167  {
168  pCrsEauGeoNode = pTabCrsEau->operator[](i);
169  pCrsEauGeoNode->getGraphicObject()->display(renderContext);
170  }
171 
172  // Courbes de niveau
173  // xbh: les courbes de niveau en dernier et separement pour que l'anti-aliasing soit correct
174  TYTabCourbeNiveauGeoNode* pTabCrbNiv = &getElement()->getListCrbNiv();
175  TYCourbeNiveauGeoNode* pCrbNivGeoNode = NULL;
176  for (i = 0; i < pTabCrbNiv->size(); i++)
177  {
178  pCrbNivGeoNode = pTabCrbNiv->operator[](i);
179  pCrbNivGeoNode->getGraphicObject()->display(renderContext);
180  }
181 }
182 
183 void TYTopographieGraphic::setBackgroundImage(std::shared_ptr<QImage>& image, int semiX, int semiY,
184  TYPoint ptPosition, OVector3D bgOrientation)
185 {
186  TYTopographie* pTYTopographie = getElement();
187  LPTYSiteNode pParentSite = dynamic_cast<TYSiteNode*>(pTYTopographie->getParent());
188  assert(pParentSite != nullptr && "The parent of a TYTopographie element must be a TYSiteNode");
189  if (pParentSite->getRoot())
190  {
191  LPTYAltimetrie altimetrie = pParentSite->getAltimetry();
192  LPTYElementGraphic ElementGraphic = altimetrie->getGraphicObject();
193  ((TYAltimetrieGraphic*)((TYElementGraphic*)ElementGraphic))
194  ->setBackgroundImage(image, semiX, semiY, ptPosition, bgOrientation);
195  }
196 }
197 
199 {
200  TYTopographie* pTYTopographie = getElement();
201  LPTYSiteNode pParentSite = dynamic_cast<TYSiteNode*>(pTYTopographie->getParent());
202  assert(pParentSite != nullptr && "The parent of a TYTopographie element must be a TYSiteNode");
203  if (pParentSite->getRoot())
204  {
205  LPTYAltimetrie altimetrie = pParentSite->getAltimetry();
206  LPTYElementGraphic ElementGraphic = altimetrie->getGraphicObject();
207  ((TYAltimetrieGraphic*)((TYElementGraphic*)ElementGraphic))->unsetBackgroundImage();
208  }
209 }
210 
211 void TYTopographieGraphic::collectMeshInstances(std::vector<OGLMeshInstance>& meshInstances,
212  TYRenderContext* renderContext) const
213 {
214  meshInstances.emplace_back(_empriseMesh, globalMatrix());
215 }
216 
218 {
219  std::vector<QVector3D> vertices;
220  for (auto point : getElement()->getEmprise())
221  {
222  vertices.emplace_back(point._x, point._y, point._z);
223  }
224  _empriseMesh->setVertices(vertices);
225 }
Representation graphique de l'altimetrie (fichier header)
std::vector< LPTYCourbeNiveauGeoNode > TYTabCourbeNiveauGeoNode
Collection de noeuds geometriques de type TYCourbeNiveau.
std::vector< LPTYCoursEauGeoNode > TYTabCoursEauGeoNode
Collection de noeuds geometriques de type TYCoursEau.
Definition: TYCoursEau.h:70
list< TYElementGraphic * > TYListPtrTYElementGraphic
List de pointeur de TYElement.
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
Representation graphique d'un GeometryNode (fichier header)
std::vector< LPTYPlanEauGeoNode > TYTabPlanEauGeoNode
Collection de noeuds geometriques de type TYPlanEau.
Definition: TYPlanEau.h:202
Contexte de rendu utilisé par les fonctions d'affichage.
std::vector< LPTYTerrainGeoNode > TYTabTerrainGeoNode
Collection de noeuds geometriques de type TYTerrain.
Definition: TYTerrain.h:181
Representation graphique d'une topographie (fichier header)
The 3D vector class.
Definition: 3d.h:298
classe graphique pour une altimetrie
classe graphique pour un element de base
virtual void update(bool force=false)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual void display(TYRenderContext &renderContext)
QMatrix4x4 globalMatrix() const
bool getModified() const
TYElement * getParent() const
Definition: TYElement.h:697
LPTYAltimetrie getAltimetry() const
bool getRoot() const
Definition: TYSiteNode.h:321
void setBackgroundImage(std::shared_ptr< QImage > &image, int semiX, int semiY, TYPoint ptPosition, OVector3D bgOrientation)
std::shared_ptr< OGLPolyLineMesh > _empriseMesh
virtual void display(TYRenderContext &renderContext)
void collectMeshInstances(std::vector< OGLMeshInstance > &meshInstances, TYRenderContext *renderContext) const override
virtual void update(bool force=false)
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
TYTopographieGraphic(TYTopographie *pElement)