Loading [MathJax]/extensions/tex2jax.js
MeshKernel
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages Concepts
Splines.hpp
1//---- GPL ---------------------------------------------------------------------
2//
3// Copyright (C) Stichting Deltares, 2011-2021.
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation version 3.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17// contact: delft3d.support@deltares.nl
18// Stichting Deltares
19// P.O. Box 177
20// 2600 MH Delft, The Netherlands
21//
22// All indications and logos of, and references to, "Delft3D" and "Deltares"
23// are registered trademarks of Stichting Deltares, and remain the property of
24// Stichting Deltares. All rights reserved.
25//
26//------------------------------------------------------------------------------
27
28#pragma once
29
30#include "MeshKernel/BoundingBox.hpp"
31#include "MeshKernel/Constants.hpp"
32#include "MeshKernel/Entities.hpp"
33#include "MeshKernel/LandBoundary.hpp"
34#include "MeshKernel/Operations.hpp"
35#include "MeshKernel/Utilities/LinearAlgebra.hpp"
36
37namespace meshkernel
38{
39 class CurvilinearGrid;
40
47 class Splines
48 {
49
50 public:
52 Splines() = default;
53
56 explicit Splines(Projection projection);
57
60 explicit Splines(CurvilinearGrid const& grid);
61
66 // void AddSpline(const std::vector<Point>& splines, UInt start, UInt size);
67 void AddSpline(const std::vector<Point>& splines, UInt start, UInt size);
68
71 void AddSpline(const std::vector<Point>& splines);
72
76 void Replace(const UInt splineIndex, const std::vector<Point>& splinePoints);
77
81 void SwapSplines(const UInt firstSpline, const UInt secondSpline);
82
84 void Reverse(const UInt splineId);
85
91 void SnapSpline(const size_t splineIndex,
92 const LandBoundary& landBoundary,
93 const int numberOfIterations = constants::numeric::defaultSnappingIterations);
94
104 UInt second,
105 double& crossProductIntersection,
106 Point& intersectionPoint,
107 double& firstSplineRatio,
108 double& secondSplineRatio) const;
109
119 [[nodiscard]] double ComputeSplineLength(UInt index,
120 double startAdimensionalCoordinate,
121 double endAdimensionalCoordinate,
122 UInt numSamples = 100,
123 bool accountForCurvature = false,
124 double height = 1.0,
125 double assignedDelta = -1.0) const;
126
133 std::tuple<std::vector<Point>, std::vector<double>> ComputePointOnSplineFromAdimensionalDistance(UInt index,
134 double maximumGridHeight,
135 bool isSpacingCurvatureAdapted,
136 const std::vector<double>& distances) const;
137
144 Point ComputeClosestPointOnSplineSegment(UInt index, double startSplineSegment, double endSplineSegment, Point point) const;
145
150 Point ComputeClosestPoint(UInt index, Point point) const;
151
156 Point Evaluate(const UInt whichSpline, const double lambda) const;
157
159 BoundingBox GetBoundingBox(const UInt splineIndex) const;
160
163 auto GetNumSplines() const { return static_cast<UInt>(m_splineNodes.size()); }
164
167 UInt Size(const UInt whichSpline) const;
168
171
172 std::vector<std::vector<Point>> m_splineNodes;
173 std::vector<std::vector<Point>> m_splineDerivatives;
174 std::vector<double> m_splinesLength;
175 Projection m_projection = Projection::cartesian;
176
177 private:
181 void AddPointInExistingSpline(UInt splineIndex, const Point& point);
182
187 std::tuple<Point, Point, double> ComputeCurvatureOnSplinePoint(UInt splineIndex,
188 double adimensionalPointCoordinate) const;
189
192 void DeleteSpline(UInt splineIndex);
193
195 void AllocateSplinesProperties();
196
198 static std::vector<Point> ComputeSplineDerivative(const std::vector<Point>& splinesNodes);
199 };
200
203 {
210 UInt splineIndex,
211 bool isSpacingCurvatureAdapted,
212 double h) : m_spline(splines),
213 m_splineIndex(splineIndex),
214 m_isSpacingCurvatureAdapted(isSpacingCurvatureAdapted),
215 m_h(h) {}
216
224 UInt splineIndex,
225 bool isSpacingCurvatureAdapted,
226 double h,
227 double distance) : m_spline(splines),
228 m_splineIndex(splineIndex),
229 m_isSpacingCurvatureAdapted(isSpacingCurvatureAdapted),
230 m_h(h),
231 m_DimensionalDistance(distance) {}
232
235 void SetDimensionalDistance(double distance)
236 {
237 m_DimensionalDistance = distance;
238 }
239
241 double operator()(double adimensionalDistanceReferencePoint) const
242 {
243 auto distanceFromReferencePoint = m_spline.ComputeSplineLength(m_splineIndex, 0.0, adimensionalDistanceReferencePoint, m_numSamples, m_isSpacingCurvatureAdapted, m_h, 0.1);
244 distanceFromReferencePoint = std::abs(distanceFromReferencePoint - m_DimensionalDistance);
245 return distanceFromReferencePoint;
246 }
247
251 double m_h;
254 };
255
258 {
264 UInt splineIndex,
265 Point point) : m_spline(splines),
266 m_splineIndex(splineIndex),
267 m_point(point) {}
268
270 double operator()(double adimensionalDistanceReferencePoint) const
271 {
272 const auto pointOnSpline = ComputePointOnSplineAtAdimensionalDistance(m_spline.m_splineNodes[m_splineIndex], m_spline.m_splineDerivatives[m_splineIndex], adimensionalDistanceReferencePoint);
273 return ComputeDistance(m_point, pointOnSpline, Projection::cartesian);
274 }
275
280 };
281
282} // namespace meshkernel
A class defining a bounding box.
Definition BoundingBox.hpp:40
A class containing the land boundary polylines.
Definition LandBoundary.hpp:40
A struct describing a point in a two-dimensional space.
Definition Point.hpp:41
A class describing splines.
Definition Splines.hpp:48
std::vector< std::vector< Point > > m_splineDerivatives
The spline derivatives at the corner points.
Definition Splines.hpp:173
UInt Size(const UInt whichSpline) const
Get the size of a specific spline.
void AddSpline(const std::vector< Point > &splines)
Adds a new spline to m_splineCornerPoints.
UInt MaxSizeIndex() const
Get the index of the spline with the largest number of spline points.
void Replace(const UInt splineIndex, const std::vector< Point > &splinePoints)
Replaces an existing spline.
void SnapSpline(const size_t splineIndex, const LandBoundary &landBoundary, const int numberOfIterations=constants::numeric::defaultSnappingIterations)
Snap the spline to the land boundary (snap_spline)
BoundingBox GetBoundingBox(const UInt splineIndex) const
Compute the boundary box for the spline indicated by splineIndex.
void Reverse(const UInt splineId)
Reverse the order of the points in the spline.
auto GetNumSplines() const
Get the number of splines.
Definition Splines.hpp:163
Splines()=default
Default constructor.
bool GetSplinesIntersection(UInt first, UInt second, double &crossProductIntersection, Point &intersectionPoint, double &firstSplineRatio, double &secondSplineRatio) const
Computes the intersection of two splines (sect3r)
void AddSpline(const std::vector< Point > &splines, UInt start, UInt size)
Adds a new spline to m_splineCornerPoints.
Point Evaluate(const UInt whichSpline, const double lambda) const
Computes the coordinate of a point on a spline, given the dimensionless distance from the first corne...
std::vector< double > m_splinesLength
The length of each spline.
Definition Splines.hpp:174
Point ComputeClosestPoint(UInt index, Point point) const
Computes the point on a spline segment which is the closest to another point.
Projection m_projection
The map projection.
Definition Splines.hpp:175
std::vector< std::vector< Point > > m_splineNodes
The spline corner points.
Definition Splines.hpp:172
std::tuple< std::vector< Point >, std::vector< double > > ComputePointOnSplineFromAdimensionalDistance(UInt index, double maximumGridHeight, bool isSpacingCurvatureAdapted, const std::vector< double > &distances) const
Compute the points on a spline lying at certain distance.
Splines(Projection projection)
Ctor, set projection.
Splines(CurvilinearGrid const &grid)
Ctor from grids, each gridline is converted to spline, first the first m_n horizontal lines then the ...
Point ComputeClosestPointOnSplineSegment(UInt index, double startSplineSegment, double endSplineSegment, Point point) const
Computes the point on a spline segment which is the closest to another point.
double ComputeSplineLength(UInt index, double startAdimensionalCoordinate, double endAdimensionalCoordinate, UInt numSamples=100, bool accountForCurvature=false, double height=1.0, double assignedDelta=-1.0) const
Computes the spline length in s coordinates (GETDIS)
void SwapSplines(const UInt firstSpline, const UInt secondSpline)
Swap all the data for two splines.
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
Projection
Enumerator describing the supported projections.
Definition Definitions.hpp:43
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
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition Definitions.hpp:39
double ComputeDistance(const Point &firstPoint, const Point &secondPoint, const Projection &projection)
Computes the distance between two points (dbdistance)
This structure is used to create a function for converting an adimensional distance on a spline to a ...
Definition Splines.hpp:203
bool m_isSpacingCurvatureAdapted
Is spacing curvature adapted.
Definition Splines.hpp:250
double operator()(double adimensionalDistanceReferencePoint) const
This is the function we want to find the root of.
Definition Splines.hpp:241
FuncAdimensionalToDimensionalDistanceOnSpline(const Splines &splines, UInt splineIndex, bool isSpacingCurvatureAdapted, double h, double distance)
Constructor.
Definition Splines.hpp:223
double m_DimensionalDistance
Dimensional distance.
Definition Splines.hpp:253
void SetDimensionalDistance(double distance)
Set dimensional distance.
Definition Splines.hpp:235
double m_h
When accounting for curvature, the height to use.
Definition Splines.hpp:251
UInt m_splineIndex
Spline index.
Definition Splines.hpp:249
const Splines & m_spline
Reference to splines.
Definition Splines.hpp:248
FuncAdimensionalToDimensionalDistanceOnSpline(const Splines &splines, UInt splineIndex, bool isSpacingCurvatureAdapted, double h)
Constructor.
Definition Splines.hpp:209
UInt m_numSamples
Number of samples.
Definition Splines.hpp:252
This structure is used to compute the point on a spline closest to another point.
Definition Splines.hpp:258
double m_DimensionalDistance
Dimensional distance.
Definition Splines.hpp:279
double operator()(double adimensionalDistanceReferencePoint) const
This is the function we want to find the root of.
Definition Splines.hpp:270
Point m_point
The point from where the distance is calculated.
Definition Splines.hpp:278
UInt m_splineIndex
Spline index.
Definition Splines.hpp:277
const Splines & m_spline
Reference to splines.
Definition Splines.hpp:276
FuncDistanceFromAPoint(const Splines &splines, UInt splineIndex, Point point)
Constructor.
Definition Splines.hpp:263