1 : /******************************************************************************
2 : * $Id: thinplatespline.h 14122 2008-03-30 10:33:39Z rouault $
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 : #include "gdal_alg.h"
34 : #include "cpl_conv.h"
35 :
36 : typedef enum
37 : {
38 : VIZ_GEOREF_SPLINE_ZERO_POINTS,
39 : VIZ_GEOREF_SPLINE_ONE_POINT,
40 : VIZ_GEOREF_SPLINE_TWO_POINTS,
41 : VIZ_GEOREF_SPLINE_ONE_DIMENSIONAL,
42 : VIZ_GEOREF_SPLINE_FULL,
43 :
44 : VIZ_GEOREF_SPLINE_POINT_WAS_ADDED,
45 : VIZ_GEOREF_SPLINE_POINT_WAS_DELETED
46 :
47 : } vizGeorefInterType;
48 :
49 : //#define VIZ_GEOREF_SPLINE_MAX_POINTS 40
50 : #define VIZGEOREF_MAX_VARS 2
51 :
52 : class VizGeorefSpline2D
53 : {
54 : public:
55 :
56 8 : VizGeorefSpline2D(int nof_vars = 1){
57 8 : x = y = u = NULL;
58 8 : unused = index = NULL;
59 24 : for( int i = 0; i < nof_vars; i++ )
60 : {
61 16 : rhs[i] = NULL;
62 16 : coef[i] = NULL;
63 : }
64 :
65 8 : _tx = _ty = 0.0;
66 8 : _ta = 10.0;
67 8 : _nof_points = 0;
68 8 : _nof_vars = nof_vars;
69 8 : _max_nof_points = 0;
70 8 : _AA = NULL;
71 8 : _Ainv = NULL;
72 8 : grow_points();
73 24 : for ( int v = 0; v < _nof_vars; v++ )
74 64 : for ( int i = 0; i < 3; i++ )
75 48 : rhs[i][v] = 0.0;
76 8 : type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
77 8 : }
78 :
79 8 : ~VizGeorefSpline2D(){
80 8 : if ( _AA )
81 8 : CPLFree(_AA);
82 8 : if ( _Ainv )
83 8 : CPLFree(_Ainv);
84 :
85 8 : CPLFree( x );
86 8 : CPLFree( y );
87 8 : CPLFree( u );
88 8 : CPLFree( unused );
89 8 : CPLFree( index );
90 24 : for( int i = 0; i < _nof_vars; i++ )
91 : {
92 16 : CPLFree( rhs[i] );
93 16 : CPLFree( coef[i] );
94 : }
95 8 : }
96 :
97 : int get_nof_points(){
98 : return _nof_points;
99 : }
100 :
101 : void set_toler( double tx, double ty ){
102 : _tx = tx;
103 : _ty = ty;
104 : }
105 :
106 : void get_toler( double& tx, double& ty) {
107 : tx = _tx;
108 : ty = _ty;
109 : }
110 :
111 : vizGeorefInterType get_interpolation_type ( ){
112 : return type;
113 : }
114 :
115 : void dump_data_points()
116 : {
117 : for ( int i = 0; i < _nof_points; i++ )
118 : {
119 : fprintf(stderr, "X = %f Y = %f Vars = ", x[i], y[i]);
120 : for ( int v = 0; v < _nof_vars; v++ )
121 : fprintf(stderr, "%f ", rhs[i+3][v]);
122 : fprintf(stderr, "\n");
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 :
142 : void grow_points();
143 : int add_point( const double Px, const double Py, const double *Pvars );
144 : int delete_point(const double Px, const double Py );
145 : int get_point( const double Px, const double Py, double *Pvars );
146 : bool get_xy(int index, double& x, double& y);
147 : bool change_point(int index, double x, double y, double* Pvars);
148 : void reset(void) { _nof_points = 0; }
149 : int solve(void);
150 :
151 : private:
152 : double base_func( const double x1, const double y1,
153 : const double x2, const double y2 );
154 :
155 : vizGeorefInterType type;
156 :
157 : int _nof_vars;
158 : int _nof_points;
159 : int _max_nof_points;
160 : int _nof_eqs;
161 :
162 : double _tx, _ty;
163 : double _ta;
164 : double _dx, _dy;
165 :
166 : double *x; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
167 : double *y; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
168 :
169 : // double rhs[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
170 : // double coef[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
171 : double *rhs[VIZGEOREF_MAX_VARS];
172 : double *coef[VIZGEOREF_MAX_VARS];
173 :
174 : double *u; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
175 : int *unused; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
176 : int *index; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
177 :
178 : double *_AA, *_Ainv;
179 : };
180 :
181 :
|