src/vertexmap.cpp

Tue, 27 Jul 2021 13:23:34 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 27 Jul 2021 13:23:34 +0300
changeset 117
121a40d5e34c
child 118
8e1c9f18ae15
permissions
-rw-r--r--

Add vertex map

117
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include "vertexmap.h"
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 #include "linetypes/polygonobject.h"
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 VertexMap::VertexMap(const Model *model) :
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 model{model}
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 {
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 connect(
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 model,
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 &Model::dataChanged,
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 this,
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 &VertexMap::build
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 );
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 connect(
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 model,
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 &Model::rowsInserted,
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 this,
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 &VertexMap::build
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 );
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 connect(
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 model,
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 &Model::rowsRemoved,
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 this,
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 &VertexMap::build
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 );
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 this->build();
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 }
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 void VertexMap::build()
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 {
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 this->map.clear();
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 this->model->apply<ldraw::Object>([&](const ldraw::Object* object)
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 {
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 for (int i = 0; i < object->numPoints(); i += 1)
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 {
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 const glm::vec3& point = object->getPoint(i);
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 this->map[qHash(point)].insert(object->id);
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 }
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 });
121a40d5e34c Add vertex map
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 }

mercurial