OptIm.h

00001 # ifndef Conjecture_OptIm_h
00002 # define Conjecture_OptIm_h Conjecture_OptIm_h
00003 
00004 // Insert SVN header substitution variable here
00005 // Created by wade
00006 // Class Champion: Unassigned
00007 
00008 # include <vector>
00009 # include "Root.h"  // parent
00010 # include "PixelLine.h" // has-a
00011 
00012 # include "GlyphFeatures.h"  // Variant
00013 
00014 
00015 namespace Conjecture {
00016     class Image;
00017     class ImageArgs;
00018     
00104     class OptIm : public Root {
00105         friend class PixFilt;
00106 
00107       public:
00108         // Types
00109         typedef std::vector<PixelLine> PixelMatrix;
00110 
00111         // Constructors/Destructors
00112         OptIm(const std::vector<unsigned int>& rows, u1 width = PixelLine::MaxPixels);
00113         OptIm(const Image* image, const ImageArgs& config);
00114         
00115         //static u1 BitImage(const Image* image, const ImageArgs& args, std::vector<u4>& rows);
00116 
00117         // Accessors
00118         inline const u1 & width() const { return this->_width; }
00119         inline const PixelMatrix & cols() const { return this->_cols; }
00120         inline const PixelMatrix & rows() const { return this->_rows; }
00121         
00122         // Input/Output
00123         
00124         // Interface
00125         void updateMeta();
00126 
00127         // FUTURE FIX: These methods currently return 0 if the
00128         // instance isn't updated. Should we just be updateding the image
00129         // automatically? Or should we throw asserts that are removed
00130         // in production code?
00131 
00136         int rblack(u1 i) const { return (this->updated() ? this->rows()[i].black() : 0); }
00137 
00142         int rholes(u1 i) const { return (this->updated() ? this->rows()[i].holes() : 0); }
00143 
00148         int cblack(u1 i) const { return (this->updated() ? this->cols()[i].black() : 0); }
00149 
00154         int choles(u1 i) const { return (this->updated() ? this->cols()[i].holes() : 0); }
00155 
00156         u1 height() const { return this->rows().size(); } 
00157 
00163         inline bool get(u2 x, u2 y) const { int w = this->width(); return this->rows()[y].get(w-1-x); }
00164 
00171         inline std::string str(char on = '#', char off = '.') const { return this->str("",0,on,off); }
00172 
00180         std::string str(const std::string& title, int valign = 0, char on = '#', char off = '.') const;
00181 
00198         bool crop(int level = 0);
00199         bool crop(int topthick, int bottomthick, int leftthick, int rightthick);
00200         bool crop(int topthick, int bottomthick, int leftthick, int rightthick, int& topref, int& bottomref, int& leftref, int& rightref);
00201 
00212         void identifyFeatures(GlyphFeatures& features);
00213         
00220         inline const PixelLine& row(int i) const {
00221             if ( i < 0 ) { i += this->height(); }
00222             return this->rows()[i];
00223         }
00224 
00233         bool removeBottomSerifs();
00234 
00243         bool removeTopSerifs();
00244 
00245         static void test(int argc = 0, const char* argv[] = NULL);
00246 
00247         inline void print(ostream& os = cout) const { os << this->str() << endl; }
00248         
00249       protected:
00250         // Accessors
00251         inline bool  updated() const                                 { return this->_updated; }
00252         inline void  updatedIs(const bool & updated)                   { this->_updated = updated; }
00253         inline void  widthIs(const u1 & width)                     { this->_width = width; }
00254         inline void  colsIs(const PixelMatrix & cols) { this->_cols  = cols;  }
00255         inline void  rowsIs(const PixelMatrix & rows) { this->_rows  = rows;  }
00256         
00257         // Methods 
00258         std::string rawstr(const PixelMatrix& vec, char on = '1', char off = '0', unsigned char size = PixelLine::MaxPixels) const;
00259 
00260         * Obtain a specific writeable PixelLine by row. Negative
00261         * indexes are relative to the end (-1 is last index, -2 is
00262         * second last, etc.)
00263         inline PixelLine& row(int i) {
00264             if ( i < 0 ) { i += this->height(); }
00265             return this->rowsRef()[i];
00266         }
00267 
00268         GlyphFeatures::Variant analyzeLines(u1 min, u2 max, const PixelMatrix& matrix, u1 dom, u1 rec, u1 halfn);
00269         
00270       private: 
00271         // Accessors
00272         inline bool& updatedRef()                   { return this->_updated; }
00273         inline u1& widthRef()                       { return this->_width; }
00274         inline PixelMatrix& colsRef()  { return this->_cols;  }
00275         inline PixelMatrix& rowsRef()  { return this->_rows;  }
00276         
00277         // Methods 
00278         
00279         // State
00280 
00286         bool                     _updated;
00287 
00301         u1                       _width;
00302 
00307         PixelMatrix _rows;
00308 
00313         PixelMatrix _cols;
00314     };
00315 }
00316 
00317 # endif // Conjecture_OptIm_h
00318 

Generated on Thu Jun 15 19:56:10 2006 for Conjecture by  doxygen 1.4.6