Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
PolygonalEnclosure.hpp
1//---- GPL ---------------------------------------------------------------------
2//
3// Copyright (C) Stichting Deltares, 2011-2023.
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation version 3.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17// contact: delft3d.support@deltares.nl
18// Stichting Deltares
19// P.O. Box 177
20// 2600 MH Delft, The Netherlands
21//
22// All indications and logos of, and references to, "Delft3D" and "Deltares"
23// are registered trademarks of Stichting Deltares, and remain the property of
24// Stichting Deltares. All rights reserved.
25//
26//------------------------------------------------------------------------------
27
28#pragma once
29
30#include <utility>
31#include <vector>
32
33#include "MeshKernel/BoundingBox.hpp"
34#include "MeshKernel/Entities.hpp"
35#include "MeshKernel/Point.hpp"
36#include "MeshKernel/Polygon.hpp"
37
38namespace meshkernel
39{
40
46 {
47 public:
49 enum class Region
50 {
51 None,
52 Exterior,
54 };
55
57 PolygonalEnclosure(const std::vector<Point>& points,
58 Projection projection);
59
61 const Polygon& Outer() const;
62
64 UInt NumberOfInner() const;
65
67 const Polygon& Inner(size_t i) const;
68
72
76 bool Contains(const Point& pnt) const;
77
79 Region ContainsRegion(const Point& pnt) const;
80
82 UInt NumberOfPoints(const bool includeInterior) const;
83
85 void SnapToLandBoundary(size_t startIndex, size_t endIndex, const LandBoundary& landBoundary);
86
92 std::vector<Point> Refine(UInt startIndex, UInt endIndex, double refinementDistance) const;
93
98 std::vector<Point> LinearRefine(UInt startIndex, UInt endIndex) const;
99
105 std::tuple<std::unique_ptr<PolygonalEnclosure>, std::unique_ptr<PolygonalEnclosure>> OffsetCopy(double distance, bool outwardsAndInwards) const;
106
107 private:
110 using IndexRange = std::pair<UInt, UInt>;
111
114 using IndexRangeArray = std::vector<IndexRange>;
115
117 static Polygon ConstructPolygon(const std::vector<Point>& points,
118 size_t start,
119 size_t end,
120 Projection projection);
121
128 static void CopyPoints(const std::vector<Point>& source,
129 const size_t start,
130 const size_t end,
131 UInt& count,
132 std::vector<Point>& target);
133
135 void ConstructOuterPolygon(const std::vector<Point>& points,
136 size_t start, size_t end,
137 const IndexRangeArray& innerIndices,
138 Projection projection);
139
141 void ConstructInnerPolygons(const std::vector<Point>& points,
142 const IndexRangeArray& innerIndices,
143 Projection projection);
144
146 Polygon m_outer;
147
149 std::vector<Polygon> m_inner;
150 };
151
152} // namespace meshkernel
153
155{
156 return m_outer;
157}
158
160{
161 return static_cast<UInt>(m_inner.size());
162}
163
165{
166 return m_inner[i];
167}
A class containing the land boundary polylines.
Definition LandBoundary.hpp:40
A struct describing a point in a two-dimensional space.
Definition Point.hpp:41
A closed polygon.
Definition Polygon.hpp:46
A region enclosed by a polygonal permieter.
Definition PolygonalEnclosure.hpp:46
void SnapToLandBoundary(size_t startIndex, size_t endIndex, const LandBoundary &landBoundary)
Snap all or part of the outer perimeter polygon to the land boundary.
UInt NumberOfInner() const
The number of inner hole regions.
Definition PolygonalEnclosure.hpp:159
bool Contains(const Point &pnt) const
Determine if the point lies in the polygon.
std::vector< Point > LinearRefine(UInt startIndex, UInt endIndex) const
Linear refine the outer polygon.
UInt GetNumberOfNodes() const
Get the number of nodes in the enclosure, both outer and all inner polygons.
std::tuple< std::unique_ptr< PolygonalEnclosure >, std::unique_ptr< PolygonalEnclosure > > OffsetCopy(double distance, bool outwardsAndInwards) const
Makes a new polygonal enclosure from an existing one, by offsetting it by a distance (copypol)
Region
The part of the enclosure a point is found.
Definition PolygonalEnclosure.hpp:50
@ None
The point is not contained with the enclosure.
@ Exterior
The point is contained within the outer perimeter of the enclosure.
@ Interior
The point is contained within one of the island, interior perimeters of the enclosure.
const Polygon & Outer() const
The outer perimeter polygon.
Definition PolygonalEnclosure.hpp:154
std::vector< Point > Refine(UInt startIndex, UInt endIndex, double refinementDistance) const
Refine the polygon.
UInt NumberOfPoints(const bool includeInterior) const
Get the number of points making up the polygon, including interior if requested.
PolygonalEnclosure(const std::vector< Point > &points, Projection projection)
Constructor.
Region ContainsRegion(const Point &pnt) const
Determine in which part of the enclosure the point is.
const Polygon & Inner(size_t i) const
Get an inner polygon.
Definition PolygonalEnclosure.hpp:164
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
Projection
Enumerator describing the supported projections.
Definition Definitions.hpp:43
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition Definitions.hpp:39