26 } |
26 } |
27 |
27 |
28 void VertexMap::build() |
28 void VertexMap::build() |
29 { |
29 { |
30 this->map.clear(); |
30 this->map.clear(); |
|
31 this->vertices.clear(); |
31 this->model->apply<ldraw::Object>([&](const ldraw::Object* object) |
32 this->model->apply<ldraw::Object>([&](const ldraw::Object* object) |
32 { |
33 { |
33 for (int i = 0; i < object->numPoints(); i += 1) |
34 for (int i = 0; i < object->numPoints(); i += 1) |
34 { |
35 { |
35 const glm::vec3& point = object->getPoint(i); |
36 const glm::vec3& point = object->getPoint(i); |
36 this->map[qHash(point)].insert(object->id); |
37 const unsigned int hash = qHash(point); |
|
38 this->map[hash].insert(object->id); |
|
39 this->vertices[hash] = point; |
37 } |
40 } |
38 }); |
41 }); |
|
42 Q_EMIT this->verticesChanged(); |
39 } |
43 } |
|
44 |
|
45 /** |
|
46 * @brief Apply \c fn for all vertices in the map. |
|
47 * @param fn |
|
48 */ |
|
49 void VertexMap::apply(ApplyFunction fn) const |
|
50 { |
|
51 for (auto it = this->map.cbegin(); it != this->map.cend(); ++it) |
|
52 { |
|
53 const glm::vec3& point = this->vertices.at(it->first); |
|
54 fn(point, it->second); |
|
55 } |
|
56 } |