本文整理汇总了C++中TBOX::y_overlap方法的典型用法代码示例。如果您正苦于以下问题:C++ TBOX::y_overlap方法的具体用法?C++ TBOX::y_overlap怎么用?C++ TBOX::y_overlap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBOX
的用法示例。
在下文中一共展示了TBOX::y_overlap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindAlignedBlob
// Search vertically for a blob that is aligned with the input bbox.
// The search parameters are determined by AlignedBlobParams.
// top_to_bottom tells whether to search down or up.
// The return value is nullptr if nothing was found in the search box
// or if a blob was found in the gutter. On a nullptr return, end_y
// is set to the edge of the search box or the leading edge of the
// gutter blob if one was found.
BLOBNBOX* AlignedBlob::FindAlignedBlob(const AlignedBlobParams& p,
bool top_to_bottom, BLOBNBOX* bbox,
int x_start, int* end_y) {
TBOX box = bbox->bounding_box();
// If there are separator lines, get the column edges.
int left_column_edge = bbox->left_rule();
int right_column_edge = bbox->right_rule();
// start_y is used to guarantee that forward progress is made and the
// search does not go into an infinite loop. New blobs must extend the
// line beyond start_y.
int start_y = top_to_bottom ? box.bottom() : box.top();
if (WithinTestRegion(2, x_start, start_y)) {
tprintf("Column edges for blob at (%d,%d)->(%d,%d) are [%d, %d]\n",
box.left(), box.top(), box.right(), box.bottom(),
left_column_edge, right_column_edge);
}
// Compute skew tolerance.
int skew_tolerance = p.max_v_gap / kMaxSkewFactor;
// Calculate xmin and xmax of the search box so that it contains
// all possibly relevant boxes up to p.max_v_gap above or below accoording
// to top_to_bottom.
// Start with a notion of vertical with the current estimate.
int x2 = (p.max_v_gap * p.vertical.x() + p.vertical.y()/2) / p.vertical.y();
if (top_to_bottom) {
x2 = x_start - x2;
*end_y = start_y - p.max_v_gap;
} else {
x2 = x_start + x2;
*end_y = start_y + p.max_v_gap;
}
// Expand the box by an additional skew tolerance
int xmin = std::min(x_start, x2) - skew_tolerance;
int xmax = std::max(x_start, x2) + skew_tolerance;
// Now add direction-specific tolerances.
if (p.right_tab) {
xmax += p.min_gutter;
xmin -= p.l_align_tolerance;
} else {
xmax += p.r_align_tolerance;
xmin -= p.min_gutter;
}
// Setup a vertical search for an aligned blob.
GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> 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, p.max_v_gap, p.min_gutter);
vsearch.StartVerticalSearch(xmin, xmax, start_y);
// result stores the best real return value.
BLOBNBOX* result = nullptr;
// The backup_result is not a tab candidate and can be used if no
// real tab candidate result is found.
BLOBNBOX* backup_result = nullptr;
// neighbour is the blob that is currently being investigated.
BLOBNBOX* neighbour = nullptr;
while ((neighbour = vsearch.NextVerticalSearch(top_to_bottom)) != nullptr) {
if (neighbour == bbox)
continue;
TBOX nbox = neighbour->bounding_box();
int n_y = (nbox.top() + nbox.bottom()) / 2;
if ((!top_to_bottom && n_y > start_y + p.max_v_gap) ||
(top_to_bottom && n_y < start_y - p.max_v_gap)) {
if (WithinTestRegion(2, x_start, start_y))
tprintf("Neighbour too far at (%d,%d)->(%d,%d)\n",
nbox.left(), nbox.bottom(), nbox.right(), nbox.top());
break; // Gone far enough.
}
// It is CRITICAL to ensure that forward progress is made, (strictly
// in/decreasing n_y) or the caller could loop infinitely, while
// waiting for a sequence of blobs in a line to end.
// NextVerticalSearch alone does not guarantee this, as there may be
// more than one blob in a grid cell. See comment in AlignTabs.
if ((n_y < start_y) != top_to_bottom || nbox.y_overlap(box))
continue; // Only look in the required direction.
if (result != nullptr && result->bounding_box().y_gap(nbox) > gridsize())
return result; // This result is clear.
if (backup_result != nullptr && p.ragged && result == nullptr &&
backup_result->bounding_box().y_gap(nbox) > gridsize())
return backup_result; // This result is clear.
// If the neighbouring blob is the wrong side of a separator line, then it
// "doesn't exist" as far as we are concerned.
int x_at_n_y = x_start + (n_y - start_y) * p.vertical.x() / p.vertical.y();
if (x_at_n_y < neighbour->left_crossing_rule() ||
x_at_n_y > neighbour->right_crossing_rule())
continue; // Separator line in the way.
int n_left = nbox.left();
int n_right = nbox.right();
int n_x = p.right_tab ? n_right : n_left;
if (WithinTestRegion(2, x_start, start_y))
tprintf("neighbour at (%d,%d)->(%d,%d), n_x=%d, n_y=%d, xatn=%d\n",
nbox.left(), nbox.bottom(), nbox.right(), nbox.top(),
n_x, n_y, x_at_n_y);
//.........这里部分代码省略.........