IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 8, 2010, 7:40:49 PM (16 years ago)
Author:
bills
Message:

rewrite nameCorners() the function that sorts the skycell
corners into the order expected by the code that calculates
the skycell overlap

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/magic/remove/src/diffedpixels.c

    r27102 r27223  
    22#include "pmAstrometryWCS.h"
    33
    4 // #define DEBUG_PRINT 1
     4#define DEBUG_PRINT 1
    55
    66static void addTouchedPixels(streakFiles *sf, psString fileName);
     
    136136    }
    137137#ifdef DEBUG_PRINT
    138     printf("\nSKYCELL %s Type: %s\n", fileName, type);
     138    fprintf(stderr, "\nSKYCELL %s Type: %s\n", fileName, type);
    139139    for (int i=0; i<4; i++) {
    140         printf("%f %f\n", pt[i].x, pt[i].y);
     140        fprintf(stderr, "%f %f\n", pt[i].x, pt[i].y);
    141141    }
    142142#endif
     
    145145    int ymax = fmin(pt[3].y + 0.5, sf->diffedPixels->numRows - 1);
    146146#if (DEBUG_PRINT > 1)
    147     printf("\nymin: %d ymax: %d\n", ymin, ymax);
     147    fprintf(stderr, "\nymin: %d ymax: %d\n", ymin, ymax);
    148148#endif
    149149    for (int y = ymin ; y <= ymax; y++) {
     
    164164        }
    165165#if (DEBUG_PRINT > 1)
    166         printf("  y: %d xleft: %d xright: %d\n", y, xleft, xright);
     166        fprintf(stderr, "  y: %d xleft: %d xright: %d\n", y, xleft, xright);
    167167#endif
    168168
     
    284284    psPlane   pt0, pt1, pt2, pt3;
    285285
    286     /* find pt0 the left most (bottom most) corner */
    287     int imin = 0;
    288     int  min = (int) pt[0].x;
     286    // sort points top to bottom
    289287    int i;
    290     for (i=1; i<4; i++) {
    291         int x = pt[i].x;
    292         if ((x < min) ||
    293             ((x == min) && (pt[i].y < pt[imin].y))) {
    294             imin = i;
    295             min = x;
    296         }
    297     }
    298     // remve pt0 from the list
    299     pt0 = pt[imin];
    300     for (i=imin; i<3; i++) {
    301         pt[i] = pt[i+1];
    302     }
    303 
    304     // find the bottom most (right most) corner from the remaining 3
    305     imin = 0;
    306     min = pt[0].y;
    307     for (i=1; i<3; i++) {
    308         int y = pt[i].y;
    309         if ((y < min) ||
    310             ((y == min) && (pt[i].x > pt[imin].x)) ) {
    311             imin = i;
    312             min = y;
    313         }
    314     }
    315     // remve pt1 from the list
    316     pt1 = pt[imin];
    317     for (i=imin; i<3; i++) {
    318         pt[i] = pt[i+1];
    319     }
    320 
    321     // now find the right most (top most) of the remaining 2 points
    322     if ((pt[0].x > pt[1].x) ||
    323         ((pt[0].x == pt[1].x) && (pt[0].y > pt[1].y))) {
    324         pt2 = pt[0];
     288    int j;
     289    for (i=0; i<4; i++) {
     290        for (j = 0; j < 4; j++) {
     291            if (i == j) continue;
     292            if (pt[i].y > pt[j].y) {
     293                psPlane tmpPt = pt[j];
     294                pt[j] = pt[i];
     295                pt[i] = tmpPt;
     296            }
     297        }
     298    }
     299    // sort bottom two points in x
     300    if (pt[3].x < pt[2].x) {
     301        psPlane tmpPt = pt[3];
     302        pt[3] = pt[2];
     303        pt[2] = tmpPt;
     304    }
     305    // now we know that p[3] point is pt1 - the lower right corner
     306    pt1 = pt[3];
     307   
     308    // And pt[2] is left most of the bottom 2  (either pt0 or pt2)
     309
     310    // find which of the top two is to the left
     311    if (pt[0].x < pt[1].x) {
     312        pt3 = pt[0];
     313        // now decide which of pt[1] and pt[2] is pt0 - on the left)
     314        if (pt[1].x < pt[2].x) {
     315            pt0 = pt[1];
     316            pt2 = pt[2];
     317        } else {
     318            pt0 = pt[2];
     319            pt2 = pt[1];
     320        }
     321    } else {
    325322        pt3 = pt[1];
    326     } else {
    327         pt2 = pt[1];
    328         pt3 = pt[0];
    329     }
    330     /* write the outputs */
     323        // now decide which of pt[0] and pt[2] is pt0 - on the left)
     324        if (pt[0].x < pt[2].x) {
     325            pt0 = pt[0];
     326            pt2 = pt[2];
     327        } else {
     328            pt0 = pt[2];
     329            pt2 = pt[0];
     330        }
     331    }
     332
     333    /* now write the outputs back to the input array*/
    331334    pt[0] = pt0;
    332335    pt[1] = pt1;
    333336    pt[2] = pt2;
    334337    pt[3] = pt3;
    335 }
     338
     339    // And Check the results
     340    // y3 > y0
     341    // y2 > y0
     342    // y3 > y1
     343    // x1 > x0
     344    // x2 > x0
     345    // x2 > x3
     346    if (pt[3].y <= pt[0].y) {
     347        fprintf(stderr, "ERROR calculating diff overlap\n");
     348        fprintf(stderr, "pt[3].y (%f) <= pt[0].y (%f)\n", pt[3].y, pt[0].y);
     349        streaksExit("", PS_EXIT_PROG_ERROR);
     350    }
     351    if (pt[2].y <= pt[0].y) {
     352        fprintf(stderr, "ERROR calculating diff overlap\n");
     353        fprintf(stderr, "pt[2].y (%f) <= pt[0].y (%f)\n", pt[2].y, pt[0].y);
     354        streaksExit("", PS_EXIT_PROG_ERROR);
     355    }
     356    if (pt[3].y <= pt[1].y) {
     357        fprintf(stderr, "ERROR calculating diff overlap\n");
     358        fprintf(stderr, "pt[3].y (%f) <= pt[1].y (%f)\n", pt[3].y, pt[1].y);
     359        streaksExit("", PS_EXIT_PROG_ERROR);
     360    }
     361    if (pt[1].x <= pt[0].x) {
     362        fprintf(stderr, "ERROR calculating diff overlap\n");
     363        fprintf(stderr, "pt[1].x (%f) <= pt[0].x (%f)\n", pt[1].x, pt[0].x);
     364        streaksExit("", PS_EXIT_PROG_ERROR);
     365    }
     366    if (pt[2].x <= pt[0].x) {
     367        fprintf(stderr, "ERROR calculating diff overlap\n");
     368        fprintf(stderr, "pt[2].x (%f) <= pt[0].x (%f)\n", pt[2].x, pt[0].x);
     369        streaksExit("", PS_EXIT_PROG_ERROR);
     370    }
     371    if (pt[2].x <= pt[3].x) {
     372        fprintf(stderr, "ERROR calculating diff overlap\n");
     373        fprintf(stderr, "pt[2].x (%f) <= pt[3].x (%f)\n", pt[2].x, pt[3].x);
     374        streaksExit("", PS_EXIT_PROG_ERROR);
     375    }
     376}
Note: See TracChangeset for help on using the changeset viewer.