OGS
MarkNodesOutsideOfPolygon.h
Go to the documentation of this file.
1/*
2 * \file
3 * \copyright
4 * Copyright (c) 2012-2024, 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
21namespace MeshGeoToolsLib
22{
23std::vector<bool> markNodesOutSideOfPolygon(
24 std::vector<MeshLib::Node*> const& nodes, GeoLib::Polygon const& polygon)
25{
26 // *** rotate polygon points to xy-plane
27 auto [rotated_polygon_points, 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 std::vector<bool> outside(rotated_nodes.size(), true);
45 // *** mark rotated nodes inside rotated polygon
46 {
47 // create new polygon using the rotated points
48 GeoLib::Polyline rotated_polyline(rotated_polygon_points);
49 for (std::size_t k(0); k < polygon.getNumberOfPoints(); k++)
50 {
51 rotated_polyline.addPoint(k);
52 }
53 rotated_polyline.addPoint(0);
54 GeoLib::Polygon const rotated_polygon(rotated_polyline);
55
56 for (std::size_t k(0); k < rotated_nodes.size(); k++)
57 {
58 if (rotated_polygon.isPntInPolygon(*(rotated_nodes[k])))
59 {
60 outside[k] = false;
61 }
62 }
63 }
64
65 for (auto& rotated_node : rotated_nodes)
66 {
67 delete rotated_node;
68 }
69
70 for (auto& rot_polygon_pnt : rotated_polygon_points)
71 {
72 delete rot_polygon_pnt;
73 }
74
75 return outside;
76}
77
78} // end namespace MeshGeoToolsLib
Definition of analytical geometry functions.
Definition of the Node class.
Definition of the Polygon class.
bool isPntInPolygon(MathLib::Point3d const &pnt) const
Definition Polygon.cpp:206
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:40
std::size_t getNumberOfPoints() const
Definition Polyline.cpp:109
virtual bool addPoint(std::size_t pnt_id)
Definition Polyline.cpp:35
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)