LCOV - code coverage report
Current view: directory - alg - thinplatespline.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 30 30 100.0 %
Date: 2012-12-26 Functions: 2 2 100.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: thinplatespline.h 20193 2010-08-06 17:12:10Z 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              12 :     VizGeorefSpline2D(int nof_vars = 1){
      57              12 :         x = y = u = NULL;
      58              12 :         unused = index = NULL;
      59              36 :         for( int i = 0; i < nof_vars; i++ )
      60                 :         {
      61              24 :             rhs[i] = NULL;
      62              24 :             coef[i] = NULL;
      63                 :         }
      64                 :           
      65              12 :         _tx = _ty = 0.0;    
      66              12 :         _ta = 10.0;
      67              12 :         _nof_points = 0;
      68              12 :         _nof_vars = nof_vars;
      69              12 :         _max_nof_points = 0;
      70              12 :         _AA = NULL;
      71              12 :         _Ainv = NULL;
      72              12 :         grow_points();
      73              12 :         type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
      74              12 :     }
      75                 : 
      76              12 :     ~VizGeorefSpline2D(){
      77              12 :         if ( _AA )
      78              12 :             CPLFree(_AA);
      79              12 :         if ( _Ainv )
      80              12 :             CPLFree(_Ainv);
      81                 : 
      82              12 :         CPLFree( x );
      83              12 :         CPLFree( y );
      84              12 :         CPLFree( u );
      85              12 :         CPLFree( unused );
      86              12 :         CPLFree( index );
      87              36 :         for( int i = 0; i < _nof_vars; i++ )
      88                 :         {
      89              24 :             CPLFree( rhs[i] );
      90              24 :             CPLFree( coef[i] );
      91                 :         }
      92              12 :     }
      93                 : 
      94                 :     int get_nof_points(){
      95                 :         return _nof_points;
      96                 :     }
      97                 : 
      98                 :     void set_toler( double tx, double ty ){
      99                 :         _tx = tx;
     100                 :         _ty = ty;
     101                 :     }
     102                 : 
     103                 :     void get_toler( double& tx, double& ty) {
     104                 :         tx = _tx;
     105                 :         ty = _ty;
     106                 :     }
     107                 : 
     108                 :     vizGeorefInterType get_interpolation_type ( ){
     109                 :         return type;
     110                 :     }
     111                 : 
     112                 :     void dump_data_points()
     113                 :   {
     114                 :             for ( int i = 0; i < _nof_points; i++ )
     115                 :             {
     116                 :                 fprintf(stderr, "X = %f Y = %f Vars = ", x[i], y[i]);
     117                 :                 for ( int v = 0; v < _nof_vars; v++ )
     118                 :                     fprintf(stderr, "%f ", rhs[v][i+3]);
     119                 :                 fprintf(stderr, "\n");
     120                 :             }
     121                 :   }
     122                 :     int delete_list()
     123                 :   {
     124                 :             _nof_points = 0;
     125                 :             type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
     126                 :             if ( _AA )
     127                 :             {
     128                 :                 CPLFree(_AA);
     129                 :                 _AA = NULL;
     130                 :             }
     131                 :             if ( _Ainv )
     132                 :             {
     133                 :                 CPLFree(_Ainv);
     134                 :                 _Ainv = NULL;
     135                 :             }
     136                 :             return _nof_points;
     137                 :   }
     138                 : 
     139                 :     void grow_points();
     140                 :     int add_point( const double Px, const double Py, const double *Pvars );
     141                 :     int delete_point(const double Px, const double Py );
     142                 :     int get_point( const double Px, const double Py, double *Pvars );
     143                 :     bool get_xy(int index, double& x, double& y);
     144                 :     bool change_point(int index, double x, double y, double* Pvars);
     145                 :     void reset(void) { _nof_points = 0; }
     146                 :     int solve(void);
     147                 : 
     148                 :   private:  
     149                 :     double base_func( const double x1, const double y1,
     150                 :                       const double x2, const double y2 );
     151                 : 
     152                 :     vizGeorefInterType type;
     153                 : 
     154                 :     int _nof_vars;
     155                 :     int _nof_points;
     156                 :     int _max_nof_points;
     157                 :     int _nof_eqs;
     158                 : 
     159                 :     double _tx, _ty;
     160                 :     double _ta;
     161                 :     double _dx, _dy;
     162                 : 
     163                 :     double *x; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
     164                 :     double *y; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
     165                 : 
     166                 : //    double rhs[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
     167                 : //    double coef[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
     168                 :     double *rhs[VIZGEOREF_MAX_VARS];
     169                 :     double *coef[VIZGEOREF_MAX_VARS];
     170                 : 
     171                 :     double *u; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
     172                 :     int *unused; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
     173                 :     int *index; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
     174                 :   
     175                 :     double *_AA, *_Ainv;
     176                 : };
     177                 : 
     178                 : 

Generated by: LCOV version 1.7