From 14cdf0c6fd7edb7de0f3e026ca2aadd01a55f9d5 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Fri, 17 Oct 2014 14:37:21 +0200 Subject: [PATCH] [ML] Move Face/Cell implementations in header file. --- MeshLib/Elements/Cell.cpp | 59 --------------------------------------- MeshLib/Elements/Cell.h | 23 +++++++++++++-- MeshLib/Elements/Face.cpp | 57 ------------------------------------- MeshLib/Elements/Face.h | 21 +++++++++++--- 4 files changed, 37 insertions(+), 123 deletions(-) delete mode 100644 MeshLib/Elements/Cell.cpp delete mode 100644 MeshLib/Elements/Face.cpp diff --git a/MeshLib/Elements/Cell.cpp b/MeshLib/Elements/Cell.cpp deleted file mode 100644 index 1c997a85f32..00000000000 --- a/MeshLib/Elements/Cell.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/** - * \file - * \author Karsten Rink - * \date 2012-05-02 - * \brief Implementation of the Cell class. - * - * \copyright - * Copyright (c) 2012-2014, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - */ - -#include "Cell.h" - -#include "MathLib/Vector3.h" -#include "MeshLib/Node.h" - -namespace MeshLib { - -#ifndef WIN32 -/// \todo Windows compiler does not accept this definition and issues a linking error. -const unsigned Cell::dimension; -#endif // WIN32 - -/* -Cell::Cell(Node** nodes, MeshElemType type, unsigned value) - : Element(nodes, type, value) -{ -} -*/ -Cell::Cell(unsigned value, std::size_t id) - : Element(value, id), _volume(-1.0) // init with invalid value to detect errors -{ -} - -Cell::~Cell() -{} - -bool Cell::testElementNodeOrder() const -{ - const MathLib::Vector3 c (getCenterOfGravity()); - const unsigned nFaces (this->getNFaces()); - for (unsigned j=0; j<nFaces; ++j) - { - MeshLib::Face const*const face (dynamic_cast<const MeshLib::Face*>(this->getFace(j))); - const MeshLib::Node x (*(face->getNode(1))); - const MathLib::Vector3 cx (c, x); - const double s = MathLib::scalarProduct(face->getSurfaceNormal(), cx); - delete face; - if (s >= 0) - return false; - } - return true; -} - -} - diff --git a/MeshLib/Elements/Cell.h b/MeshLib/Elements/Cell.h index d64fe479870..b143a98359b 100644 --- a/MeshLib/Elements/Cell.h +++ b/MeshLib/Elements/Cell.h @@ -39,7 +39,7 @@ public: virtual double getVolume() const { return _volume; }; /// Destructor - virtual ~Cell(); + virtual ~Cell() = default; /** * This method is pure virtual and is inherited from class @sa Element. @@ -56,7 +56,22 @@ public: * (non-planar faces, non-convex geometry, possibly zero volume) which causes the calculated * center of gravity to lie outside of the actual element */ - virtual bool testElementNodeOrder() const; + virtual bool testElementNodeOrder() const + { + const MathLib::Vector3 c (getCenterOfGravity()); + const unsigned nFaces (this->getNFaces()); + for (unsigned j=0; j<nFaces; ++j) + { + MeshLib::Face const*const face (dynamic_cast<const MeshLib::Face*>(this->getFace(j))); + const MeshLib::Node x (*(face->getNode(1))); + const MathLib::Vector3 cx (c, x); + const double s = MathLib::scalarProduct(face->getSurfaceNormal(), cx); + delete face; + if (s >= 0) + return false; + } + return true; + } protected: /* @@ -64,7 +79,9 @@ protected: Cell(Node** nodes, MeshElemType type, unsigned value = 0); */ /// Constructor for a generic mesh element without an array of mesh nodes. - Cell(unsigned value = 0, std::size_t id = std::numeric_limits<std::size_t>::max()); + Cell(unsigned value = 0, std::size_t id = std::numeric_limits<std::size_t>::max()) + : Element(value, id), _volume(-1.0) // init with invalid value to detect errors + { } double _volume; diff --git a/MeshLib/Elements/Face.cpp b/MeshLib/Elements/Face.cpp deleted file mode 100644 index 2f888f15713..00000000000 --- a/MeshLib/Elements/Face.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * \author Karsten Rink - * \date 2012-05-02 - * \brief Implementation of the Face class. - * - * \copyright - * Copyright (c) 2012-2014, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - */ - -#include "Face.h" - -#include "MathLib/MathTools.h" -#include "MathLib/Vector3.h" - -#include "Line.h" - -namespace MeshLib { - -#ifndef WIN32 - /// \todo Windows compiler does not accept this definition and issues a linking error. - const unsigned Face::dimension; -#endif // WIN32 - -/* -Face::Face(Node** nodes, MeshElemType type, unsigned value) - : Element(nodes, type, value) -{ -} -*/ -Face::Face(unsigned value, std::size_t id) - : Element(value, id), _area(-1.0) // init with invalid value to detect errors -{ -} - -Face::~Face() -{} - -MathLib::Vector3 Face::getSurfaceNormal() const -{ - const MathLib::Vector3 u (*_nodes[1], *_nodes[0]); - const MathLib::Vector3 v (*_nodes[1], *_nodes[2]); - return MathLib::crossProduct(u,v); -} - -bool Face::testElementNodeOrder() const -{ - MathLib::Vector3 up_vec (0,0,1); - return (MathLib::scalarProduct(this->getSurfaceNormal(), up_vec) < 0) ? true : false; -} - -} - diff --git a/MeshLib/Elements/Face.h b/MeshLib/Elements/Face.h index 70efd57ba69..b8f6c2a10d9 100644 --- a/MeshLib/Elements/Face.h +++ b/MeshLib/Elements/Face.h @@ -20,6 +20,7 @@ #include "GeoLib/Point.h" #include "MathLib/Vector3.h" +#include "MeshLib/Node.h" #include "Element.h" @@ -53,10 +54,15 @@ public: unsigned getNFaces() const { return 0; }; /// Returns the surface normal of a 2D element. - MathLib::Vector3 getSurfaceNormal() const; + MathLib::Vector3 getSurfaceNormal() const + { + const MathLib::Vector3 u (*_nodes[1], *_nodes[0]); + const MathLib::Vector3 v (*_nodes[1], *_nodes[2]); + return MathLib::crossProduct(u,v); + } /// Destructor - virtual ~Face(); + virtual ~Face() = default; /** * This method is pure virtual and is inherited from class @sa Element. @@ -69,7 +75,12 @@ public: * Checks if the node order of an element is correct by testing surface normals. * For 2D elements true is returned if the normal points (roughly) upwards. */ - virtual bool testElementNodeOrder() const; + virtual bool testElementNodeOrder() const + { + MathLib::Vector3 up_vec (0,0,1); + return (MathLib::scalarProduct(this->getSurfaceNormal(), up_vec) < 0) + ? true : false; + } protected: /* @@ -77,7 +88,9 @@ protected: Face(Node** nodes, MeshElemType type, unsigned value = 0); */ /// Constructor for a generic mesh element without an array of mesh nodes. - Face(unsigned value = 0, std::size_t id = std::numeric_limits<std::size_t>::max()); + Face(unsigned value = 0, std::size_t id = std::numeric_limits<std::size_t>::max()) + : Element(value, id), _area(-1.0) // init with invalid value to detect errors + { } double _area; -- GitLab