From 43fdc8afa83f86984ba2d1ebd655dda949082a99 Mon Sep 17 00:00:00 2001
From: Karsten Rink <karsten.rink@ufz.de>
Date: Wed, 8 Aug 2012 17:49:54 +0200
Subject: [PATCH] added some small helper functions (face normal calculation,
 on-surface-check, etc.), renamed MshElemType::LINE to EDGE, changed a bit of
 documentation

---
 FileIO/MeshIO.cpp          |  2 +-
 GeoLib/SensorData.h        | 14 ++++++++++++--
 GeoLib/Station.h           | 10 +++++-----
 MeshLib/Elements/Cell.cpp  |  8 ++++++++
 MeshLib/Elements/Cell.h    |  4 ++++
 MeshLib/Elements/Edge.cpp  |  6 +++---
 MeshLib/Elements/Element.h |  4 ++--
 MeshLib/Elements/Face.cpp  | 17 ++++++++++++++++-
 MeshLib/Elements/Face.h    |  4 ++++
 MeshLib/MshEnums.cpp       |  4 ++--
 MeshLib/MshEnums.h         |  2 +-
 11 files changed, 58 insertions(+), 17 deletions(-)

diff --git a/FileIO/MeshIO.cpp b/FileIO/MeshIO.cpp
index 7ea88cbbdeb..8534168995b 100644
--- a/FileIO/MeshIO.cpp
+++ b/FileIO/MeshIO.cpp
@@ -129,7 +129,7 @@ MeshLib::Element* MeshIO::readElement(const std::string& line, const std::vector
 
 	switch(elem_type)
 	{
-	case MshElemType::LINE:
+	case MshElemType::EDGE:
 		for (int i = 0; i < 2; i++)
 			ss >> idx[i];
 		elem = new MeshLib::Edge(nodes[idx[0]], nodes[idx[1]], patch_index);
diff --git a/GeoLib/SensorData.h b/GeoLib/SensorData.h
index 1a75aa0db46..22246fcaecc 100644
--- a/GeoLib/SensorData.h
+++ b/GeoLib/SensorData.h
@@ -18,8 +18,12 @@
 #include <string>
 #include <vector>
 
-/// Possible types of input data for time series sensor data.
-/// Implementation as Enum for specific implementations later on.
+/**
+ * Possible types of input data for time series sensor data.
+ * Implementation as Enum for specific implementations later on.
+ *
+ * \sa SensorData
+ */
 struct SensorDataType
 {
 	enum type {
@@ -31,6 +35,12 @@ struct SensorDataType
 	};
 };
 
+/**
+ * Possible types of time specification.
+ * In addition to the usual units we added 'DATE' for specification of dates
+ * in the format 'dd.mm.yyyy' as well as 'DATETIME' in the format
+ * 'dd.mm.yyyy.hh.mm.ss'.
+ */
 struct TimeStepType
 {
 	enum type {
diff --git a/GeoLib/Station.h b/GeoLib/Station.h
index 11fb36c475e..0005b310a8a 100644
--- a/GeoLib/Station.h
+++ b/GeoLib/Station.h
@@ -29,14 +29,14 @@ namespace GeoLib
 /**
  * \ingroup GeoLib
  *
- * \brief An observation station as a geometric object (i.e. basically a Point with some additional information.
+ * \brief A Station (observation site) is basically a Point with some additional information.
  *
- * An observation station as a geometric object. A station is basically a point object
- * with some additional information. This may include a name, a stratigraphy (only for the derived class StationBore),
- * time series data (as a SensorData-object), etc.
+ * Additional information is largely optional (except for a name, but even this may be empty). 
+ * It may include a name, a stratigraphy (only for the derived class StationBore), 
+ * time series data from data loggers (as a SensorData-object), etc.
  *
  * Notes concerning the property-system used in this class:
- * Variables of Station and derived classes can be defined to be "properties" of this class.
+ * Variables of Station and derived classes can be defined to be "properties" of this class (this is entirely optional!).
  * Certain functions in the GUI allow you to modify aspects of the visualisation based on these
  * properties (e.g. filtering operations such as "display only boreholes drilled after 1990 with a
  * depth between 400-800m").
diff --git a/MeshLib/Elements/Cell.cpp b/MeshLib/Elements/Cell.cpp
index 7c1a9f0f588..bb551fdaa0a 100644
--- a/MeshLib/Elements/Cell.cpp
+++ b/MeshLib/Elements/Cell.cpp
@@ -29,6 +29,14 @@ Cell::~Cell()
 	delete[] this->_neighbors;
 }
 
+bool Cell::isOnSurface() const
+{
+	unsigned n (this->getNNeighbors());
+	for (unsigned i(0); i<n; i++)
+		if (!this->_neighbors[i])
+			return true;
+	return false;
+}
 
 }
 
diff --git a/MeshLib/Elements/Cell.h b/MeshLib/Elements/Cell.h
index d3d02df3fb7..e07ca0adf0d 100644
--- a/MeshLib/Elements/Cell.h
+++ b/MeshLib/Elements/Cell.h
@@ -14,6 +14,7 @@
 #define CELL_H_
 
 #include "Element.h"
+#include "Face.h"
 
 namespace MeshLib {
 
@@ -32,6 +33,9 @@ public:
 	/// Get the volume of this 3d element.
 	virtual double getVolume() const { return _volume; };
 
+	/// Returns true if the cell is somewhere on the mesh surface and false otherwise.
+	bool isOnSurface() const;
+
 	/// Destructor
 	virtual ~Cell();
 
diff --git a/MeshLib/Elements/Edge.cpp b/MeshLib/Elements/Edge.cpp
index efbb774d2b0..fd922a85c2b 100644
--- a/MeshLib/Elements/Edge.cpp
+++ b/MeshLib/Elements/Edge.cpp
@@ -18,14 +18,14 @@
 namespace MeshLib {
 
 Edge::Edge(Node* nodes[2], unsigned value)
-	: Element(MshElemType::LINE, value)
+	: Element(MshElemType::EDGE, value)
 {
 	_nodes = nodes;
 	this->_length = this->computeLength();
 }
 
 Edge::Edge(Node* n0, Node* n1, unsigned value)
-	: Element(MshElemType::LINE, value)
+	: Element(MshElemType::EDGE, value)
 {
 	_nodes = new Node*[2];
 	_nodes[0] = n0;
@@ -35,7 +35,7 @@ Edge::Edge(Node* n0, Node* n1, unsigned value)
 }
 
 Edge::Edge(const Edge &edge)
-	: Element(MshElemType::LINE, edge.getValue())
+	: Element(MshElemType::EDGE, edge.getValue())
 {
 	_nodes = new Node*[2];
 	_nodes[0] = edge._nodes[0];
diff --git a/MeshLib/Elements/Element.h b/MeshLib/Elements/Element.h
index 33abe67e144..fe665baf358 100644
--- a/MeshLib/Elements/Element.h
+++ b/MeshLib/Elements/Element.h
@@ -47,10 +47,10 @@ public:
 	/// Get dimension of the mesh element.
 	virtual unsigned getDimension() const = 0;
 
-	/// Returns the edge i of the element.
+	/// Returns the i-th edge of the element.
 	const Element* getEdge(unsigned i) const;
 
-	/// Returns the face i of the element.
+	/// Returns the i-th face of the element.
 	virtual const Element* getFace(unsigned i) const = 0;
 
 	/// Get the number of edges for this element.
diff --git a/MeshLib/Elements/Face.cpp b/MeshLib/Elements/Face.cpp
index cab9b9ece36..d3d097fe2fd 100644
--- a/MeshLib/Elements/Face.cpp
+++ b/MeshLib/Elements/Face.cpp
@@ -12,6 +12,10 @@
 
 #include "Face.h"
 #include "Edge.h"
+#include "Node.h"
+
+#include "MathTools.h"
+
 
 namespace MeshLib {
 /*
@@ -30,7 +34,18 @@ Face::~Face()
 	delete[] this->_neighbors;
 }
 
-
+const double* Face::getSurfaceNormal() const
+{
+	const double edge1[3] = { (*this->_nodes[0])[0]-(*this->_nodes[1])[0],
+				 			  (*this->_nodes[0])[1]-(*this->_nodes[1])[1],
+							  (*this->_nodes[0])[2]-(*this->_nodes[1])[2] };
+	const double edge2[3] = { (*this->_nodes[1])[0]-(*this->_nodes[2])[0],
+							  (*this->_nodes[1])[1]-(*this->_nodes[2])[1],
+							  (*this->_nodes[1])[2]-(*this->_nodes[2])[2] };
+	double normal[3];
+	MathLib::crossProd(edge1, edge2, normal);
+	return normal;
+}
 
 }
 
diff --git a/MeshLib/Elements/Face.h b/MeshLib/Elements/Face.h
index f3866aebd07..1aa9e38f739 100644
--- a/MeshLib/Elements/Face.h
+++ b/MeshLib/Elements/Face.h
@@ -15,6 +15,7 @@
 
 #include "Element.h"
 
+
 namespace MeshLib {
 
 /**
@@ -41,6 +42,9 @@ public:
 	/// 2D elements have no faces.
 	unsigned getNFaces() const { return 0; };
 
+	/// Returns the surface normal of a 2D element.
+	const double* getSurfaceNormal() const;
+
 	/// Destructor
 	virtual ~Face();
 
diff --git a/MeshLib/MshEnums.cpp b/MeshLib/MshEnums.cpp
index 0833bd0be24..ac21c6a19cb 100644
--- a/MeshLib/MshEnums.cpp
+++ b/MeshLib/MshEnums.cpp
@@ -14,7 +14,7 @@
 
 const std::string MshElemType2String(const MshElemType::type t)
 {
-	if (t == MshElemType::LINE)
+	if (t == MshElemType::EDGE)
 		return "line";
 	if (t == MshElemType::QUAD)
 		return "quad";
@@ -34,7 +34,7 @@ const std::string MshElemType2String(const MshElemType::type t)
 MshElemType::type String2MshElemType(const std::string &s)
 {
 	if (s.compare("line") == 0)
-		return MshElemType::LINE;
+		return MshElemType::EDGE;
 	if (s.compare("quad") == 0)
 		return MshElemType::QUAD;
 	if (s.compare("hex")  == 0)
diff --git a/MeshLib/MshEnums.h b/MeshLib/MshEnums.h
index 431e2f8be71..765a4dcfd9c 100644
--- a/MeshLib/MshEnums.h
+++ b/MeshLib/MshEnums.h
@@ -22,7 +22,7 @@ struct MshElemType
 {
 	enum type {
 		INVALID,
-		LINE,
+		EDGE,
 		QUAD,
 		HEXAHEDRON,
 		TRIANGLE,
-- 
GitLab