Cli Clipping i Werner Purgathofer Werner Purgathofer Viewing in - - PowerPoint PPT Presentation

cli clipping i
SMART_READER_LITE
LIVE PREVIEW

Cli Clipping i Werner Purgathofer Werner Purgathofer Viewing in - - PowerPoint PPT Presentation

Einfhrung in Visual Computing g p g 186.822 Cli Clipping i Werner Purgathofer Werner Purgathofer Viewing in the Rendering Pipeline g g p object capture/creation j p scene objects in object space modeling modeling vertex stage


slide-1
SLIDE 1

Einführung in Visual Computing g p g

186.822

Cli i Clipping

Werner Purgathofer Werner Purgathofer

slide-2
SLIDE 2

Viewing in the Rendering Pipeline g g p

  • bject capture/creation

j p modeling scene objects in object space modeling viewing

vertex stage

viewing projection

(„vertex shader“)

p j transformed vertices in clip space clipping + homogenization i li d d i di t viewport transformation scene in normalized device coordinates rasterization viewport transformation shading

pixel stage ( fragment shader“)

Werner Purgathofer 2

raster image in pixel coordinates

(„fragment shader )

slide-3
SLIDE 3

Overview: Clipping

line clipping

pp g

line clipping polygon clipping polygon clipping triangle clipping triangle clipping

Werner Purgathofer 3

slide-4
SLIDE 4

Clipping pp g

partly visible or completely invisible parts b b must not be ignored and must not be drawn ignored?: scrolled?: vertices edges vertices edges  must be cut off (as early as possible)   must be cut off (as early as possible)

Werner Purgathofer 4

slide-5
SLIDE 5

Clipping Operations

remove objects outside a clip window

pp g p

remove objects outside a clip window

clip window: rectangle, polygon, curved boundaries clip window: rectangle, polygon, curved boundaries applied somewhere in the viewing pipeline pp g p p can be combined with scan conversion

  • bjects to clip: points, lines, triangles, polygons, curves, text, ...

Werner Purgathofer 5

slide-6
SLIDE 6

3 Principle Possibilities for Clipping

analytically in world coordinates

p pp g

analytically in world coordinates

reduces WC DC transformations reduces WC DC transformations

analytically in clip coordinates

simple comparisons

during raster conversation during raster conversation = as part of the rasterization algorithm as part of the rasterization algorithm

may be efficient for complex primitives y p p

Werner Purgathofer 6

slide-7
SLIDE 7

Line Clipping (1) pp g ( )

P9 P P4 P2 P2 P P8 P10 P P´8 P1 P6 P8 P3 P1 P6 P´

8

P7 P5 P 5 P´7

before clipping after clipping

7 7

[li li i i l li i d ]

before clipping after clipping

[line clipping against a rectangular clip window]

Werner Purgathofer 7

slide-8
SLIDE 8

Line Clipping (2)

goals

pp g ( )

goals

eliminate simple cases fast eliminate simple cases fast avoid intersection calculations

for endpoints (x0,y0), (xend,yend) intersect parametric representation intersect parametric representation x = x0 + u·(xend - x0) u (

end 0)

y = y0 + u·(yend - y0) with window borders: i t ti

 0 <

< 1 intersection  0 < u < 1

Werner Purgathofer 8

slide-9
SLIDE 9

Cohen‐Sutherland Line Clipping

assignment of region codes to line endpoints

pp g

assignment of region codes to line endpoints

bit1: left

1001 1000 1010

Window

bit1: left bit2: right

0001 0000 0010

g bit3: below

0001 0000 0010

bit4: above

0101 0100 0110 binary region codes assigned to line endpoints according to relative binary region codes assigned to line endpoints according to relative position with respect to the clipping rectangle position with respect to the clipping rectangle

Werner Purgathofer 9

slide-10
SLIDE 10

Cohen‐Sutherland Line Clipping pp g

“or” of codes of both points p = 0000  line entirely visible 1001 1000 1010

Window

0001 0000 0010 “and” of codes of both points 0000  li ti l i i ibl 0001 0000 0010  0000  line entirely invisible 0101 0100 0110 all others intersect! all others intersect!

Werner Purgathofer 10

slide-11
SLIDE 11

Cohen‐Sutherland Line Clipping pp g

l d f

P2 P’

lines extending from one coordinate region to another

window P” P’2

coordinate region to another may pass through the clip

window P 2

may pass through the clip window, or they may intersect clipping boundaries without entering the window

P3 P’1 P1 P4 P’3

1

P4

Werner Purgathofer 11

slide-12
SLIDE 12

Cohen‐Sutherland Line Clipping

remaining lines

pp g

remaining lines

intersection test with bounding lines of clipping window intersection test with bounding lines of clipping window left, right, bottom, top , g , , p discard an outside part repeat intersection test up to four times

vertical: y = y + m(xw x ) y = y + m(xw x ) vertical: y = y0 + m(xwmin – x0), y = y0 + m(xwmax – x0) horizontal: x = x0 + (ywmin – y0)/m, x = x0 + (ywmax – y0)/m

Werner Purgathofer 12

(ywmin y0)/ , (ywmax y0)/

slide-13
SLIDE 13

Cohen‐Sutherland Line Clipping pp g

P2 P’

passes through clipping window

window P”2 P 2

p g pp g

window P 2

intersects boundaries without entering clipping window entering clipping window

P3 P’1 P1 P4 P’3

vertical: y = y + m(xw x ) y = y + m(xw x )

4

vertical: y = y0 + m(xwmin – x0), y = y0 + m(xwmax – x0) horizontal: x = x0 + (ywmin – y0)/m, x = x0 + (ywmax – y0)/m

Werner Purgathofer 13

(ywmin y0)/ , (ywmax y0)/

slide-14
SLIDE 14

Polygon Clipping

modification of line clipping

yg pp g

modification of line clipping goal: one or more closed areas

display of a correctly li d l display of a polygon processed b li li i l ith clipped polygon by a line‐clipping algorithm

Werner Purgathofer 14

slide-15
SLIDE 15

Sutherland‐Hodgman Polygon Clipping g yg pp g

processing polygon boundary as a whole against each window edge processing polygon boundary as a whole against each window edge

  • utput: list of vertices
  • utput: list of vertices
  • riginal

polygon clip left clip right clip bottom clip top li i l i t i i d b d i polygon clipping a polygon against successive window boundaries

Werner Purgathofer 15

slide-16
SLIDE 16

Sutherland‐Hodgman Polygon Clipping

four possible edge cases

g yg pp g

p g

V1 V2 Vnew V2 V1

new

V1 V2 V1 V2 Vnew

  • ut  in

in  in in  out

  • ut  out

V1 V2

  • utput: Vnew, V2

V2 Vnew no output successive processing of pairs of polygon vertices against the successive processing of pairs of polygon vertices against the left window boundary

Werner Purgathofer 16

y

slide-17
SLIDE 17

Sutherland‐Hodgman Polygon Clipping

V := 1st vertex

for 1 edge: g yg pp g

V2:= 1st vertex

for 1 edge:

V1:=V2 V2:=next vertex V2 result list V visible?

no yes

V2 visible?

y

V1 visible?

yes

V1 visible?

no yes no

1 1

V’1 = clip edge  V1V2 result list

Werner Purgathofer 17

slide-18
SLIDE 18

Sutherland‐Hodgman Polygon Clipping

window

g yg pp g

window clipping a polygon against 3 the left boundary of a i d t ti ith window, starting with vertex 1 1’ 2’ 2 vertex 1. 1 4 primed numbers are used 3’ 6 1 4 to label the points in the li f hi 3’

  • utput vertex list for this

window boundary 5’ 4’ 5 window boundary 4 5

Werner Purgathofer 18

slide-19
SLIDE 19

Polygon Clip: Combination of 4 Passes yg p

the polygon is clipped against each of the 4 borders separately the polygon is clipped against each of the 4 borders separately, that would produce 3 intermediate results. p by calling the 4 tests recursively, (or by using a clipping pipeline) l i i i di l d every result point is immediately processed on, so that only one result list is produced so that only one result list is produced

Werner Purgathofer 19

slide-20
SLIDE 20

Sutherland‐Hodgman Clipping Example

pipeline of boundary

g pp g p

window

pipeline of boundary clippers to avoid

2

1st clip:

window

intermediate vertex lists p left

2’ 2 3 2” 1’ 3

2nd clip: b tt

3’

P i h l i h h b d li i

1

bottom

3’

Processing the polygon vertices through a boundary‐clipping pipeline After all vertices are processed through the pipeline the

  • pipeline. After all vertices are processed through the pipeline, the

vertex list for the clipped polygon is {1’, 2, 2’, 2”}

Werner Purgathofer 20

vertex list for the clipped polygon is {1 , 2, 2 , 2 }

slide-21
SLIDE 21

Sutherland‐Hodgman Polygon Clipping

extraneous lines for concave polygons:

g yg pp g

extraneous lines for concave polygons:

split into separate parts

  • r

split into separate parts or final check of output vertex list p

clipping the concave pp g polygon with the Sutherland‐Hodgeman clipper prod ces three clipper produces three connected areas connected areas

Werner Purgathofer 21

slide-22
SLIDE 22

Clipping of Triangles

  • ften b‐reps are “triangle soups”

pp g g

  • ften b‐reps are triangle soups

clipping a triangle  triangle(s) clipping a triangle  triangle(s) 4 possible cases: 4 possible cases:

inside

(inside)

  • utside

(inside)

triangle quadrilateral  2 triangles

Werner Purgathofer 22

slide-23
SLIDE 23

Clipping of Triangles

corner cases need no extra handling!

pp g g

corner cases need no extra handling!

Werner Purgathofer 23

slide-24
SLIDE 24

From Object Space to Screen Space j p p

„view frustum“ d li modeling transformation camera transformation

  • bject space

world space camera space projection transformation viewport transformation transformation transformation

Werner Purgathofer 24

clip space screen space

slide-25
SLIDE 25

Clipping in Clip‐Space

clipping against x = ± 1 y = ± 1 z = ± 1

pp g p p

clipping against x = ± 1, y = ± 1, z = ± 1 (x y z) inside? (x,y,z) inside?  only compare one value!  only compare one value! is done before homogenization: x = ± h, y = ± h, z = ± h li i h b hi d h ! clips points that are behind the camera! d h i ti di i i reduces homogenization divisions

Werner Purgathofer 25

slide-26
SLIDE 26

Einführung in Visual Computing g p g

186.822

A ti li i Antialiasing

Werner Purgathofer Werner Purgathofer

slide-27
SLIDE 27

Antialiasing in the Rendering Pipeline g g p

  • bject capture/creation

j p modeling scene objects in object space modeling viewing

vertex stage

viewing projection

(„vertex shader“)

p j transformed vertices in clip space clipping + homogenization i li d d i di t viewport transformation scene in normalized device coordinates rasterization viewport transformation shading

pixel stage ( fragment shader“)

Werner Purgathofer 27

raster image in pixel coordinates

(„fragment shader )

slide-28
SLIDE 28

Aliasing and Antialiasing g g

what is aliasing? ['eiliæsiη] what is aliasing? [ eiliæsiη] what is the reason for aliasing? what is the reason for aliasing? what can we do against it? g

Werner Purgathofer 28

slide-29
SLIDE 29

What is Aliasing? g

errors that are caused by the discretization of analog data to digital data

too bad resolution too few colors f / too few images / sec geometric errors geometric errors numeric errors

Werner Purgathofer 29

numeric errors

slide-30
SLIDE 30

Aliasing: Staircase Effect g

Werner Purgathofer 30

slide-31
SLIDE 31

Various Aliasing Effects g

Werner Purgathofer 31

slide-32
SLIDE 32

Aliasing from too few Colors g

artificial color borders can appear artificial color borders can appear

Werner Purgathofer 32

slide-33
SLIDE 33

Aliasing in Animations

jumping images

g

jumping images "worming“ worming

t

backwards rotating wheels g

Werner Purgathofer 33

slide-34
SLIDE 34

Solutions against Aliasing? g g

  • 1. improve the devices

expensive

higher resolution

expensive

  • r

more color levels f t i

  • r

incompatible

faster image sequence

2 improve the images = antialiasing

  • 2. improve the images = antialiasing

postprocessing

f !

postprocessing prefiltering !

software !

p g

Werner Purgathofer 34

slide-35
SLIDE 35

Nyquist‐Shannon Sampling Theorem yq p g

a signal can only be reconstructed without information loss if h li f i l if the sampling frequency is at least twice the highest frequency of the signal twice the highest frequency of the signal this border frequency is called "Nyquist Limit" this border frequency is called Nyquist Limit

Werner Purgathofer 35

slide-36
SLIDE 36

Nyquist‐Shannon Sampling Theorem yq p g

  • riginal
  • riginal

signal signal t t d reconstructed signal

Nyquist sampling

sampling rate  signal

sampling interval

sampling rate 

Werner Purgathofer 36

slide-37
SLIDE 37

Antialiasing: Nyquist Sampling Frequency g yq p g q y

a signal can only be reconstructed without information loss if h li f i l if the sampling frequency is at least twice the highest frequency of the signal twice the highest frequency of the signal

2 f f

N q ist samplin freq enc

max

2 f f s 

Nyquist sampling frequency:

/ 1 x

ith

f x x

cycle

    

max cycle

/ 1 x

with

2 f x

y s

   

i.e. sampling interval  one‐half cycle interval

Werner Purgathofer 37

p g y

slide-38
SLIDE 38

Antialiasing Strategies

li i h li

g g

supersampling straight‐line segments b i l i hti k subpixel weighting masks area sampling straight line segments area sampling straight‐line segments filtering techniques filtering techniques compensating for line‐intensity differences compensating for line‐intensity differences antialiasing area boundaries antialiasing area boundaries

(adjusting boundary pixel positions) (adjusting boundary pixel positions) adjusting boundary pixel intensity

Werner Purgathofer 38

slide-39
SLIDE 39

Antialiasing: Supersampling Lines g p p g

0 0 0 1 1 0 0 4 0 2 2 0 0 4 1 6 8 0 2 2 1 6 8 3 1 0 8 5 0 3 1 0 8 5 0

mathematical line line of finite width 3 = max. intensity 9 = max. intensity ... 0 = min. intensity ... 0 = min. intensity

Werner Purgathofer 39

y y

slide-40
SLIDE 40

Antialiasing

Werner Purgathofer 40

slide-41
SLIDE 41

Antialiasing: Pixel Weighting Masks

more weight for center

g g g

more weight for center subpixels subpixels must be divided by sum of must be divided by sum of weights subpixel grids can also include some neighboring pixels relative weights for a grid of 3x3 subpixels relative weights for a grid of 3x3 subpixels

Werner Purgathofer 41

slide-42
SLIDE 42

Antialiasing: Area Sampling Lines

calculate the pixel coverage exactly

g p g

calculate the pixel coverage exactly can be done with incremental schemes

0% 0% 0% 0% 43% 43%

can be done with incremental schemes

15% 15% 71% 71% 84% 84% 15% 15% 71% 71% 84% 84% 90% 90% 52% 52% 3% 3%

Werner Purgathofer 42

slide-43
SLIDE 43

Antialiasing: Filtering Techniques

continuous overlapping weighting functions

g g q

continuous overlapping weighting functions to calculate the antialiased values with integrals box filter cone filter Gaussian filter

Werner Purgathofer 43

box filter cone filter Gaussian filter

slide-44
SLIDE 44

Antialiasing: Intensity Differences g y

unequal line lengths displayed i h h b f with the same number of pixels in each line/row have 1,41421 pixels in each line/row have different intensities , proper antialiasing p p g compensates for that! 1

Werner Purgathofer 44

slide-45
SLIDE 45

Antialiasing Area Boundaries g

Werner Purgathofer 45

slide-46
SLIDE 46

Antialiasing Area Boundaries (1)

alternative 1:

g

( )

alternative 1: supersampling adjusting pixel intensities adjusting pixel intensities along an area boundary

Werner Purgathofer 46

slide-47
SLIDE 47

Antialiasing Area Boundaries (2)

alternative 2: similar to Bresenham algorithm

g

( )

alternative 2: similar to Bresenham algorithm p´ = y y = [m(x + 1) + b] (y + 0 5) p = y  ymid = [m(xk + 1) + b]  (yk + 0.5) ´ 0 l p´<0  y closer to yk p´>0  y closer to y

y = mx + b

p >0  y closer to yk+1 p = p´ + (1m) : y

yk + 1 + 0 5

y p p ( ) p<1m  y closer to yk ymid

yk + 0.5 yk

y p>1m  y closer to yk+1

yk

( and p  [0,1] )

xk + 1 xk

Werner Purgathofer 47

( and p  [0,1] )

slide-48
SLIDE 48

Antialiasing Area Boundaries (3)

p = p´+ (1m) =[m(xk + 1) + b]  (yk + 0 5) + (1  m) =

g

( )

p p + (1 m) [m(xk + 1) + b] (yk + 0.5) + (1 m) = mxk + b  yk + 0.5 = mxk + b  (yk  0.5)

k

yk yk+ 0 5

k

(yk ) yk+ 0.5 p´ p for next pixel l yk m = overlap area for current pixel for current pixel p 1-m p xk xk+1 p´

Werner Purgathofer 48

k k

slide-49
SLIDE 49

Antialiasing Area Boundaries (4) g

( )

Werner Purgathofer 49

slide-50
SLIDE 50

Antialiasing Examples g p

Werner Purgathofer 50

slide-51
SLIDE 51

Antialiasing Examples g p

Werner Purgathofer 51