31 #include "MeshKernel/BoundingBox.hpp"
32 #include "MeshKernel/Definitions.hpp"
33 #include "MeshKernel/Entities.hpp"
34 #include "MeshKernel/Exceptions.hpp"
35 #include "MeshKernel/UndoActions/AddEdgeAction.hpp"
36 #include "MeshKernel/UndoActions/AddNodeAction.hpp"
37 #include "MeshKernel/UndoActions/CompoundUndoAction.hpp"
38 #include "MeshKernel/UndoActions/DeleteEdgeAction.hpp"
39 #include "MeshKernel/UndoActions/DeleteNodeAction.hpp"
40 #include "MeshKernel/UndoActions/FullUnstructuredGridUndo.hpp"
41 #include "MeshKernel/UndoActions/MeshConversionAction.hpp"
42 #include "MeshKernel/UndoActions/NodeTranslationAction.hpp"
43 #include "MeshKernel/UndoActions/ResetEdgeAction.hpp"
44 #include "MeshKernel/UndoActions/ResetNodeAction.hpp"
45 #include "MeshKernel/UndoActions/UndoAction.hpp"
46 #include "Utilities/RTreeBase.hpp"
109 virtual ~Mesh() =
default;
134 Mesh(
const std::vector<Edge>& edges,
135 const std::vector<Point>& nodes,
193 const std::vector<Point>&
Nodes()
const;
199 void SetNodes(
const std::vector<Point>& newValues);
205 [[nodiscard]] std::unique_ptr<ResetNodeAction>
ResetNode(
const UInt index,
const Point& newValue);
209 const std::vector<Edge>&
Edges()
const;
215 void SetEdges(
const std::vector<Edge>& newValues);
221 [[nodiscard]] std::unique_ptr<ResetEdgeAction>
ResetEdge(
UInt edgeId,
const Edge& edge);
241 [[nodiscard]] std::tuple<UInt, std::unique_ptr<AddNodeAction>>
InsertNode(
const Point& newPoint);
248 [[nodiscard]] std::tuple<UInt, std::unique_ptr<AddEdgeAction>>
ConnectNodes(
UInt startNode,
UInt endNode);
253 [[nodiscard]] std::unique_ptr<DeleteNodeAction>
DeleteNode(
UInt node);
270 [[nodiscard]] std::unique_ptr<UndoAction>
MoveNode(
Point newPoint,
UInt nodeindex);
280 const std::vector<bool>& locationMask = {},
281 const BoundingBox& boundingBox = {});
292 [[nodiscard]] std::unique_ptr<DeleteEdgeAction>
DeleteEdge(
UInt edge);
321 virtual void Administrate(CompoundUndoAction* undoAction =
nullptr);
363 std::unique_ptr<UndoAction>
Join(
const Mesh& rhs);
404 void CommitAction(FullUnstructuredGridUndo& undoAction);
506 static double constexpr m_minimumDeltaCoordinate = 1e-14;
509 bool m_nodesRTreeRequiresUpdate =
true;
510 bool m_edgesRTreeRequiresUpdate =
true;
511 bool m_facesRTreeRequiresUpdate =
true;
512 bool m_administrationRequired =
true;
513 std::unordered_map<Location, std::unique_ptr<RTreeBase>> m_RTrees;
517 void SetUnConnectedNodesAndEdgesToInvalid(CompoundUndoAction* undoAction);
523 void FindConnectedNodes(std::vector<bool>& connectedNodes,
524 UInt& numInvalidEdges)
const;
527 void InvalidateUnConnectedNodes(
const std::vector<bool>& connectedNodes,
528 UInt& numInvalidNodes,
529 CompoundUndoAction* undoAction =
nullptr);
540 if (index >= GetNumNodes())
545 return m_nodes[index];
551 m_nodesRTreeRequiresUpdate =
true;
552 m_edgesRTreeRequiresUpdate =
true;
553 m_facesRTreeRequiresUpdate =
true;
554 m_administrationRequired =
true;
559 if (index >= GetNumEdges())
564 return m_edges[index];
569 if (index >= GetNumEdges())
574 m_administrationRequired =
true;
575 m_edges[index] = edge;
586 m_nodesRTreeRequiresUpdate =
true;
587 m_edgesRTreeRequiresUpdate =
true;
588 m_facesRTreeRequiresUpdate =
true;
589 m_administrationRequired =
true;
594 return m_administrationRequired;
std::vector< Point > m_edgesCenters
The edges centers.
Definition: Mesh.hpp:476
UInt FindCommonNode(UInt firstEdgeIndex, UInt secondEdgeIndex) const
Find the common node two edges share This method uses return parameters since the success is evaluate...
std::unique_ptr< DeleteEdgeAction > DeleteEdge(UInt edge)
Deletes an edge.
Projection
Enumerator describing the supported projections.
Definition: Definitions.hpp:41
std::vector< std::array< UInt, 2 > > m_edgesFaces
For each edge, the shared face index (lne)
Definition: Mesh.hpp:473
void SortEdgesInCounterClockWiseOrder(UInt startNode, UInt endNode)
Sort mesh edges around a node in counterclockwise order (Sort_links_ccw)
const std::vector< Edge > & Edges() const
Get all edges.
Definition: Mesh.hpp:578
std::unique_ptr< UndoAction > Join(const Mesh &rhs)
Add meshes: result is a mesh composed of the additions firstMesh += secondmesh results in the second ...
std::vector< UInt > GetValidEdgeMapping() const
Get the mapping/indexing from the edge array mapped to valid edges.
void SetEdge(const UInt index, const Edge &edge)
Set the edge to a new value, bypassing the undo action.
Definition: Mesh.hpp:567
std::vector< double > m_faceArea
The face area.
Definition: Mesh.hpp:484
double ComputeMinEdgeLength(const Polygons &polygon) const
Compute the minimum edge length of the edges included in the polygon. An edge is considered included ...
void DeleteInvalidNodesAndEdges()
Removes all invalid nodes and edges.
std::vector< bool > IsLocationInPolygon(const Polygons &polygon, Location location) const
Computes if a location is in polygon.
const std::vector< Point > & Nodes() const
Get vector of all nodes.
Definition: Mesh.hpp:533
UInt GetEdgeIndex(const UInt elementId, const UInt edgeId) const
Get the local edge number for an element edge.
std::vector< UInt > m_nodesNumEdges
For each node, the number of connected edges (nmk)
Definition: Mesh.hpp:468
void RestoreAction(const ResetNodeAction &undoAction)
Undo the reset node action.
static constexpr UInt m_maximumNumberOfConnectedNodes
Maximum number of connected nodes.
Definition: Mesh.hpp:492
std::vector< Edge > m_edges
The edges, defined as first and second node(kn)
Definition: Mesh.hpp:503
virtual void Administrate(CompoundUndoAction *undoAction=nullptr)
Perform complete administration.
std::vector< Point > m_facesCircumcenters
The face circumcenters the face circumcenter (xz, yz)
Definition: Mesh.hpp:482
void SetNodesRTreeRequiresUpdate(bool value)
Set the m_nodesRTreeRequiresUpdate flag.
Definition: Mesh.hpp:456
auto GetNumNodes() const
Get the number of valid nodes.
Definition: Mesh.hpp:145
Mesh()
Default constructor, setting a cartesian projection.
A class derived from Mesh, which describes unstructures 2d meshes.
Definition: Mesh2D.hpp:55
Type
Enumerator describing the different mesh types.
Definition: Mesh.hpp:102
void ComputeEdgesCenters()
Computes the edges centers in one go.
bool IsValidEdge(const UInt edgeId) const
Indicate if the edge-id is a valid edge.
A class defining a bounding box.
Definition: BoundingBox.hpp:39
std::unique_ptr< ResetEdgeAction > ResetEdge(UInt edgeId, const Edge &edge)
Change the nodes referenced by the edge.
virtual ~Mesh()=default
Define virtual destructor.
void SetAdministrationRequired(const bool value)
Determine if a administration is required.
static constexpr UInt m_maximumNumberOfEdgesPerNode
Maximum number of edges per node.
Definition: Mesh.hpp:489
A struct describing a point in a two-dimensional space.
Definition: Point.hpp:40
double ComputeMaxLengthSurroundingEdges(UInt node)
Compute the max length of the edges connected to a node.
auto GetNumFaceEdges(UInt faceIndex) const
Get the number of edges for a face.
Definition: Mesh.hpp:166
std::vector< UInt > m_numFacesNodes
The number of nodes composing the face (netcellN)
Definition: Mesh.hpp:480
void BuildTree(Location location, const BoundingBox &boundingBox={})
Build the rtree for the corresponding location, using only the locations inside the bounding box.
void ComputeEdgesLengths()
Compute the lengths of all edges in one go.
bool NodeAdministration()
Node administration (setnodadmin)
std::unique_ptr< UndoAction > MergeNodesInPolygon(const Polygons &polygons, double mergingDistance)
Merge close mesh nodes inside a polygon (MERGENODESINPOLYGON)
Location
Mesh locations enumeration.
Definition: Definitions.hpp:74
std::vector< double > m_edgeLengths
The edge lengths.
Definition: Mesh.hpp:475
const Point & Node(const UInt index) const
Get the node at the position.
Definition: Mesh.hpp:538
const Edge & GetEdge(const UInt index) const
Get constant reference to an edge.
Definition: Mesh.hpp:557
bool AdministrationRequired() const
Determine if a administration is required.
Definition: Mesh.hpp:592
UInt GetNumValidEdges() const
Get the number of valid edges.
bool IsEdgeOnBoundary(UInt edge) const
Inquire if an edge is on boundary.
Definition: Mesh.hpp:184
std::vector< std::vector< UInt > > m_facesEdges
The edge indices composing the face (netcelllin)
Definition: Mesh.hpp:481
std::unique_ptr< UndoAction > MergeTwoNodes(UInt startNode, UInt endNode)
Merges two mesh nodes.
void SetNodes(const std::vector< Point > &newValues)
Set all nodes to a new set of values.
Definition: Mesh.hpp:548
UInt GetNumValidNodes() const
Get the number of valid nodes.
void SetFacesRTreeRequiresUpdate(bool value)
Set the m_facesRTreeRequiresUpdate flag.
Definition: Mesh.hpp:464
std::unique_ptr< UndoAction > MoveNode(Point newPoint, UInt nodeindex)
Move a node to a new location.
bool IsNodeOnBoundary(UInt node) const
Inquire if a node is on boundary.
Definition: Mesh.hpp:141
Projection m_projection
The projection used.
Definition: Mesh.hpp:486
std::vector< Point > m_facesMassCenters
The faces centers of mass (xzw, yzw)
Definition: Mesh.hpp:483
void SetEdges(const std::vector< Edge > &newValues)
Set all edges to a new set of values.
Definition: Mesh.hpp:583
UInt FindEdgeWithLinearSearch(UInt firstNodeIndex, UInt secondNodeIndex) const
Find the edge using a linear search, without connectivity information (much slower than FindEdge)
UInt GetNodeIndex(const UInt elementId, const UInt nodeId) const
Get the local node number for an element node.
UInt FindEdge(UInt firstNodeIndex, UInt secondNodeIndex) const
Find the edge sharing two nodes.
bool IsFaceOnBoundary(UInt face) const
Inquire if a face is on boundary.
auto GetNumEdgesFaces(UInt edgeIndex) const
Get the number of faces an edges shares.
Definition: Mesh.hpp:171
Contains the logic of the C++ static library.
Definition: AveragingInterpolation.hpp:36
std::vector< UInt > m_edgesNumFaces
For each edge, the number of shared faces(lnn)
Definition: Mesh.hpp:474
std::vector< std::vector< UInt > > m_nodesNodes
For each node, its neighbors.
Definition: Mesh.hpp:469
auto GetNumFaces() const
Get the number of valid faces.
Definition: Mesh.hpp:153
static constexpr UInt m_maximumNumberOfNodesPerFace
Maximum number of nodes per face.
Definition: Mesh.hpp:491
std::unique_ptr< ResetNodeAction > ResetNode(const UInt index, const Point &newValue)
Set the node to a new value, this value may be the in-valid value.
UInt FindNodeCloseToAPoint(Point const &point, double searchRadius)
Get the index of a node close to a point.
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition: Definitions.hpp:38
std::unique_ptr< DeleteNodeAction > DeleteNode(UInt node)
Deletes a node and removes any connected edges.
void AdministrateNodesEdges(CompoundUndoAction *undoAction=nullptr)
Perform node and edges administration.
A class containing a list of polygonaly enclosed regions.
Definition: Polygons.hpp:44
std::vector< UInt > GetValidNodeMapping() const
Get the mapping/indexing from the node array mapped to valid nodes.
std::pair< UInt, UInt > Edge
Describes an edge with two indices.
Definition: Entities.hpp:50
RTreeBase & GetRTree(Location location) const
Get a reference to the RTree for a specific location.
Definition: Mesh.hpp:452
UInt GetLocalFaceNodeIndex(const UInt faceIndex, const UInt nodeIndex) const
Get the local index of the node belong to a face.
static constexpr UInt m_maximumNumberOfEdgesPerFace
Maximum number of edges per face.
Definition: Mesh.hpp:490
void CommitAction(const ResetNodeAction &undoAction)
Apply the reset node action.
void SetNode(const UInt index, const Point &newValue)
Set a node to a new value, bypassing the undo action.
Mesh & operator+=(Mesh const &rhs)
Add meshes: result is a mesh composed of the additions firstMesh += secondmesh results in the second ...
UInt FindLocationIndex(Point point, Location location, const std::vector< bool > &locationMask={}, const BoundingBox &boundingBox={})
Get the index of a location (node/edge or face) close to a point.
std::tuple< UInt, std::unique_ptr< AddEdgeAction > > ConnectNodes(UInt startNode, UInt endNode)
Connect two existing nodes, checking if the nodes are already connected. If the nodes are not connect...
std::vector< Point > m_nodes
The mesh nodes (xk, yk)
Definition: Mesh.hpp:502
std::tuple< UInt, std::unique_ptr< AddNodeAction > > InsertNode(const Point &newPoint)
Insert a new node in the mesh (setnewpoint)
Mesh & operator=(const Mesh &mesh)=delete
Delete assignment operator.
std::vector< int > m_nodesTypes
The node types (nb)
Definition: Mesh.hpp:470
std::vector< Point > ComputeLocations(Location location) const
Computes a vector with the mesh locations coordinates (nodes, edges or faces coordinates).
An exception class thrown when an attempt is made that violates a range constraint.
Definition: Exceptions.hpp:266
void SetEdgesRTreeRequiresUpdate(bool value)
Set the m_edgesRTreeRequiresUpdate flag.
Definition: Mesh.hpp:460
A class describing an unstructured mesh. This class contains the shared functionality between 1d or 2...
Definition: Mesh.hpp:98
std::vector< std::vector< UInt > > m_nodesEdges
For each node, the indices of connected edges (nodlin)
Definition: Mesh.hpp:467
std::vector< std::vector< UInt > > m_facesNodes
The nodes composing the faces, in ccw order (netcellNod)
Definition: Mesh.hpp:479
auto GetNumEdges() const
Get the number of valid edges.
Definition: Mesh.hpp:149