OGS
ProjectPointOnMesh.cpp
Go to the documentation of this file.
1 
12 #include "MathLib/Point3d.h"
13 #include "MeshLib/Elements/Quad.h"
14 #include "MeshLib/Elements/Tri.h"
16 
17 namespace MeshLib
18 {
19 namespace ProjectPointOnMesh
20 {
21 Element const* getProjectedElement(std::vector<const Element*> const& elements,
22  Node const& node)
23 {
24  auto is_right_of = [&node](Node const& a, Node const& b) {
25  return GeoLib::getOrientationFast(node, a, b) ==
27  };
28 
29  for (auto const* e : elements)
30  {
31  auto const* nodes = e->getNodes();
32  if (e->getGeomType() == MeshElemType::TRIANGLE)
33  {
34  auto const& a = *nodes[0];
35  auto const& b = *nodes[1];
36  auto const& c = *nodes[2];
37  if (!is_right_of(a, b) && !is_right_of(b, c) && !is_right_of(c, a))
38  {
39  return e;
40  }
41  }
42  else if (e->getGeomType() == MeshElemType::QUAD)
43  {
44  auto const& a = *nodes[0];
45  auto const& b = *nodes[1];
46  auto const& c = *nodes[2];
47  auto const& d = *nodes[3];
48  if (!is_right_of(a, b) && !is_right_of(b, c) &&
49  !is_right_of(c, d) && !is_right_of(d, a))
50  {
51  return e;
52  }
53  }
54  }
55  return nullptr;
56 }
57 
58 double getElevation(Element const& element, Node const& node)
59 {
60  Eigen::Vector3d const v =
61  Eigen::Map<Eigen::Vector3d const>(node.getCoords()) -
62  Eigen::Map<Eigen::Vector3d const>(element.getNode(0)->getCoords());
63  auto const n = FaceRule::getSurfaceNormal(element).normalized();
64  return node[2] - n.dot(v) * n[2];
65 }
66 
67 } // namespace ProjectPointOnMesh
68 
69 } // end namespace MeshLib
Definition of analytical geometry functions.
Definition of the Point3d class.
Definition of the Quad class.
Definition of the Tri class.
const T * getCoords() const
Definition: TemplatePoint.h:75
virtual const Node * getNode(unsigned idx) const =0
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Definition: FaceRule.cpp:40
Orientation getOrientationFast(MathLib::Point3d const &p0, MathLib::Point3d const &p1, MathLib::Point3d const &p2)
double getElevation(Element const &element, Node const &node)
Element const * getProjectedElement(std::vector< const Element * > const &elements, Node const &node)