Tesseract  3.02
tesseract-ocr/wordrec/olutil.cpp
Go to the documentation of this file.
00001 /* -*-C-*-
00002  ********************************************************************************
00003  *
00004  * File:        olutil.c  (Formerly olutil.c)
00005  * Description:
00006  * Author:       Mark Seaman, OCR Technology
00007  * Created:      Fri Oct 16 14:37:00 1987
00008  * Modified:     Fri May 17 13:11:24 1991 (Mark Seaman) marks@hpgrlt
00009  * Language:     C
00010  * Package:      N/A
00011  * Status:       Reusable Software Component
00012  *
00013  * (c) Copyright 1987, Hewlett-Packard Company.
00014  ** Licensed under the Apache License, Version 2.0 (the "License");
00015  ** you may not use this file except in compliance with the License.
00016  ** You may obtain a copy of the License at
00017  ** http://www.apache.org/licenses/LICENSE-2.0
00018  ** Unless required by applicable law or agreed to in writing, software
00019  ** distributed under the License is distributed on an "AS IS" BASIS,
00020  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00021  ** See the License for the specific language governing permissions and
00022  ** limitations under the License.
00023  *
00024  *********************************************************************************/
00025 /*----------------------------------------------------------------------
00026               I n c l u d e s
00027 ----------------------------------------------------------------------*/
00028 #include "olutil.h"
00029 #include "structures.h"
00030 #include "blobs.h"
00031 #include "const.h"
00032 
00033 #ifdef __UNIX__
00034 #include <assert.h>
00035 #endif
00036 
00037 /*----------------------------------------------------------------------
00038               F u n c t i o n s
00039 ----------------------------------------------------------------------*/
00040 /**********************************************************************
00041  * correct_blob_order
00042  *
00043  * Check to see if the blobs are in the correct order.  If they are not
00044  * then swap which outlines are attached to which blobs.
00045  **********************************************************************/
00046 void correct_blob_order(TBLOB *blob1, TBLOB *blob2) { 
00047   TPOINT origin1;
00048   TPOINT origin2;
00049   TESSLINE *temp;
00050 
00051   blob_origin(blob1, &origin1); 
00052   blob_origin(blob2, &origin2); 
00053 
00054   if (origin1.x > origin2.x) {
00055     temp = blob2->outlines;
00056     blob2->outlines = blob1->outlines;
00057     blob1->outlines = temp;
00058   }
00059 }
00060 
00061 
00062 /**********************************************************************
00063  * eliminate_duplicate_outlines
00064  *
00065  * Find and delete any duplicate outline records in this blob.
00066  **********************************************************************/
00067 void eliminate_duplicate_outlines(TBLOB *blob) { 
00068   TESSLINE *outline;
00069   TESSLINE *other_outline;
00070   TESSLINE *last_outline;
00071 
00072   for (outline = blob->outlines; outline; outline = outline->next) {
00073 
00074     for (last_outline = outline, other_outline = outline->next;
00075       other_outline;
00076     last_outline = other_outline, other_outline = other_outline->next) {
00077 
00078       if (same_outline_bounds (outline, other_outline)) {
00079         last_outline->next = other_outline->next;
00080         // This doesn't leak - the outlines share the EDGEPTs.
00081         other_outline->loop = NULL;
00082         delete other_outline;
00083         other_outline = last_outline;
00084         // If it is part of a cut, then it can't be a hole any more.
00085         outline->is_hole = false;
00086       }
00087     }
00088   }
00089 }
00090 
00091 /**********************************************************************
00092  * setup_blob_outlines
00093  *
00094  * Set up each of the outlines in this blob.
00095  **********************************************************************/
00096 void setup_blob_outlines(TBLOB *blob) { 
00097   TESSLINE *outline;
00098 
00099   for (outline = blob->outlines; outline; outline = outline->next) {
00100     outline->ComputeBoundingBox();
00101   }
00102 }