src/vertexmap.cpp

Tue, 11 Apr 2023 20:27:04 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Tue, 11 Apr 2023 20:27:04 +0300
changeset 375
21a5ecbe34e4
parent 374
75efc3ba5a56
permissions
-rw-r--r--

Simplify signature of updateRenderPreferences

264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
1 #include "src/vertexmap.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
2 #include "src/gl/common.h"
117
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
4 hash_t hashVertex(const glm::vec3& vec)
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
5 {
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
6 return qHash(glm::ivec3{
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
7 int(vec.x * 10000),
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
8 int(vec.y * 10000),
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
9 int(vec.z * 10000),
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
10 });
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
11 }
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
12
338
719b909a7d2b Delete unused code
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 333
diff changeset
13 VertexMap::VertexMap(const QTextDocument *model) :
117
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 model{model}
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 {
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 this->build();
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 }
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
19 struct Edge
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
20 {
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
21 const glm::vec3& a;
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
22 const glm::vec3& b;
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
23 };
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
24
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
25 static void edges(const PlainPolygonElement& element, std::function<void(Edge&&)> fn)
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
26 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
27 std::visit<void>(overloaded{
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
28 [fn](const LineSegment& edge) {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
29 fn(Edge{edge.p1, edge.p2});
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
30 },
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
31 [fn](const Triangle& triangle) {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
32 fn(Edge{triangle.p1, triangle.p2});
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
33 fn(Edge{triangle.p2, triangle.p3});
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
34 fn(Edge{triangle.p3, triangle.p1});
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
35 },
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
36 [fn](const Quadrilateral& quad) {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
37 fn(Edge{quad.p1, quad.p2});
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
38 fn(Edge{quad.p2, quad.p3});
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
39 fn(Edge{quad.p3, quad.p4});
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
40 fn(Edge{quad.p4, quad.p1});
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
41 },
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
42 [fn](const ConditionalEdge& cedge) {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
43 fn(Edge{cedge.p1, cedge.p2});
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
44 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
45 }, element);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
46 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
47
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
48 inline void points(
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
49 const PlainPolygonElement& element,
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
50 std::function<void(const glm::vec3&)> fn)
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
51 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
52 std::visit<void>(overloaded{
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
53 [fn](const LineSegment& edge) {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
54 fn(edge.p1);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
55 fn(edge.p2);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
56 },
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
57 [fn](const Triangle& triangle) {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
58 fn(triangle.p1);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
59 fn(triangle.p2);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
60 fn(triangle.p3);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
61 },
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
62 [fn](const Quadrilateral& quad) {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
63 fn(quad.p1);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
64 fn(quad.p2);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
65 fn(quad.p3);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
66 fn(quad.p4);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
67 },
374
75efc3ba5a56 More refactor and renaming
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 338
diff changeset
68 [fn](const ConditionalEdge& cedge) {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
69 fn(cedge.p1);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
70 fn(cedge.p2);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
71 fn(cedge.c1);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
72 fn(cedge.c2);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
73 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
74 [](const ModelElement&&){}
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
75 }, element);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
76 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
77
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
78 template<typename R>
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
79 auto ifplanar(
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
80 const ModelElement& element,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
81 std::function<R(const glm::vec3&, const glm::vec3&, const glm::vec3&)> fn
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
82 )
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
83 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
84 return std::visit(overloaded{
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
85 [fn](const Triangle& triangle) -> std::optional<R> {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
86 return fn(triangle.p1, triangle.p2, triangle.p3);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
87 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
88 [fn](const Quadrilateral quad) -> std::optional<R> {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
89 return fn(quad.p1, quad.p2, quad.p3);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
90 },
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
91 [](const ModelElement&&) -> std::optional<R> {return {};}
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
92 }, element);
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
93 }
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
94
117
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
95 void VertexMap::build()
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
96 {
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 this->map.clear();
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
98 this->vertices.clear();
119
Teemu Piippo <teemu@hecknology.net>
parents: 118
diff changeset
99 this->vertexHashes.clear();
333
07e65a4c6611 Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
100 #if 0
250
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 200
diff changeset
101 for (std::size_t i = 0; i < this->model->size(); ++i)
117
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
103 const ModelElement& element = this->model->at(i);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
104 std::optional<glm::mat4> matrix = ifplanar<glm::mat4>(
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
105 element,
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
106 [](const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& p3)
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
107 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
108 const glm::vec3 a = glm::normalize(p2 - p1);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
109 const glm::vec3 b = glm::normalize(p3 - p1);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
110 const glm::vec3 c = glm::normalize(glm::cross(a, b));
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
111 const glm::vec3 d = glm::normalize(glm::cross(a, c));
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
112 return glm::mat4{{a, 0}, {-c, 0}, {d, 0}, {}};
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
113 });
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
114 points(element, [&](const glm::vec3 point) {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 250
diff changeset
115 const hash_t hash = hashVertex(point);
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
116 VertexInfo& info = this->map[hash];
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
117 info.point = point;
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
118 info.objects.insert(this->model->idAt(i));
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
119 if (matrix.has_value() and not info.transformSet)
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
120 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
121 info.transform = matrix.value();
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
122 info.transform[3] = {point, 1};
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
123 info.transformSet = true;
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
124 }
119
Teemu Piippo <teemu@hecknology.net>
parents: 118
diff changeset
125 if (not this->vertexHashes.contains(hash))
Teemu Piippo <teemu@hecknology.net>
parents: 118
diff changeset
126 {
Teemu Piippo <teemu@hecknology.net>
parents: 118
diff changeset
127 this->vertexHashes.insert(hash);
Teemu Piippo <teemu@hecknology.net>
parents: 118
diff changeset
128 this->vertices.push_back(point);
Teemu Piippo <teemu@hecknology.net>
parents: 118
diff changeset
129 }
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
130 });
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
131 }
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
132 for (auto& pair : this->map)
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
133 {
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
134 auto& info = pair.second;
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
135 // If there's no transformation calculated yet, make up a simple one that at least
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
136 // contains translation.
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
137 if (not info.transformSet)
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
138 {
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
139 info.transform = glm::translate(glm::identity<glm::mat4>(), info.point);
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
140 info.transformSet = true;
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
141 }
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
142 float scale = 1.0f;
309
d862721d19a3 Fixed ModelId being used to identify both models and elements, added ElementId to identify elements
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
143 for (const ElementId objectId : info.objects)
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
144 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
145 const std::optional<int> index = model->find(objectId);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
146 if (index.has_value()) {
250
2837b549e616 I felt that the compiler was too kind to me, so I enabled a big pile of warnings
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 200
diff changeset
147 edges(this->model->at(unsigned_cast(index.value())), [&](Edge&& edge)
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
148 {
200
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
149 if (hashVertex(edge.a) == pair.first or hashVertex(edge.b) == pair.first)
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
150 {
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
151 scale = std::min(scale, glm::length(edge.b - edge.a) / 3);
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
152 }
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
153 });
ca23936b455b Giant refactor
Teemu Piippo <teemu@hecknology.net>
parents: 151
diff changeset
154 }
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
155 }
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
156 info.transform = glm::scale(info.transform, glm::vec3{scale, scale, scale});
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
157 }
333
07e65a4c6611 Experiment to delete the Model class and rely solely on text documents
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 309
diff changeset
158 #endif
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
159 Q_EMIT this->verticesChanged();
117
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
160 }
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
161
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
162 /**
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
163 * @brief Apply \c fn for all vertices in the map.
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
164 * @param fn
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
165 */
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
166 void VertexMap::apply(ApplyFunction fn) const
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
167 {
119
Teemu Piippo <teemu@hecknology.net>
parents: 118
diff changeset
168 for (unsigned int i = 0; i < this->vertices.size(); i += 1)
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
169 {
119
Teemu Piippo <teemu@hecknology.net>
parents: 118
diff changeset
170 const glm::vec3& point = this->vertices[i];
120
8c9fff699241 rework rendering of vertices
Teemu Piippo <teemu@hecknology.net>
parents: 119
diff changeset
171 fn(point, this->map.at(hashVertex(point)));
118
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
172 }
8e1c9f18ae15 Add vertex rendering
Teemu Piippo <teemu@hecknology.net>
parents: 117
diff changeset
173 }

mercurial