Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Attributes | Friends
tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT > Class Template Reference

`#include <bbgrid.h>`

Inheritance diagram for tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >:

List of all members.

## 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)
Public Member Functions inherited from tesseract::GridBase
| GridBase ()
| GridBase (int gridsize, const ICOORD &bleft, const ICOORD &tright)
virtual | ~GridBase ()
int | gridsize () const
int | gridwidth () const
int | gridheight () const
const ICOORD & | bleft () const
const ICOORD & | tright () const
void | GridCoords (int x, int y, int *grid_x, int *grid_y) const
void | ClipGridCoords (int *x, int *y) const

## Protected Attributes

BBC_CLIST * | grid_
Protected Attributes inherited from tesseract::GridBase
int | gridsize_
int | gridwidth_
int | gridheight_
int | gridbuckets_
ICOORD | bleft_
ICOORD | tright_

## Friends

class | GridSearch< BBC, BBC_CLIST, BBC_C_IT >

## Detailed Description

### template<class BBC, class BBC_CLIST, class BBC_C_IT>
class tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >

Definition at line 163 of file bbgrid.h.

## Constructor & Destructor Documentation

template<class BBC , class BBC_CLIST , class BBC_C_IT >

tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::BBGrid | ( |  | ) |

Definition at line 425 of file bbgrid.h.

: grid_(NULL) {
}
template<class BBC , class BBC_CLIST , class BBC_C_IT >

tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::BBGrid | ( | int | gridsize,
|  | const ICOORD & | bleft,
|  | const ICOORD & | tright
| ) |  |

Definition at line 429 of file bbgrid.h.

: grid_(NULL) {
Init(gridsize, bleft, tright);
}
template<class BBC , class BBC_CLIST , class BBC_C_IT >

tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::~BBGrid | ( |  | ) |

virtual

Definition at line 436 of file bbgrid.h.

{
if (grid_ != NULL)
delete [] grid_;
}

## Member Function Documentation

template<class BBC , class BBC_CLIST , class BBC_C_IT >

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);
}
}
}
}
template<class BBC , class BBC_CLIST , class BBC_C_IT >

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();
}
}
template<class BBC, class BBC_CLIST , class BBC_C_IT >

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());
}
}
template<class BBC , class BBC_CLIST , class BBC_C_IT >

IntGrid * tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::CountCellElements | ( |  | ) |

Definition at line 561 of file bbgrid.h.

{
IntGrid* intgrid = new IntGrid(gridsize(), bleft(), tright());
for (int y = 0; y < gridheight(); ++y) {
for (int x = 0; x < gridwidth(); ++x) {
int cell_count = grid_[y * gridwidth() + x].length();
intgrid->SetGridCell(x, y, cell_count);
}
}
return intgrid;
}
template<class BBC , class BBC_CLIST , class BBC_C_IT >

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
}
template<class BBC , class BBC_CLIST , class BBC_C_IT >

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);
}
template<class BBC , class BBC_CLIST , class BBC_C_IT >

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_];
}
template<class BBC, class BBC_CLIST , class BBC_C_IT >

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);
}
}
}
template<class BBC, class BBC_CLIST , class BBC_C_IT >

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);
}
}
}
}
template<class BBC , class BBC_CLIST , class BBC_C_IT >

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;
}
template<class BBC , class BBC_CLIST , class BBC_C_IT >

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;
}
template<class BBC, class BBC_CLIST , class BBC_C_IT >

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();
}
}
}
}

## Friends And Related Function Documentation

template<class BBC, class BBC_CLIST, class BBC_C_IT>

friend class GridSearch< BBC, BBC_CLIST, BBC_C_IT >

friend

Definition at line 165 of file bbgrid.h.

## Member Data Documentation

template<class BBC, class BBC_CLIST, class BBC_C_IT>

BBC_CLIST* tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::grid_

protected

Definition at line 226 of file bbgrid.h.

The documentation for this class was generated from the following file:

- /mnt/data/src/tesseract-ocr/textord/bbgrid.h