Presentation is loading. Please wait.

Presentation is loading. Please wait.

Output Primitives Jehee Lee Seoul National University.

Similar presentations


Presentation on theme: "Output Primitives Jehee Lee Seoul National University."— Presentation transcript:

1 Output Primitives Jehee Lee Seoul National University

2 OpenGL Programming OpenGL ( gl ) is a common graphics library which provides functions for drawings and interactive input. OpenGL is accessible via C or C++ programs http://www.opengl.org OpenGL basic (core) library –Functions, symbols, and types glBegin, glClear, glCopyPixels, glPolygonMode GL_2D, GL_RGB, GL_POLYGON Glbyte, Glshort, Glint, Glfloat, Gldouble

3 Related Libraries OpenGL Utility (GLU) –Setting up viewing and projection matrices –Complex objects Line and polygon approximations Displaying quadrics, B-splines –Prefix glu OpenGL Utility Toolkit (GLUT) –Support any screen-windowing system

4 An Example of Open GL Initialize OpenGL and GLUT Initialize a drawing window Draw a line segment

5

6 Output and Input Pipeline Scan conversion –converts primitives such as lines, circles, etc. into pixel values –geometric description  a finite scene area Clipping –the process of determining the portion of a primitive lying within a region called clip region

7 Output Pipeline Output pipeline (rendering process) –Application model : descriptions of objects –Application program : generates a sequence of functions to display a model –Graphics package : clipping, scan conversion, shading –Display H/W

8 Output Pipeline

9 Input Pipeline Input pipeline –user interaction (e.g., mouse click) –graphic package (by sampling or event-driven input functions) –application program –modify the model or the image on the screen

10 Hardware vs Software Pipelines Displays with frame buffers only –scan conversion by a graphic package Displays with frame buffers and display controllers –common in plug-in graphics card –scan conversion by a graphic package and display processor

11 Scan conversion and Clipping Clipping before scan conversion –Eg) Lines, rectangles, and polygons (scissoring) Clipping after scan converting the entire collection of primitives into a temporary canvas –Eg) Text window Text can be clipped

12 Scan Converting Lines A line from (x1,y1) to (x2,y2)  a series of pixels [Criteria] –uniform, user-selected density –straight lines should appear straight –line end-points should be constrained –line drawing algorithms should be fast

13 f f : L 1 => L 2  quality degradation!! Line drawing is at the heart of many graphics programs.  Smooth, even, and continuous as much as possible !!! Simple and fast !!! Scan Converting Lines ( x 1, y 1 ) ( x 2, y 2 )

14 Continuity 8-connectivity (king – continuity) 4-connectivity (rook – continuity)

15 Why Study Scan Conversion Algorithms?  Every high-end graphics card support this.  You will never have to write these routines yourself, unless you become a graphics hardware designer.  So why do we learn this stuff?  Maybe you will become a graphics hardware designer  But seriously, the same basic tricks underlie lots of algorithms:  3-D shaded polygons, texture mapping

16 Scan Converting Lines Digital Differential Analyzer(DDA) –Basic incremental algorithm –Each point is generated from the previous point in a simple fashion –Slope of a line m = Δy/Δx xx yy

17 Digital Differential Analyzer(DDA) Idea 1.Go to starting point 2.Increment x and y values by constants proportional to x and y such that one of them is 1. 3.Round to the closest raster position Drawbacks –rounding to an integer takes time –floating-point operations

18 Digital Differential Analyzer(DDA)

19 Bresenham’s Line Drawing Algorithm  additions / subtractions only  integer arithmetic  not programmers’ point of view but system developers’ point of view

20 Midpoint Line Algorithm (Bresenham's Line Algorithm) Assume a line from (x 0,y 0 ) to (x 1,y 1 ) that 0<slope<1 and x 0 <x 1 Suppose that we have just finished drawing a pixel P = (x p, y p ) and we are interested in figuring out which pixel to draw next.

21 Midpoint Line Algorithm (Bresenham's Line Algorithm) If distance(NE,Q) > distance(E,Q) then select E = (x p +1, y p ) else select NE = (x p +1, y p +1) NE E M P Q

22 Midpoint Line Algorithm (Bresenham's Line Algorithm) A line eq. in the implicit form F(x, y) = ax + by + c = 0 Using y = (Δy/Δx)x + B, where a = Δy, b = -Δx, c = B·Δx. F(x,y) = Δy·x - Δx·y + B·Δx = 0 Let's use an equivalent representation F(x,y) = 2ax + 2by + 2c = 0.

23 Midpoint Line Algorithm (Bresenham's Line Algorithm) Making slope assumptions, observe that b < 0, and this implies: –F(x,y) < 0 for points above the line –F(x,y) > 0 for points below the line To apply the midpoint criterion, we need only to compute F(M) = F(x p +1, y p +½) and to test its sign.

24 Midpoint Line Algorithm (Bresenham's Line Algorithm) To determine which one to pick up, we define a decision variable D = F(x p +1, y p +½) D = 2a(x p +1) + 2b(y p +½) + 2c = 2ax p + 2by p + (2a + b + c) If D > 0 then M is below the line, so select NE, otherwise select E. NE E M P Q

25 Midpoint Line Algorithm (Bresenham's Line Algorithm) How to compute D incrementally? –Suppose we know the current D value, and we want to determine the next D. –If we decide on going to E next, D new = F(x p + 2, y p + ½) = 2a(x p + 2) + 2b(y p + ½) + c = D + 2a = D + 2Δy –If we decide on going to NE next, D new = F(x p + 2, y p + 1 + ½) = 2a(x p + 2) + 2b(y p + 1 + ½) + c = D + 2(a + b) = D + 2(Δy - Δx).

26 Midpoint Line Algorithm (Bresenham's Line Algorithm) Since we start at (x 0,y 0 ), the initial value of D can be calculated by D init = F(x 0 + 1, y 0 + ½) = (2ax 0 + 2by 0 + c) + (2a + b) = 0 + 2a + b = 2Δy - Δx Advantages –need to add integers and multiply by 2 (which can be done by shift operations) –incremental algorithm

27 Line end points: (x 0,y 0 ) = (5,8); (x 1,y 1 ) = (9,11) Δx = 4; Δy = 3 D init = 2Δy – Δx = 2 > 0   select NE D new = D + 2(Δy - Δx) = 0  Select E D new = D + 2Δy = 0 + 6 = 6  Select NE Midpoint Line Algorithm- Example 4 5 6 7 8 9 10 11 13 12 11 10 9 8 7 6

28 Scan Converting Lines (issues) Endpoint order –S 01 is a set of pixels that lie on the line from P 0 to P 1 –S 10 is a set of pixels that lie on the line from P 1 to P 0  S 01 should be the same as S 10 Varying intensity of a line as a function of slope –For the diagonal line, it is longer than the horizontal line but has the same number of pixels as the latter  needs antialiasing Outline primitives composed of lines –Care must be taken to draw shared vertices of polylines only once

29 Scan Converting Lines (issues) Starting at the edge of a clip rectangle –Starting point is not the intersection point of the line with clipping edge  Clipped line may have a different slope

30 Aliasing Effects staircases (or jaggies) intensity variation  line drawing

31 animation texturing popping-up Aliasing Effects

32 Anti-aliasing Lines Removing the staircase appearance of a line –Why staircases? raster effect !!!  need some compensation in line-drawing algorithms for this raster effect? How to anti-alias? well, … increasing resolution. However,...

33 Increasing resolution memory cost memory bandwidth scan conversion time display device cost

34  super sampling (postfiltering)  area sampling (prefiltering)  stochastic sampling Cook, ACM Trans. CG, 5(1), 307-316, 1986. Anti-aliasing Line (Cont’) Anti-aliasing Techniques

35 Area Sampling (Prefiltering)

36 box filtercone filter Filters unweighted area sampling weighted area sampling

37 Table look-up for f ( D, t ) The table is invariant of the slope of line! Why? The search key for the table is D! Why? D

38 Intensity Functions f(D, t) (assumption : t=1)

39 Scan Converting Circles Equation of Circle?

40 Scan Converting Circles Eight-way symmetry We only consider 45° of a circle

41 Midpoint Circle Algorithm Suppose that we have just finished drawing a pixel (x p, y p ) and we are interested in figuring out which pixel to draw next.

42 Midpoint Circle Algorithm F(x,y) = x 2 + y 2 - R 2 = 0 on the circle > 0 outside the circle < 0 inside the circle If F(midpoint between E and SE) > 0 then select SE = (x p +1,y p -1) else select E = (x p +1, y p );

43 Midpoint Circle Algorithm Decision variable d old = F(x p +1, y p -½) = (x p +1) 2 + (y p -½) 2 - R 2 –If d old < 0, select E. d new = F(x p +2, y p -½) = d old + (2x p + 3) –If d old  0, select SE. d new = F(x p +2, y p -½-1) = d old + (2x p - 2y p + 5) We have to calculate new d based on the point of evaluation P=(x p, y p ), but this is not expensive computationally.

44 Midpoint Circle Algorithm Since we start at (0,R), the initial value of d can be calculated by d init = F(1, R - ½) = 5/4 – R By substituting d - 1/4 by h, we can get the integer midpoint circle scan-conversion algorithm.

45 Scan Converting Ellipses F(x,y) = b 2 x 2 + a 2 y 2 -a 2 b 2 Divide the quadrant into two regions; the boundary of two regions is the point at which the curve has a slope of -1. And then apply any midpoint algorithm.

46 4. Curve Drawing   parametric equation  discrete data set − curve fitting − piecewise linear

47 Homework 공통 숙제 : –Bresenham's Line Algorithm 완성  모든 경우에 동작 할 수 있도록 Test Image 만들기 :

48 Homework Graphics Group 학생들 숙제 – 원과 타원을 그리는 완성된 코드 –2 가지 버전 : 삼각 함수 및 라인그리기를 이용한 버전 Midpoint 알고리즘을 이용한 버젼 – 다양한 크기의 원과 다양한 파라메터의 타원을 그려서 제출


Download ppt "Output Primitives Jehee Lee Seoul National University."

Similar presentations


Ads by Google