Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
edgloop.cpp File Reference
#include "mfcpch.h"
#include "scanedg.h"
#include "drawedg.h"
#include "edgloop.h"

Go to the source code of this file.

Macros

#define MINEDGELENGTH   8
 

Functions

void complete_edge (CRACKEDGE *start, C_OUTLINE_IT *outline_it)
 
ScrollView::Color check_path_legal (CRACKEDGE *start)
 
inT16 loop_bounding_box (CRACKEDGE *&start, ICOORD &botleft, ICOORD &topright)
 

Variables

int edges_maxedgelength = 16000
 

Macro Definition Documentation

#define MINEDGELENGTH   8

Definition at line 30 of file edgloop.cpp.

Function Documentation

ScrollView::Color check_path_legal ( CRACKEDGE start)

Definition at line 70 of file edgloop.cpp.

72  {
73  int lastchain; //last chain code
74  int chaindiff; //chain code diff
75  inT32 length; //length of loop
76  inT32 chainsum; //sum of chain diffs
77  CRACKEDGE *edgept; //current point
78  const ERRCODE ED_ILLEGAL_SUM = "Illegal sum of chain codes";
79 
80  length = 0;
81  chainsum = 0; //sum of chain codes
82  edgept = start;
83  lastchain = edgept->prev->stepdir; //previous chain code
84  do {
85  length++;
86  if (edgept->stepdir != lastchain) {
87  //chain code difference
88  chaindiff = edgept->stepdir - lastchain;
89  if (chaindiff > 2)
90  chaindiff -= 4;
91  else if (chaindiff < -2)
92  chaindiff += 4;
93  chainsum += chaindiff; //sum differences
94  lastchain = edgept->stepdir;
95  }
96  edgept = edgept->next;
97  }
98  while (edgept != start && length < edges_maxedgelength);
99 
100  if ((chainsum != 4 && chainsum != -4)
101  || edgept != start || length < MINEDGELENGTH) {
102  if (edgept != start) {
103  return ScrollView::YELLOW;
104  } else if (length < MINEDGELENGTH) {
105  return ScrollView::MAGENTA;
106  } else {
107  ED_ILLEGAL_SUM.error ("check_path_legal", TESSLOG, "chainsum=%d",
108  chainsum);
109  return ScrollView::GREEN;
110  }
111  }
112  //colour on inside
113  return chainsum < 0 ? ScrollView::BLUE : ScrollView::RED;
114 }
int edges_maxedgelength
Definition: edgloop.cpp:32
inT8 stepdir
Definition: crakedge.h:33
int inT32
Definition: host.h:102
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:41
#define MINEDGELENGTH
Definition: edgloop.cpp:30
CRACKEDGE * prev
Definition: crakedge.h:34
CRACKEDGE * next
Definition: crakedge.h:35
void complete_edge ( CRACKEDGE start,
C_OUTLINE_IT *  outline_it 
)

Definition at line 40 of file edgloop.cpp.

41  {
42  ScrollView::Color colour; //colour to draw in
43  inT16 looplength; //steps in loop
44  ICOORD botleft; //bounding box
45  ICOORD topright;
46  C_OUTLINE *outline; //new outline
47 
48  //check length etc.
49  colour = check_path_legal (start);
50 
51  if (colour == ScrollView::RED || colour == ScrollView::BLUE) {
52  looplength = loop_bounding_box (start, botleft, topright);
53  outline = new C_OUTLINE (start, botleft, topright, looplength);
54  //add to list
55  outline_it->add_after_then_move (outline);
56  }
57 }
ScrollView::Color check_path_legal(CRACKEDGE *start)
Definition: edgloop.cpp:70
class DLLSYM C_OUTLINE
Definition: coutln.h:40
short inT16
Definition: host.h:100
integer coordinate
Definition: points.h:30
inT16 loop_bounding_box(CRACKEDGE *&start, ICOORD &botleft, ICOORD &topright)
Definition: edgloop.cpp:122
inT16 loop_bounding_box ( CRACKEDGE *&  start,
ICOORD botleft,
ICOORD topright 
)

Definition at line 122 of file edgloop.cpp.

125  {
126  inT16 length; //length of loop
127  inT16 leftmost; //on top row
128  CRACKEDGE *edgept; //current point
129  CRACKEDGE *realstart; //topleft start
130 
131  edgept = start;
132  realstart = start;
133  botleft = topright = ICOORD (edgept->pos.x (), edgept->pos.y ());
134  leftmost = edgept->pos.x ();
135  length = 0; //coutn length
136  do {
137  edgept = edgept->next;
138  if (edgept->pos.x () < botleft.x ())
139  //get bounding box
140  botleft.set_x (edgept->pos.x ());
141  else if (edgept->pos.x () > topright.x ())
142  topright.set_x (edgept->pos.x ());
143  if (edgept->pos.y () < botleft.y ())
144  //get bounding box
145  botleft.set_y (edgept->pos.y ());
146  else if (edgept->pos.y () > topright.y ()) {
147  realstart = edgept;
148  leftmost = edgept->pos.x ();
149  topright.set_y (edgept->pos.y ());
150  }
151  else if (edgept->pos.y () == topright.y ()
152  && edgept->pos.x () < leftmost) {
153  //leftmost on line
154  leftmost = edgept->pos.x ();
155  realstart = edgept;
156  }
157  length++; //count elements
158  }
159  while (edgept != start);
160  start = realstart; //shift it to topleft
161  return length;
162 }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
ICOORD pos
Definition: crakedge.h:30
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
short inT16
Definition: host.h:100
integer coordinate
Definition: points.h:30
CRACKEDGE * next
Definition: crakedge.h:35

Variable Documentation

int edges_maxedgelength = 16000

"Max steps in any outline"

Definition at line 32 of file edgloop.cpp.