SatDump 2.0.0-alpha-76a915210
Loading...
Searching...
No Matches
thinplatespline.h
1#pragma once
2
3/******************************************************************************
4 *
5 *
6 * Project: GDAL Warp API
7 * Purpose: Declarations for 2D Thin Plate Spline transformer.
8 * Author: VIZRT Development Team.
9 *
10 * This code was provided by Gilad Ronnen (gro at visrt dot com) with
11 * permission to reuse under the following license.
12 *
13 ******************************************************************************
14 * Copyright (c) 2004, VIZRT Inc.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files (the "Software"),
18 * to deal in the Software without restriction, including without limitation
19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 * and/or sell copies of the Software, and to permit persons to whom the
21 * Software is furnished to do so, subject to the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be included
24 * in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 * DEALINGS IN THE SOFTWARE.
33 ****************************************************************************/
34
35/*
36 This file is originally from https://github.com/OSGeo/gdal
37 It was modified for the purposes required here by Aang23.
38
39 All credits go to the GDAL Project and the VIZRT Team.
40*/
41
42#include <cstdlib>
43
44namespace satdump
45{
46 namespace projection
47 {
48 // Ground Control Point
49 struct GCP
50 {
51 double x;
52 double y;
53 double lon;
54 double lat;
55 };
56
57 typedef enum
58 {
59 VIZ_GEOREF_SPLINE_ZERO_POINTS,
60 VIZ_GEOREF_SPLINE_ONE_POINT,
61 VIZ_GEOREF_SPLINE_TWO_POINTS,
62 VIZ_GEOREF_SPLINE_ONE_DIMENSIONAL,
63 VIZ_GEOREF_SPLINE_FULL,
64
65 VIZ_GEOREF_SPLINE_POINT_WAS_ADDED,
66 VIZ_GEOREF_SPLINE_POINT_WAS_DELETED
67 } vizGeorefInterType;
68
69// #define VIZ_GEOREF_SPLINE_MAX_POINTS 40
70#define VIZGEOREF_MAX_VARS 2
71
72 class VizGeorefSpline2D
73 {
74 bool grow_points();
75
76 public:
77 explicit VizGeorefSpline2D(int nof_vars = 1)
78 : type(VIZ_GEOREF_SPLINE_ZERO_POINTS),
79 _nof_vars(nof_vars),
80 _nof_points(0),
81 _max_nof_points(0),
82 _nof_eqs(0),
83 _dx(0.0),
84 _dy(0.0),
85 x(nullptr),
86 y(nullptr),
87 u(nullptr),
88 unused(nullptr),
89 index(nullptr),
90 x_mean(0),
91 y_mean(0)
92 {
93 for (int i = 0; i < VIZGEOREF_MAX_VARS; i++)
94 {
95 rhs[i] = nullptr;
96 coef[i] = nullptr;
97 }
98
99 grow_points();
100 }
101
102 ~VizGeorefSpline2D()
103 {
104 free(x);
105 free(y);
106 free(u);
107 free(unused);
108 free(index);
109
110 for (int i = 0; i < _nof_vars; i++)
111 {
112 free(rhs[i]);
113 free(coef[i]);
114 }
115 }
116
117 bool add_point(const double Px, const double Py, const double *Pvars);
118 int get_point(const double Px, const double Py, double *Pvars);
119 int solve(void);
120
121 private:
122 vizGeorefInterType type;
123
124 public:
125 const int _nof_vars;
126 int _nof_points;
127 int _max_nof_points;
128 int _nof_eqs;
129
130 double _dx, _dy;
131
132 double *x; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
133 double *y; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
134
135 // double rhs[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
136 // double coef[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
137 double *rhs[VIZGEOREF_MAX_VARS];
138 double *coef[VIZGEOREF_MAX_VARS];
139
140 double *u; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
141 int *unused; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
142 int *index; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
143
144 double x_mean;
145 double y_mean;
146 };
147 };
148};
Definition thinplatespline.h:50