Exemple #1
0
/* --------------------------------------------
 * gap_locateAreaWithinRadius
 * --------------------------------------------
 * processing starts at reference coords and continues
 * outwards upto targetMoveRadius for 4 quadrants.
 * 
 * returns average color difference (0.0 upto 1.0)
 *    where 0.0 indicates exact matching area
 *      and 1.0 indicates all pixel have maximum color diff (when comaring full white agains full black area)
 */
gdouble
gap_locateAreaWithinRadius(gint32  refDrawableId
  , gint32  refX
  , gint32  refY
  , gint32  refShapeRadius
  , gint32  targetDrawableId
  , gint32  targetMoveRadius
  , gint32  *targetX
  , gint32  *targetY
  )
{
  gdouble avgColordiff;
  
  avgColordiff =
    gap_locateAreaWithinRadiusWithOffset(refDrawableId
       , refX
       , refY
       , refShapeRadius
       , targetDrawableId
       , targetMoveRadius
       , targetX
       , targetY
       , 0
       , 0
       );
  return (avgColordiff);
  
}  /* end gap_locateAreaWithinRadius */
/* ------------------------------------
 * p_locate_target
 * ------------------------------------
 */
static void
p_locate_target(gint32 refLayerId, PixelCoords *refCoords
                , gint32 targetLayerId, PixelCoords *targetCoords
                , gint32 locateOffsetX, gint32 locateOffsetY
                , FilterValues *valPtr, gint32 *lostTraceCount)
{
    gdouble colordiffLocate;
    gint          ref_offset_x;
    gint          ref_offset_y;
    gint          target_offset_x;
    gint          target_offset_y;
    gint32        refX;
    gint32        refY;
    gint32        targetX;
    gint32        targetY;


    /* get offsets of the layers within the image */
    gimp_drawable_offsets (refLayerId, &ref_offset_x, &ref_offset_y);
    gimp_drawable_offsets (targetLayerId, &target_offset_x, &target_offset_y);

    targetCoords->valid = FALSE;
    refX = refCoords->px - ref_offset_x;
    refY = refCoords->py - ref_offset_y;
    colordiffLocate =
        gap_locateAreaWithinRadiusWithOffset (refLayerId
                , refX
                , refY
                , valPtr->refShapeRadius
                , targetLayerId
                , valPtr->targetMoveRadius
                , &targetX
                , &targetY
                , locateOffsetX
                , locateOffsetY
                                             );

    targetCoords->px = targetX + target_offset_x;
    targetCoords->py = targetY + target_offset_y;


    if (colordiffLocate < valPtr->loacteColodiffThreshold)
    {
        /* successful located the deatail in target layer
         * set target coordinates valid.
         */
        targetCoords->valid = TRUE;
    }
    else
    {
        (*lostTraceCount) += 1;
    }

    if(gap_debug)
    {
        printf("p_locate_target: refX:%d refY:%d locateOffsetX:%d locateOffsetY:%d\n"
               "                targetX:%d targetY:%d targetCoords->px:%d py:%d  avgColodiff:%.5f valid:%d\n"
               ,(int)refX
               ,(int)refY
               ,(int)locateOffsetX
               ,(int)locateOffsetY
               ,(int)targetX
               ,(int)targetY
               ,(int)targetCoords->px
               ,(int)targetCoords->py
               ,(float)colordiffLocate
               , targetCoords->valid
              );
    }


}  /* end p_locate_target */