Page.h

00001 # ifndef Page_h
00002 # define Page_h Page_h
00003 
00004 // C++ Dependencies
00005 # include <iostream>
00006 # include "Element.h"
00007 
00008 // Declaration
00009 namespace Conjecture {
00010 
00011     // C++ Dependencies
00012     class Env;             // belongs-to
00013     class OCRModule;       // returns
00014     
00015     /***********************************************************************
00016      * \class Page
00017      *
00018      * \brief An Image and associated meta-data representing an entire
00019      * page of to-be-scanned data.
00020      *
00021      * This class is one of the most important in the Part hierarchy. It
00022      * may be sub-divided into Regions, Lines, Words and/or Glyphs,
00023      * although only Glyphs are crucial.  It plays a special role relative
00024      * to other Part subclasses:
00025      *  - it is the only Part that does not have a containing parent.
00026      *  - it is the only Part to maintain an Image
00027      *  - all other Parts are contained within a Page, and can eventually
00028      *    obtain a Page (and thus an Image) by following their 'parent'
00029      *    pointer.
00030      * See the documentation in Part for more details on this.
00031      *
00032      * Much of the high-level segmenting functionality is defined on
00033      * this class, and can be redefined by subclasses. Segmenting
00034      * includes region detection, picture detection, noise removal, line
00035      * detection, glyph detection, etc. etc., but does not involve
00036      * glyph-to-character identification (see Glyph for the
00037      * identification interface).
00038      *
00039      * Each Page is associated with a file (representing the input image
00040      * to be analyzed) and an Image (describing the in-memory
00041      * representation of the file).
00042      *
00043      **********************************************************************/
00044 
00045     class Page : public Element {
00046         // For now, Env gets to set certain fields of Page that
00047         // violate total encapsulation. FUTURE FIX: This 'friend'
00048         // statement needs to be refined to a list of methods within
00049         // Env - the current statement is unnecessarily permissive.
00050         // And if possible, the friendship should be removed entirely.
00051         friend class Env;
00052 
00053         // In order to allow all Parts access to an image stored only
00054         // in Page, we must allow Part::image access to
00055         // Page::imageRef()
00056         friend const Image* Element::pageImage() const;
00057 
00058       public:
00059         /*
00060          * The "normal" way to create a Page instance
00061          *
00062          */
00063         Page(Env* env, const std::string& file);
00064 
00065         /*
00066          * A "special" Page constructor used to establish training sets.
00067          *
00068          */
00069         Page(Env* env, const std::string& imagefile, const std::string& validfile);
00070 
00076         virtual bool process();
00077 
00089         virtual bool segment();
00090 
00101         virtual bool identify();
00102 
00115         virtual bool format();
00116 
00122         virtual Page* asPage() { return this; }
00123         virtual const Page* asPage() const { return this; }
00124 
00129         virtual void printSummary(std::ostream& os = std::cerr, const std::string& indent = "", int index = -1) const;
00130 
00139         virtual void writeText(std::ostream& os) const;
00140 
00150         static void test(int argc = 0, const char* argv[] = NULL);
00151 
00152         // *********
00153         // Accessors
00154         inline const Env* env()           const { return this->_env;   }
00155         inline const std::string & file() const { return this->_file;  }
00156         inline const Image*    image()    const { return this->_image; }
00157 
00158       protected:
00159         OCRModule* algorithms() const;
00160 
00161         // *********
00162         // Accessors
00163         inline void envIs(Env* env) { this->_env = env; }
00164         inline void fileIs(const std::string & file) { this->_file = file; }
00165         virtual int type() const    { return Type; }
00166         inline void imageIs(Image* image) { this->_image = image; }
00167 
00168       private:
00169         // *********
00170         // Accessors
00171         inline Env* &          envRef()  { return this->_env;  }
00172         inline std::string &   fileRef() { return this->_file; }
00173         inline Image* &        imageRef() { return this->_image; }
00174 
00175         // *****
00176         // State
00177         static const ElementType Type = ELEMENT_PAGE;
00178 
00196          Env*            _env;
00197 
00198          /*
00199           * The input file to be processed.
00200           *
00201           * This file is also used to establish a prefix for various
00202           * output files.
00203           */
00204          std::string     _file;
00205 
00216          Image*          _image;
00217     };
00218 };
00219 
00220 // C++ Dependencies
00221 # include "Env.h"    // belongs-to
00222 
00223 # endif // Page_h
00224 

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