Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSiteNodeGraphic.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 
21 #include <cstddef>
22 #include <memory>
23 #include <qcolor.h>
24 #include <qimage.h>
25 #include <qmatrix4x4.h>
26 #include <qnamespace.h>
27 #include <qopengltexture.h>
28 #include <qsize.h>
31 #include "TYSiteNodeGraphic.h"
38 
40  : TYElementGraphic(pElement), _backgroundImage(std::shared_ptr<QImage>()),
41  _imageMesh(std::make_shared<OGLRectangleMesh>(QSizeF(0., 0.)))
42 {
43  _visible = true;
45 }
46 
48 
49 void TYSiteNodeGraphic::update(bool force /*=false*/)
50 {
51  if (getModified() || force)
52  {
55  }
56 }
57 
59 {
60  TYSiteNode* pSite = getElement();
61  QString topoFileName = pSite->getTopoFileName();
62  if (_sOldTopoFile != topoFileName)
63  {
64  _sOldTopoFile = topoFileName;
65  _backgroundImage = std::make_shared<QImage>();
66  bool loaded = _backgroundImage->load(topoFileName);
67  if (loaded)
68  {
69  *_backgroundImage = _backgroundImage->mirrored();
70  }
71  else
72  {
73  _backgroundImage.reset();
74  }
75  _imageMesh->material().image = _backgroundImage;
76  }
77  TYTopographieGraphic* topoGraphic =
78  ((TYTopographieGraphic*)((TYElementGraphic*)getElement()->getTopographie()->getGraphicObject()));
79  if (pSite->getUseTopoFile() && _backgroundImage != nullptr && !_backgroundImage->isNull())
80  {
81  float width = _backgroundImage->width() * getElement()->getEchelle();
82  float height = _backgroundImage->height() * getElement()->getEchelle();
83  _imageMesh->setDimensions({width, height});
84  TYPoint pt = getElement()->getPosition();
85  OVector3D vecOrientation = getElement()->getOrientation().toVector3D();
86  topoGraphic->setBackgroundImage(_backgroundImage, width / 2, height / 2, pt, vecOrientation);
87  }
88  else
89  {
90  topoGraphic->unsetBackgroundImage();
91  }
92 }
93 
94 void TYSiteNodeGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursif /*=true*/)
95 {
96  TYElementGraphic* pTYElementGraphic = nullptr;
97 
98  pTYElementGraphic = getElement()->getTopographie()->getGraphicObject().getRealPointer();
99  childs.push_back(pTYElementGraphic);
100  if (recursif)
101  {
102  pTYElementGraphic->getChilds(childs, recursif);
103  }
104 
105  pTYElementGraphic = getElement()->getInfrastructure()->getGraphicObject().getRealPointer();
106  childs.push_back(pTYElementGraphic);
107  if (recursif)
108  {
109  pTYElementGraphic->getChilds(childs, recursif);
110  }
111 
112  // Sites childs
113  TYSiteNode* pTYSiteNode = getElement();
114  TYTabSiteNodeGeoNode& TabSite = pTYSiteNode->getListSiteNode();
115  for (unsigned int i = 0; i < TabSite.size(); i++)
116  {
117  pTYElementGraphic = TabSite.at(i)->getGraphicObject().getRealPointer();
118  childs.push_back(pTYElementGraphic);
119  if (recursif)
120  {
121  pTYElementGraphic->getChilds(childs, recursif);
122  }
123  }
124 }
125 
127 {
128  if (!getElement()->isInCurrentCalcul())
129  {
130  return;
131  }
132 
133  TYElementGraphic::display(renderContext);
134 
135  // Draw site node displayed in modeler site at z=0
136  // Its subsites shall be drawn is same 3D referential
137  float fSiteNodeAltitude = (float)getElement()->getAltiEmprise();
138  glTranslatef(0.0f, 0.0f, -fSiteNodeAltitude);
139 
140  getElement()->getTopographie()->getGraphicObject()->display(renderContext);
141  getElement()->getInfrastructure()->getGraphicObject()->display(renderContext);
142  // Sites childs
143  TYSiteNode* pTYSiteNode = getElement(); // az++
144 
145  glTranslatef(0.0f, 0.0f, 0.01f);
146  TYTabSiteNodeGeoNode& TabSite = pTYSiteNode->getListSiteNode(); // az++
147  for (unsigned int i = 0; i < TabSite.size(); i++)
148  {
149  // az++
150  // Le site n'est affiché que s'il est dans le calcul courant
151  if (TabSite.at(i)->getElement()->isInCurrentCalcul())
152  {
153  TYSiteNode* pTYSiteNodeChild = dynamic_cast<TYSiteNode*>(TabSite.at(i)->getElement());
154  float fSiteNodeChildAltitude = pTYSiteNodeChild->getAltiEmprise();
155  // Subsites must be drawn in their parent 3D referential
156  glTranslatef(0.0f, 0.0f, fSiteNodeChildAltitude);
157  TabSite.at(i)->getGraphicObject()->display(renderContext); // az++
158  glTranslatef(0.0f, 0.0f, -fSiteNodeChildAltitude);
159  }
160  } // az++
161 
162  glTranslatef(0.0f, 0.0f, -0.01f + fSiteNodeAltitude);
163 }
164 
165 void TYSiteNodeGraphic::collectMeshInstances(std::vector<OGLMeshInstance>& meshInstances,
166  TYRenderContext* renderContext) const
167 {
168  bool renderBackgroundImage = getElement()->getUseTopoFile() && _imageMesh != nullptr;
169  if (renderContext != nullptr)
170  {
171  renderBackgroundImage &= renderContext->showBackgroundImage;
172  }
173  if (renderBackgroundImage)
174  if (getElement()->getUseTopoFile() && _imageMesh != nullptr)
175  {
176  QMatrix4x4 backgroundImageTransform;
177  float fSiteNodeAltitude = (float)getElement()->getAltiEmprise();
178  backgroundImageTransform.translate(0, 0, -fSiteNodeAltitude);
179 
180  double angle = 0.0;
181  OVector3D vecOrientation = getElement()->getOrientation().toVector3D();
182 
183  // On verifie que le vecteur orientation n'est pas nul
184  if (vecOrientation.norme() != 0)
185  {
186  // Calcul de l'angle
187  angle = SIGNE(vecOrientation._y) * acos(vecOrientation._x / vecOrientation.norme());
188  angle = (M_PI / 2.0) - angle;
189  }
190 
191  float fImgZOffset = 0.1f;
192  if (getElement()->getUseEmpriseAsCrbNiv())
193  {
194  fImgZOffset += (float)getElement()->getAltiEmprise();
195  }
196  backgroundImageTransform.translate(0, 0, fImgZOffset);
197 
198  backgroundImageTransform.rotate(angle * 180 / M_PI, 0.0, 0.0, 1.0);
199 
200  TYPoint pt = getElement()->getPosition();
201  backgroundImageTransform.translate(pt._x, pt._y, pt._z);
202 
203  meshInstances.emplace_back(_imageMesh, globalMatrix() * backgroundImageTransform);
204  }
205 }
206 
207 #if TY_USE_IHM
208 void TYSiteNodeGraphic::connectUpdateSignal(QObject* pReceiver, const char* member)
209 {
210  // _pUpdateSignal->connect(pReceiver, member);
211 }
212 #endif // TY_USE_IHM
213 
214 #if TY_USE_IHM
215 void TYSiteNodeGraphic::disconnectUpdateSignal(QObject* pReceiver, const char* member)
216 {
217  // _pUpdateSignal->disconnect(pReceiver, member);
218 }
219 #endif
double SIGNE(double a)
Return the number sign.
Definition: 3d.h:78
list< TYElementGraphic * > TYListPtrTYElementGraphic
List de pointeur de TYElement.
Contexte de rendu utilisé par les fonctions d'affichage.
Classe Modeler specialisee pour l'edition des sites (fichier header)
Representation graphique d'un ensemble de sites (fichier header)
std::vector< LPTYSiteNodeGeoNode > TYTabSiteNodeGeoNode
Collection de noeuds geometriques de type TYSiteNode.
Definition: TYSiteNode.h:40
Representation graphique d'une topographie (fichier header)
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 vector class.
Definition: 3d.h:298
double norme() const
Computes the length of this vector.
Definition: 3d.cpp:215
classe graphique pour un element de base
bool _visible
Inique si l'element est visible.
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
virtual void update(bool force=false)
TYSiteNodeGraphic(TYSiteNode *pElement)
std::shared_ptr< OGLRectangleMesh > _imageMesh
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
void collectMeshInstances(std::vector< OGLMeshInstance > &meshInstances, TYRenderContext *renderContext) const override
virtual void display(TYRenderContext &renderContext)
std::shared_ptr< QImage > _backgroundImage
const double getAltiEmprise() const
Definition: TYSiteNode.h:141
TYTabSiteNodeGeoNode & getListSiteNode()
Definition: TYSiteNode.h:346
QString getTopoFileName() const
Definition: TYSiteNode.h:241
bool getUseTopoFile() const
Definition: TYSiteNode.h:198
classe graphique pour une topographie
void setBackgroundImage(std::shared_ptr< QImage > &image, int semiX, int semiY, TYPoint ptPosition, OVector3D bgOrientation)
#define M_PI
Pi.
Definition: color.cpp:25