From 4ccaf80191e75d726f8edc370e4eec7b44dbca14 Mon Sep 17 00:00:00 2001
From: rahv <karsten.rink@ufz.de>
Date: Tue, 24 Mar 2015 16:16:42 +0100
Subject: [PATCH] introduced interface for handling element quality

---
 MeshLib/MeshQuality/ElementQualityInterface.h | 94 +++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 MeshLib/MeshQuality/ElementQualityInterface.h

diff --git a/MeshLib/MeshQuality/ElementQualityInterface.h b/MeshLib/MeshQuality/ElementQualityInterface.h
new file mode 100644
index 00000000000..f8265a42c3a
--- /dev/null
+++ b/MeshLib/MeshQuality/ElementQualityInterface.h
@@ -0,0 +1,94 @@
+/**
+ * \file   ElementQualityInterface.h
+ * \author Karsten Rink
+ * \date   2015-03-24
+ * \brief  Definition of the ElementQualityInterface class.
+ *
+ * \copyright
+ * Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+#ifndef ELEMENTQUALITYINTERFACE_H_
+#define ELEMENTQUALITYINTERFACE_H_
+
+#include <vector>
+
+#include "BaseLib/Histogram.h"
+
+#include "MeshLib/Mesh.h"
+#include "MeshLib/MeshQuality/ElementQualityMetric.h"
+#include "MeshLib/MeshQuality/EdgeRatioMetric.h"
+#include "MeshLib/MeshQuality/AreaMetric.h"
+#include "MeshLib/MeshQuality/VolumeMetric.h"
+#include "MeshLib/MeshQuality/AngleSkewMetric.h"
+#include "MeshLib/MeshQuality/RadiusEdgeRatioMetric.h"
+
+namespace MeshLib
+{
+
+/**
+ * Interface class for handling mesh element quality metrics
+ */
+class ElementQualityInterface
+{
+public:
+	ElementQualityInterface(MeshLib::Mesh const& mesh, MeshQualityType t)
+	: _type(t), _mesh(mesh), _quality_tester(nullptr)
+	{
+		init(_mesh, _type);
+	}
+
+	~ElementQualityInterface() 
+	{ 
+		delete _quality_tester; 
+	}
+
+	std::vector<double> const& getQualityVector() const
+	{ 
+		return _quality_tester->getElementQuality(); 
+	}
+
+	int writeHistogram(std::string const& file_name) const
+	{
+		if (_quality_tester == nullptr)
+			return 1;
+
+		double const n_bins (1 + 3.3 * log (static_cast<float>(_mesh.getNElements())));
+		BaseLib::Histogram<double> const histogram (_quality_tester->getHistogram(static_cast<size_t>(n_bins)));
+		histogram.write(file_name, _mesh.getName(), MeshQualityType2String(_type));
+		return 0;
+	}
+	
+private:
+	void init(MeshLib::Mesh const& mesh, MeshQualityType t)
+	{
+		if (t == MeshQualityType::EDGERATIO)
+			_quality_tester = new MeshLib::EdgeRatioMetric(mesh);
+		else if (t == MeshQualityType::AREA)
+			_quality_tester = new MeshLib::AreaMetric(mesh);
+		else if (t == MeshQualityType::VOLUME)
+			_quality_tester = new MeshLib::VolumeMetric(mesh);
+		else if (t == MeshQualityType::EQUIANGLESKEW)
+			_quality_tester = new MeshLib::AngleSkewMetric(mesh);
+		else if (t == MeshQualityType::RADIUSEDGERATIO)
+			_quality_tester = new MeshLib::RadiusEdgeRatioMetric(mesh);
+		else
+		{
+			ERR("VtkVisPipeline::checkMeshQuality(): Unknown MeshQualityType.");
+			return;
+		}
+		_quality_tester->calculateQuality();
+	}
+
+	MeshQualityType const _type;
+	MeshLib::Mesh const& _mesh;
+	MeshLib::ElementQualityMetric* _quality_tester;
+};
+
+}
+
+#endif /* ELEMENTQUALITYINTERFACE_H_ */
-- 
GitLab