Top Banner
Clipping Clipping Any Procedure that identifies Any Procedure that identifies those portions of a picture those portions of a picture that are either inside or that are either inside or outside of a specified region outside of a specified region of a space is referred to as of a space is referred to as a a Clipping algorithm Clipping algorithm or or simply simply Clipping Clipping . . The region against which The region against which an object is to clipped is an object is to clipped is called a called a Clip Window. Clip Window.
23
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Clipping

ClippingClipping

Any Procedure that identifies those Any Procedure that identifies those portions of a picture that are either inside portions of a picture that are either inside or outside of a specified region of a space or outside of a specified region of a space is referred to as a is referred to as a Clipping algorithmClipping algorithm or or simply simply ClippingClipping..

The region against which an object The region against which an object is to clipped is called a is to clipped is called a Clip Window.Clip Window.

Page 2: Clipping

ClippingClipping

* Clipping algorithms are 2D-3D.* Clipping algorithms are 2D-3D.* Clipping algorithm can be implemented in hardware or * Clipping algorithm can be implemented in hardware or software.software.* When implemented in software, clipping algorithms are * When implemented in software, clipping algorithms are slower than required for real time applications.slower than required for real time applications.* For this reason both 2D & 3D clipping algorithm have been * For this reason both 2D & 3D clipping algorithm have been implemented in hardware or firmware.implemented in hardware or firmware.* The purpose of a clipping algorithm is to determine which * The purpose of a clipping algorithm is to determine which points, lines or portions of lines lie with in the clipping points, lines or portions of lines lie with in the clipping window.window.* These points, lines or portions of lines are relative for * These points, lines or portions of lines are relative for display.display.* All other are discarded.* All other are discarded.

Page 3: Clipping

* Application of clipping include extracting part of a * Application of clipping include extracting part of a defined scene for viewing.defined scene for viewing.* Identifying visible surface in 3D views.* Identifying visible surface in 3D views.* Antiliasing line segment or object boundaries.* Antiliasing line segment or object boundaries.* Creating objects using solid-modeling procedures.* Creating objects using solid-modeling procedures.* Displaying a multi window environment.* Displaying a multi window environment.* Drawing & painting operation that allow part of a * Drawing & painting operation that allow part of a picture to be selected for clipping, moving, erasing or picture to be selected for clipping, moving, erasing or duplicating.duplicating.

Page 4: Clipping

* Depending on the application, the clip window can * Depending on the application, the clip window can be a general polygon or it can even have curved be a general polygon or it can even have curved boundaries.boundaries.* For the viewing transformation, we want to * For the viewing transformation, we want to display only those picture parts that are within the display only those picture parts that are within the window area. Everything outside the window is window area. Everything outside the window is discarded.discarded.* Clipping algorithm can be applied in World * Clipping algorithm can be applied in World Coordinates, so that only the contents of the Coordinates, so that only the contents of the window interior are mapped to Device window interior are mapped to Device coordinates. coordinates.

Page 5: Clipping

Types of ClippingTypes of Clipping

Point ClippingPoint Clipping Line ClippingLine Clipping Polygon ClippingPolygon Clipping Curve ClippingCurve Clipping Text ClippingText Clipping

Page 6: Clipping

Point ClippingPoint Clipping

We have a point P=(x, y) for display if the We have a point P=(x, y) for display if the following inequalities are satisfiedfollowing inequalities are satisfied

Xwmin <= X <= XwmaxXwmin <= X <= Xwmax

Ywmin <= Y <= YwmaxYwmin <= Y <= Ywmax

where the Xwmin, Ywmin, Xwmax, Ywmax where the Xwmin, Ywmin, Xwmax, Ywmax are the edge of the Clip Window.are the edge of the Clip Window.

Page 7: Clipping

Line ClippingLine Clipping

* A line clipping procedure involves several * A line clipping procedure involves several parts.parts.

* In many cases the large majority of points or * In many cases the large majority of points or lines are either interior or exterior to the lines are either interior or exterior to the clipping window.clipping window.

* Therefore it is important to be able to quickly * Therefore it is important to be able to quickly accept a line which is completely interior to accept a line which is completely interior to the window & reject a line which is exterior to the window & reject a line which is exterior to the window.the window.

Page 8: Clipping

Line ClippingLine Clipping

* Lines are interior to the clipping window & * Lines are interior to the clipping window & hence visible if both end points are interior to hence visible if both end points are interior to the the window.window.* Points are interior to the clipping window provided * Points are interior to the clipping window provided

thatthatXL <= X <= XRXL <= X <= XRYB <= Y <= YTYB <= Y <= YT

Page 9: Clipping

I

J

G

H

EF

A

B

C

D

K

L

Right

Bottom

Top

Left

Line Clipping

Page 10: Clipping

Line ClippingLine Clipping * However, if both endpoints of a line are * However, if both endpoints of a line are exterior to the window, the line is not exterior to the window, the line is not necessarily completely exterior to the window.necessarily completely exterior to the window.* If both end points of a lines are:-* If both end points of a lines are:-

# completely to the right of the window.# completely to the right of the window.# completely to the left of the window.# completely to the left of the window.# completely above the window.# completely above the window.# completely bottom the window.# completely bottom the window.

Then the line is completely exterior to the window & hence Then the line is completely exterior to the window & hence invisibleinvisible

Page 11: Clipping

Cohen & Sutherland AlgorithmCohen & Sutherland Algorithm

The tests for totally visible lines and the region tests for The tests for totally visible lines and the region tests for totally invisible lines can be formalized using a totally invisible lines can be formalized using a technique i.e. Cohen & Sutherland Algorithm.technique i.e. Cohen & Sutherland Algorithm.

The technique uses a The technique uses a four digit (bit) code, known as “Region Code”, to four digit (bit) code, known as “Region Code”, to indicate which of nine regions contains the end points indicate which of nine regions contains the end points of a line. of a line.

Page 12: Clipping

Cohen & Sutherland AlgorithmCohen & Sutherland Algorithm

The rightmost bit is the first bit. The bits are The rightmost bit is the first bit. The bits are set to 1 based on the following scheme.set to 1 based on the following scheme.

1) First bit Set- If the end point is to the left of the window. 1) First bit Set- If the end point is to the left of the window. 2) Second bit Set- If the end point is to the right of the window. 2) Second bit Set- If the end point is to the right of the window. 3) Third bit Set- If the end point is to the below the window. 3) Third bit Set- If the end point is to the below the window. 4) Fourth bit Set- If the end point is to the above the window. 4) Fourth bit Set- If the end point is to the above the window. Otherwise the bit is set to Zero.Otherwise the bit is set to Zero.

It is obvious that, if both end point codes are zero, It is obvious that, if both end point codes are zero, then both ends of the line lie inside the window & the then both ends of the line lie inside the window & the line is visible.line is visible.

Page 13: Clipping

Cohen & Sutherland AlgorithmCohen & Sutherland Algorithm

For First bit:- For First bit:- X<XLX<XL

Second bit:- Second bit:- X>XRX>XR

Third bit:- Third bit:- Y<YBY<YB

Fourth bit:-Fourth bit:-Y>YTY>YT

B L R

T

XL XR

YT

YB

Window

0101 0100 0110

0001 0000 0010

1001 1000 1010

Page 14: Clipping

Cohen & Sutherland AlgorithmCohen & Sutherland Algorithm

If the bit by bit logical intersection of the two end If the bit by bit logical intersection of the two end points codes is not zero, then the line is totally points codes is not zero, then the line is totally invisible & may be trivially reject.invisible & may be trivially reject.

When the logical intersection is not zero, the line is in When the logical intersection is not zero, the line is in fact totally invisible.fact totally invisible.

When the logical intersection is zero, the line may be When the logical intersection is zero, the line may be totally or partially visible or in fact totally invisible.totally or partially visible or in fact totally invisible.

For this reason, it is necessary to check both end For this reason, it is necessary to check both end points codes separately to determine total visibility.points codes separately to determine total visibility.

Page 15: Clipping

Cohen & Sutherland AlgorithmCohen & Sutherland Algorithm

Lines Lines thatthat can not be identified as completely inside can not be identified as completely inside or completely outside a clip window by there tests are or completely outside a clip window by there tests are checked for intersection with the window boundaries.checked for intersection with the window boundaries.

Such lines may or may not cross into the window Such lines may or may not cross into the window interior.interior.

We begin the clipping process for a line by We begin the clipping process for a line by comparing an outside endpoint to a clipping boundary comparing an outside endpoint to a clipping boundary to determine how much of line can be discarded. to determine how much of line can be discarded.

Page 16: Clipping

Cohen & Sutherland AlgorithmCohen & Sutherland Algorithm

Then the remaining part of the line is checked against Then the remaining part of the line is checked against the other boundaries, and we continue until either the the other boundaries, and we continue until either the line is totally discarded or a section is found inside line is totally discarded or a section is found inside the window.the window.

We set up our algorithm to check line end point We set up our algorithm to check line end point against clipping boundaries in the order left, right, against clipping boundaries in the order left, right, bottom, & top.bottom, & top.

Page 17: Clipping

Cohen & Sutherland AlgorithmCohen & Sutherland Algorithm

The equation of the The equation of the infinite line through infinite line through P1(X1, Y1) & P2(X2, P1(X1, Y1) & P2(X2, Y2) is Y2) is

Y=m(X-X1)+Y1Y=m(X-X1)+Y1

Or Or

Y=m(X-X2)+Y2Y=m(X-X2)+Y2

m= Y2-Y1/X2-X1m= Y2-Y1/X2-X1

P4

P4’P3’P3

P1

P1’

P2”

P2”P2

Page 18: Clipping

Cohen & Sutherland AlgorithmCohen & Sutherland Algorithm

The intersection with the window edges are The intersection with the window edges are given bygiven by

Left XL Y=m(XL-X1)+Y1Left XL Y=m(XL-X1)+Y1

Right XR Y=m(XR-X1)+Y1Right XR Y=m(XR-X1)+Y1

Top YT X=X1+1/m(YT-Y1)Top YT X=X1+1/m(YT-Y1)

Bottom YB X=X1+1/m(YB-Y1)Bottom YB X=X1+1/m(YB-Y1)

Page 19: Clipping

Cohen & Sutherland AlgorithmCohen & Sutherland Algorithm

To develop an efficient clipping algorithm some special To develop an efficient clipping algorithm some special cases must be consideredcases must be considered

If the slope of line is infinite, it is parallel to the left If the slope of line is infinite, it is parallel to the left & right, and only the top & bottom edges need to & right, and only the top & bottom edges need to checked for intersection. checked for intersection.

If the slope of the line is zero, the line is parallel to If the slope of the line is zero, the line is parallel to the top & bottom edges, and only the left & right the top & bottom edges, and only the left & right edge need to checked for intersection. edge need to checked for intersection.

Page 20: Clipping

Mid Point Subdivision AlgorithmMid Point Subdivision Algorithm

The Cohen-Sutherland algorithm requires the The Cohen-Sutherland algorithm requires the calculation of the intersection of the line with calculation of the intersection of the line with window edge.window edge.

This direct calculation can be avoided by This direct calculation can be avoided by performing a binary search for the intersection performing a binary search for the intersection by always dividing the line at its mid point.by always dividing the line at its mid point.

This algorithm is implemented in hardware. This algorithm is implemented in hardware.

Page 21: Clipping

Mid Point Subdivision AlgorithmMid Point Subdivision Algorithm

Implementation in hardware is fast & efficient Implementation in hardware is fast & efficient because a parallel architecture can be used and because a parallel architecture can be used and hardware addition & division by 2 are very hardware addition & division by 2 are very fast.fast.

In hardware, division by 2 can be In hardware, division by 2 can be accomplished by shifting each bit to the right.accomplished by shifting each bit to the right.

The algorithm uses the line end point codes & The algorithm uses the line end point codes & associated test to immediately identify totally associated test to immediately identify totally visible lines, & trivially invisible lines. visible lines, & trivially invisible lines.

Page 22: Clipping

Mid Point Subdivision AlgorithmMid Point Subdivision Algorithm

Lines which can not be immediately identified Lines which can not be immediately identified using there test are subdivided into 2 equal using there test are subdivided into 2 equal parts.parts.

The test are then applied to each half until the The test are then applied to each half until the intersection with the window edge is found or intersection with the window edge is found or the length of the divided segment is the length of the divided segment is infinitesimal i.e. 0 point.infinitesimal i.e. 0 point.

The visibility of the point is then determined.The visibility of the point is then determined. The result is to perform a logarithmic search for The result is to perform a logarithmic search for

the intersection point. the intersection point.

Page 23: Clipping

Mid Point Subdivision AlgorithmMid Point Subdivision Algorithm

P1

P2

Pm1

Pm2

Pm2

P1

P2

Pm1

Pm2