SlideShare a Scribd company logo
1 of 21
Implementation III
Ed Angel
Professor Emeritus of Computer Science
University of New Mexico
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Objectives
•Survey Line Drawing Algorithms
- DDA
- Bresenham’s Algorithm
•Aliasing and Antialiasing
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Rasterization
•Rasterization (scan conversion)
- Determine which pixels that are inside primitive
specified by a set of vertices
- Produces a set of fragments
- Fragments have a location (pixel location) and
other attributes such color and texture
coordinates that are determined by interpolating
values at vertices
•Pixel colors determined later using color,
texture, and other vertex properties
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Scan Conversion of Line
Segments
•Start with line segment in window
coordinates with integer values for
endpoints
•Assume implementation has a
write_pixel function
y = mx + h
x
y
m



E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
DDA Algorithm
• Digital Differential Analyzer
- DDA was a mechanical device for numerical
solution of differential equations
- Line y=mx+ h satisfies differential equation
dy/dx = m = y/x = y2-y1/x2-x1
• Along scan line x = 1
For(x=x1; x<=x2,ix++) {
y+=m;
write_pixel(x, round(y), line_color)
}
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Problem
•DDA = for each x plot pixel at closest y
- Problems for steep lines
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Using Symmetry
•Use for 1  m  0
•For m > 1, swap role of x and y
- For each y, plot closest x
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Bresenham’s Algorithm
• DDA requires one floating point addition per step
• We can eliminate all fp through Bresenham’s
algorithm
• Consider only 1  m  0
- Other cases by symmetry
• Assume pixel centers are at half integers
• If we start at a pixel that has been written, there
are only two candidates for the next pixel to be
written into the frame buffer
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Candidate Pixels
1  m  0
last pixel
candidates
Note that line could have
passed through any
part of this pixel
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Decision Variable
-
d = x(b-a)
d is an integer
d > 0 use upper pixel
d < 0 use lower pixel
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Incremental Form
•More efficient if we look at dk, the value of
the decision variable at x = k
dk+1= dk –2y, if dk <0
dk+1= dk –2(y- x), otherwise
•For each x, we need do only an integer
addition and a test
•Single instruction on graphics chips
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Polygon Scan Conversion
•Scan Conversion = Fill
•How to tell inside from outside
- Convex easy
- Nonsimple difficult
- Odd even test
• Count edge crossings
- Winding number
odd-even fill
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Winding Number
•Count clockwise encirclements of point
•Alternate definition of inside: inside if
winding number  0
winding number = 2
winding number = 1
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Filling in the Frame Buffer
•Fill at end of pipeline
- Convex Polygons only
- Nonconvex polygons assumed to have been
tessellated
- Shades (colors) have been computed for
vertices (Gouraud shading)
- Combine with z-buffer algorithm
• March across scan lines interpolating shades
• Incremental work small
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Using Interpolation
span
C1
C3
C2
C5
C4
scan line
C1 C2 C3 specified by glColor or by vertex shading
C4 determined by interpolating between C1 and C2
C5 determined by interpolating between C2 and C3
interpolate between C4 and C5 along span
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Flood Fill
• Fill can be done recursively if we know a seed
point located inside (WHITE)
• Scan convert edges into buffer in edge/inside
color (BLACK)
flood_fill(int x, int y) {
if(read_pixel(x,y)= = WHITE) {
write_pixel(x,y,BLACK);
flood_fill(x-1, y);
flood_fill(x+1, y);
flood_fill(x, y+1);
flood_fill(x, y-1);
} }
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Scan Line Fill
• Can also fill by maintaining a data structure of all
intersections of polygons with scan lines
- Sort by scan line
- Fill each span
vertex order generated
by vertex list desired order
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Data Structure
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Aliasing
•Ideal rasterized line should be 1 pixel wide
•Choosing best y for each x (or visa versa)
produces aliased raster lines
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Antialiasing by Area
Averaging
• Color multiple pixels for each x depending on
coverage by ideal line
original antialiased
magnified
E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
Polygon Aliasing
•Aliasing problems can be serious for
polygons
- Jaggedness of edges
- Small polygons neglected
- Need compositing so color
of one polygon does not
totally determine color of
pixel
All three polygons should contribute to color

More Related Content

Similar to Angel6E25educationmaterial for reference

Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- ButkarComputer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- ButkarVishal Butkar
 
Machine Learning Foundations for Professional Managers
Machine Learning Foundations for Professional ManagersMachine Learning Foundations for Professional Managers
Machine Learning Foundations for Professional ManagersAlbert Y. C. Chen
 
SCALABLE PATTERN MATCHING OVER COMPRESSED GRAPHS VIA DE-DENSIFICATION
SCALABLE PATTERN MATCHING OVER COMPRESSED GRAPHS VIA DE-DENSIFICATIONSCALABLE PATTERN MATCHING OVER COMPRESSED GRAPHS VIA DE-DENSIFICATION
SCALABLE PATTERN MATCHING OVER COMPRESSED GRAPHS VIA DE-DENSIFICATIONaftab alam
 
Making BIG DATA smaller
Making BIG DATA smallerMaking BIG DATA smaller
Making BIG DATA smallerTony Tran
 
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUES
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUESA STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUES
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUEScscpconf
 
Digital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image FundamentalsDigital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image FundamentalsMostafa G. M. Mostafa
 
Visualization of general defined space data
Visualization of general defined space dataVisualization of general defined space data
Visualization of general defined space dataijcga
 
Slides: Perspective click-and-drag area selections in pictures
Slides: Perspective click-and-drag area selections in picturesSlides: Perspective click-and-drag area selections in pictures
Slides: Perspective click-and-drag area selections in picturesFrank Nielsen
 
Embeddings the geometry of relational algebra
Embeddings  the geometry of relational algebraEmbeddings  the geometry of relational algebra
Embeddings the geometry of relational algebraNikolaos Vasiloglou
 
An Efficient Convex Hull Algorithm for a Planer Set of Points
An Efficient Convex Hull Algorithm for a Planer Set of PointsAn Efficient Convex Hull Algorithm for a Planer Set of Points
An Efficient Convex Hull Algorithm for a Planer Set of PointsKasun Ranga Wijeweera
 
"Demystifying Deep Neural Networks," a Presentation from BDTI
"Demystifying Deep Neural Networks," a Presentation from BDTI"Demystifying Deep Neural Networks," a Presentation from BDTI
"Demystifying Deep Neural Networks," a Presentation from BDTIEdge AI and Vision Alliance
 
Variational Autoencoders For Image Generation
Variational Autoencoders For Image GenerationVariational Autoencoders For Image Generation
Variational Autoencoders For Image GenerationJason Anderson
 
Study on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan GraphicsStudy on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan GraphicsChandrakantDivate1
 

Similar to Angel6E25educationmaterial for reference (20)

Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- ButkarComputer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
Computer Graphics - Introduction in Brief By: Prof. Manisha Waghmare- Butkar
 
Machine Learning Foundations for Professional Managers
Machine Learning Foundations for Professional ManagersMachine Learning Foundations for Professional Managers
Machine Learning Foundations for Professional Managers
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Angel6 e05
Angel6 e05Angel6 e05
Angel6 e05
 
SCALABLE PATTERN MATCHING OVER COMPRESSED GRAPHS VIA DE-DENSIFICATION
SCALABLE PATTERN MATCHING OVER COMPRESSED GRAPHS VIA DE-DENSIFICATIONSCALABLE PATTERN MATCHING OVER COMPRESSED GRAPHS VIA DE-DENSIFICATION
SCALABLE PATTERN MATCHING OVER COMPRESSED GRAPHS VIA DE-DENSIFICATION
 
Making BIG DATA smaller
Making BIG DATA smallerMaking BIG DATA smaller
Making BIG DATA smaller
 
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUES
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUESA STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUES
A STUDY AND ANALYSIS OF DIFFERENT EDGE DETECTION TECHNIQUES
 
Digital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image FundamentalsDigital Image Processing: Digital Image Fundamentals
Digital Image Processing: Digital Image Fundamentals
 
V2 v posenet
V2 v posenetV2 v posenet
V2 v posenet
 
Visualization of general defined space data
Visualization of general defined space dataVisualization of general defined space data
Visualization of general defined space data
 
Cg
CgCg
Cg
 
Slides: Perspective click-and-drag area selections in pictures
Slides: Perspective click-and-drag area selections in picturesSlides: Perspective click-and-drag area selections in pictures
Slides: Perspective click-and-drag area selections in pictures
 
Primitives
PrimitivesPrimitives
Primitives
 
Embeddings the geometry of relational algebra
Embeddings  the geometry of relational algebraEmbeddings  the geometry of relational algebra
Embeddings the geometry of relational algebra
 
An Efficient Convex Hull Algorithm for a Planer Set of Points
An Efficient Convex Hull Algorithm for a Planer Set of PointsAn Efficient Convex Hull Algorithm for a Planer Set of Points
An Efficient Convex Hull Algorithm for a Planer Set of Points
 
"Demystifying Deep Neural Networks," a Presentation from BDTI
"Demystifying Deep Neural Networks," a Presentation from BDTI"Demystifying Deep Neural Networks," a Presentation from BDTI
"Demystifying Deep Neural Networks," a Presentation from BDTI
 
Variational Autoencoders For Image Generation
Variational Autoencoders For Image GenerationVariational Autoencoders For Image Generation
Variational Autoencoders For Image Generation
 
Study on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan GraphicsStudy on Fundamentals of Raster Scan Graphics
Study on Fundamentals of Raster Scan Graphics
 
Deep Learning for Computer Vision: Attention Models (UPC 2016)
Deep Learning for Computer Vision: Attention Models (UPC 2016)Deep Learning for Computer Vision: Attention Models (UPC 2016)
Deep Learning for Computer Vision: Attention Models (UPC 2016)
 
PPT s12-machine vision-s2
PPT s12-machine vision-s2PPT s12-machine vision-s2
PPT s12-machine vision-s2
 

Recently uploaded

An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 

Angel6E25educationmaterial for reference

  • 1. Implementation III Ed Angel Professor Emeritus of Computer Science University of New Mexico E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012
  • 2. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Objectives •Survey Line Drawing Algorithms - DDA - Bresenham’s Algorithm •Aliasing and Antialiasing
  • 3. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Rasterization •Rasterization (scan conversion) - Determine which pixels that are inside primitive specified by a set of vertices - Produces a set of fragments - Fragments have a location (pixel location) and other attributes such color and texture coordinates that are determined by interpolating values at vertices •Pixel colors determined later using color, texture, and other vertex properties
  • 4. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Scan Conversion of Line Segments •Start with line segment in window coordinates with integer values for endpoints •Assume implementation has a write_pixel function y = mx + h x y m   
  • 5. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 DDA Algorithm • Digital Differential Analyzer - DDA was a mechanical device for numerical solution of differential equations - Line y=mx+ h satisfies differential equation dy/dx = m = y/x = y2-y1/x2-x1 • Along scan line x = 1 For(x=x1; x<=x2,ix++) { y+=m; write_pixel(x, round(y), line_color) }
  • 6. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Problem •DDA = for each x plot pixel at closest y - Problems for steep lines
  • 7. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Using Symmetry •Use for 1  m  0 •For m > 1, swap role of x and y - For each y, plot closest x
  • 8. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Bresenham’s Algorithm • DDA requires one floating point addition per step • We can eliminate all fp through Bresenham’s algorithm • Consider only 1  m  0 - Other cases by symmetry • Assume pixel centers are at half integers • If we start at a pixel that has been written, there are only two candidates for the next pixel to be written into the frame buffer
  • 9. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Candidate Pixels 1  m  0 last pixel candidates Note that line could have passed through any part of this pixel
  • 10. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Decision Variable - d = x(b-a) d is an integer d > 0 use upper pixel d < 0 use lower pixel
  • 11. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Incremental Form •More efficient if we look at dk, the value of the decision variable at x = k dk+1= dk –2y, if dk <0 dk+1= dk –2(y- x), otherwise •For each x, we need do only an integer addition and a test •Single instruction on graphics chips
  • 12. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Polygon Scan Conversion •Scan Conversion = Fill •How to tell inside from outside - Convex easy - Nonsimple difficult - Odd even test • Count edge crossings - Winding number odd-even fill
  • 13. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Winding Number •Count clockwise encirclements of point •Alternate definition of inside: inside if winding number  0 winding number = 2 winding number = 1
  • 14. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Filling in the Frame Buffer •Fill at end of pipeline - Convex Polygons only - Nonconvex polygons assumed to have been tessellated - Shades (colors) have been computed for vertices (Gouraud shading) - Combine with z-buffer algorithm • March across scan lines interpolating shades • Incremental work small
  • 15. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Using Interpolation span C1 C3 C2 C5 C4 scan line C1 C2 C3 specified by glColor or by vertex shading C4 determined by interpolating between C1 and C2 C5 determined by interpolating between C2 and C3 interpolate between C4 and C5 along span
  • 16. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Flood Fill • Fill can be done recursively if we know a seed point located inside (WHITE) • Scan convert edges into buffer in edge/inside color (BLACK) flood_fill(int x, int y) { if(read_pixel(x,y)= = WHITE) { write_pixel(x,y,BLACK); flood_fill(x-1, y); flood_fill(x+1, y); flood_fill(x, y+1); flood_fill(x, y-1); } }
  • 17. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Scan Line Fill • Can also fill by maintaining a data structure of all intersections of polygons with scan lines - Sort by scan line - Fill each span vertex order generated by vertex list desired order
  • 18. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Data Structure
  • 19. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Aliasing •Ideal rasterized line should be 1 pixel wide •Choosing best y for each x (or visa versa) produces aliased raster lines
  • 20. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Antialiasing by Area Averaging • Color multiple pixels for each x depending on coverage by ideal line original antialiased magnified
  • 21. E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Polygon Aliasing •Aliasing problems can be serious for polygons - Jaggedness of edges - Small polygons neglected - Need compositing so color of one polygon does not totally determine color of pixel All three polygons should contribute to color