SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
15-462 Computer Graphics I
Lecture 13


Clipping

                              Line Clipping
                              Polygon Clipping
                              Clipping in Three Dimensions
                                                [Angel 8.3-8.7]
March 11, 2003
Frank Pfenning
Carnegie Mellon University
http://www.cs.cmu.edu/~fp/courses/graphics/
The Graphics Pipeline, Revisited



• Must eliminate objects outside viewing frustum
• Tied in with projections
     – Clipping: object space (eye coordinates)
     – Scissoring: image space (pixels in frame buffer)
• Introduce clipping in stages
     – 2D (for simplicity)
     – 3D (as in OpenGL)
• In a later lecture: scissoring
03/11/2003               15-462 Graphics I                2
Transformations and Projections
•     Sequence applied in many implementations
     1.      Object coordinates to
     2.      Eye coordinates to
     3.      Clip coordinates to
     4.      Normalized device coordinates to
     5.      Screen coordinates




03/11/2003                   15-462 Graphics I   3
Clipping Against a Frustum
• General case of frustum (truncated pyramid)
              y
                                                      clipped line
                           x


                                                                z
             image plane

                           near
                                              far


• Clipping is tricky because of frustum shape


03/11/2003                        15-462 Graphics I                  4
Perspective Normalization
 • Solution:
        – Implement perspective projection by perspective
          normalization and orthographic projection
        – Perspective normalization is a homogeneous tfm.
    y                                                     y               clipped line
                         clipped line
              x                                       1               x
                                                              1
                                                   near                       far
                               z                      0           1       z
image plane
         near          far
                                                 See [Angel Ch. 5.8]


 03/11/2003                  15-462 Graphics I                                      5
The Normalized Frustum
• OpenGL uses -1 · x,y,z · 1 (others possible)
• Clip against resulting cube
• Clipping against programmer-specified planes
  is different and more expensive
• Often a useful programming device




03/11/2003         15-462 Graphics I             6
The Viewport Transformation
•     Transformation sequence again:
     1.      Camera: From object coordinates to eye coords
     2.      Perspective normalization: to clip coordinates
     3.      Clipping
     4.      Perspective division: to normalized device coords.
     5.      Orthographic projection (setting zp = 0)
     6.      Viewport transformation: to screen coordinates
•     Viewport transformation can distort
•     Often in OpenGL: resize callback


03/11/2003                    15-462 Graphics I                   7
Line-Segment Clipping
• General: 3D object against cube
• Simpler case:
     – In 2D: line against square or rectangle
     – Before scan conversion (rasterization)
     – Later: polygon clipping
• Several practical algorithms
     –   Avoid expensive line-rectangle intersections
     –   Cohen-Sutherland Clipping
     –   Liang-Barsky Clipping
     –   Many more [see Foley et al.]

03/11/2003                 15-462 Graphics I            8
Clipping Against Rectangle
• Line-segment clipping: modify endpoints of
  lines to lie within clipping rectangle
• Could calculate intersections of line (segments)
  with clipping rectangle (expensive)




03/11/2003          15-462 Graphics I            9
Cohen-Sutherland Clipping
• Clipping rectangle as intersection of 4 half-
  planes

                                                   y < ymax          y > ymin


                                      ∩
 ymax




  ymin
                interior
                                  =
                                                          x > xmin x < xmax
         xmin              xmax




• Encode results of four half-plane tests
• Generalizes to 3 dimensions (6 half-planes)

03/11/2003                            15-462 Graphics I                         10
Outcodes
• Divide space into 9 regions
• 4-bit outcode determined by comparisons
             1001          1000          1010          bo: y > ymax
                                                       b1: y < ymin
        ymax
                                                       b2: x > xmax
             0001          0000          0010
                                                       b3: x < xmin

        ymin

             0101          0100          0110
                    xmin          xmax

• o1 = outcode(x1,y1) and o2 = outcode(x2,y2)

03/11/2003                         15-462 Graphics I                  11
Cases for Outcodes
• Outcomes: accept, reject, subdivide
   1001             1000          1010


ymax
                                             o1 = o2 = 0000: accept
                                             o1 & o2 ≠ 0000: reject
   0001             0000          0010
                                             o1 = 0000, o2 ≠ 0000: subdiv
                                             o1 ≠ 0000, o2 = 0000: subdiv
ymin                                         o1 & o2 = 0000: subdiv
   0101             0100          0110
             xmin          xmax




03/11/2003                         15-462 Graphics I                   12
Cohen-Sutherland Subdivision
•   Pick outside endpoint (o ≠ 0000)
•   Pick a crossed edge (o = b0b1b2b3 and bk ≠ 0)
•   Compute intersection of this line and this edge
•   Replace endpoint with intersection point
•   Restart with new line segment
     – Outcodes of second point are unchanged
• Must converge (roundoff errors?)




03/11/2003             15-462 Graphics I              13
Liang-Barsky Clipping
• Starting point is parametric form




• Compute four intersections with extended
  clipping rectangle
• Will see that this can be avoided




03/11/2003           15-462 Graphics I       14
Ordering of intersection points




• Order the intersection points
• Figure (a): 1 > α4 > α3 > α2 > α1 > 0
• Figure (b): 1 > α4 > α2 > α3 > α1 > 0

03/11/2003           15-462 Graphics I    15
Liang-Barsky Efficiency Improvements
• Efficiency improvement 1:
     – Compute intersections one by one
     – Often can reject before all four are computed
• Efficiency improvement 2:
     – Equations for α3, α2




     – Compare α3, α2 without floating-point division

03/11/2003               15-462 Graphics I              16
Line-Segment Clipping Assessment
• Cohen-Sutherland
     – Works well if many lines can be rejected early
     – Recursive structure (multiple subdiv) a drawback
• Liang-Barsky
     – Avoids recursive calls (multiple subdiv)
     – Many cases to consider (tedious, but not expensive)
     – Used more often in practice (?)




03/11/2003               15-462 Graphics I                17
Outline
• Line-Segment Clipping
     – Cohen-Sutherland
     – Liang-Barsky
• Polygon Clipping
     – Sutherland-Hodgeman
• Clipping in Three Dimensions




03/11/2003                15-462 Graphics I   18
Polygon Clipping
• Convert a polygon into one ore more polygons
• Their union is intersection with clip window
• Alternatively, we can first tesselate concave
  polygons (OpenGL supported)




03/11/2003         15-462 Graphics I              19
Concave Polygons
• Approach 1: clip and join to a single polygon




• Approach 2: tesselate and clip triangles




03/11/2003          15-462 Graphics I             20
Sutherland-Hodgeman I
• Subproblem:
     – Input: polygon (vertex list) and single clip plane
     – Output: new (clipped) polygon (vertex list)
• Apply once for each clip plane
     – 4 in two dimensions
     – 6 in three dimensions
     – Can arrange in pipeline




03/11/2003                15-462 Graphics I                 21
Sutherland-Hodgeman II
• To clip vertex list (polygon) against half-plane:
     – Test first vertex. Output if inside, otherwise skip.
     – Then loop through list, testing transitions
             •   In-to-in: output vertex
             •   In-to-out: output intersection
             •   out-to-in: output intersection and vertex
             •   out-to-out: no output
     – Will output clipped polygon as vertex list
• May need some cleanup in concave case
• Can combine with Liang-Barsky idea


03/11/2003                          15-462 Graphics I         22
Other Cases and Optimizations
• Curves and surfaces
     – Analytically if possible
     – Through approximating lines and polygons otherwise
• Bounding boxes
     – Easy to calculate and maintain
     – Sometimes big savings




03/11/2003               15-462 Graphics I             23
Outline
• Line-Segment Clipping
     – Cohen-Sutherland
     – Liang-Barsky
• Polygon Clipping
     – Sutherland-Hodgeman
• Clipping in Three Dimensions




03/11/2003                15-462 Graphics I   24
Clipping Against Cube
• Derived from earlier algorithms
• Can allow right parallelepiped




03/11/2003          15-462 Graphics I   25
Cohen-Sutherland in 3D
• Use 6 bits in outcode
     – b4: z > zmax
     – b5: z < zmin
• Other calculations
  as before




03/11/2003             15-462 Graphics I   26
Liang-Barsky in 3D
• Add equation z(α) = (1- α) z1 + α z2
• Solve, for p0 in plane and normal n:



• Yields



• Optimizations as for Liang-Barsky in 2D


03/11/2003          15-462 Graphics I       27
Perspective Normalization
• Intersection simplifies for orthographic viewing
     – One division only (no multiplication)
     – Other Liang-Barsky optimizations also apply
• Otherwise, use perspective normalization
     – Reduces to orthographic case
     – Applies to oblique and perspective viewing




                            Normalization of oblique projections

03/11/2003               15-462 Graphics I                         28
Summary: Clipping
• Clipping line segments to rectangle or cube
     – Avoid expensive multiplications and divisions
     – Cohen-Sutherland or Liang-Barsky
• Clipping to viewing frustum
     – Perspective normalization to orthographic projection
     – Apply clipping to cube from above
• Client-specific clipping
     – Use more general, more expensive form
• Polygon clipping
     – Sutherland-Hodgeman pipeline

03/11/2003               15-462 Graphics I                29
Preview and Announcements
•   Scan conversion
•   Anti-aliasing
•   Other pixel-level operations
•   Assignment 5 due a week from Thursday!
•   Start early!
•   Sriram’s office hours now Mon 4:30-6:30
•   Movie
•   Returning Midterm


03/11/2003           15-462 Graphics I        30

Weitere ähnliche Inhalte

Was ist angesagt?

Cohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmCohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmShilpa Hait
 
Computer Graphic - Clipping
Computer Graphic - ClippingComputer Graphic - Clipping
Computer Graphic - Clipping2013901097
 
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmPolygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmMani Kanth
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clippingavelraj
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
 
Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)Aamir Sohail
 
Lect7 viewing in2d
Lect7 viewing in2dLect7 viewing in2d
Lect7 viewing in2dBCET
 
Cohen and Sutherland Algorithm for 7-8 marks
Cohen and Sutherland Algorithm for 7-8 marksCohen and Sutherland Algorithm for 7-8 marks
Cohen and Sutherland Algorithm for 7-8 marksRehan Khan
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphicsShaishavShah8
 
Cohen sutherland line clipping algorithm
Cohen sutherland line clipping algorithmCohen sutherland line clipping algorithm
Cohen sutherland line clipping algorithmTawfiq Ahmed
 
Cohen sutherland algorithm
Cohen sutherland algorithmCohen sutherland algorithm
Cohen sutherland algorithmFarwa Ansari
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer GraphicsLaxman Puri
 

Was ist angesagt? (20)

Cohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithmCohen-sutherland & liang-basky line clipping algorithm
Cohen-sutherland & liang-basky line clipping algorithm
 
Computer Graphic - Clipping
Computer Graphic - ClippingComputer Graphic - Clipping
Computer Graphic - Clipping
 
06 clipping
06 clipping06 clipping
06 clipping
 
Clipping 22
Clipping 22Clipping 22
Clipping 22
 
Curve clipping
Curve clippingCurve clipping
Curve clipping
 
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithmPolygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
Polygon clipping with sutherland hodgeman algorithm and scan line fill algorithm
 
Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )
 
Clipping2
Clipping2Clipping2
Clipping2
 
Lecture 2d point,curve,text,line clipping
Lecture   2d point,curve,text,line clippingLecture   2d point,curve,text,line clipping
Lecture 2d point,curve,text,line clipping
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)Line clipping algorithm (Detailed)
Line clipping algorithm (Detailed)
 
Lect7 viewing in2d
Lect7 viewing in2dLect7 viewing in2d
Lect7 viewing in2d
 
Cohen and Sutherland Algorithm for 7-8 marks
Cohen and Sutherland Algorithm for 7-8 marksCohen and Sutherland Algorithm for 7-8 marks
Cohen and Sutherland Algorithm for 7-8 marks
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
 
Cohen sutherland line clipping algorithm
Cohen sutherland line clipping algorithmCohen sutherland line clipping algorithm
Cohen sutherland line clipping algorithm
 
Clipping
ClippingClipping
Clipping
 
Cohen sutherland algorithm
Cohen sutherland algorithmCohen sutherland algorithm
Cohen sutherland algorithm
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
 
2D viewing
2D viewing2D viewing
2D viewing
 

Ähnlich wie clipping

Clipping & Rasterization
Clipping & RasterizationClipping & Rasterization
Clipping & RasterizationAhmed Daoud
 
visible surface detection in 3D objects for viewing
visible surface detection in 3D objects for viewingvisible surface detection in 3D objects for viewing
visible surface detection in 3D objects for viewingsrinivasan779644
 
Double Patterning (4/2 update)
Double Patterning (4/2 update)Double Patterning (4/2 update)
Double Patterning (4/2 update)Danny Luk
 
Lecture1616_16827_2D Clipping.ppt
Lecture1616_16827_2D Clipping.pptLecture1616_16827_2D Clipping.ppt
Lecture1616_16827_2D Clipping.pptGaganvirKaur
 
rural marketing ppt
rural marketing pptrural marketing ppt
rural marketing pptelaya1984
 
Visual surface detection i
Visual surface detection   iVisual surface detection   i
Visual surface detection ielaya1984
 
"Fundamentals of Monocular SLAM," a Presentation from Cadence
"Fundamentals of Monocular SLAM," a Presentation from Cadence"Fundamentals of Monocular SLAM," a Presentation from Cadence
"Fundamentals of Monocular SLAM," a Presentation from CadenceEdge AI and Vision Alliance
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmJyotiraman De
 
Vlsi physical design automation on partitioning
Vlsi physical design automation on partitioningVlsi physical design automation on partitioning
Vlsi physical design automation on partitioningSushil Kundu
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3Roziq Bahtiar
 

Ähnlich wie clipping (20)

Clipping & Rasterization
Clipping & RasterizationClipping & Rasterization
Clipping & Rasterization
 
Implementation
ImplementationImplementation
Implementation
 
Surface design and visible surfaces
Surface design and visible surfacesSurface design and visible surfaces
Surface design and visible surfaces
 
Week6.ppt
Week6.pptWeek6.ppt
Week6.ppt
 
Projection Matrices
Projection MatricesProjection Matrices
Projection Matrices
 
Clipping
ClippingClipping
Clipping
 
Lec-4_Rendering-1.pdf
Lec-4_Rendering-1.pdfLec-4_Rendering-1.pdf
Lec-4_Rendering-1.pdf
 
7-Clipping-16 (1).pdf
7-Clipping-16 (1).pdf7-Clipping-16 (1).pdf
7-Clipping-16 (1).pdf
 
visible surface detection in 3D objects for viewing
visible surface detection in 3D objects for viewingvisible surface detection in 3D objects for viewing
visible surface detection in 3D objects for viewing
 
Double Patterning (4/2 update)
Double Patterning (4/2 update)Double Patterning (4/2 update)
Double Patterning (4/2 update)
 
99995327.ppt
99995327.ppt99995327.ppt
99995327.ppt
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Lecture1616_16827_2D Clipping.ppt
Lecture1616_16827_2D Clipping.pptLecture1616_16827_2D Clipping.ppt
Lecture1616_16827_2D Clipping.ppt
 
rural marketing ppt
rural marketing pptrural marketing ppt
rural marketing ppt
 
Visual surface detection i
Visual surface detection   iVisual surface detection   i
Visual surface detection i
 
"Fundamentals of Monocular SLAM," a Presentation from Cadence
"Fundamentals of Monocular SLAM," a Presentation from Cadence"Fundamentals of Monocular SLAM," a Presentation from Cadence
"Fundamentals of Monocular SLAM," a Presentation from Cadence
 
Computer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal AlgorithmComputer Graphics - Hidden Line Removal Algorithm
Computer Graphics - Hidden Line Removal Algorithm
 
Vlsi physical design automation on partitioning
Vlsi physical design automation on partitioningVlsi physical design automation on partitioning
Vlsi physical design automation on partitioning
 
UNIT I_5.pdf
UNIT I_5.pdfUNIT I_5.pdf
UNIT I_5.pdf
 
Open GL T0074 56 sm3
Open GL T0074 56 sm3Open GL T0074 56 sm3
Open GL T0074 56 sm3
 

Mehr von HiteshJain007

Mehr von HiteshJain007 (10)

object 3d(1)
object 3d(1)object 3d(1)
object 3d(1)
 
object 3d(2)
object 3d(2)object 3d(2)
object 3d(2)
 
Raster Display(1)
Raster Display(1)Raster Display(1)
Raster Display(1)
 
02mathematics
02mathematics02mathematics
02mathematics
 
Introduction to Computer Graphics(1)
Introduction to Computer Graphics(1)Introduction to Computer Graphics(1)
Introduction to Computer Graphics(1)
 
Introduction to Computer Graphics(2)
Introduction to Computer Graphics(2)Introduction to Computer Graphics(2)
Introduction to Computer Graphics(2)
 
Graphics pipeline
Graphics pipelineGraphics pipeline
Graphics pipeline
 
Hidden Surfaces
Hidden SurfacesHidden Surfaces
Hidden Surfaces
 
transformation 3d
transformation 3dtransformation 3d
transformation 3d
 
viewing3d pipeline
viewing3d pipelineviewing3d pipeline
viewing3d pipeline
 

Kürzlich hochgeladen

Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICESayali Powar
 
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfTechSoup
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRATanmoy Mishra
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptxSandy Millin
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationMJDuyan
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...raviapr7
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapitolTechU
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxDr. Asif Anas
 
What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?TechSoup
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17Celine George
 
3.21.24 The Origins of Black Power.pptx
3.21.24  The Origins of Black Power.pptx3.21.24  The Origins of Black Power.pptx
3.21.24 The Origins of Black Power.pptxmary850239
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...CaraSkikne1
 
The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsEugene Lysak
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...Nguyen Thanh Tu Collection
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxMYDA ANGELICA SUAN
 

Kürzlich hochgeladen (20)

Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICE
 
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive Education
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 
Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptx
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptx
 
What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17
 
3.21.24 The Origins of Black Power.pptx
3.21.24  The Origins of Black Power.pptx3.21.24  The Origins of Black Power.pptx
3.21.24 The Origins of Black Power.pptx
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...
 
The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George Wells
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptx
 

clipping

  • 1. 15-462 Computer Graphics I Lecture 13 Clipping Line Clipping Polygon Clipping Clipping in Three Dimensions [Angel 8.3-8.7] March 11, 2003 Frank Pfenning Carnegie Mellon University http://www.cs.cmu.edu/~fp/courses/graphics/
  • 2. The Graphics Pipeline, Revisited • Must eliminate objects outside viewing frustum • Tied in with projections – Clipping: object space (eye coordinates) – Scissoring: image space (pixels in frame buffer) • Introduce clipping in stages – 2D (for simplicity) – 3D (as in OpenGL) • In a later lecture: scissoring 03/11/2003 15-462 Graphics I 2
  • 3. Transformations and Projections • Sequence applied in many implementations 1. Object coordinates to 2. Eye coordinates to 3. Clip coordinates to 4. Normalized device coordinates to 5. Screen coordinates 03/11/2003 15-462 Graphics I 3
  • 4. Clipping Against a Frustum • General case of frustum (truncated pyramid) y clipped line x z image plane near far • Clipping is tricky because of frustum shape 03/11/2003 15-462 Graphics I 4
  • 5. Perspective Normalization • Solution: – Implement perspective projection by perspective normalization and orthographic projection – Perspective normalization is a homogeneous tfm. y y clipped line clipped line x 1 x 1 near far z 0 1 z image plane near far See [Angel Ch. 5.8] 03/11/2003 15-462 Graphics I 5
  • 6. The Normalized Frustum • OpenGL uses -1 · x,y,z · 1 (others possible) • Clip against resulting cube • Clipping against programmer-specified planes is different and more expensive • Often a useful programming device 03/11/2003 15-462 Graphics I 6
  • 7. The Viewport Transformation • Transformation sequence again: 1. Camera: From object coordinates to eye coords 2. Perspective normalization: to clip coordinates 3. Clipping 4. Perspective division: to normalized device coords. 5. Orthographic projection (setting zp = 0) 6. Viewport transformation: to screen coordinates • Viewport transformation can distort • Often in OpenGL: resize callback 03/11/2003 15-462 Graphics I 7
  • 8. Line-Segment Clipping • General: 3D object against cube • Simpler case: – In 2D: line against square or rectangle – Before scan conversion (rasterization) – Later: polygon clipping • Several practical algorithms – Avoid expensive line-rectangle intersections – Cohen-Sutherland Clipping – Liang-Barsky Clipping – Many more [see Foley et al.] 03/11/2003 15-462 Graphics I 8
  • 9. Clipping Against Rectangle • Line-segment clipping: modify endpoints of lines to lie within clipping rectangle • Could calculate intersections of line (segments) with clipping rectangle (expensive) 03/11/2003 15-462 Graphics I 9
  • 10. Cohen-Sutherland Clipping • Clipping rectangle as intersection of 4 half- planes y < ymax y > ymin ∩ ymax ymin interior = x > xmin x < xmax xmin xmax • Encode results of four half-plane tests • Generalizes to 3 dimensions (6 half-planes) 03/11/2003 15-462 Graphics I 10
  • 11. Outcodes • Divide space into 9 regions • 4-bit outcode determined by comparisons 1001 1000 1010 bo: y > ymax b1: y < ymin ymax b2: x > xmax 0001 0000 0010 b3: x < xmin ymin 0101 0100 0110 xmin xmax • o1 = outcode(x1,y1) and o2 = outcode(x2,y2) 03/11/2003 15-462 Graphics I 11
  • 12. Cases for Outcodes • Outcomes: accept, reject, subdivide 1001 1000 1010 ymax o1 = o2 = 0000: accept o1 & o2 ≠ 0000: reject 0001 0000 0010 o1 = 0000, o2 ≠ 0000: subdiv o1 ≠ 0000, o2 = 0000: subdiv ymin o1 & o2 = 0000: subdiv 0101 0100 0110 xmin xmax 03/11/2003 15-462 Graphics I 12
  • 13. Cohen-Sutherland Subdivision • Pick outside endpoint (o ≠ 0000) • Pick a crossed edge (o = b0b1b2b3 and bk ≠ 0) • Compute intersection of this line and this edge • Replace endpoint with intersection point • Restart with new line segment – Outcodes of second point are unchanged • Must converge (roundoff errors?) 03/11/2003 15-462 Graphics I 13
  • 14. Liang-Barsky Clipping • Starting point is parametric form • Compute four intersections with extended clipping rectangle • Will see that this can be avoided 03/11/2003 15-462 Graphics I 14
  • 15. Ordering of intersection points • Order the intersection points • Figure (a): 1 > α4 > α3 > α2 > α1 > 0 • Figure (b): 1 > α4 > α2 > α3 > α1 > 0 03/11/2003 15-462 Graphics I 15
  • 16. Liang-Barsky Efficiency Improvements • Efficiency improvement 1: – Compute intersections one by one – Often can reject before all four are computed • Efficiency improvement 2: – Equations for α3, α2 – Compare α3, α2 without floating-point division 03/11/2003 15-462 Graphics I 16
  • 17. Line-Segment Clipping Assessment • Cohen-Sutherland – Works well if many lines can be rejected early – Recursive structure (multiple subdiv) a drawback • Liang-Barsky – Avoids recursive calls (multiple subdiv) – Many cases to consider (tedious, but not expensive) – Used more often in practice (?) 03/11/2003 15-462 Graphics I 17
  • 18. Outline • Line-Segment Clipping – Cohen-Sutherland – Liang-Barsky • Polygon Clipping – Sutherland-Hodgeman • Clipping in Three Dimensions 03/11/2003 15-462 Graphics I 18
  • 19. Polygon Clipping • Convert a polygon into one ore more polygons • Their union is intersection with clip window • Alternatively, we can first tesselate concave polygons (OpenGL supported) 03/11/2003 15-462 Graphics I 19
  • 20. Concave Polygons • Approach 1: clip and join to a single polygon • Approach 2: tesselate and clip triangles 03/11/2003 15-462 Graphics I 20
  • 21. Sutherland-Hodgeman I • Subproblem: – Input: polygon (vertex list) and single clip plane – Output: new (clipped) polygon (vertex list) • Apply once for each clip plane – 4 in two dimensions – 6 in three dimensions – Can arrange in pipeline 03/11/2003 15-462 Graphics I 21
  • 22. Sutherland-Hodgeman II • To clip vertex list (polygon) against half-plane: – Test first vertex. Output if inside, otherwise skip. – Then loop through list, testing transitions • In-to-in: output vertex • In-to-out: output intersection • out-to-in: output intersection and vertex • out-to-out: no output – Will output clipped polygon as vertex list • May need some cleanup in concave case • Can combine with Liang-Barsky idea 03/11/2003 15-462 Graphics I 22
  • 23. Other Cases and Optimizations • Curves and surfaces – Analytically if possible – Through approximating lines and polygons otherwise • Bounding boxes – Easy to calculate and maintain – Sometimes big savings 03/11/2003 15-462 Graphics I 23
  • 24. Outline • Line-Segment Clipping – Cohen-Sutherland – Liang-Barsky • Polygon Clipping – Sutherland-Hodgeman • Clipping in Three Dimensions 03/11/2003 15-462 Graphics I 24
  • 25. Clipping Against Cube • Derived from earlier algorithms • Can allow right parallelepiped 03/11/2003 15-462 Graphics I 25
  • 26. Cohen-Sutherland in 3D • Use 6 bits in outcode – b4: z > zmax – b5: z < zmin • Other calculations as before 03/11/2003 15-462 Graphics I 26
  • 27. Liang-Barsky in 3D • Add equation z(α) = (1- α) z1 + α z2 • Solve, for p0 in plane and normal n: • Yields • Optimizations as for Liang-Barsky in 2D 03/11/2003 15-462 Graphics I 27
  • 28. Perspective Normalization • Intersection simplifies for orthographic viewing – One division only (no multiplication) – Other Liang-Barsky optimizations also apply • Otherwise, use perspective normalization – Reduces to orthographic case – Applies to oblique and perspective viewing Normalization of oblique projections 03/11/2003 15-462 Graphics I 28
  • 29. Summary: Clipping • Clipping line segments to rectangle or cube – Avoid expensive multiplications and divisions – Cohen-Sutherland or Liang-Barsky • Clipping to viewing frustum – Perspective normalization to orthographic projection – Apply clipping to cube from above • Client-specific clipping – Use more general, more expensive form • Polygon clipping – Sutherland-Hodgeman pipeline 03/11/2003 15-462 Graphics I 29
  • 30. Preview and Announcements • Scan conversion • Anti-aliasing • Other pixel-level operations • Assignment 5 due a week from Thursday! • Start early! • Sriram’s office hours now Mon 4:30-6:30 • Movie • Returning Midterm 03/11/2003 15-462 Graphics I 30