Loading...
Searching...
No Matches
naturalnbinterpolator.h
Go to the documentation of this file.
1
35
36#ifndef OPENSWMMVIS_MESH_NATURALNBINTERPOLATOR_H
37#define OPENSWMMVIS_MESH_NATURALNBINTERPOLATOR_H
38
39#include <QPair>
40#include <QPointF>
41#include <QString>
42#include <QVector>
43
44#include <utility>
45#include <vector>
46
47namespace mesh
48{
49
59{
60public:
66 enum class Variant {
69 };
70
79
88 void setVariant(Variant v) { m_variant = v; }
94 Variant variant() const { return m_variant; }
95
119 bool build(const QVector<QPointF> &pts, const QVector<double> &z, QString *err);
120
135 bool build(const QVector<QPointF> &pts, QString *err);
136
144 bool isValid() const { return m_valid; }
145
162 double interpolate(double x, double y) const;
163
189 bool weightsAt(double x, double y, QVector<QPair<int, double>> &out) const;
190
203 const std::vector<int> &keptSeedIndices() const { return m_seedOf; }
204
205private:
226 bool computeWeights(double qx, double qy, std::vector<std::pair<int, double>> &out) const;
227
228 // Coordinates are normalised to a local [0,~1] space: translated by
229 // (-m_ox, -m_oy) (the seed bbox minimum) then divided by m_scale (the
230 // larger bbox side). This keeps orientation / in-circle / circumcenter
231 // determinants well-conditioned at projected-CRS magnitudes. z, and the
232 // Sibson (area-ratio) / Laplace (length-ratio) weights, are invariant
233 // under this affine map.
245 int locate(double qx, double qy) const; // returns triangle index or -1 (outside hull)
246
247 Variant m_variant = Variant::Sibson;
248 bool m_valid = false;
249
250 double m_ox = 0.0, m_oy = 0.0; // local-origin translation
251 double m_scale = 1.0; // normalisation scale (max bbox side)
252
253 std::vector<double> m_px, m_py, m_pz; // per Delaunay vertex (translated x,y; raw z)
254 std::vector<int> m_seedOf; // Delaunay vertex -> original input index
255 std::vector<int> m_tris; // 3 * numTri vertex indices (CCW)
256 std::vector<int> m_nbrs; // 3 * numTri neighbour tri indices (-1 = hull)
257 std::vector<double> m_ccx, m_ccy; // circumcenter per triangle (NaN if degenerate)
258 int m_numTri = 0;
259
260 mutable int m_lastTri = 0; // jump-and-walk start hint
261
262 // ── computeWeights() scratch, reused across queries ─────────────────
263 // A query used to allocate three QHashes; at a few hundred samples per
264 // subcatchment that allocation dominated rain-gage interpolation. Stamped
265 // arrays make membership tests O(1) without clearing between queries.
266 struct NbSlot {
267 int v = -1;
268 std::vector<QPointF> ncs; // new circumcenters (incident boundary edges)
269 std::vector<QPointF> ocs; // old circumcenters (incident cavity triangles)
270 };
271 mutable std::vector<int> m_triStamp; // per triangle: == m_stamp ⇒ in cavity
272 mutable std::vector<int> m_vertStamp; // per vertex: == m_stamp ⇒ m_vertSlot valid
273 mutable std::vector<int> m_vertSlot;
274 mutable std::vector<NbSlot> m_slots;
275 mutable int m_nSlots = 0;
276 mutable int m_stamp = 0;
277 mutable std::vector<int> m_cavity, m_stack;
278 mutable std::vector<QPointF> m_ring;
279};
280
281} // namespace mesh
282
283#endif // OPENSWMMVIS_MESH_NATURALNBINTERPOLATOR_H
Variant variant() const
Read the currently stored interpolation variant.
Definition naturalnbinterpolator.h:94
bool build(const QVector< QPointF > &pts, const QVector< double > &z, QString *err)
Replace interpolation geometry with a snap-deduplicated normalized Delaunay seed set.
Definition naturalnbinterpolator.cpp:94
double interpolate(double x, double y) const
Interpolate one scalar through the chosen normalized natural-neighbor weight scheme.
Definition naturalnbinterpolator.cpp:438
void setVariant(Variant v)
Select which natural-neighbor weight construction later queries use.
Definition naturalnbinterpolator.h:88
const std::vector< int > & keptSeedIndices() const
Borrow the original input-index mapping in internal Delaunay-vertex order.
Definition naturalnbinterpolator.h:203
bool weightsAt(double x, double y, QVector< QPair< int, double > > &out) const
Return normalized natural-neighbor weights keyed by original retained input indices.
Definition naturalnbinterpolator.cpp:461
bool isValid() const
Read whether the latest full build completed successfully.
Definition naturalnbinterpolator.h:144
NaturalNeighbourInterpolator()=default
Construct an invalid empty interpolator using the Sibson variant.
Variant
Natural-neighbour coordinate construction used by interpolate() and weightsAt(): Sibson (default) use...
Definition naturalnbinterpolator.h:66
@ Laplace
Voronoi facet length divided by the distance to the seed.
Definition naturalnbinterpolator.h:68
@ Sibson
Area-stealing (Sibson) coordinates; the default.
Definition naturalnbinterpolator.h:67
The Qt-facing MeshKit API (meshkit::core_qt, meshkit::model_qt, meshkit::io_qt): mesh value types and...