• Tidak ada hasil yang ditemukan

13_Scan_Conversion.pdf Official Site of Achmad Benny Mutiara Gunadarma University Scan Conversion

N/A
N/A
Protected

Academic year: 2018

Membagikan "13_Scan_Conversion.pdf Official Site of Achmad Benny Mutiara Gunadarma University Scan Conversion"

Copied!
44
0
0

Teks penuh

(1)

Andries van Dam

Scan Conversion

CS123

(2)

Andries van Dam Line Drawing

 Draw a line on a raster screen between two points

 Why is this a difficult problem?

 What is drawing on a raster display?  What is a line in raster world?

 Efficiency and appearance are both important

Problem Statement

 Given two points P and Q in XY plane, both with integer coordinates,

determine which pixels on raster screen should be on in order to draw a unit-width line segment starting at P and ending at Q

2 of 44

Scan Converting Lines

(3)

Andries van Dam

 Final step of rasterisation (process of taking geometric shapes and converting them into an array of pixels stored in the framebuffer to be displayed)

 Takes place after clipping occurs

 All graphics packages do this at the end of the rendering pipeline

 Takes triangles and maps them to pixels on the screen

 Also takes into account other properties like lighting and shading, but we’ll focus first on algorithms for line scan conversion

3 of 44

What is Scan Conversion?

(4)

Andries van Dam

Special cases:

Horizontal Line:

 Draw pixel P and increment x coordinate value by 1 to get next pixel.  Vertical Line:

 Draw pixel P and increment y coordinate value by 1 to get next pixel.  Diagonal Line:

 Draw pixel P and increment both x and y coordinate by 1 to get next pixel.  What should we do in general case?

 Increment x coordinate by 1 and choose point closest to line.  But how do we measure closest ?

4 of 44

Finding the next pixel:

(5)

Andries van Dam

 Why can we use vertical distance as a measure of which point is closer?

 … because vertical distance is proportional to actual distance  Similar triangles show that true

distances to line (in blue) are directly proportional to vertical distances to line (in black) for each point

 Therefore, point with smaller

vertical distance to line is closest to line

5 of 44

Vertical Distance

,

,

(6)

Andries van Dam

 Each iteration requires a floating-point multiplication

 Modify algorithm to use deltas

 ( �+) = ∗ ( �+) + B

�+ = + ∗ ( �+)

 If  = �+ = 1, then �+ = +

 At each step, we make incremental calculations based on preceding step to find next y value

6 of 44

Strategy 1

Incremental Algorithm (1/3)

(7)

Andries van Dam 7 of 44

Strategy 1

Incremental Algorithm (2/3)

� + , � +

�, �

�, �

� + , � +

(8)

Andries van Dam 8 of 44

Sample Code and Problems (3/3)

void Line(int x0, int y0, int x1, int y1) { Since slope is fractional, need special case for vertical lines (dx = 0)

(9)

Andries van Dam

Assume that line’s slope is shallow and positive < slope < ;

other slopes can be handled by suitable reflections about

principle axes

Call lower left endpoint

,

and upper right endpoint

,

Assume that we have just selected pixel at

,

Next, we must choose between pixel to right (E pixel), or one

right and one up (NE pixel)

Let

Q

be intersection point of line being scan-converted and

vertical line

=

+

9 of 44

Strategy 2

Midpoint Line Algorithm (1/3)

(10)

Andries van Dam 10 of 44

Strategy 2

Midpoint Line Algorithm (2/3)

Previous pixel

E pixel NE pixel

Midpoint M

Q = ,

= + dashed

(11)

Andries van Dam

 Line passes between E and NE

 Point that is closer to intersection point must be chosen

 Observe on which side of line midpoint � lies:

 E is closer to line if midpoint � lies above line, i.e., line crosses bottom half

 NE is closer to line if midpoint � lies below line, i.e., line crosses top half

 Error (vertical distance between chosen pixel and actual line) is always ≤ .

11 of 44

Strategy 2- Midpoint Line Algorithm (3/3)

For line shown, algorithm chooses NE as next pixel.

Now, need to find a way to calculate on which side of line midpoint lies

E pixel NE pixel

(12)

Andries van Dam

 Line equation as function: � = = + = +

 Line equation as implicit function: � , = + + =

 Avoids infinite slopes, provides symmetry between x and y

 So from above,

∙ = ∙ + ∙

∙ − ∙ + ∙ =

∴ = , = − , = ∙

 Properties (proof by case analysis):

 � , = when any point is on line

(13)

Andries van Dam

Decision Variable :

 We only need sign of f + , + . to see where the line lies, and then

How do we incrementally update ?

 On basis of picking E or NE, figure out location of � for the next pixel, and corresponding value for next grid line.

 We can derive for the next pixel based on our current decision.

13 of 44

Decision Variable

(14)

Andries van Dam

 We can compute value of decision variable at next step incrementally without computing F(M) directly

 = + E = +

 E can be thought of as correction or update factor to take to

 It is referred to as forward difference

14 of 44

Incrementing Decision Variable if E was chosen:

(15)

Andries van Dam

Increment M by one in both x and y directions:  = � + , + .

= + + + . +

 NE = −

 = + + → NE = + = −

 Thus, incrementally,

= + NE = + −

15 of 44

If NE was chosen:

(16)

Andries van Dam

At each step, algorithm chooses between 2 pixels based on

sign of decision variable calculated in previous iteration.

It then updates decision variable by adding either

E or

NE to old value depending on choice of pixel. Simple

additions only!

First pixel is first endpoint

,

,

so we can directly

calculate initial value of

d

for choosing between E and NE.

16 of 44

Summary (1/2)

(17)

Andries van Dam

 This multiplies each constant and decision variable by 2, but does not change sign

 Note: this is identical to Bresenham’salgorithm , though derived by different means.

That won’t be true for circle and ellipse scan conversion.

17 of 44

Summary (2/2)

(18)

Andries van Dam

(19)

Andries van Dam

Version 1: really bad

For from − :

= − ;

WritePixel(round( ), round( ));

WritePixel(round( ), round(− );

Version 2: slightly less bad

For from to :

(20)

Andries van Dam 20 of 44

are also on the circle

 Hence there is 8-way symmetry

 Reduce the problem to finding the pixels for 1/8 of the circle.

(21)

Andries van Dam

Scan top right 1/8 of circle of radius

Circle starts at

,

+

Let’s use another incremental

algorithm with decision variable

evaluated at midpoint

21 of 44

Using the Symmetry

(x0, y0)

(22)

Andries van Dam

Note: can replace all occurrences of , with 0, shifting coordinates by − , −

22 of 44

The incremental algorithm

a sketch

(23)

Andries van Dam

Decision variable

negative if we move E, positive if we move SE (or vice versa).

Follow line strategy: Use implicit equation of circle

� ,

=

+

=

� ,

is zero on circle, negative inside, positive outside

If we are at pixel

,

examine

+ ,

and

+ , −

Compute

f

at the midpoint.

23 of 44

What we need for the Incremental Algorithm

(24)

Andries van Dam

 Evaluate � , = + − at the point:

+ , −

 We are asking: Is � � =

� + , − = + + − −

positive or negative? it is zero on circle

24 of 44

The Decision Variable

 If negative, midpoint inside circle, choose E

vertical distance to the circle is less at + , than at

+ , −

 If positive, opposite is true, choose SE

(25)

Andries van Dam

 Decision based on vertical distance

 Ok for lines, since d and dvert are proportional

 For circles, not true:

+ , , �� = + + −

+ , − , �� = + + − −

 Which d is closer to zero? (i.e., which value below is closest to R?):

+ + or + + −

25 of 44

The right decision variable?

(26)

Andries van Dam

 We could ask instead: )s + + or + + − closer to

?

 The two values in equation above differ by:

 + + − + + − = −

26 of 44

Alternate Phrasing (1/3)

(27)

Andries van Dam

 The second value, which is always less, is closer if its difference from R2 is less

than: −

i.e., if − + + − < −

then < − + + + − − R

< + + − + + − − < + + − + −

< + + − +

4 −

27 of 44

Alternate Phrasing (2/3)

(28)

Andries van Dam

 The radial distance decision is whether

= + + − + −

is positive or negative.

 The vertical distance decision is whether

= + + − −

is positive or negative; and are ¼ apart.

 The integer is positive only if + ¼ is positive (except special case

where = : remember you’re using integers .

28 of 44

Alternate Phrasing (3/3)

(29)

Andries van Dam

 How can we compute the value of

� , = + + − −

at successive points? (vertical distance approach)

 Answer:

 Note that � + , − � , = Δ , = +

 and that � + , − − � ,

= Δ�� , = − +

29 of 44

Incremental Computation Revisited (1/2)

(30)

Andries van Dam

 If we move E, update d = f(M) by adding +

 If we move SE, update d by adding

− +

 Forward differences of a 1st degree

polynomial are constants and those

of a 2nd degree polynomial are 1st degree polynomials

 this first order forward difference, like a partial derivative, is one

degree lower

30 of 44

Incremental Computation (2/2)

(31)

Andries van Dam

 The function ΔE , = + is linear, hence amenable to incremental computation:

ΔE + , − ΔE , = ΔE + , − − ΔE , =

 Similarly

ΔSE + , − ΔSE , = ΔSE + , − − ΔSE , =

31 of 44

Second Differences (1/2)

(32)

Andries van Dam

 For any step, can compute new ΔE , from old ΔE , by adding

appropriate second constant increment – update delta terms as we move. This is also true of ΔSE , .

(33)

Andries van Dam

Midpoint Eighth Circle Algorithm

(34)

Andries van Dam

 Uses floats!

 1 test, 3 or 4 additions per pixel

 Initialization can be improved

 Multiply everything by 4: No Floats!

 Makes the components even, but sign of decision variable remains same

Questions

 Are we getting all pixels whose distance from the circle is less than ½?

 Why is y > x the right criterion?

 What if it were an ellipse?

34 of 44

Analysis

(35)

Andries van Dam

 Aligned Ellipses

 Non-integer primitives

 General conics

 Patterned primitives

35 of 44

Other Scan Conversion Problems

(36)

Andries van Dam

 Equation is 22 + 22 = i.e., + =

 Computation of Δ and Δ�� is similar

 Only 4-fold symmetry

 When do we stop stepping horizontally and switch to vertical?

36 of 44

Aligned Ellipses

(37)

Andries van Dam

 When absolute value of slope of ellipse is more than 1:

 How do you check this? At a point , for which � , = , a vector perpendicular to the curve is �� , , which is

[� , ,� , ]

 This vector points more right than up when

� , −

� , >

37 of 44

Direction Changing Criterion (1/2)

(38)

Andries van Dam

 In our case, �

� , = and

� , =

so we check for

− >

− >

 This, too, can be computed incrementally

38 of 44

Direction Changing Criterion (2/2)

(39)

Andries van Dam

 Now in ENE octant, not ESE octant

 This problem is an artifact of aliasing, remember filter?

39 of 44

Problems with aligned ellipses

(40)

Andries van Dam 40 of 44

 Cosmetic: Texture applied after transformations

 Geometric: Pattern subject to transformations

(41)

Andries van Dam 41 of 44

Geometric vs. Cosmetic

+

Geometric

(Perspectivized/Filtered) Cosmetic (Real-World

Contact Paper)

(42)

Andries van Dam

Non-Integer Primitives

Initialization is harder

Endpoints are hard, too

making Line

,

and Line

,

join properly is a good

test

Symmetry is lost

General Conics

Very

hard

the octant-changing test is tougher, the difference

computations are tougher, etc.

Do it only if you have to

42 of 44

Non-Integer Primitives and General Conics

(43)

Andries van Dam

What's the difference between these two solutions? Under

which circumstances is the right one "better"?

43 of 44

Generic Polygons

Balsa Demo

(44)

Andries van Dam

 Rapid Prototyping is becoming cheaper and more prevalent  3D printers lay down layer after layer to produce solid objects

 We have an RP lab across the street in Barus and Holley

 http://www.youtube.com/watch?v=ZboxMsSz5Aw

 http://www.youtube.com/watch?v=Ah1067HXNdM&NR=1

44 of 44

Scan Converting Arbitrary Solids

Referensi

Dokumen terkait

Gedung H, Kampus Sekaran-Gunungpati, Semarang 50229 Telepon: (024)

Maka berdasarkan hasil QFD di atas maka produk baru akan berfokus pada desain meja yang memiliki sandaran yang bisa diatur kemiringannya untuk mengakomodasi konsumen yang

1) The investment management website is created successfully in order to apply the concept of crowdfunding for SMEs in distributing form of submission funds. The website is

Dalam penepatan barang yang dilakukan Toko A, toko A meletakan barang yang ada di tokonya tidak rapi dan ditumpuk-tumpuk ini membuat para konsumen tidak dapat melihat barang

Penerapan konsep crowdsourcing pada portal web site berfungsi untuk memberikan kemudahan pada pihak penyelenggara untuk mempublikasikan event yang diselenggarakan

Membuat rancangan service catalogue management yang menghasilkan sebuah dokumen yang menyediakan sumber informasi tentang IT service delivery bagi bisnis dari

Kerja sama yang baik antara Ayah dan Bunda dengan pihak sekolah akan mengantarkan kesuksesan anak kita dalam meraih cita-citanya.. Untuk anak usia SMA/SMK, pendampingan

untuk mengetahui apakah ada pengaruh model cycle learning menggunakan media power point terhadap hasil belajar materi garis dan sudut kelas VII MTsN Karangrejo.