Deleted lots of dead code, including PBLOB

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@562 d0cd1f9f-072b-0410-8dd7-cf729c803f20
This commit is contained in:
theraysmith 2011-03-18 21:54:32 +00:00
parent 06dda0009e
commit 33b346991a
11 changed files with 78 additions and 856 deletions

View File

@ -26,7 +26,6 @@
#define BLKOCC_H
#include "params.h"
#include "polyblob.h"
#include "elst.h"
#include "notdll.h"
#include "notdll.h"
@ -255,20 +254,12 @@ extern INT_VAR_H (blockocc_asc_height, 255,
extern INT_VAR_H (blockocc_band_count, 4, "Number of bands used");
extern double_VAR_H (textord_underline_threshold, 0.9,
"Fraction of width occupied");
BOOL8 test_underline( //look for underlines
BOOL8 testing_on, //drawing blob
PBLOB *blob, //blob to test
float baseline, //coords of baseline
float xheight //height of line
);
BOOL8 test_underline( //look for underlines
BOOL8 testing_on, //drawing blob
C_BLOB *blob, //blob to test
inT16 baseline, //coords of baseline
inT16 xheight //height of line
);
void block_occ (PBLOB * blob, //blob to do
float occs[] //output histogram
);
#endif

View File

@ -297,15 +297,11 @@ void plot_word_decisions( //draw words
blob_box.left (), blob_box.top ());
}
}
if (!blob->joined_to_prev ())
prev_x = blob_box.right ();
if (blob->blob () != NULL)
//draw it
blob->blob ()->plot (win, colour, colour);
if (!blob->joined_to_prev())
prev_x = blob_box.right();
if (blob->cblob () != NULL)
blob->cblob ()->plot (win, colour, colour);
if (!blob->joined_to_prev ()
&& (blob->blob () != NULL || blob->cblob () != NULL))
if (!blob->joined_to_prev() && blob->cblob() != NULL)
blob_count++;
}
if (pitch > 0 && textord_show_fixed_cuts && blob_count > 0)

View File

@ -42,7 +42,7 @@ EXTERN INT_VAR (textord_fp_chop_error, 2,
EXTERN double_VAR (textord_fp_chop_snap, 0.5,
"Max distance of chop pt from vertex");
ELISTIZE (OUTLINE_FRAG) ELISTIZE (C_OUTLINE_FRAG)
ELISTIZE(C_OUTLINE_FRAG)
//#undef ASSERT_HOST
//#define ASSERT_HOST(x) if (!(x)) AfxMessageBox(#x);
/**********************************************************************
@ -61,13 +61,9 @@ ROW *fixed_pitch_words( //find lines
inT16 prev_chop_coord; //start of cell
inT16 rep_left; //left edge of rep word
ROW *real_row; //output row
OUTLINE_LIST left_outlines; //in current blob
OUTLINE_LIST right_outlines; //for next blob
C_OUTLINE_LIST left_coutlines;
C_OUTLINE_LIST right_coutlines;
PBLOB_LIST blobs; //blobs in word
C_BLOB_LIST cblobs;
PBLOB_IT blob_it = &blobs; //iterator
C_BLOB_IT cblob_it = &cblobs;
WERD_LIST words;
WERD_IT word_it = &words; //new words
@ -126,25 +122,20 @@ ROW *fixed_pitch_words( //find lines
prev_x = box_it.data ()->bounding_box ().right ();
split_to_blob (box_it.extract (), chop_coord,
textord_fp_chop_error + 0.5f,
&left_outlines, &left_coutlines,
&right_outlines, &right_coutlines);
&left_coutlines,
&right_coutlines);
box_it.forward ();
while (!box_it.empty ()
&& box_it.data ()->blob () == NULL
&& box_it.data ()->cblob () == NULL) {
delete box_it.extract ();
box_it.forward ();
while (!box_it.empty() && box_it.data()->cblob() == NULL) {
delete box_it.extract();
box_it.forward();
}
}
if ((!right_outlines.empty () || !right_coutlines.empty ())
&& left_outlines.empty () && left_coutlines.empty ())
if (!right_coutlines.empty() && left_coutlines.empty())
split_to_blob (NULL, chop_coord,
textord_fp_chop_error + 0.5f,
&left_outlines, &left_coutlines,
&right_outlines, &right_coutlines);
if (!left_outlines.empty ())
blob_it.add_after_then_move (new PBLOB (&left_outlines));
else if (!left_coutlines.empty ())
&left_coutlines,
&right_coutlines);
if (!left_coutlines.empty ())
cblob_it.add_after_then_move (new C_BLOB (&left_coutlines));
else {
if (rep_left < chop_coord) {
@ -161,18 +152,11 @@ ROW *fixed_pitch_words( //find lines
else
new_blanks = 0;
}
if (!blob_it.empty () || !cblob_it.empty ()) {
if (!cblob_it.empty()) {
if (blanks < 1 && word != NULL && !word->flag (W_REP_CHAR))
blanks = 1;
if (!blob_it.empty ()) {
//make real word
word = new WERD (&blobs, blanks, NULL);
blob_it.set_to_list (&blobs);
}
else {
word = new WERD (&cblobs, blanks, NULL);
cblob_it.set_to_list (&cblobs);
}
word = new WERD (&cblobs, blanks, NULL);
cblob_it.set_to_list (&cblobs);
word->set_flag (W_DONT_CHOP, TRUE);
word_it.add_after_then_move (word);
if (bol) {
@ -191,12 +175,8 @@ ROW *fixed_pitch_words( //find lines
if (prev_chop_coord < chop_coord)
prev_chop_coord = chop_coord;
}
if (!blob_it.empty () || !cblob_it.empty ()) {
if (!blob_it.empty ())
//last word on line
word = new WERD (&blobs, blanks, NULL);
else
word = new WERD (&cblobs, blanks, NULL);
if (!cblob_it.empty()) {
word = new WERD(&cblobs, blanks, NULL);
word->set_flag (W_DONT_CHOP, TRUE);
word_it.add_after_then_move (word);
if (bol)
@ -270,28 +250,16 @@ void split_to_blob( //split the blob
BLOBNBOX *blob, //blob to split
inT16 chop_coord, //place to chop
float pitch_error, //allowed deviation
OUTLINE_LIST *left_outlines, //left half of chop
C_OUTLINE_LIST *left_coutlines, //for cblobs
OUTLINE_LIST *right_outlines, //right half of chop
C_OUTLINE_LIST *right_coutlines) {
PBLOB *real_blob; //blob to chop
C_BLOB *real_cblob; //cblob to chop
if (blob != NULL) {
real_blob = blob->blob ();
real_cblob = blob->cblob ();
}
else {
real_blob = NULL;
real_cblob = blob->cblob();
} else {
real_cblob = NULL;
}
if (!right_outlines->empty () || real_blob != NULL)
fixed_chop_blob(real_blob,
chop_coord,
pitch_error,
left_outlines,
right_outlines);
else if (!right_coutlines->empty () || real_cblob != NULL)
if (!right_coutlines->empty() || real_cblob != NULL)
fixed_chop_cblob(real_cblob,
chop_coord,
pitch_error,
@ -301,543 +269,6 @@ void split_to_blob( //split the blob
delete blob; //free it
}
/**********************************************************************
* fixed_chop_blob
*
* Chop the given blob (if any) and the existing right outlines to
* produce a list of outlines left of the chop point and more to the right.
**********************************************************************/
void fixed_chop_blob( //split the blob
PBLOB *blob, //blob to split
inT16 chop_coord, //place to chop
float pitch_error, //allowed deviation
OUTLINE_LIST *left_outlines, //left half of chop
OUTLINE_LIST *right_outlines //right half of chop
) {
OUTLINE *old_right; //already there
OUTLINE_LIST new_outlines; //new right ones
//ouput iterator
OUTLINE_IT left_it = left_outlines;
//in/out iterator
OUTLINE_IT right_it = right_outlines;
OUTLINE_IT new_it = &new_outlines;
OUTLINE_IT blob_it; //outlines in blob
if (!right_it.empty ()) {
while (!right_it.empty ()) {
old_right = right_it.extract ();
right_it.forward ();
fixed_split_outline(old_right,
chop_coord,
pitch_error,
&left_it,
&new_it);
}
right_it.add_list_before (&new_outlines);
}
if (blob != NULL) {
blob_it.set_to_list (blob->out_list ());
for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
blob_it.forward ())
fixed_split_outline (blob_it.extract (), chop_coord, pitch_error,
&left_it, &right_it);
delete blob;
}
}
/**********************************************************************
* fixed_split_outline
*
* Chop the given outline (if necessary) placing the fragments which
* fall either side of the chop line into the appropriate list.
**********************************************************************/
void fixed_split_outline( //chop the outline
OUTLINE *srcline, //source outline
inT16 chop_coord, //place to chop
float pitch_error, //allowed deviation
OUTLINE_IT *left_it, //left half of chop
OUTLINE_IT *right_it //right half of chop
) {
OUTLINE *child; //child outline
TBOX srcbox; //box of outline
OUTLINE_LIST left_ch; //left children
OUTLINE_LIST right_ch; //right children
OUTLINE_FRAG_LIST left_frags; //chopped fragments
OUTLINE_FRAG_LIST right_frags;;
OUTLINE_IT left_ch_it = &left_ch;
//for whole children
OUTLINE_IT right_ch_it = &right_ch;
//for holes
OUTLINE_IT child_it = srcline->child ();
srcbox = srcline->bounding_box ();
//left of line
if (srcbox.left () + srcbox.right () <= chop_coord * 2
//and not far over
&& srcbox.right () < chop_coord + pitch_error)
//stick whole in left
left_it->add_after_then_move (srcline);
else if (srcbox.left () + srcbox.right () > chop_coord * 2
&& srcbox.left () > chop_coord - pitch_error)
//stick whole in right
right_it->add_before_stay_put (srcline);
else {
//needs real chopping
if (fixed_chop_outline (srcline, chop_coord, pitch_error,
&left_frags, &right_frags)) {
for (child_it.mark_cycle_pt (); !child_it.cycled_list ();
child_it.forward ()) {
child = child_it.extract ();
srcbox = child->bounding_box ();
if (srcbox.right () < chop_coord)
left_ch_it.add_after_then_move (child);
else if (srcbox.left () > chop_coord)
right_ch_it.add_after_then_move (child);
else {
if (fixed_chop_outline (child, chop_coord, pitch_error,
&left_frags, &right_frags))
delete child;
else {
if (srcbox.left () + srcbox.right () <= chop_coord * 2)
left_ch_it.add_after_then_move (child);
else
right_ch_it.add_after_then_move (child);
}
}
}
close_chopped_fragments(&left_frags, &left_ch, left_it);
close_chopped_fragments(&right_frags, &right_ch, right_it);
ASSERT_HOST (left_ch.empty () && right_ch.empty ());
//no children left
delete srcline; //smashed up
}
else {
if (srcbox.left () + srcbox.right () <= chop_coord * 2)
//stick whole in left
left_it->add_after_then_move (srcline);
else
right_it->add_before_stay_put (srcline);
}
}
}
/**********************************************************************
* fixed_chop_outline
*
* Chop the given outline (if necessary) placing the fragments which
* fall either side of the chop line into the appropriate list.
* If the outline lies too heavily to one side to chop, FALSE is returned.
**********************************************************************/
BOOL8 fixed_chop_outline( //chop the outline
OUTLINE *srcline, //source outline
inT16 chop_coord, //place to chop
float pitch_error, //allowed deviation
OUTLINE_FRAG_LIST *left_frags, //left half of chop
OUTLINE_FRAG_LIST *right_frags //right half of chop
) {
BOOL8 not_first; //fragment
BOOL8 test_valid; //test pt valid
float left_edge; //of outline
FCOORD chop_pos; //coords of chop
float chop_starty; //test chop pt
POLYPT *startpt; //in first fragment
//general iterator
POLYPT_IT poly_it = srcline->polypts ();
POLYPT_IT head_it; //head of fragment
POLYPT_IT tail_it; //tail of fragment
POLYPT_IT test_tail; //possible chop pt
left_edge = poly_it.data ()->pos.x ();
tail_it = poly_it;
for (poly_it.mark_cycle_pt (); !poly_it.cycled_list (); poly_it.forward ()) {
if (poly_it.data ()->pos.x () < left_edge) {
left_edge = poly_it.data ()->pos.x ();
tail_it = poly_it; //find leftmost pt
}
}
if (left_edge >= chop_coord - pitch_error)
return FALSE; //not worth it
startpt = tail_it.data ();
not_first = FALSE;
head_it = tail_it;
chop_starty = tail_it.data ()->pos.y ();
do {
test_valid = FALSE;
do {
tail_it.forward ();
if (test_valid
&& tail_it.data ()->pos.x () >= chop_coord
&& tail_it.data ()->pos.x () + tail_it.data ()->vec.x () <=
chop_coord) {
chop_pos = find_chop_coords (&tail_it, chop_coord);
if (chop_pos.y () >= chop_starty)
test_valid = FALSE;
else {
tail_it = test_tail;
break; //must chop there
}
}
if (tail_it.data ()->pos.x () <= chop_coord
&& tail_it.data ()->pos.x () + tail_it.data ()->vec.x () >=
chop_coord) {
chop_pos = find_chop_coords (&tail_it, chop_coord);
chop_starty = chop_pos.y ();
test_tail = tail_it; //save possible chop pt
test_valid = TRUE;
if (tail_it.data ()->vec.x () == 0
&& tail_it.data ()->vec.y () < 0)
break; //must chop here
}
}
while (tail_it.data () != startpt
&& tail_it.data ()->pos.x () < chop_coord + pitch_error);
//back to start
if (tail_it.data () == startpt) {
if (not_first)
break;
else
return FALSE; //doesn't cross line
}
while (tail_it.data ()->pos.x () > chop_coord)
tail_it.backward ();
if (head_it.data () == tail_it.data ())
insert_extra_pt(&tail_it);
insert_chop_pt(&tail_it, chop_coord);
if (not_first) {
save_chop_fragment(&head_it, &tail_it, left_frags);
}
else {
tail_it.forward ();
head_it = tail_it;
}
test_valid = FALSE;
do {
tail_it.forward ();
if (test_valid
&& tail_it.data ()->pos.x () <= chop_coord
&& tail_it.data ()->pos.x () + tail_it.data ()->vec.x () >=
chop_coord) {
chop_pos = find_chop_coords (&tail_it, chop_coord);
if (chop_pos.y () <= chop_starty)
test_valid = FALSE;
else {
tail_it = test_tail;
break; //must chop there
}
}
if (tail_it.data ()->pos.x () >= chop_coord
&& tail_it.data ()->pos.x () + tail_it.data ()->vec.x () <=
chop_coord) {
chop_pos = find_chop_coords (&tail_it, chop_coord);
chop_starty = chop_pos.y ();
test_tail = tail_it;
test_valid = TRUE; //save possible chop pt
if (tail_it.data ()->vec.x () == 0
&& tail_it.data ()->vec.y () > 0)
break; //must chop here
}
}
while (tail_it.data () != startpt
&& tail_it.data ()->pos.x () > chop_coord - pitch_error);
while (tail_it.data ()->pos.x () < chop_coord)
tail_it.backward ();
if (head_it.data () == tail_it.data ())
insert_extra_pt(&tail_it);
insert_chop_pt(&tail_it, chop_coord);
save_chop_fragment(&head_it, &tail_it, right_frags);
not_first = TRUE;
}
while (tail_it.data () != startpt);
startpt = head_it.data_relative (-1);
while (tail_it.data () != startpt)
tail_it.forward ();
save_chop_fragment(&head_it, &tail_it, left_frags);
return TRUE; //did some chopping
}
/**********************************************************************
* save_chop_fragment
*
* Store the given fragment in the given fragment list.
**********************************************************************/
void save_chop_fragment( //chop the outline
POLYPT_IT *head_it, //head of fragment
POLYPT_IT *tail_it, //tail of fragment
OUTLINE_FRAG_LIST *frags //fragment list
) {
OUTLINE_FRAG *head; //head of fragment
OUTLINE_FRAG *tail; //tail of fragment
float tail_y; //ycoord of tail
tail_y = tail_it->data ()->pos.y ();
head = new OUTLINE_FRAG (head_it, tail_it);
tail = new OUTLINE_FRAG (head, tail_y);
head->other_end = tail;
add_frag_to_list(head, frags);
add_frag_to_list(tail, frags);
head_it->forward ();
tail_it->forward ();
}
/**********************************************************************
* OUTLINE_FRAG::OUTLINE_FRAG
*
* Constructors for OUTLINE_FRAG.
**********************************************************************/
OUTLINE_FRAG::OUTLINE_FRAG( //record fragment
POLYPT_IT *head_it, //head of fragment
POLYPT_IT *tail_it //tail of fragment
) {
ycoord = head_it->data ()->pos.y ();
other_end = NULL;
polypts.assign_to_sublist (head_it, tail_it);
}
OUTLINE_FRAG::OUTLINE_FRAG( //record fragment
OUTLINE_FRAG *head, //other end
float tail_y) {
ycoord = tail_y;
other_end = head;
}
/**********************************************************************
* add_frag_to_list
*
* Insert the fragment in the list at the appropriate place to keep
* them in ascending ycoord order.
**********************************************************************/
void add_frag_to_list( //ordered add
OUTLINE_FRAG *frag, //fragment to add
OUTLINE_FRAG_LIST *frags //fragment list
) {
//output list
OUTLINE_FRAG_IT frag_it = frags;
if (!frags->empty ()) {
for (frag_it.mark_cycle_pt (); !frag_it.cycled_list ();
frag_it.forward ()) {
if (frag_it.data ()->ycoord >= frag->ycoord) {
frag_it.add_before_then_move (frag);
return;
}
}
}
frag_it.add_to_end (frag);
}
/**********************************************************************
* insert_chop_pt
*
* Decide whether or not to use the actual point as chop coord.
* Insert either a duplicate of the current point or 2 copies
* of the new chop point. Position the iterator at the first.
**********************************************************************/
void insert_chop_pt( //make chop
POLYPT_IT *it, //iterator
inT16 chop_coord //required chop pt
) {
POLYPT *prev_pt; //point befor chop
POLYPT *chop_pt; //new vertex
FCOORD chop_pos; //coords of chop
FCOORD chop_vec; //vector to next
prev_pt = it->data ();
if (prev_pt->pos.x () + textord_fp_chop_snap >= chop_coord
&& prev_pt->pos.x () - textord_fp_chop_snap <= chop_coord) {
chop_pt = new POLYPT (prev_pt->pos, prev_pt->vec);
}
else {
chop_pos = FCOORD (chop_coord, prev_pt->pos.y ()
+ prev_pt->vec.y () * (chop_coord -
prev_pt->pos.x ()) /
prev_pt->vec.x ());
chop_vec = it->data_relative (1)->pos - chop_pos;
chop_pt = new POLYPT (chop_pos, chop_vec);
it->add_after_then_move (chop_pt);
chop_pt = new POLYPT (chop_pos, chop_vec);
}
it->add_after_stay_put (chop_pt);
}
/**********************************************************************
* find_chop_coords
*
* Decide whether or not to use the actual point as chop coord.
* Return the coords of the chop point.
**********************************************************************/
FCOORD find_chop_coords( //make chop
POLYPT_IT *it, //iterator
inT16 chop_coord //required chop pt
) {
POLYPT *prev_pt; //point befor chop
FCOORD chop_pos; //coords of chop
prev_pt = it->data ();
if (prev_pt->pos.x () + textord_fp_chop_snap >= chop_coord
&& prev_pt->pos.x () - textord_fp_chop_snap <= chop_coord) {
chop_pos = prev_pt->pos;
}
else {
chop_pos = FCOORD (chop_coord, prev_pt->pos.y ()
+ prev_pt->vec.y () * (chop_coord -
prev_pt->pos.x ()) /
prev_pt->vec.x ());
}
return chop_pos;
}
/**********************************************************************
* insert_extra_pt
*
* Add an extra pt to prevent single point fragments being made.
**********************************************************************/
void insert_extra_pt( //make extra
POLYPT_IT *it //iterator
) {
POLYPT *prev_pt; //point befor chop
POLYPT *chop_pt; //new vertex
FCOORD chop_pos; //coords of chop
FCOORD chop_vec; //vector to next
prev_pt = it->data ();
if (it->data_relative (1)->pos.y () > it->data_relative (-1)->pos.y ()) {
chop_pos = prev_pt->pos + FCOORD (0.0f,
static_cast<float>(textord_fp_chop_snap));
}
else {
chop_pos = prev_pt->pos - FCOORD (0.0f,
static_cast<float>(textord_fp_chop_snap));
}
chop_vec = it->data_relative (1)->pos - chop_pos;
prev_pt->vec = chop_pos - prev_pt->pos;
chop_pt = new POLYPT (chop_pos, chop_vec);
it->add_after_then_move (chop_pt);
}
/**********************************************************************
* close_chopped_fragments
*
* Clear the given list of fragments joining them up into outlines.
* Each outline made soaks up any of the child outlines which it encloses.
**********************************************************************/
void close_chopped_fragments( //chop the outline
OUTLINE_FRAG_LIST *frags, //list to clear
OUTLINE_LIST *children, //potential children
OUTLINE_IT *dest_it //output list
) {
//iterator
OUTLINE_FRAG_IT frag_it = frags;
OUTLINE_FRAG *bottom_frag; //bottom of cut
OUTLINE_FRAG *top_frag; //top of cut
OUTLINE *outline; //new outline
OUTLINE *child; //current child
OUTLINE_IT child_it = children;
OUTLINE_IT olchild_it; //children of outline
POLYPT_IT poly_it; //iterator for constr
while (!frag_it.empty ()) {
frag_it.move_to_first ();
//get bottom one
bottom_frag = frag_it.extract ();
frag_it.forward ();
//and one above it
top_frag = frag_it.extract ();
while (top_frag->other_end != bottom_frag) {
do {
frag_it.forward ();
}
//find other end
while (frag_it.data () != top_frag->other_end);
join_chopped_fragments(bottom_frag, top_frag);
delete top_frag;
delete frag_it.extract (); //remove middle section
frag_it.forward ();
top_frag = frag_it.extract ();
}
join_chopped_fragments(bottom_frag, top_frag);
if (bottom_frag->polypts.empty ())
poly_it.set_to_list (&top_frag->polypts);
else
poly_it.set_to_list (&bottom_frag->polypts);
outline = new OUTLINE (&poly_it);
olchild_it.set_to_list (outline->child ());
for (child_it.mark_cycle_pt (); !child_it.cycled_list ();
child_it.forward ()) {
child = child_it.data ();
if (*child < *outline)
olchild_it.add_to_end (child_it.extract ());
}
dest_it->add_after_then_move (outline);
}
while (!child_it.empty ()) {
dest_it->add_after_then_move (child_it.extract ());
child_it.forward ();
}
}
/**********************************************************************
* join_chopped_fragments
*
* Join the two lists of POLYPTs such that the first OUTLINE_FRAG
* operand keeps responsibility for the fragment.
**********************************************************************/
void join_chopped_fragments( //join pieces
OUTLINE_FRAG *bottom, //bottom of cut
OUTLINE_FRAG *top //top of cut
) {
POLYPT_IT master_it; //dest list
POLYPT_IT slave_it; //src list
POLYPT *cutpt; //vectors to change
POLYPT *nextpt; //other end of cut
if (bottom->polypts.empty ()) {
master_it.set_to_list (&bottom->other_end->polypts);
cutpt = master_it.data_relative (-1);
ASSERT_HOST (!top->polypts.empty ());
slave_it.set_to_list (&top->polypts);
nextpt = slave_it.data ();
if (bottom->other_end != top) {
master_it.move_to_last ();
master_it.add_list_after (&top->polypts);
}
}
else {
master_it.set_to_list (&bottom->polypts);
ASSERT_HOST (top->polypts.empty ());
slave_it.set_to_list (&top->other_end->polypts);
cutpt = slave_it.data_relative (-1);
nextpt = master_it.data ();
if (bottom->other_end != top)
master_it.add_list_before (&top->other_end->polypts);
}
cutpt->vec = nextpt->pos - cutpt->pos;
}
/**********************************************************************
* fixed_chop_cblob
*

View File

@ -25,23 +25,6 @@
#include "notdll.h"
#include "notdll.h"
class OUTLINE_FRAG:public ELIST_LINK
{
public:
OUTLINE_FRAG() {
} //empty constructor
//head of fragment
OUTLINE_FRAG(POLYPT_IT *head_it, POLYPT_IT *tail_it); //tail of fragment
//other end
OUTLINE_FRAG(OUTLINE_FRAG *head, float tail_y);
POLYPT_LIST polypts; //only if a head
OUTLINE_FRAG *other_end; //head if a tail
float ycoord; //coord of cut pt
private:
};
class C_OUTLINE_FRAG:public ELIST_LINK
{
public:
@ -75,7 +58,8 @@ class C_OUTLINE_FRAG:public ELIST_LINK
private:
};
ELISTIZEH (OUTLINE_FRAG) ELISTIZEH (C_OUTLINE_FRAG)
ELISTIZEH(C_OUTLINE_FRAG)
extern
INT_VAR_H (textord_fp_chop_error, 2,
"Max allowed bending of chop cells");
@ -98,60 +82,8 @@ void split_to_blob( //split the blob
BLOBNBOX *blob, //blob to split
inT16 chop_coord, //place to chop
float pitch_error, //allowed deviation
OUTLINE_LIST *left_outlines, //left half of chop
C_OUTLINE_LIST *left_coutlines, //for cblobs
OUTLINE_LIST *right_outlines, //right half of chop
C_OUTLINE_LIST *right_coutlines);
void fixed_chop_blob( //split the blob
PBLOB *blob, //blob to split
inT16 chop_coord, //place to chop
float pitch_error, //allowed deviation
OUTLINE_LIST *left_outlines, //left half of chop
OUTLINE_LIST *right_outlines //right half of chop
);
void fixed_split_outline( //chop the outline
OUTLINE *srcline, //source outline
inT16 chop_coord, //place to chop
float pitch_error, //allowed deviation
OUTLINE_IT *left_it, //left half of chop
OUTLINE_IT *right_it //right half of chop
);
BOOL8 fixed_chop_outline( //chop the outline
OUTLINE *srcline, //source outline
inT16 chop_coord, //place to chop
float pitch_error, //allowed deviation
OUTLINE_FRAG_LIST *left_frags, //left half of chop
OUTLINE_FRAG_LIST *right_frags //right half of chop
);
void save_chop_fragment( //chop the outline
POLYPT_IT *head_it, //head of fragment
POLYPT_IT *tail_it, //tail of fragment
OUTLINE_FRAG_LIST *frags //fragment list
);
void add_frag_to_list( //ordered add
OUTLINE_FRAG *frag, //fragment to add
OUTLINE_FRAG_LIST *frags //fragment list
);
void insert_chop_pt( //make chop
POLYPT_IT *it, //iterator
inT16 chop_coord //required chop pt
);
FCOORD find_chop_coords( //make chop
POLYPT_IT *it, //iterator
inT16 chop_coord //required chop pt
);
void insert_extra_pt( //make extra
POLYPT_IT *it //iterator
);
void close_chopped_fragments( //chop the outline
OUTLINE_FRAG_LIST *frags, //list to clear
OUTLINE_LIST *children, //potential children
OUTLINE_IT *dest_it //output list
);
void join_chopped_fragments( //join pieces
OUTLINE_FRAG *bottom, //bottom of cut
OUTLINE_FRAG *top //top of cut
);
void fixed_chop_cblob( //split the blob
C_BLOB *blob, //blob to split
inT16 chop_coord, //place to chop

View File

@ -507,8 +507,6 @@ static void vigorous_noise_removal(TO_BLOCK* block) {
continue; // Looks OK.
}
// It might be noise so get rid of it.
if (blob->blob() != NULL)
delete blob->blob();
if (blob->cblob() != NULL)
delete blob->cblob();
delete b_it.extract();

View File

@ -113,14 +113,6 @@ inT16 vertical_torow_projection( //project whole row
TO_ROW *row, //row to do
STATS *projection //output
);
void vertical_blob_projection( //project outlines
PBLOB *blob, //blob to project
STATS *stats //output
);
void vertical_outline_projection( //project outlines
OUTLINE *outline, //outline to project
STATS *stats //output
);
void vertical_cblob_projection( //project outlines
C_BLOB *blob, //blob to project
STATS *stats //output

View File

@ -1091,7 +1091,7 @@ BOOL8 count_pitch_stats( //find lines
blob_box = blob->bounding_box ();
if ((blob_box.left () - joined_box.right () < dm_gap
&& !blob_it.at_first ())
|| (blob->cblob () == NULL && blob->blob () == NULL))
|| blob->cblob() == NULL)
joined_box += blob_box; //merge blobs
else {
blob_width = joined_box.width ();

View File

@ -29,7 +29,6 @@
#include "drawtord.h"
#include "makerow.h"
#include "wordseg.h"
#include "genblob.h"
#include "imgs.h"
#include "textord.h"
#include "tordmain.h"

View File

@ -899,11 +899,8 @@ ROW *Textord::make_prop_words(
BOOL8 prev_gap_was_a_space = FALSE;
BOOL8 break_at_next_gap = FALSE;
ROW *real_row; //output row
OUTLINE_IT out_it; //outlines
C_OUTLINE_IT cout_it;
PBLOB_LIST blobs; //blobs in word
C_BLOB_LIST cblobs;
PBLOB_IT blob_it = &blobs; //iterator
C_BLOB_IT cblob_it = &cblobs;
WERD_LIST words;
WERD_IT word_it; //new words
@ -934,7 +931,6 @@ ROW *Textord::make_prop_words(
}
prev_x = -MAX_INT16;
blob_it.set_to_list (&blobs);
cblob_it.set_to_list (&cblobs);
box_it.set_to_list (row->blob_list ());
word_it.set_to_list (&words);
@ -994,23 +990,14 @@ ROW *Textord::make_prop_words(
bblob = box_it.data ();
blob_box = bblob->bounding_box ();
if (bblob->joined_to_prev ()) {
if (bblob->blob () != NULL) {
out_it.set_to_list (blob_it.data ()->out_list ());
out_it.move_to_last ();
out_it.add_list_after (bblob->blob ()->out_list ());
delete bblob->blob ();
}
else if (bblob->cblob () != NULL) {
if (bblob->cblob () != NULL) {
cout_it.set_to_list (cblob_it.data ()->out_list ());
cout_it.move_to_last ();
cout_it.add_list_after (bblob->cblob ()->out_list ());
delete bblob->cblob ();
}
}
else {
if (bblob->blob () != NULL)
blob_it.add_after_then_move (bblob->blob ());
else if (bblob->cblob () != NULL)
} else {
if (bblob->cblob() != NULL)
cblob_it.add_after_then_move (bblob->cblob ());
prev_x = blob_box.right ();
}
@ -1018,8 +1005,7 @@ ROW *Textord::make_prop_words(
bblob = box_it.data ();
blob_box = bblob->bounding_box ();
if (!bblob->joined_to_prev () &&
(bblob->blob () != NULL || bblob->cblob () != NULL)) {
if (!bblob->joined_to_prev() && bblob->cblob() != NULL) {
/* Real Blob - not multiple outlines or pre-chopped */
prev_gap = current_gap;
prev_within_xht_gap = current_within_xht_gap;
@ -1048,15 +1034,8 @@ ROW *Textord::make_prop_words(
break_at_next_gap) ||
box_it.at_first()) {
/* Form a new word out of the blobs collected */
if (!blob_it.empty ()) {
word = new WERD (&blobs, prev_blanks, NULL);
//make real word
word_count++;
}
else {
word = new WERD (&cblobs, prev_blanks, NULL);
word_count++;
}
word = new WERD (&cblobs, prev_blanks, NULL);
word_count++;
word_it.add_after_then_move (word);
if (bol) {
word->set_flag (W_BOL, TRUE);
@ -1725,41 +1704,23 @@ void Textord::mark_gap(
#endif
float Textord::find_mean_blob_spacing(WERD *word) {
PBLOB_IT blob_it;
C_BLOB_IT cblob_it;
TBOX blob_box;
inT32 gap_sum = 0;
inT16 gap_count = 0;
inT16 prev_right;
if (word->flag (W_POLYGON)) {
blob_it.set_to_list (word->blob_list ());
if (!blob_it.empty ()) {
blob_it.mark_cycle_pt ();
prev_right = blob_it.data ()->bounding_box ().right ();
//first blob
blob_it.forward ();
for (; !blob_it.cycled_list (); blob_it.forward ()) {
blob_box = blob_it.data ()->bounding_box ();
gap_sum += blob_box.left () - prev_right;
gap_count++;
prev_right = blob_box.right ();
}
}
}
else {
cblob_it.set_to_list (word->cblob_list ());
if (!cblob_it.empty ()) {
cblob_it.mark_cycle_pt ();
prev_right = cblob_it.data ()->bounding_box ().right ();
//first blob
cblob_it.forward ();
for (; !cblob_it.cycled_list (); cblob_it.forward ()) {
blob_box = cblob_it.data ()->bounding_box ();
gap_sum += blob_box.left () - prev_right;
gap_count++;
prev_right = blob_box.right ();
}
cblob_it.set_to_list (word->cblob_list ());
if (!cblob_it.empty ()) {
cblob_it.mark_cycle_pt ();
prev_right = cblob_it.data ()->bounding_box ().right ();
//first blob
cblob_it.forward ();
for (; !cblob_it.cycled_list (); cblob_it.forward ()) {
blob_box = cblob_it.data ()->bounding_box ();
gap_sum += blob_box.left () - prev_right;
gap_count++;
prev_right = blob_box.right ();
}
}
if (gap_count > 0)
@ -1823,11 +1784,10 @@ TBOX Textord::reduced_box_next(
if (blob->red_box_set ()) {
reduced_box = blob->reduced_box ();
do {
it->forward ();
blob = it->data ();
it->forward();
blob = it->data();
}
//until next real blob
while ((blob->blob () == NULL && blob->cblob () == NULL) || blob->joined_to_prev ());
while (blob->cblob() == NULL || blob->joined_to_prev());
return reduced_box;
}
head_blob = blob;
@ -1836,7 +1796,7 @@ TBOX Textord::reduced_box_next(
do {
it->forward ();
blob = it->data ();
if (blob->blob () == NULL && blob->cblob () == NULL)
if (blob->cblob() == NULL)
//was pre-chopped
full_box += blob->bounding_box ();
else if (blob->joined_to_prev ()) {
@ -1846,7 +1806,7 @@ TBOX Textord::reduced_box_next(
}
}
//until next real blob
while ((blob->blob () == NULL && blob->cblob () == NULL) || blob->joined_to_prev ());
while (blob->cblob() == NULL || blob->joined_to_prev());
if ((reduced_box.width () > 0) &&
((reduced_box.left () + tosp_near_lh_edge * reduced_box.width ())
@ -1906,22 +1866,8 @@ TBOX Textord::reduced_box_for_blob(
*/
left_limit = (float) MAX_INT32;
junk = (float) -MAX_INT32;
if (blob->blob () != NULL)
//blob to test
find_blob_limits (blob->blob (),
(float) -MAX_INT16, //rotated lower limit
-(baseline + 1.1 * row->xheight),
//rotated upper limit
FCOORD (0.0, 1.0), //90deg anticlock rot
left_limit, junk); //min y max_y
else
//blob to test
find_cblob_hlimits (blob->cblob (),
//rotated lower limit
(baseline + 1.1 * row->xheight), (float) MAX_INT16,
//rotated upper limit
// FCOORD( 0.0, 1.0 ), //90deg anticlock rot
left_limit, junk); //min y max_y
find_cblob_hlimits(blob->cblob(), (baseline + 1.1 * row->xheight),
static_cast<float>(MAX_INT16), left_limit, junk);
if (left_limit > junk)
*left_above_xht = MAX_INT16; //No area above xht
else
@ -1932,20 +1878,8 @@ TBOX Textord::reduced_box_for_blob(
*/
left_limit = (float) MAX_INT32;
junk = (float) -MAX_INT32;
if (blob->blob () != NULL)
//blob to test
find_blob_limits (blob->blob (),
(float) -MAX_INT16, //rotated lower limit
-baseline, //rotated upper limit
FCOORD (0.0, 1.0), //90deg anticlock rot
left_limit, junk); //min y max_y
else
//blob to test
find_cblob_hlimits (blob->cblob (),
baseline, //rotated upper limit
(float) MAX_INT16, //rotated lower limit
// FCOORD( 0.0, 1.0 ), //90deg anticlock rot
left_limit, junk); //min y max_y
find_cblob_hlimits(blob->cblob(), baseline, static_cast<float>(MAX_INT16),
left_limit, junk);
if (left_limit > junk)
return TBOX (); //no area within xht so return empty box
@ -1954,22 +1888,8 @@ TBOX Textord::reduced_box_for_blob(
*/
junk = (float) MAX_INT32;
right_limit = (float) -MAX_INT32;
if (blob->blob () != NULL)
//blob to test
find_blob_limits (blob->blob (),
-(baseline + row->xheight),
//rotated lower limit
(float) MAX_INT16, //rotated upper limit
FCOORD (0.0, 1.0), //90deg anticlock rot
junk, right_limit); //min y max_y
else
//blob to test
find_cblob_hlimits (blob->cblob (),
(float) -MAX_INT16, //rotated upper limit
(baseline + row->xheight),
//rotated lower limit
// FCOORD( 0.0, 1.0 ), //90deg anticlock rot
junk, right_limit); //min y max_y
find_cblob_hlimits(blob->cblob(), static_cast<float>(-MAX_INT16),
(baseline + row->xheight), junk, right_limit);
if (junk > right_limit)
return TBOX (); //no area within xht so return empty box

View File

@ -46,8 +46,6 @@ void restore_underlined_blobs( //get chop points
ICOORDELT_LIST chop_cells; //blobs to cut out
//real underlines
BLOBNBOX_LIST residual_underlines;
OUTLINE_LIST left_outlines; //in current blob
OUTLINE_LIST right_outlines; //for next blob
C_OUTLINE_LIST left_coutlines;
C_OUTLINE_LIST right_coutlines;
ICOORDELT_IT cell_it = &chop_cells;
@ -72,65 +70,44 @@ void restore_underlined_blobs( //get chop points
if (cell_it.data ()->y () - chop_coord > textord_fp_chop_error + 1) {
split_to_blob (u_line, chop_coord,
textord_fp_chop_error + 0.5,
&left_outlines, &left_coutlines,
&right_outlines, &right_coutlines);
if (!left_outlines.empty ())
ru_it.
add_after_then_move (new
BLOBNBOX (new PBLOB (&left_outlines)));
else if (!left_coutlines.empty ())
ru_it.
add_after_then_move (new
BLOBNBOX (new
C_BLOB (&left_coutlines)));
//right edge of lbob
&left_coutlines,
&right_coutlines);
if (!left_coutlines.empty()) {
ru_it.add_after_then_move(new BLOBNBOX(new C_BLOB(&left_coutlines)));
}
chop_coord = cell_it.data ()->y ();
split_to_blob (NULL, chop_coord,
textord_fp_chop_error + 0.5,
&left_outlines, &left_coutlines,
&right_outlines, &right_coutlines);
if (!left_outlines.empty ())
row->insert_blob (new BLOBNBOX (new PBLOB (&left_outlines)));
else if (!left_coutlines.empty ())
row->
insert_blob (new BLOBNBOX (new C_BLOB (&left_coutlines)));
else {
ASSERT_HOST(FALSE);
fprintf (stderr,
split_to_blob(NULL, chop_coord, textord_fp_chop_error + 0.5,
&left_coutlines, &right_coutlines);
if (!left_coutlines.empty()) {
row->insert_blob(new BLOBNBOX(new C_BLOB(&left_coutlines)));
} else {
fprintf(stderr,
"Error:no outlines after chopping from %d to %d from (%d,%d)->(%d,%d)\n",
cell_it.data ()->x (), cell_it.data ()->y (),
blob_box.left (), blob_box.bottom (),
blob_box.right (), blob_box.top ());
ASSERT_HOST(FALSE);
}
u_line = NULL; //no more blobs to add
}
delete cell_it.extract ();
delete cell_it.extract();
}
if (!right_outlines.empty () || !right_coutlines.empty ()) {
split_to_blob (NULL, blob_box.right (),
textord_fp_chop_error + 0.5,
&left_outlines, &left_coutlines,
&right_outlines, &right_coutlines);
if (!left_outlines.empty ())
ru_it.
add_after_then_move (new BLOBNBOX (new PBLOB (&left_outlines)));
else if (!left_coutlines.empty ())
ru_it.
add_after_then_move (new
BLOBNBOX (new C_BLOB (&left_coutlines)));
if (!right_coutlines.empty ()) {
split_to_blob(NULL, blob_box.right(), textord_fp_chop_error + 0.5,
&left_coutlines, &right_coutlines);
if (!left_coutlines.empty())
ru_it.add_after_then_move(new BLOBNBOX(new C_BLOB(&left_coutlines)));
}
if (u_line != NULL) {
if (u_line->blob() != NULL)
delete u_line->blob();
if (u_line->cblob() != NULL)
delete u_line->cblob();
delete u_line;
}
}
if (!ru_it.empty ()) {
ru_it.move_to_first ();
for (ru_it.mark_cycle_pt (); !ru_it.cycled_list (); ru_it.forward ()) {
under_it.add_after_then_move (ru_it.extract ());
if (!ru_it.empty()) {
ru_it.move_to_first();
for (ru_it.mark_cycle_pt(); !ru_it.cycled_list(); ru_it.forward()) {
under_it.add_after_then_move(ru_it.extract());
}
}
}

View File

@ -607,11 +607,8 @@ WERD *make_real_word(BLOBNBOX_IT *box_it, //iterator
BOOL8 bol, //start of line
uinT8 blanks //no of blanks
) {
OUTLINE_IT out_it; // outlines
C_OUTLINE_IT cout_it;
PBLOB_LIST blobs; // blobs in word
C_BLOB_LIST cblobs;
PBLOB_IT blob_it = &blobs; // iterator
C_BLOB_IT cblob_it = &cblobs;
WERD *word; // new word
BLOBNBOX *bblob; // current blob
@ -620,13 +617,7 @@ WERD *make_real_word(BLOBNBOX_IT *box_it, //iterator
for (blobindex = 0; blobindex < blobcount; blobindex++) {
bblob = box_it->extract();
if (bblob->joined_to_prev()) {
if (bblob->blob() != NULL) {
out_it.set_to_list(blob_it.data()->out_list());
out_it.move_to_last();
out_it.add_list_after(bblob->blob()->out_list());
delete bblob->blob();
}
else if (bblob->cblob() != NULL) {
if (bblob->cblob() != NULL) {
cout_it.set_to_list(cblob_it.data()->out_list());
cout_it.move_to_last();
cout_it.add_list_after(bblob->cblob()->out_list());
@ -634,9 +625,7 @@ WERD *make_real_word(BLOBNBOX_IT *box_it, //iterator
}
}
else {
if (bblob->blob() != NULL)
blob_it.add_after_then_move(bblob->blob());
else if (bblob->cblob() != NULL)
if (bblob->cblob() != NULL)
cblob_it.add_after_then_move(bblob->cblob());
}
delete bblob;
@ -646,10 +635,7 @@ WERD *make_real_word(BLOBNBOX_IT *box_it, //iterator
if (blanks < 1)
blanks = 1;
if (blob_it.empty())
word = new WERD(&cblobs, blanks, NULL);
else
word = new WERD(&blobs, blanks, NULL);
word = new WERD(&cblobs, blanks, NULL);
if (bol)
word->set_flag(W_BOL, TRUE);