Chapter 8: Implementation- Clipping and Rasterization

Similar documents
OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Realtime 3D Computer Graphics Virtual Reality

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Clipping and Scan Conversion

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Clipping. Concepts, Algorithms for line clipping. 1 of 16. Andries van Dam. Clipping - 10/12/17

Rasterization, or What is glbegin(gl_lines) really doing?

Scan Conversion. Drawing Lines Drawing Circles

From Ver(ces to Fragments: Rasteriza(on

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

CS 543: Computer Graphics. Rasterization

Topic #1: Rasterization (Scan Conversion)

Topics. From vertices to fragments

Clipping Lines. Dr. Scott Schaefer

Rasterization: Geometric Primitives

3D Rendering Pipeline (for direct illumination)

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Line Drawing. Foundations of Computer Graphics Torsten Möller

Einführung in Visual Computing

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

From Vertices To Fragments-1

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

CS488 2D Graphics. Luc RENAMBOT

Graphics System. Processor. Output Display. Input Devices. Frame Buffer. Memory. Array of pixels. Resolution: # of pixels Depth: # of bits/pixel

Two-Dimensional Viewing. Chapter 6

CS452/552; EE465/505. Clipping & Scan Conversion

Computer Graphics. The Two-Dimensional Viewing. Somsak Walairacht, Computer Engineering, KMITL

Graphics (Output) Primitives. Chapters 3 & 4

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Computer Graphics 7 - Rasterisation

Computer Graphics (CS 543) Lecture 9 (Part 2): Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

1 Introduction to Graphics

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Last class. A vertex (w x, w y, w z, w) - clipping is in the - windowing and viewport normalized view volume if: - scan conversion/ rasterization

Rendering. A simple X program to illustrate rendering

Computer Graphics. - Rasterization - Philipp Slusallek

CSCI 4620/8626. Computer Graphics Clipping Algorithms (Chapter 8-5 )

Computer Graphics and GPGPU Programming

CPSC / Scan Conversion

Display Technologies: CRTs Raster Displays

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

Chapter 3. Sukhwinder Singh

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi

UNIT -8 IMPLEMENTATION

Rasteriza2on and Clipping

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

The Traditional Graphics Pipeline

Clipping Points Consider a clip window which is rectangular in shape. P(x, y) is a point to be displayed.

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

COMP371 COMPUTER GRAPHICS

Department of Computer Sciences Graphics Fall 2003 (Lecture 2) Pixels

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k

The Traditional Graphics Pipeline

Chapter - 2: Geometry and Line Generations

Scan Converting Lines

Unit 2 Output Primitives and their Attributes

RASTERIZING POLYGONS IN IMAGE SPACE

From 3D World to 2D Screen. Hendrik Speleers

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

The Traditional Graphics Pipeline

Points and lines. x x 1 + y 1. y = mx + b

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

CS 130. Scan Conversion. Raster Graphics

Rendering. Basic Math Review. Rasterizing Lines and Polygons Hidden Surface Remove Multi-pass Rendering with Accumulation Buffers.

Sung-Eui Yoon ( 윤성의 )

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

Overview of Computer Graphics

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Rasterization. COMP 575/770 Spring 2013

Raster Displays and Scan Conversion. Computer Graphics, CSCD18 Fall 2008 Instructor: Leonid Sigal

2D Viewing. Viewing Pipeline: Window-Viewport Transf.

(Refer Slide Time: 00:03:51)

Part IV. 2D Clipping

Examples. Clipping. The Rendering Pipeline. View Frustum. Normalization. How it is done. Types of operations. Removing what is not seen on the screen

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

Output Primitives Lecture: 4. Lecture 4

Lab Manual. Computer Graphics. T.E. Computer. (Sem VI)

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

Line Drawing Week 6, Lecture 9

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

Polygon Filling. Can write frame buffer one word at time rather than one bit. 2/3/2000 CS 4/57101 Lecture 6 1

UNIT 2 GRAPHIC PRIMITIVES

Unit 3 Transformations and Clipping

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

CSCI 4620/8626. Coordinate Reference Frames

Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

Painter s HSR Algorithm

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

Raster Scan Displays. Framebuffer (Black and White)

Z- Buffer Store the depth for each pixel on the screen and compare stored value with depth of new pixel being drawn.

Computer Graphics D Graphics Algorithms

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

CS602 MCQ,s for midterm paper with reference solved by Shahid

Efficient Plotting Algorithm

CS Rasterization. Junqiao Zhao 赵君峤

Transcription:

Chapter 8: Implementation- Clipping and Rasterization Clipping Fundamentals Cohen-Sutherland Parametric Polygons Circles and Curves Text Basic Concepts: The purpose of clipping is to remove objects or parts of objects that lie outside the view volume. Opertaionally the acceleration in the conversion to pixels (scan conversion) is sufficient to make the process worthwhile. find parts of primitives within clip region often rectangular basic case X min x x max, y min y y max clipping usually applied to: points lines polygons curves text Clipping versus Scissoring: Clipping is carried out on the transformed coordinates in the canonical view volume (CVV). Scissoring is carried out on the pixel in memory, and is usually used to mask of parts of an image. Clipping: Operates with primitives Discards, creates or modifies Computationally expensive Usually accelerates rasterization Scissoring: operates with pixels brute force is used for arbitrary regions (masks)

Figure 1 shows the pipeline process of Clipping and Scissoring Cohen-Sutherland Clipping Algorithm Fig 1: Pipeline Process The Cohen-Sutherland algorithm uses the limits of the view volume to divide the world up into regions and assigning codes called outcodes to the regions. Line segments can be classified by the outcodes of their end points. Assign outcodes to line midpoints Test outcodes => accept, reject, split repeat until all line segments accepted or rejected The algorithm works by testing the outcodes at each end of a line segment, together with the logical and of the outcodes. From this 4 condition can be found: The line is within the view volume: render the line One end of the line is in the view volume: clip the line and render it. The line may enter the view volume: clip to the clipping planes and retest The line may not be enter the view volume: delete it. Table 1 shows the various conditions for testing.

Table 1: Condition test for total accept and Total Reject cases An Example: 1. oa = 1001; ob = 0010 2. (oa AND ob) = 0 so split using first non-zero bit giving AC & CB, throw away external segment AC 3. oc = 0000; ob = 0010 4. oc = 0; ob 0 so split using the first non-zero bit giving CD & DB, throw away the external segment DB 5. oc = 0000; od = 0000 so trivially accept Pros: The Cohen-Sutherland algorithm is best when: - the clipping region is large compared to the world so there are lots of trivial accepts - the clipping region is small compared to the world so there are lots of trivial rejects Find the intersection using slope-intercept form: where x or y is set to edge coordinate Y= y1 + m(x-x1), x= x1 + (y-y1)/m Cons

The calculations involve floating point divisions both to find x and the value of m Looking at the example we can see that redundant clipping may occur Parametric Clipping Algorithms This algorithm works by deriving the line equation in parametric form. Then the properties of the intersections with the sides of the view volume are qualitatively analyzed. Only if absolutely necessary are the intersections carried out. For a line defined by 2 points (x1, y1) and (x2, y2) the parametric form is: x=x1 + ux, y=y1 + uy Where x = x2 x1, y = y2 y1 Clearly u = 0 at (x1, y1) and u = 1 at (x2, y2). Also if y = 0 or x = 0, the line is parallel to an axis and can be handled by comparisons of the x or y values. If both increments are non zero the line will cut all 4 boundaries of the view volume. Consider the intersection of the line with the lower boundary view volume x= x min. The intersection can be found by solving x min = x1 + u1x for u1, but this involves a floating point division, which we wish to avoid. The trick is to find qualitative information on the value of u1without having to find the actual value. To do this write the equation as u1x = x min x1 If x and x min x1 have opposite signs then u1 < 0 : so the intersection is not on the segment, and if x > x min x1 then u1 > 1: so the intersection if not on the segment. The same process can be applied to the intersections with y min, x max, y max, and respectively u2, u3, u4. We can also rank the u values by without division (u1 < u4) (x min x1)/x (y max y1)/y <((x min x1)y <(y max y1)x)

We have the 4 intersections parameter values in order and know if each is less than 0 greater than 1 or in the line segment. Consider the case where the order is u2 < u1 < u3 < u4 with u2 < 0 and u4 > 1 The only form of line that satisfies these conditions is of the form: All the possible permutations of u1 to u4 can be similarly classified. As a result clipping can be applied only when need. The main parametric clipping algorithm is the Ling-Barsky algorithm that uses a slightly modified version of this approach. The Ling-Barsky algorithm is extendable to 3D. Clipping in 3D In 3D we have to clip lines against plains. The Cohen-Sutherland algorithm can be applied in a modified form. The Ling-Barsky algorithm can be applied but not other parametric clipping algorithm.

Fig 2: Clipping in 3D Clipping polygon not equal to line clipping polygon edges (new points must be added to close up polygons). The Sutherland-Hodgman algorithm clips all the lines forming the polygon against each edge of the view volume in turn. The fig 3 shows the various cases considered for polygon clipping. Fig 3: Cases of Polygon Clipping, and Clipping Concave Polygon

Conceptually: Maintain input and out vertex lists Traverse input list, storing vertices into output list Clip against each edge in turn, using output from previous clip as input Fig 4 shows pipeline of clippers Fig 4: Pipeline of Clipper Optimize by passing each vertex to next clipper immediately (i.e. pipelining) Circles and Curves: Non-linear equations are used for intersection tests. Bounding information is utilized, for example: Check bounding box for trivial accept/reject If necessary, repeat for quadrants. If necessary, repeat for octants Either: test intersection analytically Or: scissor on a pixel-by-pixel basis

Clipping Text Text is represented: As a collection of lines and curves (outline) GLUT_STROKE clipped as a polygon As a bitmap GLUT_BITMAP scissored in color buffer Since characters usually come in a string, we can accelerate clipping by using individual character bounds to identify where to clip the string. Fig 5 shows character clipping. Contents: DDA algorithm Bresenham s algorithm Additional issues Filled polygons Edge tables Fig 5: Character Clipping Scan Conversion (Rasterization) What we are given We have a line defined on the plane of real numbers (x, y). We have a discrete model of the (x, y) plane consisting of a regular array of rectangles called pixels, which can be colored. What we want to do Map the line onto the pixel array, while satisfying or optimizing the following constraints. - Maintain constant brightness - Differing pen styles or thicknesses may be required - Shape of endpoints if line thicker than one pixel - Minimize jaggies

The Pixel Space: The pixel space is a rectangle on the x y plane, bounded by 0 xxmax and 0 yymax. Each axis is divided into an integer number of pixels, Nx and Ny. The pixels there for have width and height x H = ymax Ny W = xmax Nx Pixels are referred to using integer coordinates, that either refer to the location of their lower left hand corners or their centres. Knowing the W and H values allows the pixel to be defined. Assume that W and H are equal so pixels are square. Fig 6 shows the pixel representation. Digital Differential Analyzer Algorithm Fig 6: Coordinate System This algorithm assumes that the gradient satisfies 0 m 1 other cases handled by symmetry. If a line segment is to be drawn from (x1, y1) to (x2, y2) the gradient can be found form m y/ x We now need a function round(x) that converts floats to integers and we can draw the line as follows: Remember there is no scaling involved in moving from projection to viewport coordinates.

Bresenham s Algorithm: The DDA algorithm needed to carry out a floating point addition and a rounding operation for every iteration. Bresenham s algorithm operates only on integers requiring only that the start and end points of a line segment are rounded. Assume 0 m 1 and pixel (i, j) is the current pixel.the value of y on the line x=i+1 must lie between j and j+1. Because the gradient is in the range 0-45 o the next pixel must be either E, (i+1, j) or NE, (i+1, j+1). Assume pixels identified by their centers. We now have a decision problem, and so must find a decision variable that can be tested to determine which pixel to color. First rewrite the equation of a straight line: y=mx+c mx y + c = o (y/x) x y+c = o F(x, y)=xy yx+cx=xy yx+ B = 0

The useful properties of this function are: If F(x, y)<0, then the point is above the line If F(x, y)>0, then the point is below the line Function F(x, y) clearly has the properties required of a decision variable: dn = F(xn, yn) Consider an arbitrary pixel (xp, yp) that is on a line segment. We need to test a point to determine which of the possible next 2 pixels to colour. A suitable point is (xp+1, yp+1/2) this will be on the vertical boundary between pixels E and NE and at the horizontal midpoint. If F(xp + 1, yp +1, the next pixel is E, else the next pixel is NE. Examining the next step we see it is not independent of the decision we have just made. if E was chosen then the next test will be F(xp + 2, yp +1 else if NE was chosen the next test will be F(xp + 2, yp +3 Now let dn = F(xp + 1, yp +1 definition of F and we have: If E was chosen then the next test will be dn + 1 = dn + y Else f NE was chosen the next test will be dn + 1 = dn +(y x) All we need now is a formula for d1 and we can form the line. To find d1: d1=f(x0 + 1, y0 +1y(x0 + 1) x(y0 +1B d1 = (x0y y0x + B)+ y x d1 = F(x0, y0)+ y x d1 = d0 + y x But d0 is the start point and we know that it is on the line so d0 = 0 hence d1 = y x. This still has a factor of 1/2 in it and we wanted only integers. Simple multiply everything by 2.

void bresenham(int x0, int y0, int x1, inty1){ int dx = x1 - x0; int dy = y1 - y0; int d = (2*dy) - dx; int incr_e = 2*dy; int incr_ne = 2*(dy - dx); int x = x0, y = y0; color_pixel(x0, y0); while(x<x1){ if(d<=0){ d += incr_e; x++; }else{ d += incr_ne; x++; Y++; } color_pixel(x, y); } } Additional Issues: Line intensity: Intensity is function of slope Lines with different slopes have different number of pixels per unit length To draw two such lines with the same intensity must make pixel intensity a function of the gradient (or simply use antialiasing) Clip rectangles: If line segment has been clipped... At the clipping boundary opposite: - Integer x value - Real y value The pixel at the edge produced by the clipping algorithm P is the same one that would be drawn without clipping Subsequent pixels may not be as the clipped line has different slope Solution: - Draw edge pixel - Initialize F(M) for next column over - Use original (not clipped) gradient

Filled Polygons Fig. 7: An Example

Span Filling The different cases to be considered during Polygon filling are: 1. Given an intersection at some (fractional) x value, how do we determine which side is interior? Round down when inside, round up when outside. 2. What about intersections at integer values? Leftmost pixels of span inside, rightmost outside. 3. What about shared vertices? Only count the y min vertex of an edge. 4. What about horizontal edges? Don t count these vertices at all (top edges drawn only) Edge Table: Fig 8: scan lines at value of y This is the same scan line algorithm used in for visible surface determination. There is a global list of edges maintained each with whatever interpolation information is required. At any point on a scan within a polygon we interpolate the color intensity from the 2 current edges. The figure 9 below shows the active edge table for scan line y=3.

Filled-Polygon Algorithm Basic Algorithm sort edges in ET on minimum y min y = first y value with non-empty bucket AET = empty Fig 9: Shows the Edge Table for Scan Line at Y=3 REPEAT add edges from ET(y) to AET sort AET on minimum x init fill segment defined by consecutive (x,y) pairs remove edge e when e.y max = y y++ for each e in AET, x init = x init + 1/m UNTIL AET and ET are empty As with the scanline algorithm floating point operations can be avoided use a decision variable modify edge table entries to include the decision variable and its increments