src/boxfunc5.c
l_ok
boxaPlotSizes(BOXA        *boxa,
              const char  *plotname,
              NUMA       **pnaw,
              NUMA       **pnah,
              PIX        **ppixd)
{
char            buf[128], titlebuf[128];
static l_int32  plotid = 0;
l_int32         n, i, w, h;
BOXA           *boxat;
GPLOT          *gplot;
NUMA           *naw, *nah;

    PROCNAME("boxaPlotSizes");

    if (pnaw) *pnaw = NULL;
    if (pnah) *pnah = 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 the width and height */
    naw = numaCreate(n);
    nah = numaCreate(n);
    for (i = 0; i < n; i++) {
        boxaGetBoxGeometry(boxat, i, NULL, NULL, &w, &h);
        numaAddNumber(naw, w);
        numaAddNumber(nah, h);
    }
    boxaDestroy(&boxat);

    lept_mkdir("lept/plots");
    if (plotname) {
        snprintf(buf, sizeof(buf), "/tmp/lept/plots/size.%s", plotname);
        snprintf(titlebuf, sizeof(titlebuf), "%s: Box size vs. box index",
                 plotname);
    } else {
        snprintf(buf, sizeof(buf), "/tmp/lept/plots/size.%d", plotid++);
        snprintf(titlebuf, sizeof(titlebuf), "Box size vs. box index");
    }
    gplot = gplotCreate(buf, GPLOT_PNG, titlebuf,
                        "box index", "box dimension");
    gplotAddPlot(gplot, NULL, naw, GPLOT_LINES, "width");
    gplotAddPlot(gplot, NULL, nah, GPLOT_LINES, "height");
    *ppixd = gplotMakeOutputPix(gplot);
    gplotDestroy(&gplot);

    if (pnaw)
        *pnaw = naw;
    else
        numaDestroy(&naw);
    if (pnah)
        *pnah = nah;
    else
        numaDestroy(&nah);
    return 0;
}
/*!
 * \brief   boxaPlotSizes()
 *
 * \param[in]    boxa       source boxa
 * \param[in]    plotname   [optional], can be NULL
 * \param[out]   pnaw       [optional] na of widths
 * \param[out]   pnah       [optional] na of heights
 * \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 box width
 *          and height 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 box width
and height 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 box width and height 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
boxaPlotSizes(BOXA        *boxa,
              const char  *plotname,
              NUMA       **pnaw,
              NUMA       **pnah,
              PIX        **ppixd)
{
char            buf[128], titlebuf[128];
static l_int32  plotid = 0;
l_int32         n, i, w, h;
BOXA           *boxat;
GPLOT          *gplot;
NUMA           *naw, *nah;
    PROCNAME("boxaPlotSizes");
    if (pnaw) *pnaw = NULL;
    if (pnah) *pnah = 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);
    naw = numaCreate(n);
    nah = numaCreate(n);
    for (i = 0; i < n; i++) {
        boxaGetBoxGeometry(boxat, i, NULL, NULL, &w, &h);
        numaAddNumber(naw, w);
        numaAddNumber(nah, h);
    }
    boxaDestroy(&boxat);
    lept_mkdir("lept/plots");
    if (plotname) {
        snprintf(buf, sizeof(buf), "/tmp/lept/plots/size.%s", plotname);
        snprintf(titlebuf, sizeof(titlebuf), "%s: Box size vs. box index",
                 plotname);
    } else {
        snprintf(buf, sizeof(buf), "/tmp/lept/plots/size.%d", plotid++);
        snprintf(titlebuf, sizeof(titlebuf), "Box size vs. box index");
    }
    gplot = gplotCreate(buf, GPLOT_PNG, titlebuf,
                        "box index", "box dimension");
    gplotAddPlot(gplot, NULL, naw, GPLOT_LINES, "width");
    gplotAddPlot(gplot, NULL, nah, GPLOT_LINES, "height");
    *ppixd = gplotMakeOutputPix(gplot);
    gplotDestroy(&gplot);
    if (pnaw)
        *pnaw = naw;
    else
        numaDestroy(&naw);
    if (pnah)
        *pnah = nah;
    else
        numaDestroy(&nah);
    return 0;
}
l_ok boxaPlotSizes ( BOXA * boxa , const char * plotname , NUMA * * pnaw , NUMA * * pnah , PIX * * ppixd ) { char buf [ 128 ] , titlebuf [ 128 ] ; static l_int32 plotid = 0 ; l_int32 n , i , w , h ; BOXA * boxat ; GPLOT * gplot ; NUMA * naw , * nah ; PROCNAME ( " " ) ; if ( pnaw ) * pnaw = NULL ; if ( pnah ) * pnah = 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 ) ; naw = numaCreate ( n ) ; nah = numaCreate ( n ) ; for ( i = 0 ; i < n ; i ++ ) { boxaGetBoxGeometry ( boxat , i , NULL , NULL , & w , & h ) ; numaAddNumber ( naw , w ) ; numaAddNumber ( nah , h ) ; } 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 , naw , GPLOT_LINES , " " ) ; gplotAddPlot ( gplot , NULL , nah , GPLOT_LINES , " " ) ; * ppixd = gplotMakeOutputPix ( gplot ) ; gplotDestroy ( & gplot ) ; if ( pnaw ) * pnaw = naw ; else numaDestroy ( & naw ) ; if ( pnah ) * pnah = nah ; else numaDestroy ( & nah ) ; return 0 ; }
\brief   boxaPlotSizes()
 \param[in]    boxa       source boxa
 \param[in]    plotname   [optional], can be NULL
 \param[out]   pnaw       [optional] na of widths
 \param[out]   pnah       [optional] na of heights
 \param[out]   ppixd      pix of the output plot
 \return  0 if OK, 1 on error
\ brief boxaPlotSizes () \ param [ in ] boxa source boxa \ param [ in ] plotname [ optional ] can be NULL \ param [ out ] pnaw [ optional ] na of widths \ param [ out ] pnah [ optional ] na of heights \ param [ out ] ppixd pix of the output plot \ return 0 if OK 1 on error
/* Build the numas for the width and height */