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;
207 PROCNAME(
"boxaGetWhiteblocks");
210 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
215 return (
BOXA *)ERROR_PTR(
"invalid sort flag", procName, NULL);
218 L_WARNING(
"setting maxboxes = 1\n", procName);
220 if (maxoverlap < 0.0 || maxoverlap > 1.0)
221 return (
BOXA *)ERROR_PTR(
"invalid maxoverlap", procName, NULL);
223 maxpops = DefaultMaxPops;
245 if (npop > maxpops) {
273 for (i = 0; i < nsub; i++) {
277 partel->boxa = boxasub;
290 #if OUTPUT_HEAP_STATS 292 lept_stderr(
" Number of boxes pushed: %d\n", npush);
293 lept_stderr(
" Number of boxes popped: %d\n", npop);
337 PROCNAME(
"partelDestroy");
339 if (ppartel == NULL) {
340 L_WARNING(
"ptr address is null!\n", procName);
344 if ((partel = *ppartel) == NULL)
370 PROCNAME(
"partelSetSize");
373 return ERROR_INT(
"partel not defined", procName, 1);
377 partel->size = (l_float32)w;
379 partel->size = (l_float32)h;
381 partel->size = (l_float32)L_MIN(w, h);
383 partel->size = (l_float32)L_MAX(w, h);
385 partel->size = (l_float32)(w + h);
387 partel->size = (l_float32)(w * h);
389 return ERROR_INT(
"invalid sortflag", procName, 1);
413 l_int32 x, y, w, h, xp, yp, wp, hp;
418 PROCNAME(
"boxaGenerateSubboxes");
421 return (
BOXA *)ERROR_PTR(
"box not defined", procName, NULL);
423 return (
BOXA *)ERROR_PTR(
"boxa not defined", procName, NULL);
438 if (xp + wp < x + w) {
439 boxsub =
boxCreate(xp + wp, y, x + w - xp - wp, h);
442 if (yp + hp < y + h) {
443 boxsub =
boxCreate(x, yp + hp, w, y + h - yp - hp);
491 l_int32 i, n, bw, bh, w, h;
492 l_int32 smallfound, minindex, perim, minsize;
493 l_float32 delx, dely, mindist, threshdist, dist, x, y, cx, cy;
496 PROCNAME(
"boxaSelectPivotBox");
499 return (
BOX *)ERROR_PTR(
"box not defined", procName, NULL);
501 return (
BOX *)ERROR_PTR(
"boxa not defined", procName, NULL);
504 return (
BOX *)ERROR_PTR(
"no boxes in boxa", procName, NULL);
505 if (fract < 0.0 || fract > 1.0) {
506 L_WARNING(
"fract out of bounds; using 0.0\n", procName);
512 threshdist = fract * (w * w + h * h);
513 mindist = 1000000000.;
516 for (i = 0; i < n; i++) {
521 if (bw + bh > maxperim)
526 dist = delx * delx + dely * dely;
527 if (dist <= threshdist)
529 if (dist < mindist) {
537 if (smallfound == TRUE)
541 minsize = 1000000000;
543 for (i = 0; i < n; i++) {
546 if (perim < minsize) {
568 l_float32 maxoverlap)
570 l_int32 i, n, bigoverlap;
574 PROCNAME(
"boxCheckIfOverlapIsBig");
577 return ERROR_INT(
"box not defined", procName, 1);
579 return ERROR_INT(
"boxa not defined", procName, 1);
580 if (maxoverlap < 0.0 || maxoverlap > 1.0)
581 return ERROR_INT(
"invalid maxoverlap", procName, 1);
584 if (n == 0 || maxoverlap == 1.0)
588 for (i = 0; i < n; i++) {
592 if (fract > maxoverlap) {
622 l_float32 maxoverlap)
624 l_int32 i, j, n, remove;
629 PROCNAME(
"boxaPruneSortedOnOverlap");
632 return (
BOXA *)ERROR_PTR(
"boxas not defined", procName, NULL);
633 if (maxoverlap < 0.0 || maxoverlap > 1.0)
634 return (
BOXA *)ERROR_PTR(
"invalid maxoverlap", procName, NULL);
637 if (n == 0 || maxoverlap == 1.0)
643 for (j = 1; j < n; j++) {
646 for (i = 0; i < j; i++) {
650 if (fract > maxoverlap) {
BOXA * boxaIntersectsBox(BOXA *boxas, BOX *box)
boxaIntersectsBox()
static l_int32 partelSetSize(PARTEL *partel, l_int32 sortflag)
partelSetSize()
l_ok lheapAdd(L_HEAP *lh, void *item)
lheapAdd()
void lept_stderr(const char *fmt,...)
lept_stderr()
static BOXA * boxaGenerateSubboxes(BOX *box, BOXA *boxa, l_int32 maxperim, l_float32 fract)
boxaGenerateSubboxes()
l_ok boxGetCenter(BOX *box, l_float32 *pcx, l_float32 *pcy)
boxGetCenter()
BOXA * boxaCopy(BOXA *boxa, l_int32 copyflag)
boxaCopy()
void boxaDestroy(BOXA **pboxa)
boxaDestroy()
void lheapDestroy(L_HEAP **plh, l_int32 freeflag)
lheapDestroy()
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()
l_int32 lheapGetCount(L_HEAP *lh)
lheapGetCount()
BOX * boxClone(BOX *box)
boxClone()
static void partelDestroy(PARTEL **ppartel)
partelDestroy()
static BOX * boxaSelectPivotBox(BOX *box, BOXA *boxa, l_int32 maxperim, l_float32 fract)
boxaSelectPivotBox()
L_HEAP * lheapCreate(l_int32 n, l_int32 direction)
lheapCreate()
l_ok boxaGetBoxGeometry(BOXA *boxa, l_int32 index, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxaGetBoxGeometry()
static l_int32 boxCheckIfOverlapIsBig(BOX *box, BOXA *boxa, l_float32 maxoverlap)
boxCheckIfOverlapIsBig()
l_ok boxaAddBox(BOXA *boxa, BOX *box, l_int32 copyflag)
boxaAddBox()
void * lheapRemove(L_HEAP *lh)
lheapRemove()
l_ok boxOverlapFraction(BOX *box1, BOX *box2, l_float32 *pfract)
boxOverlapFraction()
static PARTEL * partelCreate(BOX *box)
partelCreate()
BOX * boxaGetBox(BOXA *boxa, l_int32 index, l_int32 accessflag)
boxaGetBox()
l_ok boxaGetExtent(BOXA *boxa, l_int32 *pw, l_int32 *ph, BOX **pbox)
boxaGetExtent()
BOX * boxCopy(BOX *box)
boxCopy()
BOXA * boxaCreate(l_int32 n)
boxaCreate()
void boxDestroy(BOX **pbox)
boxDestroy()
l_int32 boxaGetCount(BOXA *boxa)
boxaGetCount()
l_ok boxGetGeometry(BOX *box, l_int32 *px, l_int32 *py, l_int32 *pw, l_int32 *ph)
boxGetGeometry()
BOX * boxCreate(l_int32 x, l_int32 y, l_int32 w, l_int32 h)
boxCreate()
BOXA * boxaPruneSortedOnOverlap(BOXA *boxas, l_float32 maxoverlap)
boxaPruneSortedOnOverlap()