Top Banner
Output Primitives Dr. S.M. Malaek Assistant: M. Younesi
55

Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Apr 07, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Output Primitives

Dr. S.M. MalaekAssistant: M. Younesi

Page 2: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Output PrimitivesOutput Primitives: Basic geometric structures (points, straight line segment, circles and other conic sections, quadric surfaces, spline curve and surfaces, polygon color areas, and character strings)These picture components are often defined in a continuous space.

Page 3: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Output PrimitivesIn order to draw the primitive objects, one has to first scan convert the object.

Scan convert: Refers to he operation of finding out the location of pixels to the intensified and then setting the values of corresponding bits, in the graphic memory, to the desired intensity code.

Page 4: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Output PrimitivesEach pixel on the display surface has a finite size depending on the screen resolution and hence a pixel cannot cannot representrepresent a single mathematical point.

Page 5: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Scan Converting A Point

Page 6: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Scan Converting A PointA mathematical point (x,y) needs to be scan converted to a pixel at location (x´, y´).

Page 7: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Scan Converting A Pointx´=Round(x) and y´=Round(y)All points that satisfy:

are mapped to pixel (x´,y´) 11+′<≤′+′<≤′

yyyxxx

Page 8: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Scan Converting A Pointx´=Round(x+0.5) and y´=Round(y+o.5)All points that satisfy:

are mapped to pixel (x´,y´) 5.05.05.05.0

+′<≤−′+′<≤−′

yyyxxx

Page 9: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Scan Converting A Line

Page 10: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Scan Converting A LineThe Cartesian slope- intercept equationfor a straight line is:

12

12

xxyym

−−

=

bxmy +⋅=

11 xmyb ⋅−=

xmy ∆=∆ myx ∆

=∆

Page 11: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Scan Converting A Line

These equation form the basic for determining deflection voltage in analog devices.

xmy ∆=∆myx ∆

=∆

|m|<1 |m|>1

Page 12: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Scan Converting A LineOn raster system, lines are plotted with pixels, and step size (horizontal & vertical direction) are constrained by pixel separation.

Page 13: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Scan Converting A LineWe must samplesample a line at discretepositions and determine the nearest pixel to the line at each sampled position.

Page 14: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Digital Differential Analyzer

(DDA Algorithm)

Page 15: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

DDA AlgorithmAlgorithm is an incremental scan conversion method.Based on calculating either orIf |m|<1,

x∆ y∆)1( =∆x

myyxmy

kK +=∆=∆

+1

Page 16: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

DDA AlgorithmIf |m|>1,

)1( −=∆x

)1( =∆y

mxx

myx

kK

11 +=

∆=∆

+

If

myyxmy

kK −=∆=∆

+1

Page 17: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Bresenham’s Line Algorithm

Page 18: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Bresenham’s Line AlgorithmA highly efficient incrementalmethod for scan converting lines.Using only incremental integercalculation.

By testing the sign of an integer parameter, whose value is proportional to the difference between the separation of two pixel positions from the actual line path.

Page 19: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Bresenham’s Line AlgorithmA highly efficient incrementalmethod for scan converting lines.Using only incremental integercalculation.

By testing the sign of an integer parameter, whose value is proportional to the difference between the separation of two pixel positions from the actual line path.

Page 20: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Bresenham’s Line Algorithm

Page 21: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Bresenham’s Line Algorithm

Page 22: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

y

yk

yk+1

xk+1

}}

d2

d1

Bresenham’s Line Algorithm

y

yk

yk+1

xk+1

}}

d2

d1

y

yk

yk+1

xk+1

}}

d2

d1

Page 23: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Bresenham’s Line Algorithmd1 = y - yk = m (xk + 1) + b - yk

d2 = (yk + 1) - y = yk + 1 - m (xk + 1) –b

d1 - d2 = 2 m (xk + 1) - 2 yk + 2b -1

Page 24: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Bresenham’s Line Algorithm

Pk = ∆X ( d1 - d2) =2 ∆Y . xk - 2 ∆X . yk + c

c = constante = 2 ∆Y + ∆X (2b -1)

Page 25: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Let's get rid of multiplicationsPk+1 = 2 ∆Y . xk+1 - 2 ∆X .y + c

Pk+1 - Pk = 2 ∆Y (xk+1 - xk) -2 ∆X (yk+1 - yk) (get rid of the constance)

Pk+1 = Pk + 2 ∆Y - 2 ∆X (yk+1 - yk)

Pk+1 = Pk + 2∆Y or

= Pk + 2(∆Y – ∆X )

with (yk+1 - yk) = 0 or 1 depending on Pk sign

Page 26: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

P0 =∆X (d1-d2)=∆X[2m(x0+1)-2y0+2b-1]=∆X[2(mx0+b-y0)+2m-1]

P0=2∆Y -∆X0

m=∆y/x

Bresenham’s Line Algorithm

Page 27: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Bresenham’s Line AlgorithmExample: Digitize the line with endpoint (20,10) and (30,18)

∆X=10 ∆Y= 8P0=2∆Y –∆x=6 2∆Y =162(∆Y – ∆X)=-4

P0=2∆Y –∆XPk+1 = Pk + 2∆Y

or = Pk + 2(∆Y – ∆X)

Page 28: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation Algorithms

Page 29: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation AlgorithmsThe equation of a circle:

We could solve for y in terms of x

Page 30: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation Algorithms

The spacing between plotted pixel positions is not uniform.

Page 31: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation AlgorithmsComputation can be reduced by considering the symmetry of circles

8 -Way symmetry

Page 32: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Midpoint Circle Algorithm

Page 33: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation AlgorithmsAs in the line algorithm, we sample at unit intervals and determine the closet pixel position to the circle path at each step.

Page 34: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation AlgorithmsPoints are generated from 90º to 45º, moves will be made only in the +x and –y direction.positive x direction over this octant and use a decision parameter

Page 35: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation Algorithms

We define a circle function:

⎪⎩

⎪⎨

>=<

−+=o

ryxyxfcircle 00

),( 222

Page 36: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation AlgorithmsMidpoint

Consider the coordinates of the point halfway between pixel T and pixel S

)21,1( −+ ii yx

Midpoint

Page 37: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation Algorithms

We use it to define a decision parameter

222 )21()1()

21,1( ryxyxfp iiii −−++=−+=

Page 38: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation AlgorithmsIf is negative, the midpoint is inside the pixel, and we choose pixel T.If we choose pixel S.0≥ip

0<ip

Page 39: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation AlgorithmsParameter for the next step is:

since

2

1

2

11 )21()1( ryxp iii −−++=

+++

11 +=+ ii xx

Page 40: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation Algorithms

If T is chosen ( ) we have:

If pixel S is chosen ( ) we have

0<ip

0≥ip

Page 41: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation Algorithms

In terms of

Page 42: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation Algorithms

Initial value for the decision parameter using the original function of (0,r)

When r is an integer we can simply set

Page 43: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation Algorithms

Page 44: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation Algorithmsint x = 0;int y = radius; int p = 1 - radius;circlePoints(xCenter, yCenter, x, y, pix);while (x < y) {x++;if (p < 0) {p += 2*x+1;} else {y--;p += 2*(x-y+1);}circlePoints(xCenter, yCenter, x, y, pix);}

Page 45: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Circle Generation AlgorithmsExample: A circle radius r=10x=0 to x=yP0=1-r = -9

Page 46: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

ExercisesExercises

Page 47: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

1. Scan Converting Arcs And Sectors?

Page 48: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Character Generation

Page 49: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Character Generation

Letters, numbers, and other character can be displayed in a variety of size and styles.

Page 50: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Character Generation• Typeface: The overall design style

for a set of characters is call typeface: Zar, nazanin, Titr.

Font: Referred to a set of cast metal character forms in a particular size and forma: 10 point Zar.

Page 51: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Character GenerationTwo different representation are used for storing computer fonts:

1. Bitmap font (or bitmapped font)

2. Outline font

Page 52: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Bitmap fontBitmap font (or bitmapped font): A simple method for representing the character shapes in a particular typeface is to use rectangular grid pattern.

Page 53: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Bitmap fontThe character grid only need to be mapped to a frame buffer position.Bitmap fonts required more space, because each variation (size and format) must be stored in a font cash.

Bold Italic

Page 54: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Outline FontGraphic primitives such as lines and arcs are used to define the outline of each character.Require less storage since variation does not require a distinct font cash.

Page 55: Output primitives - Sharifae.sharif.edu/~aerocad/Output primitives.pdf · 2007-04-17 · Output Primitives In order to draw the primitive objects, one has to first scan convert the

Outline FontWe can produce boldface, italic, or different size by manipulating the curve definition for the character outlines.

It does take more time to process the outline fonts, because they must be scan converted into frame buffer.