tesseract  4.00.00dev
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 159 of file bbgrid.h.

Constructor & Destructor Documentation

◆ BBGrid() [1/2]

template<class BBC , class BBC_CLIST , class BBC_C_IT >
tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::BBGrid ( )

Definition at line 429 of file bbgrid.h.

429  : grid_(NULL) {
430 }
BBC_CLIST * grid_
Definition: bbgrid.h:222

◆ BBGrid() [2/2]

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

435  : grid_(NULL) {
436  Init(gridsize, bleft, tright);
437 }
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.h:448
int gridsize() const
Definition: bbgrid.h:64
BBC_CLIST * grid_
Definition: bbgrid.h:222

◆ ~BBGrid()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::~BBGrid ( )
virtual

Definition at line 440 of file bbgrid.h.

440  {
441  if (grid_ != NULL)
442  delete [] grid_;
443 }
BBC_CLIST * grid_
Definition: bbgrid.h:222

Member Function Documentation

◆ AssertNoDuplicates()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::AssertNoDuplicates ( )

Definition at line 642 of file bbgrid.h.

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

◆ Clear()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::Clear ( )

Definition at line 459 of file bbgrid.h.

459  {
460  for (int i = 0; i < gridbuckets_; ++i) {
461  grid_[i].shallow_clear();
462  }
463 }
BBC_CLIST * grid_
Definition: bbgrid.h:222

◆ ClearGridData()

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

469  {
470  if (grid_ == NULL) return;
472  search.StartFullSearch();
473  BBC* bb;
474  BBC_CLIST bb_list;
475  BBC_C_IT it(&bb_list);
476  while ((bb = search.NextFullSearch()) != NULL) {
477  it.add_after_then_move(bb);
478  }
479  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
480  free_method(it.data());
481  }
482 }
friend class GridSearch< BBC, BBC_CLIST, BBC_C_IT >
Definition: bbgrid.h:161
LIST search(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:406
BBC_CLIST * grid_
Definition: bbgrid.h:222

◆ CountCellElements()

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

Definition at line 565 of file bbgrid.h.

565  {
566  IntGrid* intgrid = new IntGrid(gridsize(), bleft(), tright());
567  for (int y = 0; y < gridheight(); ++y) {
568  for (int x = 0; x < gridwidth(); ++x) {
569  int cell_count = grid_[y * gridwidth() + x].length();
570  intgrid->SetGridCell(x, y, cell_count);
571  }
572  }
573  return intgrid;
574 }
const ICOORD & bleft() const
Definition: bbgrid.h:73
int gridsize() const
Definition: bbgrid.h:64
int gridheight() const
Definition: bbgrid.h:70
int gridwidth() const
Definition: bbgrid.h:67
const ICOORD & tright() const
Definition: bbgrid.h:76
BBC_CLIST * grid_
Definition: bbgrid.h:222

◆ DisplayBoxes()

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

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

◆ HandleClick()

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

659  {
660  tprintf("Click at (%d, %d)\n", x, y);
661 }
#define tprintf(...)
Definition: tprintf.h:31

◆ Init()

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

450  {
451  GridBase::Init(gridsize, bleft, tright);
452  if (grid_ != NULL)
453  delete [] grid_;
454  grid_ = new BBC_CLIST[gridbuckets_];
455 }
int gridsize() const
Definition: bbgrid.h:64
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.cpp:42
BBC_CLIST * grid_
Definition: bbgrid.h:222

◆ InsertBBox()

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

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

◆ InsertPixPtBBox()

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

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

◆ MakeWindow()

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

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

◆ RectangleEmpty()

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

556  {
558  rsearch.StartRectSearch(rect);
559  return rsearch.NextRectSearch() == NULL;
560 }
friend class GridSearch< BBC, BBC_CLIST, BBC_C_IT >
Definition: bbgrid.h:161

◆ RemoveBBox()

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

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

Friends And Related Function Documentation

◆ GridSearch< BBC, BBC_CLIST, BBC_C_IT >

template<class BBC, class BBC_CLIST, class BBC_C_IT>
friend class GridSearch< BBC, BBC_CLIST, BBC_C_IT >
friend

Definition at line 161 of file bbgrid.h.

Member Data Documentation

◆ grid_

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


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