46 #include <config_auto.h>
49 #include "allheaders.h"
67 l_float32 maxoverlap);
69 static const l_int32 DefaultMaxPops = 20000;
73 #define OUTPUT_HEAP_STATS 0
196 l_float32 maxoverlap,
201 l_int32 i, w, h, n, nsub, npush, npop;
203 BOXA *boxa, *boxa4, *boxasub, *boxad;
208 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
213 return (
BOXA *)ERROR_PTR(
"invalid sort flag", __func__, NULL);
216 L_WARNING(
"setting maxboxes = 1\n", __func__);
218 if (maxoverlap < 0.0 || maxoverlap > 1.0)
219 return (
BOXA *)ERROR_PTR(
"invalid maxoverlap", __func__, NULL);
221 maxpops = DefaultMaxPops;
243 if (npop > maxpops) {
271 for (i = 0; i < nsub; i++) {
275 partel->boxa = boxasub;
288 #if OUTPUT_HEAP_STATS
290 lept_stderr(
" Number of boxes pushed: %d\n", npush);
291 lept_stderr(
" Number of boxes popped: %d\n", npop);
335 if (ppartel == NULL) {
336 L_WARNING(
"ptr address is null!\n", __func__);
340 if ((partel = *ppartel) == NULL)
367 return ERROR_INT(
"partel not defined", __func__, 1);
371 partel->size = (l_float32)w;
373 partel->size = (l_float32)h;
375 partel->size = (l_float32)L_MIN(w, h);
377 partel->size = (l_float32)L_MAX(w, h);
379 partel->size = (l_float32)(w + h);
381 partel->size = (l_float32)(w * h);
383 return ERROR_INT(
"invalid sortflag", __func__, 1);
407 l_int32 x, y, w, h, xp, yp, wp, hp;
413 return (
BOXA *)ERROR_PTR(
"box not defined", __func__, NULL);
415 return (
BOXA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
430 if (xp + wp < x + w) {
431 boxsub =
boxCreate(xp + wp, y, x + w - xp - wp, h);
434 if (yp + hp < y + h) {
435 boxsub =
boxCreate(x, yp + hp, w, y + h - yp - hp);
483 l_int32 i, n, bw, bh, w, h;
484 l_int32 smallfound, minindex, perim, minsize;
485 l_float32 delx, dely, mindist, threshdist, dist, x, y, cx, cy;
489 return (
BOX *)ERROR_PTR(
"box not defined", __func__, NULL);
491 return (
BOX *)ERROR_PTR(
"boxa not defined", __func__, NULL);
494 return (
BOX *)ERROR_PTR(
"no boxes in boxa", __func__, NULL);
495 if (fract < 0.0 || fract > 1.0) {
496 L_WARNING(
"fract out of bounds; using 0.0\n", __func__);
502 threshdist = fract * (w * w + h * h);
503 mindist = 1000000000.;
506 for (i = 0; i < n; i++) {
511 if (bw + bh > maxperim)
516 dist = delx * delx + dely * dely;
517 if (dist <= threshdist)
519 if (dist < mindist) {
527 if (smallfound == TRUE)
531 minsize = 1000000000;
533 for (i = 0; i < n; i++) {
536 if (perim < minsize) {
558 l_float32 maxoverlap)
560 l_int32 i, n, bigoverlap;
565 return ERROR_INT(
"box not defined", __func__, 1);
567 return ERROR_INT(
"boxa not defined", __func__, 1);
568 if (maxoverlap < 0.0 || maxoverlap > 1.0)
569 return ERROR_INT(
"invalid maxoverlap", __func__, 1);
572 if (n == 0 || maxoverlap == 1.0)
576 for (i = 0; i < n; i++) {
580 if (fract > maxoverlap) {
610 l_float32 maxoverlap)
612 l_int32 i, j, n, remove;
618 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
619 if (maxoverlap < 0.0 || maxoverlap > 1.0)
620 return (
BOXA *)ERROR_PTR(
"invalid maxoverlap", __func__, NULL);
623 if (n == 0 || maxoverlap == 1.0)
629 for (j = 1; j < n; j++) {
632 for (i = 0; i < j; i++) {
636 if (fract > maxoverlap) {
l_ok boxGetGeometry(const BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
void boxDestroy(BOX **pbox)
boxDestroy()
BOX * boxClone(BOX *box)
boxClone()
l_ok boxaGetBoxGeometry(BOXA *boxa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxaGetBoxGeometry()
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
l_int32 boxaGetCount(const BOXA *boxa)
boxaGetCount()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
BOX * boxCopy(BOX *box)
boxCopy()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
BOXA * boxaIntersectsBox(BOXA *boxas, BOX *box)
boxaIntersectsBox()
l_ok boxGetCenter(const BOX *box, l_float32 *pcx, l_float32 *pcy)
boxGetCenter()
l_ok boxOverlapFraction(BOX *box1, BOX *box2, l_float32 *pfract)
boxOverlapFraction()
l_ok boxaGetExtent(BOXA *boxa, l_int32 *pw, l_int32 *ph, BOX **pbox)
boxaGetExtent()
void lheapDestroy(L_HEAP **plh, l_int32 freeflag)
lheapDestroy()
L_HEAP * lheapCreate(l_int32 n, l_int32 direction)
lheapCreate()
l_int32 lheapGetCount(L_HEAP *lh)
lheapGetCount()
l_ok lheapAdd(L_HEAP *lh, void *item)
lheapAdd()
void * lheapRemove(L_HEAP *lh)
lheapRemove()
static l_int32 boxCheckIfOverlapIsBig(BOX *box, BOXA *boxa, l_float32 maxoverlap)
boxCheckIfOverlapIsBig()
static BOXA * boxaGenerateSubboxes(BOX *box, BOXA *boxa, l_int32 maxperim, l_float32 fract)
boxaGenerateSubboxes()
static PARTEL * partelCreate(BOX *box)
partelCreate()
static l_int32 partelSetSize(PARTEL *partel, l_int32 sortflag)
partelSetSize()
BOXA * boxaGetWhiteblocks(BOXA *boxas, BOX *box, l_int32 sortflag, l_int32 maxboxes, l_float32 maxoverlap, l_int32 maxperim, l_float32 fract, l_int32 maxpops)
boxaGetWhiteblocks()
static void partelDestroy(PARTEL **ppartel)
partelDestroy()
BOXA * boxaPruneSortedOnOverlap(BOXA *boxas, l_float32 maxoverlap)
boxaPruneSortedOnOverlap()
static BOX * boxaSelectPivotBox(BOX *box, BOXA *boxa, l_int32 maxperim, l_float32 fract)
boxaSelectPivotBox()
@ L_SORT_BY_MIN_DIMENSION
@ L_SORT_BY_MAX_DIMENSION
void lept_stderr(const char *fmt,...)
lept_stderr()