Tesseract
3.02
|
#include <bbgrid.h>
Public Member Functions | |
BBGrid () | |
BBGrid (int gridsize, const ICOORD &bleft, const ICOORD &tright) | |
virtual | ~BBGrid () |
void | Init (int gridsize, const ICOORD &bleft, const ICOORD &tright) |
void | Clear () |
void | ClearGridData (void(*free_method)(BBC *)) |
void | InsertBBox (bool h_spread, bool v_spread, BBC *bbox) |
void | InsertPixPtBBox (int left, int bottom, Pix *pix, BBC *bbox) |
void | RemoveBBox (BBC *bbox) |
bool | RectangleEmpty (const TBOX &rect) |
IntGrid * | CountCellElements () |
ScrollView * | MakeWindow (int x, int y, const char *window_name) |
void | DisplayBoxes (ScrollView *window) |
void | AssertNoDuplicates () |
virtual void | HandleClick (int x, int y) |
Protected Attributes | |
BBC_CLIST * | grid_ |
Friends | |
class | GridSearch< BBC, BBC_CLIST, BBC_C_IT > |
tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::BBGrid | ( | ) |
tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::BBGrid | ( | int | gridsize, |
const ICOORD & | bleft, | ||
const ICOORD & | tright | ||
) |
tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::~BBGrid | ( | ) | [virtual] |
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::AssertNoDuplicates | ( | ) |
Definition at line 638 of file bbgrid.h.
{ // Process all grid cells. for (int i = gridwidth_ * gridheight_ - 1; i >= 0; --i) { // Iterate over all elements excent the last. for (BBC_C_IT it(&grid_[i]); !it.at_last(); it.forward()) { BBC* ptr = it.data(); BBC_C_IT it2(it); // None of the rest of the elements in the list should equal ptr. for (it2.forward(); !it2.at_first(); it2.forward()) { ASSERT_HOST(it2.data() != ptr); } } } }
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::Clear | ( | ) |
Definition at line 455 of file bbgrid.h.
{ for (int i = 0; i < gridbuckets_; ++i) { grid_[i].shallow_clear(); } }
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::ClearGridData | ( | void(*)(BBC *) | free_method | ) |
Definition at line 464 of file bbgrid.h.
{ if (grid_ == NULL) return; GridSearch<BBC, BBC_CLIST, BBC_C_IT> search(this); search.StartFullSearch(); BBC* bb; BBC_CLIST bb_list; BBC_C_IT it(&bb_list); while ((bb = search.NextFullSearch()) != NULL) { it.add_after_then_move(bb); } for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) { free_method(it.data()); } }
IntGrid * tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::CountCellElements | ( | ) |
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::DisplayBoxes | ( | ScrollView * | window | ) |
Definition at line 613 of file bbgrid.h.
{ #ifndef GRAPHICS_DISABLED tab_win->Pen(ScrollView::BLUE); tab_win->Brush(ScrollView::NONE); // For every bbox in the grid, display it. GridSearch<BBC, BBC_CLIST, BBC_C_IT> gsearch(this); gsearch.StartFullSearch(); BBC* bbox; while ((bbox = gsearch.NextFullSearch()) != NULL) { TBOX box = bbox->bounding_box(); int left_x = box.left(); int right_x = box.right(); int top_y = box.top(); int bottom_y = box.bottom(); ScrollView::Color box_color = bbox->BoxColor(); tab_win->Pen(box_color); tab_win->Rectangle(left_x, bottom_y, right_x, top_y); } tab_win->Update(); #endif }
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::HandleClick | ( | int | x, |
int | y | ||
) | [virtual] |
Reimplemented in tesseract::StrokeWidth, and tesseract::ColPartitionGrid.
Definition at line 655 of file bbgrid.h.
{ tprintf("Click at (%d, %d)\n", x, y); }
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::Init | ( | int | gridsize, |
const ICOORD & | bleft, | ||
const ICOORD & | tright | ||
) |
Reimplemented from tesseract::GridBase.
Definition at line 444 of file bbgrid.h.
{ GridBase::Init(gridsize, bleft, tright); if (grid_ != NULL) delete [] grid_; grid_ = new BBC_CLIST[gridbuckets_]; }
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::InsertBBox | ( | bool | h_spread, |
bool | v_spread, | ||
BBC * | bbox | ||
) |
Definition at line 486 of file bbgrid.h.
{ TBOX box = bbox->bounding_box(); int start_x, start_y, end_x, end_y; GridCoords(box.left(), box.bottom(), &start_x, &start_y); GridCoords(box.right(), box.top(), &end_x, &end_y); if (!h_spread) end_x = start_x; if (!v_spread) end_y = start_y; int grid_index = start_y * gridwidth_; for (int y = start_y; y <= end_y; ++y, grid_index += gridwidth_) { for (int x = start_x; x <= end_x; ++x) { grid_[grid_index + x].add_sorted(SortByBoxLeft<BBC>, true, bbox); } } }
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::InsertPixPtBBox | ( | int | left, |
int | bottom, | ||
Pix * | pix, | ||
BBC * | bbox | ||
) |
Definition at line 514 of file bbgrid.h.
{ int width = pixGetWidth(pix); int height = pixGetHeight(pix); for (int y = 0; y < height; ++y) { l_uint32* data = pixGetData(pix) + y * pixGetWpl(pix); for (int x = 0; x < width; ++x) { if (GET_DATA_BIT(data, x)) { grid_[(bottom + y) * gridwidth_ + x + left]. add_sorted(SortByBoxLeft<BBC>, true, bbox); } } } }
ScrollView * tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::MakeWindow | ( | int | x, |
int | y, | ||
const char * | window_name | ||
) |
Definition at line 589 of file bbgrid.h.
{ ScrollView* tab_win = NULL; #ifndef GRAPHICS_DISABLED tab_win = new ScrollView(window_name, x, y, tright_.x() - bleft_.x(), tright_.y() - bleft_.y(), tright_.x() - bleft_.x(), tright_.y() - bleft_.y(), true); TabEventHandler<BBGrid<BBC, BBC_CLIST, BBC_C_IT> >* handler = new TabEventHandler<BBGrid<BBC, BBC_CLIST, BBC_C_IT> >(this); tab_win->AddEventHandler(handler); tab_win->Pen(ScrollView::GREY); tab_win->Rectangle(0, 0, tright_.x() - bleft_.x(), tright_.y() - bleft_.y()); #endif return tab_win; }
bool tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::RectangleEmpty | ( | const TBOX & | rect | ) |
Definition at line 552 of file bbgrid.h.
{ GridSearch<BBC, BBC_CLIST, BBC_C_IT> rsearch(this); rsearch.StartRectSearch(rect); return rsearch.NextRectSearch() == NULL; }
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::RemoveBBox | ( | BBC * | bbox | ) |
Definition at line 533 of file bbgrid.h.
{ TBOX box = bbox->bounding_box(); int start_x, start_y, end_x, end_y; GridCoords(box.left(), box.bottom(), &start_x, &start_y); GridCoords(box.right(), box.top(), &end_x, &end_y); int grid_index = start_y * gridwidth_; for (int y = start_y; y <= end_y; ++y, grid_index += gridwidth_) { for (int x = start_x; x <= end_x; ++x) { BBC_C_IT it(&grid_[grid_index + x]); for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) { if (it.data() == bbox) it.extract(); } } } }
friend class GridSearch< BBC, BBC_CLIST, BBC_C_IT > [friend] |
BBC_CLIST* tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::grid_ [protected] |