Rect Functions

Summary
Rect Functions
Constructors and Destructors
rectCreates a new Rect or adds a new Rect to a list
rectCopyMakes a copy of a Rect
rectDeleteFrees the memory used by a Rect
rectFilterFilter the Rects on the list based on a criteria.
rectMaximalWhiteRectanglesAn implementation of the algorithm described in “T.
rectIsValidChecks if the Rect is valid (left < right and top < bottom)
rectAreaReturns the area of the Rect.
rectDistanceReturns the between two Rects
rectClosestReturns the closest Rect to the (x, y) point
rectIntersectsCheck if the Rects intersect each other
rectPointInsideChecks if the passed point is inside the Rect
rectRectInsideChecks if a Rect is inside another
rectPrintPrints all the Rects in r preceded by msg
Priority Queue Functions
rectPQEnqueueEnqueue a triple of bound, obstacles and quality
rectPQGetGet the best element of the queue
rectPQUpdateFor every element, add new to the obstacles list if new intersects bound
rectPQDeleteDelete the priority queue

Constructors and Destructors

rect

Rect *rect(int x1,
int y1,
int x2,
int y2,
double fill,
Rect *next)

Creates a new Rect or adds a new Rect to a list

Parameters

x1x coordinate of the top-left corner
y1y coordinate of the top-left corner
x2x coordinate of the bottom-right corner
y1y coordinate of the bottom-right corner
fillindicates how much of the rect is filled (used in some connected components functions
nextthe next Rect in the list.  Pass NULL to create a single Rect

Returns

The Rect created.

See Also

Rect

rectCopy

Rect *rectCopy(Rect *r)

Makes a copy of a Rect

Parameters

rRect to be copied

Returns

A copy of r

See Also

Rect

rectDelete

void rectDelete(Rect *r)

Frees the memory used by a Rect

Parameters

rRect to be freed

See Also

Rect

rectFilter

Rect *rectFilter(Rect *r,
int criteria,
double min,
double max)

Filter the Rects on the list based on a criteria.

Parameters

rRects to be filtered
criteriaThe criteria to be applied.  Can be one of FILTER_WIDTH, FILTER_HEIGHT, FILTER_AREA, FILTER_RATIO or FILTER_FILL
minthe minimum value allowed.  Use -1 to ignore.
maxthe maximum value allowed.  Use -1 to ignore.

Returns

Rect list r containing only the Rects that are allowed.  The Rects that do not fill the requirements are freed with rectDelete.

See Also

rectDelete

rectMaximalWhiteRectangles

Rect *rectMaximalWhiteRectangles(Rect *bound,
Rect *obstacles,
int N,
double (*quality)(Rect *r))

An implementation of the algorithm described in “T.  M. Breuel.  Two algorithms for geometric layout analysis.  In Proceedings of the Workshop on Document Analysis Systems, Princeton, NJ, USA, 2002”.

Parameters

boundthe area that should be analyzed.  Only the obstacles in this area aree going to be considered.
obstaclesthe obstacles of the document.  All the Rects returned MUST NOT intersect any of this Rects
Nthe maximum number of Rects to find
qualitya function that receives a Rect and returns the quality of that Rect.  This number is used to classify the Rects and the greater the number the better the Rect is.  The area can be used to find the Rect that covers the maximal white area of a document, but other functions can give different results.

Returns

A list with the maximal white rectangles in bound that do not intersect obstacles.

See Also

RectPQ

rectIsValid

int rectIsValid(Rect *r)

Checks if the Rect is valid (left < right and top < bottom)

Parameters

rRect to be validated

Returns

1 if (left < right and top < bottom)m, 0 otherwise

rectArea

double rectArea(Rect *r)

Returns the area of the Rect.

Parameters

rRect

Returns

(right - left) * (bottom - top)

rectDistance

double rectDistance(Rect *r1,
Rect *r2)

Returns the between two Rects

Parameters

r1first Rect
r2second Rect

Returns

Returns the distance between the Rects’ center

rectClosest

Rect *rectClosest(Rect *r,
int x,
int y)

Returns the closest Rect to the (x, y) point

Parameters

rRect list to be searched
xx coordinate
yy coordinate

Returns

Returns the Rect from r that is the closest from the (x, y) point

rectIntersects

int rectIntersects(Rect *r1,
Rect *r2)

Check if the Rects intersect each other

Parameters

r1first Rect
r2second Rect

Returns

1 if the Rects intersect, 0 otherwise

See Also

rectPointInside, rectRectInside

rectPointInside

int rectPointInside(Rect *r,
int x,
int y)

Checks if the passed point is inside the Rect

Parameters

rRect
xx coordinate
yy coordinate

Returns

1 if (x, y) is inside r.  0 otherwise

rectRectInside

int rectRectInside(Rect *r,
Rect *r2)

Checks if a Rect is inside another

Parameters

rinner Rect
r2outer Rect

Returns

1 if r is inside r2, 0 otherwise

rectPrint

void rectPrint(char *msg,
Rect *r)

Prints all the Rects in r preceded by msg

Parameters

msgmessage to be printed before the Rect
rRect

Priority Queue Functions

rectPQEnqueue

RectPQ *rectPQEnqueue(RectPQ *pq,
Rect *bound,
Rect *obstacles,
double quality)

Enqueue a triple of bound, obstacles and quality

Parameters

pqPriorioty queue to add the element
boundthe bound of the element
obstaclesobstacles in the element’s bound
qualityquality of the element

Returns

The updated priority queue

rectPQGet

RectPQ *rectPQGet(RectPQ *pq,
Rect **bound,
Rect **obstacles,
double *q)

Get the best element of the queue

Parameters

pqPriorioty queue to get the element
boundpointer to the variable to store the element’s bound
obstaclespointer to the variable to store the element’s obstacles
qualitypointer to the variable to store the element’s quality

Returns

The updated priority queue

rectPQUpdate

RectPQ *rectPQUpdate(RectPQ *pq,
Rect *new)

For every element, add new to the obstacles list if new intersects bound

Parameters

pqPriorioty queue to update
newRect to add to the obstacles list

Returns

The updated priority queue

rectPQDelete

void rectPQDelete(RectPQ *pq)

Delete the priority queue

Parameters

pqPriorioty queue to be deleted
Rect *rect(int x1,
int y1,
int x2,
int y2,
double fill,
Rect *next)
Creates a new Rect or adds a new Rect to a list
Rect *rectCopy(Rect *r)
Makes a copy of a Rect
void rectDelete(Rect *r)
Frees the memory used by a Rect
Rect *rectFilter(Rect *r,
int criteria,
double min,
double max)
Filter the Rects on the list based on a criteria.
Rect *rectMaximalWhiteRectangles(Rect *bound,
Rect *obstacles,
int N,
double (*quality)(Rect *r))
An implementation of the algorithm described in “T.
int rectIsValid(Rect *r)
Checks if the Rect is valid (left < right and top < bottom)
double rectArea(Rect *r)
Returns the area of the Rect.
double rectDistance(Rect *r1,
Rect *r2)
Returns the between two Rects
Rect *rectClosest(Rect *r,
int x,
int y)
Returns the closest Rect to the (x, y) point
int rectIntersects(Rect *r1,
Rect *r2)
Check if the Rects intersect each other
int rectPointInside(Rect *r,
int x,
int y)
Checks if the passed point is inside the Rect
int rectRectInside(Rect *r,
Rect *r2)
Checks if a Rect is inside another
void rectPrint(char *msg,
Rect *r)
Prints all the Rects in r preceded by msg
RectPQ *rectPQEnqueue(RectPQ *pq,
Rect *bound,
Rect *obstacles,
double quality)
Enqueue a triple of bound, obstacles and quality
RectPQ *rectPQGet(RectPQ *pq,
Rect **bound,
Rect **obstacles,
double *q)
Get the best element of the queue
RectPQ *rectPQUpdate(RectPQ *pq,
Rect *new)
For every element, add new to the obstacles list if new intersects bound
void rectPQDelete(RectPQ *pq)
Delete the priority queue
The Rect type is a list of Rectangles
A priority queue of Rectangles used in the maximal white rectangles function.
Close