src/boxfunc5.c
l_ok
boxaPlotSides(BOXA        *boxa,
              const char  *plotname,
              NUMA       **pnal,
              NUMA       **pnat,
              NUMA       **pnar,
              NUMA       **pnab,
              PIX        **ppixd)
{
char            buf[128], titlebuf[128];
char           *dataname;
static l_int32  plotid = 0;
l_int32         n, i, w, h, left, top, right, bot;
l_int32         debugprint = FALSE;  /* change to TRUE to spam stderr */
l_float32       med, dev;
BOXA           *boxat;
GPLOT          *gplot;
NUMA           *nal, *nat, *nar, *nab;

    PROCNAME("boxaPlotSides");

    if (pnal) *pnal = NULL;
    if (pnat) *pnat = NULL;
    if (pnar) *pnar = NULL;
    if (pnab) *pnab = NULL;
    if (ppixd) *ppixd = NULL;
    if (!boxa)
        return ERROR_INT("boxa not defined", procName, 1);
    if ((n = boxaGetCount(boxa)) < 2)
        return ERROR_INT("less than 2 boxes", procName, 1);
    if (!ppixd)
        return ERROR_INT("&pixd not defined", procName, 1);

    boxat = boxaFillSequence(boxa, L_USE_ALL_BOXES, 0);

        /* Build the numas for each side */
    nal = numaCreate(n);
    nat = numaCreate(n);
    nar = numaCreate(n);
    nab = numaCreate(n);

    for (i = 0; i < n; i++) {
        boxaGetBoxGeometry(boxat, i, &left, &top, &w, &h);
        right = left + w - 1;
        bot = top + h - 1;
        numaAddNumber(nal, left);
        numaAddNumber(nat, top);
        numaAddNumber(nar, right);
        numaAddNumber(nab, bot);
    }
    boxaDestroy(&boxat);

    lept_mkdir("lept/plots");
    if (plotname) {
        snprintf(buf, sizeof(buf), "/tmp/lept/plots/sides.%s", plotname);
        snprintf(titlebuf, sizeof(titlebuf), "%s: Box sides vs. box index",
                 plotname);
    } else {
        snprintf(buf, sizeof(buf), "/tmp/lept/plots/sides.%d", plotid++);
        snprintf(titlebuf, sizeof(titlebuf), "Box sides vs. box index");
    }
    gplot = gplotCreate(buf, GPLOT_PNG, titlebuf,
                        "box index", "side location");
    gplotAddPlot(gplot, NULL, nal, GPLOT_LINES, "left side");
    gplotAddPlot(gplot, NULL, nat, GPLOT_LINES, "top side");
    gplotAddPlot(gplot, NULL, nar, GPLOT_LINES, "right side");
    gplotAddPlot(gplot, NULL, nab, GPLOT_LINES, "bottom side");
    *ppixd = gplotMakeOutputPix(gplot);
    gplotDestroy(&gplot);

    if (debugprint) {
        dataname = (plotname) ? stringNew(plotname) : stringNew("no_name");
        numaGetMedian(nal, &med);
        numaGetMeanDevFromMedian(nal, med, &dev);
        lept_stderr("%s left: med = %7.3f, meandev = %7.3f\n",
                    dataname, med, dev);
        numaGetMedian(nat, &med);
        numaGetMeanDevFromMedian(nat, med, &dev);
        lept_stderr("%s top: med = %7.3f, meandev = %7.3f\n",
                    dataname, med, dev);
        numaGetMedian(nar, &med);
        numaGetMeanDevFromMedian(nar, med, &dev);
        lept_stderr("%s right: med = %7.3f, meandev = %7.3f\n",
                    dataname, med, dev);
        numaGetMedian(nab, &med);
        numaGetMeanDevFromMedian(nab, med, &dev);
        lept_stderr("%s bot: med = %7.3f, meandev = %7.3f\n",
                    dataname, med, dev);
        LEPT_FREE(dataname);
    }

    if (pnal)
        *pnal = nal;
    else
        numaDestroy(&nal);
    if (pnat)
        *pnat = nat;
    else
        numaDestroy(&nat);
    if (pnar)
        *pnar = nar;
    else
        numaDestroy(&nar);
    if (pnab)
        *pnab = nab;
    else
        numaDestroy(&nab);
    return 0;
}
/*!
 * \brief   boxaPlotSides()
 *
 * \param[in]    boxa       source boxa
 * \param[in]    plotname   [optional], can be NULL
 * \param[out]   pnal       [optional] na of left sides
 * \param[out]   pnat       [optional] na of top sides
 * \param[out]   pnar       [optional] na of right sides
 * \param[out]   pnab       [optional] na of bottom sides
 * \param[out]   ppixd      pix of the output plot
 * \return  0 if OK, 1 on error
 *
 * <pre>
 * Notes:
 *      (1) This debugging function shows the progression of the four
 *          sides in the boxa.  There must be at least 2 boxes.
 *      (2) If there are invalid boxes (e.g., if only even or odd
 *          indices have valid boxes), this will fill them with the
 *          nearest valid box before plotting.
 *      (3) The plotfiles are put in /tmp/lept/plots/, and are named
 *          either with %plotname or, if NULL, a default name.  If
 *          %plotname is used, make sure it has no whitespace characters.
 * </pre>
 */



Notes:
(1) This debugging function shows the progression of the four
sides in the boxa.  There must be at least 2 boxes.
(2) If there are invalid boxes , this will fill them with the
nearest valid box before plotting.
(3) The plotfiles are put in /tmp/lept/plots/, and are named
either with %plotname or, if NULL, a default name.  If
%plotname is used, make sure it has no whitespace characters.
Notes : ( 1 ) This debugging function shows the progression of the four sides in the boxa . There must be at least 2 boxes . ( 2 ) If there are invalid boxes this will fill them with the nearest valid box before plotting . ( 3 ) The plotfiles are put in / tmp / lept / plots / and are named either with %plotname or if NULL a default name . If %plotname is used make sure it has no whitespace characters .
l_ok
boxaPlotSides(BOXA        *boxa,
              const char  *plotname,
              NUMA       **pnal,
              NUMA       **pnat,
              NUMA       **pnar,
              NUMA       **pnab,
              PIX        **ppixd)
{
char            buf[128], titlebuf[128];
char           *dataname;
static l_int32  plotid = 0;
l_int32         n, i, w, h, left, top, right, bot;
l_int32         debugprint = FALSE;  
l_float32       med, dev;
BOXA           *boxat;
GPLOT          *gplot;
NUMA           *nal, *nat, *nar, *nab;
    PROCNAME("boxaPlotSides");
    if (pnal) *pnal = NULL;
    if (pnat) *pnat = NULL;
    if (pnar) *pnar = NULL;
    if (pnab) *pnab = NULL;
    if (ppixd) *ppixd = NULL;
    if (!boxa)
        return ERROR_INT("boxa not defined", procName, 1);
    if ((n = boxaGetCount(boxa)) < 2)
        return ERROR_INT("less than 2 boxes", procName, 1);
    if (!ppixd)
        return ERROR_INT("&pixd not defined", procName, 1);
    boxat = boxaFillSequence(boxa, L_USE_ALL_BOXES, 0);
    nal = numaCreate(n);
    nat = numaCreate(n);
    nar = numaCreate(n);
    nab = numaCreate(n);
    for (i = 0; i < n; i++) {
        boxaGetBoxGeometry(boxat, i, &left, &top, &w, &h);
        right = left + w - 1;
        bot = top + h - 1;
        numaAddNumber(nal, left);
        numaAddNumber(nat, top);
        numaAddNumber(nar, right);
        numaAddNumber(nab, bot);
    }
    boxaDestroy(&boxat);
    lept_mkdir("lept/plots");
    if (plotname) {
        snprintf(buf, sizeof(buf), "/tmp/lept/plots/sides.%s", plotname);
        snprintf(titlebuf, sizeof(titlebuf), "%s: Box sides vs. box index",
                 plotname);
    } else {
        snprintf(buf, sizeof(buf), "/tmp/lept/plots/sides.%d", plotid++);
        snprintf(titlebuf, sizeof(titlebuf), "Box sides vs. box index");
    }
    gplot = gplotCreate(buf, GPLOT_PNG, titlebuf,
                        "box index", "side location");
    gplotAddPlot(gplot, NULL, nal, GPLOT_LINES, "left side");
    gplotAddPlot(gplot, NULL, nat, GPLOT_LINES, "top side");
    gplotAddPlot(gplot, NULL, nar, GPLOT_LINES, "right side");
    gplotAddPlot(gplot, NULL, nab, GPLOT_LINES, "bottom side");
    *ppixd = gplotMakeOutputPix(gplot);
    gplotDestroy(&gplot);
    if (debugprint) {
        dataname = (plotname) ? stringNew(plotname) : stringNew("no_name");
        numaGetMedian(nal, &med);
        numaGetMeanDevFromMedian(nal, med, &dev);
        lept_stderr("%s left: med = %7.3f, meandev = %7.3f\n",
                    dataname, med, dev);
        numaGetMedian(nat, &med);
        numaGetMeanDevFromMedian(nat, med, &dev);
        lept_stderr("%s top: med = %7.3f, meandev = %7.3f\n",
                    dataname, med, dev);
        numaGetMedian(nar, &med);
        numaGetMeanDevFromMedian(nar, med, &dev);
        lept_stderr("%s right: med = %7.3f, meandev = %7.3f\n",
                    dataname, med, dev);
        numaGetMedian(nab, &med);
        numaGetMeanDevFromMedian(nab, med, &dev);
        lept_stderr("%s bot: med = %7.3f, meandev = %7.3f\n",
                    dataname, med, dev);
        LEPT_FREE(dataname);
    }
    if (pnal)
        *pnal = nal;
    else
        numaDestroy(&nal);
    if (pnat)
        *pnat = nat;
    else
        numaDestroy(&nat);
    if (pnar)
        *pnar = nar;
    else
        numaDestroy(&nar);
    if (pnab)
        *pnab = nab;
    else
        numaDestroy(&nab);
    return 0;
}
l_ok boxaPlotSides ( BOXA * boxa , const char * plotname , NUMA * * pnal , NUMA * * pnat , NUMA * * pnar , NUMA * * pnab , PIX * * ppixd ) { char buf [ 128 ] , titlebuf [ 128 ] ; char * dataname ; static l_int32 plotid = 0 ; l_int32 n , i , w , h , left , top , right , bot ; l_int32 debugprint = FALSE ; l_float32 med , dev ; BOXA * boxat ; GPLOT * gplot ; NUMA * nal , * nat , * nar , * nab ; PROCNAME ( " " ) ; if ( pnal ) * pnal = NULL ; if ( pnat ) * pnat = NULL ; if ( pnar ) * pnar = NULL ; if ( pnab ) * pnab = NULL ; if ( ppixd ) * ppixd = NULL ; if ( ! boxa ) return ERROR_INT ( " " , procName , 1 ) ; if ( ( n = boxaGetCount ( boxa ) ) < 2 ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! ppixd ) return ERROR_INT ( " " , procName , 1 ) ; boxat = boxaFillSequence ( boxa , L_USE_ALL_BOXES , 0 ) ; nal = numaCreate ( n ) ; nat = numaCreate ( n ) ; nar = numaCreate ( n ) ; nab = numaCreate ( n ) ; for ( i = 0 ; i < n ; i ++ ) { boxaGetBoxGeometry ( boxat , i , & left , & top , & w , & h ) ; right = left + w - 1 ; bot = top + h - 1 ; numaAddNumber ( nal , left ) ; numaAddNumber ( nat , top ) ; numaAddNumber ( nar , right ) ; numaAddNumber ( nab , bot ) ; } boxaDestroy ( & boxat ) ; lept_mkdir ( " " ) ; if ( plotname ) { snprintf ( buf , sizeof ( buf ) , " " , plotname ) ; snprintf ( titlebuf , sizeof ( titlebuf ) , " " , plotname ) ; } else { snprintf ( buf , sizeof ( buf ) , " " , plotid ++ ) ; snprintf ( titlebuf , sizeof ( titlebuf ) , " " ) ; } gplot = gplotCreate ( buf , GPLOT_PNG , titlebuf , " " , " " ) ; gplotAddPlot ( gplot , NULL , nal , GPLOT_LINES , " " ) ; gplotAddPlot ( gplot , NULL , nat , GPLOT_LINES , " " ) ; gplotAddPlot ( gplot , NULL , nar , GPLOT_LINES , " " ) ; gplotAddPlot ( gplot , NULL , nab , GPLOT_LINES , " " ) ; * ppixd = gplotMakeOutputPix ( gplot ) ; gplotDestroy ( & gplot ) ; if ( debugprint ) { dataname = ( plotname ) ? stringNew ( plotname ) : stringNew ( " " ) ; numaGetMedian ( nal , & med ) ; numaGetMeanDevFromMedian ( nal , med , & dev ) ; lept_stderr ( " \n " , dataname , med , dev ) ; numaGetMedian ( nat , & med ) ; numaGetMeanDevFromMedian ( nat , med , & dev ) ; lept_stderr ( " \n " , dataname , med , dev ) ; numaGetMedian ( nar , & med ) ; numaGetMeanDevFromMedian ( nar , med , & dev ) ; lept_stderr ( " \n " , dataname , med , dev ) ; numaGetMedian ( nab , & med ) ; numaGetMeanDevFromMedian ( nab , med , & dev ) ; lept_stderr ( " \n " , dataname , med , dev ) ; LEPT_FREE ( dataname ) ; } if ( pnal ) * pnal = nal ; else numaDestroy ( & nal ) ; if ( pnat ) * pnat = nat ; else numaDestroy ( & nat ) ; if ( pnar ) * pnar = nar ; else numaDestroy ( & nar ) ; if ( pnab ) * pnab = nab ; else numaDestroy ( & nab ) ; return 0 ; }
\brief   boxaPlotSides()
 \param[in]    boxa       source boxa
 \param[in]    plotname   [optional], can be NULL
 \param[out]   pnal       [optional] na of left sides
 \param[out]   pnat       [optional] na of top sides
 \param[out]   pnar       [optional] na of right sides
 \param[out]   pnab       [optional] na of bottom sides
 \param[out]   ppixd      pix of the output plot
 \return  0 if OK, 1 on error
\ brief boxaPlotSides () \ param [ in ] boxa source boxa \ param [ in ] plotname [ optional ] can be NULL \ param [ out ] pnal [ optional ] na of left sides \ param [ out ] pnat [ optional ] na of top sides \ param [ out ] pnar [ optional ] na of right sides \ param [ out ] pnab [ optional ] na of bottom sides \ param [ out ] ppixd pix of the output plot \ return 0 if OK 1 on error
/* change to TRUE to spam stderr */ /* Build the numas for each side */