Wed, 28 Jul 2021 08:23:09 +0300
update
#include "vertexmap.h" #include "linetypes/polygonobject.h" VertexMap::VertexMap(const Model *model) : model{model} { connect( model, &Model::dataChanged, this, &VertexMap::build ); connect( model, &Model::rowsInserted, this, &VertexMap::build ); connect( model, &Model::rowsRemoved, this, &VertexMap::build ); this->build(); } void VertexMap::build() { this->map.clear(); this->vertices.clear(); this->vertexHashes.clear(); this->model->apply<ldraw::Object>([&](const ldraw::Object* object) { for (int i = 0; i < object->numPoints(); i += 1) { const glm::vec3& point = object->getPoint(i); const unsigned int hash = qHash(point); this->map[hash].insert(object->id); if (not this->vertexHashes.contains(hash)) { this->vertexHashes.insert(hash); this->vertices.push_back(point); } } }); Q_EMIT this->verticesChanged(); } /** * @brief Apply \c fn for all vertices in the map. * @param fn */ void VertexMap::apply(ApplyFunction fn) const { for (unsigned int i = 0; i < this->vertices.size(); i += 1) { const glm::vec3& point = this->vertices[i]; fn(point, this->map.at(qHash(point))); } }