MeshKernel
LandBoundaries.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 <memory>
31 
32 #include <MeshKernel/Entities.hpp>
33 #include <MeshKernel/LandBoundary.hpp>
34 #include <MeshKernel/UndoActions/UndoAction.hpp>
35 
36 #include <memory>
37 
38 namespace meshkernel
39 {
40  class Polygons;
41  class Mesh2D;
42 
50  {
51 
52  public:
55  {
56  DoNotProjectToLandBoundary = 0,
57  ToOriginalNetBoundary = 1,
58  OuterMeshBoundaryToLandBoundary = 2,
59  InnerAndOuterMeshBoundaryToLandBoundary = 3,
60  WholeMesh = 4
61  };
62 
64  LandBoundaries() = default;
65 
70  LandBoundaries(const std::vector<Point>& landBoundary,
71  Mesh2D& mesh,
72  const Polygons& polygons);
73 
80  void Administrate();
81 
84  void FindNearestMeshBoundary(ProjectToLandBoundaryOption projectToLandBoundaryOption);
85 
87  [[nodiscard]] std::unique_ptr<UndoAction> SnapMeshToLandBoundaries() const;
88 
91  auto GetNumNodes() const { return m_landBoundary.GetNumNodes(); }
92 
93  std::vector<UInt> m_meshNodesLandBoundarySegments;
94 
95  private:
101  void AssignLandBoundaryPolylineToMeshNodes(UInt edgeIndex,
102  bool initialize,
103  std::vector<UInt>& nodes,
104  UInt numNodes);
105 
110  void AddLandBoundary(const std::vector<UInt>& nodesLoc,
111  UInt numNodesLoc,
112  UInt nodeIndex);
113 
119  std::tuple<UInt, UInt> MakePath(UInt landBoundaryIndex);
120 
123  void ComputeMeshNodeMask(UInt landBoundaryIndex);
124 
136  void ComputeMask(UInt segmentIndex,
137  bool meshBoundOnly,
138  UInt startLandBoundaryIndex,
139  UInt endLandBoundaryIndex,
140  UInt& leftIndex,
141  UInt& rightIndex,
142  double& leftEdgeRatio,
143  double& rightEdgeRatio);
144 
148  void MaskMeshFaceMask(UInt landBoundaryIndex, const std::vector<UInt>& initialFaces);
149 
154  [[nodiscard]] UInt IsMeshEdgeCloseToLandBoundaries(UInt landBoundaryIndex, UInt edge);
155 
162  std::tuple<UInt, UInt> FindStartEndMeshNodesDijkstraAlgorithm(UInt landBoundaryIndex);
163 
169  UInt FindStartEndMeshNodesFromEdges(UInt edge, Point point) const;
170 
175  std::vector<UInt> ShortestPath(UInt landBoundaryIndex, UInt startMeshNode);
176 
182  std::tuple<double, Point, UInt, double> NearestLandBoundarySegment(UInt landBoundaryIndex, const Point& node) const;
183 
184  Mesh2D& m_mesh;
185  const Polygons m_polygons;
186  LandBoundary m_landBoundary;
187  std::vector<Point> m_polygonNodesCache;
188  std::vector<std::pair<UInt, UInt>> m_validLandBoundaries;
189  std::vector<UInt> m_nodeFaceIndices;
190 
191  std::vector<UInt> m_nodeMask;
192  std::vector<bool> m_faceMask;
193  std::vector<UInt> m_edgeMask;
194 
195  bool m_landMask = true;
196  bool m_addLandboundaries = true;
197 
198  // caches
199  std::vector<double> m_nodesMinDistances;
200 
201  // Parameters
202  const double m_closeToLandBoundaryFactor = 5.0;
203  const double m_closeWholeMeshFactor = 1.0;
204  const double m_minDistanceFromLandFactor = 2.0;
205 
206  // findOnlyOuterMeshBoundary
207  bool m_findOnlyOuterMeshBoundary = false;
208  };
209 
210 } // namespace meshkernel
meshkernel::LandBoundaries::LandBoundaries
LandBoundaries()=default
Default constructor.
meshkernel::LandBoundaries::FindNearestMeshBoundary
void FindNearestMeshBoundary(ProjectToLandBoundaryOption projectToLandBoundaryOption)
Find the mesh boundary line closest to the land boundary (find_nearest_meshline).
meshkernel::Mesh2D
A class derived from Mesh, which describes unstructures 2d meshes.
Definition: Mesh2D.hpp:55
meshkernel::LandBoundaries::ProjectToLandBoundaryOption
ProjectToLandBoundaryOption
Enumerator describing the options how to project to the land boundary.
Definition: LandBoundaries.hpp:54
meshkernel::Point
A struct describing a point in a two-dimensional space.
Definition: Point.hpp:40
meshkernel::LandBoundary
A class containing the land boundary polylines.
Definition: LandBoundary.hpp:39
meshkernel::LandBoundary::GetNumNodes
size_t GetNumNodes() const
Gets the number of land boundary nodes.
Definition: LandBoundary.hpp:94
meshkernel::LandBoundaries::m_meshNodesLandBoundarySegments
std::vector< UInt > m_meshNodesLandBoundarySegments
Mesh nodes to land boundary mapping (lanseg_map)
Definition: LandBoundaries.hpp:93
meshkernel
Contains the logic of the C++ static library.
Definition: AveragingInterpolation.hpp:36
meshkernel::UInt
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition: Definitions.hpp:38
meshkernel::Polygons
A class containing a list of polygonaly enclosed regions.
Definition: Polygons.hpp:44
meshkernel::LandBoundaries
A class describing land boundaries. These are used to visualise the land-water interface.
Definition: LandBoundaries.hpp:49
meshkernel::LandBoundaries::Administrate
void Administrate()
The portion of the boundary segments close enough to the mesh boundary are flagged (admin_landboundar...
meshkernel::LandBoundaries::GetNumNodes
auto GetNumNodes() const
Gets the number of land boundary nodes.
Definition: LandBoundaries.hpp:91
meshkernel::LandBoundaries::SnapMeshToLandBoundaries
std::unique_ptr< UndoAction > SnapMeshToLandBoundaries() const
Snap the mesh nodes to land boundaries (snap_to_landboundary)