Skip to content

Commit

Permalink
GRIDEDIT-1244 Copied code to other computer
Browse files Browse the repository at this point in the history
  • Loading branch information
BillSenior committed Jun 27, 2024
1 parent ef2c3ff commit 1d77b7c
Show file tree
Hide file tree
Showing 8 changed files with 1,008 additions and 87 deletions.
2 changes: 2 additions & 0 deletions libs/MeshKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ set(
${SRC_DIR}/SplineAlgorithms.cpp
${SRC_DIR}/Splines.cpp
${SRC_DIR}/SplitRowColumnOfMesh.cpp
${SRC_DIR}/SplitRowColumnOfMesh2.cpp
${SRC_DIR}/TriangulationInterpolation.cpp
${SRC_DIR}/TriangulationWrapper.cpp
)
Expand Down Expand Up @@ -178,6 +179,7 @@ set(
${DOMAIN_INC_DIR}/SplineAlgorithms.hpp
${DOMAIN_INC_DIR}/Splines.hpp
${DOMAIN_INC_DIR}/SplitRowColumnOfMesh.hpp
${DOMAIN_INC_DIR}/SplitRowColumnOfMesh2.hpp
${DOMAIN_INC_DIR}/TriangulationInterpolation.hpp
${DOMAIN_INC_DIR}/TriangulationWrapper.hpp
${DOMAIN_INC_DIR}/Vector.hpp
Expand Down
2 changes: 1 addition & 1 deletion libs/MeshKernel/include/MeshKernel/Operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace meshkernel
return constants::missing::uintValue;
}

return current == 0 ? vec.size() - 1 : current - 1;
return current == 0 ? static_cast<UInt>(vec.size()) - 1 : current - 1;
}

/// @brief Find all start-end positions in a vector separated by a separator
Expand Down
78 changes: 78 additions & 0 deletions libs/MeshKernel/include/MeshKernel/SplitRowColumnOfMesh2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//---- GPL ---------------------------------------------------------------------
//
// Copyright (C) Stichting Deltares, 2011-2024.
//
// 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 <array>
#include <utility>
#include <vector>

#include "MeshKernel/Definitions.hpp"
#include "MeshKernel/Mesh2D.hpp"
#include "MeshKernel/UndoActions/CompoundUndoAction.hpp"
#include "MeshKernel/UndoActions/UndoAction.hpp"

namespace meshkernel
{
class SplitRowColumnOfMesh2 final
{
public:
[[nodiscard]] std::unique_ptr<UndoAction> Compute(Mesh2D& mesh, const UInt edgeId) const;

private:
struct SplittingInfo
{
UInt elementId;
UInt localStartEdgeId;
UInt localEndEdgeId;
UInt startEdgeId;
UInt endEdgeId;
};

void SplitEdge(Mesh2D& mesh, const UInt edgeId, CompoundUndoAction& undoActions) const;

void SplitEdges(Mesh2D& mesh, std::vector<UInt>& elementIds, std::vector<UInt>& edgeIds, CompoundUndoAction& undoActions) const;

void SplitEdge(Mesh2D& mesh, UInt elementId, UInt edgeId, UInt& previousNewNode, CompoundUndoAction& undoActions) const;

void SplitEdge2(Mesh2D& mesh, UInt elementId, UInt edgeId, UInt& previousNewNode, CompoundUndoAction& undoActions) const;

void SplitEdge3(Mesh2D& mesh, UInt elementId, UInt edgeId, UInt& previousNewNode, CompoundUndoAction& undoActions, std::vector<UInt>& edgesToDelete) const;

bool IsValidEdge(const Mesh2D& mesh, const UInt edgeId) const;

/// @brief Determine if it may be possible to split the edge
///
/// If two element attached to edge then both must be quadrilaterals,
/// otherwise the sole attached elememt must be quadrilateral

Check failure on line 70 in libs/MeshKernel/include/MeshKernel/SplitRowColumnOfMesh2.hpp

View workflow job for this annotation

GitHub Actions / Codespell Check

elememt ==> element
bool MayBeSplit(const Mesh2D& mesh, const UInt edgeId) const;

void CollectElementIdsToSplit(const Mesh2D& mesh, const UInt edgeId, std::vector<UInt>& elementIds, std::vector<UInt>& edgeIds) const;

void GetNextElement(const Mesh2D& mesh, UInt& edgeId, UInt& elementId) const;
};

} // namespace meshkernel
8 changes: 5 additions & 3 deletions libs/MeshKernel/src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ meshkernel::UInt Mesh::FindEdge(UInt firstNodeIndex, UInt secondNodeIndex) const
{
if (firstNodeIndex == constants::missing::uintValue || secondNodeIndex == constants::missing::uintValue)
{
throw std::invalid_argument("Mesh::FindEdge: Invalid node index.");
throw ConstraintError("Mesh::FindEdge: Invalid node index: first {}, second {}", firstNodeIndex, secondNodeIndex);
}

for (UInt n = 0; n < m_nodesNumEdges[firstNodeIndex]; n++)
Expand Down Expand Up @@ -1044,9 +1044,11 @@ meshkernel::UInt Mesh::GetEdgeIndex(const UInt elementId, const UInt edgeId) con
throw ConstraintError("Element id is greater than the number of elements: {} >= {}", elementId, GetNumFaces());
}

if (edgeId >= GetNumValidEdges())
if (edgeId >= GetNumEdges())
// if (edgeId >= GetNumValidEdges())
{
throw ConstraintError("edge id is greater than the number of edges: {} >= {}", edgeId, GetNumValidEdges());
throw ConstraintError("edge id is greater than the number of edges: {} >= {}", edgeId, GetNumEdges());
// throw ConstraintError("edge id is greater than the number of edges: {} >= {}", edgeId, GetNumValidEdges());
}

const std::vector<UInt>& edgeIds = m_facesEdges[elementId];
Expand Down
2 changes: 1 addition & 1 deletion libs/MeshKernel/src/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace meshkernel
Point sphericalPoint;
const double angle = atan2(cartesianPoint.y, cartesianPoint.x) * constants::conversion::radToDeg;
sphericalPoint.y = atan2(cartesianPoint.z, sqrt(cartesianPoint.x * cartesianPoint.x + cartesianPoint.y * cartesianPoint.y)) * constants::conversion::radToDeg;
sphericalPoint.x = angle + std::lround((referenceLongitude - angle) / 360.0) * 360.0;
sphericalPoint.x = angle + static_cast<double>(std::lround((referenceLongitude - angle) / 360.0)) * 360.0;
return sphericalPoint;
}

Expand Down
4 changes: 2 additions & 2 deletions libs/MeshKernel/src/Polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ void meshkernel::Polygon::RefineSegment(std::vector<meshkernel::Point>& refinedP
refinedPolygon.push_back(n0);

const double segmentLength = ComputeDistance(n0, n1, projection);
int n = std::lround(segmentLength / refinementDistance);
long int n = std::lround(segmentLength / refinementDistance);

for (int i = 1; i < n; ++i)
for (long int i = 1; i < n; ++i)
{
double lambda = static_cast<double>(i) / static_cast<double>(n);
refinedPolygon.push_back((1.0 - lambda) * n0 + lambda * n1);
Expand Down
Loading

0 comments on commit 1d77b7c

Please sign in to comment.