This action might not be possible to undo. Are you sure you want to continue?

P. J. Narayanan Spring 2004

CS3500

1

**Graphics in Practice: Summary
**

Basic primitives: Points, Lines, Triangles/Polygons. Each constructed fundamentally from points. Points can be speciﬁed in different coordinate systems. The pipeline of operations on a point is:

Modelling

Object Coords World Coords

View Orientation

Camera Coords

View Mapping

Normalized Coords

Clipping Perspective

Screen Coords

CS3500

January 27, 2005

2

**Scan Conversion or Rasterization
**

Primitives are deﬁned using points, which have been mapped to the screen coordinates. In vector graphics, connect the points using a pen directly. In Raster Graphics, we create a discretized image of the whole screen onto the frame buffer ﬁrst. The image is scanned automatically onto the display periodically. This step is called Scan Conversion or Rasterization.

January 27, 2005

CS3500

3

**Scan Converting a Point
**

The 3D point has been transformed to its screen . coordinates Round the coordinates to frame buffer array indices

¡ £ ¤¢ ¥

.

¥

Current colour is deﬁned/known. Frame buffer array is initialized to the background colour. Perform: frameBuf[i, j] currentColour

©

The function WritePixel(x, y, colour) does the above. If PointSize , assign the colour to a number of points in the neighbourhood!

¦ §

¢ ¨

CS3500

January 27, 2005

4

**Scan Converting a Line
**

Identify the grid-points that lie on the line and colour them. Problem: Given two end-points on the grid, ﬁnd the pixels on the line connecting them. Incremental algorithm or Digital Differential Analyzer (DDA) algorithm. Mid-Point Algorithm

CS3500

January 27, 2005

5

Line on an Integer Grid

CS3500

January 27, 2005

6

Incremental Algorithm

Function DrawLine(

¥¦£ ¤

CS3500

, colour) , slope

©

¡

¢ ¢ ¢

¡ ¢ ¥ £ ¢ £

£

¤

¤

¤

**While ( ) WritePixel ( round , colour) , slope EndWhile , colour) WritePixel ( EndFunction
**

¨ £

¢

©

©

¡

¢

©

¡

¢ §

¢

¢

¢

¡

¢

©

¡ ¢ ¢

¥

¢

©

©

©

©

¢

¢

£

£

¢

¢

January 27, 2005

7

Points to Consider

If abs(slope) , step through y values, adding inverse slopes to x at each step.

Simple algorithm, easy to implement. Need ﬂoating point calculations (add, round), which are expensive. Can we do with integer arithmetic only? Yes: Bresenham’s Algorithm We will study a simpliﬁed version of it called the Mid-Point Line Algorithm.

January 27, 2005

CS3500

8

Two Options at Each Step!

NE M E

CS3500 January 27, 2005

9

**Mid-Point Line Algorithm
**

Line equation: slope Let

¤

. for above.

£

CS3500

¤

©

¢

¡

¢

¤

© ¢ ¥

£

£

¤

¤ ¡

¤

¥

¨

¥

¨

¢ §

**for below the line, ; else any! .
**

¡ § ¤

§

£

¦

NE if

£ § ¨

Therefore,

Initial value:

**Similar analysis for other slopes. Eight cases in total.
**

January 27, 2005

¤

© ©

¡

¢

¤

¨

¢

¢

¢

; E if

§

¢

£ ¦ §

¥

¤

¨

£

£

¦ § §

©

©

©

¨

¥

©

¨

.

£ § ¡

£

£

¤

¤ ©

¡

¨

¢

©

¨

¡ £

£ ¦

§

© ¡ ¡ ©

©

¢

¢

¥

10

¡ ¢ ¥ ¦ £

to

¥

£

¡ ¡ ¨

£ ¤

¢ ¢

¢

¤

¤

¢

£

£

¤

£

¢

¥

¡ £

¥

£

¤

£

£

£

£

Example:

§

¨

¥ © ©

£ § £ §

¥ ¢ ¢ ¢ ¢ ¥ ¢ ¢ ¥

¥ © ¥ ©

¤

¥ © ©

§ £

¢

£

£

¥

¢

£

£ § §

¢

©

©

¤

¨

© ©

¢

¥

¢

¤ £

¢

¤

©

¥ ¢

¥

¢

¥

¨

£

¥¨

¦ §

¢

¢

¥

¤

£ §

¤ ¤

¤

¤ ¤

¨

£

§

§

§

§

§

Later, NE (17, 15), NE (18, 16), E (19, 16), NE (20, 17).

CS3500

§

January 27, 2005

¤

11

**Scan Converting Circles
**

Need to consider only with centre at origin: For arbitrary centre, add

¡ ¡

¢

.

£

£

£

£

CS3500

to each point.

© ¢

¢

**8-way symmetry: Only an eighth of the circle need to be scan converted! If circle!
**

¢

¥

on circle,

,

are also on the

£ ¢

£ ¢

¢

¢

¢

¢

Easy way:

¢

¥

**, but ﬂoating point calculations!
**

January 27, 2005

¢

¢

¥

¥

£¥

£

£

¢

12

**Back to Two Points??
**

E M SE

**Choice between E and SE neighbours between the vertical and the 45 degree lines.
**

January 27, 2005

CS3500

13

**Mid-Point Circle Algorithm
**

Circle equation:

£

£ ¦

£

£

£¥

£

CS3500

¤

© ¢

**for inside circle, ; else any!
**

¤

for outside.

£¥

£

SE if

£ § ¨

Therefore,

Initial value:

¤

¨ ©

¤

¢

¢

¥

¢

; E if

©

£ ¦ §

¥

§

¤

¨

.

¥

£

£

¦ § § §

©

©

©

©

¨

¨

¢

¢

¥

.

¥

¥

£

£

¤

©

¤ ©

©

¨

¨

¢

¢

¥

¡ £

¡

¥

¥

£ ¦

£

§

¢

¥

¢

January 27, 2005

14

Pseudocode

Function DrawCircle ( , colour)

¥

**CirclePoints ( EndWhile EndFunction
**

CS3500

**CirclePoints ( , colour) ) While ( ) // East if (
**

¢

©

©

§

©

else

§

©

¤

¢ ¢

¢ ¢

©

¨

¤

¢

§

¨

§

§

©

©

// South-East

¥ ¥ ¢

§

©

¢

©

©

©

©

©

¢ ¢

© ¢

© ¢

, colour)

¥

¢

¢

January 27, 2005

15

Eliminate Multiplication?

Current selection is E: What are the new

’s?

CS3500

¤

£

£

¤

©

¤

©

¨

¥

©

©

**Current selection is SE: What are the new
**

if (

else

§

©

¨

¥

£

£

¤

¤

©

¨

© ¢

©

¥

¨

’s?

¤

£

£

¤

©

¤

©

¨

¥

©

©

¨

¥

¥ ¢

£

£

¤ ©

¨

¤

©

¨

©

¥

¥

)

©

// East += ++ ++

¥ ¢

£

§

¤

¨

©

+= // South-East +=

¤ ¤

¡ ¡

¤

§

§ §

¨

¢

¢

¢

+=

¤

¤

¤

©

¨

¨

¨

¢

¢

¢

¢

¢

January 27, 2005

16

End of Class 14

CS3500

January 27, 2005

17

Patterned Line

Represent the pattern as an array of booleans/bits, say, 16 pixels long. Fill ﬁrst half with 1 and rest with 0 for dashed lines. Perform WritePixel(x, y) only if pattern bit is a 1. if (pattern[i]) WritePixel(x, y) where i is an index variable starting with 0 giving the ordinal number (modulo 16) of the pixel from starting point.

CS3500 January 31, 2005

18

**Shared Points/Edges
**

It is common to have points common between two lines and edges between two polygons. They will be scan converted twice. Sometimes harmful. Not efﬁcient.

Solution: Treat the intervals closed on the left and open )&[ ) on the right. [ Thus, edges of polygons on the top and right boundaries are not drawn.

January 31, 2005

¡

¡

¢

¢

¢

¢

CS3500

19

CS3500

January 31, 2005

20

Clipping

Often, many points map to outside the range in the normalized 2D space. Think of the FB as an inﬁnite canvas, of which a small rectangular portion is sent to the screen. Let’s get greedy: draw only the portion that is visible. That is, clip the primitives to a clip-rectangle. Scissoring: Doing scan-conversion and clipping together.

February 12, 2004

CS3500

21

Clipping Points

Clip rectangle: For :

¥

to

¥

.

¥

¡

CS3500

¡ ¡

¢

¢

¢

¢

Can use this to clip any primitives: Scan convert normally. Check above condition before writing the pixel. Simple, but perhaps we do more work than necessary. Analytically clip to the rectangle, then scan convert.

February 12, 2004

¢

¡

¢

¢

¢

¢

¢

22

Clipping Lines

CS3500

February 12, 2004

23

**Intersecting Line Segments
**

Inﬁnite line equation: segments!

¥ £

£

¡

. Not good for line

£

CS3500

© ¢ ©

¡

.

¢

¤

¢

¤

Represent sides of clip-rectangles and lines for clipping . Both this way, with two parameters t and s. Solve for . should be within

£ ¢

© ¡

¡

¢ ¥

¢

¤

¢

¤

¥

February 12, 2004

24

**Cohen-Sutherland Algorithm
**

Identify line segments that can be accepted trivially. Identify line segments that can be rejected trivially. For the rest, identify the segment that falls within the cliprectangle. For ease of this, assign outcodes to each of the 9 regions.

CS3500

February 12, 2004

25

Region Outcodes

Bits from left to right:

¡

1001 yM 0001

1000

1010

CS3500

¢ ¨

¢ ¢

¡

¢

0000 0010

¨

ym 0101 xm 0100 xM 0110

February 12, 2004

26

Overall Algorithm

Accept: Reject: code1 code0 == 0 code1 & code0 != 0

Else, identify one of the boundaries crossed by the line segment and clip it to the inside. Do it in some order, say,

TOP, RIGHT, BOTTOM , LEFT . BOTTOM

We also have: TOP = 1000, 0001, RIGHT = 0010

= 0100,

LEFT

=

CS3500

February 12, 2004

27

**Intersecting with Right/Top
**

if (code & RIGHT) // Intersects right boundary // Adjust right boundary to the intersection with

¥

¡

¥

¥

ComputeCode(

**if (code & TOP) // Intersects top boundary // Adjust top boundary to the intersection with
**

¥ ¥ ¥

ComputeCode(

CS3500

©

¤

¤

¤

¤

©

¡

¢

¥ ¥

¢ §

¥

¢

¢

¡

©

)

¢

¢

¡

¢

¤ ¤ ¤ ¤

©

©

¡

¢ ¢ ¢ ¢

¥ ¥

§

¥

©

¡

¢

¢

)

February 12, 2004

¢

¢

28

Whole Algorithm

0 code0 ComputeCode(x0, y0), code1 1 if (! (code1 code0)) Accept and Return 2 if (code1 & code0) Reject and Return code1 ? code1 : code0 3 code line. 4 if (code & TOP) Intersect with line. 5 elsif (code & RIGHT) Intersect with line. 6 elsif (code & BOTTOM) Intersect with line. 7 elsif (code & LEFT) Intersect with 8 if (code == code1) Replace EndPoint1. 9 else Replace EndPoint0. 10 Goto step 1.

©

©

©

¡

¢

¡

¢

CS3500

February 12, 2004

29

4 to accept and 3 to reject.

CS3500

February 12, 2004

30

Discussion

Simple logical operations to check intersections etc. Not efﬁcient, as external intersections are not eliminated. In the worst case, 3 intersections may be computed and then the line segment could be rejectd. 4 intersections may be computed before accepting a line segment.

CS3500

February 12, 2004

31

Clipping Polygons

Restrict drawing/ﬁlling of a polygon to the inside of the clip rectangle. A convex polygon remains convex after clipping. A concave polygon can be clipped to multiple polygons. Can perform by intersecting to the four clip edges in turn.

CS3500

February 03, 2004

32

An Example

CS3500

February 03, 2004

33

An Example

CS3500

February 03, 2004

34

**Sutherland-Hodgman Algorithm
**

Input: A list of vertices to and from to

£ £ £

. Implied edges from

CS3500

£ ¤¢

£ ¤¢

¡

.

£

¢

£

£

¡

¡

Ouput: Another list of vertices giving the clipped polygon. Method: Clip the entire polygon to the inﬁnite line for each clip edge in turn. Four passes, the output of each is a partially clipped polygon used as input to the next. Post-processing to eliminate degenerate edges.

February 03, 2004

¡

¡

¢

35

Algorithm Detail

Process edges one by one and clip it to a line. Start with the edge .

¡ ¢

Compare the current edge with the current clip line. Clip it to lie within the clip rectangle.

**Repeat for the next edge processed. When processing and as the out vertex.
**

¡ ¢

£ £

¡

£ ¤¢

¡

¡

¥ £ £ ¤¢

¡

¡ ¢

¡

¡

¥

. Till all edges are

£

£ ¤¢

¡

, treat

¥

¡

¥

as the in vertex

¡

£ ¤¢

£

¡

¡

¡

£

¡

CS3500

February 03, 2004

36

**At Each Step ...
**

in vertex: (already handled). out vertex: . Four cases:

¡

s

s p p In Out s

p p s

In Out

In Out

In Out

CS3500

February 03, 2004

37

Function SuthHodg()

s last(inVertexList), p removeNext(inVertexList) while (notEmpty(inVertexList)) if (inside(p, clipBoundary)) if (inside(s, clipBoundary)) addToList(p, outVertexList) // Case 1 intersect(s, p, clipBoundary) // Case 4 else i addToList(i, outVertexList), addToList(p, outVertexList) elsif (inside(s, clipBoundary)) intersect(s, p, clipBoundary) // Case 2 i addToList(i, outVertexList) p, p removeNext(inVertexList) s

© © © ©

CS3500

©

©

February 03, 2004

38

Complete Algorithm

Invoke SuthHodg() 4 times for each clip edge as clipBoundary. The outVertexList after one run becomes the inVertexList for the next. Uses list data structures to implement polygons. Function inside() determines if a point is in the inside of the polygon. We can deﬁne it as “being on the left when looking from ﬁrst vertex to the second”. Can be extended to clip to any convex polygonal region!

February 03, 2004

CS3500

39

End of Class 15

CS3500

February 03, 2004

40

Filled Rectangles

Write to all pixels within the rectangle. , colour)

¡ ¡

**Function FilledRectangle ( do for do for . colour) WritePixel ( EndFunction
**

¢

¢

¢

¢

¢

How about non-upright rectangles? General polygons?

¡

¡

¢

¢

¢

¢

¢

CS3500

February 03, 2004

41

Filled Polygons

For each scan line, identify spans of the polygon interior. Strictly interior points only. For each scan line, the parity determines if we are inside or ouside the polygon. Odd is inside, Even is outside. Trick: End-points count towards parity enumeration only if it is a min point. Span extrema points and other information can be computed during scan conversion. This information is stored in a suitable data structure for the polygon.

February 03, 2004

CS3500

42

Parity Checking

D

F C E

A

B

CS3500

February 03, 2004

43

**Scan Converting Filled Polygons
**

Find intersections of each scan line with polygon edges. Sort them in increasing -coordinates.

Use parity to ﬁnd interior spans and ﬁll them. Most information can be computed during scan conversion. A list of intersecting polygons stored for each scan line. Use edge coherence for the computation otherwise.

February 03, 2004

CS3500

44

Special Concerns

Fill only strictly interior pixels: Fractions rounded up when even parity, rounded down when odd. Intersections at integer pixels: Treat interval closed on left, open on right. Intersections at vertices: Count only Horizontal edges: Do not count as

vertex for parity.

!

¢ ¢

CS3500

February 03, 2004

45

Edge Coherence

If scan line intersects with an edge , it is likely that also does. (Unless is the max vertex.)

¢

**When moving from to .
**

**Store the integer part of , the numerator ( denominator ( ) of the fraction separately.
**

¤ ¢ ¤

For next scan line, add to numerator. If sum , increment integer portion, subtract from goes numerator.

¤ ¤

CS3500

©

¢

¨

¢

to

, the

¡

¥

**-coordinate goes from
**

¥ £

£

© ¢ ¥ £

¢

£

¤

¤

¡§

¡§

©

¡ ¢ ¢ ¢

§

¥

) and the

§ ¤

¢

February 03, 2004

¢

46

**Filled Polygon Scan Conversion
**

Perform all of it together. Each scan line should not intersected with each polygon edge! Edges are known when polygon vertices are mapped to screen coordinates. Build up an edge table while that is done. Scan conversion is performed in the order of scan lines. Edge coherence can be used; an active edge table can keep track of which edges matter for the current scan line.

February 03, 2004

CS3500

47

**Edge Table for a Polygon
**

Construct a bucket-sorted table of edges, sorted into for the edge. buckets of Each bucket contains a list of edges with , in the increasing order of coordinate of the lower end point.

£

Each edge is represented by its for the edge, lower point, and the slope as a rational number.

¡

**This is the basis for constructing the Active Edge Table to compute the spans.
**

February 03, 2004

¢

¢

¢

¢

of the

¢

CS3500

48

**Polygon and Edge Table
**

35 30 25 20 15 10 5

5 10 15 20 25 30 35

25

30, 20, −15, 5 30, 5, 0, 10 32, 30, 5, 22 20, 15, −10, 15

32, 20, 15, 7

...

20 10 5

... ...

10, 15, 15, 5

CS3500

February 03, 2004

49

**Active Edge Tables
**

Start with the lowest value and an empty AET.

¢

Insert edges from bucket of ET AET. and are sorted on .) (They have Between pairs of AET entries lie spans. Fill them. Remove edges from AET where is the point.

¡

¢

**Compute next point on edge using coherence. (Increment by 1 and numerator by , etc. Or vice versa)
**

¤

£

¢

¢

¢

¢

CS3500

¢

**Continue above 4 steps till ET and AET are empty.
**

February 03, 2004

50

**Polygon and Edge Table
**

y = 15 y = 22 y = 27

AET

20, 9, −10, 15

32, 31, 5, 22

AET

30, 5, 0, 10

32, 32, 5, 22

AET

30, 5, 0, 10

30, 14, −15, 5

32, 24, 15, 7

32, 34, 5, 22

CS3500

February 03, 2004

51

Pattern Filling

A rectangular bit-map with the desired pattern can be used to ﬁll the interior with a pattern. If pattern

¦ ¢ ¨

£

**, draw pixel, else ignore.
**

¥

£

are row, col indices. Lower left corner at 0 and 0. are the pattern height and width.

¦ §

¡¢

¡¢

¢ ¨

¢

CS3500

February 03, 2004

52

**Scan Conversion: Summary
**

Filling the frame buffer given 2D primitives. Convert an analytical description of the basic primitives into pixels on an integer grid in the frame buffer. Lines, Polygons, Circles, etc. primitives. Filled and unﬁlled

Efﬁcient algorithms required since scan conversion is done repeatedly. 2D Scan Conversion is all, even for 3D graphics.

February 03, 2004

CS3500

53

**Scan Conversion: Summary
**

High level primitives (point, line, polygon) map to window coordinates using transformations. Creating the display image on the Frame Buffer is important. Needs to be done efﬁciently. Clipping before ﬁlling FB to eliminate futile effort. After clipping, line remains line, polygons can become polygons of greater number of sides, etc. General polygon algorithm for clipping and scan conversion are necessary.

February 03, 2004

CS3500

54

End of Class 16

CS3500

February 03, 2004

55

End of Class 17

CS3500

February 03, 2004

- 2D transforms
- ComputerGraphics_VisibleSurfaceDetermination
- ComputerGraphics_RepresentationOfPrimitives
- ComputerGraphics_ProjectiveGeometry
- ComputerGraphics_Lighting_N_Shading
- ComputerGraphics_History_N_2D
- ComputerGraphics_Colours
- ComputerGraphics_3D_Part2
- ComputerGraphics_3D_Part1
- Fundamentals of Image Processing
- An Introduction to Digital Image Processing
- Computer Vision - A Modern Approach by Forsythe Ponce
- Vehicle Detection_General Information
- Vehicle Detection in Monochrome Images
- Vehicle Detection Combining Gradient Analysis and AdaBoost Classification
- Vehicle Detection and Tracking_Rajagopalan
- Robust Real-Time Object Detection
- Road Vehicle Recognition in Monocular Images
- Real-Time Vehicle Detection Using Classified Background Learning
- Real-Time on-Road Vehicle Detection With Optical Flows and Haar-Like Feature Detector
- Real-Time Object Detection for Smart Vehicles
- Real-Time Depth Estimation and Obstacle Detection From Monocular Video
- Rapid Object Detection Using Boosted Cascade of Simple Features
- OpenCV Object Detection HowTo

- 2DAlgorithms
- computer notes Filled Area Primitives I
- Lecture 8
- 2DView
- Polygons
- Clipping Algm
- Graphics 4
- Explained Nicely
- Polygon Fill
- Lecture06-2DViewing-1
- cyrus beck algorith
- New Microsoft Office Word 97 - 2003 Document
- raster_graphics
- 10804278
- Polygon Filling
- scanline
- URISA Journal Volume 20 No. 1 2008
- 2D Clipping 1
- 7 Clipping
- Solid Area Scan Conversion
- LIAN BARSKY
- cg-2013
- Line Drawing,Line Clipping,Polygon Cliping Algorithm
- SD03 spatial objects
- Random Polygon Generation
- My First Try
- Maximum Area of Paralelepiped
- Cg Clipping algos
- Clipping (2)
- Maya - Poligonal Modeling

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd