SlideShare a Scribd company logo
Chapter 5
Clipping & Rasterization
by
Ahmed Daoud
Presentation
Outline
• Introduction
• Clipping
- Line segment clipping: parametric form
- Cohen-Sutherland algorithm
- Liang-Barsky algorithm
- Polygon clipping
- Clipping in 3-D
• Rasterization
- Points
- Lines
- Polygons
- Inside-Outside Testing
- Crossing (odd - even) test
- Winding test
- Fill and Sort
- Flood fill
- Scanline fill
- Odd-even fill
Introduction
Introduction
• At end of the geometric pipeline, vertices have been
assembled into primitives (lines, planes, etc.)
• Must clip out primitives that are outside the view
volume
• Algorithms based on representing primitives by lists of
vertices
• Must find which pixels can be affected by each
primitive
Fragment generation
Rasterization or scan conversion
High-Level view of the graphics process
Application
program
Graphics
system
Frame
buffer
Vertices Pixels
• Two main steps:
- We must pass every geometric object through the system.
- we must assign a color to every pixel in the color buffer
that is displayed
Clipping
What is clipping?
• Clipping is the process of eliminating objects that lie
outside the viewing volume and thus cannot be
visible in the image.
• Clipping is the process of determining which
primitives, or part of primitives, fit within the clipping
or view volume defined by the application program
 2D against clipping window
 3D against clipping volume
 Easy for line segments polygons
 Hard for curves and text
- Convert to lines and polygons first
Line
segment
clipping
▸ A clipper decide which primitives, or part of
primitives, can possibly appear on the display and
be passed on to the rasterizer
▸ Primitives that fit within the specified view volume
pass through the clipper or are accepted
▸ Primitives that cannot appear on the display are
eliminated or rejected
Line
segment
clipping
Cohen-Sutherland algorithm
2D clipping
• A point (x, y) is coded according to its position with respect to the viewport boundaries with a
4-bit code called outcode
Cases of
outcodes
in Cohen-
Sutherland
algorithm
• Let the two endpoints of a line segment be (x1, y1) and (x2, y2)
and o1 = outcode(x1, y1) , o2 = outcode (x2, y2)
• There are 4 cases:
Case 1: o1 = o2 = 0
Both endpoints inside window  no clipping
Case 2: o1 != 0, o2 = 0 or o1 = 0, o2 != 0
One endpoint inside window  clip one end (given by outcode != 0)
Test against each edge in a fixed order and clip
Code intersection point, repeat process to see if 2nd clipping required
Case 3: o1 & o2 != 0 (Bitwise AND)
If endpoints are both on same side of a window edge discard.
Case 4: o1 & o2 = 0 (Bitwise AND)
The endpoints are both outside but across adjacent edges:
a) may intersect the extensions  line segment outside the window
b) may intersect the edges  line segment must be clipped at both
adjacent edges
Line segments and the parametric form
Line segments can be specified in many ways:
• 1) Slope and y intercept
y = m x + c m = slope Will not work for vertical line (m = ∞)
• 2) One point (x1, y1) and slope
y = y1 + m (x – x1) Will not work for vertical line (m = ∞)
• 3) Two points
(y – y2) / (x – x2) = (y – y1) / (x – x1) Will not work if x = x1 or x2
• 4) Parametric form: 2 points and a parameter
x = x1 u + x2 (1-u) y = y1 u + y2 (1-u) Will work for any line.
Furthermore, says that
• 0 <= u <= 1 (x, y) lies between (x1, y1) and (x2, y2)
• u < 0 (x, y) lies outside on the side of (x1, y1)
• u > 1 (x, y) lies outside on the side of (x2, y2)
Line
segment
clipping
Liang-Barsky algorithm
▸Consider the parametric form of a line
segment
p(a) = (1-a)p1+ ap2 1 ≥ a ≥ 0
Liang-
Barsky
algorithm
▸ We can distinguish between the cases by looking at
the ordering of the values of a where the line
determined by the line segment crosses the lines that
determine the window
Polygon
clipping
▸Polygons need to be clipped against a rectangular (usually)
window.
▸Not as simple as line segment clipping
Clipping a line segment yields at most one line segment
Clipping a polygon can yield multiple polygons
▸ Sometimes clipped against non-rectangular windows
▸Consider rectangular windows:
Convex polygon  Clipped convex polygon (only one)
Concave polygon  May result in more than one
clipped piece
Strategies
1. Brute force
2. Triangulation = Replace nonconvex with convex pieces
(Tessellation)
3. Clipping as a Black Box  Pipeline approach
1. Brute Force Straightforward algorithm: Apply Cohen-Surtherland or Liang-Barsky edge by edge
2. Tessellation and
Convexity
▸Replace nonconvex (concave) polygons with a set of triangular
polygons (a tessellation)
▸Also makes fill easier
3. Black box
approach: clipping
pipeline
▸Can consider line segment clipping as a process that takes in two
vertices and produces either no vertices or the vertices of a clipped line
segment  Clipping against each side of window is independent of
other sides
▸Can use four independent clippers in a pipeline
Exmaple: Black Box:
Line clipping
▸Polygon can be clipped successively against the boundaries of the window edge by
edge
Clipping
in 3-D
▸Cohen Sutherland in 3D
▸Use 6-bit outcodes
▸When needed, clip
line segment
against planes
Clipping
in 3-D
▸Cohen Sutherland in 3D
Rasterization
What is
Rasterization?
• This is (almost) the last stage in the viewing
pipeline
• Produces fragments from the remaining objects
and them into discrete representation, in the
frame buffer, for display
• The resulting objects from the previous
transformations are essentially polygons which
must now be rasterized, that is, they must be
converted to addresses in the buffer and the
contents of the address loaded with
color/intensity information.
• Sometimes called scan conversion
Rasterization
▸This scan conversion can be considered from simple
to complicated
▸Scan conversion of :
▸Points
▸Lines
▸Polygons
Points
• The color buffer is n x m array of pixels
• The address is now the address of a pixel address
(ix, iy)
• A color or intensity is now stored in the buffer
location corresponding to (ix, iy)  write_pixel (ix, iy,
value);
Lines
• Line L is given by the points in the segment (ix1, iy1)
- (ix2, iy2)
• These points must be scan converted 
rounded/truncated to integer addresses on the
screen.
• Line scan conversion algorithms
• DDA algorithm
• Bresenham algorithm
Lines
• Points on line are obtained from the differential
equation dy/dx = m
• where m = (y2 – y1) / (x2 – x1) = Δy / Δx 0 ≤ m ≤ 1
▸Coordinates are integers  pixels generated
successively with increments of 1 in the x variable.
▸Change in y = Δy = m Δx
▸Δx always 1  Δy = m
for (ix=x; ix <= ix2; ix++)
{
y += m;
write_pixel(x, round (y),line_color);
}
Ploygons
 Inside-Outside Testing
- Crossing test = Odd-even test
- Winding test (for non-simple polygons)
 Fill and Sort
- Flood fill
- Scanline fill
- Odd-even fill
Inside-Outside
Testing
1) Crossing test = Odd-even test
- Let p be a point inside a simple polygon any ray from
p must cross an odd number of edges of the polygon
- Let p be a point outside a simple polygon any ray from
p must cross an even number of edges of the polygon
2) Winding test (for non-simple polygons)
- we must decide how to determine whether a given point
is inside or outside of the polygon.
- Winding Number Count clockwise encirclements of
point:
odd  inside even  outside
Winding test
Example
Flood fill
▸Fill can be done recursively from an initial point, seed
point, located inside the polygon (WHITE)
▸Scan convert edges into buffer in edge/inside color
(BLACK)
void 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);
}
}
Hidden-Surface Removal
What is hidden-
surface removal?
• Determines which fragments correspond to objects
that are visible.
• Those that are in the view volume and are not
blocked from view by other objects closer to the
camera.
Clipping & Rasterization

More Related Content

What's hot

Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
SIMONTHOMAS S
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsKetan Jani
 
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
Daroko blog(www.professionalbloggertricks.com)
 
Parametric equations
Parametric equationsParametric equations
Parametric equationsTarun Gehlot
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
Nv Thejaswini
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3
SIMONTHOMAS S
 
Exam ii(practice)
Exam ii(practice)Exam ii(practice)
Exam ii(practice)PublicLeaks
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
Abhishek Singh
 
Klt
KltKlt
On the Convex Layers of a Planer Dynamic Set of Points
On the Convex Layers of a Planer Dynamic Set of PointsOn the Convex Layers of a Planer Dynamic Set of Points
On the Convex Layers of a Planer Dynamic Set of Points
Kasun Ranga Wijeweera
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
Dr. C.V. Suresh Babu
 
Open GL T0074 56 sm2
Open GL T0074 56 sm2Open GL T0074 56 sm2
Open GL T0074 56 sm2Roziq Bahtiar
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
Mahesh Kodituwakku
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
PrathimaBaliga
 
Geometric algorithms
Geometric algorithmsGeometric algorithms
Geometric algorithms
Ganesh Solanke
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.Mohd Arif
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
Arvind Krishnaa
 
Interpolation
InterpolationInterpolation
Interpolation
Bhavik A Shah
 

What's hot (20)

Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
 
Parametric equations
Parametric equationsParametric equations
Parametric equations
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3Cs8092 computer graphics and multimedia unit 3
Cs8092 computer graphics and multimedia unit 3
 
Exam ii(practice)
Exam ii(practice)Exam ii(practice)
Exam ii(practice)
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
Klt
KltKlt
Klt
 
On the Convex Layers of a Planer Dynamic Set of Points
On the Convex Layers of a Planer Dynamic Set of PointsOn the Convex Layers of a Planer Dynamic Set of Points
On the Convex Layers of a Planer Dynamic Set of Points
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Open GL T0074 56 sm2
Open GL T0074 56 sm2Open GL T0074 56 sm2
Open GL T0074 56 sm2
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
Geometric algorithms
Geometric algorithmsGeometric algorithms
Geometric algorithms
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Interpolation
InterpolationInterpolation
Interpolation
 

Similar to Clipping & Rasterization

Clipping
ClippingClipping
Clipping
AMIT VIRAMGAMI
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
ShaishavShah8
 
Clipping
ClippingClipping
Clipping
nehrurevathy
 
Implementation
ImplementationImplementation
Implementation
Syed Zaid Irshad
 
Week6.ppt
Week6.pptWeek6.ppt
Week6.ppt
RUHULAMINLASKAR2
 
UNIT I_5.pdf
UNIT I_5.pdfUNIT I_5.pdf
UNIT I_5.pdf
Muthukumar P
 
Implementation
ImplementationImplementation
Implementation
Syed Zaid Irshad
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
aravindangc
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal Algorithm
Jyotiraman De
 
Module-5-1_230523_171754 (1).pdf
Module-5-1_230523_171754 (1).pdfModule-5-1_230523_171754 (1).pdf
Module-5-1_230523_171754 (1).pdf
vikasmittal92
 
7-Clipping-16 (1).pdf
7-Clipping-16 (1).pdf7-Clipping-16 (1).pdf
7-Clipping-16 (1).pdf
nikamomkarshahaji
 
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmPolygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Mani Kanth
 
An Efficient Model for Line Clipping Operation
An Efficient Model for Line Clipping OperationAn Efficient Model for Line Clipping Operation
An Efficient Model for Line Clipping Operation
Kasun Ranga Wijeweera
 
image segmentation image segmentation.pptx
image segmentation image segmentation.pptximage segmentation image segmentation.pptx
image segmentation image segmentation.pptx
NaveenKumar5162
 
super vector machines algorithms using deep
super vector machines algorithms using deepsuper vector machines algorithms using deep
super vector machines algorithms using deep
KNaveenKumarECE
 
99995327.ppt
99995327.ppt99995327.ppt
99995327.ppt
ABDULSAMADKAZI
 
clipping
clippingclipping
clipping
HiteshJain007
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3Roziq Bahtiar
 
Polygon filling
Polygon fillingPolygon filling
Materi_05_CG_2223_2_.pdf
Materi_05_CG_2223_2_.pdfMateri_05_CG_2223_2_.pdf
Materi_05_CG_2223_2_.pdf
ichsan6
 

Similar to Clipping & Rasterization (20)

Clipping
ClippingClipping
Clipping
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
 
Clipping
ClippingClipping
Clipping
 
Implementation
ImplementationImplementation
Implementation
 
Week6.ppt
Week6.pptWeek6.ppt
Week6.ppt
 
UNIT I_5.pdf
UNIT I_5.pdfUNIT I_5.pdf
UNIT I_5.pdf
 
Implementation
ImplementationImplementation
Implementation
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal Algorithm
 
Module-5-1_230523_171754 (1).pdf
Module-5-1_230523_171754 (1).pdfModule-5-1_230523_171754 (1).pdf
Module-5-1_230523_171754 (1).pdf
 
7-Clipping-16 (1).pdf
7-Clipping-16 (1).pdf7-Clipping-16 (1).pdf
7-Clipping-16 (1).pdf
 
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmPolygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
 
An Efficient Model for Line Clipping Operation
An Efficient Model for Line Clipping OperationAn Efficient Model for Line Clipping Operation
An Efficient Model for Line Clipping Operation
 
image segmentation image segmentation.pptx
image segmentation image segmentation.pptximage segmentation image segmentation.pptx
image segmentation image segmentation.pptx
 
super vector machines algorithms using deep
super vector machines algorithms using deepsuper vector machines algorithms using deep
super vector machines algorithms using deep
 
99995327.ppt
99995327.ppt99995327.ppt
99995327.ppt
 
clipping
clippingclipping
clipping
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Materi_05_CG_2223_2_.pdf
Materi_05_CG_2223_2_.pdfMateri_05_CG_2223_2_.pdf
Materi_05_CG_2223_2_.pdf
 

Recently uploaded

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 

Recently uploaded (20)

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 

Clipping & Rasterization

  • 1. Chapter 5 Clipping & Rasterization by Ahmed Daoud
  • 2. Presentation Outline • Introduction • Clipping - Line segment clipping: parametric form - Cohen-Sutherland algorithm - Liang-Barsky algorithm - Polygon clipping - Clipping in 3-D • Rasterization - Points - Lines - Polygons - Inside-Outside Testing - Crossing (odd - even) test - Winding test - Fill and Sort - Flood fill - Scanline fill - Odd-even fill
  • 4. Introduction • At end of the geometric pipeline, vertices have been assembled into primitives (lines, planes, etc.) • Must clip out primitives that are outside the view volume • Algorithms based on representing primitives by lists of vertices • Must find which pixels can be affected by each primitive Fragment generation Rasterization or scan conversion
  • 5. High-Level view of the graphics process Application program Graphics system Frame buffer Vertices Pixels • Two main steps: - We must pass every geometric object through the system. - we must assign a color to every pixel in the color buffer that is displayed
  • 7. What is clipping? • Clipping is the process of eliminating objects that lie outside the viewing volume and thus cannot be visible in the image. • Clipping is the process of determining which primitives, or part of primitives, fit within the clipping or view volume defined by the application program
  • 8.  2D against clipping window  3D against clipping volume  Easy for line segments polygons  Hard for curves and text - Convert to lines and polygons first
  • 9. Line segment clipping ▸ A clipper decide which primitives, or part of primitives, can possibly appear on the display and be passed on to the rasterizer ▸ Primitives that fit within the specified view volume pass through the clipper or are accepted ▸ Primitives that cannot appear on the display are eliminated or rejected
  • 11. • A point (x, y) is coded according to its position with respect to the viewport boundaries with a 4-bit code called outcode
  • 12.
  • 14. • Let the two endpoints of a line segment be (x1, y1) and (x2, y2) and o1 = outcode(x1, y1) , o2 = outcode (x2, y2) • There are 4 cases: Case 1: o1 = o2 = 0 Both endpoints inside window  no clipping Case 2: o1 != 0, o2 = 0 or o1 = 0, o2 != 0 One endpoint inside window  clip one end (given by outcode != 0) Test against each edge in a fixed order and clip Code intersection point, repeat process to see if 2nd clipping required Case 3: o1 & o2 != 0 (Bitwise AND) If endpoints are both on same side of a window edge discard. Case 4: o1 & o2 = 0 (Bitwise AND) The endpoints are both outside but across adjacent edges: a) may intersect the extensions  line segment outside the window b) may intersect the edges  line segment must be clipped at both adjacent edges
  • 15. Line segments and the parametric form Line segments can be specified in many ways: • 1) Slope and y intercept y = m x + c m = slope Will not work for vertical line (m = ∞) • 2) One point (x1, y1) and slope y = y1 + m (x – x1) Will not work for vertical line (m = ∞) • 3) Two points (y – y2) / (x – x2) = (y – y1) / (x – x1) Will not work if x = x1 or x2 • 4) Parametric form: 2 points and a parameter x = x1 u + x2 (1-u) y = y1 u + y2 (1-u) Will work for any line. Furthermore, says that • 0 <= u <= 1 (x, y) lies between (x1, y1) and (x2, y2) • u < 0 (x, y) lies outside on the side of (x1, y1) • u > 1 (x, y) lies outside on the side of (x2, y2)
  • 16. Line segment clipping Liang-Barsky algorithm ▸Consider the parametric form of a line segment p(a) = (1-a)p1+ ap2 1 ≥ a ≥ 0
  • 17. Liang- Barsky algorithm ▸ We can distinguish between the cases by looking at the ordering of the values of a where the line determined by the line segment crosses the lines that determine the window
  • 18. Polygon clipping ▸Polygons need to be clipped against a rectangular (usually) window. ▸Not as simple as line segment clipping Clipping a line segment yields at most one line segment Clipping a polygon can yield multiple polygons ▸ Sometimes clipped against non-rectangular windows ▸Consider rectangular windows: Convex polygon  Clipped convex polygon (only one) Concave polygon  May result in more than one clipped piece
  • 19. Strategies 1. Brute force 2. Triangulation = Replace nonconvex with convex pieces (Tessellation) 3. Clipping as a Black Box  Pipeline approach 1. Brute Force Straightforward algorithm: Apply Cohen-Surtherland or Liang-Barsky edge by edge
  • 20. 2. Tessellation and Convexity ▸Replace nonconvex (concave) polygons with a set of triangular polygons (a tessellation) ▸Also makes fill easier
  • 21. 3. Black box approach: clipping pipeline ▸Can consider line segment clipping as a process that takes in two vertices and produces either no vertices or the vertices of a clipped line segment  Clipping against each side of window is independent of other sides ▸Can use four independent clippers in a pipeline
  • 23. ▸Polygon can be clipped successively against the boundaries of the window edge by edge
  • 24. Clipping in 3-D ▸Cohen Sutherland in 3D ▸Use 6-bit outcodes ▸When needed, clip line segment against planes
  • 27. What is Rasterization? • This is (almost) the last stage in the viewing pipeline • Produces fragments from the remaining objects and them into discrete representation, in the frame buffer, for display • The resulting objects from the previous transformations are essentially polygons which must now be rasterized, that is, they must be converted to addresses in the buffer and the contents of the address loaded with color/intensity information. • Sometimes called scan conversion
  • 28. Rasterization ▸This scan conversion can be considered from simple to complicated ▸Scan conversion of : ▸Points ▸Lines ▸Polygons
  • 29. Points • The color buffer is n x m array of pixels • The address is now the address of a pixel address (ix, iy) • A color or intensity is now stored in the buffer location corresponding to (ix, iy)  write_pixel (ix, iy, value);
  • 30. Lines • Line L is given by the points in the segment (ix1, iy1) - (ix2, iy2) • These points must be scan converted  rounded/truncated to integer addresses on the screen. • Line scan conversion algorithms • DDA algorithm • Bresenham algorithm
  • 31. Lines • Points on line are obtained from the differential equation dy/dx = m • where m = (y2 – y1) / (x2 – x1) = Δy / Δx 0 ≤ m ≤ 1 ▸Coordinates are integers  pixels generated successively with increments of 1 in the x variable. ▸Change in y = Δy = m Δx ▸Δx always 1  Δy = m for (ix=x; ix <= ix2; ix++) { y += m; write_pixel(x, round (y),line_color); }
  • 32. Ploygons  Inside-Outside Testing - Crossing test = Odd-even test - Winding test (for non-simple polygons)  Fill and Sort - Flood fill - Scanline fill - Odd-even fill
  • 33. Inside-Outside Testing 1) Crossing test = Odd-even test - Let p be a point inside a simple polygon any ray from p must cross an odd number of edges of the polygon - Let p be a point outside a simple polygon any ray from p must cross an even number of edges of the polygon 2) Winding test (for non-simple polygons) - we must decide how to determine whether a given point is inside or outside of the polygon. - Winding Number Count clockwise encirclements of point: odd  inside even  outside
  • 35. Flood fill ▸Fill can be done recursively from an initial point, seed point, located inside the polygon (WHITE) ▸Scan convert edges into buffer in edge/inside color (BLACK) void 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); } }
  • 37. What is hidden- surface removal? • Determines which fragments correspond to objects that are visible. • Those that are in the view volume and are not blocked from view by other objects closer to the camera.

Editor's Notes

  1. Hidden-Surface Removal
  2. Modeling = Process of creating a set of objects making up a scene or a large object
  3. Geometric object = a set of vertices
  4. a = (ymax – y1) / (y2 – y1)