Skip to content

Commit

Permalink
Refactored undo for casulli refinement (#379 | GRIDEDIT-1499)
Browse files Browse the repository at this point in the history
  • Loading branch information
BillSenior authored Nov 25, 2024
1 parent 95323e6 commit b11e79c
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 133 deletions.
33 changes: 17 additions & 16 deletions libs/MeshKernel/include/MeshKernel/CasulliRefinement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#pragma once

#include <array>
#include <memory>
#include <vector>

#include "MeshKernel/Mesh2D.hpp"
Expand Down Expand Up @@ -104,37 +105,37 @@ namespace meshkernel
/// @param [in, out] mesh The Mesh
/// @param [in, out] newNodes List of new nodes and connectivity
/// @param [in, out] nodeMask Node mask information
[[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ComputeNewNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
static void ComputeNewNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);

/// @brief Connect newly generated nodes
///
/// @param [in, out] mesh The mesh being refined
/// @param [in] newNodes List of new nodes and connectivity
/// @param [in] numEdges Number of edges in original mesh, before refinement.
[[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ConnectNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numEdges);
static void ConnectNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numEdges);

/// @brief Compute new edges required for refinement
///
/// @param [in, out] mesh The mesh being refined
/// @param [in] numNodes Number of nodes in original mesh, before refinement.
/// @param [in] newNodes List of new nodes and connectivity
/// @param [in, out] nodeMask Node mask information
[[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> CreateMissingBoundaryEdges(Mesh2D& mesh, const UInt numNodes, const std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
static void CreateMissingBoundaryEdges(Mesh2D& mesh, const UInt numNodes, const std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);

/// @brief Compute new nodes on faces
///
/// @param [in, out] mesh The mesh being refined
/// @param [in, out] newNodes List of new nodes and connectivity
/// @param [in, out] nodeMask Node mask information
[[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ComputeNewFaceNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
static void ComputeNewFaceNodes(Mesh2D& mesh, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);

/// @brief Compute new nodes on edges
///
/// @param [in, out] mesh The mesh being refined
/// @param [in] numEdges Number of edges in original mesh, before refinement.
/// @param [in, out] newNodes List of new nodes and connectivity
/// @param [in, out] nodeMask Node mask information
[[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ComputeNewEdgeNodes(Mesh2D& mesh, const UInt numEdges, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);
static void ComputeNewEdgeNodes(Mesh2D& mesh, const UInt numEdges, std::vector<EdgeNodes>& newNodes, std::vector<NodeMask>& nodeMask);

/// @brief Connect edges
///
Expand All @@ -143,22 +144,22 @@ namespace meshkernel
/// @param [in] newNodes List of new nodes and connectivity
/// @param [out] edgeCount Number of edges created
/// @param [in, out] newEdges Identifiers of edges created
[[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ConnectEdges(Mesh2D& mesh,
const UInt currentNode,
const std::vector<EdgeNodes>& newNodes,
UInt& edgeCount,
std::vector<UInt>& newEdges);
static void ConnectEdges(Mesh2D& mesh,
const UInt currentNode,
const std::vector<EdgeNodes>& newNodes,
UInt& edgeCount,
std::vector<UInt>& newEdges);

/// @brief Connect face node
///
/// @param [in, out] mesh The mesh being refined
/// @param [in] currentFace The face being connected
/// @param [in, out] newNodes List of new nodes and connectivity
/// @param [in, out] nodeMask Node mask information
[[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ConnectFaceNodes(Mesh2D& mesh,
const UInt currentFace,
const std::vector<EdgeNodes>& newNodes,
std::vector<NodeMask>& nodeMask);
static void ConnectFaceNodes(Mesh2D& mesh,
const UInt currentFace,
const std::vector<EdgeNodes>& newNodes,
std::vector<NodeMask>& nodeMask);

/// @brief Connect newly generated nodes
///
Expand All @@ -168,7 +169,7 @@ namespace meshkernel
/// @param [in] numEdges Number of edges in original mesh, before refinement.
/// @param [in] numFaces Number of faces in original mesh, before refinement.
/// @param [in, out] nodeMask Node mask information
[[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> ConnectNewNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numNodes, const UInt numEdges, const UInt numFaces, std::vector<NodeMask>& nodeMask);
static void ConnectNewNodes(Mesh2D& mesh, const std::vector<EdgeNodes>& newNodes, const UInt numNodes, const UInt numEdges, const UInt numFaces, std::vector<NodeMask>& nodeMask);

/// @brief Add newly generated nodes to the newNodes list.
///
Expand Down Expand Up @@ -198,7 +199,7 @@ namespace meshkernel
/// @param [in, out] mesh The mesh
/// @param [in] numNodes The original number of nodes in the mesh
/// @param [in] nodeMask Node mask information
[[nodiscard]] static std::unique_ptr<meshkernel::UndoAction> Administrate(Mesh2D& mesh, const UInt numNodes, const std::vector<NodeMask>& nodeMask);
static void Administrate(Mesh2D& mesh, const UInt numNodes, const std::vector<NodeMask>& nodeMask);
};

} // namespace meshkernel
9 changes: 6 additions & 3 deletions libs/MeshKernel/include/MeshKernel/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,15 @@ namespace meshkernel
/// If the nodes are not connected a new edge is formed, otherwise UInt invalid value is returned. (connectdbn)
/// @param[in] startNode The start node index
/// @param[in] endNode The end node index
/// @param[in] collectUndo Indicate whether or not an undo action should be created, if false then the undo result will be nullptr
/// @return The index of the new edge and the undoAction to connect two nodes
[[nodiscard]] std::tuple<UInt, std::unique_ptr<AddEdgeAction>> ConnectNodes(UInt startNode, UInt endNode);
[[nodiscard]] std::tuple<UInt, std::unique_ptr<AddEdgeAction>> ConnectNodes(UInt startNode, UInt endNode, const bool collectUndo = true);

/// @brief Deletes a node and removes any connected edges
/// @param[in] node The node index
/// @param[in] collectUndo Indicate whether or not an undo action should be created, if false then the undo result will be nullptr.
/// @return The undoAction to delete the node and any connecting edges
[[nodiscard]] std::unique_ptr<DeleteNodeAction> DeleteNode(UInt node);
[[nodiscard]] std::unique_ptr<DeleteNodeAction> DeleteNode(UInt node, const bool collectUndo = true);

/// @brief Find the edge sharing two nodes
/// @param[in] firstNodeIndex The index of the first node
Expand Down Expand Up @@ -288,8 +290,9 @@ namespace meshkernel

/// @brief Deletes an edge
/// @param[in] edge The edge index
/// @param[in] collectUndo Indicate whether or not an undo action should be created, if false then the undo result will be nullptr.
/// @return The undoAction to delete the edge
[[nodiscard]] std::unique_ptr<DeleteEdgeAction> DeleteEdge(UInt edge);
[[nodiscard]] std::unique_ptr<DeleteEdgeAction> DeleteEdge(UInt edge, const bool collectUndo = true);

/// @brief Find the common node two edges share
/// This method uses return parameters since the success is evaluated in a hot loop
Expand Down
Loading

0 comments on commit b11e79c

Please sign in to comment.