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 / ascendMar8.tar / UMass / BuildingFinder / Staging / grouping.c < prev    next >
C/C++ Source or Header  |  1995-08-16  |  3KB  |  119 lines

  1. #include "../polygons.h"
  2. #include "../stdDefs.h"
  3.  
  4.  
  5. int inSearchCone(cList *c, cList *candidate, int axis, double sAngle)
  6. /*
  7.  * Test If the 'candidate' corner lays in the search cone projected
  8.  * from 'c'.  The width of the cone is defined by SEARCH_ANGLE.
  9.  *
  10.  *
  11.  */
  12. {
  13.  
  14.     double ray_x1, ray_y1, ray_x2, ray_y2;
  15.     double colInt, rowInt;
  16.     double px, py;
  17.     double theta;
  18.     
  19.  
  20.     /* Create a ray, starting at point 'c' and extending in the
  21.        image plane in a direction given by Dx, and Dy of the
  22.        axis. */
  23.     ray_x1 = (double) c->x; ray_y1 = (double) c->y;
  24.     if (axis == AXIS1) {
  25.        ray_x2 = ray_x1 + c->leg1Dx*LINE_SEARCH_DIST;
  26.        ray_y2 = ray_y1 + c->leg1Dy*LINE_SEARCH_DIST;
  27.     } else {
  28.        ray_x2 = ray_x1 + c->leg2Dx*LINE_SEARCH_DIST;
  29.        ray_y2 = ray_y1 + c->leg2Dy*LINE_SEARCH_DIST;
  30.     }
  31.     
  32.  
  33.  
  34.     /* Now check if 'candiate' overlaps the ray */
  35.     theta = LineSegTheta(ray_x1,ray_y1,ray_x2,ray_y2);
  36.     LineSegColIntercept(ray_x1,ray_y1,ray_x2,ray_y2,&colInt);
  37.     LineSegRowIntercept(ray_x1,ray_y1,ray_x2,ray_y2,&rowInt);
  38.     
  39.     
  40.      /* Project a perp. line from 'candidate' to the ray */
  41.     PtLinePerpIntercept((double)candidate->x,(double)candidate->y,
  42.             colInt,rowInt,theta,&px,&py);
  43.  
  44.     /** Take the point of intersection and check if it is on the
  45.         segment. **/
  46.     if (CheckPtParlLineSeg(px,py,0.0,0.0,
  47.         LineLength(ray_x1,ray_y1,ray_x1,ray_y2),theta,
  48.         ray_x1,ray_y1,ray_x2,ray_y2) != 0) {
  49.         /* printf("Does not Overlap !\n"); */
  50.         return(FALSE);
  51.     }
  52.  
  53.     /** Now see if the perp line to the ray from the point is within
  54.            the search cone. **/
  55.     if (LineLength(px,py,(double)candidate->x,(double)candidate->y) <= 
  56.         (3.0 + (sAngle*LineLength(px,py,(double)c->x,(double)c->y))) ) {         
  57.         return(TRUE);
  58.     }
  59.     else {
  60.         return(FALSE);
  61.     }
  62. }
  63.     
  64.  
  65. int cornersCompatible(cList *c1, cList *c2)
  66. {
  67.  
  68.  
  69.     /** Check if 'c1' and 'c2' are compatile.  That is 
  70.         if c2 is in a cone defined by SEARCH_ANGLE from c1 and
  71.         c1 is in a cone from c2 defined by a looser constraint.
  72.         Then the corners are compatible.  This is tested both
  73.           ways, that is if c1 is in c2's "tight" cone **/
  74.     
  75.     float Dx, Dy;
  76.  
  77.     if ( fabs(c1->height - c2->height) > HEIGHT_BUCKET)  {
  78.         return(FALSE);
  79.     }
  80.  
  81.     if (distance((double)c1->x,(double)c1->y,(double)c2->x,
  82.         (double)c2->y) < MIN_LINE_LENGTH)
  83.         return(FALSE);
  84.  
  85.     
  86.     Dx = c1->x - c2->x;    Dy = c1->y - c2->y;
  87.  
  88.     if (c1->x == c2->x && c1->y == c2->y)
  89.         return(FALSE);
  90.  
  91.     if ( inSearchCone(c1,c2,AXIS1,SEARCH_ANGLE)) {
  92.         if  (inSearchCone(c2,c1,AXIS1,SEARCH_ANGLE+0.1)
  93.              || inSearchCone(c2,c1,AXIS2,SEARCH_ANGLE+0.1) ) {
  94.         return(AXIS1);
  95.         }
  96.     }
  97.     if ( inSearchCone(c1,c2,AXIS2,SEARCH_ANGLE)) { 
  98.         if (inSearchCone(c2,c1,AXIS1,SEARCH_ANGLE+0.1)
  99.              || inSearchCone(c2,c1,AXIS2,SEARCH_ANGLE+0.1) ) {
  100.         return(AXIS2);
  101.         }
  102.     }
  103.  
  104.  
  105.     if ( inSearchCone(c2,c1,AXIS1,SEARCH_ANGLE)) {
  106.         if  (inSearchCone(c1,c2,AXIS1,SEARCH_ANGLE+0.1)
  107.              || inSearchCone(c1,c2,AXIS2,SEARCH_ANGLE+0.1) )
  108.         return(AXIS1);
  109.     }
  110.     if ( inSearchCone(c2,c1,AXIS2,SEARCH_ANGLE)) { 
  111.         if (inSearchCone(c1,c2,AXIS1,SEARCH_ANGLE+0.1)
  112.              || inSearchCone(c1,c2,AXIS2,SEARCH_ANGLE+0.1) )
  113.         return(AXIS2);
  114.     }
  115.  
  116.  
  117.     return(FALSE);
  118. }
  119.