IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 7, 2007, 3:28:00 PM (20 years ago)
Author:
eugene
Message:

added local linear map

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pswarp/src/pswarpMapGrid.c

    r10954 r10957  
    11# include "pswarp.h"
    22
    3 static pswarpMapFree (pswarpMap *map) {
     3// construct a grid with superpixel spacing of nXpix, nYpix
     4// XXX for the moment, ignore readout->cell->chip offsets
     5pswarpMapGrid *pswarpMapGridFromImage (pmReadout *dest, pmReadout *src, int nXpix, int nYpix) {
     6
     7    // split the difference of the remainder
     8    int xMin = 0.5*(src->image->numCols % nXpix);
     9    int yMin = 0.5*(src->image->numRows % nYpix);
     10
     11    pswarpMapGrid *grid = pswarpMapGridAlloc (src->image->numCols / nXpix, src->image->numRows / nYpix);
     12
     13    int ni = 0;
     14    int nj = 0;
     15    for (int i = xMin; i < src->image->numCols; i += nXpix, ni++) {
     16        for (int j = yMin; j < src->image->numRows; j += nYpix, nj++) {
     17            pswarpMapSetLocalModel (grid->maps[ni][nj], dest, src, i, j);
     18        }
     19    }
     20           
     21    grid->nXpix = nXpix;
     22    grid->nYpix = nYpix;
     23    grid->xMin = xMin;
     24    grid->yMin = yMin;
     25    return grid;
     26}
     27
     28bool pswarpMapGridSetGrid (pswarpMapGrid *grid, int ix, int iy, int *gridX, int *gridY) {
     29
     30    *gridX = (ix - grid->xMin + 0.5*grid->nXpix) / grid->nXpix;
     31    *gridY = (iy - grid->yMin + 0.5*grid->nYpix) / grid->nYpix;
     32    return true;
     33}
     34
     35bool pswarpMapGridNextGrid (pswarpMapGrid *grid, int gridX, int gridY, int *nextX, int *nextY) {
     36
     37    *nextX = gridX*grid->nXpix + grid->xMin + 0.5*grid->nXpix;
     38    *nextY = gridY*grid->nYpix + grid->yMin + 0.5*grid->nYpix;
     39    return true;
     40}
     41
     42// measure the max error accumulated in appling one grid point to its neighbors
     43double pswarpMapGridMaxError (pswarpMapGrid *grid) {
     44
     45    double xRaw, yRaw;
     46    double xRef, yRef;
     47    double maxError = 0;
     48
     49    for (int i = 0; i < grid->nXpts - 1; i++) {
     50        for (int j = 0; j < grid->nYpts - 1; j++) {
     51
     52            // measure the output coordinates for the next grid position using the current grid map
     53            // compare with the coordinates measured using the next grid map
     54            pswarpMapApply (&xRaw, &yRaw, grid->maps[i][j], grid->maps[i][j]->xo + grid->nXpix, grid->maps[i][j]->yo);
     55            pswarpMapApply (&xRef, &yRef, grid->maps[i+1][j], grid->maps[i][j]->xo + grid->nXpix, grid->maps[i][j]->yo);
     56
     57            double posError = hypot (xRaw-xRef, yRaw-yRef);
     58            maxError = PS_MAX (maxError, posError);
     59        }
     60    }   
     61    return maxError;
     62}
     63
     64bool pswarpMapApply (double *outX, double *outY, pswarpMap *map, double inX, double inY) {
     65
     66    *outX = map->Xo + map->Xx*inX + map->Xy*inY;
     67    *outY = map->Yo + map->Yx*inX + map->Yy*inY;
     68
     69    return true;
     70}
     71
     72// determine the map for the given pixel from src to dest. pixel is in src coords
     73bool pswarpMapSetLocalModel (pswarpMap *map, pmReadout *dest, pmReadout *src, int ix, int iy) {
     74
     75    pmCell *cell = NULL;
     76
     77    cell = src->parent;
     78    pmChip *chipSrc = cell->parent;
     79    pmFPA *fpaSrc = chipSrc->parent;
     80
     81    cell = dest->parent;
     82    pmChip *chipDest = cell->parent;
     83    pmFPA *fpaDest = chipDest->parent;
     84
     85    // XXX save these as static for speed?
     86    psPlane *offset = psPlaneAlloc();
     87
     88    psPlane *FP = psPlaneAlloc();
     89    psPlane *TP = psPlaneAlloc();
     90    psSphere *sky = psSphereAlloc();
     91
     92    psPlane *V00 = psPlaneAlloc();
     93    psPlane *V10 = psPlaneAlloc();
     94    psPlane *V01 = psPlaneAlloc();
     95
     96    // XXX need to include readout->cell->chip offsets
     97
     98    // V(0,0) position
     99    offset->x = ix;
     100    offset->y = iy;
     101    psPlaneTransformApply(FP, chipSrc->toFPA, offset);
     102    psPlaneTransformApply (TP, fpaSrc->toTPA, FP);
     103    psDeproject (sky, TP, fpaSrc->toSky);
     104    psProject (TP, sky, fpaDest->toSky);
     105    psPlaneTransformApply (FP, fpaDest->fromTPA, TP);
     106    psPlaneTransformApply (V00, chipDest->fromFPA, FP);
     107   
     108    // V(1,0) position
     109    offset->x = ix + 1;
     110    offset->y = iy;
     111    psPlaneTransformApply(FP, chipSrc->toFPA, offset);
     112    psPlaneTransformApply (TP, fpaSrc->toTPA, FP);
     113    psDeproject (sky, TP, fpaSrc->toSky);
     114    psProject (TP, sky, fpaDest->toSky);
     115    psPlaneTransformApply (FP, fpaDest->fromTPA, TP);
     116    psPlaneTransformApply (V10, chipDest->fromFPA, FP);
     117   
     118    // V(0,1) position
     119    offset->x = ix;
     120    offset->y = iy + 1;
     121    psPlaneTransformApply(FP, chipSrc->toFPA, offset);
     122    psPlaneTransformApply (TP, fpaSrc->toTPA, FP);
     123    psDeproject (sky, TP, fpaSrc->toSky);
     124    psProject (TP, sky, fpaDest->toSky);
     125    psPlaneTransformApply (FP, fpaDest->fromTPA, TP);
     126    psPlaneTransformApply (V01, chipDest->fromFPA, FP);
     127
     128    map->Xx = V10->x - V00->x;
     129    map->Xy = V01->x - V00->x;
     130    map->Xo = V00->x + map->Xx*ix + map->Xy*iy;
     131
     132    map->Yx = V10->y - V00->y;
     133    map->Yy = V01->y - V00->y;
     134    map->Yo = V00->y + map->Yx*ix + map->Yy*iy;
     135 
     136    map->xo = ix;
     137    map->yo = iy;
     138
     139    psFree (offset);
     140    psFree (FP);
     141    psFree (TP);
     142    psFree (sky);
     143
     144    psFree (V00);
     145    psFree (V10);
     146    psFree (V01);
     147
     148    return true;
     149}
     150
     151static void pswarpMapFree (pswarpMap *map) {
    4152  return;
    5153}
     
    13161}
    14162
     163static void pswarpMapGridFree (pswarpMapGrid *grid) {
     164
     165    if (grid == NULL) return;
     166    if (grid->maps == NULL) return;
     167
     168    for (int i = 0; i < grid->nXpts; i++) {
     169        for (int j = 0; j < grid->nYpts; j++) {
     170            psFree (grid->maps[i][j]);
     171        }
     172        psFree (grid->maps[i]);
     173    }
     174    psFree (grid->maps);
     175    return;
     176}
     177
     178pswarpMapGrid *pswarpMapGridAlloc (int nXpts, int nYpts) {
     179
     180  pswarpMapGrid *grid = (pswarpMapGrid *) psAlloc (sizeof(pswarpMapGrid));
     181  psMemSetDeallocator(grid, (psFreeFunc) pswarpMapGridFree);
     182
     183  grid->maps = psAlloc (nXpts*sizeof(void **));
     184  for (int i = 0; i < nXpts; i++) {
     185      grid->maps[i] = psAlloc (nYpts*sizeof(void *));
     186      for (int j = 0; j < nYpts; j++) {
     187          grid->maps[i][j] = pswarpMapAlloc();
     188      }
     189  }
     190  grid->nXpts = nXpts;
     191  grid->nYpts = nYpts;
     192
     193  grid->nXpix = 0;
     194  grid->nYpix = 0;
    15195 
     196  return grid;
     197}
     198
Note: See TracChangeset for help on using the changeset viewer.