Windowing and Clipping
 Windowing Concepts
 Introduction to Clipping
 Point Clipping
 Line Clipping
 Area Clipping
2
3
Window
Image Space
Viewport
Information
outside
the viewport is
clipped away
• World Coordinate System (Object Space) -
Representation of an object measured in some
physical units.
• Window - The rectangle defining the part of the
world we wish to display.
• Image Coordinate System (Image Space) - The
space within the image is displayed.
• Viewport - The rectangle area in image space
where the image from the window will appear.
• Viewing Transformation - The process of going
from a window in world coordinates to a
viewport in image coordinates.
4
5
• In 2D, a ‘world’ consists of an infinite plane,
defined in ‘world’ coordinates, i.e metres,
angstroms etc.
• We need to pick an area of the 2D plane to view,
referred to as the ‘window’.
• On our display device, need to allocate an area for
display, referred to as the ‘viewport’ in device
specific coordinates.
– Clip objects outside of window.
– Translate to fit viewport.
– Scale to device coordinates.
6
Choose Window in
World Coordinates
Clip to size
of Window
Translate to
origin
Scale to size of Viewport Translate to proper position in
image
 Any procedure that identifies those portions of a
picture that are either inside or outside of a
specified region is referred to as a clipping
algorithm or clipping.
7
World Coordinates
8
• When we display a scene only those objects
within a particular window are displayed.
wymax
wymin
wxmin wxmax
Window or Clipping Region
World Coordinates
9
Because drawing things to a display takes time
we clip everything outside the window.
wymax
wymin
wxmin wxmax
Window or Clipping Region
World Coordinates
 For the image below consider which lines and
points should be kept and which ones should be
clipped.
10
wymax
wymin
wxmin wxmax
Window
P1
P2
P3
P6
P5
P7
P10
P9
P4
P8
 Easy - a point (x,y) is not clipped if:
wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax
11
wymax
wymin
wxmin wxmax
Window
P1
P2
P5
P7
P10
P9
P4
P8
Clipped
Points Within the
Window are Not Clipped
Clipped
Clipped
Clipped
 Harder - examine the end-points of each line to
see if they are in the window or not.
12
Situation Solution Example
Both end-points inside
the window
Don’t clip
One end-point inside
the window, one
outside
Must clip
Both end-points
outside the window
Don’t know!
Brute force line clipping can be performed as follows:
 Don’t clip lines with both
end-points within the
window.
 For lines with one end-
point inside the window
and one end-point
outside, calculate the
intersection point (using the equation of the line) and
clip from this point out.
13
14
– For lines with both end-
points outside the
window test the line for
intersection with all of
the window boundaries,
and clip appropriately.
However, calculating line intersections is
computationally expensive.
Because a scene can contain so many lines,
the brute force approach to clipping is much
too slow.
15
An efficient line clipping
algorithm.
The key advantage of the
algorithm is that it vastly
reduces the number of line
intersections that must be
calculated.
Dr. Ivan E. Sutherland
c o - d e v e l o p e d t h e
C o h e n - S u t h e r l a n d
clipping algorithm.
Sutherland is a graphics
giant and includes
a m o n g s t h i s
a c h i e v e m e n t s t h e
invention of the head
Cohen is something of a mystery – can
anybody find out who he was?
Algorithm
Step 1 − Assign a region code for each endpoints.
Step 2 − If both endpoints have a region code 0000 then accept this line.
Step 3 − Else, perform the logical AND operation for both region codes.
Step 3.1 − If the result is not 0000, then reject the line.
Step 3.2 − Else you need clipping.
Step 3.2.1 − Choose an endpoint of the line that is outside the
window.
Step 3.2.2 − Find the intersection point at the window boundary
(base on region code).
Step 3.2.3 − Replace endpoint with the intersection point and
update the region code.
Step 3.2.4 − Repeat step 2 until we find a clipped line either
trivially accepted or trivially rejected.
Step 4 − Repeat step 1 for other lines.
16
 World space is divided into regions based on the
window boundaries.
 Each region has a unique four bit region code.
 Region codes indicate the position of the regions with
respect to the window.
17
above below right left
3 2 1 0
Region Code Legend
1001 1000 1010
0001
0000
Window
0010
0101 0100 0110
18
• Every end-point is labelled with the
appropriate region code.
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
19
Lines completely contained within the window
boundaries have region code [0000] for both end-
points so are not clipped. The OR operation can
efficiently check this.
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
20
Any lines with a common set bit in the region
codes of both end-points can be clipped.
– The AND operation can efficiently check this.
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
 Lines that cannot be identified as completely inside
or outside the window may or may not cross the
window interior.
 These lines are processed as follows:
 Compare an end-point outside the window to a
boundary (choose any order in which to consider
boundaries e.g. left, right, bottom, top) and
determine how much can be discarded.
 If the remainder of the line is entirely inside or
outside the window, retain it or clip it respectively.
21
 Otherwise, compare the remainder of the line against the
other window boundaries.
 Continue until the line is either discarded or a segment
inside the window is found.
 We can use the region codes to determine which
window boundaries should be considered for
intersection.
 To check if a line crosses a particular boundary we
compare the appropriate bits in the region codes of its
end-points.
 If one of these is a 1 and the other is a 0 then the line
crosses the boundary.
22
 Intersection points with the window boundaries are
calculated using the line-equation parameters.
 Consider a line with the end-points (x1, y1) and (x2, y2)
 The y-coordinate of an intersection with a vertical
window boundary can be calculated using:
y = y1 + m (xboundary - x1)
where xboundary can be set to either wxmin or wxmax
23
 The x-coordinate of an intersection with a
horizontal window boundary can be calculated
using:
x = x1 + (yboundary - y1) / m
where yboundary can be set to either wymin or wymax
 m is the slope of the line in question and can be
calculated as
m = (y2 - y1) / (x2 - x1)
24
 Polygons can be clipped against each edge of the
window one edge at a time. Window/edge
intersections, if any, are easy to find since the X or
Y coordinates are already known.
 Vertices which are kept after clipping against one
window edge are saved for clipping against the
remaining edges. Note that the number of vertices
usually changes and will often increase.
25
 A technique for clipping areas
developed by Sutherland &
Hodgman.
 Put simply the polygon is clipped
by comparing it against each
boundary in turn.
26
Sutherland
turns up
again. This
time with
Gary Hodgman
with whom he
worked at the first
ever graphics
company Evans &
Sutherland
Original Area Clip Left Clip Right Clip Top Clip Bottom
 To clip an area against an individual boundary:
 Consider each vertex in turn against the boundary.
 Vertices inside the boundary are saved for clipping
against the next boundary.
 Vertices outside the boundary are clipped.
 If we proceed from a point inside the boundary to one
outside, the intersection of the line with the boundary is
saved.
 If we cross from the outside to the inside intersection
point and the vertex are saved.
27
 Each example shows
the point being
processed (P) and the
previous point (S).
 Saved points define
area clipped to the
boundary in question.
28
S
P
Save Point P
S
P
Save Point I
I
P
S
No Points Saved
S
P
Save Points I & P
I
 Instead of always
proceeding around the
polygon edges as vertices are
processed, we sometime
want to follow window
boundary.
 This algorithm is used for
clipping concave polygons.
 V1, V2, V3, V4, V5 are the
vertices of the polygon.
 C1, C2, C3, C4 are the
vertices of the clip polygon
 I1, I2, I3, I4 are the
intersection points of 29
Thank You !!!
30

More Related Content

PPTX
2 d viewing computer graphics
PPT
Line drawing algo.
PPT
Clipping
PPTX
Window to viewport transformation&matrix representation of homogeneous co...
PPTX
Chapter 3 Output Primitives
PDF
Unit-IV Windowing and Clipping.pdf
PPT
Ellipses drawing algo.
PPTX
Clipping ( Cohen-Sutherland Algorithm )
2 d viewing computer graphics
Line drawing algo.
Clipping
Window to viewport transformation&matrix representation of homogeneous co...
Chapter 3 Output Primitives
Unit-IV Windowing and Clipping.pdf
Ellipses drawing algo.
Clipping ( Cohen-Sutherland Algorithm )

What's hot (20)

PPT
Window to viewport transformation
PPTX
Bresenham-Circle-drawing-algorithm, Midpoint Circle Drawing Algorithm
PPTX
clippiNG COMPUTER GRAPHICS A NEW ERA.pptx
PPT
Visible surface detection in computer graphic
PPTX
Hidden surface removal
PPT
Two dimensional geometric transformations
PPTX
Computer Graphics: Visible surface detection methods
PPT
Hidden lines & surfaces
PPTX
Graphics_3D viewing
PPTX
3d transformation computer graphics
PPTX
Cohen-Sutherland Line Clipping Algorithm
PPT
Polygon clipping
PPTX
Curve and text clipping
PPTX
Dda line algorithm presentatiion
PDF
3D Transformation
PPTX
Computer graphics basic transformation
PPTX
Viewing transformation
PPTX
Frame buffer
PPTX
Clipping in Computer Graphics
PPTX
Mid point circle algorithm
Window to viewport transformation
Bresenham-Circle-drawing-algorithm, Midpoint Circle Drawing Algorithm
clippiNG COMPUTER GRAPHICS A NEW ERA.pptx
Visible surface detection in computer graphic
Hidden surface removal
Two dimensional geometric transformations
Computer Graphics: Visible surface detection methods
Hidden lines & surfaces
Graphics_3D viewing
3d transformation computer graphics
Cohen-Sutherland Line Clipping Algorithm
Polygon clipping
Curve and text clipping
Dda line algorithm presentatiion
3D Transformation
Computer graphics basic transformation
Viewing transformation
Frame buffer
Clipping in Computer Graphics
Mid point circle algorithm
Ad

Similar to Windowing clipping (20)

PPT
Lecture 2d point,curve,text,line clipping
PPTX
line clipping
PPTX
PPTX
Clipping
PPTX
Lect 5 2d clipping
DOC
Unit 4 notes
PDF
Unit 3
PPTX
Clipping computer graphics
PPTX
Clipping
PPT
99995327.ppt
PPT
Lecture1616_16827_2D Clipping.ppt
PPTX
UNIT_3-Two-Dimensional-Geometric-Transformations.pptx
PDF
UNIT_3-Two-Dimensional-Geometric-Transformations.pdf
PPTX
ohu.pptx
PPTX
Clipping CG ppt.pptx
PPTX
Sutherlands Cohen and Hodgeman algorithms
PPTX
Unit2- line clipping.pptx
PPTX
kgv.pptx
PPTX
CHAPTER - 4 for software engineering (1).pptx
PPTX
Clipping 22
Lecture 2d point,curve,text,line clipping
line clipping
Clipping
Lect 5 2d clipping
Unit 4 notes
Unit 3
Clipping computer graphics
Clipping
99995327.ppt
Lecture1616_16827_2D Clipping.ppt
UNIT_3-Two-Dimensional-Geometric-Transformations.pptx
UNIT_3-Two-Dimensional-Geometric-Transformations.pdf
ohu.pptx
Clipping CG ppt.pptx
Sutherlands Cohen and Hodgeman algorithms
Unit2- line clipping.pptx
kgv.pptx
CHAPTER - 4 for software engineering (1).pptx
Clipping 22
Ad

More from Shweta Shah (7)

PPTX
CG_Unit1_SShah.pptx
PPT
ConsTRUCTION AND DESTRUCTION
PPT
Inheritance in C++
PPT
Class objects oopm
PPTX
Virtual function and abstract class
PPT
Introduction to computer graphics and multimedia
PPTX
Introduction to Operating Systems
CG_Unit1_SShah.pptx
ConsTRUCTION AND DESTRUCTION
Inheritance in C++
Class objects oopm
Virtual function and abstract class
Introduction to computer graphics and multimedia
Introduction to Operating Systems

Recently uploaded (20)

PPTX
communication and presentation skills 01
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
CyberSecurity Mobile and Wireless Devices
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PPTX
Feature types and data preprocessing steps
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PDF
Design Guidelines and solutions for Plastics parts
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
communication and presentation skills 01
distributed database system" (DDBS) is often used to refer to both the distri...
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Abrasive, erosive and cavitation wear.pdf
III.4.1.2_The_Space_Environment.p pdffdf
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
Module 8- Technological and Communication Skills.pptx
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
CyberSecurity Mobile and Wireless Devices
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Feature types and data preprocessing steps
Visual Aids for Exploratory Data Analysis.pdf
Fundamentals of safety and accident prevention -final (1).pptx
"Array and Linked List in Data Structures with Types, Operations, Implementat...
Design Guidelines and solutions for Plastics parts
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx

Windowing clipping

  • 2.  Windowing Concepts  Introduction to Clipping  Point Clipping  Line Clipping  Area Clipping 2
  • 4. • World Coordinate System (Object Space) - Representation of an object measured in some physical units. • Window - The rectangle defining the part of the world we wish to display. • Image Coordinate System (Image Space) - The space within the image is displayed. • Viewport - The rectangle area in image space where the image from the window will appear. • Viewing Transformation - The process of going from a window in world coordinates to a viewport in image coordinates. 4
  • 5. 5 • In 2D, a ‘world’ consists of an infinite plane, defined in ‘world’ coordinates, i.e metres, angstroms etc. • We need to pick an area of the 2D plane to view, referred to as the ‘window’. • On our display device, need to allocate an area for display, referred to as the ‘viewport’ in device specific coordinates. – Clip objects outside of window. – Translate to fit viewport. – Scale to device coordinates.
  • 6. 6 Choose Window in World Coordinates Clip to size of Window Translate to origin Scale to size of Viewport Translate to proper position in image
  • 7.  Any procedure that identifies those portions of a picture that are either inside or outside of a specified region is referred to as a clipping algorithm or clipping. 7 World Coordinates
  • 8. 8 • When we display a scene only those objects within a particular window are displayed. wymax wymin wxmin wxmax Window or Clipping Region World Coordinates
  • 9. 9 Because drawing things to a display takes time we clip everything outside the window. wymax wymin wxmin wxmax Window or Clipping Region World Coordinates
  • 10.  For the image below consider which lines and points should be kept and which ones should be clipped. 10 wymax wymin wxmin wxmax Window P1 P2 P3 P6 P5 P7 P10 P9 P4 P8
  • 11.  Easy - a point (x,y) is not clipped if: wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax 11 wymax wymin wxmin wxmax Window P1 P2 P5 P7 P10 P9 P4 P8 Clipped Points Within the Window are Not Clipped Clipped Clipped Clipped
  • 12.  Harder - examine the end-points of each line to see if they are in the window or not. 12 Situation Solution Example Both end-points inside the window Don’t clip One end-point inside the window, one outside Must clip Both end-points outside the window Don’t know!
  • 13. Brute force line clipping can be performed as follows:  Don’t clip lines with both end-points within the window.  For lines with one end- point inside the window and one end-point outside, calculate the intersection point (using the equation of the line) and clip from this point out. 13
  • 14. 14 – For lines with both end- points outside the window test the line for intersection with all of the window boundaries, and clip appropriately. However, calculating line intersections is computationally expensive. Because a scene can contain so many lines, the brute force approach to clipping is much too slow.
  • 15. 15 An efficient line clipping algorithm. The key advantage of the algorithm is that it vastly reduces the number of line intersections that must be calculated. Dr. Ivan E. Sutherland c o - d e v e l o p e d t h e C o h e n - S u t h e r l a n d clipping algorithm. Sutherland is a graphics giant and includes a m o n g s t h i s a c h i e v e m e n t s t h e invention of the head Cohen is something of a mystery – can anybody find out who he was?
  • 16. Algorithm Step 1 − Assign a region code for each endpoints. Step 2 − If both endpoints have a region code 0000 then accept this line. Step 3 − Else, perform the logical AND operation for both region codes. Step 3.1 − If the result is not 0000, then reject the line. Step 3.2 − Else you need clipping. Step 3.2.1 − Choose an endpoint of the line that is outside the window. Step 3.2.2 − Find the intersection point at the window boundary (base on region code). Step 3.2.3 − Replace endpoint with the intersection point and update the region code. Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially accepted or trivially rejected. Step 4 − Repeat step 1 for other lines. 16
  • 17.  World space is divided into regions based on the window boundaries.  Each region has a unique four bit region code.  Region codes indicate the position of the regions with respect to the window. 17 above below right left 3 2 1 0 Region Code Legend 1001 1000 1010 0001 0000 Window 0010 0101 0100 0110
  • 18. 18 • Every end-point is labelled with the appropriate region code. wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]
  • 19. 19 Lines completely contained within the window boundaries have region code [0000] for both end- points so are not clipped. The OR operation can efficiently check this. wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]
  • 20. 20 Any lines with a common set bit in the region codes of both end-points can be clipped. – The AND operation can efficiently check this. wymax wymin wxmin wxmax Window P3 [0001] P6 [0000] P5 [0000] P7 [0001] P10 [0100] P9 [0000] P4 [1000] P8 [0010] P12 [0010] P11 [1010] P13 [0101] P14 [0110]
  • 21.  Lines that cannot be identified as completely inside or outside the window may or may not cross the window interior.  These lines are processed as follows:  Compare an end-point outside the window to a boundary (choose any order in which to consider boundaries e.g. left, right, bottom, top) and determine how much can be discarded.  If the remainder of the line is entirely inside or outside the window, retain it or clip it respectively. 21
  • 22.  Otherwise, compare the remainder of the line against the other window boundaries.  Continue until the line is either discarded or a segment inside the window is found.  We can use the region codes to determine which window boundaries should be considered for intersection.  To check if a line crosses a particular boundary we compare the appropriate bits in the region codes of its end-points.  If one of these is a 1 and the other is a 0 then the line crosses the boundary. 22
  • 23.  Intersection points with the window boundaries are calculated using the line-equation parameters.  Consider a line with the end-points (x1, y1) and (x2, y2)  The y-coordinate of an intersection with a vertical window boundary can be calculated using: y = y1 + m (xboundary - x1) where xboundary can be set to either wxmin or wxmax 23
  • 24.  The x-coordinate of an intersection with a horizontal window boundary can be calculated using: x = x1 + (yboundary - y1) / m where yboundary can be set to either wymin or wymax  m is the slope of the line in question and can be calculated as m = (y2 - y1) / (x2 - x1) 24
  • 25.  Polygons can be clipped against each edge of the window one edge at a time. Window/edge intersections, if any, are easy to find since the X or Y coordinates are already known.  Vertices which are kept after clipping against one window edge are saved for clipping against the remaining edges. Note that the number of vertices usually changes and will often increase. 25
  • 26.  A technique for clipping areas developed by Sutherland & Hodgman.  Put simply the polygon is clipped by comparing it against each boundary in turn. 26 Sutherland turns up again. This time with Gary Hodgman with whom he worked at the first ever graphics company Evans & Sutherland Original Area Clip Left Clip Right Clip Top Clip Bottom
  • 27.  To clip an area against an individual boundary:  Consider each vertex in turn against the boundary.  Vertices inside the boundary are saved for clipping against the next boundary.  Vertices outside the boundary are clipped.  If we proceed from a point inside the boundary to one outside, the intersection of the line with the boundary is saved.  If we cross from the outside to the inside intersection point and the vertex are saved. 27
  • 28.  Each example shows the point being processed (P) and the previous point (S).  Saved points define area clipped to the boundary in question. 28 S P Save Point P S P Save Point I I P S No Points Saved S P Save Points I & P I
  • 29.  Instead of always proceeding around the polygon edges as vertices are processed, we sometime want to follow window boundary.  This algorithm is used for clipping concave polygons.  V1, V2, V3, V4, V5 are the vertices of the polygon.  C1, C2, C3, C4 are the vertices of the clip polygon  I1, I2, I3, I4 are the intersection points of 29