GDAL
thinplatespline.h
1/******************************************************************************
2 * $Id$
3 *
4 * Project: GDAL Warp API
5 * Purpose: Declarations for 2D Thin Plate Spline transformer.
6 * Author: VIZRT Development Team.
7 *
8 * This code was provided by Gilad Ronnen (gro at visrt dot com) with
9 * permission to reuse under the following license.
10 *
11 ******************************************************************************
12 * Copyright (c) 2004, VIZRT Inc.
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be included
22 * in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 * DEALINGS IN THE SOFTWARE.
31 ****************************************************************************/
32
33#ifndef THINPLATESPLINE_H_INCLUDED
34#define THINPLATESPLINE_H_INCLUDED
35
36#ifndef DOXYGEN_SKIP
37
38#include "gdal_alg.h"
39#include "cpl_conv.h"
40
41typedef enum
42{
43 VIZ_GEOREF_SPLINE_ZERO_POINTS,
44 VIZ_GEOREF_SPLINE_ONE_POINT,
45 VIZ_GEOREF_SPLINE_TWO_POINTS,
46 VIZ_GEOREF_SPLINE_ONE_DIMENSIONAL,
47 VIZ_GEOREF_SPLINE_FULL,
48
49 VIZ_GEOREF_SPLINE_POINT_WAS_ADDED,
50 VIZ_GEOREF_SPLINE_POINT_WAS_DELETED
51} vizGeorefInterType;
52
53// #define VIZ_GEOREF_SPLINE_MAX_POINTS 40
54#define VIZGEOREF_MAX_VARS 2
55
56class VizGeorefSpline2D
57{
58 bool grow_points();
59
60 public:
61 explicit VizGeorefSpline2D(int nof_vars = 1)
62 : type(VIZ_GEOREF_SPLINE_ZERO_POINTS), _nof_vars(nof_vars),
63 _nof_points(0), _max_nof_points(0), _nof_eqs(0),
64#if 0
65 _tx(0.0),
66 _ty(0.0),
67 _ta(10.0),
68#endif
69 _dx(0.0), _dy(0.0), x(nullptr), y(nullptr), u(nullptr),
70 unused(nullptr), index(nullptr), x_mean(0), y_mean(0)
71 {
72 for (int i = 0; i < VIZGEOREF_MAX_VARS; i++)
73 {
74 rhs[i] = nullptr;
75 coef[i] = nullptr;
76 }
77
78 grow_points();
79 }
80
81 ~VizGeorefSpline2D()
82 {
83 CPLFree(x);
84 CPLFree(y);
85 CPLFree(u);
86 CPLFree(unused);
87 CPLFree(index);
88 for (int i = 0; i < _nof_vars; i++)
89 {
90 CPLFree(rhs[i]);
91 CPLFree(coef[i]);
92 }
93 }
94
95#if 0
96 int get_nof_points(){
97 return _nof_points;
98 }
99
100 void set_toler( double tx, double ty ){
101 _tx = tx;
102 _ty = ty;
103 }
104
105 void get_toler( double& tx, double& ty) {
106 tx = _tx;
107 ty = _ty;
108 }
109
110 vizGeorefInterType get_interpolation_type ( ){
111 return type;
112 }
113
114 void dump_data_points()
115 {
116 for ( int i = 0; i < _nof_points; i++ )
117 {
118 fprintf(stderr, "X = %f Y = %f Vars = ", x[i], y[i]);
119 for ( int v = 0; v < _nof_vars; v++ )
120 fprintf(stderr, "%f ", rhs[v][i+3]);
121 fprintf(stderr, "\n");
122 }
123 }
124
125 int delete_list()
126 {
127 _nof_points = 0;
128 type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
129 if ( _AA )
130 {
131 CPLFree(_AA);
132 _AA = NULL;
133 }
134 if ( _Ainv )
135 {
136 CPLFree(_Ainv);
137 _Ainv = NULL;
138 }
139 return _nof_points;
140 }
141#endif
142
143 bool add_point(const double Px, const double Py, const double *Pvars);
144 int get_point(const double Px, const double Py, double *Pvars);
145#if 0
146 int delete_point(const double Px, const double Py );
147 bool get_xy(int index, double& x, double& y);
148 bool change_point(int index, double x, double y, double* Pvars);
149 void reset(void) { _nof_points = 0; }
150#endif
151 int solve(void);
152
153 private:
154 vizGeorefInterType type;
155
156 const int _nof_vars;
157 int _nof_points;
158 int _max_nof_points;
159 int _nof_eqs;
160
161#if 0
162 // Disabled because the methods that use there is disabled.
163 double _tx, _ty;
164 double _ta;
165#endif
166
167 double _dx, _dy;
168
169 double *x; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
170 double *y; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
171
172 // double rhs[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
173 // double coef[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
174 double *rhs[VIZGEOREF_MAX_VARS];
175 double *coef[VIZGEOREF_MAX_VARS];
176
177 double *u; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
178 int *unused; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
179 int *index; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
180
181 double x_mean;
182 double y_mean;
183
184 private:
185 CPL_DISALLOW_COPY_ASSIGN(VizGeorefSpline2D)
186};
187
188#endif /* #ifndef DOXYGEN_SKIP */
189
190#endif /* THINPLATESPLINE_H_INCLUDED */
Various convenience functions for CPL.
#define CPLFree
Alias of VSIFree()
Definition cpl_conv.h:98
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:1042
Public (C callable) GDAL algorithm entry points, and definitions.