Skip to content
Snippets Groups Projects
Commit 04e69576 authored by Karsten Rink's avatar Karsten Rink
Browse files

added method for testing if point is inside element for all element types

parent 0acbabce
No related branches found
No related tags found
No related merge requests found
......@@ -212,8 +212,7 @@ double orient3d(GeoLib::Point const& p,
/// Checks if the four given points are located on a plane.
bool isCoplanar(const GeoLib::Point& a, const GeoLib::Point& b,
const GeoLib::Point& c, const GeoLib::Point& d);
/**
* Method first computes the intersection points of line segements of GeoLib::Polyline objects
* (@see computeIntersectionPoints()) and pushes each intersection point in the GeoLib::PointVec
......
......@@ -19,10 +19,13 @@
#include <limits>
#include <boost/optional.hpp>
#include "Point.h"
#include "MeshLib/MeshEnums.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/MeshQuality/ElementErrorCode.h"
namespace MeshLib {
class Node;
......@@ -152,6 +155,9 @@ public:
/// Returns true if these two indeces form an edge and false otherwise
virtual bool isEdge(unsigned i, unsigned j) const = 0;
/// Returns true if the given point is not located outside of the element
virtual bool isPntInElement(GeoLib::Point const& pnt) const = 0;
/**
* Tests if the element is geometrically valid.
*/
......
......@@ -139,6 +139,17 @@ bool TemplateHex<NNODES,CELLHEXTYPE>::isEdge(unsigned idx1, unsigned idx2) const
return false;
}
template <unsigned NNODES, CellType CELLHEXTYPE>
bool TemplateHex<NNODES,CELLHEXTYPE>::isPntInElement(GeoLib::Point const& pnt) const
{
return (GeoLib::isPointInTetrahedron(pnt, *_nodes[4], *_nodes[7], *_nodes[5], *_nodes[0]) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[3], *_nodes[1], *_nodes[0]) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[7], *_nodes[3], *_nodes[0]) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[5], *_nodes[7], *_nodes[6], *_nodes[2]) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[1], *_nodes[3], *_nodes[5], *_nodes[2]) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[3], *_nodes[7], *_nodes[5], *_nodes[2]));
}
template <unsigned NNODES, CellType CELLHEXTYPE>
Element* TemplateHex<NNODES,CELLHEXTYPE>::clone() const
{
......
......@@ -104,6 +104,9 @@ public:
/// Returns true if these two indices form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/// Returns true if the given point is not located outside of the hexahedron
bool isPntInElement(GeoLib::Point const& pnt) const;
/**
* Tests if the element is geometrically valid.
* @param check_zero_volume indicates if volume == 0 should be checked
......
......@@ -55,6 +55,15 @@ template <unsigned NNODES, CellType CELLLINETYPE>
TemplateLine<NNODES,CELLLINETYPE>::~TemplateLine()
{}
template <unsigned NNODES, CellType CELLLINETYPE>
bool TemplateLine<NNODES,CELLLINETYPE>::isPntInElement(GeoLib::Point const& pnt) const
{
double tmp;
double dist(0);
MathLib::calcProjPntToLineAndDists(pnt.getCoords(), _nodes[0]->getCoords(), _nodes[1]->getCoords(), tmp, dist);
return (dist < std::numeric_limits<double>::epsilon());
}
template <unsigned NNODES, CellType CELLLINETYPE>
ElementErrorCode TemplateLine<NNODES,CELLLINETYPE>::validate() const
{
......
......@@ -115,6 +115,9 @@ public:
return false;
}
/// Returns true if pnt is located on the line segment and false otherwise
bool isPntInElement(GeoLib::Point const& pnt) const;
/**
* Tests if the element is geometrically valid.
* @param check_zero_volume indicates if area == 0 should be checked
......
......@@ -148,6 +148,14 @@ bool TemplatePrism<NNODES,CELLPRISMTYPE>::isEdge(unsigned idx1, unsigned idx2) c
return false;
}
template <unsigned NNODES, CellType CELLPRISMTYPE>
bool TemplatePrism<NNODES,CELLPRISMTYPE>::isPntInElement(GeoLib::Point const& pnt) const
{
return (GeoLib::isPointInTetrahedron(pnt, *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[3]) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[1], *_nodes[4], *_nodes[2], *_nodes[3]) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[2], *_nodes[4], *_nodes[5], *_nodes[3]));
}
template <unsigned NNODES, CellType CELLPRISMTYPE>
Element* TemplatePrism<NNODES,CELLPRISMTYPE>::clone() const
{
......
......@@ -102,6 +102,9 @@ public:
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/// Returns true if the given point is not located outside of the prism
bool isPntInElement(GeoLib::Point const& pnt) const;
/**
* Tests if the element is geometrically valid.
* @param check_zero_volume indicates if volume == 0 should be checked
......
......@@ -150,6 +150,13 @@ bool TemplatePyramid<NNODES,CELLPYRAMIDTYPE>::isEdge(unsigned idx1, unsigned idx
return false;
}
template <unsigned NNODES, CellType CELLPYRAMIDTYPE>
bool TemplatePyramid<NNODES,CELLPYRAMIDTYPE>::isPntInElement(GeoLib::Point const& pnt) const
{
return (GeoLib::isPointInTetrahedron(pnt, *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[4]) ||
GeoLib::isPointInTetrahedron(pnt, *_nodes[0], *_nodes[2], *_nodes[3], *_nodes[4]));
}
template <unsigned NNODES, CellType CELLPYRAMIDTYPE>
Element* TemplatePyramid<NNODES,CELLPYRAMIDTYPE>::clone() const
{
......
......@@ -100,6 +100,9 @@ public:
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/// Returns true if the given point is not located outside of the pyramid
bool isPntInElement(GeoLib::Point const& pnt) const;
/**
* Tests if the element is geometrically valid.
* @param check_zero_volume indicates if volume == 0 should be checked
......
......@@ -89,6 +89,9 @@ public:
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/// Returns true if the given point is not located outside of the quad
bool isPntInElement(GeoLib::Point const& pnt) const { return isPntInside(pnt); }
/**
* Check if the 3d GeoLib::Point is inside of the quad element.
* @param pnt the 3d GeoLib::Point object
......
......@@ -128,6 +128,12 @@ bool TemplateTet<NNODES,CELLTETTYPE>::isEdge(unsigned idx1, unsigned idx2) const
return false;
}
template <unsigned NNODES, CellType CELLTETTYPE>
bool TemplateTet<NNODES,CELLTETTYPE>::isPntInElement(GeoLib::Point const& pnt) const
{
return GeoLib::isPointInTetrahedron(pnt, *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[3]);
}
template <unsigned NNODES, CellType CELLTETTYPE>
Element* TemplateTet<NNODES,CELLTETTYPE>::clone() const
{
......
......@@ -99,6 +99,9 @@ public:
/// Returns true if these two indeces form an edge and false otherwise
bool isEdge(unsigned i, unsigned j) const;
/// Returns true if the given point is not located outside of the tetrahedron
bool isPntInElement(GeoLib::Point const& pnt) const;
/**
* Tests if the element is geometrically valid.
* @param check_zero_volume indicates if volume == 0 should be checked
......
......@@ -93,6 +93,9 @@ public:
/// Returns true if these two indices form an edge and false otherwise
bool isEdge(unsigned idx1, unsigned idx2) const;
/// Returns true if the given point is not located outside of the triangle
bool isPntInElement(GeoLib::Point const& pnt) const { return isPntInside(pnt); }
/**
* Check if the 3d GeoLib::Point is inside of the element.
* @param pnt the 3d GeoLib::Point object
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment