Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OGLArrayMesh.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 
16 #include "gui/tools/OGLArrayMesh.h"
17 #include "gui/tools/OGLMesh.h"
19 #include <cassert>
20 #include <memory>
21 #include <qcolor.h>
22 #include <vector>
23 
24 void OGLArrayMesh::fromMeshVertices(const OGLMesh& sourceMesh)
25 {
26  setVertices(sourceMesh.vertices());
28  setNormals(sourceMesh.normals());
30  std::vector<unsigned int> indices(sourceMesh.vertices().size());
31  std::iota(indices.begin(), indices.end(), 0);
33 };
34 
36 {
37  assert(sourceMesh.primitiveType() == OGLPrivimitiveType::Quads);
38  setVertices(sourceMesh.vertices());
40  setNormals(sourceMesh.normals());
42  std::vector<unsigned int> indices(sourceMesh.vertices().size() * 2);
43  int quadCount = sourceMesh.indices().size() / 4;
44  for (int quadIndex = 0; quadIndex < quadCount; quadIndex++)
45  {
46  for (int i = 0; i < 4; i++)
47  {
48  indices[quadIndex * 8 + i * 2] = quadIndex * 4 + i;
49  indices[quadIndex * 8 + i * 2 + 1] = quadIndex * 4 + (i + 1) % 4;
50  }
51  }
53 }
54 
55 void OGLArrayMesh::setVertices(const std::vector<QVector3D>& vertices)
56 {
59 }
60 
61 void OGLArrayMesh::setVerticesColors(const std::vector<QColor>& verticesColors)
62 {
63  _verticesColors.clear();
64  _verticesColors.reserve(verticesColors.size() * 4);
65  for (const QColor& color : verticesColors)
66  {
67  _verticesColors.push_back(color.redF());
68  _verticesColors.push_back(color.greenF());
69  _verticesColors.push_back(color.blueF());
70  _verticesColors.push_back(color.alphaF());
71  }
72 }
73 
74 void OGLArrayMesh::setNormals(const std::vector<QVector3D>& normals)
75 {
76  _normals = normals;
77 }
78 
79 void OGLArrayMesh::setTextureCoordinates(const std::vector<QVector2D>& textureCoordinates)
80 {
82 }
83 
84 void OGLArrayMesh::setIndices(const std::vector<unsigned int>& indices)
85 {
86  _indices = indices;
87 }
88 
90 {
92 }
OGLPrivimitiveType
Definition: OGLMesh.h:27
void fromQuadMeshEdges(const OGLMesh &mesh)
void setTextureCoordinates(const std::vector< QVector2D > &textureCoordinates)
void setIndices(const std::vector< unsigned int > &indices)
void setVertices(const std::vector< QVector3D > &vertices)
void fromMeshVertices(const OGLMesh &mesh)
void setVerticesColors(const std::vector< QColor > &verticesColors)
void setPrimitiveType(OGLPrivimitiveType primitiveType)
void setNormals(const std::vector< QVector3D > &normals)
std::vector< QVector3D > _vertices
Definition: OGLMesh.h:101
OGLPrivimitiveType _primitiveType
Definition: OGLMesh.h:107
const std::vector< unsigned int > & indices() const
Definition: OGLMesh.cpp:40
const std::vector< QVector3D > & normals() const
Definition: OGLMesh.cpp:30
const std::vector< QVector3D > & vertices() const
Definition: OGLMesh.cpp:20
std::vector< unsigned int > _indices
Definition: OGLMesh.h:105
std::vector< float > _verticesColors
Definition: OGLMesh.h:102
const std::vector< QVector2D > & textureCoordinates() const
Definition: OGLMesh.cpp:35
std::vector< QVector3D > _normals
Definition: OGLMesh.h:103
const std::vector< float > & verticesColors() const
Definition: OGLMesh.cpp:25
std::vector< QVector2D > _textureCoordinates
Definition: OGLMesh.h:104
void recomputeBoundingBox()
Definition: OGLMesh.cpp:59
const OGLPrivimitiveType primitiveType() const
Definition: OGLMesh.h:87