From b11f9eed87d01029b5c6cb40fbd2b4a9b6d4c9f2 Mon Sep 17 00:00:00 2001
From: Karsten Rink <karsten.rink@ufz.de>
Date: Mon, 7 Oct 2013 16:43:06 +0200
Subject: [PATCH] added support for quad-elements, added error-msg if mesh is
 not 2D

---
 Gui/DataView/GeoMapper.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/Gui/DataView/GeoMapper.cpp b/Gui/DataView/GeoMapper.cpp
index 0360f6389ee..9d759d32759 100644
--- a/Gui/DataView/GeoMapper.cpp
+++ b/Gui/DataView/GeoMapper.cpp
@@ -60,6 +60,12 @@ void GeoMapper::mapOnMesh(const std::string &file_name)
 
 void GeoMapper::mapOnMesh(const MeshLib::Mesh* mesh)
 {
+	if (mesh->getDimension() != 2)
+	{
+		ERR("GeoMapper::mapOnMesh(): Method only works on 2D meshes (triangle and quad elements)");
+		return;
+	}
+
 	this->_mesh = const_cast<MeshLib::Mesh*>(mesh);
 	std::vector<GeoLib::PointWithID*> sfc_pnts;
 	// init grid
@@ -348,12 +354,14 @@ double GeoMapper::getMeshElevation(double x, double y, double min_val, double ma
 
 	for (std::size_t i=0; i<elements.size(); ++i)
 	{
-		if (intersection==nullptr && elements[i]->getGeomType() == MeshElemType::TRIANGLE)
+		if (intersection==nullptr)
 			intersection=GeoLib::triangleLineIntersection(*elements[i]->getNode(0), *elements[i]->getNode(1), *elements[i]->getNode(2), GeoLib::Point(x,y,max_val), GeoLib::Point(x,y,min_val));
+		if (intersection==nullptr && elements[i]->getGeomType() == MeshElemType::QUAD)
+			intersection=GeoLib::triangleLineIntersection(*elements[i]->getNode(0), *elements[i]->getNode(2), *elements[i]->getNode(3), GeoLib::Point(x,y,max_val), GeoLib::Point(x,y,min_val));
 	}
-	// if the intersection point is not a triangle or something else goes wrong, we simply take the elevation of the nearest point	
 	if (intersection)
 		return (*intersection)[2];
+	// if something goes wrong, simply take the elevation of the nearest mesh node
 	return (*(_mesh->getNode(pnt->getID())))[2];
 }
 
-- 
GitLab