thinplatespline.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /******************************************************************************
  2. * $Id: thinplatespline.h 26650 2013-11-24 14:05:58Z 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. #include "gdal_alg.h"
  33. #include "cpl_conv.h"
  34. typedef enum
  35. {
  36. VIZ_GEOREF_SPLINE_ZERO_POINTS,
  37. VIZ_GEOREF_SPLINE_ONE_POINT,
  38. VIZ_GEOREF_SPLINE_TWO_POINTS,
  39. VIZ_GEOREF_SPLINE_ONE_DIMENSIONAL,
  40. VIZ_GEOREF_SPLINE_FULL,
  41. VIZ_GEOREF_SPLINE_POINT_WAS_ADDED,
  42. VIZ_GEOREF_SPLINE_POINT_WAS_DELETED
  43. } vizGeorefInterType;
  44. //#define VIZ_GEOREF_SPLINE_MAX_POINTS 40
  45. #define VIZGEOREF_MAX_VARS 2
  46. class VizGeorefSpline2D
  47. {
  48. public:
  49. VizGeorefSpline2D(int nof_vars = 1){
  50. x = y = u = NULL;
  51. unused = index = NULL;
  52. for( int i = 0; i < nof_vars; i++ )
  53. {
  54. rhs[i] = NULL;
  55. coef[i] = NULL;
  56. }
  57. _tx = _ty = 0.0;
  58. _ta = 10.0;
  59. _nof_points = 0;
  60. _nof_vars = nof_vars;
  61. _max_nof_points = 0;
  62. grow_points();
  63. type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
  64. }
  65. ~VizGeorefSpline2D(){
  66. CPLFree( x );
  67. CPLFree( y );
  68. CPLFree( u );
  69. CPLFree( unused );
  70. CPLFree( index );
  71. for( int i = 0; i < _nof_vars; i++ )
  72. {
  73. CPLFree( rhs[i] );
  74. CPLFree( coef[i] );
  75. }
  76. }
  77. #if 0
  78. int get_nof_points(){
  79. return _nof_points;
  80. }
  81. void set_toler( double tx, double ty ){
  82. _tx = tx;
  83. _ty = ty;
  84. }
  85. void get_toler( double& tx, double& ty) {
  86. tx = _tx;
  87. ty = _ty;
  88. }
  89. vizGeorefInterType get_interpolation_type ( ){
  90. return type;
  91. }
  92. void dump_data_points()
  93. {
  94. for ( int i = 0; i < _nof_points; i++ )
  95. {
  96. fprintf(stderr, "X = %f Y = %f Vars = ", x[i], y[i]);
  97. for ( int v = 0; v < _nof_vars; v++ )
  98. fprintf(stderr, "%f ", rhs[v][i+3]);
  99. fprintf(stderr, "\n");
  100. }
  101. }
  102. int delete_list()
  103. {
  104. _nof_points = 0;
  105. type = VIZ_GEOREF_SPLINE_ZERO_POINTS;
  106. if ( _AA )
  107. {
  108. CPLFree(_AA);
  109. _AA = NULL;
  110. }
  111. if ( _Ainv )
  112. {
  113. CPLFree(_Ainv);
  114. _Ainv = NULL;
  115. }
  116. return _nof_points;
  117. }
  118. #endif
  119. void grow_points();
  120. int add_point( const double Px, const double Py, const double *Pvars );
  121. int get_point( const double Px, const double Py, double *Pvars );
  122. #if 0
  123. int delete_point(const double Px, const double Py );
  124. bool get_xy(int index, double& x, double& y);
  125. bool change_point(int index, double x, double y, double* Pvars);
  126. void reset(void) { _nof_points = 0; }
  127. #endif
  128. int solve(void);
  129. private:
  130. vizGeorefInterType type;
  131. int _nof_vars;
  132. int _nof_points;
  133. int _max_nof_points;
  134. int _nof_eqs;
  135. double _tx, _ty;
  136. double _ta;
  137. double _dx, _dy;
  138. double *x; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
  139. double *y; // [VIZ_GEOREF_SPLINE_MAX_POINTS+3];
  140. // double rhs[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
  141. // double coef[VIZ_GEOREF_SPLINE_MAX_POINTS+3][VIZGEOREF_MAX_VARS];
  142. double *rhs[VIZGEOREF_MAX_VARS];
  143. double *coef[VIZGEOREF_MAX_VARS];
  144. double *u; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
  145. int *unused; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
  146. int *index; // [VIZ_GEOREF_SPLINE_MAX_POINTS];
  147. };