RASTERIZATION
Scan Converting a Line
Lecture 02-03
Graphics Pipeline
• The graphics pipeline or rendering pipeline refers to the sequence of steps
used to create a 2D raster representation of a 3D scene.
• Stages of the graphics pipeline:
• Modeling individual Objects using 3D geometric primitives: Traditionally done
using triangles, making a wire frame for an object.
• Modeling and transformation into world coordinates: Transform from the local
coordinate system to the 3d world coordinate system.
• Camera transformation: Transform the 3d world coordinate system into the 3d
camera coordinate system, with the camera as the origin.
• Lighting: Illuminate according to lighting and reflectance.
• Projection transformation: Transform the 3d world coordinates into the 2d view of
the camera.
• Clipping: Geometric primitives that now fall completely outside of the viewing
frustum will not be visible and are discarded at this stage.
• Scan conversion or rasterization: The process by which the 2D image space
representation of the scene is converted into raster format and the correct resulting
pixel values are determined. From now on, operations will be carried out on each
single pixel.
• Texturing, fragment shading: At this stage of the pipeline individual fragments are
assigned a color based on values interpolated from the vertices during rasterization,
from a texture in memory, or from a shader program.
Points
• How to draw points in processing?
• Coordinates of the screen
• top left corner is assigned as origin, going right increases in x to width-1
coordinate, and going down increases in y to the height-1
• The setup() function
• Creating a window using size(width, height)
• Drawing a point using point(x,y)
• Setting point size using strokeWeight(no. of pixels)
• Setting color using stroke(colorR, colorG, colorB)
• single color value for working with greyscale images, each argument has a
value from 0-255
• Changing background color using background()
• Once stroke or stroke weight is changed, it affects the primitives
used/written after this line of code and not to any of the previously
drawn.
• How to rasterize a line between two given points?
Scan Conversion
• ‘Scan conversion’/rasterization is the process of taking
geometric shapes and converting them into an array of
pixels stored in the framebuffer to be displayed
• Or converting from ‘random scan’/vector specification to a raster
scan where we specify which pixels are ‘ON’ based on a stored
array of pixels
• Takes place after clipping occurs
• All graphics packages do this at end of the rendering
pipeline
How does computer draw line?
• Screen made of pixels
• High-level language specifies line
• System must color pixels
• There should be
• No gaps in adjacent pixels
• Pixels close to ideal line
• Consistent choices; same pixels in same
situations
• Smooth looking
• Even brightness in all orientations
• Same line for as for P0, P1 and P1, P0
• Which pixels to choose?
Scan Convert a Line
• Finding the next pixel
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. Here |slope|=1
• What should we do in the general case?
• For |slope| < 1 (gentle slope), increment x coordinate by 1 and
choose pixel on or closest to line. For |slope| > 1 (steep slope),
increment y coordinate by 1 and choose pixel on or closest to line.
• But how do we measure “closest”?
Steep Slope vs. Gentle Slope
• So, choose which coordinate to increment and the point to
start from wisely
Strategy 1: Explicit Line Equation
• Slope-intercept form: y=mx+c, where
• Find out m and c for once
• For |m| <=1 find out no. of pixels to be shaded, for every x
find out the value for y
00 mxyb 
x
y
xx
yy
m
end
end






0
0
Strategy 2: Parametric Form
• P(t)=(1-t)P0+tP1
where P(0)=P0 and P(1)=P1
• Putting t=0 gives the first point and putting t=1 gives the
second point, so, t varies from 0 to 1 i.e. 0<=t<=1
• The value of t represents the step size to be used.
• It is one unit of movement in the given direction
• Smaller t means smaller step.
• Smaller step means more steps are required to complete
the line
• More steps, i.e. smaller steps, is better resolution
• 1/t = number of “subdivisions” of the line
void DrawLine(Point p1, Point p2)
{
for(float t = 0.0; t <= 1.0; t += 0.005)
{
float newX = p1.X * (1.0-t) + p2.X * t;
float newY = p1.Y * (1.0-t) + p2.Y * t;
point(newX, newY);
}
}
Using t implies any resolution of the line is normalized between 0 and 1
Implementing Parametric Form
The previous two strategies
• Every value of (x,y) pair is independent of the calculations
performed for the previous pair
• Interpolate instead, do incremental calculations
• Expensive to implement since it uses floating point
multiplication for finding each value of y
• Get rid of expensive operations
Strategy 3: Incremental Algorithms
DDA – Digital Differential Analyzer Algorithm
(works for lines of both steep and gentle slopes)
1. Start with starting and ending coordinates of the line:
• (x0, y0) and (x1, y1)
2. Color first pixel (round to nearest integer)
3. Suppose x1-x0 > y1-y0 (gentle slope)
• numsteps=x1-x0 steps (# pixels to be colored)
• else there will be y1-y0 steps i.e. numsteps=y1-y0
4. Set x=x0, y=y0
5. Set stepX= (x1-x0)/numsteps; stepY= (y1-y0)/numsteps
6. At each step,
• increment x by stepX, and
• increment y by stepY
7. For each step, round off x and y to nearest integer, and color
pixel
DDA Example
• Suppose we want to
draw a line starting at
pixel (2,3) and ending
at pixel (12,8).
• What are the values of
the variables x and y at
each timestep?
• What are the pixels
colored, according to
the DDA algorithm?
numsteps = 12 – 2 = 10
xinc = 10/10 = 1.0
yinc = 5/10 = 0.5
t x y R(x) R(y)
0 2 3 2 3
1 3 3.5 3 4
2 4 4 4 4
3 5 4.5 5 5
4 6 5 6 5
5 7 5.5 7 6
6 8 6 8 6
7 9 6.5 9 7
8 10 7 10 7
9 11 7.5 11 8
10 12 8 12 8
DDAAlgorithm (continued)
• Advantage
• Does not calculate coordinates based on the complete equation
• Disadvantage
• Round-off errors are accumulated, thus line diverges more and
more from actual line
• Round-off operations take time and still uses floating point
additions, both of which are expensive
References
• Computer Graphics with OpenGL, Hearn and Baker,
2010, 4th edition (text book)
• http://www.ltcconline.net/greenl/courses/107/polarparam/p
arameq.htm
• http://cs.brown.edu/courses/
• https://courses.engr.illinois.edu/ece390/lecture/lockwood/
bresenham.gif

More Related Content

PPTX
Digital Differential Analyzer Line Drawing Algorithm
PDF
Computer vision lane line detection
PPTX
Line Detection
PPTX
A mid point ellipse drawing algorithm on a hexagonal grid
PPTX
Computer graphics presentation
PPTX
Singular Value Decomposition Image Compression
PPT
Graphics6 bresenham circlesandpolygons
Digital Differential Analyzer Line Drawing Algorithm
Computer vision lane line detection
Line Detection
A mid point ellipse drawing algorithm on a hexagonal grid
Computer graphics presentation
Singular Value Decomposition Image Compression
Graphics6 bresenham circlesandpolygons

What's hot (20)

PPTX
DDA (digital differential analyzer)
PPTX
Visible surface determination
PPTX
Computer Graphics Unit 1
PPTX
Computer Graphics - Hidden Line Removal Algorithm
PPTX
COMPUTER GRAPHICS
PPT
1536 graphics &amp; graphical programming
PPTX
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
PPTX
Clipping 22
PPT
visible surface detection
PPTX
Basics of Linear Hough Transform
PPT
Cs8092 computer graphics and multimedia unit 2
PDF
Algorithm
PPTX
Computer Graphics: Visible surface detection methods
PPT
Visible surface detection in computer graphic
PPTX
Intensity Transformation Functions of image with Matlab
PPTX
Hidden surface removal algorithm
PPT
Hidden Surfaces
PPT
Basics of CT- Lecture 9.ppt
PPTX
Hidden surface removal
PPT
DDA (digital differential analyzer)
Visible surface determination
Computer Graphics Unit 1
Computer Graphics - Hidden Line Removal Algorithm
COMPUTER GRAPHICS
1536 graphics &amp; graphical programming
Raster Scan Graphics, Line Drawing Algorithm and Circle Drawing Algorithm
Clipping 22
visible surface detection
Basics of Linear Hough Transform
Cs8092 computer graphics and multimedia unit 2
Algorithm
Computer Graphics: Visible surface detection methods
Visible surface detection in computer graphic
Intensity Transformation Functions of image with Matlab
Hidden surface removal algorithm
Hidden Surfaces
Basics of CT- Lecture 9.ppt
Hidden surface removal
Ad

Similar to Lec02 03 rasterization (20)

PDF
Computer graphics notes 2 tutorials duniya
PPTX
Chapter 3 Output Primitives
PPT
Introduction to Computer Graphics elements
PPT
Unit I-cg.ppt Introduction to Computer Graphics elements
PPT
Introduction to Computer Graphics computer
PPT
Implementation
PDF
Computer Graphics Unit 2
PPT
Line drawing algorithm and antialiasing techniques
DOCX
Unit 2 notes
PPT
Angel6E25educationmaterial for reference
PDF
Open GL T0074 56 sm3
PDF
PPTX
B. SC CSIT Computer Graphics Lab By Tekendra Nath Yogi
PDF
Open GL T0074 56 sm1
PPT
Lab lecture 1 line_algo
PDF
Unit 2
PPTX
L-5 (Line Drawing Algorithms Computer graphics).pptx
PPT
Bresenham circles and polygons derication
PPT
Bresenham circlesandpolygons
Computer graphics notes 2 tutorials duniya
Chapter 3 Output Primitives
Introduction to Computer Graphics elements
Unit I-cg.ppt Introduction to Computer Graphics elements
Introduction to Computer Graphics computer
Implementation
Computer Graphics Unit 2
Line drawing algorithm and antialiasing techniques
Unit 2 notes
Angel6E25educationmaterial for reference
Open GL T0074 56 sm3
B. SC CSIT Computer Graphics Lab By Tekendra Nath Yogi
Open GL T0074 56 sm1
Lab lecture 1 line_algo
Unit 2
L-5 (Line Drawing Algorithms Computer graphics).pptx
Bresenham circles and polygons derication
Bresenham circlesandpolygons
Ad

Lec02 03 rasterization

  • 1. RASTERIZATION Scan Converting a Line Lecture 02-03
  • 2. Graphics Pipeline • The graphics pipeline or rendering pipeline refers to the sequence of steps used to create a 2D raster representation of a 3D scene. • Stages of the graphics pipeline: • Modeling individual Objects using 3D geometric primitives: Traditionally done using triangles, making a wire frame for an object. • Modeling and transformation into world coordinates: Transform from the local coordinate system to the 3d world coordinate system. • Camera transformation: Transform the 3d world coordinate system into the 3d camera coordinate system, with the camera as the origin. • Lighting: Illuminate according to lighting and reflectance. • Projection transformation: Transform the 3d world coordinates into the 2d view of the camera. • Clipping: Geometric primitives that now fall completely outside of the viewing frustum will not be visible and are discarded at this stage. • Scan conversion or rasterization: The process by which the 2D image space representation of the scene is converted into raster format and the correct resulting pixel values are determined. From now on, operations will be carried out on each single pixel. • Texturing, fragment shading: At this stage of the pipeline individual fragments are assigned a color based on values interpolated from the vertices during rasterization, from a texture in memory, or from a shader program.
  • 3. Points • How to draw points in processing? • Coordinates of the screen • top left corner is assigned as origin, going right increases in x to width-1 coordinate, and going down increases in y to the height-1 • The setup() function • Creating a window using size(width, height) • Drawing a point using point(x,y) • Setting point size using strokeWeight(no. of pixels) • Setting color using stroke(colorR, colorG, colorB) • single color value for working with greyscale images, each argument has a value from 0-255 • Changing background color using background() • Once stroke or stroke weight is changed, it affects the primitives used/written after this line of code and not to any of the previously drawn. • How to rasterize a line between two given points?
  • 4. Scan Conversion • ‘Scan conversion’/rasterization is the process of taking geometric shapes and converting them into an array of pixels stored in the framebuffer to be displayed • Or converting from ‘random scan’/vector specification to a raster scan where we specify which pixels are ‘ON’ based on a stored array of pixels • Takes place after clipping occurs • All graphics packages do this at end of the rendering pipeline
  • 5. How does computer draw line? • Screen made of pixels • High-level language specifies line • System must color pixels • There should be • No gaps in adjacent pixels • Pixels close to ideal line • Consistent choices; same pixels in same situations • Smooth looking • Even brightness in all orientations • Same line for as for P0, P1 and P1, P0 • Which pixels to choose?
  • 6. Scan Convert a Line • Finding the next pixel 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. Here |slope|=1 • What should we do in the general case? • For |slope| < 1 (gentle slope), increment x coordinate by 1 and choose pixel on or closest to line. For |slope| > 1 (steep slope), increment y coordinate by 1 and choose pixel on or closest to line. • But how do we measure “closest”?
  • 7. Steep Slope vs. Gentle Slope • So, choose which coordinate to increment and the point to start from wisely
  • 8. Strategy 1: Explicit Line Equation • Slope-intercept form: y=mx+c, where • Find out m and c for once • For |m| <=1 find out no. of pixels to be shaded, for every x find out the value for y 00 mxyb  x y xx yy m end end       0 0
  • 9. Strategy 2: Parametric Form • P(t)=(1-t)P0+tP1 where P(0)=P0 and P(1)=P1 • Putting t=0 gives the first point and putting t=1 gives the second point, so, t varies from 0 to 1 i.e. 0<=t<=1 • The value of t represents the step size to be used. • It is one unit of movement in the given direction • Smaller t means smaller step. • Smaller step means more steps are required to complete the line • More steps, i.e. smaller steps, is better resolution • 1/t = number of “subdivisions” of the line
  • 10. void DrawLine(Point p1, Point p2) { for(float t = 0.0; t <= 1.0; t += 0.005) { float newX = p1.X * (1.0-t) + p2.X * t; float newY = p1.Y * (1.0-t) + p2.Y * t; point(newX, newY); } } Using t implies any resolution of the line is normalized between 0 and 1 Implementing Parametric Form
  • 11. The previous two strategies • Every value of (x,y) pair is independent of the calculations performed for the previous pair • Interpolate instead, do incremental calculations • Expensive to implement since it uses floating point multiplication for finding each value of y • Get rid of expensive operations
  • 12. Strategy 3: Incremental Algorithms DDA – Digital Differential Analyzer Algorithm (works for lines of both steep and gentle slopes) 1. Start with starting and ending coordinates of the line: • (x0, y0) and (x1, y1) 2. Color first pixel (round to nearest integer) 3. Suppose x1-x0 > y1-y0 (gentle slope) • numsteps=x1-x0 steps (# pixels to be colored) • else there will be y1-y0 steps i.e. numsteps=y1-y0 4. Set x=x0, y=y0 5. Set stepX= (x1-x0)/numsteps; stepY= (y1-y0)/numsteps 6. At each step, • increment x by stepX, and • increment y by stepY 7. For each step, round off x and y to nearest integer, and color pixel
  • 13. DDA Example • Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8). • What are the values of the variables x and y at each timestep? • What are the pixels colored, according to the DDA algorithm? numsteps = 12 – 2 = 10 xinc = 10/10 = 1.0 yinc = 5/10 = 0.5 t x y R(x) R(y) 0 2 3 2 3 1 3 3.5 3 4 2 4 4 4 4 3 5 4.5 5 5 4 6 5 6 5 5 7 5.5 7 6 6 8 6 8 6 7 9 6.5 9 7 8 10 7 10 7 9 11 7.5 11 8 10 12 8 12 8
  • 14. DDAAlgorithm (continued) • Advantage • Does not calculate coordinates based on the complete equation • Disadvantage • Round-off errors are accumulated, thus line diverges more and more from actual line • Round-off operations take time and still uses floating point additions, both of which are expensive
  • 15. References • Computer Graphics with OpenGL, Hearn and Baker, 2010, 4th edition (text book) • http://www.ltcconline.net/greenl/courses/107/polarparam/p arameq.htm • http://cs.brown.edu/courses/ • https://courses.engr.illinois.edu/ece390/lecture/lockwood/ bresenham.gif