Ending Polylines in Bluebeam
Ending Polylines in Bluebeam
OUTPUT PRIMITIVES
Introduction
The basic elements constituting a graphic are called output primitives. Each output
primitive has an associated set of attributes, such as line width and line color for lines. The
programming technique is to set values for the output primitives and then call a basic function that
will draw the desired primitive using the current settings for the attributes. Various graphics
systems have different graphics primitives.
For example GKS defines five output primitives namely, polyline (for drawing contiguous
line segments), polymarker (for marking coordinate positions with various symmetric text
symbols), text (for plotting text at various angles and sizes), fill area (for plotting polygonal areas
with solid or hatch fill), cell array (for plotting portable raster images). At the same time GRPH1
has the output primitives namely Polyline, Polymarker, Text, Tone and have other secondary
primitives besides these namely, Line and Arrow
Points and Lines
In a CRT monitor, the electron beam is turned on to illuminate the screen phosphor at the
selected location. Depending on the display technology, the positioning of the electron beam
changes. In a random-scan (vector) system point plotting instructions are stored in a display list
and the coordinate values in these instructions are converted to deflection voltages the position the
electron beam at the screen locations. Low-level procedure for ploting a point on the screen at
(x,y) with intensity “I” can be given as
setPixel(x,y,I)
Computer Graphics and Multimedia
A line is drawn by calculating the intermediate positions between the two end points and
displaying the pixels at those positions.
y1
y2
x1 X2
the two end points in the line segement at specified position(x 1,y1),and (x2,y2).
Slope m and y as
m = y2-y1,
x2-x1.
b = y1 - m.x1
for any given x interval ∆x along a line, we compute the corresponding y interval ∆y as
∆y=m ∆x
Similiarly,we can obtain the x interval ∆x to the corresponding ∆y as
∆x= ∆y/m
Computer Graphics and Multimedia
Rasterization
Rasterization is the process of converting a vertex representation to a pixel representation;
rasterization is also called scan conversion. Included in this definition are geometric objects such
as circles where you are given a center and radius.
The digital differential analyzer (DDA) which introduces the basic concepts for
rasterization.
Bresenham's algorithm which improves on the DDA.
Scan conversion algorithms use incremental methods that exploit coherence. An
incremental method computes a new value quickly from an old value, rather than computing the
new value from scratch, which can often be slow. Coherence in space or time is the term used to
denote that nearby objects (e.g., pixels) have qualities similar to the current object.
1. Digital Differential Analyzer (DDA) Algorithm
DDAs are used for rasterization of lines, triangles and polygons. In its simplest
implementation the DDA algorithm interpolates values in interval [(x start, ystart), (xend, yend)] by
computing for each xi the equations xi = xi−1+1, yi = yi−1 + Δy/Δx, where Δx = xend − xstart and Δy
= yend − ystart.
In this algorithm, the line is sampled at unit intervals in one coordinate and find the corresponding
values nearest to the path for the other coordinate. For a line with positive slope less than one, x >
y (where x = x2-x1 and y = y2-y1).
Hence we sample at unit x=1 intervals and compute each successive y values as
yk+1=yk + m
For lines with positive slope greater than one, y > x. Hence we sample at unit y intervals and
compute each successive x values as
Xk+1=Xk +1/m
Since the slope, m, can be any real number, the calculated value must be rounded to the nearest
integer.
(xi , yi)
(xi , Round(yi))
Computer Graphics and Multimedia
positive slope left to right positive slope right to left all points are joint together
For a line with negative slope, if the absolute value of the slope is less than one, we make unit
increment in the x direction and calculate y values as
yk+1=yk - m
For a line with negative slope, if the absolute value of the slope is greater than one, we make unit
decrement in the y direction and calculate x values as
Xk+1=Xk +1/m
[Note :- for all the above four cases it is assumed that the first point is on the left and second point
is in the right.]
DDA Line Algorithm
void myLine(int x1, int y1, int x2, int y2)
{
int length,i;
double x,y;
double xincrement;
double yincrement;
length = abs(x2 - x1);
if (abs(y2 - y1) > length) length = abs(y2 - y1);
xincrement = (double)(x2 - x1)/(double)length;
yincrement = (double)(y2 - y1)/(double)length;
x = x1 + 0.5;
y = y1 + 0.5;
for (i = 1; i<= length;++i)
{
myPixel((int)x, (int)y);
Computer Graphics and Multimedia
x = x + xincrement;
y = y + yincrement;
}
}
[Link]'s line algorithm
While algorithms such as Wu's algorithm are also frequently used in modern computer
graphics because they can support antialiasing, the speed and simplicity of Bresenham's line
algorithm mean that it is still important. The algorithm is used in hardware such as plotters and in
the graphics chips of modern graphics cards. It can also be found in many software graphics
libraries. Because the algorithm is very simple, it is often implemented in either the firmware or
the hardware of modern graphics cards.
The label "Bresenham" is used today for a whole family of algorithms extending or
modifying Bresenham's original algorithm
The algorithm
The common conventions will be used: That pixel coordinates increase in the right and down
directions (e.g. that the pixel at (1,1) is directly above the pixel at (1,2)), andthat the pixel centers
have integer coordinates.
The endpoints of the line are the pixels at (x0, y0) and (x1, y1), where the first coordinate of
the pair is the column and the second is the row.
The algorithm will be initially presented only for the octant in which the segment goes
down and to the right (x0≤x1 and y0≤y1), and its horizontal projection x1 − x0 is longer than the
vertical projection y1 − y0 (the line has a slope whose absolute value is less than 1 and greater than
0.) In this octant, for each column x between x0 and x1, there is exactly one row y (computed by
the algorithm) containing a pixel of the line, while each row between y0 and y1 may contain
multiple rasterized pixels.
Bresenham's algorithm chooses the integer y corresponding to the pixel center that is
closest to the ideal (fractional) y for the same x; on successive columns y can remain the same or
increase by 1. The general equation of the line through the endpoints.
Computer Graphics and Multimedia
Since we know the column, x, the pixel's row, y, is given by rounding this quantity to the
nearest integer.
The slope (y1 − y0) / (x1 − x0) depends on the endpoint coordinates only and can be
precomputed, and the ideal y for successive integer values of x can be computed starting
from y0and repeatedly adding the slope.
In practice, the algorithm can track, instead of possibly large y values, a small error value
between −0.5 and 0.5: the vertical distance between the rounded and the exact y values for the
current x. Each time x is increased, the error is increased by the slope; if it exceeds 0.5, the
rasterization y is increased by 1 (the line continues on the next lower row of the raster) and the
error is decremented by 1.0.
In the following pseudocode sample plot(x,y) plots a point and abs returns absolute value:
The version above only handles lines that descend to the right. We would of course like to
be able to draw all lines. The first case is allowing us to draw lines that still slope downwards but
head in the opposite direction. This is a simple matter of swapping the initial points if x0 > x1.
Trickier is determining how to draw lines that go up. To do this, we check if y0 ≥ y1; if so, we step
y by -1 instead of 1.
Lastly, we still need to generalize the algorithm to drawing lines in all directions. Up until
now we have only been able to draw lines with a slope less than one. To be able to draw lines with
a steeper slope, we take advantage of the fact that a steep line can be reflected across the line y=x to
obtain a line with a small slope. The effect is to switch the x and y variables throughout, including
switching the parameters to plot. The code looks like this:
The function now handles all lines and implements the complete Bresenham's algorithm.
Optimization
The problem with this approach is that computers operate relatively slowly on fractional
numbers like error and deltaerr; moreover, errors can accumulate over many floating-point
additions. Working with integers will be both faster and more accurate. The trick we use is to
multiply all the fractional numbers (including the constant 0.5) in the code above by deltax, which
enables us to express them as integers. This results in a divide inside the main loop, however. To
deal with this we modify how error is initialized and used so that rather than starting at zero and
counting up towards 0.5, it starts at 0.5 and counts down to zero. The new program looks like this:
Computer Graphics and Multimedia
Remark: If you need to control the points in order of appearance (for example to print several
consecutive dashed lines) you will have to simplify this code by skipping the 2nd swap:
Simplification
It is further possible to eliminate the swaps in the initialisation by considering the error
calculation for both directions simultaneously:
loop
setPixel(x0,y0)
if x0 = x1 and y0 = y1 exit loop
e2 := 2*err
if e2 > -dy then
err := err - dy
x0 := x0 + sx
end if
if e2 < dx then
err := err + dx
y0 := y0 + sy
end if
end loop
In this method, developed by Jack Bresenham, we look at just the center of the pixels. We
determine d1 and d2 which is the "error", i.e., the difference from the "true line."
Now the y coordinate on the mathematical line at pixel position xi+1 is calculated as
y = m(xi+1) + b
And the distances are calculated as
d1 = y - yi= m(xi+1) + b - yi
d2 = (yi+1) - y = yi +1 -m(xi +1) - b
Then
d1 - d2 = 2m(xi+1) - 2y + 2b -1
Now define pi = dx(d1 - d2) = relative error of the two pixels.
Note: pi < 0 if yi pixel is closer, pi >= 0 if yi+1 pixel is closer. Therefore we only need to know
the sign of pi .
ith m = dy/dx and substituting in for (d1 - d2) we get
pi = 2 * dy * xi - 2 * dx * yi + 2 * dy + dx * (2 * b - 1) (1)
Computer Graphics and Multimedia
Let C = 2 * dy + dx * (2 * b - 1)
For a line with slope 0 m 1 and leftpoint (x0,y0) the distance to the right endpoint
(left endpoint for next segment) is
where
xk = x0 + kxp
Computer Graphics and Multimedia
i.e. x = 15 , np = 4 processors
yp = mxp
At the kth segment, the starting y-coordinates is
yk = y0 + round(kyp)
Also, the initial decision parameter for Bresenham’s algorithm at the start of the
kth subinterval is:
Each processor then calculates the pixel positions over its assigned subinterval
using the starting decision parameter value for that subinterval and the starting
coordinates (xk,yk).
Another way to set up parallel algorithms on raster systems is to assign each
processor to a particular group of screen pixels. Assign each processor to 1 pixel
within some screen region. This approach can be adapted to line display by
assigning 1 processor to each of the pixels within the limits of the line coordinates
extends (bounding rectangle) and calculating the pixel distances from the line path.
Computer Graphics and Multimedia
The no: of pixels within the bounding box of the line is ∆x * ∆y. Perpendicular
distance d from the line to a pixel with coordinates (x,y) is calculated as,
d = Ax + By + C
where, A = -∆y / line length
B = ∆x / line length
C = x0∆y – y0∆x / line length
With line length = √(∆x2 + ∆y2)
Once the constants A,B,C are calculated, the processor needs to perform 2
multiplications and 2 additions to compute the pixel distance d. A pixel is plotted
if d < a specified line thickness parameter. Instead of partitioning the screen
intosingle pixels, we can assign to each processor either a scanline or a column of
pixels depending on the line slope
LINE FUNCTION
A procedure for specifying straight-line segments can be set up in a number of different
forms. In PHIGS, GKS, and some other packages, the two-dimensionalline function is where
parameter n is assigned an integer value equal to the number of coordinate positions to be input,
and wcpoints is the array of input world coordinate values for line segment endpoints.
This function is used to define a set of n – 1 connected straight line segments. Because
series of connected line segments occur more often than isolated line segments in graphics
applications, polyline provides a more general line function. To display a single straight-line
segment, we set n -= 2 and list the x and y values of the two endpoint [Link] an example
Computer Graphics and Multimedia
of the use of polyline, the following statements generate two connected line segments, with
endpoints at (50, 103, (150, 2501, and (250,100):
wcPoints[ll .x = SO;
wcPoints[ll .y = 100;
wcPoints[21 .x = 150;
wc~oints[2l.y = 250;
wc~oints[3l.x = 250;
wcPoints[31 .y = 100;
polyline ( 3 , wcpoints);
Coordinate references in the polyline function are stated as absolute coordinate values.
This means that the values specified are the actual point positions in the coordinate system in use.
Some systems employ line (and point) functions with relative coordinate specifications. In
this case, coordinate values are stated as offsets from the last position referenced (called the current
position).
For example, if location(3,2) is the last position that has been referenced in an application
program, a relative coordinate specification of (2, -1) corresponds to an absolute position of (5,1).
An additional function is also available for setting the current position before the line routine is
summoned. With these packages, a user lists only the single pair of offsets in the line command.
This signals the system to display a line starting from the current position to a final position
determined by the offsets.
The current position is then updated to this final line position. A series of connected lines
is produced with such packages by a sequence of line commands, one for each line section to be
drawn. Some graphics packages provide options allowing the user to specify Line endpoints using
either relative or absolute coordinates.
Implementation of the polyline procedure is accomplished by first performing a series of
coordinate transformations, then malung a sequence of calls to a device-level line-drawing routine.
In PHIGS, the input line endpoints are actually specified in modeling coordinates, which are then
converted to world c eordinates.
Next, world coordinates are converted to normalized coordinates, then to device
coordinates. We discuss the details for carrying out these two dimensional coordinate
transformations in Chapter 6. Once in device coordinates, we display the plyline by invoking a
line routine, such as Bresenham's algorithm,n - 1 times to connect the n coordinate points.
Each successive call passes the c c ~ordinate pair needed to plot the next line section, where
the first endpoint of each coordinate pair is the last endpoint of the previous section. To avoid
setting the intensity of some endpoints twice, we could modify the line algorithm so that the last
endpoint of each segment is not plotted. We discuss methods for avoiding overlap of displayed
objects.
The set of points in the circumference of the circle are all at equal distance r from the centre
(xc,yc) and its relation is given be pythagorean theorem as
(X –XC)2 + (Y-YC)2= r2
The points in the circumference of the circle can be calculated by unit increments in the x
direction from xc - r to xc+ r and the corresponding y values can be obtained as
Y=Yc±√𝐫2- (xc-x)2
The major problem here is that the spacing between the points will not be [Link] can be
adjusted by interchanging x and y whenever the absolute value of the slope of the circle is greater
than 1.
The unequal spacing can be eliminated by using polar coordinates and is given by
X= XC +rcos𝜽
Y=Yc + rsin 𝜽
The major problem in the above two methods is the computational time. The computational
time can be reduced by considering the symmetry of circles. The shape of the circle is similar in
each quadrant. Thinking one step further shows that there are symmetry between octants too.
3 2
4
1
5
8
Computer Graphics and Multimedia
If the point is inside the circle then f(x,y)<0 and if it is outside then f(x,y)>0 and if the point
is in the circumference of the circle then f(x,y)=[Link] the circle function is the decision parameter
in the midpoint [Link] that we have just plotted (xk,yk), we have to decide whether to
point
(xk+1, yk) or (xk+1, yk - 1) nearer to the circle.
Computer Graphics and Multimedia
Now we consider the midpoint between the points and define the decision parameter as
𝟏
Pk= fcircle (xk+1, yk+ )-----------1
𝟐
Similarly
𝟏
=( xk+1)2+( yk+ )2- r2 and
𝟐
𝟏
Pk+1= fcircle (xk+1+1, yk+1 + )------------2
𝟐
Algorithm
1. Initial values:- point(0,r)
x0 = 0
y0 = r
2. Initial decision parameter
3. At each xi position, starting at i = 0, perform the following test: if pi < 0, the next point is
(xi + 1, yi) and
pi+1 = pi + 2xi+1 + 1
If pi ≥ 0, the next point is (xi+1, yi-1) and
pi+1 = pi + 2xi+1 + 1 – 2yi+1
where 2xi+1 = 2xi + 2 and 2yi+1 = 2yi – 2
4. Determine symmetry points in the other octants
5. Move pixel positions (x,y) onto the circular path centered on (xc, yc) and plot the
coordinates: x = x + xc, y = y + yc
6. Repeat 3 – 5 until x ≥ y
Computer Graphics and Multimedia
Example
r = 10
p0 = 1 – r = -9 (if r is integer round p0 = 5/4 – r to integer) Initial point (x0, y0) = (0, 10)
Computer Graphics and Multimedia
Midpoint Algorithm
Ellipse – A modified circle whose radius varies from a maximum value in one direction
(major axis) to a minimum value in the perpendicular direction (minor axis).
The sum of the two distances d1 and d2, between the fixed positions F1 and F2 (called the
foci of the ellipse) to any point P on the ellipse, is the same value, i.e.
d1 + d2 = constant
Expressing distances d1 and d2 in terms of the focal coordinates F1 = (x1, x2) and F2 = (x2,
y2),wehave:
Cartesian coordinates:
Computer Graphics and Multimedia
Polar coordinates:
Thus, we must calculate pixel positions along the elliptical arc through one quadrant and
then we obtain positions in the remaining 3 quadrants by symmetry
Decision parameter:
Computer Graphics and Multimedia
Starting at (0, ry) we take unit steps in the x direction until we reach the boundary between
region 1 and region 2. Then we take unit steps in the y direction over the remainder of the
curve in the first quadrant.
At the boundary
OR
where yi+1 = yi
or yi+1 = yi – 1
Decision parameters are incremented by:
Algorithm:
1. Input rx, ry, and ellipse center (xc, yc), and obtain the first point on an ellipse centered on
the origin as
(x0, y0) = (0, ry)
2. Calculate the initial parameter in region 1 as
3. At each xi position, starting at i = 0, if p1i < 0, the next point along the ellipse centered on
(0, 0) is (xi + 1, yi) and
Example
Region1
Computer Graphics and Multimedia
Region 2
(x0, y0) = (7, 3) (Last position in region 1)
Computer Graphics and Multimedia
The graph drawing routines may be freely mixed with those described in this section,
allowing the user to control line color, width and styles. The attributes set up by these routines
apply modally, i.e, all subsequent objects (lines, characters and symbols) plotted until the next
change in attributes are affected in the same way. The only exception to this rule is that characters
and symbols are not affected by a change in the line style, but are always drawn using a continuous
line.
1. Line type
Solid
Dotted – very short dash with spacing equal to or greater than dash itself
Dashed – displayed by generating an interdash spacing
Pixel count for the span and interspan length is specified
by the mask . Ex. 111100011110001111
Note : Fixed pixel with dashes can produce unequal length dashes. It depend on line
orientation. So, need to adjust the number of plotted pixels for different slopes.
2. Line Width
.Specify in pixels and proportion of a standard line width.
Thicker line can be produced by.
Adding extra pixel vertically when |m| < 1
Adding extra pixel horizontally when |m| > 1
Issues:
Line have different thickness on the slope
Problem with
. End of the line
. Joining the two lines (polygon)
1. Butt Cap
To adjust the end position of the component parallel line.
2. Round Cap.
To fill the semi circle of the each butt cap.
3. Projecting Square Cap.
To extend the add butt cap at the specific end point.
CURVE ATTRIBUTES
A device context (DC) contains attributes that affect line and curve output. The line and
curve attributes include the current position, brush style, brush color, pen style, pen color,
transformation, and so on.
The default current position for any DC is located at the point (0,0) in logical (or world)
space. You can set these coordinates to a new position by calling the MoveToEx function and
passing a new set of coordinates.
Computer Graphics and Multimedia
Note There are two sets of line- and curve-drawing functions. The first set retains the
current position in a DC, and the second set alters the position. You can identify the functions that
alter the current position by examining the function name.
If the function name ends with the preposition "To", the function sets the current position
to the ending point of the last line drawn (LineTo, ArcTo, PolylineTo, or PolyBezierTo). If the
function name does not end with this preposition, it leaves the current position intact
(Arc,Polyline, or PolyBezier).
The default brush is a solid white brush. An application can create a new brush by calling
the CreateBrushIndirect function. After creating a brush, the application can select it into its DC
by calling the SelectObject function. Windows provides a complete set of functions to create,
select, and alter the brush in an application's DC. For more information about these functions and
about brushes in general, see Brushes.
The default pen is a cosmetic, solid black pen that is one pixel wide. An application can
create a pen by using the ExtCreatePen function. After creating a pen, your application can select
it into its DC by calling theSelectObject function. Windows provides a complete set of functions
to create, select, and alter the pen in an application's DC. For more information about these
functions and about pens in general, see Pens.
The default transformation is the unity transformation (specified by the identity matrix).
An application can specify a new transformation by calling the SetWorldTransform function.
Windows provides a complete set of functions to transform lines and curves by altering their width,
location, and general appearance. For more information about these functions, see Coordinate
Spaces and Transformations.
Computer Graphics and Multimedia
The color lookup table with 24 bits entry accessed from a frame buffer with 8 bits per pixel.A vale
of 196 stored at a pixel position(x,y) references the location in this table containing the value of
2081.
Gray Scale
Apply for monitor that have no color
Shades of grey (white->light grey->dark grey->black)
Color code mapped onto grayscale codes
2 bits can give 4 level of grayscale
8 bits per pixel will allow 256 combination
Dividing the actual code with 256 will give range of 0 and 1
Ex:
Color code in color display is 118
To map to nearest grayscale then
Computer Graphics and Multimedia
Many plotting programs will allow the user to draw filled polygons or symbols. The fill
specification may take two forms:
Solid color
Pattern fill
FILL:
In the first case we may specify a gray shade (0-255), RGB color (r/g/b all in the 0-255
range or in hexadecimal#rrggbb), HSV color (hue-saturation-value in the 0-360, 0-1, 0-1 range),
CMYK color (cyan/magenta/yellow/black, each ranging from 0-100%), or a valid color name; in
that respect it is similar to specifying the pen color settings .
There are three fill styles:
where fs is normally applied to the polygon areas it can also implemented to fill region
with curved boundaries
Filled with solid color
It is used to display the single color uptoincluding the borders of the region.
Function:
SetInteriorColorIndex(Fc)
Where the fill color parameter fc is to set the desired color code.
Computer Graphics and Multimedia
Pattern Fill
Select fill pattern with
Set interior Style Index(pi)
The process of filling a rectangular pattern called [Link] rectangular fill pattern is
sometimes called as tiling pattern.
Soft fill
The modified boundary fill and flood fill procedures that are applied to repaint area so that
the fill color is combined with the background color is referred to as soft fill and tint fill algorithm.
Example
Using linear soft fill algorithm repaints the area that was originally painted by merging the
foreground color F with the single background color B ,where F!= B.
Computer Graphics and Multimedia
Assuming that we know the values of F and B we have to determine how these colors
originally combined with current color contents of the frame buffer.
The current RGB color P of each pixel within a area is defined as
P=tF+(1-t)B
Where T is the transperancy factor between o and 1 for each [Link] value of the T is less
than 0.5,the background color contributes more to interior color.
CHARACTER ATTRIBUTES
The appearance of displayed characters is controlled by attributes such as font,size, color,
and orientation. Attributes can be set Ooth for entire character strings(text) and for individual
characters defined as marker symbols .
There are a great many text options that can be made available to graphics programmers
.First of all, there is the choice of font (or typeface), which is a set of characters with a particular
design style such as New York, Courier, Helvetica, London, 'Times Roman, and various special
symbol groups.
The characters in a selected font can also be displayed with assorted underlining styles
(sodx,o,t.t ,e. . .d. . , d-ouble), in boldface, in italics. and in outline or shadow styles. A particular
font and associated stvle is selected in a PHlCS program by setting an integer code for the text font
parameter t f in the function.
setTextFont {tf}
Control of text color (or intensity) is managed from an application program with
SetYextColorIndex {tc}
where text color piramcter tc specifies an allowable color code.
Text size can be adjusted without changing the width-to-height ratio of characters with
setCharacterHeight {ch}
The width only of text can be set wlth the function
setCharacterExpansionFactor (cw)
Spacing between characters is controlled separately with
setCharacterSpacing (cs)
The orientation for a displayed character string is set according to the direction of the
character up vector:
setCharacterUpVector (upvect)