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 * SPDX-License-Identifier: MIT
15 ****************************************************************************/
16
17#ifndef THINPLATESPLINE_H_INCLUDED
18#define THINPLATESPLINE_H_INCLUDED
19
20#ifndef DOXYGEN_SKIP
21
22#include "gdal_alg.h"
23#include "cpl_conv.h"
24
25 typedef enum
26{
27 VIZ_GEOREF_SPLINE_ZERO_POINTS,
28 VIZ_GEOREF_SPLINE_ONE_POINT,
29 VIZ_GEOREF_SPLINE_TWO_POINTS,
30 VIZ_GEOREF_SPLINE_ONE_DIMENSIONAL,
31 VIZ_GEOREF_SPLINE_FULL,
32
33 VIZ_GEOREF_SPLINE_POINT_WAS_ADDED,
34 VIZ_GEOREF_SPLINE_POINT_WAS_DELETED
35} vizGeorefInterType;
36
37// #define VIZ_GEOREF_SPLINE_MAX_POINTS 40
38#define VIZGEOREF_MAX_VARS 2
39
40 class VizGeorefSpline2D
41{
42 bool grow_points();
43
44 public:
45 explicit VizGeorefSpline2D(int nof_vars = 1)
46 : type(VIZ_GEOREF_SPLINE_ZERO_POINTS), _nof_vars(nof_vars),
47 _nof_points(0), _max_nof_points(0), _nof_eqs(0),
48#if 0
49 _tx(0.0),
50 _ty(0.0),
51 _ta(10.0),
52#endif
53 _dx(0.0), _dy(0.0), x(nullptr), y(nullptr), u(nullptr),
54 unused(nullptr), index(nullptr), x_mean(0), y_mean(0)
55 {
56 for (int i = 0; i < VIZGEOREF_MAX_VARS; i++)
57 {
58 rhs[i] = nullptr;
59 coef[i] = nullptr;
60 }
61
62 grow_points();
63 }
64
65 ~VizGeorefSpline2D()
66 {
67 CPLFree(x);
68 CPLFree(y);
69 CPLFree(u);
70 CPLFree(unused);
71 CPLFree(index);
72 for (int i = 0; i < _nof_vars; i++)
73 {
74 CPLFree(rhs[i]);
75 CPLFree(coef[i]);
76 }
77 }
78
79#if 0
80 int get_nof_points(){
81 return _nof_points;
82 }
83
84 void set_toler( double tx, double ty ){
85 _tx = tx;
86 _ty = ty;
87 }
88
89 void get_toler( double& tx, double& ty) {
90 tx = _tx;
91 ty = _ty;
92 }
93
94 vizGeorefInterType get_interpolation_type ( ){
95 return type;
96 }
97
98 void dump_data_points()
99 {
100 for ( int i = 0; i < _nof_points; i++ )
101 {
102 fprintf(stderr, "X = %f Y = %f Vars = ", x[i], y[i]);
103 for ( int v = 0; v < _nof_vars; v++ )
104 fprintf(stderr, "%f ", rhs[v][i+3]);
105 fprintf(stderr, "\n");
106 }
107 }
108
109 int delete_list()
110 {
111 _nof_points = 0;
112 type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
113 if ( _AA )
114 {
115 CPLFree(_AA);
116 _AA = NULL;
117 }
118 if ( _Ainv )
119 {
120 CPLFree(_Ainv);
121 _Ainv = NULL;
122 }
123 return _nof_points;
124 }
125#endif
126
127 bool add_point(const double Px, const double Py, const double *Pvars);
128 int get_point(const double Px, const double Py, double *Pvars);
129#if 0
130 int delete_point(const double Px, const double Py );
131 bool get_xy(int index, double& x, double& y);
132 bool change_point(int index, double x, double y, double* Pvars);
133 void reset(void) { _nof_points = 0; }
134#endif
135 int solve(void);
136
137 private:
138 vizGeorefInterType type;
139
140 const int _nof_vars;
141 int _nof_points;
142 int _max_nof_points;
143 int _nof_eqs;
144
145#if 0
146 // Disabled because the methods that use there is disabled.
147 double _tx, _ty;
148 double _ta;
149#endif
150
151 double _dx, _dy;
152
153 double *x; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
154 double *y; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
155
156 // double rhs[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
157 // double coef[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
158 double *rhs[VIZGEOREF_MAX_VARS];
159 double *coef[VIZGEOREF_MAX_VARS];
160
161 double *u; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
162 int *unused; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
163 int *index; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
164
165 double x_mean;
166 double y_mean;
167
168 private:
169 CPL_DISALLOW_COPY_ASSIGN(VizGeorefSpline2D)
170};
171
172#endif /* #ifndef DOXYGEN_SKIP */
173
174#endif /* THINPLATESPLINE_H_INCLUDED */
cpl_conv.h
Various convenience functions for CPL.
CPLFree
#define CPLFree
Alias of VSIFree()
Definition cpl_conv.h:90
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:936
gdal_alg.h
Public (C callable) GDAL algorithm entry points, and definitions.