tesseract  5.0.0
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)
 
 ~BBGrid () override
 
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, Image 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 472 of file bbgrid.h.

472 : grid_(nullptr) {}
BBC_CLIST * grid_
Definition: bbgrid.h:226

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

476  : grid_(nullptr) {
478 }
int gridsize() const
Definition: bbgrid.h:63
const ICOORD & bleft() const
Definition: bbgrid.h:72
const ICOORD & tright() const
Definition: bbgrid.h:75
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.h:488

◆ ~BBGrid()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
tesseract::BBGrid< BBC, BBC_CLIST, BBC_C_IT >::~BBGrid
override

Definition at line 481 of file bbgrid.h.

481  {
482  delete[] grid_;
483 }

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

674  {
675  // Process all grid cells.
676  for (int i = gridwidth_ * gridheight_ - 1; i >= 0; --i) {
677  // Iterate over all elements excent the last.
678  for (BBC_C_IT it(&grid_[i]); !it.at_last(); it.forward()) {
679  BBC *ptr = it.data();
680  BBC_C_IT it2(it);
681  // None of the rest of the elements in the list should equal ptr.
682  for (it2.forward(); !it2.at_first(); it2.forward()) {
683  ASSERT_HOST(it2.data() != ptr);
684  }
685  }
686  }
687 }
#define ASSERT_HOST(x)
Definition: errcode.h:59

◆ Clear()

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

Definition at line 497 of file bbgrid.h.

497  {
498  for (int i = 0; i < gridbuckets_; ++i) {
499  grid_[i].shallow_clear();
500  }
501 }

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

506  {
507  if (grid_ == nullptr) {
508  return;
509  }
511  search.StartFullSearch();
512  BBC *bb;
513  BBC_CLIST bb_list;
514  BBC_C_IT it(&bb_list);
515  while ((bb = search.NextFullSearch()) != nullptr) {
516  it.add_after_then_move(bb);
517  }
518  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
519  free_method(it.data());
520  }
521 }
LIST search(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:211
friend class GridSearch< BBC, BBC_CLIST, BBC_C_IT >
Definition: bbgrid.h:160

◆ CountCellElements()

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

Definition at line 604 of file bbgrid.h.

604  {
605  auto *intgrid = new IntGrid(gridsize(), bleft(), tright());
606  for (int y = 0; y < gridheight(); ++y) {
607  for (int x = 0; x < gridwidth(); ++x) {
608  int cell_count = grid_[y * gridwidth() + x].length();
609  intgrid->SetGridCell(x, y, cell_count);
610  }
611  }
612  return intgrid;
613 }
int gridheight() const
Definition: bbgrid.h:69
int gridwidth() const
Definition: bbgrid.h:66

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

649  {
650  tab_win->Pen(ScrollView::BLUE);
651  tab_win->Brush(ScrollView::NONE);
652 
653  // For every bbox in the grid, display it.
655  gsearch.StartFullSearch();
656  BBC *bbox;
657  while ((bbox = gsearch.NextFullSearch()) != nullptr) {
658  const TBOX &box = bbox->bounding_box();
659  int left_x = box.left();
660  int right_x = box.right();
661  int top_y = box.top();
662  int bottom_y = box.bottom();
663  ScrollView::Color box_color = bbox->BoxColor();
664  tab_win->Pen(box_color);
665  tab_win->Rectangle(left_x, bottom_y, right_x, top_y);
666  }
667  tab_win->Update();
668 }
@ TBOX

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

691  {
692  tprintf("Click at (%d, %d)\n", x, y);
693 }
void tprintf(const char *format,...)
Definition: tprintf.cpp:41

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

489  {
491  delete[] grid_;
492  grid_ = new BBC_CLIST[gridbuckets_];
493 }
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
Definition: bbgrid.cpp:40

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

529  {
530  TBOX box = bbox->bounding_box();
531  int start_x, start_y, end_x, end_y;
532  GridCoords(box.left(), box.bottom(), &start_x, &start_y);
533  GridCoords(box.right(), box.top(), &end_x, &end_y);
534  if (!h_spread) {
535  end_x = start_x;
536  }
537  if (!v_spread) {
538  end_y = start_y;
539  }
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  grid_[grid_index + x].add_sorted(SortByBoxLeft<BBC>, true, bbox);
544  }
545  }
546 }
void GridCoords(int x, int y, int *grid_x, int *grid_y) const
Definition: bbgrid.cpp:53

◆ 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,
Image  pix,
BBC *  bbox 
)

Definition at line 558 of file bbgrid.h.

558  {
559  int width = pixGetWidth(pix);
560  int height = pixGetHeight(pix);
561  for (int y = 0; y < height; ++y) {
562  l_uint32 *data = pixGetData(pix) + y * pixGetWpl(pix);
563  for (int x = 0; x < width; ++x) {
564  if (GET_DATA_BIT(data, x)) {
565  grid_[(bottom + y) * gridwidth_ + x + left].add_sorted(SortByBoxLeft<BBC>, true, bbox);
566  }
567  }
568  }
569 }

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

633  {
634  auto tab_win =
635  new ScrollView(window_name, x, y, tright_.x() - bleft_.x(), tright_.y() - bleft_.y(),
636  tright_.x() - bleft_.x(), tright_.y() - bleft_.y(), true);
637  auto *handler = new TabEventHandler<BBGrid<BBC, BBC_CLIST, BBC_C_IT>>(this);
638  tab_win->AddEventHandler(handler);
639  tab_win->Pen(ScrollView::GREY);
640  tab_win->Rectangle(0, 0, tright_.x() - bleft_.x(), tright_.y() - bleft_.y());
641  return tab_win;
642 }
TDimension y() const
access_function
Definition: points.h:62
TDimension x() const
access function
Definition: points.h:58
ICOORD tright_
Definition: bbgrid.h:91

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

595  {
597  rsearch.StartRectSearch(rect);
598  return rsearch.NextRectSearch() == nullptr;
599 }

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

575  {
576  TBOX box = bbox->bounding_box();
577  int start_x, start_y, end_x, end_y;
578  GridCoords(box.left(), box.bottom(), &start_x, &start_y);
579  GridCoords(box.right(), box.top(), &end_x, &end_y);
580  int grid_index = start_y * gridwidth_;
581  for (int y = start_y; y <= end_y; ++y, grid_index += gridwidth_) {
582  for (int x = start_x; x <= end_x; ++x) {
583  BBC_C_IT it(&grid_[grid_index + x]);
584  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
585  if (it.data() == bbox) {
586  it.extract();
587  }
588  }
589  }
590  }
591 }

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


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