CPCS 391 Computer Graphics 1 - PowerPoint PPT Presentation

About This Presentation
Title:

CPCS 391 Computer Graphics 1

Description:

CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 2 – PowerPoint PPT presentation

Number of Views:151
Avg rating:3.0/5.0
Slides: 34
Provided by: Christop499
Category:

less

Transcript and Presenter's Notes

Title: CPCS 391 Computer Graphics 1


1
CPCS 391 Computer Graphics 1
  • Instructor Dr. Sahar Shabanah
  • Lecture 2

2
Graphics Application Distinctions
  • Sample-based graphics
  • discrete samples are used to describe visual
    information
  • pixels can be created by digitizing images, using
    a sample-based painting program, etc.
  • example programs Adobe Photoshop, GIMP
  • Geometry-based graphics
  • geometrical model is created, along with various
    appearance attributes, and is then sampled for
    visualization (rendering)
  • often some aspect of physical world is visually
    simulated
  • examples of 2D apps Adobe Illustrator, Adobe
    Freehand, Corel CorelDRAW
  • examples of 3D apps Autodesks AutoCAD2010,
    Maya, 3D Studio Max

3
Sample-based Graphics
  • Images are made up of grid of discrete pixels,
    for 2D picture elements
  • Pixels are point locations with associated sample
    values, usually of light intensities/colors,
    transparency, and other control information
  • When we sample an image, we sample the point
    location along the continuous signal and we
    cannot treat the pixels as little circles or
    squares

light intensity
1 pixel
4
Sample-based Graphics
  • Samples created
  • directly in paint-type program,
  • as a sampling of continuous (analog) visual
    materials. E.g., photograph can be sampled (light
    intensity/color measured at regular intervals)
    with scanners, cameras
  • Sample values can also be input numerically
    (e.g., with numbers from computed dataset)
  • Once an image is defined as pixel-array, it can
    be manipulated
  • Image editing changes made by user, such as
    cutting and pasting sections, brush-type tools,
    and processing selected areas
  • Image processing algorithmic operations that are
    performed on image without user intervention.
    Includes blurring, sharpening, edge-detection,
    color balancing, rotating, and warping.
    Pre-processing step in computer vision

5
Sampling an Image
3D scene
  • A color value is measured at every grid point and
    used to color corresponding grid square
  • Note this poor sampling and image reconstruction
    method creates blocky image

0 white, 5 gray, 10 black
6
Whats the Advantage?
  • Once image is defined in terms of colors at (x,
    y) locations on grid, can change image easily by
    altering location or color values
  • E.g., if we reverse our mapping above and make 10
    white and 0 black, the image would look like
    this
  • Pixel information from one image can be copied
    and pasted into another, replacing or combining
    with previously stored pixels

7
Whats the Disadvantage?
  • WYSIAYG (What You See Is All You Get) No
    additional information
  • no depth information
  • cant examine scene from different point of view
  • at most can play with the individual pixels or
    groups of pixels to change colors, enhance
    contrast, find edges, etc.
  • But recently, strong interest in image-based
    rendering to fake 3D scenes and arbitrary camera
    positions. New images constructed by
    interpolation, composition, warping and other
    operations.

Photo Tourism Exploring photo collections in 3D
(Siggraph 2006)
8
Geometry-Based Graphics
  • Geometry-based graphics applications store
    mathematical descriptions, or models, of
    geometric elements (lines, polygons,
    polyhedrons) and associated attributes (e.g.,
    color, material properties). Elements are
    primitive geometric shapes, primitives for short
  • Images created as pixel arrays (via sampling of
    geometry) for viewing, but not stored as part of
    model. Images of many different views are
    generated from same model
  • Users cannot usually work directly with
    individual pixels in geometry-based programs as
    user manipulates geometric elements, program
    resamples and redisplays elements
  • Increasingly rendering combines geometric and
    sample-based graphics, both as performance hack
    and to increase quality of final product

9
What is Geometric Modeling?
  • What is a model?
  • Captures salient features (data, behavior) of
    thing/phenomenon being modeled
  • data includes geometry, appearance attributes
  • Real some geometry inherent
  • physical (e.g., actual object such as a pump)
  • non-physical (e.g., mathematical function,
    weather data)
  • Abstract no inherent geometry, but for
    visualization
  • organizational (e.g., company org. chart)
  • quantitative (e.g., graph of stock market)
  • Modeling is coping with complexity

10
Modeling vs. Rendering
  • Modeling
  • Rendering
  • Create models
  • Apply materials to models
  • Place models around scene
  • Place lights in scene
  • Place the camera
  • Rendering
  • Take picture with camera
  • Both can be done by modern commercial software
  • Autodesk MayaTM ,3D Studio MaxTM, BlenderTM, etc.

Point Light
Spot Light
Directional Light
Ambient Light
lighting assignment by Patrick Doran, Spring
2009
11
Decomposition of a Geometric Model
  • Divide and Conquer
  • Hierarchy of geometrical components
  • Reduction to primitives (e.g., spheres, cubes,
    etc.)
  • Simple vs. not-so-simple elements (nail vs. screw)

Head
Shaft
Point
decomposition
composition
12
Hierarchical (Tree) Diagram of Nail
  • Object to be modeled is (visually) analyzed, and
    then decomposed into collections of primitive
    shapes.
  • Tree diagram provides visual method of expressing
    composed of relationships of model
  • Such diagrams are part of 3D program interfaces
    (e.g., 3D Studio MAX, Maya)
  • As pointer data structure to be rendered, it is
    called a scenegraph

root node
Nail
Head (cylinder)
Body
Shaft (cylinder)
Point (cone)
leaf nodes
tree diagram
13
Composition of a Geometric Model
Translate
Translate and Scale
Translate and Rotate
Primitives in their own modeling coordinate system
Composition in world (root) coordinate system
  • Primitives created in decomposition process must
    be assembled to create final object. Done with
    affine transformations, T, R, S (as in above
    example).

14
2D Output Primitives and Attributes
  • Primitives
  • Attributes
  • Points
  • Lines
  • Circles
  • Ellipses
  • Curves
  • Polygon
  • Text
  • Line Type, Width and Color
  • Fill Styles Hollow, Solid and Patterned
  • Text Font, Color , Size and Style
  • Text
  • Text
  • Text
  • Text

15
Scan conversion Algorithms
  • Primitives and Attributes
  • Why Scan Conversion?
  • Algorithms for Scan Conversion
  • Lines
  • Circles
  • Ellipses
  • Filling
  • Polygons

16
Scan Conversion Problem
  • To represent a perfect image as a bitmapped image.

17
Line Drawing Algorithms
  • Lines are used a lot - want to get them right.
  • Lines should appear straight, not jagged.
  • Horizontal, vertical and diagonal easy, others
    difficult
  • Lines should terminate accurately.
  • Lines should have constant density.
  • Line density should be independent of line length
    or angle.
  • Lines should be drawn rapidly.
  • Efficient algorithms.

18
DDA Digital Differential Analyzer
  • Line Left to Right
  • 1- Slope mgt0
  • sample at unit x intervals ( ?x 1),
  • calculate each succeeding y value as

19
DDA
  • 2- Slope mlt0
  • sample at unit y intervals ( ?y 1),
  • calculate each succeeding x value as
  • Line from Right to Left
  • 3- Slope mgt 0

4- Slope mlt 0
20
DDA
  • Advantages
  • Disadvantages
  • Faster than brute force.
  • Based on Calculating either ?x or ?y.
  • Mathematically well defined
  • Floating point
  • Round off error.
  • Time consuming arithmetic

21
Bresenhams Line Algorithm
  • Accurate
  • Efficient
  • Integer Calculations
  • Uses Symmetry for other lines
  • Adapted to display circles, ellipses and curves
  • It has been proven that the algorithm gives an
    optimal fit for lines

22
Bresenhams Line Algorithm
yk1
d2
y
d1
yk
Xk1
23
Bresenhams Line Algorithm
24
Bresenhams Line Algorithm
  • The sign of pk is the same as the sign of d1
    d2,
  • since ?xgt 0 for our example. Parameter c is
    independent and will be eliminated in the
    recursive calculations for pk.
  • If the pixel at yk is closer to the line path
    than the pixel at ykl (that is, d1 lt d2), then
    decision parameter pk is negative. In that case,
    we plot the lower pixel otherwise, we plot the
    upper pixel.

25
Bresenhams Line Algorithm
  • This recursive calculation of decision parameters
    is performed at each integer x position, starting
    at the left coordinate endpoint of the line. The
    first parameter, po is evaluated from Eq. 3-12 at
    the starting pixel position (xo, yo) and with m
    evaluated as ?y/?x

26
Bresenhams Line Drawing Algorithm
  • Input the two line endpoints, store the left
    endpoint (x0,y0).
  • Plot the first point (x0,y0).
  • Calculate constants ?x, ?y, and 2?y - 2?x and
    2?y, get starting values for decision parameter
    pk,
    p02?y-?x
  • At each xk along the line, starting at k 0, do
    the following test if pk lt 0, the next
    point to plot is(xk1, yk)
  • pk1 pk 2?y
  • else, the next point to plot is(xk1, yk1)
  • pk1pk 2?y-2?x
  • Repeat step 4. ?x times.

27
Bresenhams Line Algorithm
28
Midpoint Line Algorithm
  • If (BlueLine lt Midpoint) Plot_East_Pixel()
  • Else Plot_Northeast_Pixel()

29
Midpoint Line Algorithm
  • Find an equation, given a line and a point, that
    will tell us if the point is above or below that
    line?
  • If F(x,y) 0
  • (x,y) on the line
  • lt0 for points below the line
  • gt0 for points above the line
  • dF(M)

30
Midpoint Line Algorithm
  • P(xp, yp) is pixel chosen by the algorithm in
    previous step
  • To calculate d incrementally we require dnew
  • If d gt 0 then choose NE

Yp2
P(xp, yp)
31
Midpoint Line Algorithm
  • If d lt 0 then choose E

32
Midpoint Line Algorithm
  • To find Initial value of d

NE
M
E
P(x0, y0)
x01
x0
Only fractional value
Start
Initial do
  • Multiply by 2 to avoid fractions. Redefine d0,
    ?E, ?NE

33
Midpoint Line Algorithm
  • Midpoint Looks at which side of the line the mid
    point falls on.
  • Bresenham Looks at sign of scaled difference in
    errors.
  • It has been proven that Midpoint is equivalent to
    Bresenhams for lines.
Write a Comment
User Comments (0)
About PowerShow.com