src/vertexmap.cpp

changeset 117
121a40d5e34c
child 118
8e1c9f18ae15
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/vertexmap.cpp	Tue Jul 27 13:23:34 2021 +0300
@@ -0,0 +1,39 @@
+#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->model->apply<ldraw::Object>([&](const ldraw::Object* object)
+	{
+		for (int i = 0; i < object->numPoints(); i += 1)
+		{
+			const glm::vec3& point = object->getPoint(i);
+			this->map[qHash(point)].insert(object->id);
+		}
+	});
+}

mercurial