1 / 64

Yingcai Xiao

Yingcai Xiao. Chapter 3 Computer Graphics Primer. Graphics Using VTK. VTK Classes for Graphics. VTKRenderWindow : a class specifies which part of physical screen we can use to draw , in DC, manages a window . VTKRenderWindowInteractor : Enable interaction of a window .

aquila
Download Presentation

Yingcai Xiao

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Yingcai Xiao Chapter 3 Computer Graphics Primer

  2. Graphics Using VTK

  3. VTK Classesfor Graphics • VTKRenderWindow: a class specifies which part of physical screen we can use to draw, in DC, manages a window. • VTKRenderWindowInteractor: Enable interaction of a window. • VTKRender: in W.C., manages the scene, light, cameras and actors (objects). • VTKLight: specifies a light. • VTKCamera: specifies a camera. • VTKActor: defines an object. • VTK???Mapper: defines geometry of actors. • VTKProperty: defines the appearance of actors.

  4. VTK Classesfor Graphics • Objects are created using Class::New(); vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor :: New() ; • vtkRenderWindow *ren= vtkRenderWindow :: New() ; iren->SetRenderWindow(ren) ; • A property can be shared by many actors

  5. VTK Demos • T:\xiao\visualization\Examples\src\Tutorial • Step1\Cxx\Cone.cxx: basic objects • Step1\Cxx\Cone2.cxx: callbacks • Step 3\Cxx\Cone3.cxx: viewport • Step 4\Cxx\Cone4.cxx: object property • Step 5\Cxx\Cone5.cxx: track ball • Step 6\CXX\Cone6.cxx: control and manipulation of objects

  6. GEOMETRIC TRANSFORMATIONSand Animation

  7. GEOMETRIC TRANSFORMATIONS Review of Mathematical Preliminaries Points: • Vectors: directional lines P1(x1,y1) P0(x0,y0)

  8. 1. A vector has a direction and a length: Length: |V|=(x2 + y2)1/2 A unit vector: |V| = 1 e.g.: • Normalize a vector: 2. Add two vectors • 3. Scalar Multiplication

  9. V •  W , • 4. Dot product of two vectors scalar • V  W if  = 90 => cos = 0 => V  W = 0. • if  < 90 => cos > 0 => V  W > 0. • if  > 90 => cos < 0 => V  W < 0. • 5.Normal: a unit vector perpendicular to a surface

  10. . • Lines y=mx+b e.g.: y = x; ax+by+c=0 Let f(x,y) = ax + by + c A point p(xp,yp) is on the line if f(xp,yp) = 0. When b < 0: p(xp,yp) is above the line if f(xp,yp) < 0. p(xp,yp) is below the line if f(xp,yp) > 0. When b > 0: p(xp,yp) is above the line if f(xp,yp) > 0. p(xp,yp) is below the line if f(xp,yp) < 0.

  11. Parametric Form: P(t)=P0+t(P1-P0); 0 <= t <= 1 P1(x1,y1) P0(x0,y0) • P(t)=P0+t(P1-P0)

  12. Where, • x(t) = x0 + t * (x1 – x0) • y(t) = y0 + t * (y1 – y0) • 0 <= t <= 1 • x(t) = (1-t) * x0 + t * x1 • y(t) = (1-t) * y0 + t * y1 • 0 <= t <= 1

  13. 2D Transformations • Translate a point The algebraic representation of translation of point P(x,y) by D(dx,dy) is x’= x + dx y’= y + dy Its “matrix” representation is • Its logical representation is P’ = P + D • Its visual representation is P’ (x’,y’) P(x,y) D(dx,dy)

  14. Y Y 10 10 5 5 X X 0 0 5 5 10 10 (4,5) (7,5) (10,1) (7,1) Before Translation After Translation • To move a shape: translate every vertex of the shape

  15. Scaling (relative to the origin) Scale a point P(x,y) by S(sx,sy) Algebraic: x’=sx* x y’=sy* y Matrix: Logic: P’ = SP or P’ = S(sx,sy)P Scale a line P0P1 (scale each point) P0’=SP0 • P1’=SP1

  16. Y Y 10 10 5 5 X X 0 0 5 5 10 10 (4,5) (7,5) (2,5/4) (7/2,5/4) Before Scaling After Scaling • Scale a shape: scale every vertex of the shape. Visual representation Uniform Scaling:sx=sy

  17. (4.9, 7.8) (2.1, 4.9) (5,2) (9,2) Y Y Y Y Before Rotation After Rotation 10 10 10 10 5 5 5 5 X X X X 0 0 0 0 5 5 5 5 10 10 10 10 • Visual representation Before After Rotate a shape: rotate every vertex of the shape

  18. Summary • Translation: P’ = P + D • Scaling: P’ = S P • Rotation: P’ = R P Homogeneous Coordinates: P(x,y,w) (x,y) to (x,y,w) : (x,y,w) to (x,y)

  19. y’= y + dy • w’=1 • x’= x + dx • P’’ = T(dx2 , dy2)P’ • = T(dx2 , dy2) T(dx1 , dy1) P • = T(dx2+dx1, dy2+dy1) P

  20. Scaling P’=S(Sx, Sy)P • P’’ = S(Sx2 , Sy2)P’ • = S(Sx2 , Sy2)S(Sx1 , Sy1) P • = S(Sx2Sx1, Sy2Sy1)P

  21. Rotation • P’=R()P P’’=R(2)R(1)PP”=R(2+1)P

  22. Shear Transformation:SHx(a) and SHy(b) P’=SHx(a)P • Shear in x against y by a (or an angle). • x’ = x+ay • y’ = y w’=1

  23. P’=SHy(b)P • Shear in y against x by b (or an angle). • x’=x • y’=y + bx • w’=1.

  24. Y Y Y 10 10 10 5 5 5 X X X 0 0 0 5 5 5 10 10 10 Sheared in x Before Shear Sheared in y

  25. Rigid-body Transformation: T and R. • change: location, orientation; • not change: size, angle between elements. Affine Transformation: S, SH • change: size, location, angle; • not change: line (parallelism). • Note: uniform scaling is between the two. It changes size but not angle. • So far, our S, R, SH are all around the origin.

  26. y x After translation of P1 to origin y y P1  x x After rotation After translation to original P1 • Composition of 2D Transformation Rotate the house around P1 For every vertex (P) on the object: P’ = T(P1)R()T(-P1)P y

  27. y y y P1 x x x Original house P1 Translate P1 to origin Scale y y P2 x x Translate to final position P2 Rotate Scale and rotate the house around P1 and move it to P2

  28. For every vertex (P) on the object: P’ = T(P2) R()S(Sx,Sy)T(-P1)P. • Swap the order of operations:not permitted, except uniform scaling (sx=sy) can be swapped with rotation.

  29. y Maximum range of screen coordinates y Viewport 2 Window Viewport 1 x x World coordinates Window in world coordinates Window translated to origin Window scale to size of viewport Screen coordinates Translated by (u,v) to final position y y Window Window x x Screen coordinates World coordinates 5.4 Window-to-Viewport Transformation world-coordinate: inches, feet etc & screen-coordinate: pixels

  30. y x z • Matrix Representation of 3D Transformation Translation: Scaling:

  31. Rotation, around Z-axis: Rotation, around X-axis: Rotation, around Y-axis:

  32. P( x, y, z ) x xp P’(xp, yp, zp) z d z (0,0,0) Projection Plane (View Plane) Projection: Project 3D objects on to a 2D surface

  33. xp= x’ / w’ = x / (z/d + 1) • yp= y’ / w’ = y / (z/d + 1)

  34. 0 Parallel Projection: d  , lines of sight become parallel P1 0 z P2 View Plan (0,0,0)

  35. Color

  36. Color • RGB • For screen display • All other colors are combination of the three primitives • Additive

  37. Color • YMCK • For printing • All other colors are combination of the three primitives • Subtractive

  38. Color • HSV: • For human interaction • Hue (Tint) • Saturation (Color) • Value (Brightness) • Can interpolate hue and saturation

  39. Color Conversions

  40. Lighting/Shading

  41. Shading Shading: determining light reflection from objects at each pixel. Basic Reflection Model: Phong Reflection Model (most commonly used) I= kaIa + kd Id (l · n) + ksIs(v · r )α I : reflected-light intensity

  42. Ambient Reflection: Direction independent kaIa Ia : incident ambient-light intensity ka : object ambient-reflection coefficient part of the object material properties

  43. Lambertian / Diffusive Reflection: Lighting-direction dependent Idkd(ln) = Idkdcos() Id : incident difussive-light intensity kd : object diffusive-reflection coefficient  : angle between light direction (l) and surface normal (n). Both l and n are unit vectors.

  44. Specular Reflection: Viewing-direction dependent Isks(vr)α = Iskscos α (Ф). Is : incident specular-light intensity ks : object specular-reflection coefficient Ф : angle between reflection direction (r) and viewing direction (v).  : specular-reflection exponent, shaniness coefficient. 1/: roughness.

  45. Attenuation: Distance dependent, no impact on ambient light fatt = 1/(a + bd + cd2) d : distance from the light to the surface point. a,b,c: constant, linear, quadratic attenuation coefficients. I = kaIa + fattkd Id (l · n) + fattksIs(v · r )α I = kaIa + Idkdcos() / (a + bd + cd2) + Iskscos α (Ф) / (a + bd + cd2)

  46. Summary: I = kaIa + fattkd Id (l · n) + fattksIs(v · r )α I = kaIa + Idkdcos() / (a + bd + cd2) + Iskscos α (Ф) / (a + bd + cd2)

  47. Colored Lights and Surfaces : I = (Ir, Ig, Ib) = { I,= r, g, b} : color channel ->Colored lights: Ia, Id, Is, ->Colored objects: ka, kd, ks, I = Ia ka+ fatt Idkd(ln) + fatt Isks(vr) α with = r, g, b.  Ir = Iar kar + fatt Idr kdr(ln) + fatt Isr ksr(vr)α Ig = Iagkag+ fattIdgkdg(ln) + fattIsgksg(vr) α Ib = Iabkab+ fattIdbkdb(ln) + fattIsbksb(vr) α

  48. Multiple Lights: I = Ia ka+ fatti [Idikd(lin) + Isiks(vri) α] with = r, g, b. m: number of lights. OpenGL support ambient component for individual light. I = [ Iai ka+ fatti [Idikd(lin) + Isiks(vri) α]]

  49. How to get to each pixel? Two approaches: object order and image order

More Related