41 # define FLT_MAX 1e+37 42 # define FLT_MIN 1e-37 49 #define A(r,c) _AA[ _nof_eqs * (r) + (c) ] 50 #define Ainv(r,c) _Ainv[ _nof_eqs * (r) + (c) ] 53 #define VIZ_GEOREF_SPLINE_DEBUG 0 55 static int matrixInvert(
int N,
double input[],
double output[] );
67 index.resize( new_max );
70 rhs[i].resize( new_max );
71 coef[i].resize( new_max );
90 rhs[j][i+3] = Pvars[j];
103 rhs[j][i+3] = Pvars[j];
139 rhs[k][j+3] =
rhs[k][j+3+1];
182 double xmax =
x[0], xmin =
x[0], ymax =
y[0], ymin =
y[0];
185 double sumx = 0.0f, sumy= 0.0f, sumx2 = 0.0f, sumy2 = 0.0f, sumxy = 0.0f;
186 double SSxx, SSyy, SSxy;
211 if ( delx < 0.001 * dely || dely < 0.001 * delx ||
212 fabs ( SSxy * SSxy / ( SSxx * SSyy ) ) > 0.99 )
226 double dxp =
x[p] -
x[0];
227 double dyp =
y[p] -
y[0];
240 if ( min_index < 0 ||
u[p1] < min_u )
247 index[p] = min_index;
262 for ( r = 0; r < 3; r++ )
263 for ( c = 0; c < 3; c++ )
282 A(c+3,r+3 ) =
A(r+3,c+3);
292 <<
" There is a problem to invert the interpolation matrix\n" 314 int leftP=0, rightP=0, found = 0;
327 fact =
_dx * ( Px -
x[0] ) +
_dy * ( Py -
y[0] );
329 vars[v] = ( 1 - fact ) *
rhs[v][3] + fact *
rhs[v][4];
332 Pu =
_dx * ( Px -
x[0] ) +
_dy * ( Py -
y[0] );
349 if ( Pu >=
u[leftP] && Pu <=
u[rightP] )
354 fact = ( Pu -
u[leftP] ) / (
u[rightP] -
u[leftP] );
356 vars[v] = ( 1.0 - fact ) *
rhs[v][leftP+3] +
357 fact *
rhs[v][rightP+3];
361 vars[v] =
coef[v][0] +
coef[v][1] * Px +
coef[v][2] * Py;
367 vars[v] +=
coef[v][r+3] * tmp;
371 fprintf(stderr,
" A point was added after the last solve\n");
372 fprintf(stderr,
" NO interpolation - return values are zero\n");
378 fprintf(stderr,
" A point was deleted after the last solve\n");
379 fprintf(stderr,
" NO interpolation - return values are zero\n");
392 const double x2,
const double y2 )
const 394 if ( ( x1 == x2 ) && (y1 == y2 ) )
397 double dist = ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 );
399 return dist * log( dist );
402 static int matrixInvert(
int N,
double input[],
double output[] )
419 fprintf(stderr,
"Matrix Inversion input matrix (N=%d)\n", N);
420 for ( row=0; row<N; row++ )
422 for ( col=0; col<N; col++ )
424 fprintf(stderr,
"%5.2f ", input[row*N + col ] );
426 fprintf(stderr,
"\n");
430 int tempSize = 2 * N * N;
431 std::vector<double> temp(tempSize);
436 fprintf(stderr,
"matrixInvert(): ERROR - memory allocation failed.\n");
443 for ( row=0; row<N; row++ )
445 for ( col=0; col<N; col++ )
450 temp[ 2*row*N + col ] = input[ row*N+col ];
451 temp[ 2*row*N + col + N ] = 0.0f;
453 temp[ 2*row*N + row + N ] = 1.0f;
462 for (k = 0; k < N; k++)
467 for (row = k+1; row < N; row++)
469 if (fabs( temp[row*2*N + k] ) > fabs( temp[
max*2*N + k] ))
477 for (col=k; col<2*N; col++)
479 ftemp = temp[k*2*N + col];
480 temp[k*2*N + col] = temp[
max*2*N + col];
481 temp[
max*2*N + col] = ftemp;
486 ftemp = temp[ k*2*N + k ];
492 for ( col=k; col<2*N; col++ )
494 temp[ k*2*N + col ] /= ftemp;
497 for ( row=0; row<N; row++ )
501 ftemp = temp[ row*2*N + k ];
502 for ( col=k; col<2*N; col++ )
504 temp[ row*2*N + col ] -= ftemp * temp[ k*2*N + col ];
512 for (row = 0; row < N; row++)
514 for (col = 0; col < N; col++)
516 output[row*N + col] = temp[row*2*N + col + N ];
double baseFunc(const double x1, const double y1, const double x2, const double y2) const
std::vector< int > unused
int deletePoint(const double Px, const double Py)
bool getXy(int index, double &x, double &y) const
std::vector< std::vector< double > > rhs
std::vector< std::vector< double > > coef
int addPoint(const double Px, const double Py, const double *Pvars)
std::vector< double > _AA
int getPoint(const double Px, const double Py, double *Pvars) const
bool changePoint(int index, double x, double y, double *Pvars)
std::vector< double > _Ainv
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)