int GDALGCPTransform( void *pTransformArg, int bDstToSrc, int nPointCount, double *x, double *y, double *z, int *panSuccess ) { int i; GCPTransformInfo *psInfo = (GCPTransformInfo *) pTransformArg; if( psInfo->bReversed ) bDstToSrc = !bDstToSrc; for( i = 0; i < nPointCount; i++ ) { if( x[i] == HUGE_VAL || y[i] == HUGE_VAL ) { panSuccess[i] = FALSE; continue; } if( bDstToSrc ) { CRS_georef( x[i], y[i], x + i, y + i, psInfo->adfFromGeoX, psInfo->adfFromGeoY, psInfo->nOrder ); } else { CRS_georef( x[i], y[i], x + i, y + i, psInfo->adfToGeoX, psInfo->adfToGeoY, psInfo->nOrder ); } panSuccess[i] = TRUE; } return TRUE; }
static int worst_outlier(struct Control_Points *cp, double x_mean, double y_mean, int nOrder, double E[], double N[], double dfTolerance) { int nI = 0, nIndex = 0; double dfDifference = 0.0; double dfSampleRes = 0.0; double dfLineRes = 0.0; double dfCurrentDifference = 0.0; double dfSampleResidual = 0.0; double dfLineResidual = 0.0; double *padfResiduals = (double *) CPLCalloc(sizeof(double),cp->count); for(nI = 0; nI < cp->count; nI++) { CRS_georef( cp->e1[nI] - x_mean, cp->n1[nI] - y_mean, &dfSampleRes, &dfLineRes,E,N,nOrder ); dfSampleRes -= cp->e2[nI]; dfLineRes -= cp->n2[nI]; dfSampleResidual += dfSampleRes*dfSampleRes; dfLineResidual += dfLineRes*dfLineRes; padfResiduals[nI] = sqrt(dfSampleRes*dfSampleRes + dfLineRes*dfLineRes); } nIndex = -1; dfDifference = -1.0; for(nI = 0; nI < cp->count; nI++) { dfCurrentDifference = padfResiduals[nI]; if(fabs(dfCurrentDifference) < 1.19209290E-07F /*FLT_EPSILON*/) { dfCurrentDifference = 0.0; } if(dfCurrentDifference > dfDifference && dfCurrentDifference >= dfTolerance) { dfDifference = dfCurrentDifference; nIndex = nI; } } CPLFree( padfResiduals ); return nIndex; }
static int compute_transformation(void) { /* returns 0 on success, 1 on fail */ int n, count; double d, d1, d2, sum; double e1, e2, n1, n2; double xval, yval, gval; static int order_pnts[3] = { 3, 6, 10 }; char msg[40]; xmax = ymax = gmax = 0; xval = yval = gval = 0.0; CRS_Compute_equation(trans_order); if (group.equation_stat <= 0) { if (group.equation_stat == 0) { sprintf(msg, "Not Enough Points -- %d are required.", order_pnts[trans_order - 1]); Menu_msg(msg); G_sleep(2); } return 1; } /* compute the row,col error plus ground error * keep track of largest and second largest error */ sum = 0.0; rms = 0.0; count = 0; for (n = 0; n < group.points.count; n++) { if (group.points.status[n] <= 0) continue; count++; CRS_georef(group.points.e2[n], group.points.n2[n], &e1, &n1, group.E21, group.N21, trans_order); CRS_georef(group.points.e1[n], group.points.n1[n], &e2, &n2, group.E12, group.N12, trans_order); if ((d = xres[n] = e1 - group.points.e1[n]) < 0) d = -d; if (d > xval) { xmax = n; xval = d; } if ((d = yres[n] = n1 - group.points.n1[n]) < 0) d = -d; if (d > yval) { ymax = n; yval = d; } /* compute ground error (ie along diagonal) */ d1 = e2 - group.points.e2[n]; d2 = n2 - group.points.n2[n]; d = d1 * d1 + d2 * d2; sum += d; /* add it to rms sum, before taking sqrt */ d = sqrt(d); gnd[n] = d; if (d > gval) { /* is this one the max? */ gmax = n; gval = d; } } /* compute overall rms error */ if (count) rms = sqrt(sum / count); return 0; }