Download ppt - Yingcai Xiao

Transcript
Display Hardware 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.
VTKRender: in W.C., manages the scene, light, cameras and actors (objects).
VTKLight: specifies a light.
VTKCamera: specifies a camera.
VTKActor: defines an object.
VTKProperty: defines the appearance of actors.
VTK Classes for Graphics
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor :: New() ;
VTK Demos
Step1\Cxx\Cone.cxx: basic objects
Step1\Cxx\Cone2.cxx: callbacks
Step 4\Cxx\Cone4.cxx: object property
Step 5\Cxx\Cone5.cxx: track ball
Step 6\CXX\Cone6.cxx: control and manipulation of objects
GEOMETRIC TRANSFORMATIONS and Animation
Length: |V|=(x2 + y2)1/2
e.g.:
,
if < 90 => cos > 0 => V W > 0.
if > 90 => cos < 0 => V W < 0.
5.Normal: a unit vector perpendicular to a surface
.
A point p(xp,yp) is on the line if f(xp,yp) = 0.
When b < 0:
When b > 0:
Parametric Form:
P1(x1,y1)
P0(x0,y0)
0 <= t <= 1
0 <= t <= 1
Translate a point
The algebraic representation of translation of point P(x,y) by D(dx,dy) is
x’= x + dx
y’= y + dy
To move a shape: translate every vertex of the shape
0
5
10
5
10
X
Y
Scale a point P(x,y) by S(sx, sy)
Algebraic:
P0’=SP0
P1’=SP1
Visual representation
After
Before
0
5
10
5
10
X
Y
Scaling
Rotation
P’=SHx(a)P
Shear in x against y by a (or an angle).
x’ = x+ay
Shear in y against x by b (or an angle).
x’=x
change: location, orientation;
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.
Composition of 2D Transformation
For every vertex (P) on the object: P’ = T(P1)R()T(-P1)P
y
y
x
to original P1
Scale and rotate the house around P1 and move it to P2
y
x
P1
Original
house
y
x
P1
P’ = T(P2) R()S(Sx,Sy)T(-P1)P.
except uniform scaling (sx=sy) can be swapped with rotation.
5.4 Window-to-Viewport Transformation
y
x
y
z
Translation:
Scaling:
(0,0,0)
d
z
z
0
View Plan
Additive
37
Color
YMCK
Subtractive
38
Color
HSV:
39
HSV
Basic Reflection Model:
I= kaIa + kd Id (l · n) + ksIs(v · r ) α
I : reflected-light intensity
Lambertian / Diffusive Reflection:
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.
Specular Reflection:
Viewing-direction dependent
Is : incident specular-light intensity
ks : object specular-reflection coefficient
direction (v).
fatt = 1/(a + bd + cd2)
a,b,c: constant, linear, quadratic attenuation coefficients.
 
I = kaIa + fatt kd Id (l · n) + fatt ksIs(v · r ) α
I = kaIa + Id kdcos() / (a + bd + cd2)
+ Is ks cos α () / (a + bd + cd2)
Summary:
 
I = kaIa + fatt kd Id (l · n) + fatt ksIs(v · r ) α
I = kaIa +
Is ks cos α () / (a + bd + cd2)
Colored Lights and Surfaces :
: color channel
->Colored lights:
ka, kd, ks,
I = Ia ka + fatt Id kd(ln) + fatt Is ks(vr) α
with = r, g, b.
 Ir = Iar kar + fatt Idr kdr(ln) + fatt Isr ksr(vr) α
Ig = Iag kag + fatt Idg kdg(ln) + fatt Isg ksg(vr) α
Ib = Iab kab + fatt Idb kdb(ln) + fatt Isb ksb(vr) α
Multiple Lights:
I = Ia ka + fatti [Idi kd(l i n) + Isi ks(vr i) α]
with = r, g, b.
m: number of lights.
OpenGL support ambient component for individual light.
 
Two approaches: object order and image order
 
(Image created by Russell Yuncker) (Image created by Jian He)
Simple Ray Tracing:
for(each object in scene) {
if(object is intersected and
record intersection point and object id.
}
set pixel’s color to that at closest object intersection point
(using the I formula given above.)
}
}
Recursive Ray Tracing:
Set pixel’s color to that at closest object intersection point using the I formular given below.
I= (1- kr - kt )Iregular+ kr Ir+ kt It
Iregular: regular reflection of lights from light source.
Computed by the formula above.
kr : reflection coefficient.
kt : transmission coefficient.
 
Each surface is composed of triangle patches (ObjectsPrimitives).
Project each triangle on to the view plane.
Render the projected triangle (compute the shade colors in the triangle).
No consideration of reflection light from other objects.
H.W.: Faster: Open GLVTK
Using Marching Cubes to create isosurfaces (geometrical objects).
 
Frame Buffer: a buffer of memory to store the colors of the screen, one memory cell per pixel.
Shading: Rendering of a projected triangle.
 
 
Phong shading interpolate vertex normals and vertex colors to each pixel and then use the Rc formula to compute the shaded color at the pixel.
Flat/Constant Shading: http://www.yourdictionary.com/computer/flat-shading
for (each object)
compute its reflection
for(each pixel in the triangle)
if(closer to the viewer than the
current z buffer value) {
}
{ for(each vertex of in the triangle)
compute the vertex reflection
for(each pixel in the triangle)
if(closer to the viewer than the current z buffer value)
{ update z buffer with the new z
interpolate the pixel color
from the vertex reflections.
if(closer to the viewer than the
current z buffer value)
interpolate the pixel normal
from the vertex normals
compute the pixel color/relection
}
if(closer to the viewer than the
current z buffer value)
interpolate the pixel normal
from the vertex normals
compute the pixel color/relection
}
Visualization (surface-based) : transforming data into graphics primitives with geometry and attributes (color, textures, patterns, …)
Rendering: transforming graphics primitives into images
65
Primitive

Recommended