reference/ocr-new/Component.h
changeset 0 6b8091ca909a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/reference/ocr-new/Component.h	Thu May 18 23:12:51 2006 +0200
@@ -0,0 +1,167 @@
+#ifndef _COMPONENT_H
+#define _COMPONENT_H
+#include "stdlib.h"
+#include <iostream.h>
+#include "Point.h"
+#include "system.h" 
+#include "list.h"
+#include "RLEMap.h"
+
+
+class BitMap;
+
+class Component;
+
+class Components: public List
+{
+ public:
+  Components();
+  ~Components();
+  
+  Component * compAt(Point p);   // returns smallest component that contains
+                                 // this point.
+     
+
+};
+
+class Component{
+      public:
+        friend class Word;
+       	Component(Point ul, Point lr)
+	  :ful(ul), flr(lr), fnumBits(0),fasciiId(NULL), fconfid(0),
+	  charGroup(0), ffontId(0)
+	    { fproperty = new Property[numProperties];
+	      for (int i = 0; i < numProperties; i++)
+	         fproperty[i] = 0;};
+
+	Component()
+	  :ful(-1), flr(-1), fnumBits(0),fasciiId(0),fconfid(0),
+	  charGroup(0), ffontId(0)
+	    { fproperty = new Property[numProperties];
+	      for (int i = 0; i < numProperties; i++)
+	         fproperty[i] = 0;};
+	~Component(){
+	    if (fproperty != NULL) delete fproperty;
+	    if (fasciiId != NULL)  delete fasciiId;
+	  }
+
+         Component * copy(); // make a new copy of the component
+	 inline Point & ul() {return ful;};
+	 inline Point & lr() {return flr;};
+
+	 inline double width() {return (double)(flr.x() - ful.x() + 1); };
+	 inline double height() {return (double)(flr.y() - ful.y() + 1); };
+         inline double area() { return width()*height(); };
+         inline int & numBits(){return fnumBits;};
+	 short int charGroup; // values 0-3: 0=acemno, 1=gpqy, 2=dfhikl, 3=j([}
+         int vertShrink(BitMap * bitmap);	
+         int horizontalShrink(BitMap * bitmap);
+
+	int AddToComponent(ListElement* intrvl, RLEMap* rlemap, int horizMerge);
+	/*--------------------------------------------------------------
+	Primary Purpose: Extend boundaries of component by connected intervals.       Arguments: startIntrvl is interval to start from
+        Return Value: Number of intervals added. 
+	Effects: Updates component's LR and UL. Deletes all added intervals. 
+	----------------------------------------------------------------*/
+
+	 // Access entire property vector
+	 inline Property * properties()
+	   {return fproperty;}
+
+	 // Set or read one value in property vector
+	 inline Property & property(int p) // Possibly use overload []
+	   {return fproperty[p];};
+
+	 // Set or read ascii id;
+	 inline Character & asciiId(){ return fasciiId[0];};
+
+	 inline int asciiLen(){return strlen(fasciiId);}
+	// Set or read font id;
+	inline short int & fontId() {return ffontId;};
+
+	 inline Confidence & confid(){ return fconfid; };
+	// Determine heuristic distance between this and comp
+	 Distance distance(Component * comp);
+
+         Point Component::center() { return (Point((ful.x() + flr.x())/2, 
+						  (ful.y() +flr.y())/2)); };
+	// Use the BitMap map to set the property vector for 
+        // this component
+
+         
+	void setProperties(RLEMap * map);
+	void setProperties(BitMap * map);
+	void setSectionFlags(short int hflag[], short int vflag[]);
+
+  
+	void display_bounding_box();
+        void display_bounding_box(char * color);     
+        void display_bounding_box(char * color,  double scaleFactor,  
+				  char * window);
+	Distance recognize(Component * learnedchars);
+	// find best match in learned characters.  Set ascii value
+        // and return distance.
+
+
+	Distance recognize(Components * learnedgroups, bool allGroups=FALSE);
+	// find best match from learned character groups. Set ascii value
+        // and return distance.
+
+        void join(Component * comp);
+        inline bool operator < (Component * comp)
+                 {if((ul().y() < comp->ul().y()))  return TRUE;
+		  if((ul().y() > comp->ul().y())) return FALSE;
+		  // otherwise if y values are equal
+		  return ((ul().x() <= comp->ul().x()) ?  TRUE : FALSE);
+		  }
+        inline bool operator > (Component * comp)
+                 {if((ul().y() > comp->ul().y()))  return TRUE;
+		  if((ul().y() < comp->ul().y())) return FALSE;
+		  // otherwise if y values are equal
+		  return((ul().x() > comp->ul().x()) ? TRUE : FALSE);
+		  
+		 }        
+  inline bool xoverlap(Component * comp)
+                  {
+		   if (ful.x() <= comp->ul().x() && comp->ul().x() <= flr.x())
+		     return TRUE;
+		   if (comp->ul().x() < ful.x() && ful.x() < comp->lr().x())
+		     return TRUE;
+		   return FALSE;
+		     }
+    
+        Property * fproperty;
+       	char * fasciiId;
+      private:
+       	Point ful;
+      	Point flr;
+       	int fnumBits;
+
+
+
+	short int ffontId;
+       	Confidence fconfid;     
+};
+
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+