imageprocessing/guidedVectorize.c
POINT_T* findPoint(BYTE* image,int width, int height,
		   int refx, int refy, int tolerance, int direction)
{
    POINT_T * pNew = NULL;
    POINT_T refpoint;
    int bFound = 0;     /* flag telling us we've found a white pixel */
    int xFound = -1;  /* coordinates of points found */
    int yFound = -1;
    int i = 0;
    int j = 0;
    char message[256]; /* for logging */
    int stepsX[] = {0,1,1,1,0,-1,-1,-1};    /* N, NE, E, SE, S, SW, W, NW */
    int stepsY[] = {-1,-1,0,1,1,1,0,-1};    /* N, NE, E, SE, S, SW, W, NW */
    int nextX[] = {1,0,0,-1,-1,0,0,1};
    int nextY[] = {0,1,1,0,0,-1,-1,0};
    int order[] = {0,1,-1,2,-2,3,-3,4};     /* increment to add to get which direction
					     * to check next 
					     */
    int radius = 1;  /* start at 1, gradually increase */
    refpoint.x = refx;
    refpoint.y = refy;
    sprintf(message,"Looking for point at (%d,%d) direction %s\n",refx,refy,directionLabels[direction]);
    logOutput(message);
    //printf(message);
    //showNeighborhood(image,width,height,refx,refy,tolerance,-1,-1);
    if (direction < 0)
       direction = 0;
    /* First examine the exact same location in the image! */
    if (pixval(refx,refy,width) == WHITE)
      {
      xFound = refx;
      yFound = refy;
      bFound = 1;
      }
    //if (bFound)
    //  logOutput("Found exact match\n");

    /* If we didn't get a match at the exact pixel, look around it.
     * Start at preferred direction, then search one on either side, two on either side, etc.
     */
    while ((!bFound) & (radius <= tolerance))
      {  
      int dirX =0;
      int dirY =0;
      int dirXNext = 0;
      int dirYNext = 0;
      int baseIncX = 0;
      int baseIncY = 0;
      int incrementX = 0;
      int incrementY = 0;
      int signDiffX = 0;
      int signDiffY = 0;
      //sprintf(message,"--- RADIUS IS %d\n",radius);
      //logOutput(message);
      
      for (i = 0; (i < 8) && (!bFound); i++)
	{  
	dirX = stepsX[i];
	dirY = stepsY[i];
	baseIncX = dirX * radius; 
	baseIncY = dirY * radius; 
	for (j = 0; (j < radius) && (!bFound); j++)
	  {
	  incrementX = baseIncX + nextX[i]*j;
	  incrementY = baseIncY + nextY[i]*j;
          if ((refx + incrementX < 0) || 
	      (refx + incrementX >= width) ||
	      (refy + incrementY < 0) || 
	      (refy + incrementY >= height))
	    continue; 
	  sprintf(message,"--- Examining (%d,%d)\n",refx+incrementX,refy+incrementY);
	  //logOutput(message);
	  //printf(message);
	  //showNeighborhood(image,width,height,refx,refy,tolerance,refx+incrementX,refy+incrementY);
	  if (pixval((refx+incrementX),(refy+incrementY),width) == WHITE)
	      {
	      xFound = refx+incrementX;
	      yFound = refy+incrementY;
	      bFound = 1;
	      }
          } /* end j loop */
	}   /* end i loop */
      radius++;
      }
    if (bFound)
      {
      sprintf(message,"--- FOUND at (%d,%d)\n",xFound,yFound);
      logOutput(message);

      pNew = calloc(1,sizeof(POINT_T));
      if (pNew == NULL)
	{
	  printf("Error allocating point structure\n");
	  exit(100);
	}
      pNew->x = xFound;
      pNew->y = yFound;
      pNew->matchdistance = calculateDistance(&refpoint,pNew);
      }

    return pNew;
}
/* Look for match to point refx,refy, starting at the same pixel
 * and looking in the neighborhood.
 * Must be within 'tolerance' pixels 
 * If found allocate a POINT_T for that point and return it.
 * @param image  BYTE array of data values to search
 * @param width  Width of the image
 * @param height Height of the image
 * @param refx   Reference feature start x
 * @param refy   Reference feature start y
 * @param tolerance Radius of region to search for the starting point
 * @param direction Preferred direction for searching: 0 = N, 1 = NE, 2 = E, etc.
 *               Based on direction between last ref point and last target point
 *               -1 if no information (or the last ref and last target were the same)
 * @return newly allocated POINT_T with coordinates set, or NULL if can't find
 */
Look for match to point refx,refy, starting at the same pixel
and looking in the neighborhood.
Must be within 'tolerance' pixels
If found allocate a POINT_T for that point and return it.
Look for match to point refx refy starting at the same pixel and looking in the neighborhood . Must be within ' tolerance ' pixels If found allocate a POINT_T for that point and return it .
POINT_T* findPoint(BYTE* image,int width, int height,
		   int refx, int refy, int tolerance, int direction)
{
    POINT_T * pNew = NULL;
    POINT_T refpoint;
    int bFound = 0;     
    int xFound = -1;  
    int yFound = -1;
    int i = 0;
    int j = 0;
    char message[256]; 
    int stepsX[] = {0,1,1,1,0,-1,-1,-1};    
    int stepsY[] = {-1,-1,0,1,1,1,0,-1};    
    int nextX[] = {1,0,0,-1,-1,0,0,1};
    int nextY[] = {0,1,1,0,0,-1,-1,0};
    int order[] = {0,1,-1,2,-2,3,-3,4};     
    int radius = 1;  
    refpoint.x = refx;
    refpoint.y = refy;
    sprintf(message,"Looking for point at (%d,%d) direction %s\n",refx,refy,directionLabels[direction]);
    logOutput(message);
    if (direction < 0)
       direction = 0;
    if (pixval(refx,refy,width) == WHITE)
      {
      xFound = refx;
      yFound = refy;
      bFound = 1;
      }
    while ((!bFound) & (radius <= tolerance))
      {  
      int dirX =0;
      int dirY =0;
      int dirXNext = 0;
      int dirYNext = 0;
      int baseIncX = 0;
      int baseIncY = 0;
      int incrementX = 0;
      int incrementY = 0;
      int signDiffX = 0;
      int signDiffY = 0;
      for (i = 0; (i < 8) && (!bFound); i++)
	{  
	dirX = stepsX[i];
	dirY = stepsY[i];
	baseIncX = dirX * radius; 
	baseIncY = dirY * radius; 
	for (j = 0; (j < radius) && (!bFound); j++)
	  {
	  incrementX = baseIncX + nextX[i]*j;
	  incrementY = baseIncY + nextY[i]*j;
          if ((refx + incrementX < 0) || 
	      (refx + incrementX >= width) ||
	      (refy + incrementY < 0) || 
	      (refy + incrementY >= height))
	    continue; 
	  sprintf(message,"--- Examining (%d,%d)\n",refx+incrementX,refy+incrementY);
	  if (pixval((refx+incrementX),(refy+incrementY),width) == WHITE)
	      {
	      xFound = refx+incrementX;
	      yFound = refy+incrementY;
	      bFound = 1;
	      }
          } 
	}   
      radius++;
      }
    if (bFound)
      {
      sprintf(message,"--- FOUND at (%d,%d)\n",xFound,yFound);
      logOutput(message);
      pNew = calloc(1,sizeof(POINT_T));
      if (pNew == NULL)
	{
	  printf("Error allocating point structure\n");
	  exit(100);
	}
      pNew->x = xFound;
      pNew->y = yFound;
      pNew->matchdistance = calculateDistance(&refpoint,pNew);
      }
    return pNew;
}
POINT_T * findPoint ( BYTE * image , int width , int height , int refx , int refy , int tolerance , int direction ) { POINT_T * pNew = NULL ; POINT_T refpoint ; int bFound = 0 ; int xFound = -1 ; int yFound = -1 ; int i = 0 ; int j = 0 ; char message [ 256 ] ; int stepsX [ ] = { 0 , 1 , 1 , 1 , 0 , -1 , -1 , -1 } ; int stepsY [ ] = { -1 , -1 , 0 , 1 , 1 , 1 , 0 , -1 } ; int nextX [ ] = { 1 , 0 , 0 , -1 , -1 , 0 , 0 , 1 } ; int nextY [ ] = { 0 , 1 , 1 , 0 , 0 , -1 , -1 , 0 } ; int order [ ] = { 0 , 1 , -1 , 2 , -2 , 3 , -3 , 4 } ; int radius = 1 ; refpoint . x = refx ; refpoint . y = refy ; sprintf ( message , " \n " , refx , refy , directionLabels [ direction ] ) ; logOutput ( message ) ; if ( direction < 0 ) direction = 0 ; if ( pixval ( refx , refy , width ) == WHITE ) { xFound = refx ; yFound = refy ; bFound = 1 ; } while ( ( ! bFound ) & ( radius <= tolerance ) ) { int dirX = 0 ; int dirY = 0 ; int dirXNext = 0 ; int dirYNext = 0 ; int baseIncX = 0 ; int baseIncY = 0 ; int incrementX = 0 ; int incrementY = 0 ; int signDiffX = 0 ; int signDiffY = 0 ; for ( i = 0 ; ( i < 8 ) && ( ! bFound ) ; i ++ ) { dirX = stepsX [ i ] ; dirY = stepsY [ i ] ; baseIncX = dirX * radius ; baseIncY = dirY * radius ; for ( j = 0 ; ( j < radius ) && ( ! bFound ) ; j ++ ) { incrementX = baseIncX + nextX [ i ] * j ; incrementY = baseIncY + nextY [ i ] * j ; if ( ( refx + incrementX < 0 ) || ( refx + incrementX >= width ) || ( refy + incrementY < 0 ) || ( refy + incrementY >= height ) ) continue ; sprintf ( message , " \n " , refx + incrementX , refy + incrementY ) ; if ( pixval ( ( refx + incrementX ) , ( refy + incrementY ) , width ) == WHITE ) { xFound = refx + incrementX ; yFound = refy + incrementY ; bFound = 1 ; } } } radius ++ ; } if ( bFound ) { sprintf ( message , " \n " , xFound , yFound ) ; logOutput ( message ) ; pNew = calloc ( 1 , sizeof ( POINT_T ) ) ; if ( pNew == NULL ) { printf ( " \n " ) ; exit ( 100 ) ; } pNew -> x = xFound ; pNew -> y = yFound ; pNew -> matchdistance = calculateDistance ( & refpoint , pNew ) ; } return pNew ; }
Look for match to point refx,refy, starting at the same pixel
 and looking in the neighborhood.
Look for match to point refx refy starting at the same pixel and looking in the neighborhood .
/* flag telling us we've found a white pixel */ /* coordinates of points found */ /* for logging */ /* N, NE, E, SE, S, SW, W, NW */ /* N, NE, E, SE, S, SW, W, NW */ /* increment to add to get which direction
					     * to check next 
					     */ /* start at 1, gradually increase */ //printf(message); //showNeighborhood(image,width,height,refx,refy,tolerance,-1,-1); /* First examine the exact same location in the image! */ //if (bFound) //  logOutput("Found exact match\n"); /* If we didn't get a match at the exact pixel, look around it.
     * Start at preferred direction, then search one on either side, two on either side, etc.
     */ //sprintf(message,"--- RADIUS IS %d\n",radius); //logOutput(message); //logOutput(message); //printf(message); //showNeighborhood(image,width,height,refx,refy,tolerance,refx+incrementX,refy+incrementY); /* end j loop */ /* end i loop */