Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Friends
TBOX Class Reference

`#include <rect.h>`

List of all members.

## Public Member Functions
| TBOX ()
| TBOX (const ICOORD pt1, const ICOORD pt2)
| TBOX (inT16 left, inT16 bottom, inT16 right, inT16 top)
| TBOX (const FCOORD pt)
bool | null_box () const
bool | operator== (const TBOX &other) const
inT16 | top () const
void | set_top (int y)
inT16 | bottom () const
void | set_bottom (int y)
inT16 | left () const
void | set_left (int x)
inT16 | right () const
void | set_right (int x)
const ICOORD & | botleft () const
ICOORD | botright () const
ICOORD | topleft () const
const ICOORD & | topright () const
inT16 | height () const
inT16 | width () const
inT32 | area () const
void | pad (int xpad, int ypad)
void | move_bottom_edge (const inT16 y)
void | move_left_edge (const inT16 x)
void | move_right_edge (const inT16 x)
void | move_top_edge (const inT16 y)
void | move (const ICOORD vec)
void | move (const FCOORD vec)
void | scale (const float f)
void | scale (const FCOORD vec)
void | rotate (const FCOORD &vec)
void | rotate_large (const FCOORD &vec)
bool | contains (const FCOORD pt) const
bool | contains (const TBOX &box) const
bool | overlap (const TBOX &box) const
bool | major_overlap (const TBOX &box) const
bool | x_overlap (const TBOX &box) const
int | x_gap (const TBOX &box) const
int | y_gap (const TBOX &box) const
bool | major_x_overlap (const TBOX &box) const
bool | y_overlap (const TBOX &box) const
bool | major_y_overlap (const TBOX &box) const
double | overlap_fraction (const TBOX &box) const
double | x_overlap_fraction (const TBOX &box) const
double | y_overlap_fraction (const TBOX &box) const
bool | x_almost_equal (const TBOX &box, int tolerance) const
bool | almost_equal (const TBOX &box, int tolerance) const
TBOX | intersection (const TBOX &box) const
TBOX | bounding_union (const TBOX &box) const
void | set_to_given_coords (int x_min, int y_min, int x_max, int y_max)
void | print () const
void | append_debug (STRING *str) const
void | plot (ScrollView *fd) const
void | plot (ScrollView *fd, ScrollView::Color fill_colour, ScrollView::Color border_colour) const
bool | Serialize (FILE *fp) const
bool | DeSerialize (bool swap, FILE *fp)

## Friends
TBOX & | operator+= (TBOX &, const TBOX &)
TBOX & | operator&= (TBOX &, const TBOX &)

## Detailed Description

Definition at line 29 of file rect.h.

## Constructor & Destructor Documentation

TBOX::TBOX | ( |  | ) |
| inline

Definition at line 31 of file rect.h.

: // empty constructor making a null box
bot_left (MAX_INT16, MAX_INT16), top_right (-MAX_INT16, -MAX_INT16) {
}

TBOX::TBOX | ( | const ICOORD | pt1,
|  | const ICOORD | pt2
| ) |  |

Definition at line 33 of file rect.cpp.

{
if (pt1.x () <= pt2.x ()) {
if (pt1.y () <= pt2.y ()) {
bot_left = pt1;
top_right = pt2;
}
else {
bot_left = ICOORD (pt1.x (), pt2.y ());
top_right = ICOORD (pt2.x (), pt1.y ());
}
}
else {
if (pt1.y () <= pt2.y ()) {
bot_left = ICOORD (pt2.x (), pt1.y ());
top_right = ICOORD (pt1.x (), pt2.y ());
}
else {
bot_left = pt2;
top_right = pt1;
}
}
}

TBOX::TBOX | ( | inT16 | left,
|  | inT16 | bottom,
|  | inT16 | right,
|  | inT16 | top
| ) |  |

Definition at line 65 of file rect.cpp.

: bot_left(left, bottom), top_right(right, top) {
}

TBOX::TBOX | ( | const FCOORD | pt | ) |
| inline

Definition at line 310 of file rect.h.

{
bot_left = ICOORD ((inT16) floor (pt.x ()), (inT16) floor (pt.y ()));
top_right = ICOORD ((inT16) ceil (pt.x ()), (inT16) ceil (pt.y ()));
}

## Member Function Documentation

bool TBOX::almost_equal | ( | const TBOX & | box,
|  | int | tolerance
| ) |  | const

Definition at line 249 of file rect.cpp.

{
return (abs(left() - box.left()) <= tolerance &&
abs(right() - box.right()) <= tolerance &&
abs(top() - box.top()) <= tolerance &&
abs(bottom() - box.bottom()) <= tolerance);
}

void TBOX::append_debug | ( | STRING * | str | ) | const
| inline

Definition at line 270 of file rect.h.

{
char buffer[256];
sprintf(buffer, "Bounding box=(%d,%d)->(%d,%d)\n",
left(), bottom(), right(), top());
*str += buffer;
}

inT32 TBOX::area | ( |  | ) | const
| inline

Definition at line 111 of file rect.h.

{ // what is the area?
if (!null_box ())
return width () * height ();
else
return 0;
}

const ICOORD& TBOX::botleft | ( |  | ) | const
| inline

Definition at line 81 of file rect.h.

{ // access function
return bot_left;
}

ICOORD TBOX::botright | ( |  | ) | const
| inline

Definition at line 85 of file rect.h.

{ // ~ access function
return ICOORD (top_right.x (), bot_left.y ());
}

inT16 TBOX::bottom | ( |  | ) | const
| inline

Definition at line 60 of file rect.h.

{ // coord of bottom
return bot_left.y ();
}

TBOX TBOX::bounding_union | ( | const TBOX & | box | ) | const

Definition at line 130 of file rect.cpp.

{
ICOORD bl; //bottom left
ICOORD tr; //top right
if (box.bot_left.x () < bot_left.x ())
bl.set_x (box.bot_left.x ());
else
bl.set_x (bot_left.x ());
if (box.top_right.x () > top_right.x ())
tr.set_x (box.top_right.x ());
else
tr.set_x (top_right.x ());
if (box.bot_left.y () < bot_left.y ())
bl.set_y (box.bot_left.y ());
else
bl.set_y (bot_left.y ());
if (box.top_right.y () > top_right.y ())
tr.set_y (box.top_right.y ());
else
tr.set_y (top_right.y ());
return TBOX (bl, tr);
}

bool TBOX::contains | ( | const FCOORD | pt | ) | const
| inline

Definition at line 323 of file rect.h.

{
return ((pt.x () >= bot_left.x ()) &&
(pt.x () <= top_right.x ()) &&
(pt.y () >= bot_left.y ()) && (pt.y () <= top_right.y ()));
}

bool TBOX::contains | ( | const TBOX & | box | ) | const
| inline

Definition at line 335 of file rect.h.

{
return (contains (box.bot_left) && contains (box.top_right));
}

bool TBOX::DeSerialize | ( | bool | swap,
|  | FILE * | fp
| ) |  |

Definition at line 183 of file rect.cpp.

{
if (!bot_left.DeSerialize(swap, fp)) return false;
if (!top_right.DeSerialize(swap, fp)) return false;
return true;
}

inT16 TBOX::height | ( |  | ) | const
| inline

Definition at line 97 of file rect.h.

{ // how high is it?
if (!null_box ())
return top_right.y () - bot_left.y ();
else
return 0;
}

TBOX TBOX::intersection | ( | const TBOX & | box | ) | const

Definition at line 88 of file rect.cpp.

{
inT16 left;
inT16 bottom;
inT16 right;
inT16 top;
if (overlap (box)) {
if (box.bot_left.x () > bot_left.x ())
left = box.bot_left.x ();
else
left = bot_left.x ();
if (box.top_right.x () < top_right.x ())
right = box.top_right.x ();
else
right = top_right.x ();
if (box.bot_left.y () > bot_left.y ())
bottom = box.bot_left.y ();
else
bottom = bot_left.y ();
if (box.top_right.y () < top_right.y ())
top = box.top_right.y ();
else
top = top_right.y ();
}
else {
left = MAX_INT16;
bottom = MAX_INT16;
top = -MAX_INT16;
right = -MAX_INT16;
}
return TBOX (left, bottom, right, top);
}

inT16 TBOX::left | ( |  | ) | const
| inline

Definition at line 67 of file rect.h.

{ // coord of left
return bot_left.x ();
}

bool TBOX::major_overlap | ( | const TBOX & | box | ) | const
| inline

Definition at line 358 of file rect.h.

{
int overlap = MIN(box.top_right.x(), top_right.x());
overlap -= MAX(box.bot_left.x(), bot_left.x());
overlap += overlap;
if (overlap < MIN(box.width(), width()))
return false;
overlap = MIN(box.top_right.y(), top_right.y());
overlap -= MAX(box.bot_left.y(), bot_left.y());
overlap += overlap;
if (overlap < MIN(box.height(), height()))
return false;
return true;
}

bool TBOX::major_x_overlap | ( | const TBOX & | box | ) | const
| inline

Definition at line 402 of file rect.h.

{
inT16 overlap = box.width();
if (this->left() > box.left()) {
overlap -= this->left() - box.left();
}
if (this->right() < box.right()) {
overlap -= box.right() - this->right();
}
return (overlap >= box.width() / 2 || overlap >= this->width() / 2);
}

bool TBOX::major_y_overlap | ( | const TBOX & | box | ) | const
| inline

Definition at line 429 of file rect.h.

{
inT16 overlap = box.height();
if (this->bottom() > box.bottom()) {
overlap -= this->bottom() - box.bottom();
}
if (this->top() < box.top()) {
overlap -= box.top() - this->top();
}
return (overlap >= box.height() / 2 || overlap >= this->height() / 2);
}

void TBOX::move | ( | const ICOORD | vec | ) |
| inline

Definition at line 146 of file rect.h.

{ // by vector
bot_left += vec;
top_right += vec;
}

void TBOX::move | ( | const FCOORD | vec | ) |
| inline

Definition at line 152 of file rect.h.

{ // by float vector
bot_left.set_x ((inT16) floor (bot_left.x () + vec.x ()));
// round left
bot_left.set_y ((inT16) floor (bot_left.y () + vec.y ()));
// round down
top_right.set_x ((inT16) ceil (top_right.x () + vec.x ()));
// round right
top_right.set_y ((inT16) ceil (top_right.y () + vec.y ()));
// round up
}

void TBOX::move_bottom_edge | ( | const inT16 | y | ) |
| inline

Definition at line 126 of file rect.h.

{ // by +/- y
bot_left += ICOORD (0, y);
}

void TBOX::move_left_edge | ( | const inT16 | x | ) |
| inline

Definition at line 131 of file rect.h.

{ // by +/- x
bot_left += ICOORD (x, 0);
}

void TBOX::move_right_edge | ( | const inT16 | x | ) |
| inline

Definition at line 136 of file rect.h.

{ // by +/- x
top_right += ICOORD (x, 0);
}

void TBOX::move_top_edge | ( | const inT16 | y | ) |
| inline

Definition at line 141 of file rect.h.

{ // by +/- y
top_right += ICOORD (0, y);
}

bool TBOX::null_box | ( |  | ) | const
| inline

Definition at line 45 of file rect.h.

{ // Is box null
return ((left () >= right ()) || (top () <= bottom ()));
}

bool TBOX::operator== | ( | const TBOX & | other | ) | const
| inline

Definition at line 49 of file rect.h.

{
return bot_left == other.bot_left && top_right == other.top_right;
}

bool TBOX::overlap | ( | const TBOX & | box | ) | const
| inline

Definition at line 345 of file rect.h.

{
return ((box.bot_left.x () <= top_right.x ()) &&
(box.top_right.x () >= bot_left.x ()) &&
(box.bot_left.y () <= top_right.y ()) &&
(box.top_right.y () >= bot_left.y ()));
}

double TBOX::overlap_fraction | ( | const TBOX & | box | ) | const
| inline

Definition at line 378 of file rect.h.

{
double fraction = 0.0;
if (this->area()) {
fraction = this->intersection(box).area() * 1.0 / this->area();
}
return fraction;
}

void TBOX::pad | ( | int | xpad,
|  | int | ypad
| ) |  |
| inline

Definition at line 120 of file rect.h.

{
ICOORD pad(xpad, ypad);
bot_left -= pad;
top_right += pad;
}

void TBOX::plot | ( | ScrollView * | fd | ) | const
| inline

Definition at line 278 of file rect.h.

{ // where to paint
fd->Rectangle(bot_left.x (), bot_left.y (), top_right.x (),
top_right.y ());
}

void TBOX::plot | ( | ScrollView * | fd,
|  | ScrollView::Color | fill_colour,
|  | ScrollView::Color | border_colour
| ) |  | const

Definition at line 164 of file rect.cpp.

{
fd->Brush(fill_colour);
fd->Pen(border_colour);
plot(fd);
}

void TBOX::print | ( |  | ) | const
| inline

Definition at line 263 of file rect.h.

{ // print
tprintf("Bounding box=(%d,%d)->(%d,%d)\n",
left(), bottom(), right(), top());
}

inT16 TBOX::right | ( |  | ) | const
| inline

Definition at line 74 of file rect.h.

{ // coord of right
return top_right.x ();
}

void TBOX::rotate | ( | const FCOORD & | vec | ) |
| inline

Definition at line 182 of file rect.h.

{ // by vector
bot_left.rotate (vec);
top_right.rotate (vec);
*this = TBOX (bot_left, top_right);
}

void TBOX::rotate_large | ( | const FCOORD & | vec | ) |

Definition at line 73 of file rect.cpp.

{
ICOORD top_left(bot_left.x(), top_right.y());
ICOORD bottom_right(top_right.x(), bot_left.y());
top_left.rotate(vec);
bottom_right.rotate(vec);
rotate(vec);
TBOX box2(top_left, bottom_right);
*this += box2;
}

void TBOX::scale | ( | const float | f | ) |
| inline

Definition at line 164 of file rect.h.

{ // by multiplier
bot_left.set_x ((inT16) floor (bot_left.x () * f)); // round left
bot_left.set_y ((inT16) floor (bot_left.y () * f)); // round down
top_right.set_x ((inT16) ceil (top_right.x () * f)); // round right
top_right.set_y ((inT16) ceil (top_right.y () * f)); // round up
}

void TBOX::scale | ( | const FCOORD | vec | ) |
| inline

Definition at line 171 of file rect.h.

{ // by float vector
bot_left.set_x ((inT16) floor (bot_left.x () * vec.x ()));
bot_left.set_y ((inT16) floor (bot_left.y () * vec.y ()));
top_right.set_x ((inT16) ceil (top_right.x () * vec.x ()));
top_right.set_y ((inT16) ceil (top_right.y () * vec.y ()));
}

bool TBOX::Serialize | ( | FILE * | fp | ) | const

Definition at line 176 of file rect.cpp.

{
if (!bot_left.Serialize(fp)) return false;
if (!top_right.Serialize(fp)) return false;
return true;
}

void TBOX::set_bottom | ( | int | y | ) |
| inline

Definition at line 63 of file rect.h.

{
bot_left.set_y(y);
}

void TBOX::set_left | ( | int | x | ) |
| inline

Definition at line 70 of file rect.h.

{
bot_left.set_x(x);
}

void TBOX::set_right | ( | int | x | ) |
| inline

Definition at line 77 of file rect.h.

{
top_right.set_x(x);
}

void TBOX::set_to_given_coords | ( | int | x_min,
|  | int | y_min,
|  | int | x_max,
|  | int | y_max
| ) |  |
| inline

Definition at line 256 of file rect.h.

{
bot_left.set_x(x_min);
bot_left.set_y(y_min);
top_right.set_x(x_max);
top_right.set_y(y_max);
}

void TBOX::set_top | ( | int | y | ) |
| inline

Definition at line 56 of file rect.h.

{
top_right.set_y(y);
}

inT16 TBOX::top | ( |  | ) | const
| inline

Definition at line 53 of file rect.h.

{ // coord of top
return top_right.y ();
}

ICOORD TBOX::topleft | ( |  | ) | const
| inline

Definition at line 89 of file rect.h.

{ // ~ access function
return ICOORD (bot_left.x (), top_right.y ());
}

const ICOORD& TBOX::topright | ( |  | ) | const
| inline

Definition at line 93 of file rect.h.

{ // access function
return top_right;
}

inT16 TBOX::width | ( |  | ) | const
| inline

Definition at line 104 of file rect.h.

{ // how high is it?
if (!null_box ())
return top_right.x () - bot_left.x ();
else
return 0;
}

bool TBOX::x_almost_equal | ( | const TBOX & | box,
|  | int | tolerance
| ) |  | const

Definition at line 244 of file rect.cpp.

{
return (abs(left() - box.left()) <= tolerance &&
abs(right() - box.right()) <= tolerance);
}

int TBOX::x_gap | ( | const TBOX & | box | ) | const
| inline

Definition at line 210 of file rect.h.

{
return MAX(bot_left.x(), box.bot_left.x()) -
MIN(top_right.x(), box.top_right.x());
}

bool TBOX::x_overlap | ( | const TBOX & | box | ) | const
| inline

Definition at line 391 of file rect.h.

{
return ((box.bot_left.x() <= top_right.x()) &&
(box.top_right.x() >= bot_left.x()));
}

double TBOX::x_overlap_fraction | ( | const TBOX & | box | ) | const
| inline

Definition at line 447 of file rect.h.

{
int low = MAX(left(), other.left());
int high = MIN(right(), other.right());
int width = right() - left();
if (width == 0) {
int x = left();
if (other.left() <= x && x <= other.right())
return 1.0;
else
return 0.0;
} else {
return MAX(0, static_cast<double>(high - low) / width);
}
}

int TBOX::y_gap | ( | const TBOX & | box | ) | const
| inline

Definition at line 218 of file rect.h.

{
return MAX(bot_left.y(), box.bot_left.y()) -
MIN(top_right.y(), box.top_right.y());
}

bool TBOX::y_overlap | ( | const TBOX & | box | ) | const
| inline

Definition at line 418 of file rect.h.

{
return ((box.bot_left.y() <= top_right.y()) &&
(box.top_right.y() >= bot_left.y()));
}

double TBOX::y_overlap_fraction | ( | const TBOX & | box | ) | const
| inline

Definition at line 469 of file rect.h.

{
int low = MAX(bottom(), other.bottom());
int high = MIN(top(), other.top());
int height = top() - bottom();
if (height == 0) {
int y = bottom();
if (other.bottom() <= y && y <= other.top())
return 1.0;
else
return 0.0;
} else {
return MAX(0, static_cast<double>(high - low) / height);
}
}

## Friends And Related Function Documentation

TBOX& operator&= | ( | TBOX & | op1,
|  | const TBOX & | op2
| ) |  |
| friend

Definition at line 221 of file rect.cpp.

{
if (op1.overlap (op2)) {
if (op2.bot_left.x () > op1.bot_left.x ())
op1.bot_left.set_x (op2.bot_left.x ());
if (op2.top_right.x () < op1.top_right.x ())
op1.top_right.set_x (op2.top_right.x ());
if (op2.bot_left.y () > op1.bot_left.y ())
op1.bot_left.set_y (op2.bot_left.y ());
if (op2.top_right.y () < op1.top_right.y ())
op1.top_right.set_y (op2.top_right.y ());
}
else {
op1.bot_left.set_x (MAX_INT16);
op1.bot_left.set_y (MAX_INT16);
op1.top_right.set_x (-MAX_INT16);
op1.top_right.set_y (-MAX_INT16);
}
return op1;
}

TBOX& operator+= | ( | TBOX & | op1,
|  | const TBOX & | op2
| ) |  |
| friend

Definition at line 196 of file rect.cpp.

{
if (op2.bot_left.x () < op1.bot_left.x ())
op1.bot_left.set_x (op2.bot_left.x ());
if (op2.top_right.x () > op1.top_right.x ())
op1.top_right.set_x (op2.top_right.x ());
if (op2.bot_left.y () < op1.bot_left.y ())
op1.bot_left.set_y (op2.bot_left.y ());
if (op2.top_right.y () > op1.top_right.y ())
op1.top_right.set_y (op2.top_right.y ());
return op1;
}

The documentation for this class was generated from the following files:

- /mnt/data/src/tesseract-ocr/ccstruct/rect.h
- /mnt/data/src/tesseract-ocr/ccstruct/rect.cpp