From 4dae8ca5f198dc4ad8a0623e31b5962cd3b79d3f Mon Sep 17 00:00:00 2001
From: Karsten Rink <karsten.rink@ufz.de>
Date: Fri, 31 Jan 2014 12:03:03 +0100
Subject: [PATCH] Fixed issue where mesh to surface conversion would fail if
 points had been collapsed when creating geometry point vector; current
 solution allows for triangles with A=0.

---
 MeshLib/convertMeshToGeo.cpp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/MeshLib/convertMeshToGeo.cpp b/MeshLib/convertMeshToGeo.cpp
index 76cbe28626f..4475e919267 100644
--- a/MeshLib/convertMeshToGeo.cpp
+++ b/MeshLib/convertMeshToGeo.cpp
@@ -43,6 +43,10 @@ bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects* geo_objects
 	for (unsigned i=0; i<nNodes; ++i)
 		(*points)[i] = new GeoLib::Point(static_cast<GeoLib::Point>(*nodes[i]));
 
+	std::string mesh_name (mesh.getName());
+	geo_objects->addPointVec(points, mesh_name);
+	const std::vector<std::size_t> id_map (geo_objects->getPointVecObj(mesh_name)->getIDMap());
+
 	// elements to surface triangles conversion
 	const std::vector<MeshLib::Element*> &elements = mesh.getElements();
 	GeoLib::Surface* sfc = new GeoLib::Surface(*points);
@@ -52,11 +56,11 @@ bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects* geo_objects
 	{
 		MeshLib::Element* e (elements[i]);
 		if (e->getGeomType() == MeshElemType::TRIANGLE)
-			sfc->addTriangle(e->getNodeIndex(0), e->getNodeIndex(1), e->getNodeIndex(2));
+			sfc->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]);
 		if (e->getGeomType() == MeshElemType::QUAD)
 		{
-			sfc->addTriangle(e->getNodeIndex(0), e->getNodeIndex(1), e->getNodeIndex(2));
-			sfc->addTriangle(e->getNodeIndex(0), e->getNodeIndex(2), e->getNodeIndex(3));
+			sfc->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(1)], id_map[e->getNodeIndex(2)]);
+			sfc->addTriangle(id_map[e->getNodeIndex(0)], id_map[e->getNodeIndex(2)], id_map[e->getNodeIndex(3)]);
 		}
 		// all other element types are ignored (i.e. lines)
 	}
@@ -64,8 +68,6 @@ bool convertMeshToGeo(const MeshLib::Mesh &mesh, GeoLib::GEOObjects* geo_objects
 	std::vector<GeoLib::Surface*> *sfcs = new std::vector<GeoLib::Surface*>(1);
 	(*sfcs)[0] = sfc;
 
-	std::string mesh_name (mesh.getName());
-	geo_objects->addPointVec(points, mesh_name);
 	geo_objects->addSurfaceVec(sfcs, mesh_name);
 	return true;
 }
-- 
GitLab