00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "gdal_alg.h"
00043 #include "cpl_conv.h"
00044
00045 typedef enum
00046 {
00047 VIZ_GEOREF_SPLINE_ZERO_POINTS,
00048 VIZ_GEOREF_SPLINE_ONE_POINT,
00049 VIZ_GEOREF_SPLINE_TWO_POINTS,
00050 VIZ_GEOREF_SPLINE_ONE_DIMENSIONAL,
00051 VIZ_GEOREF_SPLINE_FULL,
00052
00053 VIZ_GEOREF_SPLINE_POINT_WAS_ADDED,
00054 VIZ_GEOREF_SPLINE_POINT_WAS_DELETED
00055
00056 } vizGeorefInterType;
00057
00058
00059 #define VIZGEOREF_MAX_VARS 2
00060
00061 class VizGeorefSpline2D
00062 {
00063 public:
00064
00065 VizGeorefSpline2D(int nof_vars = 1){
00066 x = y = u = NULL;
00067 unused = index = NULL;
00068 for( int i = 0; i < nof_vars; i++ )
00069 {
00070 rhs[i] = NULL;
00071 coef[i] = NULL;
00072 }
00073
00074 _tx = _ty = 0.0;
00075 _ta = 10.0;
00076 _nof_points = 0;
00077 _nof_vars = nof_vars;
00078 _max_nof_points = 0;
00079 _AA = NULL;
00080 _Ainv = NULL;
00081 grow_points();
00082 for ( int v = 0; v < _nof_vars; v++ )
00083 for ( int i = 0; i < 3; i++ )
00084 rhs[i][v] = 0.0;
00085 type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
00086 }
00087
00088 ~VizGeorefSpline2D(){
00089 if ( _AA )
00090 delete _AA;
00091 if ( _Ainv )
00092 delete _Ainv;
00093
00094 CPLFree( x );
00095 CPLFree( y );
00096 CPLFree( u );
00097 CPLFree( unused );
00098 CPLFree( index );
00099 for( int i = 0; i < _nof_vars; i++ )
00100 {
00101 CPLFree( rhs[i] );
00102 CPLFree( coef[i] );
00103 }
00104 }
00105
00106 int get_nof_points(){
00107 return _nof_points;
00108 }
00109
00110 void set_toler( double tx, double ty ){
00111 _tx = tx;
00112 _ty = ty;
00113 }
00114
00115 void get_toler( double& tx, double& ty) {
00116 tx = _tx;
00117 ty = _ty;
00118 }
00119
00120 vizGeorefInterType get_interpolation_type ( ){
00121 return type;
00122 }
00123
00124 void dump_data_points()
00125 {
00126 for ( int i = 0; i < _nof_points; i++ )
00127 {
00128 fprintf(stderr, "X = %f Y = %f Vars = ", x[i], y[i]);
00129 for ( int v = 0; v < _nof_vars; v++ )
00130 fprintf(stderr, "%f ", rhs[i+3][v]);
00131 fprintf(stderr, "\n");
00132 }
00133 }
00134 int delete_list()
00135 {
00136 _nof_points = 0;
00137 type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
00138 if ( _AA )
00139 {
00140 delete _AA;
00141 _AA = NULL;
00142 }
00143 if ( _Ainv )
00144 {
00145 delete _Ainv;
00146 _Ainv = NULL;
00147 }
00148 return _nof_points;
00149 }
00150
00151 void grow_points();
00152 int add_point( const double Px, const double Py, const double *Pvars );
00153 int delete_point(const double Px, const double Py );
00154 int get_point( const double Px, const double Py, double *Pvars );
00155 bool get_xy(int index, double& x, double& y);
00156 bool change_point(int index, double x, double y, double* Pvars);
00157 void reset(void) { _nof_points = 0; }
00158 int solve(void);
00159
00160 private:
00161 double base_func( const double x1, const double y1,
00162 const double x2, const double y2 );
00163
00164 vizGeorefInterType type;
00165
00166 int _nof_vars;
00167 int _nof_points;
00168 int _max_nof_points;
00169 int _nof_eqs;
00170
00171 double _tx, _ty;
00172 double _ta;
00173 double _dx, _dy;
00174
00175 double *x;
00176 double *y;
00177
00178
00179
00180 double *rhs[VIZGEOREF_MAX_VARS];
00181 double *coef[VIZGEOREF_MAX_VARS];
00182
00183 double *u;
00184 int *unused;
00185 int *index;
00186
00187 double *_AA, *_Ainv;
00188 };
00189
00190