68#include <config_auto.h>
72#include "allheaders.h"
78static const l_int32 MinCompsForBinSort = 200;
114 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
115 n = boxaGetCount(boxas);
116 if ((boxad = boxaCreate(n)) == NULL)
117 return (
BOXA *)ERROR_PTR(
"boxad not made", __func__, NULL);
118 for (i = 0; i < n; i++) {
119 if ((boxs = boxaGetBox(boxas, i,
L_CLONE)) == NULL) {
121 return (
BOXA *)ERROR_PTR(
"boxs not found", __func__, NULL);
123 boxd =
boxTransform(boxs, shiftx, shifty, scalex, scaley);
158 return (
BOX *)ERROR_PTR(
"box not defined", __func__, NULL);
159 if (box->
w <= 0 || box->
h <= 0)
160 return boxCreate(0, 0, 0, 0);
162 return boxCreate((l_int32)(L_MAX(0, scalex * (box->
x + shiftx) + 0.5)),
163 (l_int32)(L_MAX(0, scaley * (box->
y + shifty) + 0.5)),
164 (l_int32)(L_MAX(1.0, scalex * box->
w + 0.5)),
165 (l_int32)(L_MAX(1.0, scaley * box->
h + 0.5)));
218 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
219 n = boxaGetCount(boxas);
220 if ((boxad = boxaCreate(n)) == NULL)
221 return (
BOXA *)ERROR_PTR(
"boxad not made", __func__, NULL);
222 for (i = 0; i < n; i++) {
223 if ((boxs = boxaGetBox(boxas, i,
L_CLONE)) == NULL) {
225 return (
BOXA *)ERROR_PTR(
"boxs not found", __func__, NULL);
228 xcen, ycen, angle, order);
301l_int32 bx, by, bw, bh, tx, ty, tw, th;
303l_float32 sina, cosa, xdif, ydif, rx, ry, rw, rh;
307 return (
BOX *)ERROR_PTR(
"boxs not defined", __func__, NULL);
310 return (
BOX *)ERROR_PTR(
"order invalid", __func__, NULL);
312 boxGetGeometry(boxs, &bx, &by, &bw, &bh);
313 if (bw <= 0 || bh <= 0)
314 return boxCreate(0, 0, 0, 0);
321 tx = (l_int32)(scalex * (bx + shiftx) + 0.5);
322 ty = (l_int32)(scaley * (by + shifty) + 0.5);
323 tw = (l_int32)(L_MAX(1.0, scalex * bw + 0.5));
324 th = (l_int32)(L_MAX(1.0, scaley * bh + 0.5));
325 xcent = (l_int32)(scalex * xcen + 0.5);
326 ycent = (l_int32)(scaley * ycen + 0.5);
328 boxd = boxCreate(tx, ty, tw, th);
330 xdif = tx + 0.5 * tw - xcent;
331 ydif = ty + 0.5 * th - ycent;
332 rw = L_ABS(tw * cosa) + L_ABS(th * sina);
333 rh = L_ABS(th * cosa) + L_ABS(tw * sina);
334 rx = xcent + xdif * cosa - ydif * sina - 0.5 * rw;
335 ry = ycent + ydif * cosa + xdif * sina - 0.5 * rh;
336 boxd = boxCreate((l_int32)rx, (l_int32)ry, (l_int32)rw,
340 tx = (l_int32)(scalex * bx + shiftx + 0.5);
341 ty = (l_int32)(scaley * by + shifty + 0.5);
342 tw = (l_int32)(L_MAX(1.0, scalex * bw + 0.5));
343 th = (l_int32)(L_MAX(1.0, scaley * bh + 0.5));
344 xcent = (l_int32)(scalex * xcen + 0.5);
345 ycent = (l_int32)(scaley * ycen + 0.5);
347 boxd = boxCreate(tx, ty, tw, th);
349 xdif = tx + 0.5 * tw - xcent;
350 ydif = ty + 0.5 * th - ycent;
351 rw = L_ABS(tw * cosa) + L_ABS(th * sina);
352 rh = L_ABS(th * cosa) + L_ABS(tw * sina);
353 rx = xcent + xdif * cosa - ydif * sina - 0.5 * rw;
354 ry = ycent + ydif * cosa + xdif * sina - 0.5 * rh;
355 boxd = boxCreate((l_int32)rx, (l_int32)ry, (l_int32)rw,
365 xdif = bx + 0.5 * bw - xcen;
366 ydif = by + 0.5 * bh - ycen;
367 rw = L_ABS(bw * cosa) + L_ABS(bh * sina);
368 rh = L_ABS(bh * cosa) + L_ABS(bw * sina);
369 rx = xcen + xdif * cosa - ydif * sina - 0.5 * rw;
370 ry = ycen + ydif * cosa + xdif * sina - 0.5 * rh;
372 tx = (l_int32)(scalex * (rx + shiftx) + 0.5);
373 ty = (l_int32)(scaley * (ry + shifty) + 0.5);
374 tw = (l_int32)(L_MAX(1.0, scalex * rw + 0.5));
375 th = (l_int32)(L_MAX(1.0, scaley * rh + 0.5));
376 boxd = boxCreate(tx, ty, tw, th);
384 xdif = bx + 0.5 * bw - xcen;
385 ydif = by + 0.5 * bh - ycen;
386 rw = L_ABS(bw * cosa) + L_ABS(bh * sina);
387 rh = L_ABS(bh * cosa) + L_ABS(bw * sina);
388 rx = xcen + xdif * cosa - ydif * sina - 0.5 * rw;
389 ry = ycen + ydif * cosa + xdif * sina - 0.5 * rh;
391 tx = (l_int32)(scalex * rx + shiftx + 0.5);
392 ty = (l_int32)(scaley * ry + shifty + 0.5);
393 tw = (l_int32)(L_MAX(1.0, scalex * rw + 0.5));
394 th = (l_int32)(L_MAX(1.0, scaley * rh + 0.5));
395 boxd = boxCreate(tx, ty, tw, th);
405 xdif = tx + 0.5 * bw - xcen;
406 ydif = ty + 0.5 * bh - ycen;
407 rw = L_ABS(bw * cosa) + L_ABS(bh * sina);
408 rh = L_ABS(bh * cosa) + L_ABS(bw * sina);
409 rx = xcen + xdif * cosa - ydif * sina - 0.5 * rw;
410 ry = ycen + ydif * cosa + xdif * sina - 0.5 * rh;
412 tx = (l_int32)(scalex * rx + 0.5);
413 ty = (l_int32)(scaley * ry + 0.5);
414 tw = (l_int32)(L_MAX(1.0, scalex * rw + 0.5));
415 th = (l_int32)(L_MAX(1.0, scaley * rh + 0.5));
416 boxd = boxCreate(tx, ty, tw, th);
418 tx = (l_int32)(scalex * bx + 0.5);
419 ty = (l_int32)(scaley * by + 0.5);
420 tw = (l_int32)(L_MAX(1.0, scalex * bw + 0.5));
421 th = (l_int32)(L_MAX(1.0, scaley * bh + 0.5));
422 xcent = (l_int32)(scalex * xcen + 0.5);
423 ycent = (l_int32)(scaley * ycen + 0.5);
430 xdif = tx + 0.5 * tw - xcent;
431 ydif = ty + 0.5 * th - ycent;
432 rw = L_ABS(tw * cosa) + L_ABS(th * sina);
433 rh = L_ABS(th * cosa) + L_ABS(tw * sina);
434 rx = xcent + xdif * cosa - ydif * sina - 0.5 * rw;
435 ry = ycent + ydif * cosa + xdif * sina - 0.5 * rh;
437 tx = (l_int32)(rx + shiftx + 0.5);
438 ty = (l_int32)(ry + shifty + 0.5);
439 tw = (l_int32)(rw + 0.5);
440 th = (l_int32)(rh + 0.5);
441 boxd = boxCreate(tx, ty, tw, th);
473 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
474 if (rotation < 0 || rotation > 3)
475 return (
BOXA *)ERROR_PTR(
"rotation not in {0,1,2,3}", __func__, NULL);
477 return boxaCopy(boxas,
L_COPY);
479 n = boxaGetCount(boxas);
480 if ((boxad = boxaCreate(n)) == NULL)
481 return (
BOXA *)ERROR_PTR(
"boxad not made", __func__, NULL);
482 for (i = 0; i < n; i++) {
483 if ((boxs = boxaGetBox(boxas, i,
L_CLONE)) == NULL) {
485 return (
BOXA *)ERROR_PTR(
"boxs not found", __func__, NULL);
518l_int32 bx, by, bw, bh, xdist, ydist;
521 return (
BOX *)ERROR_PTR(
"box not defined", __func__, NULL);
522 if (rotation < 0 || rotation > 3)
523 return (
BOX *)ERROR_PTR(
"rotation not in {0,1,2,3}", __func__, NULL);
527 boxGetGeometry(box, &bx, &by, &bw, &bh);
528 if (bw <= 0 || bh <= 0)
529 return boxCreate(0, 0, 0, 0);
533 return boxCreate(ydist, bx, bh, bw);
534 else if (rotation == 2)
535 return boxCreate(xdist, ydist, bw, bh);
537 return boxCreate(by, xdist, bh, bw);
570l_int32 i, n, x, y, full;
575 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
576 boxaIsFull(boxas, &full);
578 return (
BOXA *)ERROR_PTR(
"boxas not full", __func__, NULL);
580 return (
BOXA *)ERROR_PTR(
"pta not defined", __func__, NULL);
581 if (dir != 1 && dir != -1)
582 return (
BOXA *)ERROR_PTR(
"invalid dir", __func__, NULL);
583 n = boxaGetCount(boxas);
584 if (n != ptaGetCount(pta))
585 return (
BOXA *)ERROR_PTR(
"boxas and pta not same size", __func__, NULL);
587 if ((boxad = boxaCreate(n)) == NULL)
588 return (
BOXA *)ERROR_PTR(
"boxad not made", __func__, NULL);
589 for (i = 0; i < n; i++) {
590 box1 = boxaGetBox(boxas, i,
L_COPY);
591 ptaGetIPt(pta, i, &x, &y);
629l_int32 i, n, x, y, w, h, size;
633 if (pnaindex) *pnaindex = NULL;
635 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
636 if ((n = boxaGetCount(boxas)) == 0) {
637 L_WARNING(
"boxas is empty\n", __func__);
638 return boxaCopy(boxas,
L_COPY);
648 return (
BOXA *)ERROR_PTR(
"invalid sort type", __func__, NULL);
650 return (
BOXA *)ERROR_PTR(
"invalid sort order", __func__, NULL);
653 if (n > MinCompsForBinSort &&
657 return boxaBinSort(boxas, sorttype, sortorder, pnaindex);
660 if ((na = numaCreate(n)) == NULL)
661 return (
BOXA *)ERROR_PTR(
"na not made", __func__, NULL);
662 for (i = 0; i < n; i++) {
663 boxaGetBoxGeometry(boxas, i, &x, &y, &w, &h);
667 numaAddNumber(na, x);
670 numaAddNumber(na, y);
673 numaAddNumber(na, x + w - 1);
676 numaAddNumber(na, y + h - 1);
679 numaAddNumber(na, w);
682 numaAddNumber(na, h);
686 numaAddNumber(na, size);
690 numaAddNumber(na, size);
694 numaAddNumber(na, size);
698 numaAddNumber(na, size);
701 numaAddNumber(na, (l_float32)w / (l_float32)h);
704 L_WARNING(
"invalid sort type\n", __func__);
709 naindex = numaGetSortIndex(na, sortorder);
712 return (
BOXA *)ERROR_PTR(
"naindex not made", __func__, NULL);
720 numaDestroy(&naindex);
751l_int32 i, n, x, y, w, h;
755 if (pnaindex) *pnaindex = NULL;
757 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
758 if ((n = boxaGetCount(boxas)) == 0) {
759 L_WARNING(
"boxas is empty\n", __func__);
760 return boxaCopy(boxas,
L_COPY);
765 return (
BOXA *)ERROR_PTR(
"invalid sort type", __func__, NULL);
767 return (
BOXA *)ERROR_PTR(
"invalid sort order", __func__, NULL);
770 if ((na = numaCreate(n)) == NULL)
771 return (
BOXA *)ERROR_PTR(
"na not made", __func__, NULL);
772 for (i = 0; i < n; i++) {
773 boxaGetBoxGeometry(boxas, i, &x, &y, &w, &h);
777 numaAddNumber(na, x);
780 numaAddNumber(na, y);
783 numaAddNumber(na, w);
786 numaAddNumber(na, h);
789 numaAddNumber(na, w + h);
792 L_WARNING(
"invalid sort type\n", __func__);
797 naindex = numaGetBinSortIndex(na, sortorder);
800 return (
BOXA *)ERROR_PTR(
"naindex not made", __func__, NULL);
808 numaDestroy(&naindex);
829 return (
BOXA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
830 if ((n = boxaGetCount(boxas)) == 0) {
831 L_WARNING(
"boxas is empty\n", __func__);
832 return boxaCopy(boxas,
L_COPY);
835 return (
BOXA *)ERROR_PTR(
"naindex not defined", __func__, NULL);
837 boxad = boxaCreate(n);
838 for (i = 0; i < n; i++) {
839 numaGetIValue(naindex, i, &index);
840 box = boxaGetBox(boxas, index,
L_COPY);
902l_int32 i, index, h, nt, ne, n, m, ival;
904BOXA *boxa, *boxae, *boxan, *boxa1, *boxa2, *boxa3, *boxav, *boxavs;
905BOXAA *baa, *baa1, *baad;
906NUMA *naindex, *nae, *nan, *nah, *nav, *na1, *na2, *nad, *namap;
907NUMAA *naa, *naa1, *naad;
909 if (pnaad) *pnaad = NULL;
911 return (
BOXAA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
912 if (boxaGetCount(boxas) == 0)
913 return (
BOXAA *)ERROR_PTR(
"boxas is empty", __func__, NULL);
918 return (
BOXAA *)ERROR_PTR(
"boxa not made", __func__, NULL);
921 nt = boxaGetCount(boxa);
922 baa = boxaaCreate(0);
923 naa = numaaCreate(0);
924 boxae = boxaCreate(0);
926 for (i = 0; i < nt; i++) {
927 box = boxaGetBox(boxa, i,
L_CLONE);
928 boxGetGeometry(box, NULL, NULL, NULL, &h);
931 numaAddNumber(nae, i);
933 n = boxaaGetCount(baa);
936 boxaaAddBox(baa, index, box,
L_INSERT);
938 boxan = boxaCreate(0);
944 numaGetIValue(naindex, i, &ival);
945 numaaAddNumber(naa, index, ival);
949 numaDestroy(&naindex);
952 ne = boxaGetCount(boxae);
953 for (i = 0; i < ne; i++) {
954 box = boxaGetBox(boxae, i,
L_CLONE);
955 n = boxaaGetCount(baa);
958 boxaaAddBox(baa, index, box,
L_INSERT);
960 boxan = boxaCreate(0);
966 numaGetIValue(nae, i, &ival);
967 numaaAddNumber(naa, index, ival);
981 n = boxaaGetCount(baa);
983 boxa1 = boxaHandleOverlaps(boxa3,
L_REMOVE_SMALL, 1000, 0.5, 0.5, &namap);
986 for (i = 0; i < n; i++) {
987 numaGetIValue(namap, i, &ival);
989 boxa1 = boxaaGetBoxa(baa, i,
L_COPY);
990 boxa2 = boxaaGetBoxa(baa, ival,
L_CLONE);
991 boxaJoin(boxa2, boxa1, 0, -1);
994 na1 = numaaGetNuma(naa, i,
L_COPY);
995 na2 = numaaGetNuma(naa, ival,
L_CLONE);
996 numaJoin(na2, na1, 0, -1);
1001 baa1 = boxaaCreate(n);
1002 naa1 = numaaCreate(n);
1003 for (i = 0; i < n; i++) {
1004 numaGetIValue(namap, i, &ival);
1006 boxa1 = boxaaGetBoxa(baa, i,
L_CLONE);
1007 boxaaAddBoxa(baa1, boxa1,
L_INSERT);
1008 na1 = numaaGetNuma(naa, i,
L_CLONE);
1012 numaDestroy(&namap);
1019 m = boxaaGetCount(baa);
1020 for (i = 0; i < m; i++) {
1021 boxa1 = boxaaGetBoxa(baa, i,
L_CLONE);
1023 boxaaReplaceBoxa(baa, i, boxa2);
1024 na1 = numaaGetNuma(naa, i,
L_CLONE);
1025 na2 = numaSortByIndex(na1, nah);
1026 numaaReplaceNuma(naa, i, na2);
1027 boxaDestroy(&boxa1);
1034 m = boxaaGetCount(baa);
1035 boxav = boxaCreate(m);
1036 naad = numaaCreate(m);
1039 baad = boxaaCreate(m);
1040 for (i = 0; i < m; i++) {
1041 boxa1 = boxaaGetBoxa(baa, i,
L_CLONE);
1042 box = boxaGetBox(boxa1, 0,
L_CLONE);
1044 boxaDestroy(&boxa1);
1047 for (i = 0; i < m; i++) {
1048 numaGetIValue(nav, i, &index);
1049 boxa = boxaaGetBoxa(baa, index,
L_CLONE);
1050 boxaaAddBoxa(baad, boxa,
L_INSERT);
1051 nad = numaaGetNuma(naa, index,
L_CLONE);
1060 boxaDestroy(&boxav);
1061 boxaDestroy(&boxavs);
1062 boxaDestroy(&boxae);
1067 numaaDestroy(&naad);
1084l_int32 ntot, boxtot, i, j, n, nn, index;
1091 return (
BOXAA *)ERROR_PTR(
"boxas not defined", __func__, NULL);
1092 if ((boxtot = boxaGetCount(boxas)) == 0)
1093 return (
BOXAA *)ERROR_PTR(
"boxas is empty", __func__, NULL);
1095 return (
BOXAA *)ERROR_PTR(
"naindex not defined", __func__, NULL);
1098 ntot = numaaGetNumberCount(naa);
1100 return (
BOXAA *)ERROR_PTR(
"element count mismatch", __func__, NULL);
1102 n = numaaGetCount(naa);
1103 baa = boxaaCreate(n);
1104 for (i = 0; i < n; i++) {
1105 na = numaaGetNuma(naa, i,
L_CLONE);
1106 nn = numaGetCount(na);
1107 boxa = boxaCreate(nn);
1108 for (j = 0; j < nn; j++) {
1109 numaGetIValue(na, i, &index);
1110 box = boxaGetBox(boxas, index,
L_COPY);
1155 l_int32 keepinvalid)
1157l_int32 i, n, left, top, right, bot, w, h;
1159 if (!pnal && !pnat && !pnar && !pnab && !pnaw && !pnah)
1160 return ERROR_INT(
"no output requested", __func__, 1);
1161 if (pnal) *pnal = NULL;
1162 if (pnat) *pnat = NULL;
1163 if (pnar) *pnar = NULL;
1164 if (pnab) *pnab = NULL;
1165 if (pnaw) *pnaw = NULL;
1166 if (pnah) *pnah = NULL;
1168 return ERROR_INT(
"boxa not defined", __func__, 1);
1169 if (!keepinvalid && boxaGetValidCount(boxa) == 0)
1170 return ERROR_INT(
"no valid boxes", __func__, 1);
1172 n = boxaGetCount(boxa);
1173 if (pnal) *pnal = numaCreate(n);
1174 if (pnat) *pnat = numaCreate(n);
1175 if (pnar) *pnar = numaCreate(n);
1176 if (pnab) *pnab = numaCreate(n);
1177 if (pnaw) *pnaw = numaCreate(n);
1178 if (pnah) *pnah = numaCreate(n);
1179 for (i = 0; i < n; i++) {
1180 boxaGetBoxGeometry(boxa, i, &left, &top, &w, &h);
1181 if (!keepinvalid && (w <= 0 || h <= 0))
1183 right = left + w - 1;
1185 if (pnal) numaAddNumber(*pnal, left);
1186 if (pnat) numaAddNumber(*pnat, top);
1187 if (pnar) numaAddNumber(*pnar, right);
1188 if (pnab) numaAddNumber(*pnab, bot);
1189 if (pnaw) numaAddNumber(*pnaw, w);
1190 if (pnah) numaAddNumber(*pnah, h);
1234 l_int32 keepinvalid)
1236l_int32 i, n, left, top, right, bot, w, h;
1238 if (!pptal && !pptar && !pptat && !pptab && !pptaw && !pptah)
1239 return ERROR_INT(
"no output requested", __func__, 1);
1240 if (pptal) *pptal = NULL;
1241 if (pptat) *pptat = NULL;
1242 if (pptar) *pptar = NULL;
1243 if (pptab) *pptab = NULL;
1244 if (pptaw) *pptaw = NULL;
1245 if (pptah) *pptah = NULL;
1247 return ERROR_INT(
"boxa not defined", __func__, 1);
1248 if (!keepinvalid && boxaGetValidCount(boxa) == 0)
1249 return ERROR_INT(
"no valid boxes", __func__, 1);
1251 n = boxaGetCount(boxa);
1252 if (pptal) *pptal = ptaCreate(n);
1253 if (pptat) *pptat = ptaCreate(n);
1254 if (pptar) *pptar = ptaCreate(n);
1255 if (pptab) *pptab = ptaCreate(n);
1256 if (pptaw) *pptaw = ptaCreate(n);
1257 if (pptah) *pptah = ptaCreate(n);
1258 for (i = 0; i < n; i++) {
1259 boxaGetBoxGeometry(boxa, i, &left, &top, &w, &h);
1260 if (!keepinvalid && (w <= 0 || h <= 0))
1262 right = left + w - 1;
1264 if (pptal) ptaAddPt(*pptal, i, left);
1265 if (pptat) ptaAddPt(*pptat, i, top);
1266 if (pptar) ptaAddPt(*pptar, i, right);
1267 if (pptab) ptaAddPt(*pptab, i, bot);
1268 if (pptaw) ptaAddPt(*pptaw, i, w);
1269 if (pptah) ptaAddPt(*pptah, i, h);
1298l_int32 i, n, left, top, right, bot, w, h;
1302 return (
PTA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
1305 return (
PTA *)ERROR_PTR(
"invalid location", __func__, NULL);
1307 n = boxaGetCount(boxa);
1308 if ((pta = ptaCreate(n)) == NULL)
1309 return (
PTA *)ERROR_PTR(
"pta not made", __func__, NULL);
1311 for (i = 0; i < n; i++) {
1312 boxaGetBoxGeometry(boxa, i, &left, &top, &w, &h);
1313 right = left + w - 1;
1315 if (w == 0 || h == 0) {
1322 ptaAddPt(pta, left, top);
1324 ptaAddPt(pta, right, top);
1326 ptaAddPt(pta, left, bot);
1328 ptaAddPt(pta, right, bot);
1330 ptaAddPt(pta, (left + right) / 2, (top + bot) / 2);
1381l_float32 xval, yval, rval, bval, wval, hval;
1382NUMA *nax, *nay, *nar, *nab, *naw, *nah;
1391 return ERROR_INT(
"boxa not defined", __func__, 1);
1392 if (fract < 0.0 || fract > 1.0)
1393 return ERROR_INT(
"fract not in [0.0 ... 1.0]", __func__, 1);
1394 if (boxaGetValidCount(boxa) == 0)
1395 return ERROR_INT(
"no valid boxes in boxa", __func__, 1);
1401 numaGetRankValue(nax, 1.0 - fract, NULL, 1, &xval);
1402 *px = (l_int32)xval;
1405 numaGetRankValue(nay, 1.0 - fract, NULL, 1, &yval);
1406 *py = (l_int32)yval;
1409 numaGetRankValue(nar, fract, NULL, 1, &rval);
1410 *pr = (l_int32)rval;
1413 numaGetRankValue(nab, fract, NULL, 1, &bval);
1414 *pb = (l_int32)bval;
1417 numaGetRankValue(naw, fract, NULL, 1, &wval);
1418 *pw = (l_int32)wval;
1421 numaGetRankValue(nah, fract, NULL, 1, &hval);
1422 *ph = (l_int32)hval;
1461 return ERROR_INT(
"boxa not defined", __func__, 1);
1462 if (boxaGetValidCount(boxa) == 0)
1463 return ERROR_INT(
"no valid boxes in boxa", __func__, 1);
1482l_int32 i, n, bw, bh;
1483l_float32 sumw, sumh;
1488 return ERROR_INT(
"boxa not defined", __func__, 1);
1489 if ((n = boxaGetCount(boxa)) == 0)
1490 return ERROR_INT(
"boxa is empty", __func__, 1);
1493 for (i = 0; i < n; i++) {
1494 boxaGetBoxGeometry(boxa, i, NULL, NULL, &bw, &bh);
1499 if (pw) *pw = sumw / n;
1500 if (ph) *ph = sumh / n;
1537l_int32 i, n, x, y, w, h, xmax, ymax, xmin, ymin, found;
1541 if (!pw && !ph && !pbox && !pboxa)
1542 return ERROR_INT(
"no ptrs defined", __func__, 1);
1545 if (pbox) *pbox = NULL;
1546 if (pboxa) *pboxa = NULL;
1548 return ERROR_INT(
"baa not defined", __func__, 1);
1550 n = boxaaGetCount(baa);
1552 return ERROR_INT(
"no boxa in baa", __func__, 1);
1554 boxa = boxaCreate(n);
1556 xmin = ymin = 100000000;
1558 for (i = 0; i < n; i++) {
1559 boxa1 = boxaaGetBoxa(baa, i,
L_CLONE);
1560 boxaGetExtent(boxa1, NULL, NULL, &box1);
1561 boxaDestroy(&boxa1);
1562 boxGetGeometry(box1, &x, &y, &w, &h);
1563 if (w > 0 && h > 0) {
1565 xmin = L_MIN(xmin, x);
1566 ymin = L_MIN(ymin, y);
1567 xmax = L_MAX(xmax, x + w);
1568 ymax = L_MAX(ymax, y + h);
1578 *pbox = boxCreate(xmin, ymin, xmax - xmin, ymax - ymin);
1618 if (pnaindex) *pnaindex = NULL;
1620 return (
BOXA *)ERROR_PTR(
"baa not defined", __func__, NULL);
1622 return (
BOXA *)ERROR_PTR(
"invalid copyflag", __func__, NULL);
1624 naindex = numaCreate(0);
1625 *pnaindex = naindex;
1628 n = boxaaGetCount(baa);
1629 boxa = boxaCreate(n);
1630 for (i = 0; i < n; i++) {
1631 boxat = boxaaGetBoxa(baa, i,
L_CLONE);
1632 m = boxaGetCount(boxat);
1634 box = boxCreate(0, 0, 0, 0);
1637 numaAddNumber(naindex, i);
1639 for (j = 0; j < m; j++) {
1640 box = boxaGetBox(boxat, j, copyflag);
1643 numaAddNumber(naindex, i);
1646 boxaDestroy(&boxat);
1678l_int32 i, j, m, n, mval, nshort;
1683 return (
BOXA *)ERROR_PTR(
"baa not defined", __func__, NULL);
1685 return (
BOXA *)ERROR_PTR(
"invalid copyflag", __func__, NULL);
1687 n = boxaaGetCount(baa);
1688 boxad = boxaCreate(n);
1689 for (i = 0; i < n; i++) {
1690 boxat = boxaaGetBoxa(baa, i,
L_CLONE);
1691 m = boxaGetCount(boxat);
1692 mval = L_MIN(m, num);
1693 nshort = num - mval;
1694 for (j = 0; j < mval; j++) {
1695 box = boxaGetBox(boxat, j, copyflag);
1698 for (j = 0; j < nshort; j++) {
1700 boxaAddBox(boxad, fillerbox,
L_COPY);
1702 box = boxCreate(0, 0, 0, 0);
1706 boxaDestroy(&boxat);
1733l_int32 i, j, n, nbaa, index;
1739 return (
BOXAA *)ERROR_PTR(
"boxa not defined", __func__, NULL);
1741 return (
BOXAA *)ERROR_PTR(
"invalid copyflag", __func__, NULL);
1743 n = boxaGetCount(boxa);
1745 if (num * nbaa != n)
1746 L_ERROR(
"inconsistent alignment: num doesn't divide n\n", __func__);
1747 baa = boxaaCreate(nbaa);
1748 for (i = 0, index = 0; i < nbaa; i++) {
1749 boxat = boxaCreate(num);
1750 for (j = 0; j < num; j++, index++) {
1751 box = boxaGetBox(boxa, index, copyflag);
1754 boxaaAddBoxa(baa, boxat,
L_INSERT);
1783l_int32 i, j, ny, nb, nbox;
1789 return (
BOXAA *)ERROR_PTR(
"baas not defined", __func__, NULL);
1790 if ((ny = boxaaGetCount(baas)) == 0)
1791 return (
BOXAA *)ERROR_PTR(
"baas empty", __func__, NULL);
1794 for (i = 0; i < ny; i++) {
1795 if ((boxa = boxaaGetBoxa(baas, i,
L_CLONE)) == NULL)
1796 return (
BOXAA *)ERROR_PTR(
"baas is missing a boxa", __func__, NULL);
1797 nb = boxaGetCount(boxa);
1801 else if (nb != nbox)
1802 return (
BOXAA *)ERROR_PTR(
"boxa are not all the same size",
1807 baad = boxaaCreate(nbox);
1808 for (i = 0; i < nbox; i++) {
1809 boxa = boxaCreate(ny);
1810 for (j = 0; j < ny; j++) {
1811 box = boxaaGetBox(baas, j, i,
L_COPY);
1814 boxaaAddBoxa(baad, boxa,
L_INSERT);
1843l_int32 i, n, m, y, yt, h, ht, ovlp, maxovlp, maxindex;
1847 if (pindex) *pindex = 0;
1849 return ERROR_INT(
"baa not defined", __func__, 1);
1851 return ERROR_INT(
"box not defined", __func__, 1);
1853 return ERROR_INT(
"&index not defined", __func__, 1);
1855 n = boxaaGetCount(baa);
1856 boxGetGeometry(box, NULL, &y, NULL, &h);
1857 maxovlp = -10000000;
1858 for (i = 0; i < n; i++) {
1859 boxa = boxaaGetBoxa(baa, i,
L_CLONE);
1860 if ((m = boxaGetCount(boxa)) == 0) {
1862 L_WARNING(
"no boxes in boxa\n", __func__);
1865 boxaGetExtent(boxa, NULL, NULL, &boxt);
1866 boxGetGeometry(boxt, NULL, &yt, NULL, &ht);
1872 ovlp = y + h - 1 - yt;
1874 ovlp = yt + ht - 1 - y;
1875 if (ovlp > maxovlp) {
1881 if (maxovlp + delta >= 0)
BOXA * boxaaFlattenToBoxa(BOXAA *baa, NUMA **pnaindex, l_int32 copyflag)
boxaaFlattenToBoxa()
l_ok boxaaAlignBox(BOXAA *baa, BOX *box, l_int32 delta, l_int32 *pindex)
boxaaAlignBox()
l_ok boxaGetRankVals(BOXA *boxa, l_float32 fract, l_int32 *px, l_int32 *py, l_int32 *pr, l_int32 *pb, l_int32 *pw, l_int32 *ph)
boxaGetRankVals()
BOXA * boxaTransformOrdered(BOXA *boxas, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley, l_int32 xcen, l_int32 ycen, l_float32 angle, l_int32 order)
boxaTransformOrdered()
BOXA * boxaShiftWithPta(BOXA *boxas, PTA *pta, l_int32 dir)
boxaShiftWithPta()
l_ok boxaaGetExtent(BOXAA *baa, l_int32 *pw, l_int32 *ph, BOX **pbox, BOXA **pboxa)
boxaaGetExtent()
BOXAA * boxaaTranspose(BOXAA *baas)
boxaaTranspose()
BOXAA * boxaEncapsulateAligned(BOXA *boxa, l_int32 num, l_int32 copyflag)
boxaEncapsulateAligned()
BOX * boxRotateOrth(BOX *box, l_int32 w, l_int32 h, l_int32 rotation)
boxRotateOrth()
BOXA * boxaRotateOrth(BOXA *boxas, l_int32 w, l_int32 h, l_int32 rotation)
boxaRotateOrth()
BOX * boxTransform(BOX *box, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley)
boxTransform()
BOXA * boxaBinSort(BOXA *boxas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex)
boxaBinSort()
l_ok boxaGetMedianVals(BOXA *boxa, l_int32 *px, l_int32 *py, l_int32 *pr, l_int32 *pb, l_int32 *pw, l_int32 *ph)
boxaGetMedianVals()
l_ok boxaGetAverageSize(BOXA *boxa, l_float32 *pw, l_float32 *ph)
boxaGetAverageSize()
BOX * boxTransformOrdered(BOX *boxs, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley, l_int32 xcen, l_int32 ycen, l_float32 angle, l_int32 order)
boxTransformOrdered()
PTA * boxaExtractCorners(BOXA *boxa, l_int32 loc)
boxaExtractCorners()
BOXA * boxaTransform(BOXA *boxas, l_int32 shiftx, l_int32 shifty, l_float32 scalex, l_float32 scaley)
boxaTransform()
BOXA * boxaSortByIndex(BOXA *boxas, NUMA *naindex)
boxaSortByIndex()
BOXA * boxaSort(BOXA *boxas, l_int32 sorttype, l_int32 sortorder, NUMA **pnaindex)
boxaSort()
BOXAA * boxaSort2dByIndex(BOXA *boxas, NUMAA *naa)
boxaSort2dByIndex()
l_ok boxaExtractAsPta(BOXA *boxa, PTA **pptal, PTA **pptat, PTA **pptar, PTA **pptab, PTA **pptaw, PTA **pptah, l_int32 keepinvalid)
boxaExtractAsPta()
BOXAA * boxaSort2d(BOXA *boxas, NUMAA **pnaad, l_int32 delta1, l_int32 delta2, l_int32 minh1)
boxaSort2d()
l_ok boxaExtractAsNuma(BOXA *boxa, NUMA **pnal, NUMA **pnat, NUMA **pnar, NUMA **pnab, NUMA **pnaw, NUMA **pnah, l_int32 keepinvalid)
boxaExtractAsNuma()
BOXA * boxaaFlattenAligned(BOXAA *baa, l_int32 num, BOX *fillerbox, l_int32 copyflag)
boxaaFlattenAligned()
@ L_SORT_BY_MIN_DIMENSION
@ L_SORT_BY_MAX_DIMENSION