home *** CD-ROM | disk | FTP | other *** search
/ vis-ftp.cs.umass.edu / vis-ftp.cs.umass.edu.tar / vis-ftp.cs.umass.edu / pub / Software / ASCENDER / support.c < prev    next >
C/C++ Source or Header  |  1996-05-30  |  5KB  |  239 lines

  1. #include "../polygons.h"
  2.  
  3.  
  4. /**
  5. float sweep_mask(c_handle im, int x, int y, int width, int len,
  6.                 float Dx, float Dy, int *maxPos, int virt,
  7.                 int *dir);
  8. float convolve_at(c_handle im, int x, int y, int len,
  9.                         float Dx, float Dy);
  10. **/
  11. int calcDelta(c_handle im, int x, int y, int axis);
  12.  
  13.  
  14. int mask[5];
  15.  
  16. double support_val(c_handle im, cList *ptr, int *axis, int x2, int y2,
  17.                 float Dx, float Dy, int *pos, int virt)
  18. /*****
  19.     Calculate the underlying edge support the lies in the intensity
  20.     plane from the corner at 'ptr' and (x1,y1).
  21.  
  22.     This should be done by construction of a local edge template
  23.     and looking at the intensity plane for a gradient.
  24.  
  25.     However, right now, simply search for a local corner point
  26.     compute the overlap of that line projected onto the hypothesized
  27.     edge.
  28.  
  29. ******/
  30. {
  31.  
  32.     int dir;
  33.     double s_val;
  34.     int i;
  35.  
  36.     /** First Check for another line that intersects the "proposed" 
  37.         one, with an angle close to 90 degrees **/
  38.         
  39.     if (distance(ptr->x,ptr->y,x2,y2) > MIN_LINE_LENGTH) {
  40.  
  41.       if (!conflictIntersection(ptr->x,ptr->y,x2,y2) || virt) {
  42.  
  43.  
  44.     /*** VIRTUAL FEATURE SUPPORT ONLY REQUIRES THAT THE SUM OF THE 
  45.          SUPPORTS Be > MIN_LINE_SUPPORT ***/
  46.       if (virt) 
  47.         s_val = (double) image_line_support(im,(double)ptr->x,
  48.             (double)ptr->y,
  49.             (double)x2,(double)y2,(double)LINE_SWEEP_COLUMN,
  50.             0.0);
  51.       else 
  52.           s_val = (double) image_line_support(im,(double)ptr->x,
  53.             (double)ptr->y,
  54.             (double)x2,(double)y2,(double)LINE_SWEEP_COLUMN,
  55.             MIN_LINE_SUPPORT);
  56.         }
  57.       else {
  58.        s_val = 0.0;
  59.       }
  60.         } else
  61.        s_val = 0.0;
  62.  
  63.  
  64.    return(s_val);
  65. }
  66.  
  67.  
  68. double virtualSupport(c_handle im, Point *feature,
  69.                  cList *vert1, int axis, cList *vert2, int *dir)
  70. {
  71. /*** Is there enough edge support for a virtual feature to be
  72.      created at (feature.x,feature.y)?  Check both corners against
  73.      the new feature and the intensity gradient of the lines between
  74.      them.  If they both pass MIN_EDGE_SUPPORT, then return the sum 
  75.      of the supports.
  76. ***/
  77.  
  78.     double support1, support2;
  79.     float Dx, Dy;
  80.     int pos1, pos2;
  81.     int axis2;
  82.  
  83.     /*** swap the axis, because we are looking forward from the dfs
  84.          search axis. **/
  85.     if (axis == AXIS1)
  86.         axis = AXIS2;
  87.     else
  88.         axis = AXIS1;  
  89.  
  90.     if (axis == AXIS1) {
  91.         Dx = vert1->leg1Dx;    
  92.         Dy = vert1->leg1Dy;
  93.     }
  94.     else {
  95.         Dx = vert1->leg2Dx;    
  96.         Dy = vert1->leg2Dy;
  97.     }
  98.     /*
  99.       * NOTE: pos1, and pos2 are unused as of version 1.0
  100.      *      in the future they will be use to set the correct
  101.      *    corner location according to the maximum edge response
  102.      */
  103.     pos1 = 0;
  104.     pos2 = 0;
  105.  
  106.     support1 = support_val(im,vert1,dir,(int)floor(feature->x),
  107.                         (int)floor(feature->y), Dx, Dy,
  108.                          &pos1, 1);
  109.  
  110.     /** We know that vert2 must have a different axis type **/
  111.     if (axis == AXIS1)
  112.         axis = AXIS2;
  113.     else
  114.         axis = AXIS1;
  115.  
  116.     if (axis == AXIS1) {
  117.         Dx = vert2->leg1Dx;    
  118.         Dy = vert2->leg1Dy;
  119.     }
  120.     else {
  121.         Dx = vert2->leg2Dx;    
  122.         Dy = vert2->leg2Dy;
  123.     }
  124.  
  125.     support2 = support_val(im,vert2,dir,(int)floor(feature->x),
  126.                                             (int)floor(feature->y),Dx,Dy, &pos2, 1);
  127.  
  128.  
  129.     if ( ((support1+support2)/2.0) > MIN_LINE_SUPPORT) {
  130.             (int)feature->x_corr = (int)feature->x + pos1;    
  131.             (int)feature->y_corr = (int)feature->y + pos2;    
  132.         return((support1 + support2)/2.0);
  133.     }
  134.     else {
  135.           (int)feature->x_corr = -1;
  136.           (int)feature->y_corr = -1;
  137.       return(0.0);
  138.     }
  139.         
  140. }
  141.  
  142.  
  143. void
  144. calc_line_direction(char *image, int u1, int v1, int u2, int v2,
  145.                              float *dx, float *dy)
  146. {
  147.  
  148.     /*** Project the (u,v) co-ordinates into 3D and take a step 
  149.          in the direction indicated by type and axis.  Project
  150.          the 3D result into the image. ***/
  151.  
  152.     mat_4x1        vec1;
  153.     mat_4x1     vec2;
  154.     double         StepX, StepY;
  155.  
  156. /***********
  157.  
  158.     vec1[0] = (double) u1; vec2[0] = (double) u2;
  159.     vec1[1] = (double) v1; vec2[1] = (double) v2;
  160.     vec1[2] = 0.0;           vec2[2] = 0.0;
  161.     vec1[3] = 1.0;           vec2[3] = 1.0;
  162.  
  163.  
  164.     project_2d_to_3d(image,vec1,vec1);
  165.     project_2d_to_3d(image,vec2,vec2);
  166.  
  167.     StepX = vec2[0] - vec1[0];
  168.     StepY = vec2[1] - vec1[1];
  169.  
  170.     vec1[0] = vec1[0] + StepX;
  171.     vec1[1] = vec1[1] + StepY;
  172.  
  173.     project_3d_to_2d(image,vec1,vec1);
  174. ***********/
  175.  
  176.     StepX = (double)(u2 - u1);
  177.     StepY = (double)(v2 - v1);
  178.  
  179.     if (fabs(StepX) > fabs(StepY) ) {
  180.        if (StepX < 0) 
  181.         *dx = -1.0;
  182.        else
  183.         *dx = 1.0;
  184.        *dy = (StepY/fabs(StepX));
  185.     }
  186.     else {
  187.         if (StepY < 0)
  188.         *dy = -1.0;
  189.        else
  190.         *dy = 1.0;
  191.        *dx = (StepX / fabs(StepY));
  192.     }
  193.     
  194.  
  195.  
  196.     /** Normalize the Line length with respect to the maximum change
  197.         to compute a Delta X, Delta Y for line following ...
  198.     if (fabs(vec1[0]) > fabs(vec1[0]) ) {
  199.        if (vec1[0] < 0) 
  200.         *dx = -1.0;
  201.        else
  202.         *dx = 1.0;
  203.        *dy = (vec1[1]/fabs(vec1[0]));
  204.     }
  205.     else {
  206.         if (vec1[1] < 0)
  207.         *dy = -1.0;
  208.        else
  209.         *dy = 1.0;
  210.        *dx = (vec1[0] / fabs(vec1[1]));
  211.     }
  212.     ***/
  213.  
  214.  
  215. }
  216.  
  217. int calcDelta(c_handle im, int x, int y, int axis)
  218. {
  219.  
  220.  
  221.     int delta;
  222.  
  223.     if (axis == X) {
  224.        delta = iref_int(im,(int)x,(int)y-2)*mask[0];
  225.        delta += iref_int(im,(int)x,(int)y-1)*mask[1];
  226.            delta += iref_int(im,(int)x,(int)y)*mask[2];
  227.            delta += iref_int(im,(int)x,(int)y+1)*mask[3];
  228.            delta += iref_int(im,(int)x,(int)y+2)*mask[4];
  229.     } else {
  230.        delta = iref_int(im,(int)x-2,(int)y)*mask[0];
  231.        delta += iref_int(im,(int)x-1,(int)y)*mask[1];
  232.            delta += iref_int(im,(int)x,(int)y)*mask[2];
  233.            delta += iref_int(im,(int)x+1,(int)y)*mask[3];
  234.            delta += iref_int(im,(int)x+2,(int)y)*mask[4];
  235.     }
  236.  
  237.     return(delta);
  238. }
  239.