Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a889942
GRIDEDIT-1795 updated comment for edge
BillSenior Sep 25, 2025
769b622
GRIDEDIT-1795 New approach to illegal cells that uses mostly existing…
BillSenior Sep 29, 2025
df1ea32
GRIDEDIT-1795 Found inner boundaries for holes
BillSenior Oct 2, 2025
95ddbaf
GRIDEDIT-1795 Corrected orientation of all polygons, orientation shou…
BillSenior Oct 6, 2025
65a5cb2
GRIDEDIT-1795 Passing to other computer
BillSenior Oct 6, 2025
0134c1e
GRIDEDIT-1795 Merged master into branch
BillSenior Oct 7, 2025
4c672a8
GRIDEDIT-1795 Removed invalid element information from mesh2d after d…
BillSenior Oct 8, 2025
8e001fd
GRIDEDIT-1795 Update edge-face connectivity info when one of more fac…
BillSenior Oct 8, 2025
dd21ce2
GRIDEDIT-1795 Small refactoring and added comments
BillSenior Oct 9, 2025
61a76bc
GRIDEDIT-1795 Apply invalid cells mask after steps that will call an …
BillSenior Oct 9, 2025
5ac8946
GRIDEDIT-1795 Added a new file containing tests for the keeping of in…
BillSenior Oct 9, 2025
d6a0765
Merge branch 'master' into feature/GRIDEDIT-1795_export_illegal_cells…
BillSenior Oct 9, 2025
86d1ca7
GRIDEDIT-1795 Merged master into the branch
BillSenior Oct 9, 2025
86da75a
GRIDEDIT-1795 Fix windows build, update comments and fix clang format…
BillSenior Oct 9, 2025
5f14efd
GRIDEDIT-1795 Updated comments
BillSenior Oct 9, 2025
3ef4478
GRIDEDIT-1795 Updated comments
BillSenior Oct 9, 2025
7d80ffe
GRIDEDIT-1795 Added extra information to polygon not closed error
BillSenior Oct 9, 2025
94b84ff
GRIDEDIT-1795 Added extra information to polygon not closed error
BillSenior Oct 9, 2025
566a365
GRIDEDIT-1795 Added vtk output for data collected via api
BillSenior Oct 22, 2025
3502f50
GRIDEDIT-1795 Corrected orientating polygons
BillSenior Oct 22, 2025
fefc95e
GRIDEDIT-1795 Corrected unit test
BillSenior Oct 22, 2025
54fb30b
GRIDEDIT-1795 Fixed illegal cells, code need tidying up
BillSenior Oct 23, 2025
e038cd8
GRIDEDIT-1795 Fixed api call to delete cell in polygon
BillSenior Oct 23, 2025
51a351c
GRIDEDIT-1795 Added unit tests for handling of holes in the mesh
BillSenior Oct 27, 2025
5602591
GRIDEDIT-1795 Corrected comment for undo action
BillSenior Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libs/MeshKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ set(
${UNDO_SRC_DIR}/MeshConversionAction.cpp
${UNDO_SRC_DIR}/NoActionUndo.cpp
${UNDO_SRC_DIR}/NodeTranslationAction.cpp
${UNDO_SRC_DIR}/PointArrayUndo.cpp
${UNDO_SRC_DIR}/ResetEdgeAction.cpp
${UNDO_SRC_DIR}/ResetNodeAction.cpp
${UNDO_SRC_DIR}/SphericalCoordinatesOffsetAction.cpp
Expand Down Expand Up @@ -231,6 +232,7 @@ set(
${UNDO_INC_DIR}/MeshConversionAction.hpp
${UNDO_INC_DIR}/NoActionUndo.hpp
${UNDO_INC_DIR}/NodeTranslationAction.hpp
${UNDO_INC_DIR}/PointArrayUndo.hpp
${UNDO_INC_DIR}/ResetEdgeAction.hpp
${UNDO_INC_DIR}/ResetNodeAction.hpp
${UNDO_INC_DIR}/SphericalCoordinatesOffsetAction.hpp
Expand Down
2 changes: 1 addition & 1 deletion libs/MeshKernel/include/MeshKernel/Entities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace meshkernel
// t.IsValid
//};

/// @brief Describes an edge with two indices
/// @brief Describes an edge connecting two nodes.
using Edge = std::pair<UInt, UInt>;

//// @brief Determine if the value is a valid value (true) or is the undefined value (false)
Expand Down
7 changes: 4 additions & 3 deletions libs/MeshKernel/include/MeshKernel/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ namespace meshkernel
/// @brief Perform node and edges administration
void AdministrateNodesEdges(CompoundUndoAction* undoAction = nullptr);

/// @brief Determine if a administration is required
bool AdministrationRequired() const;

/// @brief Sort mesh edges around a node in counterclockwise order (Sort_links_ccw)
/// @param[in] startNode The first node index where to perform edge sorting.
/// @param[in] endNode The last node index where to perform edge sorting.
Expand Down Expand Up @@ -477,9 +480,6 @@ namespace meshkernel
Projection m_projection; ///< The projection used

protected:
/// @brief Determine if a administration is required
bool AdministrationRequired() const;

/// @brief Determine if a administration is required
void SetAdministrationRequired(const bool value);

Expand Down Expand Up @@ -513,6 +513,7 @@ namespace meshkernel
UInt& numInvalidNodes,
CompoundUndoAction* undoAction = nullptr);
};

} // namespace meshkernel

inline const std::vector<meshkernel::Point>& meshkernel::Mesh::Nodes() const
Expand Down
64 changes: 54 additions & 10 deletions libs/MeshKernel/include/MeshKernel/Mesh2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <utility>
#include <vector>

#include "MeshKernel/UndoActions/PointArrayUndo.hpp"
#include <MeshKernel/Constants.hpp>
#include <MeshKernel/Definitions.hpp>
#include <MeshKernel/Entities.hpp>
Expand Down Expand Up @@ -127,11 +128,17 @@ namespace meshkernel
/// @brief Apply the coordinate offset action
void CommitAction(const SphericalCoordinatesOffsetAction& undoAction);

/// @brief Set the node values.
void CommitAction(PointArrayUndo& undoAction);

/// @brief Undo the coordinate offset action
///
/// Restore mesh to state before coordinate offset action was applied
void RestoreAction(const SphericalCoordinatesOffsetAction& undoAction);

/// @brief Undo node array
void RestoreAction(PointArrayUndo& undoAction);

/// @brief For a face create a closed polygon and fill local mapping caches (get_cellpolygon)
/// @param[in] faceIndex The face index
/// @param[out] polygonNodesCache The node cache array filled with the nodes values
Expand Down Expand Up @@ -244,15 +251,9 @@ namespace meshkernel
/// @return The resulting polygon mesh boundary
[[nodiscard]] std::vector<Point> ComputeBoundaryPolygons(const std::vector<Point>& polygon);

/// @brief Constructs a polygon from the meshboundary, by walking through the mesh
/// @param[in] polygon The input polygon
/// @param[in,out] isVisited the visited mesh nodes
/// @param[in,out] currentNode the current node
/// @param[out] meshBoundaryPolygon The resulting polygon points
void WalkBoundaryFromNode(const Polygon& polygon,
std::vector<bool>& isVisited,
UInt& currentNode,
std::vector<Point>& meshBoundaryPolygon) const;
/// @brief Convert all mesh boundaries to a vector of polygon nodes
/// @return The resulting set of polygons, describing interior mesh boundaries
std::vector<Point> ComputeInnerBoundaryPolygons() const;

/// @brief Gets the hanging edges
/// @return A vector with the indices of the hanging edges
Expand All @@ -273,6 +274,11 @@ namespace meshkernel
/// @param[in] invertDeletion Inverts the selected node to delete (instead of outside the polygon, inside the polygon)
[[nodiscard]] std::unique_ptr<UndoAction> DeleteMesh(const Polygons& polygon, DeleteMeshOptions deletionOption, bool invertDeletion);

/// @brief Deletes the mesh faces inside a set of polygons
/// @param[in] polygon The polygon where to perform the operation
/// @param[in] appendDeletedFaces Indicate if the deleted cells should be appended to the list of polygons describing holes in the mesh
[[nodiscard]] std::unique_ptr<UndoAction> DeleteMeshFacesInPolygon(const Polygons& polygon, const bool appendDeletedFaces = true);

/// @brief This method generates a mask indicating which locations are within the specified range of the given metric.
///
/// @param[in] location The location representing the location where to filter the object.
Expand Down Expand Up @@ -435,12 +441,49 @@ namespace meshkernel
/// @brief Find the mesh faces that lie entirely within the polygon.
std::vector<bool> FindFacesEntirelyInsidePolygon(const std::vector<bool>& isNodeInsidePolygon) const;

/// @brief Constructs a polygon from the meshboundary, by walking through the mesh
void WalkBoundaryFromNode(const Polygon& polygon,
std::vector<bool>& isVisited,
UInt& currentNode,
std::vector<Point>& meshBoundaryPolygon) const;

/// @brief Constructs a polygon or polygons from the meshboundary, by walking through the mesh
///
/// If there are multiple polygons connected by a single node, then these will be separated into individual polygons
void WalkMultiBoundaryFromNode(std::vector<bool>& edgeIsVisited,
std::vector<bool>& nodeIsVisited,
UInt& currentNode,
std::vector<Point>& meshBoundaryPolygon,
std::vector<UInt>& nodeIds,
std::vector<Point>& subsSequence) const;

/// @brief Ensure that all polynomials are orientated in the ACW direction.
void OrientatePolygonsAntiClockwise(std::vector<Point>& polygonNodes) const;

/// @brief Removes the outer domain boundary polygon from the set of polygons
///
/// It is assumed that the outer domain polygon contains the most nodes
std::vector<Point> RemoveOuterDomainBoundaryPolygon(const std::vector<Point>& polygonNodes) const;

/// @brief Deletes the mesh faces inside a polygon
/// @param[in] polygon The polygon where to perform the operation
/// If this Polygons instance contains multiple polygons, the first one will be taken.
/// @param[in] invertDeletion Inverts the selected node to delete (instead of outside the polygon, inside the polygon)
[[nodiscard]] std::unique_ptr<UndoAction> DeleteMeshFaces(const Polygons& polygon, bool invertDeletion);

/// @brief Append the polygon describing the cell to the list of invalid cells polygons
void AppendCellPolygon(const UInt faceId);

/// @brief Delete parts of the mesh described by the invalid cells polygons
void DeleteMeshHoles(CompoundUndoAction* undoAction);

/// @brief Update information about a list of faces and face-edge information
///
/// @param [in] faceIndices Mapping between old and new face-ids, the invalid value implies a deleted element
/// @param [in,out] deleteMeshAction Gather any additional undo information
/// @param [in] appendDeletedFaces Indicate if the deleted cells should be appended to the list of polygons describing holes in the mesh
void UpdateFaceInformation(const std::vector<UInt>& faceIndices, CompoundUndoAction& deleteMeshAction, const bool appendDeletedFaces);

/// @brief Find cells recursive, works with an arbitrary number of edges
/// @param[in] startNode The starting node
/// @param[in] node The current node
Expand Down Expand Up @@ -511,7 +554,8 @@ namespace meshkernel
/// @returns The number of edges that have been invalidated
UInt InvalidateEdgesWithNoFace();

std::vector<MeshNodeType> m_nodesTypes; ///< The node types (nb)
std::vector<MeshNodeType> m_nodesTypes; ///< The node types (nb)
std::vector<Point> m_invalidCellPolygons; ///< Invalid cell polygons
};

} // namespace meshkernel
65 changes: 65 additions & 0 deletions libs/MeshKernel/include/MeshKernel/UndoActions/PointArrayUndo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2025.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// contact: delft3d.support@deltares.nl
// Stichting Deltares
// P.O. Box 177
// 2600 MH Delft, The Netherlands
//
// All indications and logos of, and references to, "Delft3D" and "Deltares"
// are registered trademarks of Stichting Deltares, and remain the property of
// Stichting Deltares. All rights reserved.
//
//------------------------------------------------------------------------------

#pragma once

#include <cstdint>
#include <vector>

#include "MeshKernel/Entities.hpp"
#include "MeshKernel/Point.hpp"
#include "MeshKernel/UndoActions/BaseMeshUndoAction.hpp"

namespace meshkernel
{
/// @brief Forward declaration of the unstructured mesh
class Mesh2D;

/// @brief Action to save an array of points stored in the mesh
///
/// The undo will simply swap these values
class PointArrayUndo : public BaseMeshUndoAction<PointArrayUndo, Mesh2D>
{
public:
/// @brief Allocate a DeleteNodeAction and return a unique_ptr to the newly created object.
static std::unique_ptr<PointArrayUndo> Create(Mesh2D& mesh, const std::vector<Point>& nodes);

/// @brief Constructor
explicit PointArrayUndo(Mesh2D& mesh, const std::vector<Point>& nodes);

/// @brief Swap the array of points with the saved values.
void Swap(std::vector<Point>& nodes);

/// \brief Compute the approximate amount of memory being used, in bytes.
std::uint64_t MemorySize() const override;

private:
/// @brief The saved point values.
std::vector<Point> m_savedNodes;
};

} // namespace meshkernel
9 changes: 9 additions & 0 deletions libs/MeshKernel/include/MeshKernel/Utilities/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ namespace meshkernel
/// @note saves only triangle and quadrilateral elements.
void SaveVtk(const std::vector<Point>& nodes, const std::vector<std::vector<UInt>>& faces, const std::string& fileName);

/// @brief Save the mesh data in a vtk file format
///
/// @note saves only triangle and quadrilateral elements.
void SaveVtk(const std::vector<double>& nodesX,
const std::vector<double>& nodesY,
const std::vector<int>& facesNodes,
const std::vector<int>& facesNumNodes,
const std::string& fileName);

} // namespace meshkernel
1 change: 1 addition & 0 deletions libs/MeshKernel/src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <cmath>
#include <iomanip>
#include <numeric>
#include <ranges>

#include "MeshKernel/Entities.hpp"
#include "MeshKernel/Exceptions.hpp"
Expand Down
Loading
Loading