+ All Categories
Home > Documents > 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care...

10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care...

Date post: 17-Jan-2016
Category:
Upload: buddy-anderson
View: 220 times
Download: 0 times
Share this document with a friend
Popular Tags:
22
10/19/04 © University of Wisconsin, CS559 F all 2004 Last Time • Clipping Why we care – Sutherland-Hodgman – Cohen-Sutherland Intuition for Liang-Barsky Homework 4, due Oct 26 in class
Transcript
Page 1: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Last Time

• Clipping– Why we care

– Sutherland-Hodgman

– Cohen-Sutherland

– Intuition for Liang-Barsky

• Homework 4, due Oct 26 in class

Page 2: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Midterm Info

• October 28 in class

• All material listed in online “to-know” list

• Allowed:– Pencil/pen, ruler

– One sheet of letter (standard) sized paper, with anything on it, both sides

• Nothing to increase the surface area

• Not allowed:– Calculator, anything else

Page 3: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Today

• Liang-Barsky Details

• Weiler-Atherton clipping algorithm

• Drawing points and lines

Page 4: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Liang-Barsky Intuition

• To be inside the clip region, you must have entered every clip edge before you have left any clip edge

Enter Enter

Leave Leave

Enter

LeaveEnter

Leave

Page 5: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

When are we Inside?

• We want parameter values that are inside all the clip planes

• Last parameter value to enter is the start of the visible segment

• First parameter value to leave is the end of the visible segment

• If we leave some clip plane before we enter another, we cannot see any part of the line– First to leave will be before last to enter

• All this leads to an algorithm – Liang-Barsky

Page 6: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Liang-Barsky Sub-Tasks

1. Find parametric intersection points– Parameter values where line crosses each clip edge/plane

2. Find entering/leaving flags– For every clip edge/plane, are either entering or leaving

3. Find last parameter to enter, and first one to leave– Check that enter before leave

4. Convert these into endpoints of clipped segment

Page 7: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

1. Parametric Intersection

• Segment goes from (x1,y1) to (x2,y2):

• Rectangular clip region with xmin, xmax, ymin, ymax

• Infinite line intersects rectangular clip region edges when:

k

kk p

qt

1max

min1

1max

min1

yyqyp

yyqyp

xxqxp

xxqxp

toptop

bottombottom

rightright

leftleft

where

12

12

yyy

xxx

Page 8: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

2. Entering or Leaving?

• When pk<0, as t increases line goes from outside to inside – entering

• When pk>0, line goes from inside to outside – leaving

• When pk=0, line is parallel to an edge– Special case: one endpoint outside, no part of

segment visible, otherwise, ignore this clip edge and continue

yp

yp

xp

xp

top

bottom

right

left

Page 9: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Find Visible Segment ts

• Last parameter is enter is tsmall=max(0, entering t’s)

• First parameter is leave is tlarge=min(1, leaving t’s)

• If tsmall>tlarge, there is no visible segment

• If tsmall<tlarge, there is a line segment– Compute endpoints by substituting t values into parametric equation

for the line segment

• Improvement (and actual Liang-Barsky):– compute t’s for each edge in turn (some rejects occur earlier like

this)

Page 10: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

General Liang-Barsky

• Liang-Barsky works for any convex clip region– E.g. Perspective view volume in world or view coordinates

• Require a way to perform steps 1 and 21. Compute intersection t for all clip lines/planes

2. Label them as entering or exiting Near

Far

Left

Right

Page 11: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

In View Space

• For Project 2, you need to clip edges to a view frustum in world space

• Situation is:

eye, e

frustumxright

xleft

x1

x2

Page 12: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

First Step

• Compute inside/outside for endpoints of the line segment– Determine which side of each clip plane the segment endpoints lie

– Use the cross product

– What do we know if (x1 - e) (xleft - e) > 0 ?

– Other cross products give other information

• What can we say if both segment endpoints are outside one clip plane?– Stop here if we can, otherwise…

Page 13: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Finding Parametric Intersection

• Left clip edge: x = e + (xleft - e) t

• Line: x = x1 + (x2 - x1) s

• Solve simultaneous equations in t and s:

• Use endpoint inside/outside information to label as entering or leaving

• Now we have general Liang-Barsky case

st

st

yyyyylefty

xxxxxleftx

)()(

)()(

,1,2,1,

,1,2,1,

xxxexe

xxxexe

Page 14: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

General Clipping

• Liang-Barsky can be generalized to clip line segments to arbitrary polygonal clip regions– Consider clip edges as non-infinite segments

– Look at all intersecting ts between 0 and 1

• Clipping general polygons against general clip regions is quite hard: Weiler-Atherton algorithm– Start with polygons as lists of vertices

– Replace crossing points with vertices

– Double all edges and form linked lists of edges

– Adjust links at crossing vertices

– Enumerate polygon patches

Page 15: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Weiler-Atherton – Form Lists

Original Polygons Double Linked Lists -outside and inside lists

Page 16: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Weiler-Atherton – Find Crossings

Crossing vertices added –links re-written

Page 17: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Weiler-Atherton – Enumerate

“Not clip not poly” “Clip not Poly”

“Clip and Poly”

Every link used once

“Poly not Clip”

Page 18: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Where We Stand

• At this point we know how to:– Convert points from local to screen coordinates

– Clip polygons and lines to the view volume

• Next thing:– Determine which pixels to fill for any given point, line or polygon

Page 19: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Drawing Points

• When points are mapped into window coordinates, they could land anywhere – not just at a pixel center

• Solution is the simple, obvious one– Map to window space

– Fill the closest pixel

– Can also specify a radius – fill a square of that size, or fill a circle• Square is faster

• What function are we sampling with?

Page 20: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Drawing Lines

• Task: Decide which pixels to fill (samples to use) to represent a line

• We know that all of the line lies inside the visible region (clipping gave us this!)

• Issues:– If slope between -1 and 1, one pixel per column. Otherwise, one

pixel per row– Constant brightness? Lines of the same length should light the same

number of pixels (we normally ignore this)– Anti-aliasing? (Getting rid of the “jaggies”)– Sampling theory?

Page 21: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Line Drawing Algorithms

• Consider lines of the form y=m x + c, where m=y/x, 0<m<1, integer coordinates– All others follow by symmetry, modify for real numbers

• Variety of slow algorithms (Why slow?):– step x, compute new y at each step by equation, rounding:

– step x, compute new y at each step by adding m to old y, rounding:

)( ,1 111 bmxroundyxx iiii

)( ,1 11 myroundyxx iiii

Page 22: 10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.

10/19/04 © University of Wisconsin, CS559 Fall 2004

Bresenham’s Algorithm Overview

• Aim: For each x, plot the pixel whose y-value is closest to the line

• Given (xi,yi), must choose from either (xi+1,yi+1) or (xi+1,yi)

• Idea: compute a decision variable– Value that will determine which pixel to draw

– Easy to update from one pixel to the next

• Bresenham’s algorithm is the midpoint algorithm for lines– Other midpoint algorithms for conic sections (circles, ellipses)


Recommended