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 / process.c < prev    next >
C/C++ Source or Header  |  1995-07-06  |  5KB  |  186 lines

  1. #include "../polygons.h"
  2.  
  3. #define BORDER    5
  4. /*
  5.  *
  6.  * acquireModel
  7.  * 
  8.  * This is the main program to take an RCDE image and search for
  9.  * polygons using the perceptual grouping algorithm of the building
  10.  * finder.  
  11.  *
  12.  * The image _must_ be part of a 3d world so that the grouping algorithm
  13.  * can recover the world-to-image transform matrix/function.
  14.  *
  15.  * The algorithm proceeds as follows:
  16.  *
  17.  * Open the 3d lines file, 
  18.  *     Compute 3d intersections,
  19.  *     Partition the image into regions of Maxblock in size
  20.  *    compute polygon.
  21.  *     if a polygon is found in region i, then mark region i 
  22.  *    as done.
  23.  *    place all polygons into the 3dWorld
  24.  * Open the 2dLines file
  25.  *    Compute 2d intersections,
  26.  *    For all regions that are not marked as used, 
  27.  *    compute polygons.
  28.  *    
  29.  *    Save polygons with the image 2dWorld.
  30.  *     Store 2d polygon data to file until they can be triangulated
  31.  *    
  32.  *
  33.  * Takes the following parameters:
  34.  *
  35.  *      Image Name    : directory and filename of the input image.
  36.  *    3d lines     : Line file for 3d data (null if no such file exists)
  37.  *    2d lines    : Line file for 2d data 
  38.  *     Maxblock    : Maximum block size to use for each iteration
  39.  *              of the building detector algorithm. (in feet).
  40.  *    Overlap     : Amount of overlap between iterations. (in feet).
  41.  *    
  42.  *    
  43.  *
  44.  * Written for RCDE Version 2.
  45.  *
  46.  * RADIUS Project.
  47.  * UMass, Amherst.
  48.  * Computer Vision Research Laboratory
  49.  *
  50.  * Christopher Jaynes
  51.  */
  52.  
  53. /*
  54.  * Global Defs necessary to run the detector properly (pane and image)
  55.  *
  56.  */
  57. c_handle    userPane;
  58. c_handle    userImage;
  59.  
  60.  
  61.  
  62. int acquireModel(double Sensitivity, int constrain, double maxBlock, double overlap)
  63. {
  64.  
  65.  
  66.     struct c_handle_1_int_3*        pick, *pick_a_pane();
  67.     c_handle    view;
  68.     double_2    *drawPoint1, *drawPoint2;
  69.  
  70.     char         lineFile[280];
  71.     char         cornerFile[280];
  72.     c_handle    inImage;
  73.     int        i;
  74.     int        j;
  75.     int        numRegionsX, numRegionsY;
  76.     double_2    *temp;
  77.     int        Ncorners;
  78.  
  79.  
  80.     
  81.  
  82.     /*
  83.      * Open the input image file. User selected the appropriate image.
  84.      */
  85.  
  86.     setup_defaults(Sensitivity);
  87.  
  88.     CONSTRAIN = constrain;
  89.  
  90.     pick = pick_a_pane(get_interactor(0),1,"Pick Image for Model Acquisition.");
  91.  
  92.     in_pane = pick->h1;
  93.     inImage = working_image(get_2d_world(top_image(1,in_pane)));
  94.     view =  top_view(1,in_pane);
  95.  
  96.         view_trans = two_d_to_window_transform(view);
  97.     image_trans = image_to_window_transform(view);
  98.  
  99.  
  100.     numRegionsY = (image_y_dim(inImage)-(2*BORDER)) / (maxBlock-overlap);
  101.     numRegionsX = (image_x_dim(inImage)-(2*BORDER)) / (maxBlock-overlap);
  102.  
  103.     fprintf(stderr,"NumX %d, NumY %d\n",numRegionsX,numRegionsY);
  104.  
  105.     strcpy(lineFile,get2_5dlineFile(inImage));
  106.     sprintf(cornerFile,"%scorners",getTempDir(inImage));
  107.  
  108.     for (i = 0; i < numRegionsY; i++) 
  109.        for (j = 0; j < numRegionsX; j++) {
  110.         xstart = j*(maxBlock-overlap)+BORDER;
  111.         ystart = i*(maxBlock-overlap)+BORDER;
  112.         xstop  = (j*(maxBlock-overlap))+maxBlock+BORDER;
  113.         ystop  = (i*(maxBlock-overlap))+maxBlock+BORDER;
  114.  
  115.         if (xstop >= image_x_dim(inImage) )
  116.             xstop = image_x_dim(inImage) - BORDER;
  117.         if (ystop >= image_y_dim(inImage) )
  118.             ystop = image_y_dim(inImage) - BORDER;
  119.  
  120.         temp = (double_2 *) transform_point(view_trans,(double)
  121.                 xstart, (double) ystart, 0);
  122.  
  123.                 drawPoint1 = (double_2 *)inverse_transform_point(image_trans,
  124.                     temp->d1, temp->d2,0);
  125.  
  126.         temp = (double_2 *) transform_point(view_trans,(double)
  127.                 xstop, (double) ystop, 0);
  128.                 drawPoint2 = (double_2 *)inverse_transform_point(image_trans,
  129.                     temp->d1, temp->d2,0);
  130.  
  131.          refresh(in_pane);
  132.  
  133.  
  134.  
  135.         /*** Draw the bounding region ***/
  136.             draw_fat_line(in_pane,drawPoint1->d1,drawPoint1->d2,
  137.                                 drawPoint2->d1,drawPoint1->d2,1.0);
  138.             draw_fat_line(in_pane,drawPoint2->d1,drawPoint1->d2,
  139.                                 drawPoint2->d1,drawPoint2->d2,1.0);
  140.             draw_fat_line(in_pane,drawPoint2->d1,drawPoint2->d2,
  141.                                 drawPoint1->d1,drawPoint2->d2,1.0);
  142.             draw_fat_line(in_pane,drawPoint1->d1,drawPoint2->d2,
  143.                                 drawPoint1->d1,drawPoint1->d2,1.0);
  144.  
  145.  
  146.  
  147.         fprintf(stderr,"Region %d:(%d %d, %d %d)\n",
  148.                     i+j,xstart,ystart,xstop,ystop);
  149.         strcpy(lineFile,get2_5dlineFile(inImage));
  150.             Ncorners = compute_intersections_region(lineFile,cornerFile,
  151.             in_pane, inImage, xstart,ystart, xstop,ystop);
  152.  
  153.         fprintf(stderr,"Found %d corners.\n",Ncorners);
  154.         strcpy(lineFile, get2dlineFile(inImage));
  155.         process_region(lineFile, cornerFile, inImage);
  156.  
  157.         }
  158.  
  159. }
  160.  
  161.  
  162.  
  163. /* 
  164.  * mask_regions
  165.  *
  166.  * Take a list of bounding boxes that have been found to contain polygons.
  167.  *
  168.  * Remove from the line data any lines take have an endpoint within one
  169.  * of these regions.
  170.  * The modified line data is stored in a new file, return the new file name.
  171.  *
  172.  * NOTE: This procedure assumes that the lines are stored in the "Tokens"
  173.  *      directory.
  174.  
  175. char *
  176. mask_regions(file *name, boundingBox *list)
  177. {
  178.  
  179.     while (list != NULL)
  180.         list = list->next;
  181.  
  182.  
  183.     return(name);
  184. }
  185.  */
  186.