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

239  : grid_(grid), unique_mode_(false),
240  previous_return_(NULL), next_return_(NULL) {
241  }

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

244  {
245  return x_;
246  }

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

247  {
248  return y_;
249  }

◆ NextFullSearch()

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

Definition at line 679 of file bbgrid.h.

679  {
680  int x;
681  int y;
682  do {
683  while (it_.cycled_list()) {
684  ++x_;
685  if (x_ >= grid_->gridwidth_) {
686  --y_;
687  if (y_ < 0)
688  return CommonEnd();
689  x_ = 0;
690  }
691  SetIterator();
692  }
693  CommonNext();
694  TBOX box = previous_return_->bounding_box();
695  grid_->GridCoords(box.left(), box.bottom(), &x, &y);
696  } while (x != x_ || y != y_);
697  return previous_return_;
698 }
inT16 left() const
Definition: rect.h:68
Definition: rect.h:30
inT16 bottom() const
Definition: rect.h:61

◆ NextRadSearch()

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

Definition at line 717 of file bbgrid.h.

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

◆ NextRectSearch()

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

Definition at line 846 of file bbgrid.h.

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

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

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

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

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

◆ RemoveBBox()

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

Definition at line 870 of file bbgrid.h.

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

◆ RepositionIterator()

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

Definition at line 896 of file bbgrid.h.

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

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

266  {
267  TBOX box = previous_return_->bounding_box();
268  int x_center = (box.left()+box.right())/2;
269  int y_center = (box.top()+box.bottom())/2;
270  int grid_x, grid_y;
271  grid_->GridCoords(x_center, y_center, &grid_x, &grid_y);
272  return (x_ == grid_x) && (y_ == grid_y);
273  }
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

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

255  {
256  unique_mode_ = mode;
257  }
const char int mode
Definition: ioapi.h:38

◆ StartFullSearch()

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

Definition at line 669 of file bbgrid.h.

669  {
670  // Full search uses x_ and y_ as the current grid
671  // cell being searched.
672  CommonStart(grid_->bleft_.x(), grid_->tright_.y());
673 }

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

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

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

834  {
835  // Rect search records the xmin in x_origin_, the ymin in y_origin_
836  // and the xmax in max_radius_.
837  // The search proceeds left to right, top to bottom.
838  rect_ = rect;
839  CommonStart(rect.left(), rect.top());
840  grid_->GridCoords(rect.right(), rect.bottom(), // - rect.height(),
841  &max_radius_, &y_origin_);
842 }
inT16 left() const
Definition: rect.h:68
inT16 top() const
Definition: rect.h:54
inT16 right() const
Definition: rect.h:75
inT16 bottom() const
Definition: rect.h:61

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

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

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

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

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