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
41 typedef 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
56 class VizGeorefSpline2D
57 {
58 bool grow_points();
59
60 public:
61
62 explicit VizGeorefSpline2D(int nof_vars = 1) :
63 type(VIZ_GEOREF_SPLINE_ZERO_POINTS),
64 _nof_vars(nof_vars),
65 _nof_points(0),
66 _max_nof_points(0),
67 _nof_eqs(0),
68 #if 0
69 _tx(0.0),
70 _ty(0.0),
71 _ta(10.0),
72 #endif
73 _dx(0.0),
74 _dy(0.0),
75 x(nullptr),
76 y(nullptr),
77 u(nullptr),
78 unused(nullptr),
79 index(nullptr),
80 x_mean(0),
81 y_mean(0)
82 {
83 for( int i = 0; i < VIZGEOREF_MAX_VARS; i++ )
84 {
85 rhs[i] = nullptr;
86 coef[i] = nullptr;
87 }
88
89 grow_points();
90 }
91
92 ~VizGeorefSpline2D() {
93 CPLFree( x );
94 CPLFree( y );
95 CPLFree( u );
96 CPLFree( unused );
97 CPLFree( index );
98 for( int i = 0; i < _nof_vars; i++ )
99 {
100 CPLFree( rhs[i] );
101 CPLFree( coef[i] );
102 }
103 }
104
105 #if 0
106 int get_nof_points(){
107 return _nof_points;
108 }
109
110 void set_toler( double tx, double ty ){
111 _tx = tx;
112 _ty = ty;
113 }
114
115 void get_toler( double& tx, double& ty) {
116 tx = _tx;
117 ty = _ty;
118 }
119
120 vizGeorefInterType get_interpolation_type ( ){
121 return type;
122 }
123
124 void dump_data_points()
125 {
126 for ( int i = 0; i < _nof_points; i++ )
127 {
128 fprintf(stderr, "X = %f Y = %f Vars = ", x[i], y[i]);
129 for ( int v = 0; v < _nof_vars; v++ )
130 fprintf(stderr, "%f ", rhs[v][i+3]);
131 fprintf(stderr, "\n");
132 }
133 }
134
135 int delete_list()
136 {
137 _nof_points = 0;
138 type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
139 if ( _AA )
140 {
141 CPLFree(_AA);
142 _AA = NULL;
143 }
144 if ( _Ainv )
145 {
146 CPLFree(_Ainv);
147 _Ainv = NULL;
148 }
149 return _nof_points;
150 }
151 #endif
152
153 bool add_point( const double Px, const double Py, const double *Pvars );
154 int get_point( const double Px, const double Py, double *Pvars );
155 #if 0
156 int delete_point(const double Px, const double Py );
157 bool get_xy(int index, double& x, double& y);
158 bool change_point(int index, double x, double y, double* Pvars);
159 void reset(void) { _nof_points = 0; }
160 #endif
161 int solve(void);
162
163 private:
164
165 vizGeorefInterType type;
166
167 const int _nof_vars;
168 int _nof_points;
169 int _max_nof_points;
170 int _nof_eqs;
171
172 #if 0
173 // Disabled because the methods that use there is disabled.
174 double _tx, _ty;
175 double _ta;
176 #endif
177
178 double _dx, _dy;
179
180 double *x; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
181 double *y; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
182
183 // double rhs[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
184 // double coef[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
185 double *rhs[VIZGEOREF_MAX_VARS];
186 double *coef[VIZGEOREF_MAX_VARS];
187
188 double *u; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
189 int *unused; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
190 int *index; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
191
192 double x_mean;
193 double y_mean;
194 private:
195 CPL_DISALLOW_COPY_ASSIGN(VizGeorefSpline2D)
196 };
197
198 #endif /* #ifndef DOXYGEN_SKIP */
199
200 #endif /* THINPLATESPLINE_H_INCLUDED */
cpl_conv.h
gdal_alg.h
CPLFree
#define CPLFree
Alias of VSIFree()
Definition: cpl_conv.h:83
CPL_DISALLOW_COPY_ASSIGN
#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:930