22
HIDDEN LINE REMOVAL ALGORITHM COMPUTER GRAPHICS FOR CAD/CAM SUBMITTED BY : JYOTIRAMAN DE M TECH (CAD/CAM) 2014-15 TAE I DEPARTMENT OF MECHANICAL ENGINEERING

Computer Graphics - Hidden Line Removal Algorithm

Embed Size (px)

Citation preview

Page 1: Computer Graphics - Hidden Line Removal Algorithm

HIDDEN LINE REMOVAL ALGORITHM

COMPUTER GRAPHICS FOR CAD/CAM

SUBMITTED BY: JYOTIRAMAN DE

M TECH (CAD/CAM)

2014-15TAE I

DEPARTMENT OF MECHANICAL ENGINEERING

Page 2: Computer Graphics - Hidden Line Removal Algorithm

Problem:Given a scene and a projection, what can we see?

Page 3: Computer Graphics - Hidden Line Removal Algorithm

Two main types of algorithms:

Object space: Determine which part of the object are visible. Also called as World Coordinates

Image space: Determine per pixel which point of an object is visible. Also called as Screen Coordinates

Object space Image space

Page 4: Computer Graphics - Hidden Line Removal Algorithm

Two main Hidden Surface Removal Algorithm Techniques:

Object space: Hidden Surface Removal for all objects

Image space: Objects: 3 D Clipping Transformed to Screen Coordinates Hidden Surface Removal

Page 5: Computer Graphics - Hidden Line Removal Algorithm

ALGORITHMS WE ARE GOING TO DISCUSS:

• Z-buffer method

• Scan-line method

• Spanning scan-line method

• Floating horizon method

• Discrete data method

Page 6: Computer Graphics - Hidden Line Removal Algorithm

Z-BUFFER ALGORITHM:

• Its an extension of Frame Buffer• Display is always stored on Frame Buffer• Frame Buffer stores information of each and every

pixel on the screen• Bits (0, 1) decide that the pixel will be ON or OFF

• Z- Buffer apart from Frame buffer stores the depth of pixel

• After analyzing the data of the overlapping polygons, pixel closer to the eye will be updated

• Resolution of X,Y => Array[X,Y]

Page 7: Computer Graphics - Hidden Line Removal Algorithm

Given set of polygon in image spaceZ-Buffer Algorithm:

1. Set the frame buffer & Z-Buffer to a background value

(Z-BUFFER=Zmin) where, Zmin is value

To display polygon decide=>color, intensity and depth2. Scan convert each polygon i.e, for each pixel, find depth at that point If Z(X,Y)>Z-BUFFER(X,Y) Update Z-BUFFER(X,Y)=Z(X,Y) & FRAME BUFFERThis process will repeat for each pixel

Page 8: Computer Graphics - Hidden Line Removal Algorithm

• By this way we can remove hidden lines and display those polygons which are closer to eye

• X*Y space required to maintain Z-Buffer=> X*Y times will be scanned

• Expensive in terms of time and space as space is very large

x

z display

S

S’x

y S

S’

Page 9: Computer Graphics - Hidden Line Removal Algorithm

Pseudocode for the z-buffer algorithm

void zBuffer(void){ int x,y;

for(y=0;y<YMAX;y++) { /*Clear frame buffer and z-buffer*/ for(x=0;x<XMAX;x++) {

WritePixel(x,y,BACKGROUND_VALUE); WriteZ(x,y,0);}

} for(each polygon) { /*Draw Polygons*/ for(each pixel in polygons projection) {

double pz=polygons z-value at pixel coords(x,y);if(pz>=ReadZ(x,y)) { /*New point is not farther*/ WriteZ(x,y,pz); WritePixel(x,y,polygons color at pixel coords(x,y));}

} } }

Page 10: Computer Graphics - Hidden Line Removal Algorithm

SCAN LINE Z-BUFFER ALGORITHM:

• An image space method for identifying visible surfaces

• Computes and compares depth values along the various scan-lines for a scene

Page 11: Computer Graphics - Hidden Line Removal Algorithm

• Scanning takes place row by row

• To facilitate the search for surfaces crossing a given scan-line an active list of edges is formed for each scan-line as it is processed

• The active list stores only those edges that cross the scan-line in order of increasing x

• Pixel positions across each scan-line are processed from left to right

• We only need to perform depth calculations

• In Scan Line, Z-Buffer(X) whereas earlier it was X*Y

Page 12: Computer Graphics - Hidden Line Removal Algorithm

Use Z-Buffer for only 1 scan line / 1 row of pixel

• During scan conversion in the Active Edge List(AEL)=> Calculate Z(X,Y)

i.e, -Pixel info between 1 & 2 active edges will only be stored -Next pixel will be stored as z=z1+∆z -∆z will be constant but can change anywhere in case of slope

• If Z(X,Y)>Z BUFFER(X) => Update

• If 2 polygons are present-along with Active Edge List, Active Polygon List will also be included

• Active Polygon List=> List of polygons intersecting a scan line

Page 13: Computer Graphics - Hidden Line Removal Algorithm

Pseudocode for the general scan line algorithm

Add surfaces to surface table;Initialize active-surface table;

for(each scan line) { update active-surface table;

for(each pixel on scan line) {

determine surfaces in active-surface table that project to pixel; find closest such surface; determine closest surface’s shade at pixel;

}}

Page 14: Computer Graphics - Hidden Line Removal Algorithm

SPANNING SCAN LINE Z-BUFFER ALGORITHM:

• Z-Buffer is not applicable

• Scan conversion is not done

• Speed increases

Page 15: Computer Graphics - Hidden Line Removal Algorithm

1 2 3 4 5 6

Each span at most one polygon shall be displayed

• For each polygon determine the highest scan line intersected by it

• Place the polygon in the Y-Bucket of that scan line [YB]

• For each scan line -Examine YB for any new polygon -Add new polygon to APL -Update AEL -Divide into spans -In each span decide which polygon shall be displayed -Increment Y, update AEL & APL

Page 16: Computer Graphics - Hidden Line Removal Algorithm

FLOATING HORIZON ALGORITHM:

• Used for displaying surface

• Take each plane & intersection z=constant plane and get a curve from F(x,y)=0 f(x,y,z)=0

Array HORIZONTAL[X]=Ymax

Curve in each plane=>f(x,y)=0y=f(x,y)z=constant curvesFamily of curves

Page 17: Computer Graphics - Hidden Line Removal Algorithm

1. Sort all curves as per z-coordinates

2. Start by z=constant curve closest to eye - If at any x-value Y=f(x,y) Y<HORIZON(X)-curve is hidden - If Y>HORIZON(X)-curve is visible & update HORIZON(X)=Y - If Y<HORIZON-L(X) : curve is visible & update HORIZON L(X)=Y - If Y>HORIZON-U(X) : HORIZON U(X)=Y

Page 18: Computer Graphics - Hidden Line Removal Algorithm

• Above Algorithm are applied on surfaces which is in the form of mathematical equation

• If this curve is not a mathematical equation like this but it is a set of discrete data points then this algorithm might not be directly useful

Page 19: Computer Graphics - Hidden Line Removal Algorithm

• Maintain HORIZON[X] at each side

• While displaying next curve, it will be compared to 2 points i.e, Y(Xi) & Y(Xi+1)

• If both points are visible, then the complete curve is visible

• Algorithm will be complex as the curve is in discrete data form

Y(Xi) Y(Xi+1) Result

V V Curve is visible

V I Xi to Intersection -> VisibleIntersection to Xi+1 -> NOT Visible

I V Xi to Intersection -> NOT VisibleIntersection to Xi+1 -> Visible

I I NOT Visible

Page 20: Computer Graphics - Hidden Line Removal Algorithm

SUMMARY

• We need to make sure that we only draw visible surfaces when rendering scenes

• There are a number of techniques for doing this such as– Z-buffer method– Scan-line method– Spanning scan-line method– Floating horizon method– Discrete data method

Page 21: Computer Graphics - Hidden Line Removal Algorithm

REFERENCES• NPTEL Video Lectures: CAD by Dr. Anoop Chawla, Dept. of

Mechanical Engineering, Indian Institute of Technology, Delhi, Lecture No. # 12,13,14

• Ibrahim Zeid, “CAD/CAM” TMH

• Hoschek J, Dieter L, “Fundamentals of Computer Aided Geometric Design ”, A K Peters, 1997

• Rogers D F I and Adams J A, “Mathematical Elements for Computer Graphics”, McGraw-Hill, 1996

• J.H. Hughes, J.D.F., A.V.M., S.K.F., “Computer Graphics Principles And Practice”, Pearson Education Asia,2001

Page 22: Computer Graphics - Hidden Line Removal Algorithm

THANK YOU!!!