00001 # ifndef Conjecture_Element_h
00002 # define Conjecture_Element_h Conjecture_Element_h
00003
00004
00005
00006
00007
00008 # include "Root.h"
00009 # include <list>
00010 # include <vector>
00011 # include <iostream>
00012 # include "Coord.h"
00013 # include "ImageArgs.h"
00014
00015
00016 namespace Conjecture {
00017
00018 class Page;
00019 class Region;
00020 class Line;
00021 class Word;
00022 class Glyph;
00023 class Image;
00024
00025
00026 typedef enum ElementType {
00027 ELEMENT_PAGE,
00028 ELEMENT_REGION,
00029 ELEMENT_LINE,
00030 ELEMENT_WORD,
00031 ELEMENT_GLYPH
00032 };
00033
00120 class Element : public Root {
00121 public:
00122
00123 typedef std::list<Element*> ElementList;
00124
00143 Element(Element* parent, const Coord& topleft, const Coord& size);
00144 virtual ~Element();
00145
00151 inline void markInvisible(bool invisible = true) { this->invisibleIs(invisible); }
00152
00171 virtual int type() const;
00172
00177 void registerElement(Element* part);
00178 Element* firstElement() const { return ( this->parts().empty() ) ? NULL : this->parts().front(); }
00179 Element* lastElement() const { return ( this->parts().empty() ) ? NULL : this->parts().back(); }
00180
00181 Coord size() const { return Coord( this->width(), this->height() ); }
00182
00191 void allGlyphs(std::vector<Glyph*>& glyphs);
00192 void allGlyphs(std::vector<const Glyph*>& glyphs) const;
00193
00209 Page* containingPage() const;
00210
00222 virtual const Image* pageImage() const;
00223
00228 virtual void writeText(std::ostream& os) const;
00229
00240 void writeImage(const std::string& filebase, const ImageArgs& config);
00241
00250 virtual Page* asPage() { return NULL; }
00251 virtual Region* asRegion() { return NULL; }
00252 virtual Line* asLine() { return NULL; }
00253 virtual Word* asWord() { return NULL; }
00254 virtual Glyph* asGlyph() { return NULL; }
00255
00256 virtual const Page* asPage() const { return NULL; }
00257 virtual const Region* asRegion() const { return NULL; }
00258 virtual const Line* asLine() const { return NULL; }
00259 virtual const Word* asWord() const { return NULL; }
00260 virtual const Glyph* asGlyph() const { return NULL; }
00261
00266 inline int height() const { return this->bottomright().y - this->topleft().y + 1; }
00267
00272 inline int width() const { return this->bottomright().x - this->topleft().x + 1; }
00273
00274
00275 u2 topY() const { return this->topleft().y; }
00276 u2 bottomY() const { return this->bottomright().y; }
00277 u2 leftX() const { return this->topleft().x; }
00278 u2 rightX() const { return this->bottomright().x; }
00279
00280
00281
00282
00283
00288 void printStructure(std::ostream& os = std::cerr, const std::string& indent = "") const;
00289
00294 virtual void printSummary(std::ostream& os = std::cerr, const std::string& indent = "", int index = -1) const;
00295
00300 void writeGlyphs(const std::string& dir, const ImageArgs& adj) const;
00301
00315 virtual std::string id() const;
00316
00325 int findIndex(const Element* image) const;
00326
00336 static void test(int argc = 0, const char* argv[] = NULL);
00337
00338 inline ElementList & partsRef() { return this->_parts; }
00339
00340
00341 inline const Coord & topleft() const { return this->_topleft; }
00342 inline const Coord & bottomright() const { return this->_bottomright; }
00343 inline const ElementList& parts() const { return this->_parts; }
00344 inline const Element* parent() const { return this->_parent; }
00345 inline bool invisible() const { return this->_invisible; }
00346
00347 protected:
00348
00349 inline void topleftIs(const Coord & topleft) { this->_topleft = topleft; }
00350 inline Coord & topleftRef() { return this->_topleft; }
00351 inline void bottomrightIs(const Coord & bottomright) { this->_bottomright = bottomright; }
00352 inline Coord & bottomrightRef() { return this->_bottomright; }
00353 inline void partsIs(const ElementList & parts) { this->_parts = parts; }
00354 inline void parentIs(Element* parent) { this->_parent = parent; }
00355 inline Element* & parentRef() { return this->_parent; }
00356 inline void invisibleIs(bool invisible) { this->_invisible = invisible; }
00357
00358
00359
00360
00361 static char* ClassName[6];
00362
00363 private:
00364
00365 inline bool& invisibleRef() { return this->_invisible; }
00366
00367
00368
00369
00370
00371
00378 Coord _topleft;
00379
00386 Coord _bottomright;
00387
00408 Element* _parent;
00409
00436 ElementList _parts;
00437
00452 bool _invisible;
00453 };
00454 };
00455
00456 # endif // Conjecture_Element_h
00457