GlyphFeatures.h

00001 # ifndef GlyphFeatures_h
00002 # define GlyphFeatures_h GlyphFeatures_h
00003 
00004 // ####################################################################
00005 // # Conjecture: An Extensible Optical Character Recognition Framework  #
00006 // #                                                                  #
00007 // # Copyright: Lesser GNU Public License (LGPL)                      #
00008 // #                                                                  #
00009 // # Overview:                                                        #
00010 // #  - Conjecture is a collection of C++ classes, and an OCR engine    #
00011 // #  - Conjecture is designed to allow customization at all levels     #
00012 // #    and to encourage individuals to contribute incremental        #
00013 // #    improvements in algorithms.                                   #
00014 // #  - Overall design discussions can be found in                    #
00015 // #      $SNROOT/docs/doxygen/html/index.html                        #
00016 // #  - Conjecture is designed to interact with and build on other      #
00017 // #    open-source OCR programs.                                     #
00018 // ####################################################################
00019 // Created 2006/06/10 by wade
00020 
00021 # include "Root.h"  // parent
00022 
00023 // PRIVATE - will be removed later
00024 # include <vector>
00025 
00026 namespace Conjecture {
00027     class Glyph;
00028     
00029     // ##################################################################
00095 
00096     // ##################################################################
00097     class GlyphFeatures : public Root {
00098       public:
00099         // Types
00100 
00117         typedef float Confidence;
00118 
00132         typedef enum { 
00133             // CODE TANGLE #2: The ordinal values assigned to these
00134             // are tangled with the _LineTypes field init in the .cc
00135             LTUnknown = 0,
00136             Base      = 1, 
00137             Ascender  = 2, 
00138             Descender = 3, 
00139             Total     = 4,
00140             // this should always be last one
00141             __LTSIZE  = 5,
00142         } LineType;
00143 
00153         typedef enum {
00154             // CODE TANGLE #2: The ordinal values assigned to these
00155             // are tangled with the _Variants field init in the .cc!
00156             Center     = 1,
00157             Top        = 2,
00158             Bottom     = 3,
00159             Left       = 4,
00160             Right      = 5,
00161             Dominant   = 8,
00162             Recessive  = 9,
00163             HalfLine   = 10,
00164             // Undef should always be the highest ordinal value
00165             Undef      = 11,
00166         } Variant;
00167 
00168       private:
00169         static const char* _LineTypes[__LTSIZE+1];
00170         static std::string LineTypeStr(LineType v);
00171 
00172         static const char* _Variants[Undef+1];
00173         static std::string VariantStr(Variant v);
00174 
00181         typedef std::vector<Variant> VariantSet;
00182         typedef std::pair<Variant,Variant> Variant2;
00183         typedef std::vector<Variant2> Variant2Set;
00184 
00185       public:
00186         // Constructors/Destructors
00187         GlyphFeatures(LineType lineType = LTUnknown);
00188 
00229         GlyphFeatures(wchar_t unicode, LineType lineType, const std::string& spec);
00230 
00231         void init(wchar_t unicode, LineType lineType);
00232         
00233         // **************
00234         // Accessors
00235         inline wchar_t unicode()          const { return this->_unicode; }
00236         inline bool xdisconnect()         const { return this->_xdisconnect; }
00237         inline bool ydisconnect()         const { return this->_ydisconnect; }
00238         inline float MostOfLength()       const { return this->_MostOfLength; }
00239         inline const LineType& lineType() const { return this->_lineType; }
00240         
00241         // **************
00242         // Input/Output
00243         
00244         // **************
00245         // Interface
00246         void addHorizontal(Variant position, Variant length);
00247         void addVertical(Variant position, Variant length);
00248         void addHole(Variant position);
00249         void addCup(Variant position);
00250 
00255 
00261         Variant hasHorizontal(Variant position) const;
00262         Variant hasVertical(Variant position) const;
00263         bool hasHole(Variant position) const;
00264         bool hasCup(Variant position) const;
00265 
00266 
00268         std::ostream& print(std::ostream& os = std::cout, const std::string& indent = "") const;
00269 
00270         static void Test(int argc = 0, const char* argv[] = NULL);
00271 
00332         Confidence matches(const GlyphFeatures& target) const;
00333         
00334       protected:
00335         // **************
00336         // Accessors
00337         inline void            unicodeIs(const wchar_t & unicode)      { this->_unicode = unicode;           }
00338         inline void            xdisconnectIs(const bool & xdisconnect) { this->_xdisconnect = xdisconnect;   }
00339         inline void            ydisconnectIs(const bool & ydisconnect) { this->_ydisconnect = ydisconnect;   }
00340         inline void            lineTypeIs(const LineType & lineType)   { this->_lineType = lineType;         }
00341         inline void            MostOfLengthIs(float MostOfLength)      { this->_MostOfLength = MostOfLength; }
00342 
00343         // Placed at protected scope so as not to expose Variant[2]Set to public scope
00344         inline const Variant2Set & horizontal() const { return this->_horizontal; }
00345         inline const Variant2Set & vertical() const { return this->_vertical; }
00346         inline const VariantSet  & holes() const { return this->_holes; }
00347         inline const VariantSet  & cups() const { return this->_cups; }
00348 
00349         inline wchar_t &       unicodeRef()     { return this->_unicode; }
00350         inline bool &          xdisconnectRef() { return this->_xdisconnect; }
00351         inline bool &          ydisconnectRef() { return this->_ydisconnect; }
00352         inline LineType &      lineTypeRef()    { return this->_lineType;    }
00353         inline Variant2Set &   horizontalRef()  { return this->_horizontal;  }
00354         inline Variant2Set &   verticalRef()    { return this->_vertical;    }
00355         inline VariantSet &    holesRef()       { return this->_holes;       }
00356         inline VariantSet &    cupsRef()        { return this->_cups;        }
00357         
00358         // **************
00359         // Methods
00360         Confidence lineMatch(Variant mine, Variant target) const;
00361         
00362       private: 
00363         // **************
00364         // Accessors
00365         inline float &         MostOfLengthRef() { return this->_MostOfLength; }
00366         
00367         // **************
00368         // Methods 
00369         
00370         // **************
00371         // State
00372         wchar_t         _unicode;
00373         bool            _xdisconnect;
00374         bool            _ydisconnect;
00375 
00382         LineType               _lineType;
00383 
00384         Variant2Set            _horizontal;
00385         Variant2Set            _vertical;
00386         VariantSet             _holes;
00387         VariantSet             _cups;
00388 
00389         static float           _MostOfLength;
00390     };
00391 }
00392 
00393 # endif // GlyphFeatures_h
00394 

Generated on Wed Jun 14 15:08:02 2006 for Conjecture by  doxygen 1.4.6