Example a5: Multiple element groups, MAYA and translucency: the torso model

Uses semi-transparent surfaces to view the heart and lungs through the muscle and fat layers and outer surface of the torso.

Screenshot of example a/a5

If you are using the firefox web browser and have installed the Zinc extension you can run this example using Zinc (unsigned) - requires some configuration of Firefox security settings.

For more information about running zinc see The Zinc web page.


The comfile run by this example is as follows:

#Example_a5: Multiple element groups and translucency: the torso model
#
# The torso model contains 6 separate element groups, each a boundary element
# mesh separating a region of the torso. From the inside to out they are the
# heart, left and right lungs, muscle, fat and the torso skin. This example
# demonstrates the use of multiple graphical element groups and uses translucent
# materials to view the inside and out of the torso simultaneously. It also
# shows how to get around problems with semi-transparent materials by drawing
# the groups in a set order from inside to out.
#
# Be sure to run the commands in this example in the order they are presented.
# It is recommended that you read the comments then execute the commands that
# follow them either individually or in groups if they are on consecutive lines.
#
#----------
#
#Create some materials to be given to surfaces of the various torso parts.
gfx create material heart diffuse 1. 0. 0.               #Red heart
gfx create material lungs diffuse 0.9 0.3 0.3            #Slightly pink lungs
gfx create material fat diffuse 0.9 0.7 0.0 alpha 0.4    #Translucent yellow fat
gfx create material muscle diffuse 1.0 0.1 0.0 alpha 0.5 #Translucent red muscle
gfx create material torso diffuse 0.7 0.7 0.7 alpha 0.3  #Translucent grey torso
gfx create material axes ambient 1 1 0 diffuse 1 1 0     #Yellow axes
#
# Read in the nodes. Note that we only read in one node group containing all the
# nodes used in this example; the graphical element groups will each make a node
# group containing just the nodes in that element group.
gfx read node example body.exnode
#
# (In older versions of this example the element groups were read in alphabetical order,
# and in older versions of cmgui it was necessary to reorder them to fix transparency. 
# In new new versions of cmgui groups no longer have separate graphics, so the
# order graphics are added in the region is all that matters.)
gfx read elem example body_heart.exelem
gfx read elem example body_llung.exelem
gfx read elem example body_rlung.exelem
gfx read elem example body_muscle.exelem
gfx read elem example body_fat.exelem
gfx read elem example body_torso.exelem
#
# draw axes
gfx modify g_element "/" general clear;
gfx modify g_element "/" point as 1 glyph axes_xyz general size "100*100*100" select_on material axes selected_material default;
#
# In latest versions of cmgui nodes are not automatically added to groups.
# The following commands manually add them:
gfx modify egroup heart add group heart manage_subobjects;
gfx modify egroup llung add group llung manage_subobjects;
gfx modify egroup rlung add group rlung manage_subobjects;
gfx modify egroup muscle add group muscle manage_subobjects;
gfx modify egroup fat add group fat manage_subobjects;
gfx modify egroup torso add group torso manage_subobjects;
#
# Modify the graphical finite elements to show lines plus surfaces in appropriate materials.
gfx modify g_element heart lines coordinate coordinates material default;
gfx modify g_element heart surfaces coordinate coordinates material heart;
gfx modify g_element llung lines coordinate coordinates material default;
gfx modify g_element llung surfaces coordinate coordinates material lungs;
gfx modify g_element rlung lines coordinate coordinates material default;
gfx modify g_element rlung surfaces coordinate coordinates material lungs;
gfx modify g_element muscle lines coordinate coordinates material default;
gfx modify g_element muscle surfaces coordinate coordinates material muscle;
gfx modify g_element fat lines coordinate coordinates material default;
gfx modify g_element fat surfaces coordinate coordinates material fat;
gfx modify g_element torso lines coordinate coordinates material default;
gfx modify g_element torso surfaces coordinate coordinates material torso;
#
# Create a 3-D graphics window:
gfx create window 1
gfx modify window 1 view perspective
#
# The easiest way to get the transparency behaviour we expect is to turn on
# 'slow_transparency'. This requires drawing the image twice and thus slows
# down the display somewhat. The following command turns it on:
gfx modify window 1 set slow_transparency
#
# If display speed is important and you don't mind the odd visual artefact, the
# default 'fast_transparency' option should be used:
gfx modify window 1 set fast_transparency
#
# The following reordering of graphics used to be necessary because each
# group had its own graphics (groups appeared as pseudo regions).
# They would still be necessary if we updated this example to put each
# layer in a separate region.
if (0) {
# In this mode, the surfaces drawn first obscure any surfaces under them, so you
# have to draw your objects from back to front/inside to outside to get the
# expected view.
# By default, graphics are drawn in the order the regions appear in their
# parent. Hence, it is necessary to order the regions from inside to out:
#
gfx set order region heart before torso;
gfx set order region llung before torso;
gfx set order region rlung before torso;
gfx set order region muscle before torso;
gfx set order region fat before torso;
}
#
# We now have the view we want. Next open the scene editor to list the
# graphics for the model.
gfx edit scene
#
# The scene editor lists all the graphics for the groups we have read in,
# and we can select modify/remove and add graphics. Since we are looking at 2-D
# boundary element meshes, there are fewer ways to view them than with 3-D
# meshes. However, this example is good for demonstrating visibility of layers
# and controlling discretization/tessellation.
#
# Hide the 'fat' layer by unchecking the visibility toggle left of its graphics.
# Fo the same with group 'muscle'. Visibility changes always take effect immediately.
#
# Now select any surface or line graphic and open the tessellation editor using
# the Edit... button next to the tessellation chooser. Change the refinement
# factors to 1 (the minimum). Enter then click "apply" to see the changes in
# all the graphics using them. Increase the number to 12 to see higher quality
# graphics. If you choose a higher number there is an increasing delay before
# the graphics update, and rendering slows. Be careful not to enter a very
# large number as it applies in all 3 directions in 3-D elements! 
#
# MAYA is a powerful rendering program produced by ALIAS/Wavefront, a division of
# Silicon Graphics.  It has numerous rendering features unavailable in CMGUI such
# as raytracing and much greater control over lighting and material properties.
# All the MAYA manuals are online (choose help when MAYA is running) and I (Shane)
# can provide some help and have a hard copy of the manuals.
# To export to MAYA we will write the volumes and surfaces to OBJ files.
# By default 'gfx export wavefront' exports all the visible objects (which it can)
# from the default scene, each graphics object is listed in its own file. Other 
# parameters allow you to export just a specific graphics_object by name, change
# the scene or override the default filename.
gfx export wavefront file export_test
#
# Many errors report the inability of the export wavefront routine to write the
# line graphics objects, however in the directory you started a whole series of
# .obj files are created.  These ascii files describe the surfaces of the torso.
# To load them into MAYA, start maya and then choose File->Import.  You can then
# change to the directory where the *.obj files were written and load them in
# one by one.  To change your viewpoint in a MAYA window you drag the mouse while
# holding down the ALT key.  To change the materials for the different surfaces
# choose Window->Multilister, you should see spheres representing each surface
# material.  Double click to edit the material, within this dialog double click 
# a colour patch to edit it.  To render your window, make sure Rendering is
# your option on the chooser top left just below the menu bar, then the Render menu
# is available on the top right.  Choose Render->Render_globals.  This dialog
# controls your resolution and whether you raytrace or not (raytracing is off by
# default).  To actually do a render choose Render->Render_into_New_Window.

#Set the command prompt to 'gfx' for entering further commands.
gfx
#
#----------

Files used by this example are:

Name                Modified     Size

example_a5.com 17-Mar-2014 8.1k COPYRIGHT 17-Mar-2014 504 body.exnode 17-Mar-2014 297k body_fat.exelem 17-Mar-2014 150k body_heart.exelem 17-Mar-2014 20k body_llung.exelem 17-Mar-2014 47k body_muscle.exelem 17-Mar-2014 150k body_rlung.exelem 17-Mar-2014 47k body_torso.exelem 17-Mar-2014 150k default.sdf 17-Mar-2014 644

Download the entire example:

Name                  Modified     Size

examples_a_a5.tar.gz 09-Mar-2016 564k

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxFailureSun Mar 6 00:14:30 20164
last breakTue Mar 31 00:28:00 20155
cmgui-wx-debugFailureSun Mar 6 00:13:55 20162
last breakTue Mar 31 00:26:00 20153
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:14:53 20164
last breakTue Mar 31 00:28:00 20155
cmgui-wx-debug-valgrindFailureSun Mar 6 01:20:45 201665
last breakSun Mar 6 01:19:00 201665
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:26 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debugFailureSun Mar 6 00:01:26 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:27 20161
last breakSun Mar 6 00:01:00 20161
cmgui-wx-debug-valgrindFailureSun Mar 6 00:02:46 20169
last breakSun Mar 6 00:02:00 20169
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:02:04 20167

Testing status by file:


Html last generated: Wed Mar 9 16:01:13 2016

Input last modified: Wed Mar 9 15:49:38 2016


CMISS Help / Examples / a / a5