1 / 17

The Rasterization Problem: Idealized Primitives Map to Discrete Display Space

This article explores the problem of rasterization, specifically how idealized primitives are mapped to discrete display space. It discusses scan converting lines and presents the DDA and Bresenham's algorithms as solutions.

luong
Télécharger la présentation

The Rasterization Problem: Idealized Primitives Map to Discrete Display Space

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Rasterization Problem: Idealized PrimitivesMap to Discrete Display Space Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt 更新时间2019年10月31日星期四7时38分11秒

  2. Solution Involves Selection of DiscreteRepresentation Values Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  3. Scan Converting Lines:Characterizing the Problem ideal line i.e. for each x, choose y i.e. for each y, choose x Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  4. Scan Converting Lines:The Strategy • Pick pixels closest to endpoints • Select in between pixels “closest” to ideal line • Objective: To minimize the required calculations. • Pixels can be displayed in multiple shapes and sizes. • In OpenGL, the centers of pixels are located at values halfway between intergers. Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  5. Calculate ideal line equation Starting at leftmost point: for each xi Calculate Select pixel at Scan Converting Lines:DDA (Digital Differential Analyzer) Algorithm Selected Not Selected Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  6. Scan Converting Lines:DDA Algorithm, Incremental Form Therefore, rather than recomputing y in each step, simply add m. The Algorithm: void Line(int x0, int y0, int xn, int yn) { int x; float dy, dx, y, m; dy = yn - y0; dx = xn - x0; m = dy/dx; y = y0; for (x = x0; x<=xn,x++){ WritePixel(x, round(y)); y += m; } } Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  7. We assume m ≤1 in the above. • For larger slope, the separation between pixels can be large, generating an unacceptable rendering of the line segment. • We swap the roles of x and y for line segments with larger slopes. Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  8. Not Allowed Option NE 0 <= Slope <= 1 Option E Last Selection Bresenham’s Algorithm:Allowable Pixel Selections • DDA requires a floating-point addition. • Bresenham derived an algorithm that avoids all floating-point claculations. Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  9. Bresenham’s Algorithm:Iterating 0 <= Slope <= 1 Select E Select NE Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  10. Bresenham’s AlgorithmDecision Function: (implicit equation of the line) Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  11. Bresenham’s Algorithm:Calculating the Decision Function Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  12. Option NE Option E Bresenham’s Algorithm:Incremental Calculation of di Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  13. Bresenham’s Algorithm:The Code void BresenhamLine(int x0, int y0, int xn, int yn) { int dx,dy,incrE,incrNE,d,x,y; dx=xn-x0; dy=yn-y0; d=2*dy-dx; /* initial value of d */ incrE=2*dy; /* decision funct incr for E */ incrNE=2*dy-2*dx; /* decision funct incr for NE */ x=x0; y=y0; DrawPixel(x,y) /* draw the first pixel */ while (x<xn){ if (d<=0){ /* choose E */ d+=incrE; x++; /* move E */ }else{ /* choose NE */ d+=incrNE; x++; y++; /* move NE */ } DrawPixel (x,y); } } Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  14. Bresenham’s AlgorithmAn example 12 11 10 9 8 7 4 5 6 7 8 9 Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  15. Bresenham’s AlgorithmAn example 12 11 10 9 8 7 4 5 6 7 8 9 Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  16. Bresenham’s AlgorithmAn example 12 11 10 9 8 7 4 5 6 7 8 9 Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

  17. Another derivation: comparing d1 and d2 Not Allowed Option NE 0 <= Slope <= 1 d1 d2 Last Selection Option E Ref. [HA], Section 3.2.2 Edited from http://www.comp.hkbu.edu.hk/~sci3750/lect8-04.ppt

More Related