tesseract  4.0.0-1-g2a2b
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 ()=default
 
 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_(nullptr) {
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_(nullptr) {
437 }
int gridsize() const
Definition: bbgrid.h:64
const ICOORD & bleft() const
Definition: bbgrid.h:73
BBC_CLIST * grid_
Definition: bbgrid.h:222
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.h:447
const ICOORD & tright() const
Definition: bbgrid.h:76

◆ ~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  delete [] grid_;
442 }
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 640 of file bbgrid.h.

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

◆ Clear()

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

Definition at line 457 of file bbgrid.h.

457  {
458  for (int i = 0; i < gridbuckets_; ++i) {
459  grid_[i].shallow_clear();
460  }
461 }
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 466 of file bbgrid.h.

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

◆ CountCellElements()

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

Definition at line 563 of file bbgrid.h.

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

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

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

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

657  {
658  tprintf("Click at (%d, %d)\n", x, y);
659 }
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

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

449  {
451  delete [] grid_;
452  grid_ = new BBC_CLIST[gridbuckets_];
453 }
int gridsize() const
Definition: bbgrid.h:64
const ICOORD & bleft() const
Definition: bbgrid.h:73
BBC_CLIST * grid_
Definition: bbgrid.h:222
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.cpp:41
const ICOORD & tright() const
Definition: bbgrid.h:76

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

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

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

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

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

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

554  {
556  rsearch.StartRectSearch(rect);
557  return rsearch.NextRectSearch() == nullptr;
558 }
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 535 of file bbgrid.h.

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

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: