OGS
MarkNodesOutsideOfPolygon.h
Go to the documentation of this file.
1 /*
2  * \file
3  * \copyright
4  * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
5  * Distributed under a Modified BSD License.
6  * See accompanying file LICENSE.txt or
7  * http://www.opengeosys.org/project/license
8  *
9  */
10 
11 #pragma once
12 
13 #include <algorithm>
14 #include <vector>
15 
17 #include "GeoLib/Polygon.h"
18 
19 #include "MeshLib/Node.h"
20 
21 namespace MeshGeoToolsLib
22 {
23 std::vector<bool> markNodesOutSideOfPolygon(
24  std::vector<MeshLib::Node*> const& nodes, GeoLib::Polygon const& polygon)
25 {
26  // *** rotate polygon to xy_plane
27  Eigen::Vector3d normal;
28  GeoLib::Polygon rot_polygon(GeoLib::rotatePolygonToXY(polygon, normal));
29 
30  // *** rotate mesh nodes to xy-plane
31  // 1 copy all mesh nodes to GeoLib::Points
32  std::vector<GeoLib::Point*> rotated_nodes;
33  for (auto node : nodes)
34  {
35  rotated_nodes.push_back(new GeoLib::Point(*node, node->getID()));
36  }
37  // 2 rotate the Points
38  Eigen::Matrix3d const rot_mat = GeoLib::computeRotationMatrixToXY(normal);
39  GeoLib::rotatePoints(rot_mat, rotated_nodes);
40  // 3 set z coord to zero
41  std::for_each(rotated_nodes.begin(), rotated_nodes.end(),
42  [](GeoLib::Point* p) { (*p)[2] = 0.0; });
43 
44  // *** mark rotated nodes
45  std::vector<bool> outside(rotated_nodes.size(), true);
46  for (std::size_t k(0); k < rotated_nodes.size(); k++)
47  {
48  if (rot_polygon.isPntInPolygon(*(rotated_nodes[k])))
49  {
50  outside[k] = false;
51  }
52  }
53 
54  for (auto& rotated_node : rotated_nodes)
55  {
56  delete rotated_node;
57  }
58 
59  std::vector<GeoLib::Point*>& rot_polygon_pnts(
60  const_cast<std::vector<GeoLib::Point*>&>(rot_polygon.getPointsVec()));
61  for (auto& rot_polygon_pnt : rot_polygon_pnts)
62  {
63  delete rot_polygon_pnt;
64  }
65 
66  return outside;
67 }
68 
69 } // end namespace MeshGeoToolsLib
Definition of analytical geometry functions.
Definition of the Node class.
Definition of the Polygon class.
bool isPntInPolygon(const MathLib::Point3d &pnt) const
Definition: Polygon.cpp:71
std::vector< Point * > const & getPointsVec() const
Definition: Polyline.cpp:182
GeoLib::Polygon rotatePolygonToXY(GeoLib::Polygon const &polygon_in, Eigen::Vector3d &plane_normal)
void rotatePoints(Eigen::Matrix3d const &rot_mat, InputIterator pnts_begin, InputIterator pnts_end)
Eigen::Matrix3d computeRotationMatrixToXY(Eigen::Vector3d const &n)
std::vector< bool > markNodesOutSideOfPolygon(std::vector< MeshLib::Node * > const &nodes, GeoLib::Polygon const &polygon)