35#include "MeshKernel/BoundingBox.hpp"
36#include "MeshKernel/Constants.hpp"
37#include "MeshKernel/Entities.hpp"
38#include "MeshKernel/Utilities/LinearAlgebra.hpp"
39#include "MeshKernel/Utilities/RTreeBase.hpp"
40#include "MeshKernel/Vector.hpp"
52 void ResizeAndFill2DVector(std::vector<std::vector<T>>& v,
UInt const& firstDimension,
UInt const& secondDimension,
bool fill =
false,
const T& fillValue = {})
54 v.resize(firstDimension);
57 e.resize(secondDimension);
60 std::fill(e.begin(), e.end(), fillValue);
52 void ResizeAndFill2DVector(std::vector<std::vector<T>>& v,
UInt const& firstDimension,
UInt const& secondDimension,
bool fill =
false,
const T& fillValue = {}) {
…}
74 void ResizeAndFill3DVector(std::vector<std::vector<std::vector<T>>>& v,
UInt const& firstDimension,
UInt const& secondDimension,
UInt const& thirdDim,
bool fill =
false,
const T& fillValue = {})
76 v.resize(firstDimension);
79 e.resize(secondDimension);
85 std::fill(ee.begin(), ee.end(), fillValue);
74 void ResizeAndFill3DVector(std::vector<std::vector<std::vector<T>>>& v,
UInt const& firstDimension,
UInt const& secondDimension,
UInt const& thirdDim,
bool fill =
false,
const T& fillValue = {}) {
…}
98 for (
UInt n = 0; n < vec.size(); n++)
106 return constants::missing::uintValue;
110 template <
typename T>
113 if (vec.size() == 0) [[unlikely]]
115 return constants::missing::uintValue;
118 return current == vec.size() - 1 ? 0 : current + 1;
122 template <
typename T>
125 if (vec.size() == 0) [[unlikely]]
127 return constants::missing::uintValue;
130 return current == 0 ?
static_cast<UInt>(vec.size()) - 1 : current - 1;
139 std::vector<std::pair<UInt, UInt>>
FindIndices(
const std::vector<Point>& vec,
size_t start,
size_t end,
double separator);
153 template <
typename T>
156 std::vector<UInt> indices(v.size());
157 iota(indices.begin(), indices.end(), 0);
158 std::ranges::stable_sort(indices.begin(), indices.end(), [&v](
UInt i1,
UInt i2)
159 { return v[i1] < v[i2]; });
167 template <
typename T>
170 std::vector<T> ordered;
171 ordered.reserve(v.size());
172 for (
const auto& value : order)
174 ordered.emplace_back(v[value]);
184 template <
typename F>
188 const double c = 0.38196602;
189 const double r = 0.61803399;
190 const double tolerance = 1e-5;
193 double middle = (min + max) * 0.5;
197 double x1 = middle - c * (middle - left);
200 if (std::abs(right - middle) > std::abs(middle - left))
203 x2 = middle + c * (right - left);
206 double f1 = func(x1);
207 double f2 = func(x2);
209 while (std::abs(x3 - x0) > tolerance * std::max(std::abs(x1) + std::abs(x2), 1e-8))
215 x2 = r * x1 + c * x3;
224 x1 = r * x2 + c * x0;
231 return f1 < f2 ? x1 : x2;
269 const std::vector<Point>& polygonNodes,
271 Point polygonCenter = {constants::missing::doubleValue, constants::missing::doubleValue},
272 UInt startNode = constants::missing::uintValue,
273 UInt endNode = constants::missing::uintValue);
285 const std::vector<Point>& polygonNodes,
288 Point polygonCenter = {constants::missing::doubleValue, constants::missing::doubleValue},
289 UInt startNode = constants::missing::uintValue,
290 UInt endNode = constants::missing::uintValue);
298 const std::span<const Point> triangleNodes,
335 const Point& firstPointSecondSegment,
const Point& secondPointSecondSegment,
const Projection& projection);
400 const std::vector<UInt>& polygonIndices,
457 const std::vector<UInt>& edgesNumFaces,
459 std::array<Point, constants::geometric::maximumNumberOfNodesPerFace>& middlePoints,
460 std::array<Point, constants::geometric::maximumNumberOfNodesPerFace>& normals,
466 const UInt pointCount,
467 const std::array<Point, constants::geometric::maximumNumberOfNodesPerFace>& middlePoints,
468 const std::array<Point, constants::geometric::maximumNumberOfNodesPerFace>& normals,
473 const std::vector<UInt>& edgesNumFaces,
490 const Point& firstSegmentSecondPoint,
491 const Point& secondSegmentFirstPoint,
492 const Point& secondSegmentSecondPoint,
493 bool adimensionalCrossProduct,
501 template <
typename T>
503 const std::vector<T>& coordinatesDerivatives,
504 double pointAdimensionalCoordinate)
507 if (pointAdimensionalCoordinate < 0)
509 return pointCoordinate;
512 const double eps = 1e-5;
513 const double splFac = 1.0;
514 const auto coordinate = std::floor(pointAdimensionalCoordinate);
516 if (pointAdimensionalCoordinate - coordinate < eps)
518 return pointCoordinate = coordinates[
static_cast<UInt>(coordinate)];
521 const UInt low =
static_cast<UInt>(coordinate);
522 const UInt high = low + 1;
523 const double a = high - pointAdimensionalCoordinate;
524 const double b = pointAdimensionalCoordinate - low;
526 pointCoordinate = coordinates[low] * a + coordinates[high] * b +
527 (coordinatesDerivatives[low] * (pow(a, 3) - a) + coordinatesDerivatives[high] * (pow(b, 3) - b)) / 6.0 * splFac;
529 return pointCoordinate;
542 template <
typename T>
543 [[nodiscard]]
int sgn(T val)
545 return (T(0) < val ? 1 : 0) - (val < T(0) ? 1 : 0);
543 [[nodiscard]]
int sgn(T val) {
…}
558 const std::vector<Point>& rightDiscretization,
559 const std::vector<Point>& bottomDiscretization,
560 const std::vector<Point>& upperDiscretization,
569 [[nodiscard]] std::vector<Point>
ComputeEdgeCenters(
const std::vector<Point>& nodes,
const std::vector<Edge>& edges);
592 Point const& secondNode,
593 Point const& pointToProject);
625 [[nodiscard]]
double MatrixNorm(
const std::vector<double>& x,
const std::vector<double>& y,
const std::vector<double>& matCoefficients);
630 if (value != constants::missing::uintValue) [[likely]]
A class defining a bounding box.
Definition BoundingBox.hpp:40
A struct describing a point in a two-dimensional space.
Definition Point.hpp:41
A class defining a vector.
Definition Vector.hpp:39
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
UInt NextCircularForwardIndex(UInt currentIndex, UInt size)
Get the next forward index, for a range in 0 .. size-1.
Point ComputeAverageCoordinate(const std::span< const Point > points, const Projection &projection)
Given a series of point computes the average coordinate.
void AddIncrementToPoint(const Point &normal, double increment, const Point &referencePoint, const Projection &projection, Point &point)
Moves a point by adding an increment vector to it.
double GetDy(const Point &firstPoint, const Point &secondPoint, const Projection &projection)
Gets dy for the given projection.
Projection
Enumerator describing the supported projections.
Definition Definitions.hpp:43
Point ComputeCircumCenter(const Point ¢erOfMass, const UInt pointCount, const std::array< Point, constants::geometric::maximumNumberOfNodesPerFace > &middlePoints, const std::array< Point, constants::geometric::maximumNumberOfNodesPerFace > &normals, const Projection &projection)
Compute circumcenter of face.
UInt FindNextIndex(const std::vector< T > &vec, UInt current)
Find the next index in the vector, wraps around when current is the last index.
Definition Operations.hpp:111
Vector GetDelta(const Point &firstPoint, const Point &secondPoint, const Projection &projection)
Get the delta (dx, dy) for the given projection.
Point ReferencePoint(const std::vector< Point > &polygon, const Projection &projection)
For a given polygon compute a reference point.
std::vector< UInt > SortedIndices(const std::vector< T > &v)
Sort a vector and return the sorted indices.
Definition Operations.hpp:154
bool IsPointInPolygonNodes(const Point &point, const std::vector< Point > &polygonNodes, const Projection &projection, Point polygonCenter={constants::missing::doubleValue, constants::missing::doubleValue}, UInt startNode=constants::missing::uintValue, UInt endNode=constants::missing::uintValue)
Checks if a point is in polygonNodes using the winding number method.
void ComputeThreeBaseComponents(const Point &point, std::array< double, 3 > &exxp, std::array< double, 3 > &eyyp, std::array< double, 3 > &ezzp)
Computes three base components.
double ComputeSquaredDistance(const Point &firstPoint, const Point &secondPoint, const Projection &projection)
Computes the squared distance between two points This is faster than ComputeDistance because it does ...
double InnerProductTwoSegments(const Point &firstPointFirstSegment, const Point &secondPointFirstSegment, const Point &firstPointSecondSegment, const Point &secondPointSecondSegment, const Projection &projection)
Inner product of two segments (dprodin)
void ResizeAndFill3DVector(std::vector< std::vector< std::vector< T > > > &v, UInt const &firstDimension, UInt const &secondDimension, UInt const &thirdDim, bool fill=false, const T &fillValue={})
Resizes and fills a three dimensional vector.
Definition Operations.hpp:74
std::vector< Point > ComputePolyLineDiscretization(std::vector< Point > const &polyline, std::vector< double > &chainages, Projection projection)
Computes the discretization points along a polyline.
Point ComputeMiddlePointAccountingForPoles(const Point &firstPoint, const Point &secondPoint, const Projection &projection)
Computes the middle point (account for poles, latitudes close to 90 degrees)
int sgn(T val)
Computes the sign of a type.
Definition Operations.hpp:543
double LinearInterpolationInTriangle(const Point &interpolationPoint, const std::vector< Point > &polygon, const std::vector< double > &values, const Projection &projection)
Given a triangles with values on each node, computes the interpolated value inside the triangle,...
UInt NextCircularBackwardIndex(UInt currentIndex, UInt size)
Get the next backward index, for a range in 0 .. size-1.
std::tuple< std::vector< double >, double > ComputeAdimensionalDistancesFromPointSerie(const std::vector< Point > &v, const Projection &projection)
Computes dimensionless distances of a vector of points such as the first entry has distance 0 and the...
UInt AbsoluteDifference(UInt number_1, UInt number_2)
Calculates the absolute difference between to Index numbers.
double NormalizedInnerProductTwoSegments(const Point &firstPointFirstSegment, const Point &secondPointFirstSegment, const Point &firstPointSecondSegment, const Point &secondPointSecondSegment, const Projection &projection)
The normalized inner product of two segments (dcosphi)
lin_alg::Matrix< Point > DiscretizeTransfinite(const std::vector< Point > &leftDiscretization, const std::vector< Point > &rightDiscretization, const std::vector< Point > &bottomDiscretization, const std::vector< Point > &upperDiscretization, const Projection &projection, UInt numM, UInt numN)
Computes the transfinite discretization inside the area defined by 4 sides, each one discretized with...
UInt FindIndex(const std::vector< T > &vec, T el)
Find index of a certain element.
Definition Operations.hpp:96
Point NormalVector(const Point &firstPoint, const Point &secondPoint, const Point &insidePoint, const Projection &projection)
Normalized vector of a segment in direction 1 -> 2 with the insidePoint orientation.
Point CircumcenterOfTriangle(const Point &firstNode, const Point &secondNode, const Point &thirdNode, const Projection &projection)
Computes the circumcenter of a triangle.
T ComputePointOnSplineAtAdimensionalDistance(const std::vector< T > &coordinates, const std::vector< T > &coordinatesDerivatives, double pointAdimensionalCoordinate)
Computes the coordinate of a point on a spline, given the dimensionless distance from the first corne...
Definition Operations.hpp:502
UInt InvalidPointCount(const std::vector< Point > &points)
Determine if the number of invalid points in the point array.
std::vector< Point > ComputeEdgeCenters(const std::vector< Point > &nodes, const std::vector< Edge > &edges)
Computes the edge centers.
bool IsPointOnPole(const Point &point)
Determines if a point is close to the poles (latitude close to 90 degrees).
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition Definitions.hpp:39
Point ComputeMiddlePoint(const Point &firstPoint, const Point &secondPoint, const Projection &projection)
Computes the middle point.
double ComputeDistance(const Point &firstPoint, const Point &secondPoint, const Projection &projection)
Computes the distance between two points (dbdistance)
double OuterProductTwoSegments(const Point &firstPointFirstSegment, const Point &secondPointFirstSegment, const Point &firstPointSecondSegment, const Point &secondPointSecondSegment, const Projection &projection)
Outer product of two segments (dprodout)
double FindFunctionRootWithGoldenSectionSearch(F func, double min, double max)
Algorithm performing the zero's search using the golden section algorithm's.
Definition Operations.hpp:185
double crossProduct(const Point &firstSegmentFirstPoint, const Point &firstSegmentSecondPoint, const Point &secondSegmentFirstPoint, const Point &secondSegmentSecondPoint, const Projection &projection)
Computes the cross product between two segments (duitpl)
double MatrixNorm(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &matCoefficients)
Compute the matrix norm.
Vector ComputeNormalToline(const Point &start, const Point &end, const Projection projection)
Get the normal to the line described by the two points.
void ComputeMidPointsAndNormals(const std::vector< Point > &polygon, const std::vector< UInt > &edgesNumFaces, const UInt numNodes, std::array< Point, constants::geometric::maximumNumberOfNodesPerFace > &middlePoints, std::array< Point, constants::geometric::maximumNumberOfNodesPerFace > &normals, UInt &pointCount, const Projection &projection)
Compute mid point and normal of polygon segment.
auto ReorderVector(const std::vector< T > &v, const std::vector< UInt > &order)
Reorder vector accordingly to a specific order.
Definition Operations.hpp:168
void ResizeAndFill2DVector(std::vector< std::vector< T > > &v, UInt const &firstDimension, UInt const &secondDimension, bool fill=false, const T &fillValue={})
Resizes and fills a two dimensional vector.
Definition Operations.hpp:52
std::tuple< bool, Point, double, double, double > AreSegmentsCrossing(const Point &firstSegmentFirstPoint, const Point &firstSegmentSecondPoint, const Point &secondSegmentFirstPoint, const Point &secondSegmentSecondPoint, bool adimensionalCrossProduct, const Projection &projection)
Determines if two segments are crossing (cross, cross3D)
void TranslateSphericalCoordinates(std::vector< Point > &polygon)
For a given polygon the function may shift the input coordinates.
void ComputeTwoBaseComponents(const Point &point, double(&elambda)[3], double(&ephi)[3])
Computes two base components.
UInt CountNumberOfValidEdges(const std::vector< UInt > &edgesNumFaces, UInt numNodes)
Count the number of valid edges in list.
double GetDx(const Point &firstPoint, const Point &secondPoint, const Projection &projection)
Gets dx for the given projection.
bool IsPointInTriangle(const Point &point, const std::span< const Point > triangleNodes, const Projection &projection)
Checks if a point is in triangle using the winding number method.
std::tuple< double, Point, double > DistanceFromLine(const Point &point, const Point &firstNode, const Point &secondNode, const Projection &projection)
Computes the perpendicular distance of a point from a segment firstNode - secondNode (dlinedis3)
void NormalVectorInside(const Point &firstPoint, const Point &secondPoint, const Point &insidePoint, Point &normal, bool &flippedNormal, const Projection &projection)
Computes the normal vector to a line 1-2, which is outward w.r.t. an 'inside' point 3.
void TransformGlobalVectorToLocal(const Point &reference, const Point &globalCoordinates, const Point &globalComponents, const Projection &projection, Point &localComponents)
Transforms vector with components in global spherical coordinate directions(xglob,...
std::vector< double > ComputePolyLineEdgesLengths(std::vector< Point > const &polyline, Projection projection)
Computes the lengths of each polyline segment.
Point NormalVectorOutside(const Point &firstPoint, const Point &secondPoint, const Projection &projection)
Computes the normal vector outside (normalout)
std::vector< std::pair< UInt, UInt > > FindIndices(const std::vector< Point > &vec, size_t start, size_t end, double separator)
Find all start-end positions in a vector separated by a separator.
UInt FindPreviousIndex(const std::vector< T > &vec, UInt current)
Find the previous index in the vector, wraps around when current is the first index.
Definition Operations.hpp:123
void IncrementValidValue(UInt &value, const UInt increment)
Increment a valid value by an increment.
Definition Operations.hpp:628
std::vector< double > ComputePolyLineNodalChainages(std::vector< Point > const &polyline, Projection projection)
Computes the chainages of each polyline node.
std::tuple< Point, double, bool > OrthogonalProjectionOnSegment(Point const &firstNode, Point const &secondNode, Point const &pointToProject)
Cartesian projection of a point on a segment defined by other two points.
Point ComputeFaceCircumenter(std::vector< Point > &polygon, const std::vector< UInt > &edgesNumFaces, const Projection &projection)
Compute the circumcenter for the face described by the polygon.