From c8cac21f10027f70920b9df1f98080833ca7ec3d Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Fri, 17 Oct 2014 15:35:33 +0200 Subject: [PATCH] Revert "[ML] Move Face/Cell implementations in header file." This reverts commit 14cdf0c6fd7edb7de0f3e026ca2aadd01a55f9d5. --- MeshLib/Elements/Cell.cpp | 59 +++++++++++++++++++++++++++++++++++++++ MeshLib/Elements/Cell.h | 23 ++------------- MeshLib/Elements/Face.cpp | 57 +++++++++++++++++++++++++++++++++++++ MeshLib/Elements/Face.h | 21 +++----------- 4 files changed, 123 insertions(+), 37 deletions(-) create mode 100644 MeshLib/Elements/Cell.cpp create mode 100644 MeshLib/Elements/Face.cpp diff --git a/MeshLib/Elements/Cell.cpp b/MeshLib/Elements/Cell.cpp new file mode 100644 index 00000000000..1c997a85f32 --- /dev/null +++ b/MeshLib/Elements/Cell.cpp @@ -0,0 +1,59 @@ +/** + * \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 b143a98359b..d64fe479870 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() = default; + virtual ~Cell(); /** * This method is pure virtual and is inherited from class @sa Element. @@ -56,22 +56,7 @@ 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 - { - 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; - } + virtual bool testElementNodeOrder() const; protected: /* @@ -79,9 +64,7 @@ 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()) - : Element(value, id), _volume(-1.0) // init with invalid value to detect errors - { } + Cell(unsigned value = 0, std::size_t id = std::numeric_limits<std::size_t>::max()); double _volume; diff --git a/MeshLib/Elements/Face.cpp b/MeshLib/Elements/Face.cpp new file mode 100644 index 00000000000..2f888f15713 --- /dev/null +++ b/MeshLib/Elements/Face.cpp @@ -0,0 +1,57 @@ +/** + * \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 b8f6c2a10d9..70efd57ba69 100644 --- a/MeshLib/Elements/Face.h +++ b/MeshLib/Elements/Face.h @@ -20,7 +20,6 @@ #include "GeoLib/Point.h" #include "MathLib/Vector3.h" -#include "MeshLib/Node.h" #include "Element.h" @@ -54,15 +53,10 @@ public: unsigned getNFaces() const { return 0; }; /// Returns the surface normal of a 2D element. - 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); - } + MathLib::Vector3 getSurfaceNormal() const; /// Destructor - virtual ~Face() = default; + virtual ~Face(); /** * This method is pure virtual and is inherited from class @sa Element. @@ -75,12 +69,7 @@ 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 - { - MathLib::Vector3 up_vec (0,0,1); - return (MathLib::scalarProduct(this->getSurfaceNormal(), up_vec) < 0) - ? true : false; - } + virtual bool testElementNodeOrder() const; protected: /* @@ -88,9 +77,7 @@ 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()) - : Element(value, id), _area(-1.0) // init with invalid value to detect errors - { } + Face(unsigned value = 0, std::size_t id = std::numeric_limits<std::size_t>::max()); double _area; -- GitLab