+ All Categories
Home > Documents > Clipping

Clipping

Date post: 27-Nov-2014
Category:
Upload: lalu-saud
View: 227 times
Download: 1 times
Share this document with a friend
Popular Tags:
45
Standard output primitive in graphics packages is solid color ,patterned polygon area Polygons are easier to process due to linear boundaries Two basic approaches to area filling on a raster system 1. Determine the overlap intervals for scan lines that cross the area. Typically useful for filling polygons, circles, ellipses 2.Start from a given interior position and paint outwards from this point until we encounter the specified boundary conditions useful for filling more complex boundaries, interactive painting system. 1 Computer Graphics, Nepal College of Information Technology, 2009 Filled Area Primitives
Transcript
Page 1: Clipping

 Standard output primitive in graphics packages is solid color ,patterned polygon area

Polygons are easier to process due to linear boundaries

Two basic approaches to area filling on a raster system

1. Determine the overlap intervals for scan lines that cross the area. Typically useful for filling polygons, circles, ellipses 2.Start from a given interior position and paint outwards from this point until we encounter the specified boundary conditions useful for filling more complex boundaries, interactive painting system. 

1Computer Graphics, Nepal College of Information Technology, 2009

Filled Area Primitives

Page 2: Clipping

 Two things to consider i. which pixels to fill ii. with what value to fill

Move along scan line (from left to right) that intersect the primitive and fill in pixels that lay inside

To fill rectangle with solid color

Set each pixel lying on scan line running from left edge to right with same pixel value, each span from x max to x min   for( y from y min to y max of rectangle) /*scan line*/ for( x from x min to x max of rectangle) /*by pixel*/ writePixel(x, y, value);

2Computer Graphics, Nepal College of Information Technology, 2009

Filling rectangles

Page 3: Clipping

3Computer Graphics, Nepal College of Information Technology, 2009

Filling PolygonsScan-line fill

algorithmInside-Outside

tests

Boundary fill algorithm

1 2346 7 8 910

1151 2 3 4 5 6 7 8 9

Filling Polygons

Page 4: Clipping

4Computer Graphics, Nepal College of Information Technology, 2009

Topological Difference between 2 Scan linesy : intersection edges are opposite sidesy’ : intersection edges are same side

y

y’1

2

1

1 2

Page 5: Clipping

5Computer Graphics, Nepal College of Information Technology, 2009

Topological Difference between 2 Scan linesy : intersection edges are opposite sidesy’ : intersection edges are same side

y

y’1

2

1

1 2

Page 6: Clipping

6Computer Graphics, Nepal College of Information Technology, 2009

C

C’

B

D

E

A

01

yA

yD

yC

Scan-Line Number

yE xA1/mAE yB xA

1/mAB

yC’ xD1/mDC yE xD

1/mDE

yB xC1/mCB

Edge Sorted Table

Page 7: Clipping

7Computer Graphics, Nepal College of Information Technology, 2009

Proceed to Neighboring Pixels4-Connected8-Connected

Page 8: Clipping

Start at a point inside a region and paint the interior outward toward the boundary.

If boundary is specified in a single color the fill algorithm proceeds outward pixel by pixel until the boundary color is encountered

Accepts as input coordinates of an interior point (x, y) a fill color and boundary color.

Starting from (x, y) the procedure tests neighboring position to determine whether they are of the boundary color.

If not they are painted with fill color and their neighbors are tested Process continues until all pixels up to boundary color for the area have been tested

8Computer Graphics, Nepal College of Information Technology, 2009

Boundary Fill

Page 9: Clipping

boundaryFill(int x,y,fill_color, boundary_color){ int color; getpixel(x,y,color) if(color != boundary_color AND color != fill_color ){ setpixel( x,y,fill_color) boundaryFill( x+1,y,fill_color, boundary_color) boundaryFill( x,y+1,fill_color, boundary_color) boundaryFill( x-1,y,fill_color, boundary_color) boundaryFill( x,y-1,fill_color, boundary_color) }

}

9Computer Graphics, Nepal College of Information Technology, 2009

Page 10: Clipping

Filling an area that is not defined within a single color boundary. In this case replace a specified interior color instead of searching for boundary color value. Start from specified interior point (x , y) and reassign all pixel values that are currently set to a given interior color with the desired color. If the area we want to paint has more than 1 interior color , first assign pixel values so that all interior points have same color. We can then use 8 or 4 connected approach to move on until all interior points have been repainted. 

10Computer Graphics, Nepal College of Information Technology, 2009

Flood Fill

Page 11: Clipping

floodFill(int x,y,fill_color, original_color){ int color; getpixel(x,y,color) if(color == original_color ){ setpixel(x,y,fill_color) floodFill(x+1,y,fill_color, original_color) floodFill(x,y+1,fill_color, original_color) floodFill(x-1,y,fill_color, original_color) floodFill(x,y-1,fill_color, original_color) }

}

11Computer Graphics, Nepal College of Information Technology, 2009

Page 12: Clipping
Page 13: Clipping

Window and View ports

A rectangular area specified in world coordinates is called a window.

A rectangular area on the display device to which a window is mapped is called a view port.

The window defines what is to be viewed; the

view port defines where it is to be displayed.

Page 14: Clipping

Window and View ports

Often windows and view ports are rectangles in standard position with rectangle edges parallel to coordinate axes

The mapping of a part of world coordinate scene to device coordinate is referred to as viewing

transformation.

Page 15: Clipping

2D Viewing Pipeline

Construct World coordinate

Scene using modeling-coordinate transformations

Construct World coordinate

Scene using modeling-coordinate transformations

Convert world coordinates to viewing coordinates

Convert world coordinates to viewing coordinates

Map viewing coordinates to normalized viewing coordinates using window view port specifications

Map viewing coordinates to normalized viewing coordinates using window view port specifications

Map normalized view port to device coordinates

Map normalized view port to device coordinates

MC WC VC NVC DC

Page 16: Clipping

Clipping in Raster World 

Procedure that identifies those operations of picture that are either inside or outside

The region against which an object is to be clipped is called a clip window.

Depending on application it can be polygons or even curve surfaces.

Page 17: Clipping

Clipping in Raster World  Applications

i. Extracting parts of defined scene for viewing ii. Identifying visible surfaces in three dimension views

iii. Drawing, painting operations that allow parts of picture to be selected for copying, moving, erasing or duplicating

etc.

Page 18: Clipping

Line Clipping

Point clipping easy: Just check the inequalities xmin < x < xmax

ymin < y < ymax

Line clipping more tricky

Page 19: Clipping

Cohen-Sutherland Line Clipping

Divide 2D space into 3x3 regions. Middle region is the clipping window. Each region is assigned a 4-bit code.

Bit 1 is set to 1 if the region is to the left of the clipping window, otherwise. Similarly for bits 2, 3 and 4.

4 3 2 1

Top Bottom Right Left

Page 20: Clipping

Cohen-Sutherland Line Clipping

0000

1001

0001

0101 0100 0110

0010

10101000

(xwmin, ywmin)

(xwmax, ywmax)

Page 21: Clipping

Cohen-Sutherland Line Clipping To clip a line, find out which regions

its two endpoints lie in.

Case I If they are both in region 0000, then it’s

completely in.

Page 22: Clipping

Cohen-Sutherland Line Clipping

0000

1001

0001

0101 0100 0110

0010

10101000

(xwmin, ywmin)

(xwmax, ywmax)

Page 23: Clipping

Cohen-Sutherland Line ClippingCase II If the two region numbers both have a 1 in the

same bit position, the line is completely out.

Page 24: Clipping

Cohen-Sutherland Line Clipping

0000

1001

0001

0101 0100 0110

0010

10101000

(xwmin, ywmin)

(xwmax, ywmax)

Page 25: Clipping

Cohen-Sutherland Line ClippingCase III If lines can not be identified as completely inside or outside

we have to do some more calculations.

Here we find the intersection points with a clipping boundary using the slope intercept form of the line equation

Page 26: Clipping

Cohen-Sutherland Line Clipping

0000

1001

0001

0101 0100 0110

0010

10101000

(xwmin, ywmin)

(xwmax, ywmax)

Page 27: Clipping

Cohen-Sutherland Line Clipping For a line with end point coordinates

(x1,y1) and (x2, y2) the y coordinate of the intersection point with a vertical boundary is

y = y1 + m (x – x1) Where x is set to either xwmin or xwmax

Page 28: Clipping

Cohen-Sutherland Line Clipping

0000

1001

0001

0101 0100 0110

0010

10101000

(xwmin, ywmin)

(xwmax, ywmax)

Page 29: Clipping

Cohen-Sutherland Line Clipping Similarly for the intersection with a vertical boundary

x = x1 + (y – y1)/m Where y is set to either ywmin or

ywmax

Page 30: Clipping

Cohen-Sutherland Line Clipping

0000

1001

0001

0101 0100 0110

0010

10101000

(xwmin, ywmin)

(xwmax, ywmax)

Page 31: Clipping

Cohen-Sutherland Line Clipping For those lines that we cannot

immediately determine, we successively clip against each boundary.

Then check the new endpoint for its region code.

How to find boundary intersection: To find y coordinate at vertical intersection, substitute x value at the boundary into the line equation of the line to be clipped.

Other algorithms: Faster: Cyrus-Beck Even faster: Liang-Barsky Even faster: Nichol-Lee-Nichol

Page 32: Clipping

Cohen-Sutherland Line Clipping

Use Cohen Sutherland line clipping algorithm toclip a line with end point coordinates A(70,90) ,B(60,85) against a clip window with its lower

leftcorner at (50,80) and upper right corner at

(90,120)

Hints: i. Find the region code for each end point of the lineii. Find if it is above, below, left or right of the clip window iii. Determine the intersection point of the line segment with the

boundary

Page 33: Clipping

Polygon Fill-Area Clippingv1

v2v3

v1’

v2v3”

v1”

v3’

Note: Need to consider each of 4 edge boundaries

Page 34: Clipping

Sutherland-HodgmanPolygon Clipping Input each edge (vertex pair) successively. Output is a new list of vertices. Each edge goes through 4 clippers. The rule for each edge for each clipper is:

If first input vertex is outside, and second is inside, output the intersection and the second vertex

If first both input vertices are inside, then just output second vertex

If first input vertex is inside, and second is outside, output is the intersection

If both vertices are outside, output is nothing

Page 35: Clipping

Sutherland-Hodgman Polygon Clipping: Four possible scenarios at each clipperoutside inside

v1v1’

v2

outside inside

v1

v2

outside inside

v1v1’

v2

outside inside

v1

v2

Outside to inside:Output: v1’ and v2

Inside to inside:Output: v2

Inside to outside:Output: v1’

Outside to outside:Output: nothing

Page 36: Clipping

Sutherland-Hodgman Polygon Clipping

v2

v1

v3

Right Clipper

Bottom Clipper

Top Clipper

Left Clipper

v1v2

v2v3

v3v1

v1’

v2

v2’

v2’

v3’v1

v2v2’

v2’v3’

v3’v1

v1v2

v2’

v3’

v1

v2 v2v2’

v2’v3’

v3’v1

v1v2

v3’

Figure 6-27, page 332

v2”

v1’v2

v2’ v2’v2”

v2”v1’

v1’v2

v2v2’

v1’

v2

v2’

v2”

Edges Output Edges Output Edges Output Edges Output

Final

Page 37: Clipping

Weiler-Atherton Polygon Clipping

Sutherland-Hodgman

Weiler-Atherton

Page 38: Clipping

Clipping in 3D

Suppose the view volume has been normalized. Then the clipping boundaries are just:

xwmin = -1

ywmin = -1

zwmin = -1

xwmax = 1

ywmax = 1

zwmax = 1

Page 39: Clipping

Clipping Homogeneous Coordinates in 3D Coordinates expressed in homogeneous coordinates

After geometric, viewing and projection transformations, each vertex is: (xh, yh, zh, h)

Therefore, assuming coordinates have been normalized to a (-1,1) volume, a point (xh, yh, zh, h) is inside the view volume if:

-1 < < 1 and -1 < < 1 and -1 < < 1 xh

h

yh

h

zh

h

Suppose that h > 0, which is true in normal cases, then

-h < xh < h and -h < yh < h and -h < zh < h

Page 40: Clipping

Remember Cohen-Sutherland 2D Line Clipping Region Codes?

Divide 2D space into 3x3 regions. Middle region is the clipping window. Each region is assigned a 4-bit code. Bit 1 is set to 1 if the region is to the

left of the clipping window, 0 otherwise. Similarly for bits 2, 3 and 4.

4 3 2 1

Top Bottom Right Left

Page 41: Clipping

Cohen-Sutherland Line Clipping Region Codes in 2D

0000

1001

0001

0101 0100 0110

0010

10101000

Page 42: Clipping

3D Cohen-Sutherland Region Codes

Simply use 6 bits instead of 4.

4 3 2 1

Far Near Top Bottom Right Left

6 5

Example: If h + xh < 0, then bit 1 is set to 1.

This is because if -h > xh, then the point is to the left of the viewing volume.

Page 43: Clipping

Clipping Polygons

First, perform trivial acceptance and rejection using, for example, its coordinate extents.

Polygons usually split into triangle strips.

Then each triangle is clipped using 3D extension of the Sutherland-Hodgman method

Page 44: Clipping

Arbitrary Clipping Planes Can specify an arbitrary clipping plane:

Ax + By + Cz + D = 0. Therefore, for any point, if Ax + By + Cz

+ D < 0, it is not shown. To clip a line against an arbitrary plane,

If both end-points are in, then the line is in If both end-points are out, then the line is out If one end-point is in, and one is out, then we

need to find the intersection of the line and the plane

Page 45: Clipping

Intersection of Line and Plane

First, given two end-points of a line, P1 and P2, form a parametric representation of the line:

P = P1 + (P2 – P1) u, where 0<u<1

Equation of the clipping plane: N.P + D = 0, where N = (A,B,C)

Substituting, N.(P1 + (P2 – P1)u) + D = 0

u = – D – N.P1

N . (P2 – P1)


Recommended