lobot::Clipper Class Reference

A line clipper. More...

#include <Robots/LoBot/misc/LoClipper.H>

List of all members.

Public Types

enum  {
  COMPLETELY_INSIDE = 1, COMPLETELY_OUTSIDE = 2, FIRST_POINT_CLIPPED = 4, SECOND_POINT_CLIPPED = 8,
  BOTH_POINTS_CLIPPED = 12
}

Public Member Functions

 Clipper (float left, float right, float bottom, float top)
 Clipper (const float clip_boundary[4])
unsigned char clip (const float end_points[4], float new_end_points[4]) const

void clip_boundary (float left, float right, float bottom, float top)
void clip_boundary (const float clip_boundary[4])

Detailed Description

A line clipper.

This class implements the Cohen-Sutherland line clipping algorithm for clipping lines against rectangles aligned with the principal axes (aka upright rectangles).

Typical usage of this class is as shown below:

Create clipper object and specify clipping boundary Clipper clipper(left, right, bottom, top) ;

Specify line to be clipped double line[4] ; // first two elements are (x0,y0); next two (x1,y1) double clipped_line[4] ; Clipper::ClipInfo clip_flag = clipper.clip(line, clipped_line) ;

Examine clip flag returned by line clipper and do whatever is required with the clipped line...

Definition at line 75 of file LoClipper.H.


Member Enumeration Documentation

anonymous enum

A line may lie completely or partially inside the clipping boundary. It may also be completely outside the clipping boundary. This implementation of the Cohen-Sutherland algorithm informs clients of what the original situation was using these bit flags.

Definition at line 124 of file LoClipper.H.


Constructor & Destructor Documentation

lobot::Clipper::Clipper ( float  left,
float  right,
float  bottom,
float  top 
)

When this Cohen-Sutherland line clipper is created, it should be told the clipping boundary to use.

Definition at line 54 of file LoClipper.C.

References clip_boundary().

lobot::Clipper::Clipper ( const float  clip_boundary[4]  ) 

This constructor allows clients to pass the clipping boundary in via an array. The array is expected to have four elements that supply the boundary like so: clip_boundary[0] = left clip_boundary[1] = right clip_boundary[2] = bottom clip_boundary[3] = top

Definition at line 59 of file LoClipper.C.

References clip_boundary().


Member Function Documentation

unsigned char lobot::Clipper::clip ( const float  end_points[4],
float  new_end_points[4] 
) const

This method implements the Cohen-Sutherland line clipping algorithm. It expects its first argument to be an array specifying the input line's end points. The clipped line is passed back to the client via the second parameter. Additionally, the function's return value specifies whether the original line was completely or partially inside the clipping boundary or completely outside of it.

The input and output line's end points are stored in arrays of four elements like so: array[0] = x0 array[1] = y0 array[2] = x1 array[3] = y1

The return value is a set of bit flags that work like so: bit 0 = 1 ==> original line was completely inside bit 1 = 1 ==> original line was completely outside bit 2 = 1 ==> original line was partially inside and the first end-point was clipped bit 3 = 1 ==> original line was partially inside and the second end-point was clipped

Bits 0, 1, and the remaining two are mutually exclusive, i.e., if bit 0 is on, then none of the others can be on; if bit 1 is on, all the others will be off. Bits 2 and 3 can be on at the same time; but if either of them is on, then bit 0 and 1 will be off.

Rather than check the return code with magic numbers, the caller can use the COMPLETELY_INSIDE, COMPLETELY_OUTSIDE, FIRST_POINT_CLIPPED, SECOND_POINT_CLIPPED and/or BOTH_POINTS_CLIPPED enums defined above.

Definition at line 68 of file LoClipper.C.

void lobot::Clipper::clip_boundary ( float  left,
float  right,
float  bottom,
float  top 
) [inline]

It is possible to create an instance of this clipper with some clipping boundary and then later change that. These methods allow clients to reset the clipping boundary to new values.

Definition at line 105 of file LoClipper.H.

Referenced by Clipper().


The documentation for this class was generated from the following files:
Generated on Sun May 8 08:44:29 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3