wordrec/olutil.cpp

Go to the documentation of this file.
00001 
00020 /*----------------------------------------------------------------------
00021               I n c l u d e s
00022 ----------------------------------------------------------------------*/
00023 #include "olutil.h"
00024 #include "structures.h"
00025 #include "blobs.h"
00026 #include "const.h"
00027 
00028 #ifdef __UNIX__
00029 #include <assert.h>
00030 #endif
00031 
00032 /*----------------------------------------------------------------------
00033               F u n c t i o n s
00034 ----------------------------------------------------------------------*/
00035 /* ================== */
00039 void check_outline_mem() { 
00040   TESSLINE *outline;
00041 
00042   outline = newoutline ();
00043   outline->next = newoutline ();
00044   oldoutline (outline->next);
00045   oldoutline(outline); 
00046 
00047   outline = newoutline ();
00048   outline->next = newoutline ();
00049   oldoutline (outline->next);
00050   oldoutline(outline); 
00051 }
00052 
00053 
00054 /* ================== */
00060 void correct_blob_order(TBLOB *blob1, TBLOB *blob2) { 
00061   TPOINT origin1;
00062   TPOINT origin2;
00063   TESSLINE *temp;
00064 
00065   blob_origin(blob1, &origin1); 
00066   blob_origin(blob2, &origin2); 
00067 
00068   if (origin1.x > origin2.x) {
00069     temp = blob2->outlines;
00070     blob2->outlines = blob1->outlines;
00071     blob1->outlines = temp;
00072   }
00073 }
00074 
00075 
00076 /* ================== */
00080 void eliminate_duplicate_outlines(TBLOB *blob) { 
00081   TESSLINE *outline;
00082   TESSLINE *other_outline;
00083   TESSLINE *last_outline;
00084 
00085   for (outline = blob->outlines; outline; outline = outline->next) {
00086 
00087     for (last_outline = outline, other_outline = outline->next;
00088       other_outline;
00089     last_outline = other_outline, other_outline = other_outline->next) {
00090 
00091       if (same_outline_bounds (outline, other_outline)) {
00092         last_outline->next = other_outline->next;
00093         oldoutline(other_outline); 
00094         other_outline = last_outline;
00095       }
00096     }
00097   }
00098 }
00099 
00100 
00101 /* ================== */
00105 void setup_outline(TESSLINE *outline) { 
00106   register EDGEPT *this_edge;
00107   register int minx = MAXINT;
00108   register int miny = MAXINT;
00109   register int maxx = -MAXINT;
00110   register int maxy = -MAXINT;
00111 
00112   /* Find boundaries */
00113   this_edge = outline->loop;
00114   do {
00115     if (this_edge->pos.x < minx)
00116       minx = this_edge->pos.x;
00117     if (this_edge->pos.y < miny)
00118       miny = this_edge->pos.y;
00119     if (this_edge->pos.x > maxx)
00120       maxx = this_edge->pos.x;
00121     if (this_edge->pos.y > maxy)
00122       maxy = this_edge->pos.y;
00123     this_edge = this_edge->next;
00124   }
00125   while (this_edge != outline->loop);
00126   /* Reset bounds */
00127   outline->topleft.x = minx;
00128   outline->topleft.y = maxy;
00129   outline->botright.x = maxx;
00130   outline->botright.y = miny;
00131 }
00132 
00133 
00134 /* ================== */
00138 void setup_blob_outlines(TBLOB *blob) { 
00139   TESSLINE *outline;
00140 
00141   for (outline = blob->outlines; outline; outline = outline->next) {
00142     setup_outline(outline); 
00143   }
00144 }

Generated on Wed Feb 28 19:49:13 2007 for Tesseract by  doxygen 1.5.1