MeshKernel
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 
38 namespace meshkernel
39 {
40 
46  {
47  public:
49  enum class Region
50  {
51  None,
52  Exterior,
53  Interior
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 
71  UInt GetNumberOfNodes() const;
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 }
meshkernel::Projection
Projection
Enumerator describing the supported projections.
Definition: Definitions.hpp:41
meshkernel::PolygonalEnclosure::PolygonalEnclosure
PolygonalEnclosure(const std::vector< Point > &points, Projection projection)
Constructor.
meshkernel::PolygonalEnclosure::Inner
const Polygon & Inner(size_t i) const
Get an inner polygon.
Definition: PolygonalEnclosure.hpp:164
meshkernel::PolygonalEnclosure::Region::Interior
@ Interior
The point is contained within one of the island, interior perimeters of the enclosure.
meshkernel::Point
A struct describing a point in a two-dimensional space.
Definition: Point.hpp:40
meshkernel::PolygonalEnclosure::Contains
bool Contains(const Point &pnt) const
Determine if the point lies in the polygon.
meshkernel::LandBoundary
A class containing the land boundary polylines.
Definition: LandBoundary.hpp:39
meshkernel::Polygon
A closed polygon.
Definition: Polygon.hpp:45
meshkernel::PolygonalEnclosure::NumberOfInner
UInt NumberOfInner() const
The number of inner hole regions.
Definition: PolygonalEnclosure.hpp:159
meshkernel::PolygonalEnclosure::LinearRefine
std::vector< Point > LinearRefine(UInt startIndex, UInt endIndex) const
Linear refine the outer polygon.
meshkernel::PolygonalEnclosure::GetNumberOfNodes
UInt GetNumberOfNodes() const
Get the number of nodes in the enclosure, both outer and all inner polygons.
meshkernel::PolygonalEnclosure::OffsetCopy
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)
meshkernel
Contains the logic of the C++ static library.
Definition: AveragingInterpolation.hpp:36
meshkernel::PolygonalEnclosure
A region enclosed by a polygonal permieter.
Definition: PolygonalEnclosure.hpp:45
meshkernel::UInt
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition: Definitions.hpp:38
meshkernel::PolygonalEnclosure::ContainsRegion
Region ContainsRegion(const Point &pnt) const
Determine in which part of the enclosure the point is.
meshkernel::PolygonalEnclosure::Region
Region
The part of the enclosure a point is found.
Definition: PolygonalEnclosure.hpp:49
meshkernel::PolygonalEnclosure::Refine
std::vector< Point > Refine(UInt startIndex, UInt endIndex, double refinementDistance) const
Refine the polygon.
meshkernel::PolygonalEnclosure::NumberOfPoints
UInt NumberOfPoints(const bool includeInterior) const
Get the number of points making up the polygon, including interior if requested.
meshkernel::PolygonalEnclosure::Outer
const Polygon & Outer() const
The outer perimeter polygon.
Definition: PolygonalEnclosure.hpp:154
meshkernel::PolygonalEnclosure::SnapToLandBoundary
void SnapToLandBoundary(size_t startIndex, size_t endIndex, const LandBoundary &landBoundary)
Snap all or part of the outer perimeter polygon to the land boundary.
meshkernel::PolygonalEnclosure::Region::Exterior
@ Exterior
The point is contained within the outer perimeter of the enclosure.
meshkernel::PolygonalEnclosure::Region::None
@ None
The point is not contained with the enclosure.