Presentation is loading. Please wait.

Presentation is loading. Please wait.

In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.

Similar presentations


Presentation on theme: "In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon."— Presentation transcript:

1 In the name of God Computer Graphics

2 Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon

3 A scene from the wolfman video. The animated figure of this primitive lycanthrope is modeled with 61 bones and eight layers of fur. Each frame of the computer animation contains 100,000 surface polygons. (Courtesy of the NVIDIA Corporation.)

4 Preface On raster systems, lines are plotted with pixels, and step sizes in the horizontal and vertical directions are constrained by pixel separations. That is, we must “sample” a line at discrete positions and determine the nearest pixel to the line at each sampled position. The DDA algorithm is a faster method for calculating pixel positions than one that directly implements line equation. And in the next section, we consider a more general scan-line approach that can be applied to both lines and curves (Bresenham).

5 Sampling

6 Why Sampling? Once image is defined in terms of colors at (x, y) locations on grid, can change image easily by altering location or color values E.g., if we reverse our mapping above and make 10 = white and 0 = black, the image would look like this:

7 Why Sampling? Pixel information from one image can be copied and pasted into another, replacing or combining with previously stored pixels

8 Disadvantage? WYSIAYG (What You See Is All You Get): No additional information – no depth information – can’t examine scene from a different point of view – at most can play with the individual pixels or groups of pixels to change colors, enhance contrast, find edges, etc. But recently, strong interest in image-based rendering to fake 3D scenes and arbitrary camera positions. New images constructed by interpolation, composition, warping and other operations. Capture of Hair Geometry from Multiple Images, Siggraph 2004

9 Digital Images Computers work with discrete pieces of information How do we digitize a continuous image? –Break the continuous space into small areas, pixels –Use a single value for each pixel - the pixel value (no color, yet) –No longer continuous in space or intensity we shall see Continuous Discrete Pixels: Picture Elements

10 Point To specify the geometry of a point, we simply give a coordinate position in the world reference frame. Then this coordinate position, along with other geometric descriptions we may have in our scene, is passed to the viewing routines. Unless we specify other attribute values, OpenGL primitives are displayed with a default size and color. The default color for primitives is white and the default point size is equal to the size of one screen pixel.

11 Line Drawing Algorithm Graphics packages typically provide a function for specifying one or more straight-line segments, where each line segment is defined by two endpoint coordinate positions.

12 Line Drawing Algorithm A straight-line segment in a scene is defined by the coordinate positions for the endpoints of the segment. Example, A computed line position of (10.48, 20.51), for example, is converted to pixel position (10, 21). This rounding of coordinate values to integers causes all but horizontal and vertical lines to be displayed with a stair-step appearance (“the jaggies”) Improvement high-resolution systems. adjusting pixel intensities along the line path.

13 Display the line on a Raster Monitor This process digitizes the line into a set of discrete integer positions that, in general, only approximates the actual line path. graphics system project the endpoints to integer screen coordinates and determine the nearest pixel positions along the line path between the two endpoints. Reading from the frame buffer, the video controller plots the screen pixels. This process digitizes the line into a set of discrete integer positions. The line color is loaded into the frame buffer at the corresponding pixel coordinates.

14 Graphic Hardware Display Vector (random-scan) – still used in some plotters Raster (TV, bitmap), used in displays and laser printers Outline primitives Filed primitives

15 2D Raster Architecture Raster display stores bitmap in refresh buffer, also known as bitmap, frame buffer; can be in separate hardware (VRAM) or in CPU’s main memory (DRAM) Video controller draws all scan-lines at consistent > 60 Hz; separates update rate of the frame buffer and refresh rate of the CRT

16 2D Hardware/Algorithm Outline Display Hardware: Raster scan vs. random scan Drawing primitives by scan conversion – lines, polygons, circles and ellipses, characters, attributes (color, line style, fill pattern…) Clipping to clip rectangle: three methods – analytically compute intersections and draw clipped primitives – test each pixel and write only if inside – compute spans inside the primitive and fill entire span Color Table – indirect specification of (pseudo) color – color correction, simple types of animation Bit/RasterOp for operating on blocks of pixels

17 Line Equations(1) Determine pixel positions along a straight-line path from the geometric properties of the line. The Cartesian slope-intercept equation for a straight line is Y intercept X,Y interval slope

18 Line Equation(2) Voltage deflection in analog display system X,Y interval

19 Voltage deflection in analog display like vector-scan system For lines whose slopes have magnitudes | m | > 1, be set proportional to a small vertical deflection voltage with the corresponding horizontal deflection voltage set proportional to, calculated from Eq. 3-5. For lines with m = 1, = and the horizontal and vertical deflections voltages are equal. In each case, a smooth line with slope m is generated between the specified end points. X,Y interval

20 DDA Algorithm The digital differential analyzer (DDA) is a scan- conversion line algorithm based on calculating A line is sampled at unit intervals in one coordinate and the corresponding integer values nearest the line path are determined for the other coordinate. We consider first a line with positive slope.

21 DDA Algorithm(2) If the slope is less than or equal to 1 sample at unit x intervals ( ) and compute successive y values as Since m can be any real number between 0.0 and 1.0, each calculated y value must be rounded to the nearest integer corresponding to a screen pixel position in the x column we are processing. Subscript k takes integer values starting from 0, for the first point, and increases by 1 until the final endpoint is reached. For lines with a positive slope greater than 1.0,we reverse the roles of x and y.

22 Bresenham Algorithm? negative slope line segment is to be plotted, we need to determine at the next sample position whether to plot the pixel at position at pixel position (50, 50). next pixel position as (51, 50) or as (51, 49)?

23 Bresenham Algorithm Scan conversion for lines with 0<m<1. (xk, yk) is to be displayed. Now choose the pixel to plot in column xk+1= 1+ xk from (xk+1,yk+1) & (xk+1,yk)

24 Bresenham Algorithm(1) Accurate & efficient raster line-generating algorithm uses integer calculations-adapted to other curves scan line positions (Y axis) pixel columns (X axis) Sampling at unit x intervals, choose the closer of the 2 possible pixel positions to the line path at each sample step depending on sign of slope

25 Bresenham Algorithm(2) we first consider the scan-conversion process for lines with positive slope less than 1.0. Pixel positions along a line path are then determined by sampling at unit x intervals. Starting from the left endpoint ( x 0, y 0 ) of a given line, we step to each successive column ( x position) and plot the pixel whose scan-line y value is closest to the line path.

26 Bresenham Algorithm(2) Assuming the pixel at ( x k, y k ) is to be displayed, we need to decide which pixel to plot in column Our choices are the pixels at positions ( x k + 1, y k ) and ( x k + 1, y k + 1). At sampling position x k + 1, label vertical pixel separations from the mathematical line path as d lower and d upper. The y coordinate on the mathematical line at pixel column position x k + 1 is calculated as: y = m ( x k + 1 ) + b Then d lower = y - y k = m ( x k + 1 ) + b - y k d upper = ( y k + 1 ) - y = y k + 1 - m ( x k + 1 ) - b

27 Bresenham Algorithm(3) which of the two pixels is closest to the line path, efficient test that is difference between the two pixel separations: d lower - d upper = 2 m ( x k + 1 ) - 2 y k + 2 b - 1 A decision parameter p k for the k th step in the line algorithm can be obtained by rearranging so that it involves only integer calculations.

28 Bresenham Algorithm(4) the vertical and horizontal separations of the endpoint positions, and defining the decision parameter as p k = ( d lower - d upper ) The sign of p k is the same as the sign of d lower - d upper, since > 0for our example. Parameter c is constant and has the value,which is independent of the pixel position and will be eliminated in the recursive calculations for p k.

29 Bresenham Algorithm(5) If the pixel at y k is “closer” to the line path than the pixel at y k + 1 (that is, d lower < d upper ), then decision parameter p k is negative. In that case, we plot the lower pixel; otherwise we plot the upper pixel. Coordinate changes along the line occur in unit steps in either the x or y directions. Therefore, we can obtain the values of successive decision parameters using incremental integer calculations. At step k + 1, the decision parameter is evaluated from Eq. 3-14 as

30 Bresenham Algorithm(6) Subtracting Eq. 3-14 from the preceding equation, we have But, so that where the term y k + 1 - y k is either 0 or 1, depending on the sign of parameter p k. The first parameter, p 0, is evaluated from Eq. 3-14 at the starting pixel position ( x 0, y 0 ) and with m evaluated as

31 Bresenham Algorithm Bresenham’s Line-Drawing Algorithm for | m | < 1. 0

32 Example(1) To illustrate the algorithm, we digitize the line with endpoints (20, 10) and (30, 18). This line has a slope of 0.8, with We plot the initial point ( x 0, y 0 ) = (20, 10), and determine successive pixel positions along the line path from the decision parameter as:

33 Example(2)


Download ppt "In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon."

Similar presentations


Ads by Google