OGS
MarkNodesOutsideOfPolygon.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <algorithm>
7#include <vector>
8
10#include "GeoLib/Polygon.h"
11
12#include "MeshLib/Node.h"
13
14namespace MeshGeoToolsLib
15{
16std::vector<bool> markNodesOutSideOfPolygon(
17 std::vector<MeshLib::Node*> const& nodes, GeoLib::Polygon const& polygon)
18{
19 // *** rotate polygon points to xy-plane
20 auto [rotated_polygon_points, normal] =
22
23 // *** rotate mesh nodes to xy-plane
24 // 1 copy all mesh nodes to GeoLib::Points
25 std::vector<GeoLib::Point*> rotated_nodes;
26 for (auto node : nodes)
27 {
28 rotated_nodes.push_back(new GeoLib::Point(*node, node->getID()));
29 }
30 // 2 rotate the Points
31 Eigen::Matrix3d const rot_mat = GeoLib::computeRotationMatrixToXY(normal);
32 GeoLib::rotatePoints(rot_mat, rotated_nodes);
33 // 3 set z coord to zero
34 std::for_each(rotated_nodes.begin(), rotated_nodes.end(),
35 [](GeoLib::Point* p) { (*p)[2] = 0.0; });
36
37 std::vector<bool> outside(rotated_nodes.size(), true);
38 // *** mark rotated nodes inside rotated polygon
39 {
40 // create new polygon using the rotated points
41 GeoLib::Polyline rotated_polyline(rotated_polygon_points);
42 for (std::size_t k(0); k < polygon.getNumberOfPoints(); k++)
43 {
44 rotated_polyline.addPoint(k);
45 }
46 rotated_polyline.addPoint(0);
47 GeoLib::Polygon const rotated_polygon(rotated_polyline);
48
49 for (std::size_t k(0); k < rotated_nodes.size(); k++)
50 {
51 if (rotated_polygon.isPntInPolygon(*(rotated_nodes[k])))
52 {
53 outside[k] = false;
54 }
55 }
56 }
57
58 for (auto& rotated_node : rotated_nodes)
59 {
60 delete rotated_node;
61 }
62
63 for (auto& rot_polygon_pnt : rotated_polygon_points)
64 {
65 delete rot_polygon_pnt;
66 }
67
68 return outside;
69}
70
71} // end namespace MeshGeoToolsLib
bool isPntInPolygon(MathLib::Point3d const &pnt) const
Definition Polygon.cpp:194
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:29
std::size_t getNumberOfPoints() const
Definition Polyline.cpp:98
virtual bool addPoint(std::size_t pnt_id)
Definition Polyline.cpp:24
void rotatePoints(Eigen::Matrix3d const &rot_mat, InputIterator pnts_begin, InputIterator pnts_end)
std::tuple< std::vector< GeoLib::Point * >, Eigen::Vector3d > rotatePolygonPointsToXY(GeoLib::Polygon const &polygon_in)
Eigen::Matrix3d computeRotationMatrixToXY(Eigen::Vector3d const &n)
std::vector< bool > markNodesOutSideOfPolygon(std::vector< MeshLib::Node * > const &nodes, GeoLib::Polygon const &polygon)