C6-Visualization

advertisement
Chapter 6
Fundamental Algorithms
Yingcai Xiao
Types of Visualization
Transformation Types
1.Data (Attribute Transformation)
2.Topology (Topological Transformation)
3.Geometry(Geometric Transformation)
4.Combined
Visualization Algorithm Types
1.Scalar Algorithms
2.Vector Algorithms
3.Tensor Algorithms
4.Modeling Algorithms
Color Mapping
Scalar Algorithms: Color Mapping
•
Color mapping is a common scalar
visualization technique that maps scalar
data to colors.
• The scalar mapping is implemented by
indexing into a color lookup table
(discrete).
Scalar Algorithms: Color Mapping
v
i
rgb0
rgb1
rgb2
…
rgbn-1
color
Scalar Algorithms: Color Mapping
V < min => i = 0
V > max => i = n-1
i = (n-1) * (V - min) / (max – min)
max lower bound (mlb)
i = (truncate) (n-1) * (V - min) / (max – min)
least upper bound (lub)
i = (ceiling) (n-1) * (V - min) / (max – min)
A Color Table
Scalar Algorithms: Color Mapping
• To define a color table we need to provide
the number of colors and the color for
each entry.
• To use a color table we need to provide
the range of the scalar values.
• One color table can be used by multiple
scalars.
A Color Map
Scalar Algorithms: Color Mapping
• A color table is discrete.
• A transfer function is continuous.
• A transfer function can be any
monotonic expression that maps scalar
value into a color specification
(continuous).
R = Fr(V); G = Fg(V); B = Fb(V);
Contouring
Scalar Algorithms: Contouring
A contour is a line
(2D) or a surface
(3D) of constant
data values.
Scalar Algorithms: Contouring
Contouring: Edge Tracking (2D)
Tracks a contour as it moves across cell boundaries.
1.For each unprocessed cell, check if the contour passes through
one of its edges by checking if the contour value is between the
nodal data values.
2.If not, mark the cell processed and go to the next unprocessed cell.
3.If an edge intersection detected, follow the contour to the exit edge
and track the contour to the next cell until the contour closes itself
or exit from a boundary edge. Mark each cell processed as the
contour passes it.
4.Start the next unprocessed cell till all cells are processed.
Contouring: Marching Squares (2D)
Processing each cell independently, using state code to determine
how to draw the contour line.
1. Loop through every cell. For each cell,
2. Encoding the state of each vertex as binary code (state code):
inside (data value > contour value) or outside (data value <
contour value).
Contouring: Marching Squares (2D)
3. Create an index based on the bitwise combined state codes of
the vertexes. (Similar to the outcode in Cohen-Sutherland
clipping)
4. Using the index to look up the topological state of the cell in a
case table. (how)
5. Calculate the contour location (geometry) for each edge in the
case table. (where)
Marching Squares: Case Table
V3
V4
V1
V2
Contouring: Marching Squares (2D)
• 16 cases (4 bit indexing)
• 6 unique topological cases (one unique case for n vertex inside, n
= 0, 1, 2, 3, 4. One additional case for 2 inside vertexes: diagonal
(vs. same side).
• From programming point of view, there are only 4 unique cases:
no draw (n=0 or 4); cut one corner (n=1 or 3); cut one side (two
connected corners); and cut two opposite corners.
Contouring Ambiguity
0
4
8
0
• Need to see how its neighbors are drawn to decide which way to
draw.
• Or to use gradient information to decide which way to draw.
Marching Cubes
Marching Cubes (3D)
• Similar to 2D Marching Squares.
• Larger case table: 8 vertices, 256 cases.
• 15 unique cases.
Marching Cubes
Scalar Generation
Scalar Generation
• Converting complex input into a scalar (single valued) to use
scalar algorithms.
e.g.: the length of a vector field.
• Each data field has one data value.
valuecolor
valuecontour
Programming
Color Map Programming: Creating a Color Table
vtkLookupTable *lut = vtkLookupTable:New();
lut->SetHueRange(0.667, 0); //value range [0, 2* П]
lut->SetSaturationRange(1,1);
lut->SetValueRange(1,1);
lut->SetAlphaRange(1,1); // transparency
lut->SetNumberOfColor(256);
lut->Build();
Color Map Programming: Creating a Color Table
• Linear interpolation to build the table
c: h, s, v, a;
• Modify the color of an entry (i) in the LUT
lut->SetTableValue(i, h, s, v, a);
Color Map Programming: Using a Color Table
• mapperSetLookupTable(lut)
• There is a default red—blue color table.
• Mapper maps scalars to colors according to
lut
(Linear interpolation b/w entries)
• For the default lut, it uses data range set by
mapperSetScalarRange(d0, d1)
• To turn the scalar-color mapping off:
Color Map Programming: Using a Color Table
• To force VTK to use a single object color:
ActorGetProperty()SetColor(R,G,B)
• SubClassing from vtkLookUp Table
• VtkLogLookUpTable uses log scale instead
linear interpolation.
Contour (Isosurface) Programming
// Create an implicit function (continuous)
vtkQuadric *q = vtkQuadric::New();
qSetCoefficients=(5,1,2,0,1,0,0,2,0,0);
// F(x,y,z) = 5x2 + y2 + 2z2 + yz + 2y
F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x +
a7*y + a8*z + a9
//Create a sample filter (discrete)
vtkSampleFunction *s = vtkSampleFunction::New();
sSetImplicitFunction(q);
sSetSampleDimensions(50,50,50); // uniform grid
Contour (Isosurface) Programming
//Create a contour filter object
vtkContourFilter *c= vtkContourFilter::New();
cSetInput(sGetOutput());
//Create contours
cGenerateValues(4,0,3)
//first: number of contours
//second: starting value
//third: ending value
Contour Programming
//Create a mapper to hold the geometry of the contours
vtkPolyDataMapper *m= vtkPolyDataMapper::New();
mSetInput(cGetOutput);
mSetScalarRange(0,3); // for color mapping
//Create an actor to hold the geometry
vtkActor *a= vtkActor::New();
aSetMapper(m);
Contour (Isosurface) Programming
Vector Algorithms
Vector data is a three-dimensional representation of
direction and magnitude.
3 values: (vx, vy, vz) => direction and length
Vector Algorithms: Directed Lines
Draw a directed line based on the vector value at each data point. A
scaling factor is needed to map the data vector field to the display
vector field so that the displayed vectors will not be too small or too
large.
Vector Algorithms: Hedgehogs
Similar to Directed Lines, but no direction arrow on the lines.
Vector Algorithms: Oriented Glyphs
Similar to Directed Lines,
but use graphical objects
to represent vector values.
Vector Algorithms: Warping
Deformation of geometry according to a vector field.
DX =aV
Where DX is the deformation,
V is the vector field and
α is the scaling factor.
Vector Algorithms: Displacement Plots
Shows the motion of an object in the direction perpendicular to its
surface.
Vectors are converted to scalars by
computing the dot product between
the surface normal (N) and vector (V)
at each point.
Where D is the displacement, V is
the vector field, N is the normal field
and α is the scaling factor.
Vector Algorithms: Time Animation
Time dependent geometry change according to a vector field.
dX =aVdt
Where dX is the geometry change, V is the vector field, α is the scaling
factor and dt the time elapsed from previous step.
Most vector algorithms need to use a scaling factor to map the data
vector field to the display so that the displayed results will not be too
small or too large.
Vector Algorithms: Streamlines
Vector Algorithms: Streamlines
Particle Traces: trajectories traced by fluid particles over time. Each
trajectory follows a particle.
Streaklines: the set of particle traces at a particular time that have
previously passed through a specific point.
Streamlines: a snap shot of how particles will move at different locations
at a given time. The tangent of the streamline curve at any given
location represents the vector value at the location.
ds /dt=V
where s is the path on a streamline, V is the vector field.
Vector Algorithms: Streamlines
When the vector field is time independent, all three methods can
generate the same result.
Tensor Algorithms
9 data values at each point
Tensor Algorithms
Convert a tensor into three vectors (X)
AX = X
det |A-I| = 0
Using three eigenvalues and three eigenvectors:
1 2 3
X1  X2  X3
Tensor ellipsoid: an ellipsoid drawn using the three eigenvectors
as the major, medium, minor axis.
Tensor Algorithms
Modeling Algorithms
For creating or changing dataset geometry or topology.
Modeling Algorithms
Source Objects:
used to define geometry, read data from data file, create data.
Implicit Functions:
F(x, y, z) = C:
Generate geometry.
Region separation, F>4, F=4, F<4.
Modeling Algorithms
Modeling Objects
F(x,y,z) = x*x + y*y + z*z
=> Creates a data set with field value F(xi,yj,zk);
F(x,y,z) = 1.0;
=> Creates an Isosurface (a sphere object).
Logical operations on two fields: F and G
FG = min(F, G)
FG = max(F,G)
F - G = max(F-G)
Modeling Algorithms
Implicit Modeling
Scalars are generated using a distance function to a given
object.
Cutting:
Cutting through a data set with a surface and then display the
interpolated data values on the surface.
•Geometric intersections
•Interpolate data values onto the surface.
•Map the data into color or contours.
Modeling Algorithms
Cutting: Cutting through a data set with a surface and then
display the interpolated data values on the surface.
Download