0% found this document useful (0 votes)
7 views7 pages

visualization-scene-graph-2010

Uploaded by

Thanhbich Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

visualization-scene-graph-2010

Uploaded by

Thanhbich Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Chapter 28

Visualization Scene Graph

Abstract Creation of a scene graph determining the hierarchy of visualized objects


is discussed. Visual objects of the scene graph are finite element faces, edges and
nodes. A Java 3DTM scene graph for visualization of a finite element model and
results is generated by class J3dScene.

28.1 Schematic of the Scene Graph

Visualization of the finite element model requires rendering its visual components
– finite element faces, edges and nodes. A scene graph is used for organizing visual
components (objects). The scene graph determining the hierarchy of the objects of
the visualizer Jvis is shown in Figure 28.1. Visual objects of the scene graph are
finite element faces, edges and nodes. They are represented by Shape3D objects.
The geometry of the faces is described by array of triangles. Appearance references
polygon attributes, material and texture. Texture is used for drawing results in the
form of contours. Edges are represented as line segments defined in a line array.
Appearance includes line attributes and color. Nodes are described by a point array
with references to point attributes and color.
All Shape3D objects (faces, edges and nodes) are attached to a transform group
TG, which defines the initial transformation for the finite element model. In our
case, we need scaling of the finite element model that is necessary to place the
model inside a window used for visualization.
The next (upper) transform group is used for providing interaction with the user.
Mouse behavior, which includes rotation, translation and zooming is connected to
this transform group. Lights, background and transform group are attached to branch
group BG, which is connected to utility class SimpleUniverse. Lights, back-
ground and mouse behavior have references to bounds that define the influence of
the corresponding scene graph nodes.

325
326 28 Visualization Scene Graph

SimpleUniverse

BG

Lights TG
Mouse
Background Behavior
Bounds TG

Faces Edges Nodes

Trian Array Appearance LineArray Appearance PointArray Appearance

Material Line Attrib Point Attrib


Poly Attrib Texture Color Attrib Color Attrib

Fig. 28.1 Scene graph for visualization of finite element model and results

28.2 Implementation of the Scene Graph

A Java 3D scene graph for visualization of the finite element model and results is
created by class J3dScene. The source code of the class constructor and a method
for adding the shape of a visual object is given below.
1 package visual;
2
3 import javax.media.j3d.*;
4 import javax.vecmath.*;
5 import java.awt.*;
6 import java.applet.Applet;
7 import com.sun.j3d.utils.universe.SimpleUniverse;
8
9 // Scene graph for visualization.
10 public class J3dScene {
11
12 private SurfaceSubGeometry subGeometry;
13
14 // Construct Java3D scene for visualization.
15 public J3dScene(Applet c) {
16
17 GraphicsConfiguration config =
18 SimpleUniverse.getPreferredConfiguration();
19
28.2 Implementation of the Scene Graph 327

20 Canvas3D canvas = new Canvas3D(config);


21 c.setLayout(new BorderLayout());
22 c.add("Center", canvas);
23
24 // Element subfaces, subedges and nodes
25 subGeometry = new SurfaceSubGeometry();
26
27 BranchGroup root = new BranchGroup();
28 Lights.setLights(root);
29 TransformGroup tg =
30 MouseInteraction.setMouseBehavior();
31
32 // Add finite element model shape
33 tg = addModelShape(tg);
34
35 root.addChild(tg);
36 root.compile();
37
38 System.out.println(" Number of polygons = " +
39 subGeometry.nVertices/3);
40 if (VisData.showDeformShape) System.out.printf(
41 " Deformed shape: max displacement ="+
42 " %4.2f max size\n", VisData.deformScale);
43 if (VisData.drawContours) {
44 System.out.printf(" Contours: %d colors" +
45 " (Magenta-Blue-Cyan-Green-Yellow-Red)\n",
46 VisData.nContours);
47 System.out.printf(" %s: Fmin = %10.4e, " +
48 "Fmax = %10.4e\n", VisData.parm,
49 subGeometry.fmin, subGeometry.fmax);
50 }
51
52 SimpleUniverse u = new SimpleUniverse(canvas);
53 u.getViewingPlatform().setNominalViewingTransform();
54 u.addBranchGraph(root);
55 }
56
57 // Add model shape to the Java 3D scene graph.
58 // tg - transform group of the scene graph.
59 // returns transform group of the scene graph
60 TransformGroup addModelShape(TransformGroup tg) {
61
62 Transform3D t3d = new Transform3D();
63 t3d.setScale(subGeometry.getScale());
64 tg.setTransform(t3d);
65
66 // Element faces composed of triangular subfaces
67 tg.addChild(facesShape());
68
69 // Edges composed of line segments
70 if (VisData.showEdges) tg.addChild(edgesShape());
71
72 // Nodes located at the model surface
73 if (VisData.showNodes) tg.addChild(nodesShape());
328 28 Visualization Scene Graph

74
75 return tg;
76 }

Statements 3–7 import Java 3D packages, an abstract windowing toolkit pack-


age, an applet package and the package for simple universe object. Constructor
J3dScene obtains Applet object c as an argument. Class Applet was used
in the main class of the visualizer for creating the main frame of the application.
Applet extends class Panel, which is the simplest container class. We use con-
tainer c for placement of a drawing canvas.
The graphics configuration is set as the preferred configuration of a simple uni-
verse object (lines 17–18). Lines 20–22 create Canvas3D object where visualiza-
tion will be performed, and place the canvas at the center of panel c.
An object of the type ModelSubGeometry is constructed in line 25. During
construction, the surface geomentry of the finite element model is created and sub-
division of element surfaces into triangles and element edges into line segments is
performed.
Object root of class BranchGroup is initialized by statement 27. Lights are
set by static method setLights in line 28. Lines 29–30 set mouse behaviors that
allow interactive transformations of a visualized finite element model. Shape ob-
jects of the finite element model are added to transform group tg in line 33. This
transform group is added to the root transform group (line 35). Lines 38–50 print
information about visualization: the number of polygons (triangles) used for ren-
dering; the number of colors for drawing contours and the results parameter and its
minimal and maximal values used for visualization. Class SimpleUniverse is
used for setting an appropriate viewpoint and as a parent of the root branch group
(lines 52–54).
Method addModelShape shown in lines 60–76 adds element faces, element
edges and nodal points to the scene graph. Lines 56–58 set a scaling transform in
such a way that the image of the finite element model has a reasonable size inside
the drawing canvas.
Lines 67, 70, and 73 add subdivided element faces, element edges and nodal
points to the transform group. The method returns the transform group tg in line
75.

28.3 Shape Objects

Methods facesShape, edgesShape and nodesShape, which produce shape


objects for element faces, element edges and nodes are considered below. All these
methods call methods of subGeometry to get geometry and then set appearance
for visual objects.
Method facesShape returns a Shape3D object containing the geometry and
appearance for element faces.
28.3 Shape Objects 329

78 // Shape object for element faces


79 private Shape3D facesShape() {
80
81 TriangleArray faces = subGeometry.getModelTriangles();
82
83 Appearance facesApp = new Appearance();
84
85 // Polygon Attributes
86 PolygonAttributes pa = new PolygonAttributes();
87 pa.setCullFace(PolygonAttributes.CULL_BACK);
88 pa.setPolygonOffset(VisData.offset);
89 pa.setPolygonOffsetFactor(VisData.offsetFactor);
90 facesApp.setPolygonAttributes(pa);
91
92 // Material
93 Color3f darkColor = new Color3f(0.0f, 0.0f, 0.0f);
94 Color3f brightColor = new Color3f(0.9f, 0.9f, 0.9f);
95 Color3f surfaceColor = VisData.modelColor;
96 if (VisData.drawContours)
97 surfaceColor = VisData.surTexColor;
98 Material facesMat = new Material(surfaceColor,
99 darkColor, surfaceColor, brightColor, 16.0f);
100 facesMat.setLightingEnable(true);
101 facesApp.setMaterial(facesMat);
102
103 if (VisData.drawContours) {
104 // Texture for creating contours
105 ColorScale scale = new ColorScale();
106 Texture2D texture = scale.getTexture();
107 facesApp.setTexture(texture);
108 TextureAttributes ta = new TextureAttributes();
109 ta.setTextureMode(TextureAttributes.MODULATE);
110 facesApp.setTextureAttributes(ta);
111 }
112
113 // Create Shape using Geometry and Appearance
114 return new Shape3D(faces, facesApp);
115 }

Method getModelTriangles provides element faces subdivided into trian-


gles, which are placed in object faces (line 81). Polygon attributes for drawing
triangles are set in lines 86–90. By default, polygons are rendered by filling the in-
terior between the vertices. Statement 87 specifies that back faces of polygons are
not drawn.
Lines 88–89 set an offset, which changes the depth values of all pixels generated
by polygon rasterization. We need offset for proper visualization of element edges
and nodes. If a polygon surface and a line segment have exactly the same Z device
coordinates then the line visibility is not guaranteed. The following two values are
used to specify the offset. Offset bias is the constant polygon shift that is added to
the final device coordinate Z value. The offset factor is the factor to be multiplied by
the slope of the polygon and then added to the final, the device coordinate Z value
of the polygon primitives.
330 28 Visualization Scene Graph

Material defined in lines 93–101 is used for specifying the reflecting properties of
the surface. Different materials are specified for mesh visualization and for results
visualization. The following constructor for the material is employed:
Material(Color3f ambientColor, Color3f emissiveColor,
Color3f diffuseColor, Color3f specularColor,
float shininess)

Here, ambientColor is the ambient color reflected off the surface of the material;
emissiveColor is the color of the light the material emits (like a light source);
diffuseColor is the color of the material when illuminated (the light bounces
off objects in random directions); specularColor is the specular color of the
material (highlights); shininess is the material’s shininess.
We use black color as the emissive color. The model color specified in class
Data is used for both ambient and diffuse colors. If results are drawn by applying
texture then an almost white color is used as the surface color (line 94). Specular
effects are modeled by a color that is close to white. In order to have light effects
line 100 enables lighting for the material. Line 101 sets material properties for the
appearance of the faces.
If the results file name is specified in the input data and, consequently, we are
going to draw results contours then a texture and its appearance are set in lines 105–
110. A one-dimensional color gradation strip is created by method getTexture
of the class ColorScale (line 105). It is set as a texture for the faces appearance
in line 106. A texture mode in the texture attributes is set to MODULATE. Choosing
this parameter means that polygon material colors will be modulated by the speci-
fied texture. Lights effects including shading and bright spots are produced for the
polygon material and are visible through the texture since it is applied as modulation
of material colors.
Line 114 creates a Shape3D object using faces geometry and appearance and
returns it to the calling method.
A shape object for the edges of the finite element model surface is created by
method edgesShape.
117 // Shape object for element edges
118 private Shape3D edgesShape() {
119
120 LineArray edges = subGeometry.getModelLines();
121
122 Appearance edgesApp = new Appearance();
123
124 LineAttributes la = new LineAttributes();
125 la.setLineAntialiasingEnable(true);
126 edgesApp.setLineAttributes(la);
127
128 ColoringAttributes ca = new ColoringAttributes();
129 ca.setColor(VisData.edgeColor);
130 edgesApp.setColoringAttributes(ca);
131
132 return new Shape3D(edges, edgesApp);
133 }
Problems 331

Geometry array edges is provided by method getModelLines as straight-


line segments sufficient for visually smooth representation of curved element edges.
Line attributes are determined in lines 124–126. Setting antialiasing to true value
(line 125) produces a smooth appearance of lines on the screen. An edge line color
is set in line 129 using the color defined in class VisData.
Finally, a shape object for surface nodes of the finite element model is made by
method nodesShape given below.
135 // Shape object for nodes
136 private Shape3D nodesShape() {
137
138 PointArray nodes = subGeometry.getModelPoints();
139
140 Appearance nodesApp = new Appearance();
141
142 PointAttributes pa = new PointAttributes();
143 pa.setPointAntialiasingEnable(true);
144 pa.setPointSize(3.0f);
145 nodesApp.setPointAttributes(pa);
146
147 ColoringAttributes ca = new ColoringAttributes();
148 ca.setColor(VisData.nodeColor);
149 nodesApp.setColoringAttributes(ca);
150
151 return new Shape3D(nodes, nodesApp);
152 }
153
154 }
Line 138 creates a geometry object as a point array nodes. Point attributes con-
tain antialiasing for drawing points (line 143) and point size in pixels (line 146).
Line 148 sets the line color to that specified in class VisData. Object Shape3D
for the nodes of the finite element model is returned in line 151.

Problems

28.1. Analyze the scene graph shown in Figure 28.1. Currently, lights are attached
to branch group BG. What changes occur in visualization of the finite element model
if lights are attached to the upper transform group TG through an additional branch
group?
28.2. The scene graph of Figure 28.1 contains shape objects for element edges and
nodes. Is it possible to refer to the same appearance for both edges and nodes? Are
references to the same color attributes possible for edges and nodes (through their
appearances)?
28.3. An antialiasing technique is used for smoothing lines and points in meth-
ods edgesShape and nodesShape. Explain how antialiasing is performed on
a computer screen consisting of pixels.

You might also like