Clipping 22
Upcoming SlideShare
Loading in...5
×
 

Clipping 22

on

  • 1,239 views

ll

ll

Statistics

Views

Total Views
1,239
Views on SlideShare
1,097
Embed Views
142

Actions

Likes
1
Downloads
21
Comments
0

7 Embeds 142

http://www.shree3cse2009.blogspot.com 72
http://shree3cse2009.blogspot.com 56
http://shree3cse2009.blogspot.in 5
http://www.shree3cse2009.blogspot.in 5
http://shree3cse2009.blogspot.com.es 2
http://shree3cse2009.blogspot.jp 1
http://shree3cse2009.blogspot.kr 1
More...

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Clipping 22 Clipping 22 Presentation Transcript

  • Drawing with Thick Primitives
    Drawing with Thick Primitives
    • How do we thicken
    the line stroke width?
    • Ideas:
    – Place the center of
    the circular “brush” on
    the pixel
    – Place the upper
    corner of the square
    “marker” on the pixel
    (issues of orientation)
    – Then do scan
    conversion algorithm
  • Why Clip?
    Rasterization is very expensive
    Approximately linear with number of fragments created
    Math and logic per pixel
    If we only rasterize what is actually viewable, we can save a lot
    A few operations now can save many later
  • Clipping Primitives
    Different primitives can be handled in different ways
    Points
    Lines
    Polygons
  • 159.235
    Graphics
    4
    Viewing & Clipping - Outline
    Viewing in 2D
    Clipping in 2D
    Cohen-Sutherland Algorithm
    Cyrus & Beck Algorithm
    Clipping Polygons
    Sutherland-Hodgman Algorithm
  • 159.235
    Graphics
    5
    Viewing in 2D - Viewport
    250
    45
    Window in world coordinates.
    250 x 250
    Pixels.
    Viewport in
    Device coords
  • 159.235
    Graphics
    6
    Clipping in 2D
    Need to clip primitives (eg lines) against the sides of the viewing window
    e.g lines or polygons
    We only see what is inside the window
  • 159.235
    Graphics
    7
    Trivial Clipping Acceptance
    If all a line’s vertices lie inside box we “accept” it
  • 159.235
    Graphics
    8
    Trivial Vertex Rejection
    All line vertices lie outside and on same side  reject.
  • 159.235
    Graphics
    9
    This is an efficient method of accepting or rejecting lines that do not intersect the window edges.
    Assign a binary 4 bit code to each vertex :
    First bit : above top of window, y > ymax
    Second bit : below bottom, y < ymin
    Third bit : to right of right edge, x > xmax
    Fourth bit : to left of left edge, x < xmin
    4-bit code called: Outcode
    Cohen-Sutherland Clipping Algorithm
  • 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, 0 otherwise. Similarly for bits 2, 3 and 4.
    4
    3
    2
    1
    Top Bottom Right Left
  • Cohen-Sutherland Line Clipping
    1010
    1000
    1001
    0000
    0010
    0001
    0100
    0110
    0101
  • 159.235
    Graphics
    12
    Cohen-Sutherland Algorithm
    1001
    1000
    1010
    0000
    0001
    0010
    0100
    0110
    0101
    Both endpoint codes 0000, trivial acceptance, else:
    Do logical AND of Outcodes (reject if non-zero)
  • 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
  • 159.235
    Graphics
    14
    Clipping Polygons
    Clip polygons by clipping successively against 4 sides.
  • 159.235
    Graphics
    15
    Clipping Polygons
    Clip polygons by clipping successively against all 4 sides
    Can implement as pipelined algorithm (ie special hardware can do the work)
    Recursively test each edge.
    Form new edge with next vertex
    Call with new edge
  • 159.235
    Graphics
    16
    Four cases of polygon clipping:
    Inside
    Outside
    Inside
    Outside
    Inside
    Outside
    Inside
    Outside
    Output
    Intersection
    Second
    Output
    Case 3
    No output.
    Case 1
    Case 2.
    Case 4
    Sutherland-Hodgman Clipping Algorithm
    First
    Output
    Output
    Vertex
  • 159.235
    Graphics
    17
    Sutherland-Hodgman Algorithm
    Loop round vertices, test each against all 4 clipping planes in sequence
    Call algorithm again with new edge formed by next vertex -re-entrant
    No storage requirement between stages
    Easy to implement in hardware
  • 18
    Viewing & Clipping - Summary
    Window and Viewport
    Clipping cuts out what we do not “see”
    Also reduces unnecessary computation
    Can be done at various levels
    Java 2D system does a lot of the clipping for us if we use that rendering pipeline