diff --git a/libs/MeshKernel/CMakeLists.txt b/libs/MeshKernel/CMakeLists.txt index 5faf05ebb7..3d88a01e0c 100644 --- a/libs/MeshKernel/CMakeLists.txt +++ b/libs/MeshKernel/CMakeLists.txt @@ -41,7 +41,6 @@ set( ${SRC_DIR}/Entities.cpp ${SRC_DIR}/FlipEdges.cpp ${SRC_DIR}/Hessian.cpp - ${SRC_DIR}/LandBoundaries.cpp ${SRC_DIR}/LandBoundary.cpp ${SRC_DIR}/Mesh.cpp ${SRC_DIR}/Mesh1D.cpp @@ -60,6 +59,7 @@ set( ${SRC_DIR}/RemoveDisconnectedRegions.cpp ${SRC_DIR}/SamplesHessianCalculator.cpp ${SRC_DIR}/Smoother.cpp + ${SRC_DIR}/SnappingMesh2DToLandBoundariesCalculator.cpp ${SRC_DIR}/SplineAlgorithms.cpp ${SRC_DIR}/Splines.cpp ${SRC_DIR}/SplitRowColumnOfMesh.cpp @@ -158,7 +158,6 @@ set( ${DOMAIN_INC_DIR}/FlipEdges.hpp ${DOMAIN_INC_DIR}/Formatting.hpp ${DOMAIN_INC_DIR}/Hessian.hpp - ${DOMAIN_INC_DIR}/LandBoundaries.hpp ${DOMAIN_INC_DIR}/LandBoundary.hpp ${DOMAIN_INC_DIR}/Mesh.hpp ${DOMAIN_INC_DIR}/Mesh1D.hpp @@ -184,6 +183,7 @@ set( ${DOMAIN_INC_DIR}/RemoveDisconnectedRegions.hpp ${DOMAIN_INC_DIR}/SamplesHessianCalculator.hpp ${DOMAIN_INC_DIR}/Smoother.hpp + ${DOMAIN_INC_DIR}/SnappingMesh2DToLandBoundariesCalculator.hpp ${DOMAIN_INC_DIR}/SplineAlgorithms.hpp ${DOMAIN_INC_DIR}/Splines.hpp ${DOMAIN_INC_DIR}/SplitRowColumnOfMesh.hpp diff --git a/libs/MeshKernel/include/MeshKernel/FlipEdges.hpp b/libs/MeshKernel/include/MeshKernel/FlipEdges.hpp index eec027f7e0..2e1526ea1d 100644 --- a/libs/MeshKernel/include/MeshKernel/FlipEdges.hpp +++ b/libs/MeshKernel/include/MeshKernel/FlipEdges.hpp @@ -36,7 +36,7 @@ namespace meshkernel { // Forward declarations class Mesh2D; - class LandBoundaries; + class SnappingMesh2DToLandBoundariesCalculator; /// @brief A class used to improve mesh connectivity. /// @@ -53,7 +53,7 @@ namespace meshkernel /// @param[in] triangulateFaces Whether to triangulate all faces or not /// @param[in] projectToLandBoundary Whether to project to land boundaries or not FlipEdges(Mesh2D& mesh, - LandBoundaries& landBoundary, + SnappingMesh2DToLandBoundariesCalculator& landBoundary, bool triangulateFaces, bool projectToLandBoundary); @@ -85,8 +85,8 @@ namespace meshkernel /// @param[in] nodeIndex The index of the node to process void DeleteEdgeFromNode(UInt edgeIndex, UInt nodeIndex) const; - Mesh2D& m_mesh; ///< A pointer to the 2D mesh - LandBoundaries& m_landBoundaries; ///< A pointer to the land boundaries + Mesh2D& m_mesh; ///< A pointer to the 2D mesh + SnappingMesh2DToLandBoundariesCalculator& m_snappingToLandBoundariesCalculator; ///< A pointer to the land boundaries bool m_triangulateFaces = false; ///< Whether to triangulate faces bool m_projectToLandBoundary = false; ///< Whether to project to land boundary diff --git a/libs/MeshKernel/include/MeshKernel/OrthogonalizationAndSmoothing.hpp b/libs/MeshKernel/include/MeshKernel/OrthogonalizationAndSmoothing.hpp index f6deee473e..7cdcebc2f2 100644 --- a/libs/MeshKernel/include/MeshKernel/OrthogonalizationAndSmoothing.hpp +++ b/libs/MeshKernel/include/MeshKernel/OrthogonalizationAndSmoothing.hpp @@ -27,7 +27,7 @@ #pragma once -#include +#include #include #include @@ -55,7 +55,7 @@ namespace meshkernel /// /// - An initialization step: The original mesh boundaries are saved. In /// case the mesh needs to be snapped to the land boundaries, the indices of the land boundaries - /// are mapped to the boundary mesh edges (`LandBoundaries::FindNearestMeshBoundary`). + /// are mapped to the boundary mesh edges (`SnappingMesh2DToLandBoundariesCalculator::FindNearestMeshBoundary`). /// /// - An outer loop, which itself is composed of the following parts: /// @@ -94,8 +94,8 @@ namespace meshkernel std::unique_ptr smoother, std::unique_ptr orthogonalizer, std::unique_ptr polygon, - std::unique_ptr landBoundaries, - LandBoundaries::ProjectToLandBoundaryOption projectToLandBoundaryOption, + std::unique_ptr landBoundaries, + SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions projectToLandBoundaryOption, const OrthogonalizationParameters& orthogonalizationParameters); /// @brief Initializes the object @@ -140,13 +140,13 @@ namespace meshkernel /// @brief Compute nodes local coordinates (comp_local_coords) void ComputeCoordinates() const; - Mesh2D& m_mesh; ///< A reference to mesh - std::unique_ptr m_smoother; ///< A pointer to the smoother - std::unique_ptr m_orthogonalizer; ///< A pointer to the orthogonalizer - std::unique_ptr m_polygons; ///< The polygon pointer where to perform the orthogonalization - std::unique_ptr m_landBoundaries; ///< The land boundaries pointer - LandBoundaries::ProjectToLandBoundaryOption m_projectToLandBoundaryOption; ///< The project to land boundary option - OrthogonalizationParameters m_orthogonalizationParameters; ///< The orthogonalization parameters + Mesh2D& m_mesh; ///< A reference to mesh + std::unique_ptr m_smoother; ///< A pointer to the smoother + std::unique_ptr m_orthogonalizer; ///< A pointer to the orthogonalizer + std::unique_ptr m_polygons; ///< The polygon pointer where to perform the orthogonalization + std::unique_ptr m_snappingToLandBoundariesCalculator; ///< The land boundaries pointer + SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions m_projectOptions; ///< The projection options + OrthogonalizationParameters m_orthogonalizationParameters; ///< The orthogonalization parameters std::vector m_localCoordinatesIndices; ///< Used in sphericalAccurate projection (iloc) std::vector m_localCoordinates; ///< Used in sphericalAccurate projection (xloc,yloc) diff --git a/libs/MeshKernel/include/MeshKernel/LandBoundaries.hpp b/libs/MeshKernel/include/MeshKernel/SnappingMesh2DToLandBoundariesCalculator.hpp similarity index 78% rename from libs/MeshKernel/include/MeshKernel/LandBoundaries.hpp rename to libs/MeshKernel/include/MeshKernel/SnappingMesh2DToLandBoundariesCalculator.hpp index 8e90b4eeb3..0c256f7e61 100644 --- a/libs/MeshKernel/include/MeshKernel/LandBoundaries.hpp +++ b/libs/MeshKernel/include/MeshKernel/SnappingMesh2DToLandBoundariesCalculator.hpp @@ -29,7 +29,6 @@ #include -#include #include #include @@ -40,37 +39,53 @@ namespace meshkernel class Polygons; class Mesh2D; - /// @brief A class describing land boundaries. + /// @brief A class implementing the snapping mesh to land boundaries algorithm /// These are used to visualise the land-water interface. /// /// The main responsibility of this class is to store the land boundary polygons, /// categorize them based on their proximity to a mesh /// and provide the functionality to assign each mesh node to the appropriate land boundary polyline. - class LandBoundaries + class SnappingMesh2DToLandBoundariesCalculator { public: - /// Enumerator describing the options how to project to the land boundary - enum class ProjectToLandBoundaryOption + /// Enumerator describing the options how to project + enum class ProjectionsOptions { - DoNotProjectToLandBoundary = 0, - ToOriginalNetBoundary = 1, - OuterMeshBoundaryToLandBoundary = 2, - InnerAndOuterMeshBoundaryToLandBoundary = 3, - WholeMesh = 4 + DoNotProject = 0, + ToOriginalMeshBoundary = 1, + OuterMeshBoundaryToLandBoundaries = 2, + InnerAndOuterMeshBoundariesToLandboundaries = 3 }; /// @brief Default constructor - LandBoundaries() = default; + SnappingMesh2DToLandBoundariesCalculator() = default; /// @brief Default constructor /// @param[in] landBoundary A vector of points defining the land boundary. /// @param[in] mesh The current 2d mesh. /// @param[in] polygons A polygon for selecting part of the land boundaries. - LandBoundaries(const std::vector& landBoundary, - Mesh2D& mesh, - const Polygons& polygons); + SnappingMesh2DToLandBoundariesCalculator(const std::vector& landBoundary, + Mesh2D& mesh, + const Polygons& polygons); + /// @brief Find the mesh boundary line closest to the land boundary (find_nearest_meshline). + /// @param[in] projectionOption The option describing the projection to the land boundary. + void FindNearestMeshBoundary(ProjectionsOptions projectionOption); + + /// @brief Snap the mesh nodes to land boundaries (snap_to_landboundary) + [[nodiscard]] std::unique_ptr ComputeSnapping() const; + + /// @brief Gets the land boundary segment index for each mesh node + /// @param[in] node The mesh node index + /// @returns The land boundary segment index + UInt LandBoundarySegmentIndex(UInt node) const { return m_meshNodesLandBoundarySegments[node]; } + + /// @brief Get the land boundary used by the calculator + /// @returns A reference to the land boundary used by the calculator + const LandBoundary& LandBoundary() const { return m_landBoundary; } + + private: /// @brief The portion of the boundary segments close enough to the mesh boundary are flagged (admin_landboundary_segments) /// /// This method uses a Point vector member variable and identifies @@ -79,20 +94,6 @@ namespace meshkernel /// \image html LandBoundarySegmentation_step1.jpg "Land boundary segmentation" void Administrate(); - /// @brief Find the mesh boundary line closest to the land boundary (find_nearest_meshline). - /// @param[in] projectToLandBoundaryOption The option describing the projection to the land boundary. - void FindNearestMeshBoundary(ProjectToLandBoundaryOption projectToLandBoundaryOption); - - /// @brief Snap the mesh nodes to land boundaries (snap_to_landboundary) - [[nodiscard]] std::unique_ptr SnapMeshToLandBoundaries() const; - - /// @brief Gets the number of land boundary nodes. - /// @return The number of land boundary nodes. - auto GetNumNodes() const { return m_landBoundary.GetNumNodes(); } - - std::vector m_meshNodesLandBoundarySegments; ///< Mesh nodes to land boundary mapping (lanseg_map) - - private: /// @brief Build an additional boundary for not assigned nodes (connect_boundary_paths) /// @param[in] edgeIndex /// @param[in] initialize @@ -122,26 +123,6 @@ namespace meshkernel /// @param[in] landBoundaryIndex The land boundary polyline index void ComputeMeshNodeMask(UInt landBoundaryIndex); - /// @brief Mask the mesh nodes to be considered in the shortest path algorithm for the current segmentIndex. - /// It is setting leftIndex, rightIndex, leftEdgeRatio, rightEdgeRatio (masknodes). - //// \image html LandBoundaryNodeFlagging_step2.jpg "Flag the mesh node close to the land boundary" - /// @param[in] segmentIndex - /// @param[in] meshBoundOnly - /// @param[in] startLandBoundaryIndex - /// @param[in] endLandBoundaryIndex - /// @param[out] leftIndex - /// @param[out] rightIndex - /// @param[out] leftEdgeRatio - /// @param[out] rightEdgeRatio - void ComputeMask(UInt segmentIndex, - bool meshBoundOnly, - UInt startLandBoundaryIndex, - UInt endLandBoundaryIndex, - UInt& leftIndex, - UInt& rightIndex, - double& leftEdgeRatio, - double& rightEdgeRatio); - /// @brief Mask all face close to a land boundary, starting from a seed of others and growing from there (maskcells) /// @param[in] landBoundaryIndex The land boundary polyline index /// @param[in] initialFaces The initial face seeds @@ -183,7 +164,8 @@ namespace meshkernel Mesh2D& m_mesh; ///< A reference to mesh const Polygons m_polygons; ///< A copy of the polygons - LandBoundary m_landBoundary; ///< The nodes on the land boundary + meshkernel::LandBoundary m_landBoundary; ///< A copy of the land boundary + std::vector m_meshNodesLandBoundarySegments; ///< Mesh nodes to land boundary segments (lanseg_map) std::vector m_polygonNodesCache; ///< Array of points (e.g. points of a face) std::vector> m_validLandBoundaries; ///< Start and end indices of valid land boundaries (lanseg_startend) std::vector m_nodeFaceIndices; ///< For each node, the indices of the faces including them diff --git a/libs/MeshKernel/src/FlipEdges.cpp b/libs/MeshKernel/src/FlipEdges.cpp index 7657b382d9..eca601723b 100644 --- a/libs/MeshKernel/src/FlipEdges.cpp +++ b/libs/MeshKernel/src/FlipEdges.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -38,16 +38,16 @@ using meshkernel::FlipEdges; using meshkernel::Mesh2D; FlipEdges::FlipEdges(Mesh2D& mesh, - LandBoundaries& landBoundary, + SnappingMesh2DToLandBoundariesCalculator& landBoundary, bool triangulateFaces, bool projectToLandBoundary) : m_mesh(mesh), - m_landBoundaries(landBoundary), + m_snappingToLandBoundariesCalculator(landBoundary), m_triangulateFaces(triangulateFaces), m_projectToLandBoundary(projectToLandBoundary) { if (m_projectToLandBoundary) { - m_landBoundaries.FindNearestMeshBoundary(LandBoundaries::ProjectToLandBoundaryOption::WholeMesh); + m_snappingToLandBoundariesCalculator.FindNearestMeshBoundary(SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::OuterMeshBoundaryToLandBoundaries); } } @@ -353,9 +353,9 @@ int FlipEdges::ComputeTopologyFunctional(UInt edge, auto nL = static_cast(m_mesh.m_nodesNumEdges[nodeLeft]) - static_cast(OptimalNumberOfConnectedNodes(nodeLeft)); auto nR = static_cast(m_mesh.m_nodesNumEdges[nodeRight]) - static_cast(OptimalNumberOfConnectedNodes(nodeRight)); - if (m_projectToLandBoundary && m_landBoundaries.GetNumNodes() > 0) + if (m_projectToLandBoundary && m_snappingToLandBoundariesCalculator.LandBoundary().GetNumNodes() > 0) { - if (m_landBoundaries.m_meshNodesLandBoundarySegments[firstNode] != constants::missing::uintValue && m_landBoundaries.m_meshNodesLandBoundarySegments[secondNode] != constants::missing::uintValue) + if (m_snappingToLandBoundariesCalculator.LandBoundarySegmentIndex(firstNode) != constants::missing::uintValue && m_snappingToLandBoundariesCalculator.LandBoundarySegmentIndex(secondNode) != constants::missing::uintValue) { // Edge is associated with a land boundary -> keep the edge return largeTopologyFunctionalValue; @@ -390,7 +390,7 @@ int FlipEdges::ComputeTopologyFunctional(UInt edge, int FlipEdges::DifferenceFromOptimum(UInt nodeIndex, UInt firstNode, UInt secondNode) const { - if (m_landBoundaries.m_meshNodesLandBoundarySegments[nodeIndex] == constants::missing::uintValue) + if (m_snappingToLandBoundariesCalculator.LandBoundarySegmentIndex(nodeIndex) == constants::missing::uintValue) { return static_cast(m_mesh.m_nodesNumEdges[nodeIndex]) - static_cast(OptimalNumberOfConnectedNodes(nodeIndex)); } @@ -448,7 +448,7 @@ int FlipEdges::DifferenceFromOptimum(UInt nodeIndex, UInt firstNode, UInt second auto otherNode = OtherNodeOfEdge(m_mesh.GetEdge(edgeIndex), nodeIndex); UInt num = 1; - while (m_landBoundaries.m_meshNodesLandBoundarySegments[otherNode] == constants::missing::uintValue && + while (m_snappingToLandBoundariesCalculator.LandBoundarySegmentIndex(otherNode) == constants::missing::uintValue && !m_mesh.IsEdgeOnBoundary(edgeIndex) && currentEdgeIndexInNodeEdges != edgeIndexConnectingSecondNode) { @@ -459,7 +459,7 @@ int FlipEdges::DifferenceFromOptimum(UInt nodeIndex, UInt firstNode, UInt second } UInt firstEdgeInPathIndex = constants::missing::uintValue; - if (m_landBoundaries.m_meshNodesLandBoundarySegments[otherNode] != constants::missing::uintValue || + if (m_snappingToLandBoundariesCalculator.LandBoundarySegmentIndex(otherNode) != constants::missing::uintValue || m_mesh.IsEdgeOnBoundary(edgeIndex)) { firstEdgeInPathIndex = edgeIndex; @@ -473,7 +473,7 @@ int FlipEdges::DifferenceFromOptimum(UInt nodeIndex, UInt firstNode, UInt second edgeIndex = m_mesh.m_nodesEdges[nodeIndex][currentEdgeIndexInNodeEdges]; otherNode = OtherNodeOfEdge(m_mesh.GetEdge(edgeIndex), nodeIndex); num = num + 1; - while (m_landBoundaries.m_meshNodesLandBoundarySegments[otherNode] == constants::missing::uintValue && + while (m_snappingToLandBoundariesCalculator.LandBoundarySegmentIndex(otherNode) == constants::missing::uintValue && !m_mesh.IsEdgeOnBoundary(edgeIndex) && currentEdgeIndexInNodeEdges != edgeIndexConnectingFirstNode && edgeIndex != firstEdgeInPathIndex) @@ -488,7 +488,7 @@ int FlipEdges::DifferenceFromOptimum(UInt nodeIndex, UInt firstNode, UInt second } } - if ((m_landBoundaries.m_meshNodesLandBoundarySegments[otherNode] != constants::missing::uintValue || + if ((m_snappingToLandBoundariesCalculator.LandBoundarySegmentIndex(otherNode) != constants::missing::uintValue || m_mesh.IsEdgeOnBoundary(edgeIndex)) && edgeIndex != firstEdgeInPathIndex) { diff --git a/libs/MeshKernel/src/OrthogonalizationAndSmoothing.cpp b/libs/MeshKernel/src/OrthogonalizationAndSmoothing.cpp index 0067c38049..9b3e8d7635 100644 --- a/libs/MeshKernel/src/OrthogonalizationAndSmoothing.cpp +++ b/libs/MeshKernel/src/OrthogonalizationAndSmoothing.cpp @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include #include @@ -43,15 +43,15 @@ OrthogonalizationAndSmoothing::OrthogonalizationAndSmoothing(Mesh2D& mesh, std::unique_ptr smoother, std::unique_ptr orthogonalizer, std::unique_ptr polygon, - std::unique_ptr landBoundaries, - LandBoundaries::ProjectToLandBoundaryOption projectToLandBoundaryOption, + std::unique_ptr landBoundaries, + SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions projectToLandBoundaryOption, const OrthogonalizationParameters& orthogonalizationParameters) : m_mesh(mesh), m_smoother(std::move(smoother)), m_orthogonalizer(std::move(orthogonalizer)), m_polygons(std::move(polygon)), - m_landBoundaries(std::move(landBoundaries)), - m_projectToLandBoundaryOption(projectToLandBoundaryOption) + m_snappingToLandBoundariesCalculator(std::move(landBoundaries)), + m_projectOptions(projectToLandBoundaryOption) { CheckOrthogonalizationParameters(orthogonalizationParameters); m_orthogonalizationParameters = orthogonalizationParameters; @@ -91,8 +91,12 @@ std::unique_ptr OrthogonalizationAndSmoothing::Initializ m_originalNodes = m_mesh.Nodes(); m_orthogonalCoordinates = m_mesh.Nodes(); - // account for enclosing polygon - m_landBoundaries->FindNearestMeshBoundary(m_projectToLandBoundaryOption); + // compute land boundary segments if required + if (m_projectOptions == SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::OuterMeshBoundaryToLandBoundaries || + m_projectOptions == SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::InnerAndOuterMeshBoundariesToLandboundaries) + { + m_snappingToLandBoundariesCalculator->FindNearestMeshBoundary(m_projectOptions); + } // for spherical accurate computations we need to call PrapareOuterIteration (orthonet_comp_ops) if (m_mesh.m_projection == Projection::sphericalAccurate) @@ -254,8 +258,12 @@ void OrthogonalizationAndSmoothing::Solve() // compute local coordinates // TODO: Not implemented yet ComputeCoordinates(); - // project on land boundary - [[maybe_unused]] auto action = m_landBoundaries->SnapMeshToLandBoundaries(); + if (m_projectOptions == SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::OuterMeshBoundaryToLandBoundaries || + m_projectOptions == SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::InnerAndOuterMeshBoundariesToLandboundaries) + { + // project on land boundary + [[maybe_unused]] auto action = m_snappingToLandBoundariesCalculator->ComputeSnapping(); + } } void OrthogonalizationAndSmoothing::SnapMeshToOriginalMeshBoundary() diff --git a/libs/MeshKernel/src/LandBoundaries.cpp b/libs/MeshKernel/src/SnappingMesh2DToLandBoundariesCalculator.cpp similarity index 93% rename from libs/MeshKernel/src/LandBoundaries.cpp rename to libs/MeshKernel/src/SnappingMesh2DToLandBoundariesCalculator.cpp index 6ced51f4d5..44539143df 100644 --- a/libs/MeshKernel/src/LandBoundaries.cpp +++ b/libs/MeshKernel/src/SnappingMesh2DToLandBoundariesCalculator.cpp @@ -28,16 +28,16 @@ #include #include #include -#include +#include #include #include #include #include -using meshkernel::LandBoundaries; +using meshkernel::SnappingMesh2DToLandBoundariesCalculator; using meshkernel::Mesh2D; -LandBoundaries::LandBoundaries(const std::vector& boundaryNodes, +SnappingMesh2DToLandBoundariesCalculator::SnappingMesh2DToLandBoundariesCalculator(const std::vector& boundaryNodes, Mesh2D& mesh, const Polygons& polygons) : m_mesh(mesh), m_polygons(polygons), @@ -49,7 +49,7 @@ LandBoundaries::LandBoundaries(const std::vector& boundaryNodes, } } -void LandBoundaries::Administrate() +void SnappingMesh2DToLandBoundariesCalculator::Administrate() { if (m_landBoundary.IsEmpty()) { @@ -98,18 +98,20 @@ void LandBoundaries::Administrate() } } -void LandBoundaries::FindNearestMeshBoundary(ProjectToLandBoundaryOption projectToLandBoundaryOption) +void SnappingMesh2DToLandBoundariesCalculator::FindNearestMeshBoundary(ProjectionsOptions projectionOption) { - if (m_landBoundary.IsEmpty() || projectToLandBoundaryOption == ProjectToLandBoundaryOption::DoNotProjectToLandBoundary) + if (m_landBoundary.IsEmpty()) { return; } - if (projectToLandBoundaryOption == ProjectToLandBoundaryOption::OuterMeshBoundaryToLandBoundary || - projectToLandBoundaryOption == ProjectToLandBoundaryOption::InnerAndOuterMeshBoundaryToLandBoundary) + if (projectionOption != ProjectionsOptions::OuterMeshBoundaryToLandBoundaries && + projectionOption != ProjectionsOptions::InnerAndOuterMeshBoundariesToLandboundaries) { - m_findOnlyOuterMeshBoundary = true; + return; } + m_findOnlyOuterMeshBoundary = true; + Administrate(); @@ -124,7 +126,7 @@ void LandBoundaries::FindNearestMeshBoundary(ProjectToLandBoundaryOption project { const auto [_, numRejectedPaths] = MakePath(landBoundarySegment); - if (numRejectedPaths > 0 && projectToLandBoundaryOption == ProjectToLandBoundaryOption::InnerAndOuterMeshBoundaryToLandBoundary) + if (numRejectedPaths > 0 && projectionOption == ProjectionsOptions::InnerAndOuterMeshBoundariesToLandboundaries) { m_findOnlyOuterMeshBoundary = false; MakePath(landBoundarySegment); @@ -148,7 +150,7 @@ void LandBoundaries::FindNearestMeshBoundary(ProjectToLandBoundaryOption project } } -void LandBoundaries::AssignLandBoundaryPolylineToMeshNodes(UInt edgeIndex, bool initialize, std::vector& nodes, UInt numNodes) +void SnappingMesh2DToLandBoundariesCalculator::AssignLandBoundaryPolylineToMeshNodes(UInt edgeIndex, bool initialize, std::vector& nodes, UInt numNodes) { if (m_landBoundary.IsEmpty()) { @@ -161,7 +163,7 @@ void LandBoundaries::AssignLandBoundaryPolylineToMeshNodes(UInt edgeIndex, bool if (initialize) { if (!m_mesh.IsEdgeOnBoundary(edgeIndex) || m_mesh.GetEdge(edgeIndex).first == constants::missing::uintValue || m_mesh.GetEdge(edgeIndex).second == constants::missing::uintValue) - throw std::invalid_argument("LandBoundaries::AssignLandBoundaryPolylineToMeshNodes: Cannot not assign segment to mesh nodes."); + throw std::invalid_argument("SnappingMesh2DToLandBoundariesCalculator::AssignLandBoundaryPolylineToMeshNodes: Cannot not assign segment to mesh nodes."); const auto firstMeshNode = m_mesh.GetEdge(edgeIndex).first; const auto secondMeshNode = m_mesh.GetEdge(edgeIndex).second; @@ -287,7 +289,7 @@ void LandBoundaries::AssignLandBoundaryPolylineToMeshNodes(UInt edgeIndex, bool } } -void LandBoundaries::AddLandBoundary(const std::vector& nodesLoc, UInt numNodesLoc, UInt nodeIndex) +void SnappingMesh2DToLandBoundariesCalculator::AddLandBoundary(const std::vector& nodesLoc, UInt numNodesLoc, UInt nodeIndex) { if (m_landBoundary.IsEmpty()) { @@ -300,7 +302,7 @@ void LandBoundaries::AddLandBoundary(const std::vector& nodesLoc, UInt num if (startSegmentIndex == constants::missing::uintValue || startSegmentIndex >= m_validLandBoundaries.size() || endSegmentIndex == constants::missing::uintValue || endSegmentIndex >= m_validLandBoundaries.size()) { - throw std::invalid_argument("LandBoundaries::AddLandBoundary: Invalid segment index."); + throw std::invalid_argument("SnappingMesh2DToLandBoundariesCalculator::AddLandBoundary: Invalid segment index."); } // find start/end @@ -329,7 +331,7 @@ void LandBoundaries::AddLandBoundary(const std::vector& nodesLoc, UInt num m_validLandBoundaries.emplace_back(std::make_pair(static_cast(m_landBoundary.GetNumNodes()) - 3, static_cast(m_landBoundary.GetNumNodes()) - 2)); } -std::tuple LandBoundaries::MakePath(UInt landBoundaryIndex) +std::tuple SnappingMesh2DToLandBoundariesCalculator::MakePath(UInt landBoundaryIndex) { if (m_landBoundary.IsEmpty()) { @@ -339,7 +341,7 @@ std::tuple LandBoundaries::MakePath(UInt lan const auto& [startIndex, endIndex] = m_validLandBoundaries[landBoundaryIndex]; if (startIndex >= m_landBoundary.GetNumNodes() || startIndex >= endIndex) { - throw std::invalid_argument("LandBoundaries::MakePath: Invalid boundary index."); + throw std::invalid_argument("SnappingMesh2DToLandBoundariesCalculator::MakePath: Invalid boundary index."); } // Fractional location of the projected outer nodes(min and max) on the land boundary segment @@ -458,7 +460,7 @@ std::tuple LandBoundaries::MakePath(UInt lan return {numNodesInPath, numRejectedNodesInPath}; } -void LandBoundaries::ComputeMeshNodeMask(UInt landBoundaryIndex) +void SnappingMesh2DToLandBoundariesCalculator::ComputeMeshNodeMask(UInt landBoundaryIndex) { if (m_landBoundary.IsEmpty()) { @@ -534,7 +536,7 @@ void LandBoundaries::ComputeMeshNodeMask(UInt landBoundaryIndex) } } -void LandBoundaries::MaskMeshFaceMask(UInt landBoundaryIndex, const std::vector& initialFaces) +void SnappingMesh2DToLandBoundariesCalculator::MaskMeshFaceMask(UInt landBoundaryIndex, const std::vector& initialFaces) { if (m_landBoundary.IsEmpty()) { @@ -640,7 +642,7 @@ void LandBoundaries::MaskMeshFaceMask(UInt landBoundaryIndex, const std::vector< } } -meshkernel::UInt LandBoundaries::IsMeshEdgeCloseToLandBoundaries(UInt landBoundaryIndex, UInt edge) +meshkernel::UInt SnappingMesh2DToLandBoundariesCalculator::IsMeshEdgeCloseToLandBoundaries(UInt landBoundaryIndex, UInt edge) { UInt landBoundaryNode = constants::missing::uintValue; if (m_landBoundary.IsEmpty()) @@ -730,7 +732,7 @@ meshkernel::UInt LandBoundaries::IsMeshEdgeCloseToLandBoundaries(UInt landBounda return landBoundaryNode; } -std::tuple LandBoundaries::FindStartEndMeshNodesDijkstraAlgorithm(UInt landBoundaryIndex) +std::tuple SnappingMesh2DToLandBoundariesCalculator::FindStartEndMeshNodesDijkstraAlgorithm(UInt landBoundaryIndex) { if (m_landBoundary.IsEmpty()) { @@ -791,7 +793,7 @@ std::tuple LandBoundaries::FindStartEndMeshN if (startEdge == constants::missing::uintValue || endEdge == constants::missing::uintValue) { - throw std::invalid_argument("LandBoundaries::FindStartEndMeshNodesDijkstraAlgorithm: Cannot find startMeshNode or endMeshNode."); + throw std::invalid_argument("SnappingMesh2DToLandBoundariesCalculator::FindStartEndMeshNodesDijkstraAlgorithm: Cannot find startMeshNode or endMeshNode."); } const auto startMeshNode = FindStartEndMeshNodesFromEdges(startEdge, startPoint); @@ -800,7 +802,7 @@ std::tuple LandBoundaries::FindStartEndMeshN return {startMeshNode, endMeshNode}; } -meshkernel::UInt LandBoundaries::FindStartEndMeshNodesFromEdges(UInt edge, Point point) const +meshkernel::UInt SnappingMesh2DToLandBoundariesCalculator::FindStartEndMeshNodesFromEdges(UInt edge, Point point) const { if (m_landBoundary.IsEmpty()) { @@ -819,7 +821,7 @@ meshkernel::UInt LandBoundaries::FindStartEndMeshNodesFromEdges(UInt edge, Point return secondMeshNodeIndex; } -std::vector LandBoundaries::ShortestPath(UInt landBoundaryIndex, +std::vector SnappingMesh2DToLandBoundariesCalculator::ShortestPath(UInt landBoundaryIndex, UInt startMeshNode) { std::vector connectedNodeEdges; @@ -937,7 +939,7 @@ std::vector LandBoundaries::ShortestPath(UInt landBoundaryInde return connectedNodeEdges; } -std::tuple LandBoundaries::NearestLandBoundarySegment(UInt segmentIndex, const Point& node) const +std::tuple SnappingMesh2DToLandBoundariesCalculator::NearestLandBoundarySegment(UInt segmentIndex, const Point& node) const { double minimumDistance = std::numeric_limits::max(); Point pointOnLandBoundary = node; @@ -973,7 +975,7 @@ std::tuple LandBoundaries:: return {minimumDistance, pointOnLandBoundary, nearestLandBoundaryNodeIndex, edgeRatio}; } -std::unique_ptr LandBoundaries::SnapMeshToLandBoundaries() const +std::unique_ptr SnappingMesh2DToLandBoundariesCalculator::ComputeSnapping() const { if (m_landBoundary.IsEmpty() || m_meshNodesLandBoundarySegments.empty()) { diff --git a/libs/MeshKernel/src/Splines.cpp b/libs/MeshKernel/src/Splines.cpp index 8f30c398d6..193769e1b5 100644 --- a/libs/MeshKernel/src/Splines.cpp +++ b/libs/MeshKernel/src/Splines.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libs/MeshKernel/tests/src/FlipEdgesTests.cpp b/libs/MeshKernel/tests/src/FlipEdgesTests.cpp index a5901bb5a1..6e9c2d9321 100644 --- a/libs/MeshKernel/tests/src/FlipEdgesTests.cpp +++ b/libs/MeshKernel/tests/src/FlipEdgesTests.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -23,7 +23,7 @@ TEST(FlipEdges, FlipEdgesWithLandBoundary) {20.885406, 21.539995}, {meshkernel::constants::missing::doubleValue, meshkernel::constants::missing::doubleValue}}; - auto landBoundaries = meshkernel::LandBoundaries(landBoundary, *mesh, polygon); + auto landBoundaries = meshkernel::SnappingMesh2DToLandBoundariesCalculator(landBoundary, *mesh, polygon); // execute flipedges meshkernel::FlipEdges flipEdges(*mesh, landBoundaries, true, true); @@ -79,7 +79,7 @@ TEST(FlipEdges, FlipEdgesMediumTriangularMesh) auto polygon = meshkernel::Polygons(); std::vector landBoundary; - auto landBoundaries = meshkernel::LandBoundaries(landBoundary, *mesh, polygon); + auto landBoundaries = meshkernel::SnappingMesh2DToLandBoundariesCalculator(landBoundary, *mesh, polygon); // execute flipedges meshkernel::FlipEdges flipEdges(*mesh, landBoundaries, true, false); diff --git a/libs/MeshKernel/tests/src/LandBoundaryTests.cpp b/libs/MeshKernel/tests/src/LandBoundaryTests.cpp index 74298cc0c3..09246ba0b5 100644 --- a/libs/MeshKernel/tests/src/LandBoundaryTests.cpp +++ b/libs/MeshKernel/tests/src/LandBoundaryTests.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -24,20 +24,20 @@ TEST(LandBoundaries, OneLandBoundary) auto polygons = meshkernel::Polygons(); // Execute - auto landboundaries = meshkernel::LandBoundaries(landBoundaryPolygon, *mesh, polygons); - landboundaries.FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectToLandBoundaryOption ::OuterMeshBoundaryToLandBoundary); + auto landboundaries = meshkernel::SnappingMesh2DToLandBoundariesCalculator(landBoundaryPolygon, *mesh, polygons); + landboundaries.FindNearestMeshBoundary(meshkernel::SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions ::OuterMeshBoundaryToLandBoundaries); // Checks - EXPECT_EQ(1, landboundaries.m_meshNodesLandBoundarySegments[0]); - EXPECT_EQ(0, landboundaries.m_meshNodesLandBoundarySegments[1]); - EXPECT_EQ(2, landboundaries.m_meshNodesLandBoundarySegments[2]); - EXPECT_EQ(2, landboundaries.m_meshNodesLandBoundarySegments[3]); - EXPECT_EQ(3, landboundaries.m_meshNodesLandBoundarySegments[4]); - EXPECT_EQ(1, landboundaries.m_meshNodesLandBoundarySegments[5]); - EXPECT_EQ(1, landboundaries.m_meshNodesLandBoundarySegments[6]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.m_meshNodesLandBoundarySegments[7]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.m_meshNodesLandBoundarySegments[8]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.m_meshNodesLandBoundarySegments[9]); + EXPECT_EQ(1, landboundaries.LandBoundarySegmentIndex(0)); + EXPECT_EQ(0, landboundaries.LandBoundarySegmentIndex(1)); + EXPECT_EQ(2, landboundaries.LandBoundarySegmentIndex(2)); + EXPECT_EQ(2, landboundaries.LandBoundarySegmentIndex(3)); + EXPECT_EQ(3, landboundaries.LandBoundarySegmentIndex(4)); + EXPECT_EQ(1, landboundaries.LandBoundarySegmentIndex(5)); + EXPECT_EQ(1, landboundaries.LandBoundarySegmentIndex(6)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(7)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(8)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(9)); } TEST(LandBoundaries, TwoLandBoundaries) @@ -61,20 +61,20 @@ TEST(LandBoundaries, TwoLandBoundaries) auto polygons = meshkernel::Polygons(); // Execute - auto landboundaries = std::make_shared(landBoundaryPolygon, *mesh, polygons); - landboundaries->FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectToLandBoundaryOption::OuterMeshBoundaryToLandBoundary); + auto landboundaries = meshkernel::SnappingMesh2DToLandBoundariesCalculator(landBoundaryPolygon, *mesh, polygons); + landboundaries.FindNearestMeshBoundary(meshkernel::SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::OuterMeshBoundaryToLandBoundaries); // Checks - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[0]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[1]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[2]); - EXPECT_EQ(3, landboundaries->m_meshNodesLandBoundarySegments[3]); - EXPECT_EQ(3, landboundaries->m_meshNodesLandBoundarySegments[4]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[5]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[6]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[7]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[8]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[9]); + EXPECT_EQ(2, landboundaries.LandBoundarySegmentIndex(0)); + EXPECT_EQ(1, landboundaries.LandBoundarySegmentIndex(1)); + EXPECT_EQ(1, landboundaries.LandBoundarySegmentIndex(2)); + EXPECT_EQ(3, landboundaries.LandBoundarySegmentIndex(3)); + EXPECT_EQ(3, landboundaries.LandBoundarySegmentIndex(4)); + EXPECT_EQ(2, landboundaries.LandBoundarySegmentIndex(5)); + EXPECT_EQ(2, landboundaries.LandBoundarySegmentIndex(6)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(7)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(8)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(9)); } TEST(LandBoundaries, OneCrossingLandBoundary) @@ -93,20 +93,20 @@ TEST(LandBoundaries, OneCrossingLandBoundary) auto polygons = meshkernel::Polygons(); // Execute - auto landboundaries = std::make_shared(landBoundaryPolygon, *mesh, polygons); - landboundaries->FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectToLandBoundaryOption ::OuterMeshBoundaryToLandBoundary); + auto landboundaries = meshkernel::SnappingMesh2DToLandBoundariesCalculator(landBoundaryPolygon, *mesh, polygons); + landboundaries.FindNearestMeshBoundary(meshkernel::SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions ::OuterMeshBoundaryToLandBoundaries); // Checks - EXPECT_EQ(0, landboundaries->m_meshNodesLandBoundarySegments[0]); - EXPECT_EQ(0, landboundaries->m_meshNodesLandBoundarySegments[1]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[2]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[3]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[4]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[5]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[6]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[7]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[8]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[9]); + EXPECT_EQ(0, landboundaries.LandBoundarySegmentIndex(0)); + EXPECT_EQ(0, landboundaries.LandBoundarySegmentIndex(1)); + EXPECT_EQ(2, landboundaries.LandBoundarySegmentIndex(2)); + EXPECT_EQ(2, landboundaries.LandBoundarySegmentIndex(3)); + EXPECT_EQ(1, landboundaries.LandBoundarySegmentIndex(4)); + EXPECT_EQ(1, landboundaries.LandBoundarySegmentIndex(5)); + EXPECT_EQ(1, landboundaries.LandBoundarySegmentIndex(6)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(7)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(8)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(9)); } TEST(LandBoundaries, TwoCrossingLandBoundary) @@ -129,20 +129,20 @@ TEST(LandBoundaries, TwoCrossingLandBoundary) auto polygons = meshkernel::Polygons(); // Execute - auto landboundaries = std::make_shared(landBoundaryPolygon, *mesh, polygons); - landboundaries->FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectToLandBoundaryOption ::OuterMeshBoundaryToLandBoundary); + auto landboundaries = meshkernel::SnappingMesh2DToLandBoundariesCalculator(landBoundaryPolygon, *mesh, polygons); + landboundaries.FindNearestMeshBoundary(meshkernel::SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions ::OuterMeshBoundaryToLandBoundaries); // Checks - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[0]); - EXPECT_EQ(0, landboundaries->m_meshNodesLandBoundarySegments[1]); - EXPECT_EQ(1, landboundaries->m_meshNodesLandBoundarySegments[2]); - EXPECT_EQ(3, landboundaries->m_meshNodesLandBoundarySegments[3]); - EXPECT_EQ(3, landboundaries->m_meshNodesLandBoundarySegments[4]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[5]); - EXPECT_EQ(2, landboundaries->m_meshNodesLandBoundarySegments[6]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[7]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[8]); - EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries->m_meshNodesLandBoundarySegments[9]); + EXPECT_EQ(2, landboundaries.LandBoundarySegmentIndex(0)); + EXPECT_EQ(0, landboundaries.LandBoundarySegmentIndex(1)); + EXPECT_EQ(1, landboundaries.LandBoundarySegmentIndex(2)); + EXPECT_EQ(3, landboundaries.LandBoundarySegmentIndex(3)); + EXPECT_EQ(3, landboundaries.LandBoundarySegmentIndex(4)); + EXPECT_EQ(2, landboundaries.LandBoundarySegmentIndex(5)); + EXPECT_EQ(2, landboundaries.LandBoundarySegmentIndex(6)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(7)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(8)); + EXPECT_EQ(meshkernel::constants::missing::uintValue, landboundaries.LandBoundarySegmentIndex(9)); } TEST(LandBoundaries, LandBoundaryConstructorTestSinglePolyline) diff --git a/libs/MeshKernel/tests/src/OrthogonalizationTests.cpp b/libs/MeshKernel/tests/src/OrthogonalizationTests.cpp index bec025a040..e0ca38ed03 100644 --- a/libs/MeshKernel/tests/src/OrthogonalizationTests.cpp +++ b/libs/MeshKernel/tests/src/OrthogonalizationTests.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -33,7 +33,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationOneQuadOneTriangle) {3, 2}, {3, 1}}; - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.inner_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -49,7 +49,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationOneQuadOneTriangle) auto polygon = std::make_unique(); std::vector landBoundary{}; - auto landboundaries = std::make_unique(landBoundary, mesh, *polygon); + auto landboundaries = std::make_unique(landBoundary, mesh, *polygon); OrthogonalizationAndSmoothing orthogonalization(mesh, std::move(smoother), @@ -82,7 +82,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationSmallTriangularGrid) // now build node-edge mapping auto mesh = ReadLegacyMesh2DFromFile(TEST_FOLDER + "/data/SmallTriangularGrid_net.nc"); - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.outer_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -96,7 +96,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationSmallTriangularGrid) auto polygon = std::make_unique(); std::vector landBoundary; - auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); + auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); OrthogonalizationAndSmoothing orthogonalization(*mesh, std::move(smoother), @@ -140,7 +140,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationSmallTriangularGridAsNcFile // now build node-edge mapping auto mesh = MakeSmallSizeTriangularMeshForTestingAsNcFile(); - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.outer_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -154,7 +154,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationSmallTriangularGridAsNcFile auto polygon = std::make_unique(); std::vector landBoundary; - auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); + auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); OrthogonalizationAndSmoothing orthogonalization(*mesh, std::move(smoother), @@ -200,7 +200,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationMediumTriangularGridWithPol // The original mesh nodes const std::vector meshNodes(mesh->Nodes()); - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.outer_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -224,7 +224,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationMediumTriangularGridWithPol std::vector landBoundary; auto polygon = std::make_unique(nodes, Projection::cartesian); - auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); + auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); OrthogonalizationAndSmoothing orthogonalization(*mesh, std::move(smoother), @@ -278,7 +278,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationMediumTriangularGridWithUnd // now build node-edge mapping auto mesh = ReadLegacyMesh2DFromFile(TEST_FOLDER + "/data/TestOrthogonalizationMediumTriangularGrid_net.nc"); - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.outer_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -291,7 +291,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationMediumTriangularGridWithUnd auto smoother = std::make_unique(*mesh); auto polygon = std::make_unique(); std::vector landBoundary; - auto landBoundaries = std::make_unique(landBoundary, *mesh, *polygon); + auto landBoundaries = std::make_unique(landBoundary, *mesh, *polygon); const std::vector meshNodes = mesh->Nodes(); @@ -346,7 +346,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationFourQuads) { auto mesh = MakeRectangularMeshForTesting(3, 3, 1.0, Projection::cartesian); - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.inner_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -357,7 +357,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationFourQuads) auto polygon = std::make_unique(); std::vector landBoundary{}; - auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); + auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); auto orthogonalizer = std::make_unique(*mesh); auto smoother = std::make_unique(*mesh); @@ -393,7 +393,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizeAndSnapToLandBoundaries) {missing::doubleValue, missing::doubleValue}}; // snap to land boundaries - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::OuterMeshBoundaryToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::OuterMeshBoundaryToLandBoundaries; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.outer_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -404,7 +404,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizeAndSnapToLandBoundaries) // no enclosing polygon auto polygon = std::make_unique(); - auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); + auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); auto orthogonalizer = std::make_unique(*mesh); auto smoother = std::make_unique(*mesh); @@ -449,7 +449,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationSphericalRectangular) // 1 Setup auto mesh = MakeRectangularMeshForTesting(4, 4, 0.003, Projection::spherical, {41.1, 41.1}); - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.outer_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -463,7 +463,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationSphericalRectangular) auto polygon = std::make_unique(); std::vector landBoundary{}; - auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); + auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); OrthogonalizationAndSmoothing orthogonalization(*mesh, std::move(smoother), @@ -537,7 +537,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationSmallTriangulargridSpherica auto mesh = std::make_shared(edges, nodes, Projection::spherical); - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.outer_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -549,7 +549,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationSmallTriangulargridSpherica // no enclosing polygon auto polygon = std::make_unique(); std::vector landBoundary{}; - auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); + auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); auto orthogonalizer = std::make_unique(*mesh); auto smoother = std::make_unique(*mesh); @@ -598,7 +598,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationSmallTriangulargridSpherica auto mesh = std::make_shared(edges, nodes, Projection::spherical); - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.outer_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -610,7 +610,7 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationSmallTriangulargridSpherica // no enclosing polygon auto polygon = std::make_unique(); std::vector landBoundary{}; - auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); + auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); auto orthogonalizer = std::make_unique(*mesh); auto smoother = std::make_unique(*mesh); @@ -692,7 +692,7 @@ TEST(OrthogonalizationAndSmoothing, RefineUndoThenOrthogonalise) auto refinementUndoAction = meshRefinement.Compute(); refinementUndoAction->Restore(); - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.inner_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; @@ -706,7 +706,7 @@ TEST(OrthogonalizationAndSmoothing, RefineUndoThenOrthogonalise) auto polygon = std::make_unique(polygonNodes, Projection::cartesian); auto orthogonalisationPolygon = std::make_unique(polygonNodes, Projection::cartesian); std::vector landBoundary{}; - auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); + auto landboundaries = std::make_unique(landBoundary, *mesh, *polygon); auto orthogonalizer = std::make_unique(*mesh); auto smoother = std::make_unique(*mesh); @@ -774,11 +774,11 @@ TEST(OrthogonalizationAndSmoothing, OrthogonalizationWithGapsInNodeAndEdgeLists) [[maybe_unused]] auto nodeRemovaUndo = mesh.DeleteNode(nodeId); mesh.Administrate(); - std::unique_ptr boundary = std::make_unique(refinedPolygonPoints, mesh, *refinedPolygon); + std::unique_ptr boundary = std::make_unique(refinedPolygonPoints, mesh, *refinedPolygon); FlipEdges flipEdges1(mesh, *boundary, true, false); - const auto projectToLandBoundaryOption = LandBoundaries::ProjectToLandBoundaryOption::DoNotProjectToLandBoundary; + const auto projectToLandBoundaryOption = SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::DoNotProject; OrthogonalizationParameters orthogonalizationParameters; orthogonalizationParameters.outer_iterations = 2; orthogonalizationParameters.boundary_iterations = 25; diff --git a/libs/MeshKernelApi/src/MeshKernel.cpp b/libs/MeshKernelApi/src/MeshKernel.cpp index 521a5552d0..68b9f19522 100644 --- a/libs/MeshKernelApi/src/MeshKernel.cpp +++ b/libs/MeshKernelApi/src/MeshKernel.cpp @@ -62,7 +62,7 @@ #include #include #include -#include +#include #include #include #include @@ -504,11 +504,11 @@ namespace meshkernelapi // Construct all dependencies const auto polygon = meshkernel::Polygons(polygonNodes, meshKernelState[meshKernelId].m_projection); - auto landBoundary = meshkernel::LandBoundaries(landBoundariesPoints, *meshKernelState[meshKernelId].m_mesh2d, polygon); - landBoundary.FindNearestMeshBoundary(meshkernel::LandBoundaries::ProjectToLandBoundaryOption::InnerAndOuterMeshBoundaryToLandBoundary); + auto landBoundary = meshkernel::SnappingMesh2DToLandBoundariesCalculator(landBoundariesPoints, *meshKernelState[meshKernelId].m_mesh2d, polygon); + landBoundary.FindNearestMeshBoundary(meshkernel::SnappingMesh2DToLandBoundariesCalculator::ProjectionsOptions::InnerAndOuterMeshBoundariesToLandboundaries); // Execute algorithm - meshKernelUndoStack.Add(landBoundary.SnapMeshToLandBoundaries()); + meshKernelUndoStack.Add(landBoundary.ComputeSnapping()); } catch (...) { @@ -1267,14 +1267,14 @@ namespace meshkernelapi auto smoother = std::make_unique(*meshKernelState[meshKernelId].m_mesh2d); auto orthogonalizer = std::make_unique(*meshKernelState[meshKernelId].m_mesh2d); auto polygon = std::make_unique(polygonNodes, meshKernelState[meshKernelId].m_mesh2d->m_projection); - auto landBoundary = std::make_unique(landBoundariesPoints, *meshKernelState[meshKernelId].m_mesh2d, *polygon); + auto landBoundary = std::make_unique(landBoundariesPoints, *meshKernelState[meshKernelId].m_mesh2d, *polygon); meshkernel::OrthogonalizationAndSmoothing ortogonalization(*meshKernelState[meshKernelId].m_mesh2d, std::move(smoother), std::move(orthogonalizer), std::move(polygon), std::move(landBoundary), - static_cast(projectToLandBoundaryOption), + static_cast(projectToLandBoundaryOption), orthogonalizationParameters); meshKernelUndoStack.Add(ortogonalization.Initialize(), meshKernelId); ortogonalization.Compute(); @@ -1315,14 +1315,14 @@ namespace meshkernelapi auto smoother = std::make_unique(*meshKernelState[meshKernelId].m_mesh2d); auto orthogonalizer = std::make_unique(*meshKernelState[meshKernelId].m_mesh2d); auto polygon = std::make_unique(polygonNodesVector, meshKernelState[meshKernelId].m_mesh2d->m_projection); - auto landBoundary = std::make_unique(landBoundariesNodeVector, *meshKernelState[meshKernelId].m_mesh2d, *polygon); + auto landBoundary = std::make_unique(landBoundariesNodeVector, *meshKernelState[meshKernelId].m_mesh2d, *polygon); meshKernelState[meshKernelId].m_meshOrthogonalization = std::make_unique(*meshKernelState[meshKernelId].m_mesh2d, std::move(smoother), std::move(orthogonalizer), std::move(polygon), std::move(landBoundary), - static_cast(projectToLandBoundaryOption), + static_cast(projectToLandBoundaryOption), orthogonalizationParameters); meshKernelUndoStack.Add(meshKernelState[meshKernelId].m_meshOrthogonalization->Initialize(), meshKernelId); } @@ -3416,7 +3416,7 @@ namespace meshkernelapi // construct all dependencies auto const polygon = meshkernel::Polygons(polygonNodesVector, meshKernelState[meshKernelId].m_mesh2d->m_projection); - auto landBoundary = meshkernel::LandBoundaries(landBoundariesNodeVector, *meshKernelState[meshKernelId].m_mesh2d, polygon); + auto landBoundary = meshkernel::SnappingMesh2DToLandBoundariesCalculator(landBoundariesNodeVector, *meshKernelState[meshKernelId].m_mesh2d, polygon); bool const triangulateFaces = isTriangulationRequired == 0 ? false : true; bool const projectToLandBoundary = projectToLandBoundaryRequired == 0 ? false : true;