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