Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Examples of Clipping - Introduction to Computer Graphics - Lecture Slides, Slides of Computer Graphics

In Introduction to Computer Graphics course we study the basic concept of the principle of computer architecture. In these lecture slides the key points are:Examples of Clipping, Computer Graphics, Line Clipping, Simultaneous Equations, Trivial Acceptance, Parametric Line Formulation, Cohen-Sutherland Line Clipping, Cohen-Sutherland Algorithm, Rubikโ€™s Cube

Typology: Slides

2012/2013

Uploaded on 04/23/2013

sarasvan
sarasvan ๐Ÿ‡ฎ๐Ÿ‡ณ

4.4

(20)

120 documents

1 / 20

Related documents


Partial preview of the text

Download Examples of Clipping - Introduction to Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity! Lecture 15: Clipping Docsity.com Clipping โ€ข Last week we discussed some simple examples of clipping in Camera โ€“ We said that OpenGL takes care of a lot of that for free โ€ข But clipping is an important part of computer graphics: Docsity.com Clip Rectangle Cohen-Sutherland Line Clipping in 2D โ€ข Divide plane into 9 regions โ€ข Compute the sign bit of 4 comparisons between a vertex and a clip edge โ€“ (๐‘ฆ๐‘š๐‘Ž๐‘ฅ โˆ’ ๐‘ฆ, ๐‘ฆ โˆ’ ๐‘ฆ๐‘š๐‘–๐‘›, ๐‘ฅ๐‘š๐‘Ž๐‘ฅ โˆ’ ๐‘ฅ; ๐‘ฅ โˆ’ ๐‘ฅ๐‘š๐‘–๐‘›), cast the results to 0 or 1 โ€“ Point lines inside the region if all four bits are 0 ๏ฝ 4 bit outcode records results of four bounds tests: ๏ฝ 1st bit: outside halfplane of top edge (above top edge) ๏ฝ 2nd bit: outside halfplane of bottom edge ๏ฝ 3rd bit: outside halfplane of right edge ๏ฝ 4th bit: outside halfplane of left edge ๏ฝ Compute outcodes for both vertices of the input edge, denoted ๐‘‚๐ถ0 and ๐‘‚๐ถ1 ๏ฝ If ๐‘‚๐ถ0 = 0 and ๐‘‚๐ถ1 = 0, (i.e., outcode: 0000), then the input edge is trivially accepted ๏ฝ Lines lying entirely in a particular halfplane can e trivially rejected. That is ๐‘‚๐ถ0 ๐ด๐‘๐ท ๐‘‚๐ถ1 โ‰  0 (i.e., they share an โ€œoutside bitโ€) Docsity.com Cohen-Sutherland Algorithm โ€ข If we can neither trivially accept or reject, then we do divide-and-conquer โ€ข Subdivide line into two segments and test again Clip rectangle D C B A E F G H I ๏ฝ Use a clip edge to cut line ๏ฝ Use outcodes to choose which edge is crossed ๏ฝ The bits that are different between outcodes will tell us which edge to examine ๏ฝ Pick an order for checking edges: top โ€“ bottom โ€“ right โ€“ left ๏ฝ Compute the intersection point ๏ฝ Clip edge will be axis-aligned, so we can fix either the x or the y ๏ฝ Can substitute into the line equation ๏ฝ Iterate for the newly created line segment, might need multiple passes (e.g., E-I at H) Docsity.com Cohen-Sutherland Algorithm โ€ข Assumes the form: โ€“ ๐‘ฆ = ๐‘ฆ0 + ๐‘ ๐‘™๐‘œ๐‘๐‘’ โˆ— (๐‘ฅ โ€“ ๐‘ฅ0) โ€“ ๐‘ฅ = ๐‘ฅ0 + (1/๐‘ ๐‘™๐‘œ๐‘๐‘’) โˆ— (๐‘ฆ โˆ’ ๐‘ฆ0) Algorithm (float x0, y0, x1, y1) ComputeOutCode(x0, y0, outcode0); ComputeOutCode(x1, y1, outcode1); repeat check for trivial reject or trivial accept pick the point that is outside the clip rectangle if TOP then x = x0 + (x1 โ€“ x0) * (ymax โ€“ y0)/(y1 โ€“ y0); y = ymax; else if BOTTOM then x = x0 + (x1 โ€“ x0) * (ymin โ€“ y0)/(y1 โ€“ y0); y = ymin; else if RIGHT then y = y0 + (y1 โ€“ y0) * (xmax โ€“ x0)/(x1 โ€“ x0); x = xmax; else if LEFT then y = y0 + (y1 โ€“ y0) * (xmin โ€“ x0)/(x1 โ€“ x0); x = xmin; if (x0, y0 is the outer point) then x0 = x; y0 = y; ComputeOutCode(x0, y0, outcode0) else x1 = x; y1 = y; ComputeOutCode(x1, y1, outcode1) until done DrawRectangle(xmin, ymin, xmax, ymax) DrawLine (x0, y0, x1, y1) Docsity.com Cyrus-Beck / Liang-Barsky Parametric Line Clipping โ€ข Use the parametric line formulation: โ€“ ๐‘ƒ(๐‘ก) = ๐‘ƒ0 + ๐‘ก(๐‘ƒ1 โˆ’ ๐‘ƒ0) โ€ข Determine if the line intersects with a clip line (both extended to infinity) โ€ข Decide if the intersection actually occurs on the polygon โ€ข This is a very similar strategy for intersection tests in ray-tracing Docsity.com Parametric Line Clipping โ€ข Uses the relationship between the Normal of the clipping edge and points on the line to be clipped โ€ข Given the normal ๐‘๐‘– and any point ๐‘ƒ๐ธ๐‘– on edge ๐ธ๐‘– Docsity.com Parametric Line Clipping, Using Dot Product โ€ข Find t โ€“ Note that if t is less than 0 or greater than 1, then the intersection occurs outside of the line segment Docsity.com Parametric Line Clipping, Against A Polygon โ€ข When applied to line-clipping, there will be multiple t values (a t value for each clip edge test) โ€“ Eliminate t values outside of [0, 1] โ€“ Determine if the intersection is considered potentially entering (PE) or potentially leaving (PL) โ€ข Problem, how can you tell?? PE PL Docsity.com Parametric Line Clipping, Against A Polygon โ€ข Turns out: โ€“ if (Ni โ€ข D) < 0 => Potentially Entering (PE), if (Ni โ€ข D) > 0 => Potentially Leaving (PL) โ€ข Remember, D = (๐‘ƒ1 โˆ’ ๐‘ƒ0) โ€ข Pick the inner most pair of PE and PL โ€“ Traverse from P0 to P1: โ€ข If we encounter a PL before a PE, there is no intersection (see Line 2) โ€ข Otherwise, pick PE with the max t, and PL with the min t โ€ข Note that t must be between [0, 1] Docsity.com Pseudocode Pre-calculate Ni and select PEi for each edge; for each line segment to be clipped if P1 = P0 then line is degenerate so clip as a point; else begin tE = 0; tL = 1; for each candidate intersection with a clip edge if Ni โ€ข D ๏‚น 0 then {Ignore edges parallel to line} begin calculate t; {of line and clip edge intersection} use sign of Ni โ€ข D to categorize as PE or PL; if PE then tE = max(tE,t); if PL then tL = min(tL,t); end if tE > tL then return nil else return P(tE) and P(tL) as true clip intersections end Docsity.com
Docsity logo



Copyright ยฉ 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved