All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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

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

Macros

Definition at line 60 of file mfoutline.h.

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

Definition at line 72 of file mfoutline.h.

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

Definition at line 66 of file mfoutline.h.

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

Definition at line 69 of file mfoutline.h.

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

Definition at line 73 of file mfoutline.h.

#define MF_SCALE_FACTOR   (NORMAL_X_HEIGHT / kBlnXHeight)

Definition at line 63 of file mfoutline.h.

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

Definition at line 68 of file mfoutline.h.

#define NORMAL_BASELINE   (0.0)

Definition at line 31 of file mfoutline.h.

#define NORMAL_X_HEIGHT   (0.5)

Include Files and Type Defines

Definition at line 30 of file mfoutline.h.

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

Definition at line 67 of file mfoutline.h.

Typedef Documentation

typedef LIST MFOUTLINE

Definition at line 33 of file mfoutline.h.

Enumeration Type Documentation

enum DIRECTION
Enumerator
north 
south 
east 
west 
northeast 
northwest 
southeast 
southwest 

Definition at line 35 of file mfoutline.h.

Enumerator
baseline 
character 

Definition at line 53 of file mfoutline.h.

53  {
55 } NORM_METHOD;
NORM_METHOD
Definition: mfoutline.h:53
Enumerator
outer 
hole 

Definition at line 49 of file mfoutline.h.

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

Function Documentation

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 337 of file mfoutline.cpp.

337  {
338  MFOUTLINE Current;
339 
340  for (Current = Start; Current != End; Current = NextPointAfter (Current))
341  PointAt (Current)->Direction = Direction;
342 
343  PointAt (End)->PreviousDirection = Direction;
344 
345 } /* ChangeDirection */
#define PointAt(O)
Definition: mfoutline.h:67
#define NextPointAfter(E)
Definition: mfoutline.h:68
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 */
void LocalNormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:305
#define NIL_LIST
Definition: oldlist.h:126
#define PointAt(O)
Definition: mfoutline.h:67
#define MAX_UINT8
Definition: host.h:121
FLOAT32 y
Definition: fpoint.h:31
#define NextPointAfter(E)
Definition: mfoutline.h:68
FPOINT Point
Definition: mfoutline.h:40
Definition: points.h:189
FLOAT32 x
Definition: fpoint.h:31
#define MF_SCALE_FACTOR
Definition: mfoutline.h:63
void ComputeBlobCenter ( TBLOB Blob,
TPOINT BlobCenter 
)

Public Function Prototypes

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 401 of file mfoutline.cpp.

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

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

Definition at line 39 of file mfoutline.cpp.

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

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

Definition at line 49 of file mfoutline.cpp.

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

93  {
94  MFOUTLINE mf_outline;
95 
96  while (outline != NULL) {
97  mf_outline = ConvertOutline(outline);
98  if (mf_outline != NULL)
99  mf_outlines = push(mf_outlines, mf_outline);
100  outline = outline->next;
101  }
102  return mf_outlines;
103 }
TESSLINE * next
Definition: blobs.h:258
MFOUTLINE ConvertOutline(TESSLINE *outline)
Definition: mfoutline.cpp:49
#define NULL
Definition: host.h:144
LIST push(LIST list, void *element)
Definition: oldlist.cpp:323
void FilterEdgeNoise ( MFOUTLINE  Outline,
FLOAT32  NoiseSegmentLength 
)
void FindDirectionChanges ( MFOUTLINE  Outline,
FLOAT32  MinSlope,
FLOAT32  MaxSlope 
)

This routine searches thru 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 120 of file mfoutline.cpp.

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

154  { //MFOUTLINE Outline)
155  MFOUTLINE Start;
156  MFOUTLINE Outline = (MFOUTLINE) arg;
157 
158  /* break the circular outline so we can use std. techniques to deallocate */
159  Start = list_rest (Outline);
160  set_rest(Outline, NIL_LIST);
161  while (Start != NULL) {
162  free_struct (first_node (Start), sizeof (MFEDGEPT), "MFEDGEPT");
163  Start = pop (Start);
164  }
165 
166 } /* FreeMFOutline */
#define NIL_LIST
Definition: oldlist.h:126
#define set_rest(l, cell)
Definition: oldlist.h:222
#define first_node(l)
Definition: oldlist.h:139
LIST pop(LIST list)
Definition: oldlist.cpp:305
#define NULL
Definition: host.h:144
void free_struct(void *deadstruct, inT32, const char *)
Definition: memry.cpp:43
LIST MFOUTLINE
Definition: mfoutline.h:33
#define list_rest(l)
Definition: oldlist.h:138
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 178 of file mfoutline.cpp.

178  {
179  destroy_nodes(Outlines, FreeMFOutline);
180 } /* FreeOutlines */
void FreeMFOutline(void *arg)
Definition: mfoutline.cpp:154
void destroy_nodes(LIST list, void_dest destructor)
Definition: oldlist.cpp:204
void MarkDirectionChanges ( MFOUTLINE  Outline)

This routine searches thru 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 198 of file mfoutline.cpp.

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

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

Definition at line 220 of file mfoutline.cpp.

220  {
221  return ((MFEDGEPT *) alloc_struct(sizeof(MFEDGEPT), "MFEDGEPT"));
222 }
void * alloc_struct(inT32 count, const char *)
Definition: memry.cpp:39
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 466 of file mfoutline.cpp.

466  {
467  DIRECTION InitialDirection;
468 
469  InitialDirection = PointAt (EdgePoint)->Direction;
470 
471  MFOUTLINE next_pt = NULL;
472  do {
473  EdgePoint = NextPointAfter(EdgePoint);
474  next_pt = NextPointAfter(EdgePoint);
475  } while (PointAt(EdgePoint)->Direction == InitialDirection &&
476  !PointAt(EdgePoint)->Hidden &&
477  next_pt != NULL && !PointAt(next_pt)->Hidden);
478 
479  return (EdgePoint);
480 }
#define PointAt(O)
Definition: mfoutline.h:67
DIRECTION
Definition: mfoutline.h:35
#define NextPointAfter(E)
Definition: mfoutline.h:68
#define NULL
Definition: host.h:144
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 238 of file mfoutline.cpp.

238  {
239  EdgePoint = NextPointAfter(EdgePoint);
240  while (!PointAt(EdgePoint)->ExtremityMark)
241  EdgePoint = NextPointAfter(EdgePoint);
242 
243  return (EdgePoint);
244 
245 } /* NextExtremity */
#define PointAt(O)
Definition: mfoutline.h:67
#define NextPointAfter(E)
Definition: mfoutline.h:68
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 264 of file mfoutline.cpp.

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