All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 >:
tesseract::GridBase

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)
 
IntGridCountCellElements ()
 
ScrollViewMakeWindow (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 ()
 
void Init (int gridsize, const ICOORD &bleft, const ICOORD &tright)
 
int gridsize () const
 
int gridwidth () const
 
int gridheight () const
 
const ICOORDbleft () const
 
const ICOORDtright () 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 158 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 428 of file bbgrid.h.

428  : grid_(NULL) {
429 }
BBC_CLIST * grid_
Definition: bbgrid.h:221
#define NULL
Definition: host.h:144
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 432 of file bbgrid.h.

434  : grid_(NULL) {
435  Init(gridsize, bleft, tright);
436 }
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.h:447
BBC_CLIST * grid_
Definition: bbgrid.h:221
int gridsize() const
Definition: bbgrid.h:63
#define NULL
Definition: host.h:144
template<class BBC , class BBC_CLIST , class BBC_C_IT >
tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::~BBGrid ( )
virtual

Definition at line 439 of file bbgrid.h.

439  {
440  if (grid_ != NULL)
441  delete [] grid_;
442 }
BBC_CLIST * grid_
Definition: bbgrid.h:221
#define NULL
Definition: host.h:144

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 641 of file bbgrid.h.

641  {
642  // Process all grid cells.
643  for (int i = gridwidth_ * gridheight_ - 1; i >= 0; --i) {
644  // Iterate over all elements excent the last.
645  for (BBC_C_IT it(&grid_[i]); !it.at_last(); it.forward()) {
646  BBC* ptr = it.data();
647  BBC_C_IT it2(it);
648  // None of the rest of the elements in the list should equal ptr.
649  for (it2.forward(); !it2.at_first(); it2.forward()) {
650  ASSERT_HOST(it2.data() != ptr);
651  }
652  }
653  }
654 }
BBC_CLIST * grid_
Definition: bbgrid.h:221
#define ASSERT_HOST(x)
Definition: errcode.h:84
template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::Clear ( )

Definition at line 458 of file bbgrid.h.

458  {
459  for (int i = 0; i < gridbuckets_; ++i) {
460  grid_[i].shallow_clear();
461  }
462 }
BBC_CLIST * grid_
Definition: bbgrid.h:221
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 467 of file bbgrid.h.

468  {
469  if (grid_ == NULL) return;
471  search.StartFullSearch();
472  BBC* bb;
473  BBC_CLIST bb_list;
474  BBC_C_IT it(&bb_list);
475  while ((bb = search.NextFullSearch()) != NULL) {
476  it.add_after_then_move(bb);
477  }
478  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
479  free_method(it.data());
480  }
481 }
BBC_CLIST * grid_
Definition: bbgrid.h:221
LIST search(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:413
#define NULL
Definition: host.h:144
friend class GridSearch< BBC, BBC_CLIST, BBC_C_IT >
Definition: bbgrid.h:160
template<class BBC , class BBC_CLIST , class BBC_C_IT >
IntGrid * tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::CountCellElements ( )

Definition at line 564 of file bbgrid.h.

564  {
565  IntGrid* intgrid = new IntGrid(gridsize(), bleft(), tright());
566  for (int y = 0; y < gridheight(); ++y) {
567  for (int x = 0; x < gridwidth(); ++x) {
568  int cell_count = grid_[y * gridwidth() + x].length();
569  intgrid->SetGridCell(x, y, cell_count);
570  }
571  }
572  return intgrid;
573 }
int gridheight() const
Definition: bbgrid.h:69
BBC_CLIST * grid_
Definition: bbgrid.h:221
int gridwidth() const
Definition: bbgrid.h:66
int gridsize() const
Definition: bbgrid.h:63
const ICOORD & bleft() const
Definition: bbgrid.h:72
const ICOORD & tright() const
Definition: bbgrid.h:75
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 616 of file bbgrid.h.

616  {
617 #ifndef GRAPHICS_DISABLED
618  tab_win->Pen(ScrollView::BLUE);
619  tab_win->Brush(ScrollView::NONE);
620 
621  // For every bbox in the grid, display it.
623  gsearch.StartFullSearch();
624  BBC* bbox;
625  while ((bbox = gsearch.NextFullSearch()) != NULL) {
626  TBOX box = bbox->bounding_box();
627  int left_x = box.left();
628  int right_x = box.right();
629  int top_y = box.top();
630  int bottom_y = box.bottom();
631  ScrollView::Color box_color = bbox->BoxColor();
632  tab_win->Pen(box_color);
633  tab_win->Rectangle(left_x, bottom_y, right_x, top_y);
634  }
635  tab_win->Update();
636 #endif
637 }
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
inT16 bottom() const
Definition: rect.h:61
Definition: rect.h:30
#define NULL
Definition: host.h:144
friend class GridSearch< BBC, BBC_CLIST, BBC_C_IT >
Definition: bbgrid.h:160
inT16 top() const
Definition: rect.h:54
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 658 of file bbgrid.h.

658  {
659  tprintf("Click at (%d, %d)\n", x, y);
660 }
#define tprintf(...)
Definition: tprintf.h:31
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 
)

Definition at line 447 of file bbgrid.h.

449  {
450  GridBase::Init(gridsize, bleft, tright);
451  if (grid_ != NULL)
452  delete [] grid_;
453  grid_ = new BBC_CLIST[gridbuckets_];
454 }
BBC_CLIST * grid_
Definition: bbgrid.h:221
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.cpp:42
int gridsize() const
Definition: bbgrid.h:63
#define NULL
Definition: host.h:144
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 489 of file bbgrid.h.

490  {
491  TBOX box = bbox->bounding_box();
492  int start_x, start_y, end_x, end_y;
493  GridCoords(box.left(), box.bottom(), &start_x, &start_y);
494  GridCoords(box.right(), box.top(), &end_x, &end_y);
495  if (!h_spread)
496  end_x = start_x;
497  if (!v_spread)
498  end_y = start_y;
499  int grid_index = start_y * gridwidth_;
500  for (int y = start_y; y <= end_y; ++y, grid_index += gridwidth_) {
501  for (int x = start_x; x <= end_x; ++x) {
502  grid_[grid_index + x].add_sorted(SortByBoxLeft<BBC>, true, bbox);
503  }
504  }
505 }
BBC_CLIST * grid_
Definition: bbgrid.h:221
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
inT16 bottom() const
Definition: rect.h:61
Definition: rect.h:30
inT16 top() const
Definition: rect.h:54
void GridCoords(int x, int y, int *grid_x, int *grid_y) const
Definition: bbgrid.cpp:54
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 517 of file bbgrid.h.

518  {
519  int width = pixGetWidth(pix);
520  int height = pixGetHeight(pix);
521  for (int y = 0; y < height; ++y) {
522  l_uint32* data = pixGetData(pix) + y * pixGetWpl(pix);
523  for (int x = 0; x < width; ++x) {
524  if (GET_DATA_BIT(data, x)) {
525  grid_[(bottom + y) * gridwidth_ + x + left].
526  add_sorted(SortByBoxLeft<BBC>, true, bbox);
527  }
528  }
529  }
530 }
BBC_CLIST * grid_
Definition: bbgrid.h:221
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 592 of file bbgrid.h.

593  {
594  ScrollView* tab_win = NULL;
595 #ifndef GRAPHICS_DISABLED
596  tab_win = new ScrollView(window_name, x, y,
597  tright_.x() - bleft_.x(),
598  tright_.y() - bleft_.y(),
599  tright_.x() - bleft_.x(),
600  tright_.y() - bleft_.y(),
601  true);
602  TabEventHandler<BBGrid<BBC, BBC_CLIST, BBC_C_IT> >* handler =
603  new TabEventHandler<BBGrid<BBC, BBC_CLIST, BBC_C_IT> >(this);
604  tab_win->AddEventHandler(handler);
605  tab_win->Pen(ScrollView::GREY);
606  tab_win->Rectangle(0, 0, tright_.x() - bleft_.x(), tright_.y() - bleft_.y());
607 #endif
608  return tab_win;
609 }
void Pen(Color color)
Definition: scrollview.cpp:726
void AddEventHandler(SVEventHandler *listener)
Add an Event Listener to this ScrollView Window.
Definition: scrollview.cpp:418
inT16 y() const
access_function
Definition: points.h:56
inT16 x() const
access function
Definition: points.h:52
void Rectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:606
#define NULL
Definition: host.h:144
ICOORD tright_
Definition: bbgrid.h:91
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 555 of file bbgrid.h.

555  {
557  rsearch.StartRectSearch(rect);
558  return rsearch.NextRectSearch() == NULL;
559 }
#define NULL
Definition: host.h:144
friend class GridSearch< BBC, BBC_CLIST, BBC_C_IT >
Definition: bbgrid.h:160
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 536 of file bbgrid.h.

536  {
537  TBOX box = bbox->bounding_box();
538  int start_x, start_y, end_x, end_y;
539  GridCoords(box.left(), box.bottom(), &start_x, &start_y);
540  GridCoords(box.right(), box.top(), &end_x, &end_y);
541  int grid_index = start_y * gridwidth_;
542  for (int y = start_y; y <= end_y; ++y, grid_index += gridwidth_) {
543  for (int x = start_x; x <= end_x; ++x) {
544  BBC_C_IT it(&grid_[grid_index + x]);
545  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
546  if (it.data() == bbox)
547  it.extract();
548  }
549  }
550  }
551 }
BBC_CLIST * grid_
Definition: bbgrid.h:221
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
inT16 bottom() const
Definition: rect.h:61
Definition: rect.h:30
inT16 top() const
Definition: rect.h:54
void GridCoords(int x, int y, int *grid_x, int *grid_y) const
Definition: bbgrid.cpp:54

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 160 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 221 of file bbgrid.h.


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