PixelLine.h

00001 # ifndef PixelLine_h
00002 # define PixelLine_h PixelLine_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 
00020 # include "Root.h"  // parent
00021 
00022 namespace Conjecture {
00023     class OptIm;  // friend declaration
00024     
00025     // ##################################################################
00032     // ##################################################################
00033     
00034     // IMPLEMENTATION NOTES:
00035     //   - this class is designed for highly efficient space utiliation,
00036     //     while also providing support for highly efficient feature
00037     //     analysis.
00038     //   - some "auxillary" methods are quite slow (i.e. 'set' and
00039     //     'clear' - this class is meant to be used primarily on
00040     //     frozen images, so setting and clearing bits is not a
00041     //     priority for efficient implementation.
00042     //   - does NOT store the size of the pixel line (assumed to be
00043     //     be maintained elsewhere). This implies that the number of
00044     //     white pixels cannot be reported without obtaining the size
00045     //     (#black is stored, and #white = total - #black).
00046     //   - not using setters internally in some situations because
00047     //     bit-specifiers cause temporaries to be used in returns
00048     // ##################################################################
00049     class PixelLine : public Root {
00050       public:
00051         static const u1 MaxPixels = 31;
00052 
00053         // Constructors/Destructors
00054         PixelLine(u4 pixels);
00055         
00056         // **************
00057         // Accessors
00058         inline u1   holes()  const { return this->_holes;  }
00059         inline u4   pixels() const { return this->_pixels; }
00060         inline u1   black()  const { return this->_black;  }
00061         
00062         // **************
00063         // Input/Output
00064         
00065         // **************
00066         // Interface
00067 
00073         inline bool get(unsigned i) const {
00074             return (this->pixels() & (1<<i)) ? true : false;
00075         }
00076         
00083         void set(unsigned i);
00084 
00091         void clear(unsigned i);
00092         
00094         std::string str(char on = '#', char off = '.', u1 size = 31) const;
00095         inline std::string str(u1 size) const { return this->str('#','.',size); }
00096 
00104         void assign(const PixelLine& other, u1 rightdel = 0);
00105 
00106         static void test(int argc = 0, const char* argv[] = NULL);
00107 
00108       protected:
00109         // **************
00110         // Accessors
00111         inline const bool &    updated() const { return this->_updated; }
00112         inline void            updatedIs(const bool & updated) { this->_updated = updated; }
00113         inline void            blackIs(const u1 & black) { this->_black = black; }
00114         inline void            holesIs(const u1 & holes)   { this->_holes = holes; }
00115         inline void            pixelsIs(const u4 & pixels) { this->_pixels = pixels; }
00116         
00117         // **************
00118         // Methods 
00119         inline void rawset(unsigned i)   { this->_pixels |= (1<<i);  }
00120         inline void rawclear(unsigned i) { this->_pixels &= ~(1<<i); }
00121 
00122         inline void rawline(u4 pixels) { this->_pixels = pixels; this->updatedIs(false); }
00123 
00124         
00125       private: 
00127         friend class PixFilt;
00129         friend class OptIm;
00130 
00131         // **************
00132         // Accessors
00133         
00134         // **************
00135         // Methods 
00136         void updateMeta();
00137 
00138         // **************
00139         // State
00140 
00148         u4              _pixels;
00149 
00160         unsigned int    _holes:4;
00161 
00166         u1              _black:5;
00167 
00173         bool            _updated;
00174 
00182     };
00183 }
00184 
00185 # endif // PixelLine_h
00186 

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