26 #include "allheaders.h" 31 #define PROJECTION_MARGIN 10 //arbitrary 51 cblob_ptr->
rotate(rotation);
53 compute_bounding_box();
58 int left = -box.
right();
70 ICOORD bottom_pt(top_pt.x(), base_char_bottom_);
72 base_char_top_ = top_pt.y();
73 bottom_pt.rotate(rotation);
74 base_char_bottom_ = bottom_pt.y();
92 nextblob->joined =
TRUE;
99 if (cblob_ptr != NULL && other->cblob_ptr != NULL) {
100 C_OUTLINE_IT ol_it(cblob_ptr->
out_list());
101 ol_it.add_list_after(other->cblob_ptr->
out_list());
116 BLOBNBOX_IT *start_it,
129 float test_ymin, test_ymax;
134 blobcount = (
inT16) floor (box.
width () / xheight);
135 if (blobcount > 1 && cblob_ptr != NULL) {
137 blobwidth = (float) (box.
width () + 1) / blobcount;
138 for (blobindex = blobcount - 1, rightx = box.
right ();
139 blobindex >= 0; blobindex--, rightx -= blobwidth) {
144 blob = blob_it.data ();
147 test_ymin, test_ymax);
151 while (blob != end_it->data ());
153 leftx = (
inT16) floor (rightx - blobwidth);
154 if (leftx < box.
left ())
163 newblob->box =
TBOX (bl, tr);
165 newblob->base_char_top_ = tr.
y();
166 newblob->base_char_bottom_ = bl.
y();
167 end_it->add_after_stay_put (newblob);
177 for (
int dir = 0; dir <
BND_COUNT; ++dir) {
183 gaps[dir] = box.
x_gap(n_box);
185 gaps[dir] = box.
y_gap(n_box);
196 int* v_min,
int* v_max)
const {
202 if (*h_max > max_dimension && *h_min < max_dimension) *h_max = *h_min;
205 if (*v_max > max_dimension && *v_min < max_dimension) *v_max = *v_min;
210 for (
int dir = 0; dir <
BND_COUNT; ++dir) {
213 neighbours_[dir] = NULL;
214 good_stroke_neighbours_[dir] =
false;
223 for (
int dir = 0; dir <
BND_COUNT; ++dir) {
234 for (
int dir = 0; dir <
BND_COUNT; ++dir) {
248 if (
cblob() == NULL)
return false;
249 int box_perimeter = 2 * (box.
height() + box.
width());
260 perimeter -= 4 *
cblob()->
area() / perimeter;
261 perimeter -= 2 * box.
width();
275 perimeter -= 4 *
cblob()->
area() / perimeter;
276 perimeter -= 2 * box.
height();
288 if (box.
left() < other.box.
left() && box.
left() < other.left_rule_)
290 if (other.box.
left() < box.
left() && other.box.
left() < left_rule_)
292 if (box.
right() > other.box.
right() && box.
right() > other.right_rule_)
294 if (other.box.
right() > box.
right() && other.box.
right() > right_rule_)
301 double fractional_tolerance,
302 double constant_tolerance)
const {
307 float h_tolerance = horz_stroke_width_ * fractional_tolerance
308 + constant_tolerance;
309 float v_tolerance = vert_stroke_width_ * fractional_tolerance
310 + constant_tolerance;
311 double p_tolerance = p_width * fractional_tolerance
312 + constant_tolerance;
313 bool h_zero = horz_stroke_width_ == 0.0f || other.horz_stroke_width_ == 0.0f;
314 bool v_zero = vert_stroke_width_ == 0.0f || other.vert_stroke_width_ == 0.0f;
315 bool h_ok = !h_zero &&
NearlyEqual(horz_stroke_width_,
316 other.horz_stroke_width_, h_tolerance);
317 bool v_ok = !v_zero &&
NearlyEqual(vert_stroke_width_,
318 other.vert_stroke_width_, v_tolerance);
319 bool p_ok = h_zero && v_zero &&
NearlyEqual(p_width, n_p_width, p_tolerance);
323 return p_ok || ((v_ok || h_ok) && (h_ok || h_zero) && (v_ok || v_zero));
329 FCOORD no_rotation(1.0f, 0.0f);
330 float top = box.
top();
331 float bottom = box.
bottom();
332 if (cblob_ptr != NULL) {
334 static_cast<float>(right), no_rotation,
342 FCOORD bot_left(left, bottom);
343 FCOORD top_right(right, top);
344 TBOX shrunken_box(bot_left);
345 TBOX shrunken_box2(top_right);
346 shrunken_box += shrunken_box2;
353 baseline_y_ = box.
bottom();
354 if (cblob_ptr == NULL)
return;
360 BLOBNBOX_IT blob_it(blobs);
361 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
362 blob_it.data()->CleanNeighbours();
368 BLOBNBOX_IT blob_it(blobs);
369 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
372 delete blob->
cblob();
373 delete blob_it.extract();
381 BLOBNBOX_LIST* blobs) {
384 int scale_factor = 1;
385 if (thresholds != NULL && grey != NULL) {
386 grey_height = pixGetHeight(grey);
387 thr_height = pixGetHeight(thresholds);
391 BLOBNBOX_IT blob_it(blobs);
392 for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
394 if (blob->
cblob() != NULL) {
396 l_uint32 threshold = 128;
397 if (thresholds != NULL && grey != NULL) {
402 pixGetPixel(thresholds, pt.
x / scale_factor,
403 thr_height - 1 - pt.
y / scale_factor, &threshold);
411 #ifndef GRAPHICS_DISABLED 418 BLOBNBOX_IT it(list);
419 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
420 it.data()->plot(win, body_colour, child_colour);
431 BLOBNBOX_IT it(list);
432 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
435 blob->
plot(win, body_colour, child_colour);
483 if (cblob_ptr != NULL)
484 cblob_ptr->
plot(window, blob_colour, child_colour);
506 C_OUTLINE_IT out_it = blob->
out_list ();
510 for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
511 outline = out_it.data ();
514 for (stepindex = 0; stepindex < outline->
pathlength (); stepindex++) {
516 if (pos.
x () >= leftx && pos.
x () <= rightx) {
519 vec = outline->
step (stepindex);
545 C_OUTLINE_IT out_it = blob->
out_list ();
549 for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
550 outline = out_it.data ();
552 for (stepindex = 0; stepindex < outline->
pathlength (); stepindex++) {
554 if (pos.
x () >= leftx && pos.
x () <= rightx) {
557 vec = outline->
step (stepindex);
582 C_OUTLINE_IT out_it = blob->
out_list ();
586 for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
587 outline = out_it.data ();
589 for (stepindex = 0; stepindex < outline->
pathlength (); stepindex++) {
591 if (pos.
y () >= bottomy && pos.
y () <= topy) {
594 vec = outline->
step (stepindex);
610 C_OUTLINE_LIST out_list;
612 C_OUTLINE_IT in_it = blob->
out_list ();
614 C_OUTLINE_IT out_it = &out_list;
616 for (in_it.mark_cycle_pt (); !in_it.cycled_list (); in_it.forward ()) {
617 out_it.add_after_then_move (
new C_OUTLINE (in_it.data (), rotation));
619 return new C_BLOB (&out_list);
642 if (blob->
cblob() == NULL)
693 initial_y_min = bottom;
696 BLOBNBOX_IT it = &blobs;
698 it.add_to_end (blob);
699 diff = top - bottom - row_size;
705 else if ((top - bottom) * 3 < row_size) {
706 diff = row_size / 3 + bottom - top;
713 tprintf(
"pitch=%d, fp=%g, fps=%g, fpns=%g, prs=%g, prns=%g," 714 " spacing=%g xh=%g y_origin=%g xev=%d, asc=%g, desc=%g," 715 " body=%g, minsp=%d maxnsp=%d, thr=%d kern=%g sp=%g\n",
736 BLOBNBOX_IT it = &blobs;
738 it.add_to_end (blob);
739 allowed = row_size + y_min - y_max;
741 available = top > y_max ? top - y_max : 0;
744 available += y_min - bottom;
746 available += available;
747 if (available < allowed)
750 y_min -= (y_min - bottom) * allowed / available;
752 y_max += (top - y_max) * allowed / available;
767 BLOBNBOX_IT it = &blobs;
770 it.add_before_then_move (blob);
773 while (!it.cycled_list ()
774 && it.data ()->bounding_box ().left () <=
777 if (it.cycled_list ())
778 it.add_to_end (blob);
780 it.add_before_stay_put (blob);
797 if (blob_it.empty ())
799 row_box = blob_it.data ()->bounding_box ();
800 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ())
801 row_box += blob_it.data ()->bounding_box ();
807 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
808 blob = blob_it.data();
809 if (blob->
cblob() != NULL)
820 void TO_ROW::clear() {
852 num_repeated_sets_ = -1;
868 C_OUTLINE_IT out_it = blob->
out_list ();
870 for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
891 C_OUTLINE_IT out_it = outline->
child ();
895 for (stepindex = 0; stepindex < length; stepindex++) {
896 step = outline->
step (stepindex);
898 stats->
add (pos.
x (), -pos.
y ());
899 }
else if (step.
x () < 0) {
900 stats->
add (pos.
x () - 1, pos.
y ());
905 for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
924 static void clear_blobnboxes(BLOBNBOX_LIST* boxes) {
925 BLOBNBOX_IT it = boxes;
928 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
930 if (box->
cblob() != NULL)
963 clear_blobnboxes(&
blobs);
975 static void SizeFilterBlobs(
int min_height,
int max_height,
976 BLOBNBOX_LIST* src_list,
977 BLOBNBOX_LIST* noise_list,
978 BLOBNBOX_LIST* small_list,
979 BLOBNBOX_LIST* medium_list,
980 BLOBNBOX_LIST* large_list) {
981 BLOBNBOX_IT noise_it(noise_list);
982 BLOBNBOX_IT small_it(small_list);
983 BLOBNBOX_IT medium_it(medium_list);
984 BLOBNBOX_IT large_it(large_list);
985 for (BLOBNBOX_IT src_it(src_list); !src_it.empty(); src_it.forward()) {
990 if (height < min_height &&
991 (width < min_height || width > max_height))
992 noise_it.add_after_then_move(blob);
993 else if (height > max_height)
994 large_it.add_after_then_move(blob);
995 else if (height < min_height)
996 small_it.add_after_then_move(blob);
998 medium_it.add_after_then_move(blob);
1010 BLOBNBOX_LIST noise_list;
1011 BLOBNBOX_LIST small_list;
1012 BLOBNBOX_LIST medium_list;
1013 BLOBNBOX_LIST large_list;
1014 SizeFilterBlobs(min_height, max_height, &
blobs,
1015 &noise_list, &small_list, &medium_list, &large_list);
1016 SizeFilterBlobs(min_height, max_height, &
large_blobs,
1017 &noise_list, &small_list, &medium_list, &large_list);
1018 SizeFilterBlobs(min_height, max_height, &
small_blobs,
1019 &noise_list, &small_list, &medium_list, &large_list);
1020 SizeFilterBlobs(min_height, max_height, &
noise_blobs,
1021 &noise_list, &small_list, &medium_list, &large_list);
1022 BLOBNBOX_IT blob_it(&
blobs);
1023 blob_it.add_list_after(&medium_list);
1025 blob_it.add_list_after(&large_list);
1027 blob_it.add_list_after(&small_list);
1029 blob_it.add_list_after(&noise_list);
1057 #ifndef GRAPHICS_DISABLED 1083 BLOBNBOX_LIST *list,
1086 BLOBNBOX_IT it = list;
1087 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
1088 it.data()->plot(win, body_colour, child_colour);
1091 #endif // GRAPHICS_DISABLED #define ELISTIZE(CLASSNAME)
const TBOX & bounding_box() const
void rotate(const FCOORD &vec)
void rotate(FCOORD rotation)
float area_stroke_width() const
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
bool NearlyEqual(T x, T y, T tolerance)
int IntCastRounded(double x)
const double kMinMediumSizeRatio
void find_cblob_limits(C_BLOB *blob, float leftx, float rightx, FCOORD rotation, float &ymin, float &ymax)
void reflect_box_in_y_axis()
ScrollView::Color BoxColor() const
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
PITCH_TYPE pitch_decision
void add(inT32 value, inT32 count)
#define ELIST2IZE(CLASSNAME)
const double kComplexShapePerimeterRatio
void set_vert_possible(bool value)
bool DefiniteIndividualFlow()
TBOX bounding_box() const
void ReSetAndReFilterBlobs()
ICOORD step(int index) const
void add_blob(BLOBNBOX *blob, float top, float bottom, float row_size)
C_OUTLINE_LIST * out_list()
void really_merge(BLOBNBOX *other)
void ComputeEdgeOffsets(int threshold, Pix *pix)
static void PlotBlobs(BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour, ScrollView *win)
void set_diacritic_box(const TBOX &diacritic_box)
inT16 EstimateBaselinePosition()
const double kCosSmallAngle
void set_horz_possible(bool value)
void rotate_box(FCOORD rotation)
void DeleteUnownedNoise()
BLOBNBOX_LIST * blob_list()
PITCH_TYPE pitch_decision
const double kDefiniteAspectRatio
static void PlotNoiseBlobs(BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour, ScrollView *win)
int y_gap(const TBOX &box) const
void plot_noise_blobs(ScrollView *to_win)
BLOBNBOX_LIST noise_blobs
void compute_vertical_projection()
bool joined_to_prev() const
int NoisyNeighbours() const
BLOBNBOX * neighbour(BlobNeighbourDir n) const
void plot(ScrollView *window, ScrollView::Color blob_colour, ScrollView::Color child_colour)
inT16 x() const
access function
TBOX box_next(BLOBNBOX_IT *it)
BLOBNBOX_LIST large_blobs
void insert_blob(BLOBNBOX *blob)
void plot_blob_list(ScrollView *win, BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour)
void rotate(const FCOORD &vec)
int x_gap(const TBOX &box) const
C_BLOB * crotate_cblob(C_BLOB *blob, FCOORD rotation)
#define PROJECTION_MARGIN
bool good_stroke_neighbour(BlobNeighbourDir n) const
void EstimateBaselinePosition()
const double kMaxMediumSizeRatio
bool MatchingStrokeWidth(const BLOBNBOX &other, double fractional_tolerance, double constant_tolerance) const
void vertical_cblob_projection(C_BLOB *blob, STATS *stats)
float horz_stroke_width() const
bool ConfirmNoTabViolation(const BLOBNBOX &other) const
BLOBNBOX_LIST small_blobs
void plot_graded_blobs(ScrollView *to_win)
void NeighbourGaps(int gaps[BND_COUNT]) const
void ComputeEdgeOffsets(Pix *thresholds, Pix *grey)
void compute_bounding_box()
static void DeleteNoiseBlobs(BLOBNBOX_LIST *blobs)
void find_cblob_vlimits(C_BLOB *blob, float leftx, float rightx, float &ymin, float &ymax)
const ICOORD & start_pos() const
TBOX box_next_pre_chopped(BLOBNBOX_IT *it)
void vertical_coutline_projection(C_OUTLINE *outline, STATS *stats)
static void ComputeEdgeOffsets(Pix *thresholds, Pix *grey, BLOBNBOX_LIST *blobs)
float vert_stroke_width() const
void chop(BLOBNBOX_IT *start_it, BLOBNBOX_IT *blob_it, FCOORD rotation, float xheight)
void merge(BLOBNBOX *nextblob)
BlobRegionType region_type() const
void MinMaxGapsClipped(int *h_min, int *h_max, int *v_min, int *v_max) const
static ScrollView::Color TextlineColor(BlobRegionType region_type, BlobTextFlowType flow_type)
void find_cblob_hlimits(C_BLOB *blob, float bottomy, float topy, float &xmin, float &xmax)
TBOX BoundsWithinLimits(int left, int right)
bool DeletableNoise() const
bool set_range(inT32 min_bucket_value, inT32 max_bucket_value_plus_1)
inT16 y() const
access_function