tesseract  4.00.00dev
mfoutline.h File Reference
#include "blobs.h"
#include "host.h"
#include "oldlist.h"
#include "fpoint.h"
#include "params.h"

Go to the source code of this file.

Classes

struct  MFEDGEPT
 

Macros

#define NORMAL_X_HEIGHT   (0.5)
 
#define NORMAL_BASELINE   (0.0)
 
#define AverageOf(A, B)   (((A) + (B)) / 2)
 
#define MF_SCALE_FACTOR   (NORMAL_X_HEIGHT / kBlnXHeight)
 
#define DegenerateOutline(O)   (((O) == NIL_LIST) || ((O) == list_rest(O)))
 
#define PointAt(O)   ((MFEDGEPT *) first_node (O))
 
#define NextPointAfter(E)   (list_rest (E))
 
#define MakeOutlineCircular(O)   (set_rest (last (O), (O)))
 
#define ClearMark(P)   ((P)->ExtremityMark = FALSE)
 
#define MarkPoint(P)   ((P)->ExtremityMark = TRUE)
 

Typedefs

typedef LIST MFOUTLINE
 

Enumerations

enum  DIRECTION {
  north, south, east, west,
  northeast, northwest, southeast, southwest
}
 
enum  OUTLINETYPE { outer, hole }
 
enum  NORM_METHOD { baseline, character }
 

Functions

void ComputeBlobCenter (TBLOB *Blob, TPOINT *BlobCenter)
 
LIST ConvertBlob (TBLOB *Blob)
 
MFOUTLINE ConvertOutline (TESSLINE *Outline)
 
LIST ConvertOutlines (TESSLINE *Outline, LIST ConvertedOutlines, OUTLINETYPE OutlineType)
 
void FilterEdgeNoise (MFOUTLINE Outline, FLOAT32 NoiseSegmentLength)
 
void FindDirectionChanges (MFOUTLINE Outline, FLOAT32 MinSlope, FLOAT32 MaxSlope)
 
void FreeMFOutline (void *agr)
 
void FreeOutlines (LIST Outlines)
 
void MarkDirectionChanges (MFOUTLINE Outline)
 
MFEDGEPTNewEdgePoint ()
 
MFOUTLINE NextExtremity (MFOUTLINE EdgePoint)
 
void NormalizeOutline (MFOUTLINE Outline, FLOAT32 XOrigin)
 
void ChangeDirection (MFOUTLINE Start, MFOUTLINE End, DIRECTION Direction)
 
void CharNormalizeOutline (MFOUTLINE Outline, const DENORM &cn_denorm)
 
void ComputeDirection (MFEDGEPT *Start, MFEDGEPT *Finish, FLOAT32 MinSlope, FLOAT32 MaxSlope)
 
MFOUTLINE NextDirectionChange (MFOUTLINE EdgePoint)
 

Macro Definition Documentation

◆ AverageOf

#define AverageOf (   A,
 
)    (((A) + (B)) / 2)

Macros

Definition at line 60 of file mfoutline.h.

◆ ClearMark

#define ClearMark (   P)    ((P)->ExtremityMark = FALSE)

Definition at line 72 of file mfoutline.h.

◆ DegenerateOutline

#define DegenerateOutline (   O)    (((O) == NIL_LIST) || ((O) == list_rest(O)))

Definition at line 66 of file mfoutline.h.

◆ MakeOutlineCircular

#define MakeOutlineCircular (   O)    (set_rest (last (O), (O)))

Definition at line 69 of file mfoutline.h.

◆ MarkPoint

#define MarkPoint (   P)    ((P)->ExtremityMark = TRUE)

Definition at line 73 of file mfoutline.h.

◆ MF_SCALE_FACTOR

#define MF_SCALE_FACTOR   (NORMAL_X_HEIGHT / kBlnXHeight)

Definition at line 63 of file mfoutline.h.

◆ NextPointAfter

#define NextPointAfter (   E)    (list_rest (E))

Definition at line 68 of file mfoutline.h.

◆ NORMAL_BASELINE

#define NORMAL_BASELINE   (0.0)

Definition at line 31 of file mfoutline.h.

◆ NORMAL_X_HEIGHT

#define NORMAL_X_HEIGHT   (0.5)

Include Files and Type Defines

Definition at line 30 of file mfoutline.h.

◆ PointAt

#define PointAt (   O)    ((MFEDGEPT *) first_node (O))

Definition at line 67 of file mfoutline.h.

Typedef Documentation

◆ MFOUTLINE

typedef LIST MFOUTLINE

Definition at line 33 of file mfoutline.h.

Enumeration Type Documentation

◆ DIRECTION

enum DIRECTION
Enumerator
north 
south 
east 
west 
northeast 
northwest 
southeast 
southwest 

Definition at line 35 of file mfoutline.h.

◆ NORM_METHOD

Enumerator
baseline 
character 

Definition at line 53 of file mfoutline.h.

53  {
55 } NORM_METHOD;
NORM_METHOD
Definition: mfoutline.h:53

◆ OUTLINETYPE

Enumerator
outer 
hole 

Definition at line 49 of file mfoutline.h.

49  {
50  outer, hole
51 } OUTLINETYPE;
Definition: mfoutline.h:50
OUTLINETYPE
Definition: mfoutline.h:49

Function Documentation

◆ ChangeDirection()

void ChangeDirection ( MFOUTLINE  Start,
MFOUTLINE  End,
DIRECTION  Direction 
)

Change the direction of every vector in the specified outline segment to Direction. The segment to be changed starts at Start and ends at End. Note that the previous direction of End must also be changed to reflect the change in direction of the point before it.

Parameters
Start,Enddefines segment of outline to be modified
Directionnew direction to assign to segment
Returns
none
Note
Globals: none
Exceptions: none
History: Fri May 4 10:42:04 1990, DSJ, Created.

Definition at line 338 of file mfoutline.cpp.

338  {
339  MFOUTLINE Current;
340 
341  for (Current = Start; Current != End; Current = NextPointAfter (Current))
342  PointAt (Current)->Direction = Direction;
343 
344  PointAt (End)->PreviousDirection = Direction;
345 
346 } /* ChangeDirection */
#define PointAt(O)
Definition: mfoutline.h:67
#define NextPointAfter(E)
Definition: mfoutline.h:68

◆ CharNormalizeOutline()

void CharNormalizeOutline ( MFOUTLINE  Outline,
const DENORM cn_denorm 
)

This routine normalizes each point in Outline by translating it to the specified center and scaling it anisotropically according to the given scale factors.

Parameters
Outlineoutline to be character normalized
cn_denorm
Returns
none
Note
Globals: none
Exceptions: none
History: Fri Dec 14 10:27:11 1990, DSJ, Created.

Definition at line 359 of file mfoutline.cpp.

359  {
360  MFOUTLINE First, Current;
361  MFEDGEPT *CurrentPoint;
362 
363  if (Outline == NIL_LIST)
364  return;
365 
366  First = Outline;
367  Current = First;
368  do {
369  CurrentPoint = PointAt(Current);
370  FCOORD pos(CurrentPoint->Point.x, CurrentPoint->Point.y);
371  cn_denorm.LocalNormTransform(pos, &pos);
372  CurrentPoint->Point.x = (pos.x() - MAX_UINT8 / 2) * MF_SCALE_FACTOR;
373  CurrentPoint->Point.y = (pos.y() - MAX_UINT8 / 2) * MF_SCALE_FACTOR;
374 
375  Current = NextPointAfter(Current);
376  }
377  while (Current != First);
378 
379 } /* CharNormalizeOutline */
Definition: points.h:189
#define MAX_UINT8
Definition: host.h:63
#define MF_SCALE_FACTOR
Definition: mfoutline.h:63
#define NIL_LIST
Definition: oldlist.h:126
void LocalNormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:305
#define PointAt(O)
Definition: mfoutline.h:67
FLOAT32 y
Definition: fpoint.h:31
FPOINT Point
Definition: mfoutline.h:40
FLOAT32 x
Definition: fpoint.h:31
#define NextPointAfter(E)
Definition: mfoutline.h:68

◆ ComputeBlobCenter()

void ComputeBlobCenter ( TBLOB Blob,
TPOINT BlobCenter 
)

Public Function Prototypes

◆ ComputeDirection()

void ComputeDirection ( MFEDGEPT Start,
MFEDGEPT Finish,
FLOAT32  MinSlope,
FLOAT32  MaxSlope 
)

This routine computes the slope from Start to Finish and and then computes the approximate direction of the line segment from Start to Finish. The direction is quantized into 8 buckets: N, S, E, W, NE, NW, SE, SW Both the slope and the direction are then stored into the appropriate fields of the Start edge point. The direction is also stored into the PreviousDirection field of the Finish edge point.

Parameters
Startstarting point to compute direction from
Finishfinishing point to compute direction to
MinSlopeslope below which lines are horizontal
MaxSlopeslope above which lines are vertical
Returns
none
Note
Globals: none
Exceptions: none
History: 7/25/89, DSJ, Created.

Definition at line 400 of file mfoutline.cpp.

403  {
404  FVECTOR Delta;
405 
406  Delta.x = Finish->Point.x - Start->Point.x;
407  Delta.y = Finish->Point.y - Start->Point.y;
408  if (Delta.x == 0)
409  if (Delta.y < 0) {
410  Start->Slope = -MAX_FLOAT32;
411  Start->Direction = south;
412  }
413  else {
414  Start->Slope = MAX_FLOAT32;
415  Start->Direction = north;
416  }
417  else {
418  Start->Slope = Delta.y / Delta.x;
419  if (Delta.x > 0)
420  if (Delta.y > 0)
421  if (Start->Slope > MinSlope)
422  if (Start->Slope < MaxSlope)
423  Start->Direction = northeast;
424  else
425  Start->Direction = north;
426  else
427  Start->Direction = east;
428  else if (Start->Slope < -MinSlope)
429  if (Start->Slope > -MaxSlope)
430  Start->Direction = southeast;
431  else
432  Start->Direction = south;
433  else
434  Start->Direction = east;
435  else if (Delta.y > 0)
436  if (Start->Slope < -MinSlope)
437  if (Start->Slope > -MaxSlope)
438  Start->Direction = northwest;
439  else
440  Start->Direction = north;
441  else
442  Start->Direction = west;
443  else if (Start->Slope > MinSlope)
444  if (Start->Slope < MaxSlope)
445  Start->Direction = southwest;
446  else
447  Start->Direction = south;
448  else
449  Start->Direction = west;
450  }
451  Finish->PreviousDirection = Start->Direction;
452 }
Definition: fpoint.h:29
DIRECTION PreviousDirection
Definition: mfoutline.h:46
#define MAX_FLOAT32
Definition: host.h:66
Definition: mfoutline.h:36
FLOAT32 y
Definition: fpoint.h:31
DIRECTION Direction
Definition: mfoutline.h:45
FPOINT Point
Definition: mfoutline.h:40
FLOAT32 x
Definition: fpoint.h:31
Definition: mfoutline.h:36
FLOAT32 Slope
Definition: mfoutline.h:41

◆ ConvertBlob()

LIST ConvertBlob ( TBLOB blob)

Convert a blob into a list of MFOUTLINEs (float-based microfeature format).

Definition at line 40 of file mfoutline.cpp.

40  {
41  LIST outlines = NIL_LIST;
42  return (blob == NULL)
43  ? NIL_LIST
44  : ConvertOutlines(blob->outlines, outlines, outer);
45 }
LIST ConvertOutlines(TESSLINE *outline, LIST mf_outlines, OUTLINETYPE outline_type)
Definition: mfoutline.cpp:92
TESSLINE * outlines
Definition: blobs.h:377
#define NIL_LIST
Definition: oldlist.h:126

◆ ConvertOutline()

MFOUTLINE ConvertOutline ( TESSLINE outline)

Convert a TESSLINE into the float-based MFOUTLINE micro-feature format.

Definition at line 50 of file mfoutline.cpp.

50  {
51  MFEDGEPT *NewPoint;
52  MFOUTLINE MFOutline = NIL_LIST;
53  EDGEPT *EdgePoint;
54  EDGEPT *StartPoint;
55  EDGEPT *NextPoint;
56 
57  if (outline == NULL || outline->loop == NULL)
58  return MFOutline;
59 
60  StartPoint = outline->loop;
61  EdgePoint = StartPoint;
62  do {
63  NextPoint = EdgePoint->next;
64 
65  /* filter out duplicate points */
66  if (EdgePoint->pos.x != NextPoint->pos.x ||
67  EdgePoint->pos.y != NextPoint->pos.y) {
68  NewPoint = NewEdgePoint();
69  ClearMark(NewPoint);
70  NewPoint->Hidden = EdgePoint->IsHidden();
71  NewPoint->Point.x = EdgePoint->pos.x;
72  NewPoint->Point.y = EdgePoint->pos.y;
73  MFOutline = push(MFOutline, NewPoint);
74  }
75  EdgePoint = NextPoint;
76  } while (EdgePoint != StartPoint);
77 
78  if (MFOutline != NULL)
79  MakeOutlineCircular(MFOutline);
80  return MFOutline;
81 }
TPOINT pos
Definition: blobs.h:163
#define NIL_LIST
Definition: oldlist.h:126
#define MakeOutlineCircular(O)
Definition: mfoutline.h:69
#define ClearMark(P)
Definition: mfoutline.h:72
EDGEPT * loop
Definition: blobs.h:257
bool IsHidden() const
Definition: blobs.h:153
inT16 x
Definition: blobs.h:71
BOOL8 Hidden
Definition: mfoutline.h:43
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
MFEDGEPT * NewEdgePoint()
Definition: mfoutline.cpp:221
FLOAT32 y
Definition: fpoint.h:31
inT16 y
Definition: blobs.h:72
FPOINT Point
Definition: mfoutline.h:40
FLOAT32 x
Definition: fpoint.h:31
LIST push(LIST list, void *element)
Definition: oldlist.cpp:317

◆ ConvertOutlines()

LIST ConvertOutlines ( TESSLINE outline,
LIST  mf_outlines,
OUTLINETYPE  outline_type 
)

Convert a tree of outlines to a list of MFOUTLINEs (lists of MFEDGEPTs).

Parameters
outlinefirst outline to be converted
mf_outlineslist to add converted outlines to
outline_typeare the outlines outer or holes?

Definition at line 92 of file mfoutline.cpp.

94  {
95  MFOUTLINE mf_outline;
96 
97  while (outline != NULL) {
98  mf_outline = ConvertOutline(outline);
99  if (mf_outline != NULL)
100  mf_outlines = push(mf_outlines, mf_outline);
101  outline = outline->next;
102  }
103  return mf_outlines;
104 }
TESSLINE * next
Definition: blobs.h:258
MFOUTLINE ConvertOutline(TESSLINE *outline)
Definition: mfoutline.cpp:50
LIST push(LIST list, void *element)
Definition: oldlist.cpp:317

◆ FilterEdgeNoise()

void FilterEdgeNoise ( MFOUTLINE  Outline,
FLOAT32  NoiseSegmentLength 
)

◆ FindDirectionChanges()

void FindDirectionChanges ( MFOUTLINE  Outline,
FLOAT32  MinSlope,
FLOAT32  MaxSlope 
)

This routine searches through the specified outline, computes a slope for each vector in the outline, and marks each vector as having one of the following directions: N, S, E, W, NE, NW, SE, SW This information is then stored in the outline and the outline is returned.

Parameters
Outlinemicro-feature outline to analyze
MinSlopecontrols "snapping" of segments to horizontal
MaxSlopecontrols "snapping" of segments to vertical
Returns
none
Note
Exceptions: none
History: 7/21/89, DSJ, Created.

Definition at line 121 of file mfoutline.cpp.

123  {
124  MFEDGEPT *Current;
125  MFEDGEPT *Last;
126  MFOUTLINE EdgePoint;
127 
128  if (DegenerateOutline (Outline))
129  return;
130 
131  Last = PointAt (Outline);
132  Outline = NextPointAfter (Outline);
133  EdgePoint = Outline;
134  do {
135  Current = PointAt (EdgePoint);
136  ComputeDirection(Last, Current, MinSlope, MaxSlope);
137 
138  Last = Current;
139  EdgePoint = NextPointAfter (EdgePoint);
140  }
141  while (EdgePoint != Outline);
142 
143 } /* FindDirectionChanges */
void ComputeDirection(MFEDGEPT *Start, MFEDGEPT *Finish, FLOAT32 MinSlope, FLOAT32 MaxSlope)
Definition: mfoutline.cpp:400
#define PointAt(O)
Definition: mfoutline.h:67
#define DegenerateOutline(O)
Definition: mfoutline.h:66
#define NextPointAfter(E)
Definition: mfoutline.h:68

◆ FreeMFOutline()

void FreeMFOutline ( void *  arg)

This routine deallocates all of the memory consumed by a micro-feature outline.

Parameters
argmicro-feature outline to be freed
Returns
none
Note
Exceptions: none
History: 7/27/89, DSJ, Created.

Definition at line 155 of file mfoutline.cpp.

155  { //MFOUTLINE Outline)
156  MFOUTLINE Start;
157  MFOUTLINE Outline = (MFOUTLINE) arg;
158 
159  /* break the circular outline so we can use std. techniques to deallocate */
160  Start = list_rest (Outline);
161  set_rest(Outline, NIL_LIST);
162  while (Start != NULL) {
163  free(first_node(Start));
164  Start = pop (Start);
165  }
166 
167 } /* FreeMFOutline */
#define NIL_LIST
Definition: oldlist.h:126
LIST pop(LIST list)
Definition: oldlist.cpp:299
LIST MFOUTLINE
Definition: mfoutline.h:33
#define set_rest(l, cell)
Definition: oldlist.h:222
#define first_node(l)
Definition: oldlist.h:139
#define list_rest(l)
Definition: oldlist.h:138

◆ FreeOutlines()

void FreeOutlines ( LIST  Outlines)

Release all memory consumed by the specified list of outlines.

Parameters
Outlineslist of mf-outlines to be freed
Returns
none
Note
Exceptions: none
History: Thu Dec 13 16:14:50 1990, DSJ, Created.

Definition at line 179 of file mfoutline.cpp.

179  {
180  destroy_nodes(Outlines, FreeMFOutline);
181 } /* FreeOutlines */
void FreeMFOutline(void *arg)
Definition: mfoutline.cpp:155
void destroy_nodes(LIST list, void_dest destructor)
Definition: oldlist.cpp:199

◆ MarkDirectionChanges()

void MarkDirectionChanges ( MFOUTLINE  Outline)

This routine searches through the specified outline and finds the points at which the outline changes direction. These points are then marked as "extremities". This routine is used as an alternative to FindExtremities(). It forces the endpoints of the microfeatures to be at the direction changes rather than at the midpoint between direction changes.

Parameters
Outlinemicro-feature outline to analyze
Returns
none
Note
Globals: none
Exceptions: none
History: 6/29/90, DSJ, Created.

Definition at line 199 of file mfoutline.cpp.

199  {
200  MFOUTLINE Current;
201  MFOUTLINE Last;
202  MFOUTLINE First;
203 
204  if (DegenerateOutline (Outline))
205  return;
206 
207  First = NextDirectionChange (Outline);
208  Last = First;
209  do {
210  Current = NextDirectionChange (Last);
211  MarkPoint (PointAt (Current));
212  Last = Current;
213  }
214  while (Last != First);
215 
216 } /* MarkDirectionChanges */
MFOUTLINE NextDirectionChange(MFOUTLINE EdgePoint)
Definition: mfoutline.cpp:465
#define MarkPoint(P)
Definition: mfoutline.h:73
#define PointAt(O)
Definition: mfoutline.h:67
#define DegenerateOutline(O)
Definition: mfoutline.h:66

◆ NewEdgePoint()

MFEDGEPT* NewEdgePoint ( )

Return a new edge point for a micro-feature outline.

Definition at line 221 of file mfoutline.cpp.

221  {
222  return (MFEDGEPT *) malloc(sizeof(MFEDGEPT));
223 }

◆ NextDirectionChange()

MFOUTLINE NextDirectionChange ( MFOUTLINE  EdgePoint)

This routine returns the next point in the micro-feature outline that has a direction different than EdgePoint. The routine assumes that the outline being searched is not a degenerate outline (i.e. it must have 2 or more edge points).

Parameters
EdgePointstart search from this point
Returns
Point of next direction change in micro-feature outline.
Note
Globals: none
Exceptions: none
History: 7/25/89, DSJ, Created.

Definition at line 465 of file mfoutline.cpp.

465  {
466  DIRECTION InitialDirection;
467 
468  InitialDirection = PointAt (EdgePoint)->Direction;
469 
470  MFOUTLINE next_pt = NULL;
471  do {
472  EdgePoint = NextPointAfter(EdgePoint);
473  next_pt = NextPointAfter(EdgePoint);
474  } while (PointAt(EdgePoint)->Direction == InitialDirection &&
475  !PointAt(EdgePoint)->Hidden &&
476  next_pt != NULL && !PointAt(next_pt)->Hidden);
477 
478  return (EdgePoint);
479 }
#define PointAt(O)
Definition: mfoutline.h:67
#define NextPointAfter(E)
Definition: mfoutline.h:68
DIRECTION
Definition: mfoutline.h:35

◆ NextExtremity()

MFOUTLINE NextExtremity ( MFOUTLINE  EdgePoint)

This routine returns the next point in the micro-feature outline that is an extremity. The search starts after EdgePoint. The routine assumes that the outline being searched is not a degenerate outline (i.e. it must have 2 or more edge points).

Parameters
EdgePointstart search from this point
Returns
Next extremity in the outline after EdgePoint.
Note
Globals: none
Exceptions: none
History: 7/26/89, DSJ, Created.

Definition at line 239 of file mfoutline.cpp.

239  {
240  EdgePoint = NextPointAfter(EdgePoint);
241  while (!PointAt(EdgePoint)->ExtremityMark)
242  EdgePoint = NextPointAfter(EdgePoint);
243 
244  return (EdgePoint);
245 
246 } /* NextExtremity */
#define PointAt(O)
Definition: mfoutline.h:67
#define NextPointAfter(E)
Definition: mfoutline.h:68

◆ NormalizeOutline()

void NormalizeOutline ( MFOUTLINE  Outline,
FLOAT32  XOrigin 
)

This routine normalizes the coordinates of the specified outline so that the outline is deskewed down to the baseline, translated so that x=0 is at XOrigin, and scaled so that the height of a character cell from descender to ascender is 1. Of this height, 0.25 is for the descender, 0.25 for the ascender, and 0.5 for the x-height. The y coordinate of the baseline is 0.

Parameters
Outlineoutline to be normalized
XOriginx-origin of text
Returns
none
Note
Globals: none
Exceptions: none
History: 8/2/89, DSJ, Created.

Definition at line 265 of file mfoutline.cpp.

266  {
267  if (Outline == NIL_LIST)
268  return;
269 
270  MFOUTLINE EdgePoint = Outline;
271  do {
272  MFEDGEPT *Current = PointAt(EdgePoint);
273  Current->Point.y = MF_SCALE_FACTOR *
274  (Current->Point.y - kBlnBaselineOffset);
275  Current->Point.x = MF_SCALE_FACTOR * (Current->Point.x - XOrigin);
276  EdgePoint = NextPointAfter(EdgePoint);
277  } while (EdgePoint != Outline);
278 } /* NormalizeOutline */
const int kBlnBaselineOffset
Definition: normalis.h:29
#define MF_SCALE_FACTOR
Definition: mfoutline.h:63
#define NIL_LIST
Definition: oldlist.h:126
#define PointAt(O)
Definition: mfoutline.h:67
FLOAT32 y
Definition: fpoint.h:31
FPOINT Point
Definition: mfoutline.h:40
FLOAT32 x
Definition: fpoint.h:31
#define NextPointAfter(E)
Definition: mfoutline.h:68