Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

thinplatespline.h

00001 /******************************************************************************
00002  * $Id: thinplatespline.h,v 1.1 2004/11/14 04:16:44 fwarmerdam Exp $
00003  *
00004  * Project:  GDAL Warp API
00005  * Purpose:  Declarations for 2D Thin Plate Spline transformer. 
00006  * Author:   VIZRT Development Team.
00007  *
00008  * This code was provided by Gilad Ronnen (gro at visrt dot com) with 
00009  * permission to reuse under the following license.
00010  * 
00011  ******************************************************************************
00012  * Copyright (c) 2004, VIZRT Inc.
00013  *
00014  * Permission is hereby granted, free of charge, to any person obtaining a
00015  * copy of this software and associated documentation files (the "Software"),
00016  * to deal in the Software without restriction, including without limitation
00017  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00018  * and/or sell copies of the Software, and to permit persons to whom the
00019  * Software is furnished to do so, subject to the following conditions:
00020  *
00021  * The above copyright notice and this permission notice shall be included
00022  * in all copies or substantial portions of the Software.
00023  *
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00025  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00026  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00027  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00028  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00029  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00030  * DEALINGS IN THE SOFTWARE.
00031  ******************************************************************************
00032  *
00033  * $Log: thinplatespline.h,v $
00034  * Revision 1.1  2004/11/14 04:16:44  fwarmerdam
00035  * New
00036  *
00037  */
00038 
00039 #include "gdal_alg.h"
00040 
00041 typedef enum
00042 {
00043         VIZ_GEOREF_SPLINE_ZERO_POINTS,
00044         VIZ_GEOREF_SPLINE_ONE_POINT,
00045         VIZ_GEOREF_SPLINE_TWO_POINTS,
00046         VIZ_GEOREF_SPLINE_ONE_DIMENSIONAL,
00047         VIZ_GEOREF_SPLINE_FULL,
00048         
00049         VIZ_GEOREF_SPLINE_POINT_WAS_ADDED,
00050         VIZ_GEOREF_SPLINE_POINT_WAS_DELETED
00051 
00052 } vizGeorefInterType;
00053 
00054 #define VIZ_GEOREF_SPLINE_MAX_POINTS 40
00055 #define VIZGEOREF_MAX_VARS 2
00056 
00057 class VizGeorefSpline2D
00058 {
00059  public:
00060 
00061         VizGeorefSpline2D(int nof_vars = 1){
00062                 _tx = _ty = 0.0;                
00063                 _ta = 10.0;
00064                 _nof_points = 0;
00065                 _nof_vars = nof_vars;
00066                 _AA = NULL;
00067                 _Ainv = NULL;
00068                 for ( int v = 0; v < _nof_vars; v++ )
00069                         for ( int i = 0; i < 3; i++ )
00070                                 rhs[i][v] = 0.0;
00071                 type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
00072         }
00073 
00074         ~VizGeorefSpline2D(){
00075                 if ( _AA )
00076                         delete _AA;
00077                 if ( _Ainv )
00078                         delete _Ainv;
00079         }
00080 
00081         int get_nof_points(){
00082                 return _nof_points;
00083         }
00084 
00085         void set_toler( float tx, float ty ){
00086                 _tx = tx;
00087                 _ty = ty;
00088         }
00089 
00090         void get_toler( float& tx, float& ty) {
00091                 tx = _tx;
00092                 ty = _ty;
00093         }
00094 
00095         vizGeorefInterType get_interpolation_type ( ){
00096                 return type;
00097         }
00098 
00099         void dump_data_points()
00100         {
00101                 for ( int i = 0; i < _nof_points; i++ )
00102                 {
00103                         fprintf(stderr, "X = %f Y = %f Vars = ", x[i], y[i]);
00104                         for ( int v = 0; v < _nof_vars; v++ )
00105                                 fprintf(stderr, "%f ", rhs[i+3][v]);
00106                         fprintf(stderr, "\n");
00107                 }
00108         }
00109         int delete_list()
00110         {
00111                 _nof_points = 0;
00112                 type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
00113                 if ( _AA )
00114                 {
00115                         delete _AA;
00116                         _AA = NULL;
00117                 }
00118                 if ( _Ainv )
00119                 {
00120                         delete _Ainv;
00121                         _Ainv = NULL;
00122                 }
00123                 return _nof_points;
00124         }
00125 
00126         int add_point( const float Px, const float Py, const float *Pvars );
00127         int delete_point(const float Px, const float Py );
00128         int get_point( const float Px, const float Py, float *Pvars );
00129         bool get_xy(int index, float& x, float& y);
00130         bool change_point(int index, float x, float y, float* Pvars);
00131         void reset(void) { _nof_points = 0; }
00132         int solve(void);
00133 
00134 private:        
00135         float base_func( const float x1, const float y1,
00136                                          const float x2, const float y2 );
00137 
00138         vizGeorefInterType type;
00139 
00140         int _nof_vars;
00141         int _nof_points;
00142         int _nof_eqs;
00143 
00144         float _tx, _ty;
00145         float _ta;
00146         float _dx, _dy;
00147 
00148         float x[VIZ_GEOREF_SPLINE_MAX_POINTS+3];
00149         float y[VIZ_GEOREF_SPLINE_MAX_POINTS+3];
00150 
00151         float rhs[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
00152         float coef[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
00153 
00154         float u[VIZ_GEOREF_SPLINE_MAX_POINTS];
00155         int unused[VIZ_GEOREF_SPLINE_MAX_POINTS];
00156         int index[VIZ_GEOREF_SPLINE_MAX_POINTS];
00157         
00158         float *_AA, *_Ainv;
00159 };
00160 
00161 

Generated on Tue Mar 15 07:12:59 2005 for GDAL by  doxygen 1.4.0