From 0f09ba0f295ef3441544881e4ae8c2a9b3a6b80f Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Wed, 17 Oct 2012 15:07:10 +0200 Subject: [PATCH] added virtual method isPntInside() --- MeshLib/Elements/Face.h | 12 ++++++++++++ MeshLib/Elements/TemplateQuad.h | 9 +++++++++ MeshLib/Elements/TemplateQuad.tpp | 9 +++++++++ MeshLib/Elements/TemplateTri.h | 8 ++++++++ MeshLib/Elements/TemplateTri.tpp | 9 +++++++++ 5 files changed, 47 insertions(+) diff --git a/MeshLib/Elements/Face.h b/MeshLib/Elements/Face.h index f310b952daf..2746abcf9f8 100644 --- a/MeshLib/Elements/Face.h +++ b/MeshLib/Elements/Face.h @@ -13,8 +13,12 @@ #ifndef FACE_H_ #define FACE_H_ +#include <limits> + #include "Element.h" +// GeoLib +#include "Point.h" namespace MeshLib { @@ -48,6 +52,14 @@ public: /// Destructor virtual ~Face(); + /** + * Check if the 3d GeoLib::Point is inside of the element. + * @param pnt the 3d GeoLib::Point object + * @param eps tolerance for numerical algorithm used or computing the property + * @return true if the point is inside the element, false otherwise + */ + virtual bool isPntInside(GeoLib::Point const& pnt, double eps = std::numeric_limits<double>::epsilon()) const = 0; + /** * This method is pure virtual and is inherited from class @sa Element. * It has to be implemented in the derived classes of class Face! diff --git a/MeshLib/Elements/TemplateQuad.h b/MeshLib/Elements/TemplateQuad.h index 5acef9471e1..c2cf8c433f6 100644 --- a/MeshLib/Elements/TemplateQuad.h +++ b/MeshLib/Elements/TemplateQuad.h @@ -73,6 +73,15 @@ public: /// Returns true if these two indeces form an edge and false otherwise bool isEdge(unsigned i, unsigned j) const; + /** + * Check if the 3d GeoLib::Point is inside of the quad element. + * @param pnt the 3d GeoLib::Point object + * @param eps tolerance for numerical algorithm used or computing the property + * @return true if the point is inside the element, false otherwise + */ + virtual bool isPntInside(GeoLib::Point const& pnt, double eps = std::numeric_limits<double>::epsilon()) const; + + /** * Method clone is inherited from class Element. It makes a deep copy of the TemplateQuad instance. * @return an exact copy of the object diff --git a/MeshLib/Elements/TemplateQuad.tpp b/MeshLib/Elements/TemplateQuad.tpp index eeb46b579d3..603b6e43869 100644 --- a/MeshLib/Elements/TemplateQuad.tpp +++ b/MeshLib/Elements/TemplateQuad.tpp @@ -13,7 +13,9 @@ #include "Node.h" #include "Tri.h" +// MathLib #include "MathTools.h" +#include "AnalyticalGeometry.h" namespace MeshLib { @@ -70,6 +72,13 @@ bool TemplateQuad<NNODES,FEMQUADTYPE>::isEdge(unsigned idx1, unsigned idx2) cons return false; } +template <unsigned NNODES, FEMElemType::type FEMQUADTYPE> +bool TemplateQuad<NNODES,FEMQUADTYPE>::isPntInside(GeoLib::Point const& pnt, double eps) const +{ + return (MathLib::isPointInTriangle(pnt, *_nodes[0], *_nodes[1], *_nodes[2], eps) || + MathLib::isPointInTriangle(pnt, *_nodes[0], *_nodes[2], *_nodes[3], eps)); +} + template <unsigned NNODES, FEMElemType::type FEMQUADTYPE> Element* TemplateQuad<NNODES,FEMQUADTYPE>::clone() const { diff --git a/MeshLib/Elements/TemplateTri.h b/MeshLib/Elements/TemplateTri.h index 12ccd1ea1cd..36d2b2b030a 100644 --- a/MeshLib/Elements/TemplateTri.h +++ b/MeshLib/Elements/TemplateTri.h @@ -80,6 +80,14 @@ public: /// Returns true if these two indices form an edge and false otherwise bool isEdge(unsigned idx1, unsigned idx2) const; + /** + * Check if the 3d GeoLib::Point is inside of the element. + * @param pnt the 3d GeoLib::Point object + * @param eps tolerance for numerical algorithm used or computing the property + * @return true if the point is inside the element, false otherwise + */ + virtual bool isPntInside(GeoLib::Point const& pnt, double eps = std::numeric_limits<double>::epsilon()) const; + /** * Method clone is inherited from class Element. It makes a deep copy of the TemplateTri instance. * @return an exact copy of the object diff --git a/MeshLib/Elements/TemplateTri.tpp b/MeshLib/Elements/TemplateTri.tpp index ab1d48e8baa..346c6241177 100644 --- a/MeshLib/Elements/TemplateTri.tpp +++ b/MeshLib/Elements/TemplateTri.tpp @@ -9,6 +9,9 @@ * Created on Sep 27, 2012 by Thomas Fischer */ +// MathLib +#include "AnalyticalGeometry.h" + namespace MeshLib { template <unsigned NNODES, FEMElemType::type FEMTRITYPE> @@ -55,6 +58,12 @@ bool TemplateTri<NNODES,FEMTRITYPE>::isEdge(unsigned idx1, unsigned idx2) const return false; } +template <unsigned NNODES, FEMElemType::type FEMTRITYPE> +bool TemplateTri<NNODES,FEMTRITYPE>::isPntInside(GeoLib::Point const& pnt, double eps) const +{ + return MathLib::isPointInTriangle(pnt, *_nodes[0], *_nodes[1], *_nodes[2], eps); +} + template <unsigned NNODES, FEMElemType::type FEMTRITYPE> Element* TemplateTri<NNODES,FEMTRITYPE>::reviseElement() const { -- GitLab