Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few refactors in some files #4225

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/ccmain/paragraphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,7 +2610,6 @@ void DetectParagraphs(int debug_level, bool after_text_recognition,

// Run the paragraph detection algorithm.
std::vector<PARA *> row_owners;
std::vector<PARA *> the_paragraphs;
if (!is_image_block) {
DetectParagraphs(debug_level, &row_infos, &row_owners, block->para_list(), models);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/stepblob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const double kMaxPerimeterWidthRatio = 8.0;
**********************************************************************/
static void position_outline( // put in place
C_OUTLINE *outline, // thing to place
C_OUTLINE_LIST *destlist // desstination list
C_OUTLINE_LIST *destlist // destination list
) {
C_OUTLINE_IT it = destlist; // iterator
// iterator on children
Expand Down
4 changes: 2 additions & 2 deletions src/textord/alignedblob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ ScrollView *AlignedBlob::DisplayTabs(const char *window_name, ScrollView *tab_wi
tab_win = MakeWindow(0, 50, window_name);
}
// For every tab in the grid, display it.
GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> gsearch(this);
BlobGridSearch gsearch(this);
gsearch.StartFullSearch();
BLOBNBOX *bbox;
while ((bbox = gsearch.NextFullSearch()) != nullptr) {
Expand Down Expand Up @@ -409,7 +409,7 @@ BLOBNBOX *AlignedBlob::FindAlignedBlob(const AlignedBlobParams &p, bool top_to_b
xmin -= p.min_gutter;
}
// Setup a vertical search for an aligned blob.
GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> vsearch(this);
BlobGridSearch vsearch(this);
if (WithinTestRegion(2, x_start, start_y)) {
tprintf("Starting %s %s search at %d-%d,%d, search_size=%d, gutter=%d\n",
p.ragged ? "Ragged" : "Aligned", p.right_tab ? "Right" : "Left", xmin, xmax, start_y,
Expand Down
6 changes: 3 additions & 3 deletions src/textord/colfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ ColumnFinder::~ColumnFinder() {
}

// Performs initial processing on the blobs in the input_block:
// Setup the part_grid, stroke_width_, nontext_map.
// Setup the part_grid_, stroke_width_, nontext_map.
// Obvious noise blobs are filtered out and used to mark the nontext_map_.
// Initial stroke-width analysis is used to get local text alignment
// direction, so the textline projection_ map can be setup.
Expand Down Expand Up @@ -971,7 +971,7 @@ void ColumnFinder::ReleaseBlobsAndCleanupUnused(TO_BLOCK *block) {
// Splits partitions that cross columns where they have nothing in the gap.
void ColumnFinder::GridSplitPartitions() {
// Iterate the ColPartitions in the grid.
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> gsearch(&part_grid_);
ColPartitionGridSearch gsearch(&part_grid_);
gsearch.StartFullSearch();
ColPartition *dont_repeat = nullptr;
ColPartition *part;
Expand Down Expand Up @@ -1438,7 +1438,7 @@ void ColumnFinder::TransformToBlocks(BLOCK_LIST *blocks, TO_BLOCK_LIST *to_block
// like horizontal lines going before the text lines above them.
ColPartition_CLIST temp_part_list;
// Iterate the ColPartitions in the grid. It starts at the top
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> gsearch(&part_grid_);
ColPartitionGridSearch gsearch(&part_grid_);
gsearch.StartFullSearch();
int prev_grid_y = -1;
ColPartition *part;
Expand Down
4 changes: 2 additions & 2 deletions src/textord/makerow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2485,8 +2485,8 @@ OVERLAP_STATE most_overlapping_row( // find best row
row_it->forward();
test_row = row_it->data();
if (test_row->min_y() <= top && test_row->max_y() >= bottom) {
merge_top = test_row->max_y() > row->max_y() ? test_row->max_y() : row->max_y();
merge_bottom = test_row->min_y() < row->min_y() ? test_row->min_y() : row->min_y();
merge_top = std::max(test_row->max_y(),row->max_y());
merge_bottom = std::min(test_row->min_y(),row->min_y());
if (merge_top - merge_bottom <= rowsize) {
if (testing_blob && textord_debug_blob) {
tprintf("Merging rows at (%g,%g), (%g,%g)\n", row->min_y(), row->max_y(),
Expand Down
2 changes: 1 addition & 1 deletion src/textord/strokewidth.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class StrokeWidth : public BlobGrid {
// Corrects the data structures for the given rotation.
void CorrectForRotation(const FCOORD &rerotation, ColPartitionGrid *part_grid);

// Finds leader partitions and inserts them into the give grid.
// Finds leader partitions and inserts them into the given grid.
void FindLeaderPartitions(TO_BLOCK *block, ColPartitionGrid *part_grid);

// Finds and marks noise those blobs that look like bits of vertical lines
Expand Down
2 changes: 1 addition & 1 deletion src/textord/tabfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ ScrollView *TabFind::FindTabBoxes(int min_gutter_width, double tabfind_aligned_g
left_tab_boxes_.clear();
right_tab_boxes_.clear();
// For every bbox in the grid, determine whether it uses a tab on an edge.
GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> gsearch(this);
BlobGridSearch gsearch(this);
gsearch.StartFullSearch();
BLOBNBOX *bbox;
while ((bbox = gsearch.NextFullSearch()) != nullptr) {
Expand Down
30 changes: 11 additions & 19 deletions src/textord/tablefind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,7 @@ void TableFinder::SetVerticalSpacing(ColPartition *part) {

TBOX part_box = part->bounding_box();
// Start a rect search
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> rectsearch(
&clean_part_grid_);
ColPartitionGridSearch rectsearch(&clean_part_grid_);
rectsearch.StartRectSearch(box);
ColPartition *neighbor;
int min_space_above = kMaxVerticalSpacing;
Expand Down Expand Up @@ -843,8 +842,7 @@ void TableFinder::MarkTablePartitions() {
// 4- Partitions with leaders before/after them.
void TableFinder::MarkPartitionsUsingLocalInformation() {
// Iterate the ColPartitions in the grid.
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> gsearch(
&clean_part_grid_);
ColPartitionGridSearch gsearch(&clean_part_grid_);
gsearch.StartFullSearch();
ColPartition *part = nullptr;
while ((part = gsearch.NextFullSearch()) != nullptr) {
Expand Down Expand Up @@ -1190,8 +1188,7 @@ void TableFinder::SetColumnsType(ColSegment_LIST *column_blocks) {
TBOX box = seg->bounding_box();
int num_table_cells = 0;
int num_text_cells = 0;
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> rsearch(
&clean_part_grid_);
ColPartitionGridSearch rsearch(&clean_part_grid_);
rsearch.SetUniqueMode(true);
rsearch.StartRectSearch(box);
ColPartition *part = nullptr;
Expand Down Expand Up @@ -1320,8 +1317,7 @@ void TableFinder::GridMergeColumnBlocks() {
void TableFinder::GetTableColumns(ColSegment_LIST *table_columns) {
ColSegment_IT it(table_columns);
// Iterate the ColPartitions in the grid.
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> gsearch(
&clean_part_grid_);
ColPartitionGridSearch gsearch(&clean_part_grid_);
gsearch.StartFullSearch();
ColPartition *part;
while ((part = gsearch.NextFullSearch()) != nullptr) {
Expand All @@ -1335,8 +1331,7 @@ void TableFinder::GetTableColumns(ColSegment_LIST *table_columns) {
// Start a search below the current cell to find bottom neighbours
// Note: a full search will always process things above it first, so
// this should be starting at the highest cell and working its way down.
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> vsearch(
&clean_part_grid_);
ColPartitionGridSearch vsearch(&clean_part_grid_);
vsearch.StartVerticalSearch(box.left(), box.right(), box.bottom());
ColPartition *neighbor = nullptr;
bool found_neighbours = false;
Expand Down Expand Up @@ -1503,8 +1498,7 @@ bool TableFinder::BelongToOneTable(const TBOX &box1, const TBOX &box2) {
// Check for ColPartitions spanning both table regions
TBOX bbox = box1.bounding_union(box2);
// Start a rect search on bbox
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> rectsearch(
&clean_part_grid_);
ColPartitionGridSearch rectsearch(&clean_part_grid_);
rectsearch.StartRectSearch(bbox);
ColPartition *part = nullptr;
while ((part = rectsearch.NextRectSearch()) != nullptr) {
Expand Down Expand Up @@ -1783,8 +1777,7 @@ void TableFinder::DeleteSingleColumnTables() {
table_xprojection[i] = 0;
}
// Start a rect search on table_box
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> rectsearch(
&clean_part_grid_);
ColPartitionGridSearch rectsearch(&clean_part_grid_);
rectsearch.SetUniqueMode(true);
rectsearch.StartRectSearch(table_box);
ColPartition *part;
Expand Down Expand Up @@ -1972,7 +1965,7 @@ void TableFinder::DisplayColPartitions(ScrollView *win, ColPartitionGrid *grid,
ScrollView::Color table_color) {
ScrollView::Color color = default_color;
// Iterate the ColPartitions in the grid.
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> gsearch(grid);
ColPartitionGridSearch gsearch(grid);
gsearch.StartFullSearch();
ColPartition *part = nullptr;
while ((part = gsearch.NextFullSearch()) != nullptr) {
Expand Down Expand Up @@ -2002,7 +1995,7 @@ void TableFinder::DisplayColPartitionConnections(ScrollView *win,
ColPartitionGrid *grid,
ScrollView::Color color) {
// Iterate the ColPartitions in the grid.
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> gsearch(grid);
ColPartitionGridSearch gsearch(grid);
gsearch.StartFullSearch();
ColPartition *part = nullptr;
while ((part = gsearch.NextFullSearch()) != nullptr) {
Expand Down Expand Up @@ -2048,7 +2041,7 @@ void TableFinder::MakeTableBlocks(ColPartitionGrid *grid,
const WidthCallback &width_cb) {
// Since we have table blocks already, remove table tags from all
// colpartitions
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> gsearch(grid);
ColPartitionGridSearch gsearch(grid);
gsearch.StartFullSearch();
ColPartition *part = nullptr;

Expand All @@ -2066,8 +2059,7 @@ void TableFinder::MakeTableBlocks(ColPartitionGrid *grid,
while ((table = table_search.NextFullSearch()) != nullptr) {
const TBOX &table_box = table->bounding_box();
// Start a rect search on table_box
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT> rectsearch(
grid);
ColPartitionGridSearch rectsearch(grid);
rectsearch.StartRectSearch(table_box);
ColPartition *part;
ColPartition *table_partition = nullptr;
Expand Down
9 changes: 5 additions & 4 deletions src/textord/tordmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,17 @@ bool Textord::clean_noise_from_row( // remove empties
}
}
}
bool rejected = dot_count > norm_count * textord_noise_normratio && \
dot_count > 2 && \
super_norm_count < textord_noise_sncount;
sadra-barikbin marked this conversation as resolved.
Show resolved Hide resolved
if (textord_noise_debug) {
tprintf("Row ending at (%d,%g):", blob_box.right(), row->base_line(blob_box.right()));
tprintf(" R=%g, dc=%d, nc=%d, %s\n",
norm_count > 0 ? static_cast<float>(dot_count) / norm_count : 9999, dot_count,
norm_count,
dot_count > norm_count * textord_noise_normratio && dot_count > 2 ? "REJECTED"
: "ACCEPTED");
rejected? "REJECTED": "ACCEPTED");
sadra-barikbin marked this conversation as resolved.
Show resolved Hide resolved
}
return super_norm_count < textord_noise_sncount &&
dot_count > norm_count * textord_noise_rowratio && dot_count > 2;
return rejected;
sadra-barikbin marked this conversation as resolved.
Show resolved Hide resolved
}

/**********************************************************************
Expand Down
Loading