0% found this document useful (0 votes)
12 views122 pages

Computer Graphics Polygon Filling

The document discusses different methods for filling polygons in computer graphics, including solid fill, pattern fill, and algorithms like boundary fill and flood fill. It covers topics like polygon representation, fill rules, and determining if a point is inside or outside a polygon.

Uploaded by

Edgar Molina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views122 pages

Computer Graphics Polygon Filling

The document discusses different methods for filling polygons in computer graphics, including solid fill, pattern fill, and algorithms like boundary fill and flood fill. It covers topics like polygon representation, fill rules, and determining if a point is inside or outside a polygon.

Uploaded by

Edgar Molina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 122

Computer graphics

Polygon Filling

1
Polygon Filling
Types of filling
• Solid-fill
All the pixels inside the polygon’s boundary
are illuminated.

• Pattern-fill
the polygon is filled with an arbitrary
predefined pattern.

2
Polygon Representation
The polygon can be represented by listing its n
vertices in an ordered list.
P = {(x1, y1), (x2, y2), ……., (xn, yn)}.
The polygon can be displayed by drawing a line
between (x1, y1), and (x2, y2), then a line between
(x2, y2), and (x3, y3), and so on until the end vertex.
In order to close up the polygon, a line between (xn,
yn), and (x1, y1) must be drawn.
One problem with this representation is that if we
wish to translate the polygon, it is necessary to
apply the translation transformation to each vertex
in order to obtain the translated polygon.

3
Polygon Representation
For objects described by many polygons with many
vertices, this can be a time consuming process.
One method for reducing the computational
time is to represent the polygon by the (absolute)
location of its first vertex, and represent
subsequent vertices as relative positions from the
previous vertex. This enables us to translate the
polygon simply by changing the coordinates of the
first vertex.

4
Filling General Polygons
• Specifying the interior
– Must be able to determine which points are inside the polygon
• Need a fill rule
Filling General Polygons
• Specifying the interior
– There are two commonly used fill rules
• Even-odd parity rule
• Non-zero winding rule

Filled using even-odd parity rule Filled using none-zero winding rule
Even-odd Parity Rule
• To determine if a point P is inside or outside
– Draw a line from P to infinity
– Count the number of times the line crosses an edge
• If the number of crossing is odd, the point is inside
• If the number of crossing is even, the point is outside
Non-zero Winding Number
Rule
• The outline of the shape must be directed
– The line segments must have a consistent direction so that
they formed a continuous, closed path
Non-zero Winding Number
Rule
• To determine if a points is inside or outside
– Determine the winding number (i.e. the number of times the edge
winds around the point in either a clockwise or counterclockwise
direction)
• Points are outside if the winding number is zero
• Point are inside if the winding number is not zero
Non-zero Winding Number
Rule
• To determine the winding number at a point P
– Initialize the winding number to zero and draw a line (e.g.
horizontal) from P to infinity
– If the line crosses an edge directed bottom to up
• Add 1 to the winding number
– If the line crosses an edge directed top to bottom
• Subtract 1 from the winding number
Comparison between Odd Even Rule and Nonzero
Winding Rule
• For standard polygons and simple object both rule gives same result but for more
complicated shape both rule gives different result.

Odd Even Rule Nonzero Winding Rule


Inside-Outside Tests
• The non-zero winding number rule and the even-odd parity
rule can give different results for general polygons
– When polygons self intersect
– When polygons have interior holes

Even-odd parity Non-zero winding


Inside-Outside Tests
• Standard polygons
– Standard polygons (e.g. triangles, rectangles, octagons) do not
self intersect and do not contain holes
– The non-zero winding number rule and the even-odd parity
rule give the same results for standard polygons
Shared Vertices
• Edges share vertices
– If the line drawn for the fill rule intersects a vertex, the
edge crossing would be counted twice
• This yields incorrect and inconsistent even-odd parity
checks and winding numbers

Line pierces the outline Line grazes the outline


- Should count as one crossing - Should count as no crossings
Dealing with Shared Vertices
1. Check the vertex type (piercing or grazing)
– If the vertex is between two upwards or two downwards edges, the line
pierces the edge
• Process a single edge crossing
– If the vertex is between an upwards and a downwards edge, the line
grazes the vertex
• Don’t process any edge crossings

Vertex between two upwards edges Vertex between upwards and downwards edges
- Process a single crossing - Process no crossings
Dealing with Shared Vertices
2. Ensure that the line does not intersect a vertex
– Use a different line if the first line intersects a vertex
• Could be costly if you have to try several lines

– If using horizontal scan line for the inside-outside test


• Preprocess edge vertices to make sure that none of them fall on a scan line
– Add a small floating point value to each vertex y-position
Fill Options
• How to set pixel colors for points inside the
shape?

Pattern Fill Texture Fill


Solid Fill
Filled-Area Primitives
▪ In practical we often use polygon which are filled with some
colour or pattern inside it.
▪ There are two basic approaches to area filling on raster systems.
• One way to fill an area is to determine the overlap intervals for scan line that
cross the area.
• Another method is to start from a given interior position and paint outward
from this point until we encounter boundary.
Seed Fill
• Approach
– Select a seed point inside a region
– Move outwards from the seed point, setting neighboring
pixels until the region is filled

Seed point Move outwards Stop when the


to neighbors region is filled
Selecting the Seed Point
• Difficult to place the seed point automatically
– Seed fill works best in an interactive application where the
user sets the seed point

What is the inside of this shape?


* It depends on the user’s intent
Seed Fill
▪ Basic algorithm
select seed pixel
initialize a fill list to contain seed pixel
while (fill list not empty) {
pixel = get next pixel from fill list setPixel(pixel)
for (each of the pixel’s neighbors) {
if (neighbor is inside region AND neighbor not set)
add neighbor to fill list
}
}
Which neighbors should be
tested?
• There are two types of 2D regions
– 4-connected region (test 4 neighbors)
• Two pixels are 4-connected if they are vertical or horizontal neighbors

• 8-connected region (test 8 neighbors)


• Two pixels are 8-connected if they are vertical, horizontal, or diagonal
neighbors
Which neighbors should be
tested?
• Using 4-connected and 8-connected neighbors
gives different results

Magnified area Fill using 4-connected neighbors

Original boundary Fill using 8-connected neighbors


When is a Neighbor Inside the
Region?
▪ There are two types of tests, resulting in two filling approaches
• Boundary fill
• Flood fill
Boundary Fill Algorithm
• Another approach to area filling is to start at a
point inside a region and paint the interior outward
toward the boundary.
• If the boundary is specified in a single color, the fill
algorithm processed outward pixel by pixel until the
boundary color is encountered.
• A boundary-fill procedure accepts as input the
coordinate of the interior point (x, y), a fill color,
and a boundary color.

25
Boundary Fill Algorithm
The following steps illustrate the idea of the
recursive boundary-fill algorithm:

1. Start from an interior point.


2. If the current pixel is not already filled and if it is
not an edge point, then set the pixel with the fill
color, and store its neighboring pixels (4 or 8-
connected) in the stack for processing. Store only
neighboring pixel that is not already filled and is not
an edge point.
3. Select the next pixel from the stack, and continue
with step 2.

26
Boundary Fill Algorithm

The order of pixels that should be added to stack


using 4-connected is above, below, left, and right.
For 8-connected is above, below, left, right, above-
left, above-right, below-left, and below-right.

27
Boundary Fill Algorithm
4-connected (Example)

Start Position

28
Boundary Fill Algorithm
4-connected (Example)

3
2
1
1
2 3

29
Boundary Fill Algorithm
4-connected (Example)

4
2
1 4
1
2

30
Boundary Fill Algorithm
4-connected (Example)

2
1
1
2

31
Boundary Fill Algorithm
4-connected (Example)

5
5 1
1

32
Boundary Fill Algorithm
4-connected (Example)

1
1

33
Boundary Fill Algorithm
4-connected (Example)

34
void boundaryFill4(int x, int y, int fill_color,int boundary_color)
{
if(getpixel(x, y) != boundary_color &&
getpixel(x, y) != fill_color)
{
putpixel(x, y, fill_color);
boundaryFill4(x + 1, y, fill_color, boundary_color);
boundaryFill4(x, y + 1, fill_color, boundary_color);
boundaryFill4(x - 1, y, fill_color, boundary_color);
boundaryFill4(x, y - 1, fill_color, boundary_color);
}
}
Boundary Fill Algorithm
8-connected (Example)

Start Position

36
Boundary Fill Algorithm
8-connected (Example)

4 1 5
5
2 3
4
3
2
1

37
Boundary Fill Algorithm
8-connected (Example)

6
4 1
6
2 3
4
3
2
1

38
Boundary Fill Algorithm
8-connected (Example)

7 8

8
4 1
7
2 3
4
3
2
1

39
Boundary Fill Algorithm
8-connected (Example)

12
11 9 12
7 10 11

10
4 1
2 3
9
7
4
3
2
1

40
Boundary Fill Algorithm
8-connected (Example)

11 9
11
7 10
10
4 1
9
2 3
7
4
3
2
1

41
Boundary Fill Algorithm
8-connected (Example)

9
7 10
10

4 1 9
2 3 7
4
3
2
1

42
Boundary Fill Algorithm
8-connected (Example)

9
7

9
4 1
7
2 3
4
3
2
1

43
Boundary Fill Algorithm
8-connected (Example)

4 1
7
2 3
4
3
2
1

44
Boundary Fill Algorithm
8-connected (Example)

4 1
2 3
4
3
2
1

45
Boundary Fill Algorithm
8-connected (Example)

1
2 3

3
2
1

46
Boundary Fill Algorithm
8-connected (Example)

1
2

2
1

47
Boundary Fill Algorithm
8-connected (Example)

48
Boundary Fill Algorithm
8-connected (Example)

49
void boundaryFill8(int x, int y, int fill_color,int boundary_color)
{
if(getpixel(x, y) != boundary_color &&
getpixel(x, y) != fill_color)
{
putpixel(x, y, fill_color);
boundaryFill8(x + 1, y, fill_color, boundary_color);
boundaryFill8(x, y + 1, fill_color, boundary_color);
boundaryFill8(x - 1, y, fill_color, boundary_color);
boundaryFill8(x, y - 1, fill_color, boundary_color);
boundaryFill8(x - 1, y - 1, fill_color, boundary_color);
boundaryFill8(x - 1, y + 1, fill_color, boundary_color);
boundaryFill8(x + 1, y - 1, fill_color, boundary_color);
boundaryFill8(x + 1, y + 1, fill_color, boundary_color);
}
}
Problem of Staking and Efficient
Method
▪ Same procedure can be modified according to 8 connected region
algorithm by including four additional statements to test diagonal
positions.
▪ This procedure requires considerable stacking of neighbouring
points more, efficient methods are generally employed.
▪ Efficient method fill horizontal pixel spans across scan lines,
instead of proceeding to 4 connected or 8 connected neighbouring
points.
▪ Then we need only stack a beginning position for each horizontal
pixel span, instead of stacking all unprocessed neighbouring
positions around the current position.
▪ Starting from the initial interior point with this method, we first fill
in the contiguous span of pixels on this starting scan line.
Contd.
▪ Then we locate and stack starting positions for spans on the
adjacent scan lines.
▪ Spans are defined as the contiguous horizontal string of positions
bounded by pixels displayed in the area border colour.
▪ At each subsequent step, we unstack the next start position and
repeat the process.
▪ For e.g.
Contd.

3
2
(a) (b)
1 2 1 3
1 1

5 6 5
6
(c) 4 5 (d) 4 5
1 4 1 4
1 1
Boundary Fill Algorithm

Since the previous procedure requires considerable


stacking of neighboring pixels, more efficient
methods are generally employed.
These methods (Span Flood-Fill) fill horizontal
pixel spans across scan lines, instead of
proceeding to 4-connected or 8-connected
neighboring pixels.
Then we need only stack a beginning position for
each horizontal pixel spans, instead of stacking all
unprocessed neighboring positions around the
current position.

54
Flood Fill Algorithm
Sometimes we want to fill in (recolor) an area that is
not defined within a single color boundary.
We paint such areas by replacing a specified
interior color instead of searching for a boundary
color value.

This approach is called a flood-fill algorithm.

55
Flood Fill Algorithm
We start from a specified interior pixel (x, y) and
reassign all pixel values that are currently set to a
given interior color with the desired fill color.
If the area has more than one interior color, we
can first reassign pixel values so that all interior
pixels have the same color.
Using either 4-connected or 8-connected
approach, we then step through pixel positions
until all interior pixels have been repainted.

56
Introduction to Flood-Fill
Algorithm
▪ Sometimes it is required to fill in an area that is not defined within a single
colour boundary.
▪ In such cases we can fill areas by replacing a specified interior colour instead of
searching for a boundary colour.
▪ This approach is called a flood-fill algorithm. Like boundary fill algorithm, here
we start with some seed and examine the neighbouring pixels.
▪ However, here pixels are checked for a specified interior colour instead of
boundary colour and they are replaced by new colour.
▪ Using either a 4-connected or 8-connected approach, we can step through pixel
positions until all interior point have been filled.
Procedure floodfill (x, y,fill_ color, old_color:
integer)
If (getpixel (x, y)=old_color)
{
setpixel (x, y, fill_color);
fill (x+1, y, fill_color, old_color);
fill (x-1, y, fill_color, old_color);
fill (x, y+1, fill_color, old_color);
fill (x, y-1, fill_color, old_color);
}
}
Scan-Line Polygon Fill Algorithm
▪ For each scan-line crossing a polygon, the algorithm locates the
intersection points are of scan line with the polygon edges.
▪ This intersection points are stored from left to right.
▪ Frame buffer positions between each pair of intersection point are
set to specified fill color.

Scan
line
Contd.
▪ Scan line intersects at vertex are required special handling.
▪ For vertex we must look at the other endpoints of the two line
segments which meet at this vertex.
• If these points lie on the same (up or down) side of the scan line, then that
point is counts as two intersection points.
• If they lie on opposite sides of the scan line, then the point is counted as
single intersection.

Scan
line
Scan
line
Scan
line
Edge Intersection Calculation with Scan-
Line
Contd.
Edge Intersection Calculation with Scan-Line for parallel
execution
Simplified Method for Edge Intersection Calculation with
Scan-Line

Counter
=3
=2
=4
=0
=5
=6
=1
Use of Sorted Edge table in Scan-Line Polygon Fill
Algorithm
Contd.
Scan
Line
Numbe
B .
r .
.

C .
.
.
C E
D .
.
A .
1
0
Character Generation
▪ We can display letters and numbers in variety of size and style.
▪ The overall design style for the set of character is called typeface.
▪ Today large numbers of typefaces are available for computer
application for example Helvetica, Arial etc.
▪ Originally, the term font referred to a set of cast metal character
forms in a particular size and format.
▪ Example: 10-point Courier Italic or 12- point Palatino Bold.
The Scan-Line Polygon Fill Algorithm
The scan-line polygon-filling algorithm involves
• the horizontal scanning of the polygon from its lowermost to its
topmost vertex,
• identifying which edges intersect the scan-line,
• and finally drawing the interior horizontal lines with the specified
fill color. process.

68
The Scan-Line Polygon Fill Algorithm
Dealing with vertices

69
The Scan-Line Polygon Fill Algorithm
Dealing with vertices

• When the endpoint y coordinates of the two edges are


increasing, the y value of the upper endpoint for the
current edge is decreased by one (a)
• When the endpoint y values are decreasing, the y value
of the next edge is decreased by one (b)

70
The Scan-Line Polygon Fill Algorithm
Determining Edge Intersections
m = (yk+1 – yk) / (xk+1 – xk)
yk+1 – yk = 1
xk+1 = xk + 1/m

71
The Scan-Line Polygon Fill Algorithm
• Each entry in the table for a particular scan line contains
the maximum y value for that edge, the x-intercept value
(at the lower vertex) for the edge, and the inverse slope of
the edge.

72
The Scan-Line Polygon Fill Algorithm
(Example) Polygon = {A, B, C, D, E, F, G}
Polygon = {(2, 7), (4, 12), (8,15), (16, 9), (11, 5), (8, 7), (5, 5)}

73
The Scan-Line Polygon Fill Algorithm
(Example)

74
The Scan-Line Polygon Fill Algorithm
(Example)

• Vertex A should be split into two vertices A' (xA', 6) and


A(2, 7)
m =( 5 – 7)/( 5 – 2) = – 2/3
x'A = 5 + (–3/2)( 7 – 1 – 5) = 7/2 = 3.5  4
The vertex A is split to A' (4, 6) and A(2, 7)

75
The Scan-Line Polygon Fill Algorithm
(Example)

• Vertex B should be split into two vertices B' (xB', 11) and
B(4, 12)
m =( 7 – 12)/( 2 – 4) = 5/2
x'A = 2 + (2/5)( 12 – 1 – 7) = 18/5 = 3.6  4
The vertex B is split to B' (4, 11) and B(4, 12)

76
The Scan-Line Polygon Fill Algorithm
(Example)

• Vertex D should be split into two vertices D(16, 9) and D'


(xD', 8)
m =( 5 – 9)/( 11 – 16) = 4/5
x'D = 11 + (5/4)( 9 – 1 – 5) = 59/4 = 14.75  15
The vertex D is split to D(16, 9) and D' (15, 8)

77
The Scan-Line Polygon Fill Algorithm
(Example)

78
The Scan-Line Polygon Fill Algorithm
(Example)

79
The Scan-Line Polygon Fill Algorithm
(Example)

80
The Scan-Line Polygon Fill Algorithm
(Example)

81
The Scan-Line Polygon Fill Algorithm
(Example)

82
Contd.
▪ Now, the terms font and typeface are often used interchangeably,
since printing is no longer done with cast metal forms.
▪ Methods of character generation are:
➢ Bitmap Font/ Bitmapped Font
➢ Outline Font
➢ Stroke Method
➢ Starbust Method
Bitmap Font/ Bitmapped Font
▪ A simple method for representing the character 0 0 1 1 1 1 0 0
shapes in a particular typeface is to use 0 1 1 1 1 1 1 0
1 1 0 0 0 0 1 1
rectangular grid patterns. 1 1 0 0 0 0 1 1
1 1 1 1 1 1 1 1
▪ In frame buffer, the 1 bits designate which 1 1 1 1 1 1 1 1
pixel positions are to be displayed on the 1 1 0 0 0 0 1 1
1 1 0 0 0 0 1 1
monitor.
▪ Bitmap fonts are the simplest to define and display.
▪ Bitmap fonts require more space.
▪ It is possible to generate different size and other variation from one
set but this usually does not produce good result.
Outline Font
▪ In this method character is generated using curve
section and straight line as combine assembly.
▪ To display the character we need to fill interior
region of the character.
▪ This method requires less storage since each
variation does not required a distinct font cache.
▪ We can produce boldface, italic, or different sizes
by manipulating the curve definitions for the
character outlines.
▪ But this will take more time to process the outline
fonts, because they must be scan converted into the
frame buffer.
Stroke Method
• It uses small line segments to generate
a character.
• The small series of line segments are
drawn like a stroke of a pen to form a
character.
• We can generate our own stroke method by calling line
drawing algorithm.
• Here it is necessary to decide which line segments are
needs for each character and then draw that line to display
character.
• It support scaling by changing length of line segment.
Starbust Method
▪ In this method a fix pattern of lines (24 line) segments are used to
generate characters. 03 04
13 14
02 23 05
17 18
01 06
21
12 22 07
20
24 19
11 08
16 15
10 09

▪ We highlight those lines which are necessary to draw a particular


character.
▪ Pattern for particular character is stored in the form of 24 bit code.
▪ In which each bit represents corresponding line having that number.
▪ We put bit value 1 for highlighted line and 0 for other line.
Contd.
▪ Example letter V
03 04
13 14
02 23 05
17 18
01 06
21
12 22 07
20
24 19
11 08
16 15
10 09

▪ Code for letter V = 1 1 0 0 1 1 1 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0


▪ This technique is not used now a days because:
• It requires more memory to store 24 bit code for single character.
• It requires conversion from code to character.
• It doesn’t provide curve shapes.
Aliasing
▪ Primitives generated in raster graphics by various algorithms have
stair step shape or jagged appearance.
▪ Jagged appearance is due to integer calculation by rounding actual
values.
▪ This distortion of actual information due to low frequency
sampling is called aliasing.
Antialiasing
Contd.
Antialiasing Methods
1. Supersampling Straight Line Segments
2. Pixel-Weighting Masks
3. Filtering Techniques
4. Pixel Phasing
https://youtu.be/R3AgvpOA2qw
Antialiasing Methods
Supersampling Straight Line
Segments
▪ For the greyscale display of a straight-line segment, we can divide
each pixel into a number of sub pixels and determine the number of
sub pixel along the line path.
▪ Then we set intensity level of each pixel proportional to number of
sub pixel along the line path.
▪ E.g. in figure area of each pixel is
divided into nine sub pixel and then we
determine how many number of sub
pixel are along the line ( it can be 3 or 2
or 1 as we divide into 9 sub pixel).
▪ Based on number 3 or 2 or 1 we assign
intensity value to that pixel.
Contd.
▪ We can achieve four intensity levels by dividing pixel into 16 sub
pixels and five intensity levels by dividing into 25 sub pixels etc.
▪ Lower intensity gives blurred effect and hence performs
antialiasing.
▪ Other way is we considered pixel areas of finite size, but we
treated the line as a mathematical entity with zero width.
▪ Actually, displayed lines have a width approximately equal to that
of a pixel.
▪ If we take finite width of the line into account, we can perform
supersampling by setting each pixel intensity proportional to the
number of sub pixels inside the polygon representing the line area.
Contd.
▪ A sub pixel can be considered to be
inside the line if its lower left corner is
inside the polygon boundaries.
▪ Advantage of this is that it having
number of intensity equals to number of
sub pixel.
▪ Another advantage of this is that it will distribute total intensity
over more pixels.
▪ E.g. in figure pixel below and left to (10, 20) is also assigned some
intensity levels so that aliasing will reduce.
▪ For color display we can modify levels of color by mixing
background color and line color.
Pixel-Weighting Masks
▪ Supersampling method are often implemented by giving more
weight to sub pixel near the center of pixel area.
▪ As we expect centre sub pixel to be more important in determining
the overall intensity of a pixel.
▪ For the 3 by 3 pixel subdivisions we have considered so far, a
weighting scheme as in fig. could be used.
▪ The center sub pixel here is weighted four times that of the corner
sub pixels and twice that of the remaining sub pixels.
▪ By averaging the weight of sub pixel which are
along the line and assign intensity proportional to
average weight will reduce aliasing effect.
Filtering Techniques
▪ It is more accurate method for antialiasing.
▪ Common example of filter is rectangular, conical and Gaussian
filters.
▪ Methods for applying the filter function are similar to applying a
weighting mask, but now we integrate over the pixel surface to
obtain the weighted average intensity.
▪ For reduce computation we often use table look up.
Pixel Phasing
▪ On raster system if we pass the electron beam from the closer sub
pixel so that overall pixel is shifted by factor ¼, ½, or ¾ to pixel
diameter.
▪ Where beam strike at that part of pixel get more intensity then
other parts of the pixel and gives antialiasing effect.
▪ Some systems also allow the size of individual pixels to be
adjusted as an additional means for distributing intensities.
Line Attributes
▪ Basic attributes of a straight line segment are:
• Type
• Dimension
• color
• pen or brush option.
Line Type
▪ Possible selection for the line-type attribute includes solid lines, dashed
lines, and dotted lines etc.
1 Solid

2 Dashed

3 Dotted
4 Dotdas
h lines by setting
▪ We modify a line –drawing algorithm to generate such
the length and spacing of displayed solid sections along the line path.
▪ To set line type attributes in a PHIGS application program, a user
invokes the function: setLinetype(It)
▪ Where parameter lt is assigned a positive integer value of 1, 2, 3, 4… etc.
to generate lines that are, respectively solid, dashed, dotted, or dotdash
etc.
Line Width
▪ Implementation of line-width options depends on the capabilities
of the output device.
▪ A heavy line on a video monitor could be displayed as adjacent
parallel lines, while a pen plotter might require pen changes.
▪ To set line width attributes in a PHIGS application program, a user
invokes the function: setLinewidthScalFactor (lw)
▪ Line-width parameter lw is assigned a positive number to indicate
the relative width of the line to be displayed.
▪ Values greater than 1 produce lines thicker than the standard line
width and values less than the 1 produce line thinner than the
standard line width.
Contd.
▪ In raster graphics we generate thick line by plotting
• above and below pixel of line path when slope |m|<1. &
• left and right pixel of line path when slope |m|>1.
Line Width at Endpoints and Join
▪ As we change width of the line we can also change line end and
join of two lines which are shown below

Butt caps Miter join

Projecting square Round join


caps

Round caps Bevel join


Line color
▪ The name itself suggests that it is defining color of line displayed
on the screen.

▪ By default system produce line with current color but we can


change this color by following function in PHIGS package as
follows: setPolylinecolorIndex (lc)
▪ In this lc is constant specifying particular color to be set.
Pen and Brush Options
• In some graphics packages line is
displayed with pen and brush
selections.
• Options in this category include
shape, size, and pattern.
• These shapes can be stored in a
pixel mask that identifies the
array of pixel positions that are to
be set along the line path.
• Also, lines can be displayed with
selected patterns by
superimposing the pattern values
onto the pen or brush mask.
Area-Fill Attributes
▪ For filling any area we have choice between solid colors or pattern
to fill all these are include in area fill attributes. Which are:
• Fill Styles
• Pattern Fill
• Soft Fill
Fill Styles
▪ Area are generally displayed with three basic style.
1. hollow with color border
2. filled with solid color
3. filled with some design
▪ In PHIGS package fill style is selected by following function:
setInteriorStyle (fs)
▪ Value of fs include hollow ,solid, pattern etc.
Contd.
▪ Another values for fill style is hatch, which is patterns of line like
parallel line or crossed line.

Hollow Solid Pattern Diagonal Diagonal Cross-


Hatch Fill Hatch Fill

▪ For setting interior color in PHIGS package we use:


setInteriorColorIndex (fc)
▪ Where fc specify the fill color.
Pattern Fill
• We select the pattern with Pattern Table
setInteriorStyleIndex (pi) Index(pi Pattern(cp
• Where pattern index parameter pi ) )
specifies position in pattern table 1
entry. 2
• For example:
– SetInteriorStyle( pattern ) ;
– setInteriorStyleIndex ( 2 ) ;
– fillArea (n, points);
Contd.
▪ We can also maintain separate table for hatch pattern.
▪ We can also generate our own table with required pattern.
▪ Other function used for setting other style as follows:
setpatternsize (dx, dy)
▪ setPaternReferencePoint (position)
▪ We can create our own pattern by setting and resetting group of
pixel and then map it into the color matrix.
Soft Fill
Contd.
Character Attributes
▪ The appearance of displayed characters is controlled by attributes
such as:
• Font
• Size
• Color
• Orientation.
▪ Attributes can be set for entire string or may be individually.
Text Attributes
▪ In text we are having so many style and design like italic fonts,
bold fonts etc.
▪ For setting the font style in PHIGS package we have function:
setTextFont (tf)
▪ Where tf is used to specify text font.
▪ For setting color of character in PHIGS we have function:
setTextColorIndex (tc)
▪ Where text color parameter tc specifies an allowable color code.
▪ For setting the size of the text we use function:
setCharacterheight (ch)
▪ Where ch is used to specify character height.
Contd.
▪ For scaling the character we use function:
setCharacterExpansionFacter (cw)
▪ Where character width parameter cw is set to a positive real
number that scale the character body width.
▪ Spacing between character is controlled by function:
▪ setCharacterSpacing (cs)
▪ Where character spacing parameter cs can be assigned any real
value.
Contd.
▪ The orientation for a displayed character string is set according to
the direction of the character up vector:
setCharacterUpVector (upvect)
▪ Parameter upvect in this function is assigned two values that
specify the x and y vector components.
▪ Text is then displayed so that the orientation of characters from
baseline to cap line is in the direction of the up vector.
▪ For setting the path of the character we use function:
setTextPath (tp)
▪ Where the text path parameter tp can be assigned the value: right,
left, up, or down.
Contd.
▪ For setting the alignment we use function:
setTextAlignment (h, v)
▪ Where parameter h and v control horizontal and vertical alignment
respectively.
▪ For specifying precision for text display is given with function:
setTextPrecision (tpr)
▪ Where text precision parameter tpr is assigned one of the values:
string, char, or stroke.
▪ The highest-quality text is produced when the parameter is set to
the value stroke.
Marker Attributes
▪ A marker symbol display single character in different color and in
different sizes.
▪ For marker attributes implementation by procedure that load the
chosen character into the raster at defined position with the
specified color and size.
▪ We select marker type using function: setMarkerType (mt)
▪ Where marker type parameter mt is set to an integer code.
Contd.
▪ Typical codes for marker type are the integers 1 through 5,
specifying, respectively:
1. a dot (.)
2. a vertical cross (+)
3. an asterisk (*)
4. a circle (o)
5. a diagonal cross (x).
▪ Displayed marker types are centred on the marker coordinates.
Contd.
▪ We set the marker size with function:
SetMarkerSizeScaleFactor (ms)
▪ Where parameter marker size ms assigned a positive number
according to need for scaling.
▪ For setting marker color we use function:
setPolymarkerColorIndex (mc)
▪ Where parameter mc specify the color of the marker symbol.

You might also like