professional documents
home
Upload
docsters
Upload
about me
contact me
user photo
Manuel Arce Garcia
submit clear
Powerpoint

Computer Graphics clipping opengl center doc

1Computer GraphicsClippingFall FCC 2006Line ClippingWhat happens when one or both endpoints of a line segment are not inside the specified drawing area?Draw just the portions of a line (or object)that fall within a given region/window/screen (usually rectangular)DrawingAreaLine Clipping•Strategies for clipping:a)Check (in inner loop)if each point is inside Works, but slowb)Clip invalid coordinate(s) to boundary Incorrect resultsc)Find intersection of line with boundary Correctif (x >= xmin && x <= xmax &&y >= ymin && y <= ymax)drawPoint(x,y,c);if (x < xmin) x = xmin;else if (x > xmax) x = xmax;if (y < ymin) y = ymin;else if (y > ymax) y = ymax;InputOutputClip xClip yClip line tointersectionLine Clipping: Possible Configurations1.Both endpoints are inside the region (line AB)No clipping necessary2.One endpoint in, oneout (line CD)Clip at intersection point3.Both endpoints outsidethe region:a.No intersection (lines EF, GH)b.Line intersects the region (line IJ)-Clip line at both intersection pointsABCDFEIJGHLine Clipping: Cohen-Sutherland•Basic algorithm:Accept (and draw)lines that have both endpoints inside the regionFETrivially rejectABTrivially acceptHCDIJGClip andretestClip the remaining lines at a region boundary and repeat steps 1 and 2 on the clipped line segmentsReject (and don’t draw)lines that have both endpoints less than xminor yminor greater than xmaxor ymaxCohen-Sutherland: Accept/Reject Tests•Assign 4-bit code to each endpoint corresponding to its position relative to region:Firstbit (1000): if y> ymaxSecondbit (0100): if y< yminThirdbit (0010): if x> xmaxFourthbit (0001): if x< xmin•Test:if code0OR code1= 0000accept (draw)else if code0AND code10000reject (don’t draw)else clip and retest010001010110100010011010000100100000Cohen-Sutherland: Line ClippingIntersectionalgorithm:if code00000 then code= code0else code= code1dx= x1–x0; dy= y1–y0if codeAND1000 then begin//ymaxx= x0+ dx* (ymax–y0) /dy; y= ymaxendelse if codeAND0100 then begin//yminx= x0+ dx* (ymin–y0) /dy; y= yminendelse if codeAND0010 then begin//xmaxy= y0+ dy* (xmax–x0) /dx; x= xmaxendelse begin//xminy= y0+ dy* (xmin–x0) /dx; x= xminendif code= code0thenbegin x0= x; y0= y; endelsebegin x1= x; y1= y; end(x1, y1)(x0, y0)ymaxymindxdy(x, y)xminxmaxCohen-Sutherland: Line Clipping ExampleIntersectionalgorithm:if code00000 then code= code0else code= code1dx= x1–x0; dy= y1–y0if codeAND1000 then begin//ymaxx= x0+ dx* (ymax–y0) /dy; y= ymaxendelse if codeAND0100 then begin//yminx= x0+ dx* (ymin–y0) /dy; y= yminendelse if codeAND0010 then begin//xmaxy= y0+ dy* (xmax–x0) /dx; x= xmaxendelse begin//xminy= y0+ dy* (xmin–x0) /dx; x= xminendif code= code0thenbegin x0= x; y0= y; endelsebegin x1= x; y1= y; endCodedxyxdy(x1, y1)(400, 300)Code (1010)(x0, y0)(150, 150)Code (0000)ymax=200ymin=100Xmin= 100xmax = 300Cohen-Sutherland: Line Clipping ExampleIntersectionalgorithm:if code00000 then code= code0else code= code1dx= x1–x0; dy= y1–y0if codeAND1000 then begin//ymaxx= x0+ dx* (ymax–y0) /dy; y= ymaxendelse if codeAND0100 then begin//yminx= x0+ dx* (ymin–y0) /dy; y= yminendelse if codeAND0010 then begin//xmaxy= y0+ dy* (xmax–x0) /dx; x= xmaxendelse begin//xminy= y0+ dy* (xmin–x0) /dx; x= xminendif code= code0thenbegin x0= x; y0= y; endelsebegin x1= x; y1= y; endCodedxyxdy(x1, y1)(400, 300)Code (1010)(x0, y0)(150, 150)Code (0000)ymax=200ymin=100Xmin= 100xmax = 300Cohen-Sutherland: Line Clipping ExampleIntersectionalgorithm:if code00000 then code= code0else code= code1dx= x1–x0; dy= y1–y0if codeAND1000 then begin//ymaxx= x0+ dx* (ymax–y0) /dy; y= ymaxendelse if codeAND0100 then begin//yminx= x0+ dx* (ymin–y0) /dy; y= yminendelse if codeAND0010 then begin//xmaxy= y0+ dy* (xmax–x0) /dx; x= xmaxendelse begin//xminy= y0+ dy* (xmin–x0) /dx; x= xminendif code= code0thenbegin x0= x; y0= y; endelsebegin x1= x; y1= y; endCode1010dxyxdy(x1, y1)(400, 300)Code (1010)(x0, y0)(150, 150)Code (0000)ymax=200ymin=100Xmin= 100xmax = 300Cohen-Sutherland: Line Clipping ExampleIntersectionalgorithm:if code00000 then code= code0else code= code1dx= x1–x0; dy= y1–y0if codeAND1000 then begin//ymaxx= x0+ dx* (ymax–y0) /dy; y= ymaxendelse if codeAND0100 then begin//yminx= x0+ dx* (ymin–y0) /dy; y= yminendelse if codeAND0010 then begin//xmaxy= y0+ dy* (xmax–x0) /dx; x= xmaxendelse begin//xminy= y0+ dy* (xmin–x0) /dx; x= xminendif code= code0thenbegin x0= x; y0= y; endelsebegin x1= x; y1= y; end(x1, y1)(400, 300)Code (1010)(x0, y0)(150, 150)Code (0000)ymax=200ymin=100Xmin= 100xmax = 300Code1010dx250yxdy150Cohen-Sutherland: Line Clipping ExampleIntersectionalgorithm:if code00000 then code= code0else code= code1dx= x1–x0; dy= y1–y0if codeAND1000 then begin//ymaxx= x0+ dx* (ymax–y0) /dy; y= ymaxendelse if codeAND0100 then begin//yminx= x0+ dx* (ymin–y0) /dy; y= yminendelse if codeAND0010 then begin//xmaxy= y0+ dy* (xmax–x0) /dx; x= xmaxendelse begin//xminy= y0+ dy* (xmin–x0) /dx; x= xminendif code= code0thenbegin x0= x; y0= y; endelsebegin x1= x; y1= y; end(x1, y1)(400, 300)Code (1010)(x0, y0)(150, 150)Code (0000)ymax=200ymin=100Xmin= 100xmax = 300Code1010dx250yxdy150Cohen-Sutherland: Line Clipping ExampleIntersectionalgorithm:if code00000 then code= code0else code= code1dx= x1–x0; dy= y1–y0if codeAND1000 then begin//ymaxx= x0+ dx* (ymax–y0) /dy; y= ymaxendelse if codeAND0100 then begin//yminx= x0+ dx* (ymin–y0) /dy; y= yminendelse if codeAND0010 then begin//xmaxy= y0+ dy* (xmax–x0) /dx; x= xmaxendelse begin//xminy= y0+ dy* (xmin–x0) /dx; x= xminendif code= code0thenbegin x0= x; y0= y; endelsebegin x1= x; y1= y; end(x1, y1)(400, 300)Code (1010)(x0, y0)(150, 150)Code (0000)ymax=200ymin=100Xmin= 100xmax = 300Code1010dx250y200x233dy150Cohen-Sutherland: Line Clipping ExampleIntersectionalgorithm:if code00000 then code= code0else code= code1dx= x1–x0; dy= y1–y0if codeAND1000 then begin//ymaxx= x0+ dx* (ymax–y0) /dy; y= ymaxendelse if codeAND0100 then begin//yminx= x0+ dx* (ymin–y0) /dy; y= yminendelse if codeAND0010 then begin//xmaxy= y0+ dy* (xmax–x0) /dx; x= xmaxendelse begin//xminy= y0+ dy* (xmin–x0) /dx; x= xminendif code= code0thenbegin x0= x; y0= y; endelsebegin x1= x; y1= y; end(x1, y1)(400, 300)Code (1010)(x0, y0)(150, 150)Code (0000)ymax=200ymin=100Xmin= 100xmax = 300Code1010dx250y200x233dy150Cohen-Sutherland: Line Clipping ExampleIntersectionalgorithm:if code00000 then code= code0else code= code1dx= x1–x0; dy= y1–y0if codeAND1000 then begin//ymaxx= x0+ dx* (ymax–y0) /dy; y= ymaxendelse if codeAND0100 then begin//yminx= x0+ dx* (ymin–y0) /dy; y= yminendelse if codeAND0010 then begin//xmaxy= y0+ dy* (xmax–x0) /dx; x= xmaxendelse begin//xminy= y0+ dy* (xmin–x0) /dx; x= xminendif code= code0thenbegin x0= x; y0= y; endelsebegin x1= x; y1= y; end(x1, y1)(400, 300)Code (1010)(x0, y0)(150, 150)Code (0000)ymax=200ymin=100Xmin= 100xmax = 300Code1010dx250y200x233dy150Cohen-Sutherland: Line Clipping Summary1.Chooseanendpointoutsidetheclippingregion2.Usingaconsistentordering(toptobottom,lefttoright)findaclippingborderthelineintersects3.Discardtheportionofthelinefromtheendpointtotheintersectionpoint4.Setthenewlinetohaveasendpointsthenewintersectionpointandtheotheroriginalendpoint5.Youmayneedtorunthisseveraltimesonasingleline(e.g.,alinethatcrossesmultipleclipboundaries)Cohen-Sutherland Line Clip ExamplesABEFGHCDIJA 0001B 0100OR 0101AND 0000subdivideC 0000D 0010OR 0010AND 0000subdivideE 0000F 0000OR 0000AND 0000acceptG 0000H 1010OR 1010AND 0000subdivideI 0110J 0010OR 0110AND 0010reject010001010110100010011010000100100000Cohen-Sutherland Line Clip ExamplesABGHCDA 0001A’ 0001removeA’G’C’A’ 0001B 0100OR 0101AND 0000subdivideC 0000C’ 0000OR 0000AND 0000acceptC’ 0000D 1010removeG 0000G’ 0000OR 0000AND 0000acceptG’ 0000H 1010remove010001010110100010011010000100100000Cohen-Sutherland Line Clip ExamplesB’BA’ 0001B’ 0100removeA’B’ 0100B 0100OR 0100AND 0100reject010001010110100010011010000100100000Polygon ClippingWhat about polygons?For concave polygons, the intersectionwith the clipping region may be complexPolygon Clipping: Algorithm•Clip polygon to yminand ymax:Create empty output vertex list (listout= empty)Process input list (listin= (v0, v1, …, vn) where v0= vn)in orderFor each input vertex (viwhere 0 in–1):-If viis inside region Add vito end oflistout-If the line between viand vi+1intersects specified boundaries Add intersection point(s) to end oflistout•Repeat: clipping to xminand xmax•Post-process:Find “degenerate” sections where both sides of polygon has collapsed to region boundaryRemove those sections Create new polygonPolygon Clipping: ExampleClip first to yminand ymaxyminymaxv0v1v2v3v4v5v6v7v8v9Input vertex list:(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)vertex:v0inside region: noadd p0to output listOutput vertex list:p0line intersect boundary: yes(p0)Polygon Clipping: ExampleClip first to yminand ymaxyminymaxv0v1v2v3v4v5v6v7v8v9Input vertex list:(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)vertex:v1inside region: yesadd v1to output listOutput vertex list:p0line intersect boundary: no(p0, v1)Polygon Clipping: ExampleClip first to yminand ymaxyminymaxv0v1v2v3v4v5v6v7v8v9Input vertex list:(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)vertex:v2inside region: yesadd v2, p1to output listOutput vertex list:p0(p0, v1, v2, p1)line intersect boundary: yesp1Polygon Clipping: ExampleClip first to yminand ymaxyminymaxv0v1v2v3v4v5v6v7v8v9Input vertex list:(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)vertex:v3inside region: noOutput vertex list:p0(p0, v1, v2, p1)line intersect boundary: nop1Polygon Clipping: ExampleClip first to yminand ymaxyminymaxv0v1v2v3v4v5v6v7v8v9Input vertex list:(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)vertex:v4inside region: noadd p2to output listOutput vertex list:p0(p0, v1, v2, p1, p2)p1line intersect boundary: yesp2Polygon Clipping: ExampleClip first to yminand ymaxyminymaxv0v1v2v3v4v5v6v7v8v9Input vertex list:(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)vertex:v5inside region: yesadd v5, p3to output listOutput vertex list:p0(p0, v1, v2, p1, p2, v5, p3)p1p2line intersect boundary: yesp3Polygon Clipping: ExampleClip first to yminand ymaxyminymaxv0v1v2v3v4v5v6v7v8v9Input vertex list:(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)vertex:v6inside region: noOutput vertex list:p0(p0, v1, v2, p1, p2, v5, p3)p1p2line intersect boundary: nop3Polygon Clipping: ExampleClip first to yminand ymaxyminymaxv0v1v2v3v4v5v6v7v8v9Input vertex list:(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)vertex:v7inside region: noOutput vertex list:p0(p0, v1, v2, p1, p2, v5, p3)p1p2line intersect boundary: nop3Polygon Clipping: ExampleClip first to yminand ymaxyminymaxv0v1v2v3v4v5v6v7v8v9Input vertex list:(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)vertex:v8inside region: noadd p4to output listOutput vertex list:p0(p0, v1, v2, p1, p2, v5, p3, p4)p1p2p3line intersect boundary: yesp4Polygon Clipping: ExampleClip first to yminand ymaxyminymaxv0v1v2v3v4v5v6v7v8v9Input vertex list:(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)vertex:v9inside region: yesadd v9, p5to output listOutput vertex list:p0(p0, v1, v2, p1, p2, v5, p3, p4, v9, p5)p1p2p3p4line intersect boundary: yesp5Polygon Clipping: ExampleThis gives us a new polygonyminymaxv1v2v5v9with vertices:p0(p0, v1, v2, p1, p2, v5, p3, p4, v9, p5)p1p2p3p4p5Polygon Clipping: Example (cont.)Now clip to xminand xmaxxminxmaxInput vertex list:= (p0, v1, v2, p1, p2, v5, p3, p4, v9, p5)Output vertex list:(p0, p6, p7, v2, p1, p8, p9, p3, p4, v9, p5)v1v2v5v9p0p1p2p3p4p5p6p7p8p9Polygon Clipping: Example (cont.)Now post-processxminxmaxv9v3Output vertex list:(p0, p6, p7, v2, p1, p8, p9, p3, p4, v9, p5)Post-process:(p0, p6, p9, p3,) and (p7, v2, p1, p8) and (v4, v9, p5)p8p6v2p7p0p5p3p4p9p1Polygon OrientationpositiveNegativeABCDELRAEDCBLRLeft o RightLet A(x1,y1) and B(x2,y2) end points of a line. A point P(x,y) will be to the leftof the line segment if the expresion C= (x2-x1)*(y-y1)-(y2-y1)*(x-x1)is positive. We say the point is to the rightif C is negative.If P is to the right, it is outside the PolygonIf P is to the left, it is inside the Polygon
rate this doc
email this doc
embed this doc
add to folder
digg reddit stumble delicious
flag this doc
376
25
not rated
0
12/10/2007
English
Preview

Computer Animation

arcenal 12/10/2007 | 558 | 37 | 0 | educational
Preview

Computer Animation with Scripts and Actors

arcenal 12/10/2007 | 327 | 22 | 0 | educational
Preview

artificial life for computer graphics

arcenal 12/10/2007 | 313 | 22 | 0 | educational
Preview

open gl - advanced graphics programming techniques using OpenGL

arcenal 12/24/2007 | 1675 | 72 | 0 | educational
Preview

real time interactive graphics for computer gaming

arcenal 12/24/2007 | 253 | 13 | 0 | educational
Preview

CSC470 Computer Graphics

StarBoy 11/7/2007 | 94 | 3 | 0 | educational
Preview

Principles of traditional animation aplied to 3D computer animation

arcenal 12/24/2007 | 304 | 27 | 0 | educational
Preview

The OpenGL Graphics System a specification

arcenal 12/29/2007 | 283 | 28 | 0 | educational
Preview

The OpenGL Shading Language

arcenal 12/29/2007 | 251 | 25 | 0 | educational
Preview

The OpenGL Specification 2.1

arcenal 12/29/2007 | 266 | 13 | 0 | educational
Preview

Silicon Graphics 2006 Annual Report

AnnualReports 2/12/2008 | 76 | 1 | 0 | financial
Preview

Graphic design computer graphics and design methodology

samc 6/30/2008 | 69 | 1 | 0 | creative
Preview

kw_Computer_Animation

StarBoy 11/7/2007 | 85 | 1 | 0 | technology
Preview

brief history of computer

PastorGallo 7/23/2008 | 139 | 1 | 0 | legal
Preview

Make A Computer

faridudheen 6/17/2008 | 117 | 18 | 0 | technology
Preview

automatas de pila y lenguajesd independientes de contexto

arcenal 8/13/2008 | 49 | 3 | 0 |
Preview

Apuntes de analisis numerico

arcenal 2/9/2008 | 1381 | 112 | 3 | educational
Preview

manual de matlab 7 0 español

arcenal 2/9/2008 | 12764 | 388 | 9 | educational
Preview

criptografia y seguridad

arcenal 2/9/2008 | 1848 | 99 | 3 | educational
Preview

criptografia-matematicas

arcenal 2/9/2008 | 1068 | 79 | 0 | educational
Preview

norma rs232

arcenal 2/9/2008 | 2187 | 50 | 0 | educational
Preview

cienematica de un robot

arcenal 2/9/2008 | 882 | 33 | 0 | educational
Preview

topologia

arcenal 1/2/2008 | 218 | 2 | 0 | educational
Preview

Teoria y praxis - EMMANUEL KANT

arcenal 1/2/2008 | 1054 | 8 | 0 | educational
Preview

Romero y julieta - Willian Shakespeare

arcenal 1/2/2008 | 1483 | 6 | 0 | educational
 
review this doc