src/vertexmap.cpp

changeset 119
24275a4064f4
parent 118
8e1c9f18ae15
child 120
8c9fff699241
equal deleted inserted replaced
118:8e1c9f18ae15 119:24275a4064f4
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->vertices.clear();
32 this->vertexHashes.clear();
32 this->model->apply<ldraw::Object>([&](const ldraw::Object* object) 33 this->model->apply<ldraw::Object>([&](const ldraw::Object* object)
33 { 34 {
34 for (int i = 0; i < object->numPoints(); i += 1) 35 for (int i = 0; i < object->numPoints(); i += 1)
35 { 36 {
36 const glm::vec3& point = object->getPoint(i); 37 const glm::vec3& point = object->getPoint(i);
37 const unsigned int hash = qHash(point); 38 const unsigned int hash = qHash(point);
38 this->map[hash].insert(object->id); 39 this->map[hash].insert(object->id);
39 this->vertices[hash] = point; 40 if (not this->vertexHashes.contains(hash))
41 {
42 this->vertexHashes.insert(hash);
43 this->vertices.push_back(point);
44 }
40 } 45 }
41 }); 46 });
42 Q_EMIT this->verticesChanged(); 47 Q_EMIT this->verticesChanged();
43 } 48 }
44 49
46 * @brief Apply \c fn for all vertices in the map. 51 * @brief Apply \c fn for all vertices in the map.
47 * @param fn 52 * @param fn
48 */ 53 */
49 void VertexMap::apply(ApplyFunction fn) const 54 void VertexMap::apply(ApplyFunction fn) const
50 { 55 {
51 for (auto it = this->map.cbegin(); it != this->map.cend(); ++it) 56 for (unsigned int i = 0; i < this->vertices.size(); i += 1)
52 { 57 {
53 const glm::vec3& point = this->vertices.at(it->first); 58 const glm::vec3& point = this->vertices[i];
54 fn(point, it->second); 59 fn(point, this->map.at(qHash(point)));
55 } 60 }
56 } 61 }

mercurial