Line clipping: Line clipping algorithm is method of eliminate lines of outside area of the object,so outside of object viewing is Removed. Typically, any.

Slides:



Advertisements
Similar presentations
9.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 9 – Clipping.
Advertisements

CGPage: 1 We can define a window as a rectangular region of the world coordinate space, and the viewport as a rectangular region of the device coordinate.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Clipping Concepts, Algorithms for line clipping 1 of 16 Clipping - 10/16/12.
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam September 30, D Clipping 1/14 Clipping (pages , )
Computer Graphics CLIPPING.
Objectives Define Clipping Various clipping methods. Line clipping methods.
Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)
Clipping Lines Lecture 7 Wed, Sep 10, The Graphics Pipeline From time to time we will discuss the graphics pipeline. The graphics pipeline is the.
Clipping CSE 403 Computer Graphics Cohen Sutherland Algorithm (Line)
CGPage: 1 東吳資訊科學 江清水 The process of clipping decides which part, if any, of a primitive lies inside the window. The algorithms used for line clipping can.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 Computer Graphics Chapter 4 2D Viewing Algorithms.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
University College Dublin1 Clipping u Clipping is the removal of all objects or part of objects in a modelled scene that are outside the real-world window.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
2-Dimension Viewing and Clipping
Windowing and clipping
Clipping: Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
Windows, Viewports, and Clipping
1 Computer Graphics Clipping Fall FCC Line Clipping What happens when one or both endpoints of a line segment are not inside the specified drawing.
Computer Graphics Lecture 20 Fasih ur Rehman. Last Class Clipping – What is clipping – Why we do clipping – How clipping is done.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Clipping Primitives. Clipping line Clipping rectangle: – x min to x max – y min to y max A point (x,y) lies within a clip rectangle and thus displayed.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
Clipping. Before clipping… After clipping… Point Clipping Display P = (x, y) if xw min
1 U08181 Computer Graphics Clipping Transformations –Transformations and matrices –Homogeneous matrices –Transformations in SVG.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
CENG 538 Advanced Graphics and UIs
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphic 2 D Viewing.
Computer Graphics Clipping.
Introduction to Computer Graphics with WebGL
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
Concepts, Algorithms for line clipping
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006
2D Viewing & Clipping 한신대 류승택
Concepts, algorithms for clipping
Implementation I Ed Angel
Graphics Pipeline Clipping
WINDOWING AND CLIPPING
Computer Graphics : Viewing In 2D
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
WINDOWING AND CLIPPING
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Joshua Barczak CMSC 435 UMBC
Two Dimensional Viewing and Clipping.
Segment Clipping Simple algorithm. For each segment compute the intersection with the four sides of the rectangle, and then determine which sub-segment.
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Clipping Clipping Sutherland-Hodgman Clipping
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation I Ed Angel Professor Emeritus of Computer Science
CS U540 Computer Graphics Prof. Harriet Fell Spring 2007
Presentation transcript:

Line clipping: Line clipping algorithm is method of eliminate lines of outside area of the object,so outside of object viewing is Removed. Typically, any line or part thereof which is outside of the viewing area is removed. Cohen-Sutherland line clipping algorithm: The Cohen- Sutherland algorithm is a line clipping algorithm. The algorithm divides a 2D space into 9 parts, of which only the middle part (viewport) is visible.line clipping First we test whether both endpoints are inside (and hence draw the line segment) or whether both are left of, right of, below, or above (then we ignore line segment). Otherwise we split the line segment into two pieces at a clipping edge (and thus reject one part). Now we proceed iteratively. A rather simple accept-reject test is the following: Line clipping

Divide the plane into 9 regions and assign a 4 bit code to each: above top edge below bottom edge right of right edge left of left edge math calculate the corresponding bit-codes for both endpoints. Figure: Codes for the 9 regions associated to clipping rectangle If both codes are zero then the line segment is completely inside the rectangle. If the bitwise-and of these codes is not zero then the line does not hit since both endpoints lie on the wrong side of at least one boundary line (corresponding to a bit equal to 1). Otherwise take a line which is met by the segment (for this find one non-zero bit), divide the given line at the intersection point in two parts and reject the one lying in the outside halfplane. bit 4bit 3bit 2bit 1

Cohen-Sutherland line clipping

Flowchart : Line clipping start int driver, mode; float i,xmax,ymax,xmin,ymin,x11,y11,x22,y22,m; float a[4],b[4],c[4],x1,y1; input xmin,ymin,xmax,ymax,x11,y11,x22,y22; detectgraph(&driver,&mode); initgraph(&driver,&mode,”\\BGI”); rectangle(xmin,ymin,xmax,ymax); line(x11,y11,x22,y22); i=0 if(i<4) a[i]=0; b[i]=0; i++ m=( y22-y11)/(x22-x11) true false

if(x11<xmin) a[3]=1 if(x11>xmax) a[2]=1 if(y11<ymin) a[1]=1 if(y11>ymax) a[0]=1 if(x22<xmin) b[3]=1 true false

if(x22>xmax) b[2]=1 if(y22<ymin) b[1]=1 if(y22>ymax) b[0]=1 i=0 if(i<4) a[i] i++ i=0 if(i<4) b[i] i++ true false true

i=0 if(i<4) c[i] = a[i]&&b[i] i++ i=0 if(i<4) c[i] if((c[0]==0)&&(c[1]==0)&&(c[2]==0)&&(c[3]==0)) i++ if((a[0]==0)&&(a[1]==0)&&(a[2]==0)&&(a[3]==0)&& (b[0]==0)&&(b[1]==0)&&(b[2]==0)&&(b[3]==0)) true false true false true line is totally visible and not a clipping candidate go to block-2 line is partially visible go to block-1 line is invisible rectangle(xmin, ymin,xmax,ymax) go to block-3

rectangle(xmin,ymin,xmax,ymax) line(x11,y11,x22,y22) rectangle(xmin,ymin,xmax,ymax) line(x11,y11,x22,y22) if(a[0]==0&&a[1]=1) x1=x11+(ymin-y11)/m x11=x1 y11=ymin if(b[0]==0&&b[1]==1) x1=x22+(ymin-y22)/m x22=x1 y22=ymin false true block-2 block-1 true false if((a[0]==1)&&(a[1]==0)) x1=x11+(ymax-y11)/m x11=x1 y11=ymax true else if(b[0]==1&&b[1]==0) x1=x22+(ymax-y22)/m x22=x1 y22=ymax false true go to block-3

if((a[2]==0)&&(a[3]==1)) y1=y11+(m*(xmin-x11)) y11=y1 x11=xmin if(b[2]==0&&b[3]==1) y1=y22+(m*(xmin-x22)) y22=y1 x22=xmin false true if((a[2]==1)&&(a[3]==0)) y1=y11+(m*(xmax-x11)) y11=y1 x11=xmax if(b[2]==1&&b[3]==0) y1=y22+(m*(xmax-x22)) y22=y1 x22=xmax false true

after clipping rectangle(xmin,ymin,xmax,ymax ) line(x11,y11,x22,y22 ) getch(); output stop block-3

Program: /*Cohen-Sutherland line clipping program to clip the line outside the window boundary*/ #include void main() { int gd=DETECT, gm; float i,xmax,ymax,xmin,ymin,x11,y11,x22,y22,m; float a[4],b[4],c[4],x1,y1; clrscr(); initgraph(&gd,&gm,"c:\\tc\\bgi"); printf("\nEnter the bottom-left coordinate of viewport: "); scanf("%f %f",&xmin,&ymin); printf("\nEnter the top-right coordinate of viewport: "); scanf("%f %f",&xmax,&ymax); rectangle(xmin,ymin,xmax,ymax); printf("\nEnter the coordinates of 1st end point of line: "); scanf("%f %f",&x11,&y11); printf("\nEnter the coordinates of 2nd endpoint of line: "); scanf("%f %f",&x22,&y22);

line(x11,y11,x22,y22); //initgraph(&gd,&gm,"c:\\tc\\bin"); for(i=0;i<4;i++) { a[i]=0; b[i]=0; } m=(y22-y11)/(x22-x11); if(x11<xmin) a[3]=1; if(x11>xmax) a[2]=1; if(y11<ymin) a[1]=1; if(y11>ymax) a[0]=1; if(x22<xmin) b[3]=1; if(x22>xmax) b[2]=1; if(y22<ymin) b[1]=1; if(y22>ymax) b[0]=1; printf("\nRegion code of 1st pt "); for(i=0;i<4;i++) { printf("%f",a[i]);} printf("\nRegion code of 2nd pt "); for(i=0;i<4;i++) { printf("%f",b[i]);} printf("\nAnding : ");

for(i=0;i<4;i++) { c[i]=a[i]&&b[i];} for(i=0;i<4;i++) printf("%f",c[i]); getch(); if((c[0]==0)&&(c[1]==0)&&(c[2]==0)&&(c[3]==0)) { if((a[0]==0)&&(a[1]==0)&&(a[2]==0)&&(a[3]==0)&& (b[0]==0)&&(b[1]==0)&&(b[2]==0)&&(b[3]==0)) { clrscr(); clearviewport(); printf("\nThe line is totally visible\n and not a clipping candidate"); rectangle(xmin,ymin,xmax,ymax); line(x11,y11,x22,y22); getch(); } else { clrscr(); clearviewport(); printf("\nLine is partially visible"); rectangle(xmin,ymin,xmax,ymax); line(x11,y11,x22,y22);

getch(); if((a[0]==0)&&(a[1]==1)) { x1=x11+(ymin-y11)/m; x11=x1; y11=ymin; } else if((b[0]==0)&&(b[1]==1)) { x1=x22+(ymin-y22)/m; x22=x1; y22=ymin; } if((a[0]==1)&&(a[1]==0)) { x1=x11+(ymax-y11)/m; x11=x1; y11=ymax; } else if((b[0]==1)&&(b[1]==0)) { x1=x22+(ymax-y22)/m; x22=x1; y22=ymax; } if((a[2]==0)&&(a[3]==1)) { y1=y11+(m*(xmin-x11)); y11=y1; x11=xmin; }

else if((b[2]==0)&&(b[3]==1)) { y1=y22+(m*(xmin-x22)); y22=y1; x22=xmin; } if((a[2]==1)&&(a[3]==0)) { y1=y11+(m*(xmax-x11)); y11=y1; x11=xmax; } else if((b[2]==1)&&(b[3]==0)) { y1=y22+(m*(xmax-x22)); y22=y1; x22=xmax; } clrscr(); clearviewport(); printf("\nAfter clippling:"); rectangle(xmin,ymin,xmax,ymax); line(x11,y11,x22,y22); getch(); }

else { clrscr(); clearviewport(); printf("\nLine is invisible"); rectangle(xmin,ymin,xmax,ymax); getch(); } closegraph(); getch(); } Output of the above listed program