Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
Polygons.hpp
1//---- GPL ---------------------------------------------------------------------
2//
3// Copyright (C) Stichting Deltares, 2011-2021.
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 <vector>
31
32#include <MeshKernel/BoundingBox.hpp>
33#include <MeshKernel/Exceptions.hpp>
34#include <MeshKernel/Polygon.hpp>
35#include <MeshKernel/PolygonalEnclosure.hpp>
36
37namespace meshkernel
38{
39
41 class LandBoundary;
42
45 {
46 public:
48 Polygons() = default;
49
53 Polygons(const std::vector<Point>& polygon,
54 Projection projection);
55
57 // This is bollocks
58 // what about nodes for the interior polygons
59 std::tuple<UInt, UInt, UInt> PolygonIndex(UInt startIndex, UInt endIndex) const;
60
63 const PolygonalEnclosure& Enclosure(const UInt index) const;
64
67 [[nodiscard]] std::vector<std::vector<Point>> ComputePointsInPolygons() const;
68
74 [[nodiscard]] std::vector<Point> RefineFirstPolygon(UInt startIndex, UInt endIndex, double refinementDistance) const;
75
82 [[nodiscard]] std::vector<Point> RefinePolygon(UInt polygonIndex, UInt startIndex, UInt endIndex, double refinementDistance) const;
83
89 [[nodiscard]] std::vector<Point> LinearRefinePolygon(UInt polygonIndex, UInt startIndex, UInt endIndex) const;
90
95 [[nodiscard]] Polygons OffsetCopy(double distance, bool innerAndOuter) const;
96
103 void SnapToLandBoundary(const LandBoundary& landBoundary, UInt startIndex, UInt endIndex);
104
110 [[nodiscard]] bool IsPointInPolygon(Point const& point, UInt polygonIndex) const;
111
115 [[nodiscard]] bool IsPointInAnyPolygon(const Point& point) const;
116
117 // TODO can reduce the result of this function to only a UInt (valid value => found, invalid => not found)
121 [[nodiscard]] std::tuple<bool, UInt> IsPointInPolygons(const Point& point) const;
122
126 [[nodiscard]] std::vector<bool> PointsInPolygons(const std::vector<Point>& point) const;
127
130 [[nodiscard]] bool IsEmpty() const;
131
132 // TODO rename to NumberOfEnclosures or something like that
135 [[nodiscard]] UInt GetNumPolygons() const;
136
139 [[nodiscard]] UInt GetNumNodes() const;
140
143 [[nodiscard]] Projection GetProjection() const { return m_projection; }
144
146 [[nodiscard]] std::vector<Point> GatherAllEnclosureNodes() const;
147
151 [[nodiscard]] BoundingBox GetBoundingBox(UInt polygonIndex) const;
152
153 private:
157 double PerimeterClosedPolygon(const std::vector<Point>& polygonNodes) const;
158
162 std::vector<double> PolygonEdgeLengths(const std::vector<Point>& polygonNodes) const;
163
164 std::vector<PolygonalEnclosure> m_enclosures;
165 Projection m_projection;
166 std::vector<std::pair<UInt, UInt>> m_outer_polygons_indices;
167 UInt m_numberOfNodes = 0;
168 };
169} // namespace meshkernel
170
172{
173 if (IsEmpty())
174 {
175 throw ConstraintError("Enclosures list is empty.");
176 }
177
178 if (index >= m_enclosures.size())
179 {
180 throw ConstraintError("Invalid enclosure index: {}, maximum index: {}", index, m_enclosures.size() - 1);
181 }
182
183 return m_enclosures[index];
184}
185
187{
188 return static_cast<UInt>(m_enclosures.size());
189}
190
192{
193 return m_numberOfNodes;
194}
A class defining a bounding box.
Definition BoundingBox.hpp:40
An exception class thrown when an attempt is made that violates a range constraint.
Definition Exceptions.hpp:267
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 region enclosed by a polygonal permieter.
Definition PolygonalEnclosure.hpp:46
A class containing a list of polygonaly enclosed regions.
Definition Polygons.hpp:45
std::tuple< bool, UInt > IsPointInPolygons(const Point &point) const
Checks if a point is included in any of the polygons (dbpinpol_optinside_perpol)
Polygons(const std::vector< Point > &polygon, Projection projection)
Constructor.
Polygons OffsetCopy(double distance, bool innerAndOuter) const
Makes a new polygon from an existing one, by offsetting it by a distance (copypol)
Polygons()=default
Default constructor.
const PolygonalEnclosure & Enclosure(const UInt index) const
Get the polygonal enclosure at the index.
Definition Polygons.hpp:171
bool IsPointInPolygon(Point const &point, UInt polygonIndex) const
Checks if a point is included in a given polygon. When the polygon is empty, the point is always incl...
UInt GetNumNodes() const
Gets the number of polygon nodes.
Definition Polygons.hpp:191
void SnapToLandBoundary(const LandBoundary &landBoundary, UInt startIndex, UInt endIndex)
Snap the polygon to the land boundary.
std::vector< bool > PointsInPolygons(const std::vector< Point > &point) const
For each point, compute the index of the polygon including it.
std::tuple< UInt, UInt, UInt > PolygonIndex(UInt startIndex, UInt endIndex) const
Get index of the polygon, and map the start- and end-index to the start- and end-index of the local p...
Projection GetProjection() const
Gets the projection.
Definition Polygons.hpp:143
UInt GetNumPolygons() const
Gives the number of polygons.
Definition Polygons.hpp:186
std::vector< std::vector< Point > > ComputePointsInPolygons() const
Creates points inside the polygon using triangulation (the edges size determines how many points will...
bool IsPointInAnyPolygon(const Point &point) const
Checks if a point is included in any of the polygonal enclosures contained.
std::vector< Point > LinearRefinePolygon(UInt polygonIndex, UInt startIndex, UInt endIndex) const
Linear refines the polygon edges with additional nodes, from the start to the end index.
std::vector< Point > RefinePolygon(UInt polygonIndex, UInt startIndex, UInt endIndex, double refinementDistance) const
Refines the polygon edges with additional nodes, from the start to the end index (refinepolygonpart)
BoundingBox GetBoundingBox(UInt polygonIndex) const
Gets the bounding box for the polygon index i.
bool IsEmpty() const
Checks if the polygon is empty.
std::vector< Point > GatherAllEnclosureNodes() const
Gets the nodes of all enclosures.
std::vector< Point > RefineFirstPolygon(UInt startIndex, UInt endIndex, double refinementDistance) const
Refines the polygon edges with additional nodes, from the start to the end index (refinepolygonpart)
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