tesseract 4.1.1
Loading...
Searching...
No Matches
tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT > Class Template Reference

#include <bbgrid.h>

Public Member Functions

 GridSearch (BBGrid< BBC, BBC_CLIST, BBC_C_IT > *grid)
 
int GridX () const
 
int GridY () const
 
void SetUniqueMode (bool mode)
 
bool ReturnedSeedElement () const
 
void StartFullSearch ()
 
BBC * NextFullSearch ()
 
void StartRadSearch (int x, int y, int max_radius)
 
BBC * NextRadSearch ()
 
void StartSideSearch (int x, int ymin, int ymax)
 
BBC * NextSideSearch (bool right_to_left)
 
void StartVerticalSearch (int xmin, int xmax, int y)
 
BBC * NextVerticalSearch (bool top_to_bottom)
 
void StartRectSearch (const TBOX &rect)
 
BBC * NextRectSearch ()
 
void RemoveBBox ()
 
void RepositionIterator ()
 

Detailed Description

template<class BBC, class BBC_CLIST, class BBC_C_IT>
class tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >

Definition at line 235 of file bbgrid.h.

Constructor & Destructor Documentation

◆ GridSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::GridSearch ( BBGrid< BBC, BBC_CLIST, BBC_C_IT > *  grid)
inline

Definition at line 237 of file bbgrid.h.

238 : grid_(grid) {
239 }

Member Function Documentation

◆ GridX()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
int tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::GridX ( ) const
inline

Definition at line 242 of file bbgrid.h.

242 {
243 return x_;
244 }

◆ GridY()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
int tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::GridY ( ) const
inline

Definition at line 245 of file bbgrid.h.

245 {
246 return y_;
247 }

◆ NextFullSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
BBC * tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::NextFullSearch

Definition at line 675 of file bbgrid.h.

675 {
676 int x;
677 int y;
678 do {
679 while (it_.cycled_list()) {
680 ++x_;
681 if (x_ >= grid_->gridwidth_) {
682 --y_;
683 if (y_ < 0)
684 return CommonEnd();
685 x_ = 0;
686 }
687 SetIterator();
688 }
689 CommonNext();
690 TBOX box = previous_return_->bounding_box();
691 grid_->GridCoords(box.left(), box.bottom(), &x, &y);
692 } while (x != x_ || y != y_);
693 return previous_return_;
694}
Definition: rect.h:34
int16_t left() const
Definition: rect.h:72
int16_t bottom() const
Definition: rect.h:65

◆ NextRadSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
BBC * tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::NextRadSearch

Definition at line 713 of file bbgrid.h.

713 {
714 do {
715 while (it_.cycled_list()) {
716 ++rad_index_;
717 if (rad_index_ >= radius_) {
718 ++rad_dir_;
719 rad_index_ = 0;
720 if (rad_dir_ >= 4) {
721 ++radius_;
722 if (radius_ > max_radius_)
723 return CommonEnd();
724 rad_dir_ = 0;
725 }
726 }
727 ICOORD offset = C_OUTLINE::chain_step(rad_dir_);
728 offset *= radius_ - rad_index_;
729 offset += C_OUTLINE::chain_step(rad_dir_ + 1) * rad_index_;
730 x_ = x_origin_ + offset.x();
731 y_ = y_origin_ + offset.y();
732 if (x_ >= 0 && x_ < grid_->gridwidth_ &&
733 y_ >= 0 && y_ < grid_->gridheight_)
734 SetIterator();
735 }
736 CommonNext();
737 } while (unique_mode_ && returns_.find(previous_return_) != returns_.end());
738 if (unique_mode_)
739 returns_.insert(previous_return_);
740 return previous_return_;
741}
static ICOORD chain_step(int chaindir)
Definition: coutln.cpp:1049
integer coordinate
Definition: points.h:32
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52

◆ NextRectSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
BBC * tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::NextRectSearch

Definition at line 842 of file bbgrid.h.

842 {
843 do {
844 while (it_.cycled_list()) {
845 ++x_;
846 if (x_ > max_radius_) {
847 --y_;
848 x_ = x_origin_;
849 if (y_ < y_origin_)
850 return CommonEnd();
851 }
852 SetIterator();
853 }
854 CommonNext();
855 } while (!rect_.overlap(previous_return_->bounding_box()) ||
856 (unique_mode_ && returns_.find(previous_return_) != returns_.end()));
857 if (unique_mode_)
858 returns_.insert(previous_return_);
859 return previous_return_;
860}
bool overlap(const TBOX &box) const
Definition: rect.h:355

◆ NextSideSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
BBC * tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::NextSideSearch ( bool  right_to_left)

Definition at line 761 of file bbgrid.h.

761 {
762 do {
763 while (it_.cycled_list()) {
764 ++rad_index_;
765 if (rad_index_ > radius_) {
766 if (right_to_left)
767 --x_;
768 else
769 ++x_;
770 rad_index_ = 0;
771 if (x_ < 0 || x_ >= grid_->gridwidth_)
772 return CommonEnd();
773 }
774 y_ = y_origin_ - rad_index_;
775 if (y_ >= 0 && y_ < grid_->gridheight_)
776 SetIterator();
777 }
778 CommonNext();
779 } while (unique_mode_ && returns_.find(previous_return_) != returns_.end());
780 if (unique_mode_)
781 returns_.insert(previous_return_);
782 return previous_return_;
783}

◆ NextVerticalSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
BBC * tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::NextVerticalSearch ( bool  top_to_bottom)

Definition at line 802 of file bbgrid.h.

803 {
804 do {
805 while (it_.cycled_list()) {
806 ++rad_index_;
807 if (rad_index_ > radius_) {
808 if (top_to_bottom)
809 --y_;
810 else
811 ++y_;
812 rad_index_ = 0;
813 if (y_ < 0 || y_ >= grid_->gridheight_)
814 return CommonEnd();
815 }
816 x_ = x_origin_ + rad_index_;
817 if (x_ >= 0 && x_ < grid_->gridwidth_)
818 SetIterator();
819 }
820 CommonNext();
821 } while (unique_mode_ && returns_.find(previous_return_) != returns_.end());
822 if (unique_mode_)
823 returns_.insert(previous_return_);
824 return previous_return_;
825}

◆ RemoveBBox()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::RemoveBBox

Definition at line 866 of file bbgrid.h.

866 {
867 if (previous_return_ != nullptr) {
868 // Remove all instances of previous_return_ from the list, so the iterator
869 // remains valid after removal from the rest of the grid cells.
870 // if previous_return_ is not on the list, then it has been removed already.
871 BBC* prev_data = nullptr;
872 BBC* new_previous_return = nullptr;
873 it_.move_to_first();
874 for (it_.mark_cycle_pt(); !it_.cycled_list();) {
875 if (it_.data() == previous_return_) {
876 new_previous_return = prev_data;
877 it_.extract();
878 it_.forward();
879 next_return_ = it_.cycled_list() ? nullptr : it_.data();
880 } else {
881 prev_data = it_.data();
882 it_.forward();
883 }
884 }
885 grid_->RemoveBBox(previous_return_);
886 previous_return_ = new_previous_return;
888 }
889}
void RepositionIterator()
Definition: bbgrid.h:892

◆ RepositionIterator()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::RepositionIterator

Definition at line 892 of file bbgrid.h.

892 {
893 // Something was deleted, so we have little choice but to clear the
894 // returns list.
895 returns_.clear();
896 // Reset the iterator back to one past the previous return.
897 // If the previous_return_ is no longer in the list, then
898 // next_return_ serves as a backup.
899 it_.move_to_first();
900 // Special case, the first element was removed and reposition
901 // iterator was called. In this case, the data is fine, but the
902 // cycle point is not. Detect it and return.
903 if (!it_.empty() && it_.data() == next_return_) {
904 it_.mark_cycle_pt();
905 return;
906 }
907 for (it_.mark_cycle_pt(); !it_.cycled_list(); it_.forward()) {
908 if (it_.data() == previous_return_ ||
909 it_.data_relative(1) == next_return_) {
910 CommonNext();
911 return;
912 }
913 }
914 // We ran off the end of the list. Move to a new cell next time.
915 previous_return_ = nullptr;
916 next_return_ = nullptr;
917}

◆ ReturnedSeedElement()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
bool tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::ReturnedSeedElement ( ) const
inline

Definition at line 264 of file bbgrid.h.

264 {
265 TBOX box = previous_return_->bounding_box();
266 int x_center = (box.left()+box.right())/2;
267 int y_center = (box.top()+box.bottom())/2;
268 int grid_x, grid_y;
269 grid_->GridCoords(x_center, y_center, &grid_x, &grid_y);
270 return (x_ == grid_x) && (y_ == grid_y);
271 }
int16_t top() const
Definition: rect.h:58
int16_t right() const
Definition: rect.h:79

◆ SetUniqueMode()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::SetUniqueMode ( bool  mode)
inline

Definition at line 253 of file bbgrid.h.

253 {
254 unique_mode_ = mode;
255 }

◆ StartFullSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::StartFullSearch

Definition at line 665 of file bbgrid.h.

665 {
666 // Full search uses x_ and y_ as the current grid
667 // cell being searched.
668 CommonStart(grid_->bleft_.x(), grid_->tright_.y());
669}

◆ StartRadSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::StartRadSearch ( int  x,
int  y,
int  max_radius 
)

Definition at line 698 of file bbgrid.h.

699 {
700 // Rad search uses x_origin_ and y_origin_ as the center of the circle.
701 // The radius_ is the radius of the (diamond-shaped) circle and
702 // rad_index/rad_dir_ combine to determine the position around it.
703 max_radius_ = max_radius;
704 radius_ = 0;
705 rad_index_ = 0;
706 rad_dir_ = 3;
707 CommonStart(x, y);
708}

◆ StartRectSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::StartRectSearch ( const TBOX rect)

Definition at line 830 of file bbgrid.h.

830 {
831 // Rect search records the xmin in x_origin_, the ymin in y_origin_
832 // and the xmax in max_radius_.
833 // The search proceeds left to right, top to bottom.
834 rect_ = rect;
835 CommonStart(rect.left(), rect.top());
836 grid_->GridCoords(rect.right(), rect.bottom(), // - rect.height(),
837 &max_radius_, &y_origin_);
838}

◆ StartSideSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::StartSideSearch ( int  x,
int  ymin,
int  ymax 
)

Definition at line 746 of file bbgrid.h.

747 {
748 // Right search records the x in x_origin_, the ymax in y_origin_
749 // and the size of the vertical strip to search in radius_.
750 // To guarantee finding overlapping objects of up to twice the
751 // given size, double the height.
752 radius_ = ((ymax - ymin) * 2 + grid_->gridsize_ - 1) / grid_->gridsize_;
753 rad_index_ = 0;
754 CommonStart(x, ymax);
755}

◆ StartVerticalSearch()

template<class BBC , class BBC_CLIST , class BBC_C_IT >
void tesseract::GridSearch< BBC, BBC_CLIST, BBC_C_IT >::StartVerticalSearch ( int  xmin,
int  xmax,
int  y 
)

Definition at line 788 of file bbgrid.h.

790 {
791 // Right search records the xmin in x_origin_, the y in y_origin_
792 // and the size of the horizontal strip to search in radius_.
793 radius_ = (xmax - xmin + grid_->gridsize_ - 1) / grid_->gridsize_;
794 rad_index_ = 0;
795 CommonStart(xmin, y);
796}

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