Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYCourbeNiveauGraphic.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 
23 #include "TYCourbeNiveauGraphic.h"
28 #include <QtOpenGL>
29 #include <memory>
30 #include <qvector3d.h>
31 
33 {
35 }
36 
38  : TYElementGraphic(pElement),
39  _polylineMesh(std::make_shared<OGLPolyLineMesh>(endTypeFromCourbeNiveau(pElement)))
40 {
42  _pPolyLineGraphic->setElement(pElement);
43  updateMesh();
44 }
45 
46 void TYCourbeNiveauGraphic::update(bool force /*=false*/)
47 {
48  if (getModified() || force)
49  {
50  updateMesh();
52  }
53 }
54 
55 void TYCourbeNiveauGraphic::getChilds(TYListPtrTYElementGraphic& childs, bool recursif /*=true*/)
56 {
57  TYElementGraphic* pTYElementGraphic = _pPolyLineGraphic;
58  childs.push_back(pTYElementGraphic);
59  if (recursif)
60  {
61  pTYElementGraphic->getChilds(childs, recursif);
62  }
63 }
64 
66 {
67  if (!_visible)
68  {
69  return;
70  }
71 
72  TYElementGraphic::display(renderContext);
73 
74  if (renderContext.type == TYRenderType::Picking)
75  {
76  // XXX: Implement picking with ray casting
77  TYPickingTable::addElement(getElement());
78  glPushName((GLuint)(TYPickingTable::getIndex()));
79 
80  glColor4fv(getElement()->getColor());
81  float color[4]; // az++ test
82  glGetFloatv(GL_CURRENT_COLOR, color); // az++ test
83  _pPolyLineGraphic->display(renderContext);
84 
85  glPopName();
86  }
87 }
88 
89 void TYCourbeNiveauGraphic::collectMeshInstances(std::vector<OGLMeshInstance>& meshInstances,
90  TYRenderContext* renderContext) const
91 {
92  if (renderContext == nullptr || renderContext->showLevelCurves)
93  {
94  _polylineMesh->setMaterial(OGLSimpleMaterial{getElement()->getColor()});
95  meshInstances.emplace_back(_polylineMesh, globalMatrix());
96  }
97 };
99 {
100  // Update element graphic (legacy rendering)
101  // XXX remove it when it is no longer necessary
102  TYTabPoint tabpoints = getElement()->getListPoints();
103 
104  // Ajout d'un offset pour voir la courbe de niveau sur l'image site
105  for (unsigned int i = 0; i < tabpoints.size(); i++)
106  {
107  tabpoints[i]._z += 0.5; // Anciennement 0.05
108  }
109 
110  _pPolyLineGraphic->setTabPoint(tabpoints);
111 
112  // Update OGLMesh
113  std::vector<QVector3D> vertices;
114  for (auto point : _pPolyLineGraphic->getTabPoint())
115  {
116  vertices.emplace_back(point._x, point._y, point._z);
117  }
118  OGLPolyLineMesh::EndType endType = endTypeFromCourbeNiveau(getElement());
119 
120  _polylineMesh->setEndType(endType);
121  _polylineMesh->setVertices(vertices);
122 };
OGLPolyLineMesh::EndType endTypeFromCourbeNiveau(const TYCourbeNiveau *courbeNiveau)
Representation graphique d'une courbe de niveau (fichier header)
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.
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual void update(bool force=false)
TYCourbeNiveauGraphic(TYCourbeNiveau *pElement)
void collectMeshInstances(std::vector< OGLMeshInstance > &meshInstances, TYRenderContext *renderContext) const override
std::shared_ptr< OGLPolyLineMesh > _polylineMesh
virtual void display(TYRenderContext &renderContext)
LPTYPolyLineGraphic _pPolyLineGraphic
bool isClosed() const
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)
void setElement(TYElement *pElt)
QMatrix4x4 globalMatrix() const
bool getModified() const
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)
TYTabPoint & getTabPoint()
TYRenderType type