tesseract 4.1.1
Loading...
Searching...
No Matches
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, 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 158 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 427 of file bbgrid.h.

427 : grid_(nullptr) {
428}
BBC_CLIST * grid_
Definition: bbgrid.h:221

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

433 : grid_(nullptr) {
435}
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:445

◆ ~BBGrid()

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

Definition at line 438 of file bbgrid.h.

438 {
439 delete [] grid_;
440}

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

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

◆ Clear()

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.

455 {
456 for (int i = 0; i < gridbuckets_; ++i) {
457 grid_[i].shallow_clear();
458 }
459}

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

465 {
466 if (grid_ == nullptr) return;
468 search.StartFullSearch();
469 BBC* bb;
470 BBC_CLIST bb_list;
471 BBC_C_IT it(&bb_list);
472 while ((bb = search.NextFullSearch()) != nullptr) {
473 it.add_after_then_move(bb);
474 }
475 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
476 free_method(it.data());
477 }
478}
LIST search(LIST list, void *key, int_compare is_equal)
Definition: oldlist.cpp:258
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 561 of file bbgrid.h.

561 {
562 auto* intgrid = new IntGrid(gridsize(), bleft(), tright());
563 for (int y = 0; y < gridheight(); ++y) {
564 for (int x = 0; x < gridwidth(); ++x) {
565 int cell_count = grid_[y * gridwidth() + x].length();
566 intgrid->SetGridCell(x, y, cell_count);
567 }
568 }
569 return intgrid;
570}
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 613 of file bbgrid.h.

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

◆ 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::ColPartitionGrid, and tesseract::StrokeWidth.

Definition at line 655 of file bbgrid.h.

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

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

447 {
449 delete [] grid_;
450 grid_ = new BBC_CLIST[gridbuckets_];
451}
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 486 of file bbgrid.h.

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

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

515 {
516 int width = pixGetWidth(pix);
517 int height = pixGetHeight(pix);
518 for (int y = 0; y < height; ++y) {
519 l_uint32* data = pixGetData(pix) + y * pixGetWpl(pix);
520 for (int x = 0; x < width; ++x) {
521 if (GET_DATA_BIT(data, x)) {
522 grid_[(bottom + y) * gridwidth_ + x + left].
523 add_sorted(SortByBoxLeft<BBC>, true, bbox);
524 }
525 }
526 }
527}

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

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

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

552 {
554 rsearch.StartRectSearch(rect);
555 return rsearch.NextRectSearch() == nullptr;
556}

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

533 {
534 TBOX box = bbox->bounding_box();
535 int start_x, start_y, end_x, end_y;
536 GridCoords(box.left(), box.bottom(), &start_x, &start_y);
537 GridCoords(box.right(), box.top(), &end_x, &end_y);
538 int grid_index = start_y * gridwidth_;
539 for (int y = start_y; y <= end_y; ++y, grid_index += gridwidth_) {
540 for (int x = start_x; x <= end_x; ++x) {
541 BBC_C_IT it(&grid_[grid_index + x]);
542 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
543 if (it.data() == bbox)
544 it.extract();
545 }
546 }
547 }
548}

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


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