Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
split.cpp
Go to the documentation of this file.
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File: split.c (Formerly split.c)
5  * Description:
6  * Author: Mark Seaman, OCR Technology
7  * Created: Fri Oct 16 14:37:00 1987
8  * Modified: Fri May 17 16:27:49 1991 (Mark Seaman) marks@hpgrlt
9  * Language: C
10  * Package: N/A
11  * Status: Reusable Software Component
12  *
13  * (c) Copyright 1987, Hewlett-Packard Company.
14  ** Licensed under the Apache License, Version 2.0 (the "License");
15  ** you may not use this file except in compliance with the License.
16  ** You may obtain a copy of the License at
17  ** http://www.apache.org/licenses/LICENSE-2.0
18  ** Unless required by applicable law or agreed to in writing, software
19  ** distributed under the License is distributed on an "AS IS" BASIS,
20  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  ** See the License for the specific language governing permissions and
22  ** limitations under the License.
23  *
24  *************************************************************************/
25 /*----------------------------------------------------------------------
26  I n c l u d e s
27 ----------------------------------------------------------------------*/
28 #include "split.h"
29 #include "structures.h"
30 #include "callcpp.h"
31 
32 #ifdef __UNIX__
33 #include <assert.h>
34 #endif
35 
36 /*----------------------------------------------------------------------
37  V a r i a b l e s
38 ----------------------------------------------------------------------*/
39 BOOL_VAR(wordrec_display_splits, 0, "Display splits");
40 
41 makestructure(newsplit, free_split, SPLIT);
42 
43 /*----------------------------------------------------------------------
44  F u n c t i o n s
45 ----------------------------------------------------------------------*/
46 
47 /**********************************************************************
48  * delete_split
49  *
50  * Remove this split from existance. Take if off the display list and
51  * deallocate its memory.
52  **********************************************************************/
53 void delete_split(SPLIT *split) {
54  if (split) {
55  free_split(split);
56  }
57 }
58 
59 
60 /**********************************************************************
61  * make_edgept
62  *
63  * Create an EDGEPT and hook it into an existing list of edge points.
64  **********************************************************************/
65 EDGEPT *make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev) {
66  EDGEPT *this_edgept;
67  /* Create point */
68  this_edgept = new EDGEPT;
69  this_edgept->pos.x = x;
70  this_edgept->pos.y = y;
71  /* Hook it up */
72  this_edgept->next = next;
73  this_edgept->prev = prev;
74  prev->next = this_edgept;
75  next->prev = this_edgept;
76  /* Set up vec entries */
77  this_edgept->vec.x = this_edgept->next->pos.x - x;
78  this_edgept->vec.y = this_edgept->next->pos.y - y;
79  this_edgept->prev->vec.x = x - this_edgept->prev->pos.x;
80  this_edgept->prev->vec.y = y - this_edgept->prev->pos.y;
81 
82  return (this_edgept);
83 }
84 
85 /**********************************************************************
86  * remove_edgept
87  *
88  * Remove a given EDGEPT from its list and delete it.
89  **********************************************************************/
90 void remove_edgept(EDGEPT *point) {
91  EDGEPT *prev = point->prev;
92  EDGEPT *next = point->next;
93  prev->next = next;
94  next->prev = prev;
95  prev->vec.x = next->pos.x - prev->pos.x;
96  prev->vec.y = next->pos.y - prev->pos.y;
97  delete point;
98 }
99 
100 /**********************************************************************
101  * new_split
102  *
103  * Create a new split record and initialize it. Put it on the display
104  * list.
105  **********************************************************************/
106 SPLIT *new_split(EDGEPT *point1, EDGEPT *point2) {
107  SPLIT *s;
108  s = (SPLIT *) newsplit ();
109  s->point1 = point1;
110  s->point2 = point2;
111  return (s);
112 }
113 
114 
115 /**********************************************************************
116  * print_split
117  *
118  * Print a list of splits. Show the coordinates of both points in
119  * each split.
120  **********************************************************************/
121 void print_split(SPLIT *split) {
122  if (split) {
123  cprintf ("(%d,%d)--(%d,%d)",
124  split->point1->pos.x, split->point1->pos.y,
125  split->point2->pos.x, split->point2->pos.y);
126  }
127 }
128 
129 
130 /**********************************************************************
131  * split_outline
132  *
133  * Split between these two edge points. Apply a split and return a
134  * pointer to the other side of the split.
135  **********************************************************************/
136 void split_outline(EDGEPT *join_point1, EDGEPT *join_point2) {
137  EDGEPT *join_point1a;
138  EDGEPT *temp2;
139  EDGEPT *temp1;
140 
141  assert (join_point1 != join_point2);
142 
143  temp2 = join_point2->next;
144  temp1 = join_point1->next;
145  /* Create two new points */
146  join_point1a = make_edgept (join_point1->pos.x,
147  join_point1->pos.y, temp1, join_point2);
148 
149  make_edgept (join_point2->pos.x, join_point2->pos.y, temp2, join_point1);
150 }
151 
152 
153 /**********************************************************************
154  * unsplit_outlines
155  *
156  * Remove the split that was put between these two points.
157  **********************************************************************/
158 void unsplit_outlines(EDGEPT *p1, EDGEPT *p2) {
159  EDGEPT *tmp1 = p1->next;
160  EDGEPT *tmp2 = p2->next;
161 
162  assert (p1 != p2);
163 
164  tmp1->next->prev = p2;
165  tmp2->next->prev = p1;
166 
167  p1->next = tmp2->next;
168  p2->next = tmp1->next;
169 
170  delete tmp1;
171  delete tmp2;
172 
173  p1->vec.x = p1->next->pos.x - p1->pos.x;
174  p1->vec.y = p1->next->pos.y - p1->pos.y;
175 
176  p2->vec.x = p2->next->pos.x - p2->pos.x;
177  p2->vec.y = p2->next->pos.y - p2->pos.y;
178 }