196 l_float32 maxoverlap,
201l_int32 i, w, h, n, nsub, npush, npop;
203BOXA *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;
224 boxaGetExtent(boxas, &w, &h, NULL);
225 box = boxCreate(0, 0, w, h);
231 partel->boxa = boxaCopy(boxas,
L_CLONE);
233 lheapAdd(lh, partel);
237 boxad = boxaCreate(0);
239 if ((partel = (
PARTEL *)lheapRemove(lh)) == NULL)
243 if (npop > maxpops) {
249 boxa = boxaCopy(partel->boxa,
L_CLONE);
250 box = boxClone(partel->box);
254 n = boxaGetCount(boxa);
261 if (boxaGetCount(boxad) >= maxboxes)
270 nsub = boxaGetCount(boxa4);
271 for (i = 0; i < nsub; i++) {
272 boxsub = boxaGetBox(boxa4, i,
L_CLONE);
273 boxasub = boxaIntersectsBox(boxa, boxsub);
275 partel->boxa = boxasub;
277 lheapAdd(lh, partel);
289 lept_stderr(
"Heap statistics:\n");
290 lept_stderr(
" Number of boxes pushed: %d\n", npush);
291 lept_stderr(
" Number of boxes popped: %d\n", npop);
292 lept_stderr(
" Number of boxes on heap: %d\n", lheapGetCount(lh));
296 while ((partel = (
PARTEL *)lheapRemove(lh)) != NULL)
298 lheapDestroy(&lh, FALSE);
367 return ERROR_INT(
"partel not defined", __func__, 1);
369 boxGetGeometry(partel->box, NULL, NULL, &w, &h);
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);
407l_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);
417 boxa4 = boxaCreate(4);
419 boxGetGeometry(box, &x, &y, &w, &h);
420 boxGetGeometry(boxp, &xp, &yp, &wp, &hp);
423 boxsub = boxCreate(x, y, xp - x, h);
424 boxaAddBox(boxa4, boxsub,
L_INSERT);
427 boxsub = boxCreate(x, y, w, yp - y);
428 boxaAddBox(boxa4, boxsub,
L_INSERT);
430 if (xp + wp < x + w) {
431 boxsub = boxCreate(xp + wp, y, x + w - xp - wp, h);
432 boxaAddBox(boxa4, boxsub,
L_INSERT);
434 if (yp + hp < y + h) {
435 boxsub = boxCreate(x, yp + hp, w, y + h - yp - hp);
436 boxaAddBox(boxa4, boxsub,
L_INSERT);
483l_int32 i, n, bw, bh, w, h;
484l_int32 smallfound, minindex, perim, minsize;
485l_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);
492 n = boxaGetCount(boxa);
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__);
500 boxGetGeometry(box, NULL, NULL, &w, &h);
501 boxGetCenter(box, &x, &y);
502 threshdist = fract * (w * w + h * h);
503 mindist = 1000000000.;
506 for (i = 0; i < n; i++) {
507 boxt = boxaGetBox(boxa, i,
L_CLONE);
508 boxGetGeometry(boxt, NULL, NULL, &bw, &bh);
509 boxGetCenter(boxt, &cx, &cy);
511 if (bw + bh > maxperim)
516 dist = delx * delx + dely * dely;
517 if (dist <= threshdist)
518 return boxaGetBox(boxa, i,
L_COPY);
519 if (dist < mindist) {
527 if (smallfound == TRUE)
528 return boxaGetBox(boxa, minindex,
L_COPY);
531 minsize = 1000000000;
533 for (i = 0; i < n; i++) {
534 boxaGetBoxGeometry(boxa, i, NULL, NULL, &bw, &bh);
536 if (perim < minsize) {
541 return boxaGetBox(boxa, minindex,
L_COPY);
558 l_float32 maxoverlap)
560l_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);
571 n = boxaGetCount(boxa);
572 if (n == 0 || maxoverlap == 1.0)
576 for (i = 0; i < n; i++) {
577 boxt = boxaGetBox(boxa, i,
L_CLONE);
578 boxOverlapFraction(boxt, box, &fract);
580 if (fract > maxoverlap) {
610 l_float32 maxoverlap)
612l_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);
622 n = boxaGetCount(boxas);
623 if (n == 0 || maxoverlap == 1.0)
624 return boxaCopy(boxas,
L_COPY);
626 boxad = boxaCreate(0);
627 box2 = boxaGetBox(boxas, 0,
L_COPY);
629 for (j = 1; j < n; j++) {
630 box2 = boxaGetBox(boxas, j,
L_COPY);
632 for (i = 0; i < j; i++) {
633 box1 = boxaGetBox(boxas, i,
L_CLONE);
634 boxOverlapFraction(box1, box2, &fract);
636 if (fract > maxoverlap) {
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()