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

Similar documents
Clipping and Scan Conversion

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

Chapter 8: Implementation- Clipping and Rasterization

Einführung in Visual Computing

3D Rendering Pipeline (for direct illumination)

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

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

Realtime 3D Computer Graphics Virtual Reality

From Ver(ces to Fragments: Rasteriza(on

Topic #1: Rasterization (Scan Conversion)

Two-Dimensional Viewing. Chapter 6

Cs602-computer graphics MCQS MIDTERM EXAMINATION SOLVED BY ~ LIBRIANSMINE ~

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

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

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

SE Mock Online Test 1-CG

Pipeline implementation II

Implementation III. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Rasterization: Geometric Primitives

The Traditional Graphics Pipeline

Topics. From vertices to fragments

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

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

The Traditional Graphics Pipeline

Computer Graphics. - Rasterization - Philipp Slusallek

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

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

The Traditional Graphics Pipeline

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

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

Scan Conversion. Drawing Lines Drawing Circles

COMP371 COMPUTER GRAPHICS

OXFORD ENGINEERING COLLEGE (NAAC Accredited with B Grade) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS

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

Chapter - 2: Geometry and Line Generations

Unit 2 Output Primitives and their Attributes

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

Write C++/Java program to draw line using DDA and Bresenham s algorithm. Inherit pixel class and Use function overloading.

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

CSCI 420 Computer Graphics Lecture 14. Rasterization. Scan Conversion Antialiasing [Angel Ch. 6] Jernej Barbic University of Southern California

Graphics (Output) Primitives. Chapters 3 & 4

Binghamton University. EngiNet. Thomas J. Watson. School of Engineering and Applied Science. Computer Graphics. State University of New York.

Computer Graphics Geometry and Transform

UNIT -8 IMPLEMENTATION

Computer Graphics 7 - Rasterisation

CS Rasterization. Junqiao Zhao 赵君峤

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

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

1 Introduction to Graphics

Computer Graphics D Graphics Algorithms

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

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Viewing Transformation. Clipping. 2-D Viewing Transformation

Rendering approaches. 1.image-oriented. 2.object-oriented. foreach pixel... 3D rendering pipeline. foreach object...

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

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

From 3D World to 2D Screen. Hendrik Speleers

EF432. Introduction to spagetti and meatballs

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

Rendering. A simple X program to illustrate rendering

CS602- Computer Graphics Solved MCQS From Midterm Papers. MIDTERM EXAMINATION Spring 2013 CS602- Computer Graphics

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

Computer Graphics and GPGPU Programming

Graphics Output Primitives

Computer Graphics D Graphics Algorithms

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

Rendering. A simple X program to illustrate rendering

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

CS475m - Computer Graphics. Lecture 1 : Rasterization Basics

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

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

Line Drawing. Foundations of Computer Graphics Torsten Möller

Computer Graphics Geometry and Transform

Clipping Lines. Dr. Scott Schaefer

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

Topic 0. Introduction: What Is Computer Graphics? CSC 418/2504: Computer Graphics EF432. Today s Topics. What is Computer Graphics?

CS488 2D Graphics. Luc RENAMBOT

Computer Graphics: 7-Polygon Rasterization, Clipping

Line Drawing Week 6, Lecture 9

CS 543: Computer Graphics. Rasterization

Introduction to Computer Graphics (CS602) Lecture 05 Line Drawing Techniques

RASTERIZING POLYGONS IN IMAGE SPACE

(a) rotating 45 0 about the origin and then translating in the direction of vector I by 4 units and (b) translating and then rotation.

Painter s HSR Algorithm

Rasteriza2on and Clipping

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

521493S Computer Graphics Exercise 1 (Chapters 1-3)

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

EF432. Introduction to spagetti and meatballs

CSCI 4620/8626. Coordinate Reference Frames

Chapter 3. Sukhwinder Singh

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

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

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

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

Transcription:

General scheme of a 2D CG application 2D Image Synthesis Balázs Csébfalvi modeling image synthesis Virtual world model world defined in a 2D plane Department of Control Engineering and Information Technology email: cseb@iit.bme.hu Web: http://www.iit.bme.hu/~cseb Metaphor: 2D drawing or sketching 2 /25 Raster graphics systems 2D image synthesis 3 /25 4 /25 Vectorization Modeling transformation v y v r(t) T M βv αu u r 2 rn βv p o r [0,]: 0, t, t 2,..., t n, r =r(0), r 2 = r(t 2 ),, r n = r() αu [x, y] = o +αu + βv u [x, y, ] = [α, β, ] u x u y 0 v x v y 0 o x o y x 5 /25 T M 6 /25

Viewport transformation Composite transformation [X, Y, ] = ([α, β, ] T M ) T V [X, Y, ] = [α, β, ] (T M T V ) = [α, β, ] T C calculation of the viewport transformation T V for each object o X = (x-w x ) v w /w w + v T x V Y = (y-w y ) v h /w h + v v y w /w w 0 0 0 v h /w h 0 [X, Y, ] = [x, y, ] v x -w x v w /w w v y -w y v h /w h 7 /25 determine T M T C = T M T V for each point of object o: transformation by T C endfor 8 /25 Clipping Due to the vectorization, clipping is performed on points, segments, and polygons Clipping points x > x min, x < x max, y > y min, y min x min y max x max y < y max 9 /25 Clipping a segment by a half plane x max x i, y i x, y x 2, y 2 x(t) = x + (x 2 - x )t, y(t) = y + (y 2 - y )t x = x max intersection point: x max = x + (x 2 - x )t t = (x max -x )/(x 2 -x ) x i = x max y i = y + (y 2 - y ) (x max -x )/(x 2 -x ) 0 /25 Cohen-Sutherland algorithm Cohen-Sutherland algorithm 00 000 00 000 0000 000 00 000 00 /25 #define Code(p) ((p.x < xmin) + ((p.y < ymin)<<) + \\ ((p.x > xmax)<<2) + ((p.y > ymax)<<3) bool LineClip(Vector& p, Vector& p2) { for( ; ; ) { int c = Code(p), c2 = Code(p2); if (c == 0 && c2 == 0) return true; if ((c & c2)) return false; if ((c & )) p = IntersectX(p, p2, xmin); else if ((c & 2)) p = IntersectY(p, p2, ymin); else if ((c & 4)) p = IntersectX(p, p2, xmax); else if ((c & 8)) p = IntersectY(p, p2, ymax); else if ((c2 & )) p2 = IntersectX(p, p2, xmin); else if ((c2 & 2)) p2 = IntersectY(p, p2, ymin); else if ((c2 & 4)) p2 = IntersectX(p, p2, xmax); else if ((c2 & 8)) p2 = IntersectY(p, p2, ymax); 2 /25 2

Polygon Clipping modification of line clipping goal: one or more closed areas Sutherland-Hodgman Polygon Clipping processing polygon boundary as a whole against each window edge output: list of vertices display of a polygon processed by a lineclipping algorithm display of a correctly clipped polygon 3 /25 original polygon clip left clip right clip bottom clipping a polygon against successive window boundaries clip top 4 /25 Sutherland-Hodgman Polygon Clipping four possible edge cases out fi in output: V, V 2 in fi in V 2 in fi out out fi out V no output successive processing of pairs of polygon vertices against the left window boundary 5 /25 Sutherland-Hodgman Polygon Clipping clipping a polygon against the left boundary of a window, starting with vertex. Primed numbers are used to label the points in the output vertex list for this window boundary finished! 6 /25 Sutherland-Hodgman Algorithm: Combination of the 4 Passes The polygon is clipped against each of the 4 borders separately, that would produce 3 intermediate results. By calling the 4 tests recursively, (or by using a clipping pipeline) every result point is immediately processed on, so that only one result list is produced 7 /25 Example pipeline of boundary clippers to avoid intermediate vertex lists 3 st clip: left Processing the vertices of the polygon through a boundary-clipping pipeline. After all vertices are processed through the pipeline, the vertex list for the clipped polygon is [, 2, 2, 2 ] 2 2 3 2 2 nd clip: bottom 8 /25 3

Sutherland-Hodgman Polygon Clipping Sutherland-Hodgeman polygon clipping extraneous lines for concave polygons: split into separate convex parts or final check of output vertex list clipping the concave polygon with the Sutherland- Hodgeman clipper produces two connected areas 9 /25 PolygonClip(p[n] q[m]) m = 0; for( i=0; i < n; i++) { if (p[i] internal) { q[m++] = p[i]; if (p[i+] is external) q[m++] = Intersect(p[i], p[i+], borderline); else { if (p[i+] is internal) q[m++] = Intersect(p[i], p[i+], borderline); 20 /25 Rasterization Line drawing model transformation clipping Geometrical primitives: 0.- microsec / primitive Line equation: y = mx + b Line drawing Pixels 0-50 nanosec / pixel rasterization pixel operations frame buffer x x2 for( x = x; x <= x2; x++) { Y = m*x + b; y = Round( Y ); write( x, y ); 2 /25 22 /25 Incremental approach Calculate Y(X) Y(X) = F( Y(X-) ) = Y(X-) + dy/dx Line drawing: Y(X) = mx + b Y(X) = F( Y(X-) ) = Y(X-) + m Addition: fix-point arithmetic: y = Y 2 T T: error < for the longest segment N 2 -T < : T > log 2 N round( y ): y+0.5 is truncated DDA line drawing DDADrawLine(x, y, x2, y2) { m = (y2 - y)/(x2 - x) y = y + 0.5 FOR X = x TO x2 { Y = round(y) trunc(y) WRITE(X, Y, color) y = y+m 23 /25 24 /25 4

DDA line-drawing hardware Bresenham s Line Algorithm X Y Faster than simple DDA incremental integer calculations adaptable to circles, other curves X counter y register y = m. (x k + ) + b CLK x y m Σ Section of a display screen where a straight line segment is to be plotted, starting from the pixel at column 0 on scan line 25 /25 26 /25 Bresenham s Line Algorithm Section of the screen grid showing a pixel in column x k on scan line y k that is to be plotted along the path of a line segment with slope 0<m< 27 /25 Bresenham s Line-Drawing Algorithm (/4) y = m. (x k + ) + b d lower = y y k = = m. (x k + ) + b y k d upper = (y k + ) y = = y k + m. (x k + ) b d lower d upper = 2m. (x k + ) 2y k + 2b 28 /25 Bresenham s Line-Drawing Algorithm (2/4) Bresenham s Line-Drawing Algorithm (3/4) d lower d upper = = 2m. (x k + ) 2y k + 2b m = y/ x x, y: separations of endpoint positions decision p k = x. (d lower d upper ) = parameter: = 2 y. x k 2 x. y k + c has the same sign as (d lower d upper ) 29 /25 current decision value: p k = x. (d lower d upper ) = 2 y. x k 2 x. y k + c next decision value: p = 2 y. x k+ 2 x. k+ y k+ + c + 0 + p k 2Dy. x k + 2Dx. y k c = starting decision = p value: k + 2 y 2 x. (y k+ y k ) p 0 = 2 y x 30 /25 5

Bresenham s Algorithm (4/4). store left line endpoint in (x 0,y 0 ) 2. plot pixel (x 0,y 0 ) 3. calculate constants x, y, 2 y, 2 y - 2 x, and obtain p 0 = 2 y - x 4. At each x k along the line, perform test: if p k <0 then plot pixel (x k +,y k ); p k+ = p k + 2 y else plot pixel (x k +,y k +); p k+ = p k + 2 y - 2 x 5. perform step 4 x - times. Bresenham: Example line from (20/0) to (30/8) 3 /25 32 /25 Flood fill 2 2 2 02 starting point Internal point =BLUE Flood(x, y) { if (pixel[x][y] is internal) { Write(x, y, color); Flood(x, y-); Flood(x, y+); Flood(x-, y); Flood(x+, y); 33 /25 Specific area filling Based on the geometrical representation p,p2,...,pn vertices p-p2, p2-p3,...,pn-pedges Internal pixels cast a ray into the infinity the number of intersection points with the edges has to be odd infinity : the border line of the viewport after the clipping 34 /25 Polygon filling p2 Accelerated filling Check only the active edges Incremental intersection point calculation y p4 x x4 x3 x2 Dx/Dy Dx/Dy p p3 y 35 /25 x(y) x(y+) x(y+2) 36 /25 6

List of active edges AET: active edge table AEL ymax Dx/Dy x next ymax Dx/Dy x next ymin=024 ymax Dx/Dy x next ymax Dx/Dy x next ymin= ymin=0 37 /25 7