SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
Clipping




Learning outcomes for this lecture

You will
  understand
    What is meant by ‘clipping’
    2D clipping concepts
    3D clipping concepts

    Different kinds of clipping
    The Cohen-Sutherland 2D region-coding
    clipping technique

  Be able to
    calculate Cohen-Sutherland 2D region-coding




                                                  1
Plan

          Review of rendering pipeline

          Clipping




          The Graphics Pipeline
        Modeling
     Transformations

       Illumination
         (Shading)

  Viewing Transformation
(Perspective / Orthographic)

         Clipping

         Projection
     (to Screen Space)

     Scan Conversion
      (Rasterization)

    Visibility / Display




                                         2
Modeling Transformations
        Modeling
     Transformations

       Illumination
         (Shading)

  Viewing Transformation
(Perspective / Orthographic)
                                 Object space                          World space

         Clipping
                                    x'              a b c d                               x
         Projection                 y'              e f g h                               y
     (to Screen Space)                      =
     Scan Conversion                z'              i j k l                               z
      (Rasterization)
                                    1               0 0 0 1                               1
    Visibility / Display




         Illumination (Shading) (Lighting)
                                         Vertices lit (shaded) according to
        Modeling                         material properties, surface
     Transformations                     properties (normal) and light
                                         Local lighting model
       Illumination                      (Diffuse, Ambient, Phong, etc.)
         (Shading)
                                                                                Φ
  Viewing Transformation
(Perspective / Orthographic)
                                                (
                               L(ωr ) = k a + k d (n ⋅ l) + k s (v ⋅ r ) q   ) 4π d
                                                                                 s
                                                                                      2



         Clipping

         Projection
     (to Screen Space)

     Scan Conversion
      (Rasterization)

    Visibility / Display




                                                                                              3
Viewing Transformation
        Modeling                      Viewing position is transformed to
     Transformations                  origin & direction is oriented along
                                      some axis (usually z)
       Illumination
         (Shading)                                            Eye space
  Viewing Transformation
(Perspective / Orthographic)

         Clipping

         Projection
                               World space
     (to Screen Space)                     x'      a b c d                   x
     Scan Conversion                               e f g h                   y
                               Yet another y'
      (Rasterization)
                               4x4 matrix z'
                                                 =
                                                   i j k l                   z
    Visibility / Display
                                           1       0 0 0 1                   1




                               Clipping
        Modeling
     Transformations

       Illumination
         (Shading)

  Viewing Transformation
(Perspective / Orthographic)

         Clipping

         Projection
     (to Screen Space)

     Scan Conversion
      (Rasterization)

    Visibility / Display




                                                                                 4
Games: pipeline




Flight simulation: pipeline (painter for long time)




                                                      5
Questions?




Plan

Review of rendering pipeline

Clipping




                               6
Clipping

Clipping means
  Identifying portions of a scene that are inside (or
  outside) a specified region
Examples
  Multiple viewports on a device




  Deciding how much of a games world the player can see




Clipping

Clipping means
  Identifying portions of a scene that are inside (or
  outside) a specified region
Examples
  Multiple viewports on a device




  Deciding how much of a games world the player can see

                                   Player can’t
                                   see this far yet




                                                          7
Clipping
  we’ve been assuming that all primitives
  (lines, triangles, polygons) lie entirely
  within the viewport
     in general, this assumption will not
     hold:




             Clipping
  Eliminate portions of objects
  outside the viewing frustum
  View Frustum
     boundaries of the image
     plane projected in 3D                far
     a near & far
     clipping plane               top
  User may define
                      left
  additional clipping
  planes




                   near           right
                                          bottom




                                                   8
Why clip?


 Avoid degeneracies
     Don’t draw stuff
     behind the eye
     Avoid division
     by 0 and overflow
 Efficiency
     Don’t waste time on objects
     outside the image boundary
 Other graphics applications (often non-convex)
     Hidden-surface removal, Shadows, Picking,
     Binning, CSG (Boolean) operations (2D & 3D)




Why Clip?

bad idea to rasterize outside of
framebuffer bounds
also, don’t waste time scan converting
pixels outside window
  could be billions of pixels for very close
  objects!




                                                   9
When to clip?

 Before perspective transform
 in 3D space
     Use the equation of 6 planes
     Natural, not too degenerate

 In homogeneous coordinates after
 perspective transform (Clip space)
    Before perspective divide
    (4D space, weird w values)
    Canonical,independent of camera
    The simplest to implement in fact

 In the transformed 3D screen space
 after perspective division
     Problem: objects in the plane of
     the camera




    Clipping strategies

  Don’t clip (and hope for the best)
  Clip on-the-fly during rasterization
  Analytical clipping: alter input
  geometry




                                         10
Requirements for clipping

Is (x, y) inside or outside a given
region

For 2D graphics the region defining
what is to be clipped is called
  The clip window
                             Clip window




Clipping

analytically calculating the portions of
primitives within the viewport




                                           11
Interior and exterior clipping

interior clipping
  what is to be saved is inside the clip
  window
exterior clipping
  what is to be saved is outside clip window




            Interior clipping
            - keep point P2
                                    P2
                                    (x2, y2)




Interior and exterior clipping

 Exterior clipping                    Clip window
 - keep point P1
                         P1
                         (x1, y1)




We shall assume interior clipping for
now
  But you must be aware of exterior clipping
  too




                                                    12
Overview of types of clipping

All-or-none clipping
  If any part of object outside clip
  window
  whole object is rejected

Point clipping
  Only keep points inside clip window
Line clipping
  Only keep segment of line inside clip window
Polygon clipping
  Only keep sub-polygons inside clip window




Before and after POINT clipping

Before
                             P2


                    P3              P1
         P4

After



                    P3              P1




                                                 13
Point Classification

How can we tell if a point is inside a
rectangular window?



                                  ymax
xmin ≤ x ≤ xmax
ymin ≤ y ≤ ymax
                                  ymin
                  xmin     xmax




Line Clipping Algorithms

Goal: avoid drawing primitives that are
outside the viewing window.
The most common case: clipping line
segments against a rectangular
window




                                          14
Before and after LINE clipping

Before
            P2




After
                               P1


                 P2’



                         P1’




Before and after POLYGON clipping

Before




After




                                    15
Clipping Lines
 naïve approach to clipping lines:
  for each line segment
      for each edge of viewport
          find intersection point
          pick “nearest” point
      if anything is left, draw it
 what do we mean by “nearest”?
 how can we optimize this?            B
                                  D
                              C
                        A




Trivial Accepts

   big optimization: trivial accept/rejects
   Q: how can we quickly determine
   whether a line segment is entirely
   inside the viewport?
   A: test both endpoints.




                                              16
Trivial Rejects

Q: how can we know a line is outside
viewport?
A: if both endpoints on wrong side of
same edge, can trivially reject line




Clipping Lines To Viewport
combining trivial accepts/rejects
  trivially accept lines with both endpoints inside all
  edges of the viewport
  trivially reject lines with both endpoints outside the
  same edge of the viewport
  otherwise, reduce to trivial cases by splitting into
  two segments




                                                           17
Line Clipping Algorithms

Three cases:
  Segment is entirely inside the window -
  Accept
  Segment is entirely outside the window -
  Reject
  Segment intersects the boundary - Clip




Line Segment Clipping

If both endpoints are inside the
window, the entire segment is inside:
trivial accept
If one endpoint is inside, and the other
is outside, line segment must be split.
What happens when both endpoints
are outside?




                                             18
Clipping Lines
  (xl, yt)                 (xr, yt)
                                      A point is visible if

                                          xl < x < xr
             (x, y)                           and
                                          yb < y < yt

  (xl, yb)                 (xr, yb)


 A line is completely visible if both of its end points
 are in the window.
 Brute Force Method - Solve simultaneous
 equations for intersections of lines with window
 edges.




Cohen-Sutherland Clipping
Region Checks: Trivially reject or accept
lines and points.
Fast for large windows (everything is inside)
and for small windows (everything is
outside).
Each vertex is assigned a four-bit outcode.




                                                              19
Cohen-Sutherland 2D clipping

4 regions are defined – outside the clip
window
  TOP
  BOTTOM
  LEFT                    P2
  RIGHT




                                             P1




Cohen-Sutherland Algorithm

Assign a 4-digit binary outcode to each
of the 9 regions defined by the
window:


     1001          1000        1010
                                      ymax

     0001          0000        0010
                                      ymin
     0101          0100        0110
            xmin          xmax




                                                  20
Cohen-Sutherland Algorithm



1001          1000             1010                 bit condition
                                      ymax
                                                    1    y > ymax
0001          0000             0010
                                                    2    y < ymin
                                      ymin
                                                    3    x > xmax
0101          0100             0110
                                                    4    x < xmin
       xmin            xmax




   The 4-bit codes

   A 4-bit code is assigned to each
   point
   This code is sometimes called a
   Cohen-Sutherland region code
   LEFT              bit   1   =   binary    0001
   RIGHT             bit   2   =   binary    0010
   BOTTOM            bit   3   =   binary    0100
   TOP               bit   4   =   binary    1000


   So a point coded 0001 is LEFT of the clip
   window, etc.




                                                                    21
Cohen-Sutherland region codes

The point (65, 50) is above and to the
right of the clip window,
Therefore gets the code: 1010

                                    (65, 50)



                (10, 40)
                                    (60, 40)




                (10, 10)           (60, 10)




Cohen-Sutherland region codes

1000 indicates the TOP region
0010 indicates the RIGHT region
the 4 bit Cohen-Sutherland code
is formed by a logical OR of all region
codes


         1000              TOP
  OR 0010                  RIGHT
  ------------------
  =      1010




                                               22
How the codes are useful
    Why bother encoding points with 4-bit
    Cohen-Sutherland region codes?
    Can make some quick decisions
      If code is zero (0000) point is inside window
      If code is non-zero point is outside window


    For the two endpoints of a line
      If codes for both endpoints are zero,
      whole line is inside window
      If (logical) AND of codes for endpoints is non-zero,
      the endpoints must have a region in common …
      So the whole line must be outside clip window




Some lines and their endpoint codes

                    TOP BOTTOM RIGHT LEFT

    Line1   codes   are   1001 and 0000
    Line2   codes   are   0000 and 0000 << inside
    Line3   codes   are   1000 and 0100
    Line4   codes   are   1010 and 0110 << outside
                     L in e 1

                                                      L in e 4
                     L in e 2


                                  L in e 3




                                                                 23
Clipping from region codes

To clip a line based on region codes:
  Choose an endpoint that is OUTSIDE clip
  window (I.e. non-zero code)
  Check first bit (TOP) – if set, clip
  intersection from point to TOP of clip
  window
  Check second bit (BOTTOM) and so on




Cohen-Sutherland Algorithm

Compute the outcodes C1 and C2
corresponding to both segment
endpoints.
If ((C1 | C2) == 0): Trivial Accept
If ((C1 & C2) != 0): Trivial Reject
Otherwise, split segment into two
parts. Reject one part, and repeat the
procedure on the remaining part.
What edge should be intersected ?




                                            24
Example
                            D
                                     C
                                                                     ymax
                                         B
Outcode(A) = 0000                                 A
                                                                     ymin
Outcode(D) = 1001

No trivial accept/reject          xmin                xmax

Clip (A,D) with y = ymax, splitting it into (A,B) and (B,D)
Reject (B,D)
Proceed with (A,B)




      Example

                                                                 E
                                                                     ymax
                                                             D
                                                      C
Outcode(A) = 0100
                                              B                      ymin
Outcode(E) = 1010

No trivial accept/reject                  A
                                  xmin                xmax

Clip (A,E) with y = ymax, splitting it into (A,D) and (D,E)
Reject (D,E)
Proceed with (A,D)




                                                                            25
Example


                                                               ymax
                                                           D
                                                   C
Outcode(A) = 0100
Outcode(A)
                                               B               ymin
Outcode(D) = 0010
Outcode(D)

No trivial accept/reject                   A
                                    xmin            xmax

Clip (A,D) with y = ymin, splitting it into (A,B) and (B,D)
Reject (A,B)
Proceed with (B,D)




       Example


                                                               ymax
                                                           D
                                                   C
Outcode(B) = 0000
Outcode(B)
                                               B               ymin
Outcode(D) = 0010
Outcode(D)

No trivial accept/reject            xmin            xmax

Clip (B,D) with x = xmax, splitting it into (B,C) and (C,D)
Reject (C,D)
Proceed with (B,C)




                                                                      26
Clipping a line

Choose point P2 (code is 1000)

                     P2




                                         P1
Clip from point to TOP of clip window



                                        P1




Clipping a line

Choose point P1 (code is 0110)




Bit 1 (TOP) not set                     P1

Bit 2 (BOTTOM) set – so clip bottom




                                              27
Clipping a line




  Bit 3 (RIGHT) set – so clip right




  Bit 4 (LEFT) not set – so clipping
  finished




  How to clip a line

Need to know                            xmin
  End points of line
  (x1, y1) – (x2, y2)                          (x2, y2)
  X or Y value defining      (x1, y1)
  clip window edge


                          (newx, newy)

(similar triangles and line gradient)
m = (y2 – y1) / (x2 – x1); // (gradient)
newx = xwmin;
newy = y1 + m*(xwmin – x1)




                                                          28
Cohen-Sutherland Review


       Use opcodes to quickly eliminate/include
       lines
          Best algorithm when trivial accepts/rejects
          are common
       Must compute viewing window clipping of
       remaining lines
          Non-trivial clipping cost
          Redundant clipping of some lines
    More efficient algorithms exist




    Solving Simultaneous Equations


Equation of a line
  Slope-intercept (explicit equation): y = mx + b
  Implicit Equation: Ax + By + C = 0
  Parametric Equation: Line defined by two points,
  P0 and P1
    P(t) = P0 + (P1 - P0) t, where P is a vector [x, y]T

    x(t) = x0 + (x1 - x0) t
    y(t) = y0 + (y1 - y0) t




                                                           29
Parametric Line Equation


Describes a finite line
Works with vertical lines (like the viewport
edge)
  0 <=t <= 1
    Defines line between P0 and P1
  t<0
    Defines line before P0
  t>1
    Defines line after P1




   Parametric Lines and Clipping


Define each line in parametric form:
   P0(t)…Pn-1(t)
Define each edge of view window in
parametric form:
   PL(t), PR(t), PT(t), PB(t)
Perform Cohen-Sutherland intersection
tests using appropriate view window edge
and line




                                               30
Line / Edge Clipping Equations


Faster line clippers use parametric equations
Line 0:
  x0 = x00 + (x01 - x00) t0
  y0 = y00 + (y01 - y00) t0


View Window Edge L:
  xL = xL0 + (xL1 - xL0) tL
  yL = yL0 + (yL1 - yL0) tL


x00 + (x01 - x00) t0 = xL0 + (xL1 - xL0) tL
y00 + (y01 - y00) t0 = yL0 + (yL1 - yL0) tL
  Solve for t0 and/or tL




   Cyrus-Beck Algorithm

   We wish to optimize line/line
   intersection
      Start with parametric equation of line:
          P(t) = P0 + (P1 - P0) t
      And a point and normal for each edge
          PL, NL




                                                31
Cyrus-Beck Algorithm

Find t such that                               P1
                                      PL
NL [P(t) - PL] = 0


                          P(t)
                                      Inside
                     P0
                                NL
Substitute line equation for P(t):
   NL [P0 + (P1 - P0) t - PL] = 0
Solve for t
   t = NL [PL – P0] / -NL [P1 - P0]




   Cyrus-Beck Algorithm

Compute t for line intersection with all four
edges
Discard all (t < 0) and (t > 1)
Classify each remaining intersection as
  Potentially Entering (PE)
  Potentially Leaving (PL)
NL [P1 - P0] > 0 implies PL
NL [P1 - P0] < 0 implies PE

  Note that we computed this term when computing t so
  we can keep it around




                                                        32
Cyrus-Beck Algorithm


       Compute PE with largest t
       Compute PL with smallest t
       Clip to these two points
                              PL P1
                                PL



               PE
        PE

          P0




    Cyrus-Beck Algorithm


Because of horizontal and vertical clip lines:
  Many computations reduce
Normals: (-1, 0), (1, 0), (0, -1), (0, 1)
Pick constant points on edges
solution for t:
  -(x0 - xleft) / (x1 - x0)
  (x0 - xright) / -(x1 - x0)
  -(y0 - ybottom) / (y1 - y0)
  (y0 - ytop) / -(y1 - y0)




                                                 33
Comparison


Cohen-Sutherland
   Repeated clipping is expensive
   Best used when trivial acceptance and rejection is
   possible for most lines
Cyrus-Beck
   Computation of t-intersections is cheap
   Computation of (x,y) clip points is only done once
   Algorithm doesn’t consider trivial accepts/rejects
   Best when many lines must be clipped
Liang-Barsky: Optimized Cyrus-Beck
Nicholl et al.: Fastest, but doesn’t do 3D




                                                        34

Weitere ähnliche Inhalte

Was ist angesagt?

2D viewing & clipping
2D viewing & clipping2D viewing & clipping
2D viewing & clippingMdAlAmin187
 
3 d geometric transformations
3 d geometric transformations3 d geometric transformations
3 d geometric transformationsMohd Arif
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmJyotiraman De
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fillwahab13
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingArvind Kumar
 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithmPooja Dixit
 
Visible Surface Detection
Visible Surface DetectionVisible Surface Detection
Visible Surface DetectionAmitBiswas99
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithmAparna Joshi
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removalPunyajoy Saha
 
Clipping in Computer Graphics
Clipping in Computer Graphics Clipping in Computer Graphics
Clipping in Computer Graphics Barani Tharan
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphicsShaishavShah8
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clippingMani Kanth
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)Timbal Mayank
 

Was ist angesagt? (20)

Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Depth Buffer Method
Depth Buffer MethodDepth Buffer Method
Depth Buffer Method
 
2D viewing & clipping
2D viewing & clipping2D viewing & clipping
2D viewing & clipping
 
Shading
ShadingShading
Shading
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
3 d geometric transformations
3 d geometric transformations3 d geometric transformations
3 d geometric transformations
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal Algorithm
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
 
Cyrus beck line clipping algorithm
Cyrus beck line clipping algorithmCyrus beck line clipping algorithm
Cyrus beck line clipping algorithm
 
Visible Surface Detection
Visible Surface DetectionVisible Surface Detection
Visible Surface Detection
 
Polygon filling algorithm
Polygon filling algorithmPolygon filling algorithm
Polygon filling algorithm
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
Clipping in Computer Graphics
Clipping in Computer Graphics Clipping in Computer Graphics
Clipping in Computer Graphics
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Clipping
ClippingClipping
Clipping
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
Spline representations
Spline representationsSpline representations
Spline representations
 

Ähnlich wie Clipping

CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9fungfung Chen
 
CG OpenGL Shadows + Light + Texture -course 10
CG OpenGL Shadows + Light + Texture -course 10CG OpenGL Shadows + Light + Texture -course 10
CG OpenGL Shadows + Light + Texture -course 10fungfung Chen
 
Shadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL HardwareShadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL HardwareMark Kilgard
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2Sardar Alam
 
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation PipelineComputer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline💻 Anton Gerdelan
 
Multidisciplinary Design Optimization of Supersonic Transport Wing Using Surr...
Multidisciplinary Design Optimization of Supersonic Transport Wing Using Surr...Multidisciplinary Design Optimization of Supersonic Transport Wing Using Surr...
Multidisciplinary Design Optimization of Supersonic Transport Wing Using Surr...Masahiro Kanazaki
 
CS 354 Acceleration Structures
CS 354 Acceleration StructuresCS 354 Acceleration Structures
CS 354 Acceleration StructuresMark Kilgard
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)Michael Heron
 
OpenGL Transformation
OpenGL TransformationOpenGL Transformation
OpenGL TransformationSandip Jadhav
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardwarestefan_b
 
GFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ESGFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ESPrabindh Sundareson
 
Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well Mark Kilgard
 
CG simple openGL point & line-course 2
CG simple openGL point & line-course 2CG simple openGL point & line-course 2
CG simple openGL point & line-course 2fungfung Chen
 
3 projection computer graphics
3 projection computer graphics3 projection computer graphics
3 projection computer graphicscairo university
 
Workflows for developing next gen 3D browser games
Workflows for developing next gen 3D browser gamesWorkflows for developing next gen 3D browser games
Workflows for developing next gen 3D browser gamesMichael Plank
 
Accommodation-invariant Computational Near-eye Displays - SIGGRAPH 2017
Accommodation-invariant Computational Near-eye Displays - SIGGRAPH 2017Accommodation-invariant Computational Near-eye Displays - SIGGRAPH 2017
Accommodation-invariant Computational Near-eye Displays - SIGGRAPH 2017StanfordComputationalImaging
 
Introduction To Massive Model Visualization
Introduction To Massive Model VisualizationIntroduction To Massive Model Visualization
Introduction To Massive Model Visualizationpjcozzi
 
CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8fungfung Chen
 
Casing3d opengl
Casing3d openglCasing3d opengl
Casing3d openglgowell
 

Ähnlich wie Clipping (20)

CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9
 
CG OpenGL Shadows + Light + Texture -course 10
CG OpenGL Shadows + Light + Texture -course 10CG OpenGL Shadows + Light + Texture -course 10
CG OpenGL Shadows + Light + Texture -course 10
 
Shadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL HardwareShadow Mapping with Today's OpenGL Hardware
Shadow Mapping with Today's OpenGL Hardware
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2
 
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation PipelineComputer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline
Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline
 
Multidisciplinary Design Optimization of Supersonic Transport Wing Using Surr...
Multidisciplinary Design Optimization of Supersonic Transport Wing Using Surr...Multidisciplinary Design Optimization of Supersonic Transport Wing Using Surr...
Multidisciplinary Design Optimization of Supersonic Transport Wing Using Surr...
 
CS 354 Acceleration Structures
CS 354 Acceleration StructuresCS 354 Acceleration Structures
CS 354 Acceleration Structures
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)
 
OpenGL Transformation
OpenGL TransformationOpenGL Transformation
OpenGL Transformation
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardware
 
GFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ESGFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ES
 
Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well
 
Notes04.pdf
Notes04.pdfNotes04.pdf
Notes04.pdf
 
CG simple openGL point & line-course 2
CG simple openGL point & line-course 2CG simple openGL point & line-course 2
CG simple openGL point & line-course 2
 
3 projection computer graphics
3 projection computer graphics3 projection computer graphics
3 projection computer graphics
 
Workflows for developing next gen 3D browser games
Workflows for developing next gen 3D browser gamesWorkflows for developing next gen 3D browser games
Workflows for developing next gen 3D browser games
 
Accommodation-invariant Computational Near-eye Displays - SIGGRAPH 2017
Accommodation-invariant Computational Near-eye Displays - SIGGRAPH 2017Accommodation-invariant Computational Near-eye Displays - SIGGRAPH 2017
Accommodation-invariant Computational Near-eye Displays - SIGGRAPH 2017
 
Introduction To Massive Model Visualization
Introduction To Massive Model VisualizationIntroduction To Massive Model Visualization
Introduction To Massive Model Visualization
 
CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8CG OpenGL 3D object representations-course 8
CG OpenGL 3D object representations-course 8
 
Casing3d opengl
Casing3d openglCasing3d opengl
Casing3d opengl
 

Mehr von johanna20

Digitales examen 1
Digitales examen 1Digitales examen 1
Digitales examen 1johanna20
 
Digitales examen 2
Digitales examen 2Digitales examen 2
Digitales examen 2johanna20
 
Digitales examen 1
Digitales examen 1Digitales examen 1
Digitales examen 1johanna20
 
Datos Escalares
Datos EscalaresDatos Escalares
Datos Escalaresjohanna20
 
examen fisica c
examen fisica cexamen fisica c
examen fisica cjohanna20
 
Examen Fisica
Examen FisicaExamen Fisica
Examen Fisicajohanna20
 
EXamen Fisica Parcial Termino2004
EXamen Fisica Parcial Termino2004EXamen Fisica Parcial Termino2004
EXamen Fisica Parcial Termino2004johanna20
 
Gramaticas Regulares
Gramaticas RegularesGramaticas Regulares
Gramaticas Regularesjohanna20
 
Ciclo Contable De Una Empresa Comercial
Ciclo Contable De Una Empresa  ComercialCiclo Contable De Una Empresa  Comercial
Ciclo Contable De Una Empresa Comercialjohanna20
 
Ajustes y Actualizaciones
Ajustes y ActualizacionesAjustes y Actualizaciones
Ajustes y Actualizacionesjohanna20
 
Ciclo Contable De Una Empresa Comercial Parte Ii.Ppt(3parte)
Ciclo Contable De Una Empresa Comercial Parte Ii.Ppt(3parte)Ciclo Contable De Una Empresa Comercial Parte Ii.Ppt(3parte)
Ciclo Contable De Una Empresa Comercial Parte Ii.Ppt(3parte)johanna20
 
Ciclo Contable De Una Empresa Comercial Parte I
Ciclo Contable De Una Empresa  Comercial Parte ICiclo Contable De Una Empresa  Comercial Parte I
Ciclo Contable De Una Empresa Comercial Parte Ijohanna20
 
Ciclo Contable
Ciclo ContableCiclo Contable
Ciclo Contablejohanna20
 
Conceptos Basicos
Conceptos BasicosConceptos Basicos
Conceptos Basicosjohanna20
 
Introduccion A Sistemas De Informacion
Introduccion A Sistemas De InformacionIntroduccion A Sistemas De Informacion
Introduccion A Sistemas De Informacionjohanna20
 

Mehr von johanna20 (20)

Digitales examen 1
Digitales examen 1Digitales examen 1
Digitales examen 1
 
Digitales examen 2
Digitales examen 2Digitales examen 2
Digitales examen 2
 
Digitales examen 1
Digitales examen 1Digitales examen 1
Digitales examen 1
 
Adt
AdtAdt
Adt
 
Arreglos
ArreglosArreglos
Arreglos
 
Datos Escalares
Datos EscalaresDatos Escalares
Datos Escalares
 
examen fisica c
examen fisica cexamen fisica c
examen fisica c
 
Examen Fisica
Examen FisicaExamen Fisica
Examen Fisica
 
EXamen Fisica Parcial Termino2004
EXamen Fisica Parcial Termino2004EXamen Fisica Parcial Termino2004
EXamen Fisica Parcial Termino2004
 
Gramaticas Regulares
Gramaticas RegularesGramaticas Regulares
Gramaticas Regulares
 
Ciclo Contable De Una Empresa Comercial
Ciclo Contable De Una Empresa  ComercialCiclo Contable De Una Empresa  Comercial
Ciclo Contable De Una Empresa Comercial
 
Ajustes y Actualizaciones
Ajustes y ActualizacionesAjustes y Actualizaciones
Ajustes y Actualizaciones
 
Ciclo Contable De Una Empresa Comercial Parte Ii.Ppt(3parte)
Ciclo Contable De Una Empresa Comercial Parte Ii.Ppt(3parte)Ciclo Contable De Una Empresa Comercial Parte Ii.Ppt(3parte)
Ciclo Contable De Una Empresa Comercial Parte Ii.Ppt(3parte)
 
Ciclo Contable De Una Empresa Comercial Parte I
Ciclo Contable De Una Empresa  Comercial Parte ICiclo Contable De Una Empresa  Comercial Parte I
Ciclo Contable De Una Empresa Comercial Parte I
 
Ciclo Contable
Ciclo ContableCiclo Contable
Ciclo Contable
 
Conceptos Basicos
Conceptos BasicosConceptos Basicos
Conceptos Basicos
 
Introduccion A Sistemas De Informacion
Introduccion A Sistemas De InformacionIntroduccion A Sistemas De Informacion
Introduccion A Sistemas De Informacion
 
Color
ColorColor
Color
 
Iluminacion
IluminacionIluminacion
Iluminacion
 
Hilos
HilosHilos
Hilos
 

Kürzlich hochgeladen

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Kürzlich hochgeladen (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

Clipping

  • 1. Clipping Learning outcomes for this lecture You will understand What is meant by ‘clipping’ 2D clipping concepts 3D clipping concepts Different kinds of clipping The Cohen-Sutherland 2D region-coding clipping technique Be able to calculate Cohen-Sutherland 2D region-coding 1
  • 2. Plan Review of rendering pipeline Clipping The Graphics Pipeline Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display 2
  • 3. Modeling Transformations Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Object space World space Clipping x' a b c d x Projection y' e f g h y (to Screen Space) = Scan Conversion z' i j k l z (Rasterization) 1 0 0 0 1 1 Visibility / Display Illumination (Shading) (Lighting) Vertices lit (shaded) according to Modeling material properties, surface Transformations properties (normal) and light Local lighting model Illumination (Diffuse, Ambient, Phong, etc.) (Shading) Φ Viewing Transformation (Perspective / Orthographic) ( L(ωr ) = k a + k d (n ⋅ l) + k s (v ⋅ r ) q ) 4π d s 2 Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display 3
  • 4. Viewing Transformation Modeling Viewing position is transformed to Transformations origin & direction is oriented along some axis (usually z) Illumination (Shading) Eye space Viewing Transformation (Perspective / Orthographic) Clipping Projection World space (to Screen Space) x' a b c d x Scan Conversion e f g h y Yet another y' (Rasterization) 4x4 matrix z' = i j k l z Visibility / Display 1 0 0 0 1 1 Clipping Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display 4
  • 5. Games: pipeline Flight simulation: pipeline (painter for long time) 5
  • 7. Clipping Clipping means Identifying portions of a scene that are inside (or outside) a specified region Examples Multiple viewports on a device Deciding how much of a games world the player can see Clipping Clipping means Identifying portions of a scene that are inside (or outside) a specified region Examples Multiple viewports on a device Deciding how much of a games world the player can see Player can’t see this far yet 7
  • 8. Clipping we’ve been assuming that all primitives (lines, triangles, polygons) lie entirely within the viewport in general, this assumption will not hold: Clipping Eliminate portions of objects outside the viewing frustum View Frustum boundaries of the image plane projected in 3D far a near & far clipping plane top User may define left additional clipping planes near right bottom 8
  • 9. Why clip? Avoid degeneracies Don’t draw stuff behind the eye Avoid division by 0 and overflow Efficiency Don’t waste time on objects outside the image boundary Other graphics applications (often non-convex) Hidden-surface removal, Shadows, Picking, Binning, CSG (Boolean) operations (2D & 3D) Why Clip? bad idea to rasterize outside of framebuffer bounds also, don’t waste time scan converting pixels outside window could be billions of pixels for very close objects! 9
  • 10. When to clip? Before perspective transform in 3D space Use the equation of 6 planes Natural, not too degenerate In homogeneous coordinates after perspective transform (Clip space) Before perspective divide (4D space, weird w values) Canonical,independent of camera The simplest to implement in fact In the transformed 3D screen space after perspective division Problem: objects in the plane of the camera Clipping strategies Don’t clip (and hope for the best) Clip on-the-fly during rasterization Analytical clipping: alter input geometry 10
  • 11. Requirements for clipping Is (x, y) inside or outside a given region For 2D graphics the region defining what is to be clipped is called The clip window Clip window Clipping analytically calculating the portions of primitives within the viewport 11
  • 12. Interior and exterior clipping interior clipping what is to be saved is inside the clip window exterior clipping what is to be saved is outside clip window Interior clipping - keep point P2 P2 (x2, y2) Interior and exterior clipping Exterior clipping Clip window - keep point P1 P1 (x1, y1) We shall assume interior clipping for now But you must be aware of exterior clipping too 12
  • 13. Overview of types of clipping All-or-none clipping If any part of object outside clip window whole object is rejected Point clipping Only keep points inside clip window Line clipping Only keep segment of line inside clip window Polygon clipping Only keep sub-polygons inside clip window Before and after POINT clipping Before P2 P3 P1 P4 After P3 P1 13
  • 14. Point Classification How can we tell if a point is inside a rectangular window? ymax xmin ≤ x ≤ xmax ymin ≤ y ≤ ymax ymin xmin xmax Line Clipping Algorithms Goal: avoid drawing primitives that are outside the viewing window. The most common case: clipping line segments against a rectangular window 14
  • 15. Before and after LINE clipping Before P2 After P1 P2’ P1’ Before and after POLYGON clipping Before After 15
  • 16. Clipping Lines naïve approach to clipping lines: for each line segment for each edge of viewport find intersection point pick “nearest” point if anything is left, draw it what do we mean by “nearest”? how can we optimize this? B D C A Trivial Accepts big optimization: trivial accept/rejects Q: how can we quickly determine whether a line segment is entirely inside the viewport? A: test both endpoints. 16
  • 17. Trivial Rejects Q: how can we know a line is outside viewport? A: if both endpoints on wrong side of same edge, can trivially reject line Clipping Lines To Viewport combining trivial accepts/rejects trivially accept lines with both endpoints inside all edges of the viewport trivially reject lines with both endpoints outside the same edge of the viewport otherwise, reduce to trivial cases by splitting into two segments 17
  • 18. Line Clipping Algorithms Three cases: Segment is entirely inside the window - Accept Segment is entirely outside the window - Reject Segment intersects the boundary - Clip Line Segment Clipping If both endpoints are inside the window, the entire segment is inside: trivial accept If one endpoint is inside, and the other is outside, line segment must be split. What happens when both endpoints are outside? 18
  • 19. Clipping Lines (xl, yt) (xr, yt) A point is visible if xl < x < xr (x, y) and yb < y < yt (xl, yb) (xr, yb) A line is completely visible if both of its end points are in the window. Brute Force Method - Solve simultaneous equations for intersections of lines with window edges. Cohen-Sutherland Clipping Region Checks: Trivially reject or accept lines and points. Fast for large windows (everything is inside) and for small windows (everything is outside). Each vertex is assigned a four-bit outcode. 19
  • 20. Cohen-Sutherland 2D clipping 4 regions are defined – outside the clip window TOP BOTTOM LEFT P2 RIGHT P1 Cohen-Sutherland Algorithm Assign a 4-digit binary outcode to each of the 9 regions defined by the window: 1001 1000 1010 ymax 0001 0000 0010 ymin 0101 0100 0110 xmin xmax 20
  • 21. Cohen-Sutherland Algorithm 1001 1000 1010 bit condition ymax 1 y > ymax 0001 0000 0010 2 y < ymin ymin 3 x > xmax 0101 0100 0110 4 x < xmin xmin xmax The 4-bit codes A 4-bit code is assigned to each point This code is sometimes called a Cohen-Sutherland region code LEFT bit 1 = binary 0001 RIGHT bit 2 = binary 0010 BOTTOM bit 3 = binary 0100 TOP bit 4 = binary 1000 So a point coded 0001 is LEFT of the clip window, etc. 21
  • 22. Cohen-Sutherland region codes The point (65, 50) is above and to the right of the clip window, Therefore gets the code: 1010 (65, 50) (10, 40) (60, 40) (10, 10) (60, 10) Cohen-Sutherland region codes 1000 indicates the TOP region 0010 indicates the RIGHT region the 4 bit Cohen-Sutherland code is formed by a logical OR of all region codes 1000 TOP OR 0010 RIGHT ------------------ = 1010 22
  • 23. How the codes are useful Why bother encoding points with 4-bit Cohen-Sutherland region codes? Can make some quick decisions If code is zero (0000) point is inside window If code is non-zero point is outside window For the two endpoints of a line If codes for both endpoints are zero, whole line is inside window If (logical) AND of codes for endpoints is non-zero, the endpoints must have a region in common … So the whole line must be outside clip window Some lines and their endpoint codes TOP BOTTOM RIGHT LEFT Line1 codes are 1001 and 0000 Line2 codes are 0000 and 0000 << inside Line3 codes are 1000 and 0100 Line4 codes are 1010 and 0110 << outside L in e 1 L in e 4 L in e 2 L in e 3 23
  • 24. Clipping from region codes To clip a line based on region codes: Choose an endpoint that is OUTSIDE clip window (I.e. non-zero code) Check first bit (TOP) – if set, clip intersection from point to TOP of clip window Check second bit (BOTTOM) and so on Cohen-Sutherland Algorithm Compute the outcodes C1 and C2 corresponding to both segment endpoints. If ((C1 | C2) == 0): Trivial Accept If ((C1 & C2) != 0): Trivial Reject Otherwise, split segment into two parts. Reject one part, and repeat the procedure on the remaining part. What edge should be intersected ? 24
  • 25. Example D C ymax B Outcode(A) = 0000 A ymin Outcode(D) = 1001 No trivial accept/reject xmin xmax Clip (A,D) with y = ymax, splitting it into (A,B) and (B,D) Reject (B,D) Proceed with (A,B) Example E ymax D C Outcode(A) = 0100 B ymin Outcode(E) = 1010 No trivial accept/reject A xmin xmax Clip (A,E) with y = ymax, splitting it into (A,D) and (D,E) Reject (D,E) Proceed with (A,D) 25
  • 26. Example ymax D C Outcode(A) = 0100 Outcode(A) B ymin Outcode(D) = 0010 Outcode(D) No trivial accept/reject A xmin xmax Clip (A,D) with y = ymin, splitting it into (A,B) and (B,D) Reject (A,B) Proceed with (B,D) Example ymax D C Outcode(B) = 0000 Outcode(B) B ymin Outcode(D) = 0010 Outcode(D) No trivial accept/reject xmin xmax Clip (B,D) with x = xmax, splitting it into (B,C) and (C,D) Reject (C,D) Proceed with (B,C) 26
  • 27. Clipping a line Choose point P2 (code is 1000) P2 P1 Clip from point to TOP of clip window P1 Clipping a line Choose point P1 (code is 0110) Bit 1 (TOP) not set P1 Bit 2 (BOTTOM) set – so clip bottom 27
  • 28. Clipping a line Bit 3 (RIGHT) set – so clip right Bit 4 (LEFT) not set – so clipping finished How to clip a line Need to know xmin End points of line (x1, y1) – (x2, y2) (x2, y2) X or Y value defining (x1, y1) clip window edge (newx, newy) (similar triangles and line gradient) m = (y2 – y1) / (x2 – x1); // (gradient) newx = xwmin; newy = y1 + m*(xwmin – x1) 28
  • 29. Cohen-Sutherland Review Use opcodes to quickly eliminate/include lines Best algorithm when trivial accepts/rejects are common Must compute viewing window clipping of remaining lines Non-trivial clipping cost Redundant clipping of some lines More efficient algorithms exist Solving Simultaneous Equations Equation of a line Slope-intercept (explicit equation): y = mx + b Implicit Equation: Ax + By + C = 0 Parametric Equation: Line defined by two points, P0 and P1 P(t) = P0 + (P1 - P0) t, where P is a vector [x, y]T x(t) = x0 + (x1 - x0) t y(t) = y0 + (y1 - y0) t 29
  • 30. Parametric Line Equation Describes a finite line Works with vertical lines (like the viewport edge) 0 <=t <= 1 Defines line between P0 and P1 t<0 Defines line before P0 t>1 Defines line after P1 Parametric Lines and Clipping Define each line in parametric form: P0(t)…Pn-1(t) Define each edge of view window in parametric form: PL(t), PR(t), PT(t), PB(t) Perform Cohen-Sutherland intersection tests using appropriate view window edge and line 30
  • 31. Line / Edge Clipping Equations Faster line clippers use parametric equations Line 0: x0 = x00 + (x01 - x00) t0 y0 = y00 + (y01 - y00) t0 View Window Edge L: xL = xL0 + (xL1 - xL0) tL yL = yL0 + (yL1 - yL0) tL x00 + (x01 - x00) t0 = xL0 + (xL1 - xL0) tL y00 + (y01 - y00) t0 = yL0 + (yL1 - yL0) tL Solve for t0 and/or tL Cyrus-Beck Algorithm We wish to optimize line/line intersection Start with parametric equation of line: P(t) = P0 + (P1 - P0) t And a point and normal for each edge PL, NL 31
  • 32. Cyrus-Beck Algorithm Find t such that P1 PL NL [P(t) - PL] = 0 P(t) Inside P0 NL Substitute line equation for P(t): NL [P0 + (P1 - P0) t - PL] = 0 Solve for t t = NL [PL – P0] / -NL [P1 - P0] Cyrus-Beck Algorithm Compute t for line intersection with all four edges Discard all (t < 0) and (t > 1) Classify each remaining intersection as Potentially Entering (PE) Potentially Leaving (PL) NL [P1 - P0] > 0 implies PL NL [P1 - P0] < 0 implies PE Note that we computed this term when computing t so we can keep it around 32
  • 33. Cyrus-Beck Algorithm Compute PE with largest t Compute PL with smallest t Clip to these two points PL P1 PL PE PE P0 Cyrus-Beck Algorithm Because of horizontal and vertical clip lines: Many computations reduce Normals: (-1, 0), (1, 0), (0, -1), (0, 1) Pick constant points on edges solution for t: -(x0 - xleft) / (x1 - x0) (x0 - xright) / -(x1 - x0) -(y0 - ybottom) / (y1 - y0) (y0 - ytop) / -(y1 - y0) 33
  • 34. Comparison Cohen-Sutherland Repeated clipping is expensive Best used when trivial acceptance and rejection is possible for most lines Cyrus-Beck Computation of t-intersections is cheap Computation of (x,y) clip points is only done once Algorithm doesn’t consider trivial accepts/rejects Best when many lines must be clipped Liang-Barsky: Optimized Cyrus-Beck Nicholl et al.: Fastest, but doesn’t do 3D 34