Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
Polygon.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 <vector>
31
32#include "MeshKernel/BoundingBox.hpp"
33#include "MeshKernel/Definitions.hpp"
34#include "MeshKernel/Point.hpp"
35
36namespace meshkernel
37{
38
40 class LandBoundary;
41
45 class Polygon
46 {
47 public:
49 Polygon() = default;
50
52 Polygon(const Polygon& copy) = default;
53
55 Polygon(Polygon&& copy) = default;
56
58 Polygon(const std::vector<Point>& points,
59 Projection projection);
60
63 Polygon(std::vector<Point>&& points,
64 Projection projection);
65
67 void Reset(const std::vector<Point>& points,
68 Projection projection);
69
71 Polygon& operator=(const Polygon& copy);
72
75
77 UInt Size() const;
78
80 const std::vector<Point>& Nodes() const;
81
83 Point& Node(const size_t i);
84
86 const Point& Node(const size_t i) const;
87
89 const BoundingBox& GetBoundingBox() const;
90
92 bool Contains(const Point& point) const;
93
97 void SnapToLandBoundary(const size_t startIndex, const size_t endIndex, const LandBoundary& boundary);
98
104 std::vector<Point> Refine(UInt startIndex, UInt endIndex, double refinementDistance) const;
105
108 std::vector<Point> LinearRefine(UInt startIndex, UInt endIndex) const;
109
111 std::tuple<double, Point, TraversalDirection> FaceAreaAndCenterOfMass() const;
112
114 static std::tuple<double, Point, TraversalDirection> FaceAreaAndCenterOfMass(const std::vector<Point>& polygon, const Projection projection);
115
120 static std::tuple<double, Point, TraversalDirection> FaceAreaAndCenterOfMass(const std::vector<Point>& nodes,
121 const std::vector<UInt>& nodeIndices,
122 const Projection projection,
123 bool isClosed);
124
126 double PerimeterLength() const;
127
130 std::vector<double> EdgeLengths() const;
131
133 std::vector<Point> ComputeOffset(double displacement, const bool innerAndOuter) const;
134
137
138 private:
146 static void RefineSegment(std::vector<meshkernel::Point>& refinedPolygon,
147 const std::vector<meshkernel::Point>::const_iterator& nodeIterator,
148 const double refinementDistance,
149 const meshkernel::Projection projection);
150
152 static void computeAverageLengths(const std::vector<double>& cumulativeDistances, std::vector<double>& averageDistances);
153
155 static void smoothCumulativeDistance(const std::vector<double>& averageDistances, std::vector<double>& cumulativeDistances);
156
158 static void smoothAverageLengths(const std::vector<double>& cumulativeDistances,
159 const double firstDistance,
160 const double lastDistance,
161 std::vector<double>& averageLengths);
162
164 void GetPolygonNodes(const UInt startIndex,
165 const UInt endIndex,
166 std::vector<Point>& polygonNodes) const;
167
169 std::vector<double> ComputeCumulativeDistances(const std::vector<meshkernel::Point>& polygonNodes) const;
170
172 void ComputeResampledNodes(const size_t numberOfNewNodes,
173 const std::vector<double>& segmentLengths,
174 const std::vector<size_t>& nodeIndices,
175 std::vector<Point>& refinedPolygon) const;
176
178 std::tuple<meshkernel::UInt, meshkernel::UInt>
179 FindMinMaxRatioIndex(const std::vector<double>& averageLengths,
180 const std::vector<double>& actualAverageLengths) const;
181
183 static meshkernel::Point interpolatePointOnPolyline(const std::vector<meshkernel::Point>& points,
184 const std::vector<double>& cumulativeDistances,
185 const double pointDistance);
186
188 void Initialise();
189
193 bool ContainsCartesian(const Point& point) const;
194
196 bool ContainsSphericalAccurate(const Point& point) const;
197
199 std::vector<Point> m_nodes;
200
202 Projection m_projection = Projection::cartesian;
203
205 BoundingBox m_boundingBox;
206 };
207
208} // namespace meshkernel
209
211{
212 return static_cast<UInt>(m_nodes.size());
213}
214
215inline const std::vector<meshkernel::Point>& meshkernel::Polygon::Nodes() const
216{
217 return m_nodes;
218}
219
221{
222 return m_nodes[i];
223}
224
225inline const meshkernel::Point& meshkernel::Polygon::Node(const size_t i) const
226{
227 return m_nodes[i];
228}
229
231{
232 return m_boundingBox;
233}
234
236{
237 return m_projection;
238}
A class defining a bounding box.
Definition BoundingBox.hpp:40
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
Polygon(std::vector< Point > &&points, Projection projection)
Constructor.
Point & Node(const size_t i)
Return single point at position.
Definition Polygon.hpp:220
static std::tuple< double, Point, TraversalDirection > FaceAreaAndCenterOfMass(const std::vector< Point > &nodes, const std::vector< UInt > &nodeIndices, const Projection projection, bool isClosed)
Compute the area of the polygon, its centre of mass and the direction.
void Reset(const std::vector< Point > &points, Projection projection)
Reset the polygon.
void SnapToLandBoundary(const size_t startIndex, const size_t endIndex, const LandBoundary &boundary)
Snap the section of the polygon defined by start- and end-index to the land boundary.
Polygon(Polygon &&copy)=default
Default move constructor.
std::tuple< double, Point, TraversalDirection > FaceAreaAndCenterOfMass() const
Compute the area of the polygon, its centre of mass and the direction.
Polygon(const std::vector< Point > &points, Projection projection)
Constructor.
Polygon(const Polygon &copy)=default
Default copy constructor.
Polygon & operator=(Polygon &&copy)
Move assignment operator.
const BoundingBox & GetBoundingBox() const
Get the bounding box of the polygon.
Definition Polygon.hpp:230
Projection GetProjection() const
Get the projection used.
Definition Polygon.hpp:235
std::vector< Point > ComputeOffset(double displacement, const bool innerAndOuter) const
Compute the poygon offset.
std::vector< Point > Refine(UInt startIndex, UInt endIndex, double refinementDistance) const
Refine the polygon.
UInt Size() const
Return the number of points in the polygon.
Definition Polygon.hpp:210
const std::vector< Point > & Nodes() const
Return vector of nodes of the polygon.
Definition Polygon.hpp:215
Polygon & operator=(const Polygon &copy)
Copy assignment operator.
std::vector< double > EdgeLengths() const
Computes the edge lengths of the polygon.
bool Contains(const Point &point) const
Determine if the polygon contains the point.
static std::tuple< double, Point, TraversalDirection > FaceAreaAndCenterOfMass(const std::vector< Point > &polygon, const Projection projection)
Compute the area of the polygon, its centre of mass and the direction.
std::vector< Point > LinearRefine(UInt startIndex, UInt endIndex) const
Refine the polygon.
double PerimeterLength() const
Compute the perimiter length of the closed polygon.
Polygon()=default
Default constructor.
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