Base Class Reference

The base class for all drawable entities. More...

Inherited by Blob, CentLine, Line, Region, and Spot.

List of all members.

Public Member Functions

 Base ()
 The main constructor.
void clear ()
 Clears all but num_.
void operator= (const Base &copy)
 copy everything except number.
uint num ()
 Returns number of base-object.
char type ()
 Returns type.
ushort X ()
 left-most pixel x position
ushort Y ()
 bottom-most pixel y position or line number
ushort H ()
 height
ushort W ()
 width
ushort L (uint i)
 left edge at y==Y+i
ushort R (uint i)
 right edge at y==Y+i
uint area ()
 area from rle
float ave_contrast ()
 contrast for some color
uint ave_cont_cnt ()
 This is a count of the number of pixels on the edge of the base-object.
uchar GSba ()
 Indicates what colors were used to find base-object.
uchar darkba ()
 Indicates dark or light for each color.
uint n ()
 Number of pixels in lms_luv.
float lum_ave ()
 Average luminance.
float urg_ave ()
 Average value on red-green axis.
float vyb_ave ()
 Average value on yellow-blue axis.
float chr_ave ()
 Average chroma.
float hue_ave ()
 Average hue.
float lum (float x, float y)
 luminance as a function of x and y.
float urg (float x, float y)
 red-green axis value as a function of x and y.
float vyb (float x, float y)
 yellow-blue axis value as a function of x and y.
float chr (float x, float y)
 Chroma as a function of x and y.
float hue (float x, float y)
 Hue as a function of x and y.
float angle ()
 Returns angle in radians.
XY< float > CM ()
 Returns center of mass.
double Ix ()
 Ixx, moment of inertia.
double Iy ()
 Iyy, moment of inertia.
double Iz ()
 Ixx+Iyy, polar moment of inertia.
double Ixy ()
 product of inertia
float rad_gyration ()
 radius of gyration
LMS same ()
 Returns an LMS line same as the lms_luv of base-object.
void lms_merge (Base *ba)
 Adds the lms_luv's of Base*ba and this.
void lms_de_merge (Base *ba)
 Removes the lms_luv's of Base*ba from this.
void set_color (float lum, float urg, float vyb)
 Set a base-object's color directly.
float color_dif (PiXFrame *pf, Base *ba)
 Calculate color diference between this base and Base ba.
bool color_measure (PiXFrame *pf)
 Measure the color of the base-object, calculate angles, center of mass, etc.
ushort T (int x)
 Returns the top edge at x.
ushort B (int x)
 Returns the bottom edge at x.
bool trace_top_bot ()
 Create top_bot vector.
float length (PiXFrame *pf)
 Returns major diameter between tips.
float width (PiXFrame *pf)
 Returns minor diameter at midpoint.
XY< ushort > tip (PiXFrame *pf, int n)
 Returns major diameter end points.
XY< ushort > tip_side (PiXFrame *pf, int n)
 Returns minor diameter end points.
void tip (int n, XY< ushort > pt)
 Sets major diameter end points manually without running trace_tips().
void tip_side (int n, XY< ushort > pt)
 Sets minor diameter end points manually without running trace_tips().
virtual bool trace_tips (PiXFrame *pf)
 Vitual function - Find the tips at the major and minor diameters.
LR rle (uint i, uint j)
 Returns ith LR entry on jth line.
void rle_clear ()
 Erase rle contents.
uint rle_len (uint j)
 Returns number of entries at y==j+Y().
void rle_insert (LR ins, uint y2)
 Insert the segment ins at y2 into the rle (run-length-encoded) vectors.
bool rle_insert (PiXFrame *pf, ushort xl, ushort xr, uint y2)
 Insert the segment xl-xr at y2 into the rle (run-length-encoded) vectors.
bool rle_remove (ushort xl, ushort xr, uint y2)
 Remove the segment ins at y2 from the rle (run-length-encoded) vectors.
void rle_merge (Base *ba)
 Adds the rle's of Base*ba and this.
void rle_de_merge (Base *ba)
 Subtracts the rle's of Base*ba and this.
void canvas_insert (PiXFrame *pf, ushort xl, ushort xr, uint y)
 Mark canvas for base type for segment xl-xr, y2 with base num.
void canvas_insert_rle (PiXFrame *pf)
 Use the data in the rle (run length encoded) to mark the canvas.
void canvas_remove (PiXFrame *pf, ushort xl, ushort xr, uint y, uint new_num=0)
 Mark canvas for base type for segment xl-xr, y2 with new base num.
void canvas_remove_rle (PiXFrame *pf, uint new_num)
 Use the data in the rle (run length encoded) to erase the canvas.
void canvas_merge (PiXFrame *pf, Base *ba)
 Use the data in the ba->rle (run length encoded) to mark the canvas with this->num();.
void canvas_de_merge (PiXFrame *pf, Base *ba, uint new_num)
 Use the data in the ba-<rle (run length encoded) to erase the canvas.
void clean_interior (PiXFrame *pf, uint maxsize)
 Remove all base-objects of the same type from the interior.
void draw (PiXFrame *pf, std::ostream &ostr)
 Describe the base-object.
void draw_finish (PiXFrame *pf, std::ostream &ostr)
 Finish describing the base-object.
float edge_contrast (PiXFrame *pf, XY< float > *slope)
 Calculates the edge contrast of the base-object from rle for a given slope.
float edge_contrast_merge (PiXFrame *pf, Base *ba, XY< float > *slope)
 Combine the edge_contrast of two base-objects before merging.
bool is_me (PiXFrame *pf, uint addr)
 Is this base-object at this address on the canvas?
bool line_intersection (XY< float >(&point)[2], LMS &line)
 Find the entrance and exit of a straight line thru a base-object.
bool make_from_part_of_figure_between_two_straight_lines (PiXFrame *pf, Base *ba, LMS &ln0, LMS &ln1)
 Find the part of Base*ba between_two_straight_lines ln0 and ln1.
void make_quadrilateral (PiXFrame *pf, XY< ushort >(&point)[4])
 The base becomes the area between four corners.
void reset_X_W_Y ()
 Recalculate X_, W_, and Y.
bool split_with_line (PiXFrame *pf, Base *ba[2], Line *ln)
void trace_edges_end_left ()
 Creates el vector for drawing purposes.
void trace_edges_start_right ()
 Creates sr vector fro drawing purposes.
bool trim_edges (PiXFrame *pf, uint trim_x, uint trim_y, Base *ba_inner, Base *ba_outer=0, bool skip_holes=true)
 Create two new base-objects by trimming the edges of the base-object.

Public Attributes

std::vector< std::vector< XY
< ushort > > > 
sr
 for drawing edges start, right
std::vector< std::vector< XY
< ushort > > > 
el
 for drawing edges end, left
std::vector< SE > top_bot
 top and bottom edges as a function of x

Protected Types

enum  GSbits

Friends

class PiXFrame
class Line
class CentLine


Detailed Description

The base class for all drawable entities.

Region, Blob, Spot, CentLine, and Line inherit Base. There are many functions such as drawing, color measurement, and edge storage that are naturally common.

In all functions, PiXFrame*pf is a pointer to the particular camera frame on which the base-object resides.


Member Enumeration Documentation

enum Base::GSbits [protected]

Bits in GSba and darkba

Lum=1, Urg=2, Vyb=4, Chr=8, Hue=16


Constructor & Destructor Documentation

Base::Base (  )  [inline]

The main constructor.

num_ is assigned by PiXFrame::add_base().


Member Function Documentation

void Base::clear (  )  [inline]

Clears all but num_.

num_ is assigned by PiXFrame::add_base(char type) on allocation

Reimplemented in Blob, Line, CentLine, Region, and Spot.

uint Base::num (  )  [inline]

Returns number of base-object.

num_ is assigned by PiXFrame::add_base(char type) on allocation

char Base::type (  )  [inline]

Returns type.

Returns:
B==Blob, C==Cent, L==Line, S==Spot, R==Region

ushort Base::X (  )  [inline]

left-most pixel x position

Set by rle_insert(LR ins, uint y2)

ushort Base::Y (  )  [inline]

bottom-most pixel y position or line number

Set by rle_insert(LR ins, uint y2)

ushort Base::H (  )  [inline]

ushort Base::W (  )  [inline]

ushort Base::L ( uint  i  )  [inline]

left edge at y==Y+i

From the rle data

Parameters:
i y-Y(), the line number in the base-object

ushort Base::R ( uint  i  )  [inline]

right edge at y==Y+i

From the rle data

Parameters:
i y-Y(), the line number in the base-object

uint Base::area (  )  [inline]

area from rle

Set by rle_insert(LR ins, uint y2)

Returns:
area in pixels squared

float Base::ave_contrast (  )  [inline]

contrast for some color

Contrast is the average value of the slope at the edges of the base-object. Set by function that finds the base-object.

Returns:
contrast

uint Base::ave_cont_cnt (  )  [inline]

This is a count of the number of pixels on the edge of the base-object.

Set by function that finds the base-object.

Returns:
number of elements averaged for contrast

uchar Base::GSba (  )  [inline]

Indicates what colors were used to find base-object.

Set by function that finds the base-object.

See also:
GSbits
Returns:
combination of Lum=1, Urg=2, Vyb=4, Chr=8, Hue=16

uchar Base::darkba (  )  [inline]

Indicates dark or light for each color.

Set by function that finds the base-object.

See also:
GSbits
Returns:
combination of Lum=1, Urg=2, Vyb=4, Chr=8, Hue=16

uint Base::n (  )  [inline]

Number of pixels in lms_luv.

Set by color_measure().

Returns:
should be same as area()

float Base::lum_ave (  )  [inline]

Average luminance.

Set by color_measure().

float Base::urg_ave (  )  [inline]

Average value on red-green axis.

Set by color_measure().

float Base::vyb_ave (  )  [inline]

Average value on yellow-blue axis.

Set by color_measure().

float Base::chr_ave (  )  [inline]

Average chroma.

Set by color_measure(), calculated from LUV values.

float Base::hue_ave (  )  [inline]

Average hue.

Set by color_measure(), calculated from LUV values.

float Base::lum ( float  x,
float  y 
) [inline]

luminance as a function of x and y.

Set by color_measure().

float Base::urg ( float  x,
float  y 
) [inline]

red-green axis value as a function of x and y.

Set by color_measure().

float Base::vyb ( float  x,
float  y 
) [inline]

yellow-blue axis value as a function of x and y.

Set by color_measure().

float Base::chr ( float  x,
float  y 
) [inline]

Chroma as a function of x and y.

Set by color_measure(), calculated from LUV values.

float Base::hue ( float  x,
float  y 
) [inline]

Hue as a function of x and y.

Set by color_measure(), calculated from LUV values.

float Base::angle (  )  [inline]

Returns angle in radians.

Mechanical data gathered by color_measure() in lms_luv.

Reimplemented in Line, and CentLine.

XY< float > Base::CM (  )  [inline]

Returns center of mass.

Mechanical data gathered by color_measure() in lms_luv. Useful for aiming at with a paddle or air jet

double Base::Ix (  )  [inline]

Ixx, moment of inertia.

Mechanical data gathered by color_measure() in lms_luv.

double Base::Iy (  )  [inline]

Iyy, moment of inertia.

Mechanical data gathered by color_measure() in lms_luv.

double Base::Iz (  )  [inline]

Ixx+Iyy, polar moment of inertia.

Mechanical data gathered by color_measure() in lms_luv.

double Base::Ixy (  )  [inline]

product of inertia

Mechanical data gathered by color_measure() in lms_luv.

float Base::rad_gyration (  )  [inline]

radius of gyration

Mechanical data gathered by color_measure() in lms_luv.

LMS Base::same (  )  [inline]

Returns an LMS line same as the lms_luv of base-object.

Useful for cloning a line that has been found for manipulations.

LMS is a subset of LMSLUV without the color data

Mechanical data gathered by color_measure() in lms_luv.

void Base::lms_merge ( Base ba  )  [inline]

Adds the lms_luv's of Base*ba and this.

This saves having to redo color_measure when two base-objects are combined.

void Base::lms_de_merge ( Base ba  )  [inline]

Removes the lms_luv's of Base*ba from this.

This saves having to redo color_measure when two base-objects are separated.

void Base::set_color ( float  lum,
float  urg,
float  vyb 
)

Set a base-object's color directly.

Normally color_measure() is used to measure color. This can be used to set it to some color, say white (lum=255, urg=0, vyb=0).

Parameters:
lum new luminance
urg new red-green setting
vyb new yellow-blue setting

float Base::color_dif ( PiXFrame pf,
Base ba 
)

Calculate color diference between this base and Base ba.

If color_measure() has not been run on both base-objects, it will be. Any necessary color calibrations must have been run before.

Parameters:
ba Base to compare
pf frame pointer
Returns:
color diference.

bool Base::color_measure ( PiXFrame pf  ) 

Measure the color of the base-object, calculate angles, center of mass, etc.

This function uses the rle (run-length-encoded) data to measure the color using the lum layer and, if color, the urg and vyb layers. lms stands for least-mean-square, and luv stands for lum-urg-vyb. Color is calculated as a linear function of x and y, so if a base-object changes shades from top to bottom and/or from left to right, this can be recorded and retrieved. Average color is also calculated. Closely related to the color calculation is a line fit calculation to find the angle of the base-object. Moments for the object are also calculated. The center of mass and area are other important parameters that come out of this.

Parameters:
pf frame pointer
Returns:
true if success.

ushort Base::T ( int  x  )  [inline]

Returns the top edge at x.

This will run trace_top_bot() if it has not already been run.

ushort Base::B ( int  x  )  [inline]

Returns the bottom edge at x.

This will run trace_top_bot() if it has not already been run.

bool Base::trace_top_bot (  ) 

Create top_bot vector.

The top_bot vectors provide the maximum and minimum y values at a given x value. L() and R() provide the leftmost and rightmost values for a given y.

Returns:
true if success.

float Base::length ( PiXFrame pf  )  [inline]

Returns major diameter between tips.

This will run trace_tips() if it has not already been run.

Parameters:
pf frame pointer

float Base::width ( PiXFrame pf  )  [inline]

Returns minor diameter at midpoint.

This will run trace_tips() if it has not already been run.

Parameters:
pf frame pointer

XY< ushort > Base::tip ( PiXFrame pf,
int  n 
) [inline]

Returns major diameter end points.

This will run trace_tips() if it has not already been run.

Parameters:
pf frame pointer
n 0 or 1, for one of two tips

XY< ushort > Base::tip_side ( PiXFrame pf,
int  n 
) [inline]

Returns minor diameter end points.

This will run trace_tips() if it has not already been run.

Parameters:
pf frame pointer
n 0 or 1, tip to set

void Base::tip ( int  n,
XY< ushort >  pt 
) [inline]

Sets major diameter end points manually without running trace_tips().

This also calculates length.

Parameters:
n 0 or 1, tip to set
pt new setting

void Base::tip_side ( int  n,
XY< ushort >  pt 
) [inline]

Sets minor diameter end points manually without running trace_tips().

This also calculates width.

bool Base::trace_tips ( PiXFrame pf  )  [virtual]

Vitual function - Find the tips at the major and minor diameters.

The length and width measured are the size of the smallest rectangle that can be drawn around the base-object, with the axis of the rectangle parallel to the base-object axis determined in color_measure() and lms_luv.

Parameters:
pf frame pointer
Returns:
true if success.

Reimplemented in CentLine.

LR Base::rle ( uint  i,
uint  j 
) [inline]

Returns ith LR entry on jth line.

Parameters:
i the segment number in rle at line j
j corresponds to j = y - Y(), where y is location on y-axis.
Returns:
if fails, return is {0,0}

uint Base::rle_len ( uint  j  )  [inline]

Returns number of entries at y==j+Y().

Parameters:
j corresponds to j = y - Y(), where y is location on y-axis.
Returns:
number of segments in line j, can be zero.

void Base::rle_insert ( LR  ins,
uint  y2 
)

Insert the segment ins at y2 into the rle (run-length-encoded) vectors.

Both ends of the segment are included in the segment. This does not check limits and should be used for speed reasons if the limits have already been checked. X_, Y_, and, W_ are updated. length_ is set to zero to flag that rle has been changed.

Parameters:
ins LR segment to insert
y2 line y location to insert on

bool Base::rle_insert ( PiXFrame pf,
ushort  xl,
ushort  xr,
uint  y2 
)

Insert the segment xl-xr at y2 into the rle (run-length-encoded) vectors.

The camera frame pf is used to check the frame limits. Then the actual work is done by rle_insert(LR ins, uint y2); False is returns if it fails. The segment includes xr.

Parameters:
pf frame pointer
xl left edge of segment
xr right edge of segment, included in segment
y2 line y location to insert on
Returns:
true if success

bool Base::rle_remove ( ushort  xl,
ushort  xr,
uint  y2 
)

Remove the segment ins at y2 from the rle (run-length-encoded) vectors.

Both ends of the segment are included in the segment. length_ is set to zero to flag that rle has been changed. reset_X_W_Y() is run to reset those values.

Parameters:
xl left edge of segment
xr right edge of segment, included in segment
y2 line y location to insert on
Returns:
false if removal could not be made.

void Base::rle_merge ( Base base  )  [inline]

Adds the rle's of Base*ba and this.

Parameters:
base Blob*, Region*, Spot*, or Line*
This inserts the elements of ba->rle using rle_insert(LR ins, uint y2).

void Base::rle_de_merge ( Base base  )  [inline]

Subtracts the rle's of Base*ba and this.

Parameters:
base Blob*, Region*, Spot*, or Line*
This removes the elements of ba->rle using rle_remove().

void Base::canvas_insert ( PiXFrame pf,
ushort  xl,
ushort  xr,
uint  y2 
)

Mark canvas for base type for segment xl-xr, y2 with base num.

Segment xl-xr includes xr, so if a single pixel is being marked, xl==xr. Canvas shows relative position among base types.

Parameters:
pf frame pointer
xl left edge of segment
xr right edge of segment, included in segment
y2 line y location

void Base::canvas_insert_rle ( PiXFrame pf  )  [inline]

Use the data in the rle (run length encoded) to mark the canvas.

This is normally not required for objects and blobs since the canvas is marked as the blobs and objects are found. Lines can be a different story.

Parameters:
pf frame pointer

void Base::canvas_remove ( PiXFrame pf,
ushort  xl,
ushort  xr,
uint  y2,
uint  new_num = 0 
)

Mark canvas for base type for segment xl-xr, y2 with new base num.

Segment xl-xr includes xr, so if a single pixel is being marked, xl==xr.

Parameters:
pf frame pointer
new_num can be zero to clear canvas or number of replacement base-object.
xl left edge of segment
xr right edge of segment, included in segment
y2 line y location

void Base::canvas_remove_rle ( PiXFrame pf,
uint  new_num 
) [inline]

Use the data in the rle (run length encoded) to erase the canvas.

The canvas will be marked with the new_num. If a base_object is merged with another, the new_num will be the base merged into. Otherwise the new_num can be zero.

Parameters:
pf frame pointer
new_num can be zero to clear canvas or number of replacement base-object.

void Base::canvas_merge ( PiXFrame pf,
Base ba 
) [inline]

Use the data in the ba->rle (run length encoded) to mark the canvas with this->num();.

This should be done before merging the two rle's.

Parameters:
pf frame pointer
ba Base whose rle is to be used to mark canvas.

void Base::canvas_de_merge ( PiXFrame pf,
Base ba,
uint  new_num 
) [inline]

Use the data in the ba-<rle (run length encoded) to erase the canvas.

The canvas will be marked with the new_num. If a base_object is merged with another, the new_num will be the base merged into. Otherwise the new_num can be zero.

Parameters:
pf frame pointer
ba Base whose rle is to be removed
new_num can be zero to clear canvas or number of replacement base-object.

void Base::clean_interior ( PiXFrame pf,
uint  maxsize 
)

Remove all base-objects of the same type from the interior.

Base-objects to be removed must be completely surrounded by base, and must be of the same type as the base. This function is often useful after base_trace().

Parameters:
pf frame pointer
maxsize maximum size of area to be removed in pixels squared

void Base::draw ( PiXFrame pf,
std::ostream &  ostr 
)

Describe the base-object.

This is used to describe the base-object in a dialog. It is used mostly when testing, although it could have other uses.

Parameters:
pf frame pointer
ostr place to write to

Reimplemented in Blob, Line, CentLine, Region, and Spot.

void Base::draw_finish ( PiXFrame pf,
std::ostream &  ostr 
)

Finish describing the base-object.

The function draw is normally followed by a specific description of the Blob Region, LineCent, spot, or Line which is in each of those classes. After the specific description, this one can be run which dumps the rle data and those vectors sl and er which are used solely by draw functions. sl and er are created here if they do not exist (i.e. not drawn yet).

Parameters:
pf frame pointer
ostr place to write to

float Base::edge_contrast ( PiXFrame pf,
XY< float > *  slope 
)

Calculates the edge contrast of the base-object from rle for a given slope.

The contrast is calculated from the slope at the left and right edges of the rle (run length encoded) segments and the members of each segment that do not have the base-object above or below the segments. The slope can be for any particular color and width desired. The contrast is returned and is also stored in the base data as ave_contrast. ave_cont_cnt is a count of the number of pixels examined. The canvas must be set for the base-object if it is not already set. base_trace() sets the canvas.

Parameters:
pf frame pointer
slope to use for contrast

float Base::edge_contrast_merge ( PiXFrame pf,
Base ba,
XY< float > *  slope 
)

Combine the edge_contrast of two base-objects before merging.

This routine allows merging without a full edge_contrast count. Run this before canvas_merge(PiXFrame*pf, Base*ba). Make sure the smaller of the two is Base*ba. In some cases, it may be quicker to simply repeat edge_contrast() after merging. This returns the new average contrast.

Parameters:
pf frame pointer
slope to use for contrast
ba Base to merge

bool Base::line_intersection ( XY< float >(&)  point[2],
LMS &  line 
)

Find the entrance and exit of a straight line thru a base-object.

Entrance and exit point will be found in point[2]. Returns false if no intersection. Line can be created from Base::same() or made up. See class LMS.

bool Base::make_from_part_of_figure_between_two_straight_lines ( PiXFrame pf,
Base ba,
LMS &  ln0,
LMS &  ln1 
)

Find the part of Base*ba between_two_straight_lines ln0 and ln1.

Base*ba is not modified. Lines ln0 and ln1 can be created from a Base::same() or made up. See class LMS. this becomes the part.

void Base::make_quadrilateral ( PiXFrame pf,
XY< ushort >(&)  point[4] 
)

The base becomes the area between four corners.

Points must be clockwise and the figure has to be convex.

void Base::reset_X_W_Y (  ) 

Recalculate X_, W_, and Y.

Normally this is taken care of by Base::rle_insert(LR ins, uint y2).

bool Base::split_with_line ( PiXFrame pf,
Base ba[2],
Line ln 
)

Line*ln does not have to be straight. The new base-objects are Base*ba[2]. Line*ln will be extended to the object edges. A return of false indicates that the inputs are faulty.

void Base::trace_edges_end_left (  ) 

Creates el vector for drawing purposes.

Most programs will not use this function unless they want to draw the edges of the figure. el stands for end-left.

void Base::trace_edges_start_right (  ) 

Creates sr vector fro drawing purposes.

Most programs will not use this function unless they want to draw the edges of the figure. sr stands for start-right.

bool Base::trim_edges ( PiXFrame pf,
uint  trim_x,
uint  trim_y,
Base ba_inner,
Base ba_outer = 0,
bool  skip_holes = true 
)

Create two new base-objects by trimming the edges of the base-object.

trim_x is the amount to trim from the left and right and trim_y is the amount to trim from the top and bottom. ba_inner is the inner base-object and ba_outer is the part that is trimmed. skip_holes does just that.


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

Generated on Fri Aug 1 22:02:12 2008 for pixtrace by  doxygen 1.5.5