IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 14, 2023, 12:48:54 PM (3 years ago)
Author:
tdeboer
Message:

new version of the burntool programme

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/extsrc/gpcsw/gpcsrc/fits/burntool/burnutils.c

    r26766 r42392  
    1818STATIC int grow_box(int nx, int ny, int NX, DTYPE *data, int thr, OBJBOX *box)
    1919{
    20    int i, j, is, ie, left, right;
     20   int i, j,i2,j2, is, ie,jlo,jhi,ilo,ihi, left, right;
    2121
    2222   left = right = 1;
     
    2727
    2828   do {
    29 /* Push the right wall until it's clear */
     29      /* Push the right wall until it's clear */
     30      jlo = box->sy;
     31      jhi = box->ey;
    3032      if(right) {
    31          for(i=box->ex+1; i<nx; i++) {
    32             for(j=box->sy; j<=box->ey; j++) if(data[i+j*NX] >= thr) break;
    33             if(j > box->ey) break;
    34             if(VERBOSE & VERB_BOXGROW) {
    35                printf("right: %8d %8d\n", i, j);
    36             }
    37          }
    38          box->ex = i - 1;
    39          right = 0;
    40       }
    41 
    42 /* Push the left wall until it's clear */
     33             for(i=box->ex+1; i<nx; i++) {
     34               for(j=box->sy; j<=box->ey; j++) if(data[i+j*NX] >= thr) break;
     35          if(j > box->ey) break;
     36          for(j2=box->ey; j2>=box->sy; j2--) if(data[i+j2*NX] >= thr) break;
     37          if(j2 < box->sy) break;
     38
     39          /*Since stars are roughly diamonds, the new vertices should be contained within the previous ones*/
     40          /*If not, there is a discontinuity, and we might have overlapping sources*/
     41          if(!(j >= jlo-0.1*(jhi-jlo) && j2 <= jhi+0.1*(jhi-jlo))) {break;}
     42
     43               if(VERBOSE & VERB_BOXGROW) {
     44                 printf("right: %8d %8d %8d\n", i, j,data[i+j*NX]);
     45               }
     46          jlo = j;
     47          jhi = j2;
     48             }
     49             box->ex = i - 1;
     50             right = 0;
     51      }
     52
     53      /* Push the left wall until it's clear */
     54      jlo = box->sy;
     55      jhi = box->ey;
    4356      if(left) {
    44          for(i=box->sx-1; i>=0; i--) {
    45             for(j=box->sy; j<=box->ey; j++) if(data[i+j*NX] >= thr) break;
    46             if(j > box->ey) break;
    47             if(VERBOSE & VERB_BOXGROW) {
    48                printf("left: %8d %8d\n", i, j);
    49             }
    50          }
    51          box->sx = i + 1;
    52          left = 0;
    53       }
    54 
    55 /* Push the top wall until it's clear, catching corners! */
     57             for(i=box->sx-1; i>=0; i--) {
     58               for(j=box->sy; j<=box->ey; j++) if(data[i+j*NX] >= thr) break;
     59               if(j > box->ey) break;
     60          for(j2=box->ey; j2<=box->sy; j2--) if(data[i+j2*NX] >= thr) break;
     61          if(j2 < box->sy) break;
     62
     63          /*Since stars are roughly diamonds, the new vertices should be contained within the previous ones*/
     64          /*If not, there is a discontinuity, and we might have overlapping sources*/
     65          if(!(j >= jlo-0.1*(jhi-jlo) && j2 <= jhi+0.1*(jhi-jlo))) {break;}
     66
     67               if(VERBOSE & VERB_BOXGROW) {
     68                 printf("left: %8d %8d %8d\n", i, j,data[i+j*NX]);
     69               }
     70          jlo = j;
     71          jhi = j2;
     72             }
     73             box->sx = i + 1;
     74             left = 0;
     75      }
     76
     77      /* Push the top wall until it's clear, catching corners! */
    5678      is = MAX(0, box->sx-1);
    5779      ie = MIN(nx-1, box->ex+1);
     80      ilo = is;
     81      ihi = ie;
    5882      for(j=box->ey+1; j<ny; j++) {
    59          for(i=is; i<=ie; i++) if(data[i+j*NX] >= thr) break;
    60          if(i == is && box->sx>0) left = 1;     /* Need to redo left */
    61          if(data[ie+j*NX] >= thr && box->ex<nx-1) right = 1;  /* Redo right */
    62          if(i > ie) break;                      /* All clear */
    63          if(VERBOSE & VERB_BOXGROW) {
    64             printf("top: %8d %8d\n", i, j);
    65          }
     83             for(i=is; i<=ie; i++) if(data[i+j*NX] >= thr) break;
     84        if(i > ie) break;        /* All clear */
     85        for(i2=ie; i2<=is; i--) if(data[i2+j*NX] >= thr) break;
     86        if(i2 < is) break;        /* All clear */
     87
     88             if(i == is && box->sx>0) left = 1; /* First point hits thr, so need to redo left */
     89             if(data[ie+j*NX] >= thr && box->ex<nx-1) right = 1;  /*Last point hits thr, so redo right */
     90
     91        /*Since stars are roughly diamonds, the new vertices should be contained within the previous ones*/
     92        /*If not, there is a discontinuity, and we might have overlapping sources*/
     93        if(!(i >= ilo-0.1*(ihi-ilo) && i2 <= ihi+0.1*(ihi-ilo))) {break;}
     94
     95             if(VERBOSE & VERB_BOXGROW) {
     96               printf("top: %8d %8d %8d\n", i, j,data[i+j*NX]);
     97             }
     98        ilo = i;
     99        ihi = i2;
    66100      }
    67101      box->ey = j - 1;
    68102
    69 /* Push the bottom wall until it's clear, catching corners! */
     103      /* Push the bottom wall until it's clear, catching corners! */
    70104      is = MAX(0,box->sx-1);
    71105      ie = MIN(nx-1,box->ex+1);
     106      ilo = is;
     107      ihi = ie;
    72108      for(j=box->sy-1; j>=0; j--) {
    73          for(i=is; i<=ie; i++) if(data[i+j*NX] >= thr) break;
    74          if(i == is && box->sx>0) left = 1;     /* Need to redo left */
    75          if(data[is+1+j*NX] >= thr) box->y0m = j;
    76          if(data[ie+j*NX] >= thr && box->ex<nx-1) right = 1;  /* Redo right */
    77          if(data[ie-1+j*NX] >= thr) box->y1m = j;
    78          if(i > ie) break;                      /* All clear */
    79          if(VERBOSE & VERB_BOXGROW) {
    80             printf("bottom: %8d %8d %8d %8d\n", i, j, box->y0m, box->y1m);
    81          }
     109             for(i=is; i<=ie; i++) if(data[i+j*NX] >= thr) break;
     110        if(i > ie) break;        /* All clear */
     111        for(i2=ie; i2<=is; i--) if(data[i2+j*NX] >= thr) break;
     112        if(i2 < is) break;        /* All clear */
     113
     114             if(i == is && box->sx>0) left = 1; /* Need to redo left */
     115        if(data[ie+j*NX] >= thr && box->ex<nx-1) right = 1;  /* Redo right */
     116
     117             if(data[is+1+j*NX] >= thr) box->y0m = j;
     118             if(data[ie-1+j*NX] >= thr) box->y1m = j;
     119
     120        /*Since stars are roughly diamonds, the new vertices should be contained within the previous ones*/
     121        /*If not, there is a discontinuity, and we might have overlapping sources*/
     122        if(!(i >= ilo-0.1*(ihi-ilo) && i2 <= ihi+0.1*(ihi-ilo))) break;
     123
     124             if(VERBOSE & VERB_BOXGROW) {
     125               printf("bottom: %8d %8d %8d %8d %8d\n", i, j, box->y0m, box->y1m,data[i+j*NX]);
     126             }
     127        ilo = i;
     128        ihi = i2;
    82129      }
    83130      box->sy = j + 1;
     
    126173                     double rfac, int maskval, int nbox, OBJBOX *box)
    127174{
    128    int i, j, k, x0, y0, db, dr, r2, i0, i1, j0, j1;
     175   int i, j, k, x0, y0, db, dr, r2, i0, i1, j0, j1,boxsize;
    129176
    130177   for(k=0; k<nbox; k++) {
     
    137184
    138185      for(j=j0; j<=j1; j++) {
    139          for(i=i0+1; i<i1; i++) {
    140             if(mask[i+j*NX] == MASK_NONE) mask[i+j*NX] = maskval;
    141             if(mask[i+j*NX] == MASK_NONE) mask[i+j*NX] = maskval;
    142          }
     186             for(i=i0+1; i<i1; i++) {
     187              if(mask[i+j*NX] == MASK_NONE) mask[i+j*NX] = maskval;
     188              if(mask[i+j*NX] == MASK_NONE) mask[i+j*NX] = maskval;
     189             }
    143190      }
    144191
    145192/* Push out the center to a diameter rfac*xsize */
    146193      x0 = (box[k].sx + box[k].ex + 1) / 2;
    147       y0 = (box[k].y0p + box[k].y1p + box[k].y0m + box[k].y1m + 2) / 4;
    148       dr = NINT((box[k].ex - box[k].sx + 1) * 0.5 * rfac);
     194      //y0 = (box[k].y0p + box[k].y1p + box[k].y0m + box[k].y1m + 2) / 4;
     195      y0 = (box[k].sy + box[k].ey + 1) / 2;
     196      boxsize = MAX((box[k].ex - box[k].sx + 1),(box[k].ey - box[k].sy + 1));
     197      dr = NINT(boxsize * 0.5 * rfac);
    149198      for(j=MAX(0,y0-dr); j<=MIN(ny-1, y0+dr); j++) {
    150          for(i=MAX(0,x0-dr); i<=MIN(nx-1, x0+dr); i++) {
    151             r2 = (i-x0)*(i-x0) + (j-y0)*(j-y0);
    152             if(r2 < dr*dr && mask[i+j*NX] == MASK_NONE)
     199             for(i=MAX(0,x0-dr); i<=MIN(nx-1, x0+dr); i++) {
     200               r2 = (i-x0)*(i-x0) + (j-y0)*(j-y0);
     201               if(r2 < dr*dr && mask[i+j*NX] == MASK_NONE)
    153202               mask[i+j*NX] = maskval;
    154          }
     203             }
    155204      }
    156205   }
Note: See TracChangeset for help on using the changeset viewer.