Main Page   Data Structures   File List   Data Fields   Globals  

region_of_interest.c

Go to the documentation of this file.
00001 #include  <stdio.h>
00002 #include  <malloc.h>
00003 #include  "sadie.h"
00004 #include  "proto.h"
00005 #include  "mosaic.h"
00006 
00007 
00008 /* variables necessary for computing vstart and vend with bresh algorithm */
00009 extern int **x_array_buffer;        /* The data where info is stored      */
00010 extern int point;                   /* Counter for points used            */
00011 extern int count_point;             /* Flag to decide whether to count or fill array */
00012 
00013 
00014 
00015 /*----------------------------------------------------------------------------*/
00016 /*-General Information--------------------------------------------------------*/
00017 /*                                                                            */
00018 /*   This function computes vstart for each column in the mosaic image        */
00019 /*   from starting point to ending point based on bresh algorithm             */
00020 /*                                                                            */
00021 /*----------------------------------------------------------------------------*/
00022 /*-Interface Information------------------------------------------------------*/
00023 void COMPUTEVSTART(
00024 MOSAIC_INDEX *index,      /* Pointer to mosaic index */
00025 int X1,                   /* Coordinates of starting point */
00026 int Y1,                   
00027 int X2,                   /* Coordinates of ending point   */
00028 int Y2
00029 )
00030 /*----------------------------------------------------------------------------*/
00031 {
00032     int l;
00033     int prev;
00034 
00035     /* Count number of points in line */
00036     count_point = TRUE;
00037     point = 0;
00038     brshnm(X1, Y1, X2, Y2);
00039     
00040     /* Allocate memory */
00041     x_array_buffer = (int **) malloc((long)point*sizeof(int *));
00042     if (x_array_buffer == (int **) NULL){
00043         MESSAGE('E'," Memory request failed.");
00044         goto the_end;
00045     } else {
00046         
00047         for  (l = 0; l < point; l++){
00048             x_array_buffer[l] = (int  *) calloc(2, sizeof(int));
00049             if (x_array_buffer[l] == (int) NULL){
00050                 MESSAGE('E'," Memory request failed.");
00051                 goto the_end;
00052             }
00053         }
00054         
00055         /* Fill array */ 
00056         count_point = FALSE;
00057         point = 0;
00058         brshnm(X1, Y1, X2, Y2);
00059 
00060         prev = -1;
00061         for (l = 0; l < point; l++) {
00062             if (x_array_buffer[l][0] != prev) {
00063                 if (x_array_buffer[l][1] >= index->voffset[x_array_buffer[l][0]])
00064                     index->vstart[x_array_buffer[l][0]] = x_array_buffer[l][1];
00065                 else
00066                     index->vstart[x_array_buffer[l][0]] = index->voffset[x_array_buffer[l][0]];
00067             }
00068             
00069             prev = x_array_buffer[l][0];
00070         }
00071         
00072         if(x_array_buffer) {
00073             /* Free Bresh Array */
00074             for (l = 0; l < point; l++){
00075                 if(x_array_buffer[l]) {
00076                     free(x_array_buffer[l]);
00077                     x_array_buffer[l] = NULL;
00078                 }
00079             }
00080             
00081             free(x_array_buffer);
00082             x_array_buffer = NULL;
00083         }
00084         
00085     }
00086     
00087     
00088     the_end:
00089     return;
00090     
00091 }
00092 
00093 
00094 /*----------------------------------------------------------------------------*/
00095 /*-General Information--------------------------------------------------------*/
00096 /*                                                                            */
00097 /*   This function computes vend for each column in the mosaic image          */
00098 /*   from starting point to ending point based on bresh algorithm             */
00099 /*                                                                            */
00100 /*----------------------------------------------------------------------------*/
00101 /*-Interface Information------------------------------------------------------*/
00102 void COMPUTEVEND(
00103 MOSAIC_INDEX *index,      /* Pointer to mosaic index */
00104 int X1,                   /* Coordinates of starting point */
00105 int Y1,                   
00106 int X2,                   /* Coordinates of ending point   */
00107 int Y2             
00108 )
00109 /*----------------------------------------------------------------------------*/
00110 {
00111     int l;
00112     int prev;
00113     
00114     /* Count number of points in line */
00115     count_point = TRUE;
00116     point = 0;
00117     brshnm(X1, Y1, X2, Y2);
00118     
00119     /* Allocate memory */
00120     x_array_buffer = (int **) malloc((long)point*sizeof(int *));
00121     if (x_array_buffer == (int **) NULL){
00122         MESSAGE('E'," Memory request failed.");
00123         goto the_end;
00124     } else {
00125         
00126         for  (l = 0; l < point; l++){
00127             x_array_buffer[l] = (int  *) calloc(2, sizeof(int));
00128             if (x_array_buffer[l] == (int) NULL){
00129                 MESSAGE('E'," Memory request failed.");
00130                 goto the_end;
00131             }
00132         }
00133         
00134         /* Fill array */ 
00135         count_point = FALSE;
00136         point = 0;
00137         brshnm(X1, Y1, X2, Y2);
00138 
00139         prev = -1;
00140         for (l = 0; l < point; l++) {
00141             if (x_array_buffer[l][0] != prev) {
00142                 if (x_array_buffer[l][1] < index->voffset[x_array_buffer[l][0]] + index->vheight[x_array_buffer[l][0]])
00143                     index->vend[x_array_buffer[l][0]] = x_array_buffer[l][1];
00144                 else
00145                     index->vend[x_array_buffer[l][0]] = index->voffset[x_array_buffer[l][0]] + index->vheight[x_array_buffer[l][0]] - 1;
00146             }
00147             prev = x_array_buffer[l][0];
00148         }
00149         
00150         if(x_array_buffer) {
00151             /* Free Bresh Array */
00152             for (l = 0; l < point; l++){
00153                 if(x_array_buffer[l]) {
00154                     free(x_array_buffer[l]);
00155                     x_array_buffer[l] = NULL;
00156                 }
00157             }
00158             
00159             free(x_array_buffer);
00160             x_array_buffer = NULL;
00161         }
00162         
00163     }
00164 
00165 
00166     the_end:
00167     return;
00168     
00169 }
00170 
00171 
00172 /*----------------------------------------------------------------------------*/
00173 /*-General Information--------------------------------------------------------*/
00174 /*                                                                            */
00175 /*   This function computes the local index for a given frame from mosaic     */
00176 /*   index.                                                                   */
00177 /*                                                                            */
00178 /*----------------------------------------------------------------------------*/
00179 /*-Interface Information------------------------------------------------------*/
00180 void COMPUTE_LOCAL_INDEX(
00181 MOSAIC_INDEX *index,      /*  I   Pointer to mosaic index                     */
00182 int i,                  /*  I   Frame number                                */
00183 int jbgn,               /*  I   Starting line.                              */
00184 int jend,               /*  I   Ending line.                                */
00185 int kbgn,               /*  I   Starting pixel.                             */
00186 int kend,               /*  I   Ending pixel.                               */
00187 LOCAL_INDEX **localindex   /*  O   Address of a pointer to the local index     */                        
00188 )
00189 /*----------------------------------------------------------------------------*/
00190 {
00191 
00192     int k, npix, nlin;
00193     int startx, endx, starty, endy, shift;
00194     int vstart, vend;
00195 
00196     nlin = jend - jbgn + 1;
00197     npix = kend - kbgn + 1;
00198     startx = index->frame[i].startx;
00199     endx = index->frame[i].endx;
00200     starty = index->frame[i].starty;
00201     endy = index->frame[i].endy;
00202     
00203     (*localindex) = (LOCAL_INDEX *)malloc(sizeof(LOCAL_INDEX));
00204     (*localindex)->vstart = (short *)malloc(npix*sizeof(short));
00205     (*localindex)->vend = (short *)malloc(npix*sizeof(short));
00206 
00207     (*localindex)->hstart = (index->hstart > startx? index->hstart - startx + 5: 5);
00208     (*localindex)->hend = (index->hend < endx? npix-1-5 - (endx - index->hend): npix-1-5 );
00209 
00210     for (k = (*localindex)->hstart; k <= (*localindex)->hend; k++) {
00211         shift = k-1-5 + startx;
00212         if (shift < index->hstart)
00213             shift = index->hstart;
00214         else if (shift > index->hend)
00215             shift = index->hend;
00216         
00217         vstart = index->vstart[shift] - starty + 5;
00218         vstart = vstart < 5? 5: vstart;
00219         (*localindex)->vstart[k] = vstart;
00220         
00221         vend = nlin-1-5 - (endy - index->vend[shift]);
00222         vend = vend > nlin-1-5? nlin-1-5: vend;
00223         (*localindex)->vend[k] = vend;
00224     }
00225 
00226     
00227     
00228     return;
00229 }

Generated on Wed Apr 9 08:56:10 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002