Example aj: Integration: texturing the heart, integrating the coronaries

Shows how to define texture coordinate fields and apply those to the surfaces of the heart. Also shows how to use an integration field on a 1D tree mesh. Coronaries

Screenshot of example a/aj


The comfile run by this example is as follows:

#Example_aj: Texturing
#
# Much apparent realism can be added to graphical objects using textures.
# This example shows simple texture operations on surfaces.
# It also uses the integration computed field on a part of the coronary tree.

# Set the default tessellation to use 4 segments in each element direction.
# This command does not exist on older versions of cmgui. It is safe to ignore errors.
gfx define tessellation default minimum_divisions "4" refinement_factors "1";

gfx create spectrum rgb_spectrum clear overwrite_colour
gfx create material heart ambient 0.3 0 0.3 diffuse 1 0 0 specular 0.5 0.5 0.5 shininess 0.5
gfx cre mat trans_purple ambient 0.4 0 0.9 diffuse 0.4 0 0.9 alpha 0.3
gfx cre mat bluey ambient 0 0.2 0.4 diffuse 0 0.5 1 specular 0.5 0.5 0.5 shininess 0.8
gfx cre mat gold ambient 1 0.7 0 diffuse 1 0.7 0 specular 1 1 0.8 shininess 0.8
gfx cre mat axis ambient 0.5 0.5 0.5 diffuse 0.5 0.5 0.5
#
# Read in the heart
gfx read nodes example heart.exnode
gfx read elements example heart.exelem
#
# Open the graphics window and reorient the heart up the right way (since -x is
# "up" in the heart model). Also turn on perspective.
if (! $TESTING)
{
  gfx cre win 1
  gfx mod win 1 image rotate 0 1 0 -90
  gfx mod win 1 view perspective
}
#
#
# Read in the texture and scale it to an appropriate size.  As we are going
# to use xi_texture_coordinates the units correspond to the number of elements
# which the texture stretches across.  The placement of the texture does not
# correspond to an anatomical heart.
gfx cre texture htext1 image example htext1.rgb width 11 height 6
#
# The xi_texture_coordinates are seeded from a top level element.
# The surfaces calculate their xi coordinates in relation to their
# parents.  So when the top level elements are 3D, as in this heart,
# the xi_texture_components which vary correspond to the changing
# xi of these top level elements. (So an xi2 = 0 face varies in xi1
# and xi3, alternatively if you use xi as the texture coordinates every
# face will vary in xi1 and xi2 as these are the xi coordinates for 
# that actual face).
gfx def field /heart/heart_xi_texture xi_texture_coordinates seed 30
#
# Apply the texture to the material
gfx mod material heart texture htext1
#
# Draw the surfaces with the heart material (and texture). Remove the lines.
gfx mod g_e heart surfaces exterior mat heart texture_coord heart_xi_texture as heart_surfaces
gfx mod g_e heart lines delete
#
if (! $TESTING)
{
  gfx edit scene
}
#
# Using a multi component spectrum we can view how the texture coordinates 
# vary over our elements using red for t1, green for t2 and blue for t3.
# We select the texture_coordinate field as our data field and change the
# material so that the texture is not applied.  You can clearly see the
# discontinuity away from the seed element.
gfx modify spectrum rgb_spectrum clear overwrite_colour
gfx modify spectrum rgb_spectrum linear range -1 11 extend_above extend_below red colour_range 0 1 ambient diffuse component 1
gfx modify spectrum rgb_spectrum linear range -1 11 extend_above extend_below green colour_range 0 1 ambient diffuse component 2
gfx modify spectrum rgb_spectrum linear range -1 11 extend_above extend_below blue colour_range 0 1 ambient diffuse component 3
gfx mod g_e heart surfaces exterior data heart_xi_texture material default spectrum rgb_spectrum as heart_surfaces
#
# While any field can be used for texture_coordinates another purposely designed
# is the cubic_texture_coordinate field.  This field projects texture coordinates based
# on a cube centred on the origin.  The coordinates are not continuous along the edges
# of the "cube".  These coordinates range from -1 to 1 on each face.  As you can see
# this cubic mapping isn't very appropriate for the heart.
gfx def field /heart/heart_cubic_texture cubic_texture_coord field coordinates
gfx modify spectrum rgb_spectrum clear overwrite_colour
gfx modify spectrum rgb_spectrum linear range -1 1 extend_above extend_below red colour_range 0 1 ambient diffuse component 1
gfx modify spectrum rgb_spectrum linear range -1 1 extend_above extend_below green colour_range 0 1 ambient diffuse component 2
gfx modify spectrum rgb_spectrum linear range 0 4 extend_above extend_below blue colour_range 0 1 ambient diffuse component 3
gfx mod g_e heart surfaces exterior data heart_cubic_texture material default spectrum rgb_spectrum as heart_surfaces
#
# Show the texture again with xi_texture_coordinates.
gfx mod g_e heart surfaces exterior data none material heart texture_coord heart_xi_texture as heart_surfaces
if ($TESTING)
{
  gfx define graphics_filter heart_only_filter match_region_path heart
  gfx define scene heart filter heart_only_filter
  gfx export vrml file heart.wrl scene heart
}
#
# Xi_texture coordinates integrate xi along elements, in 1D this can be extended
# to integrate other quantities such as length or velocity.
# (In 2D anything other than xi is path dependent and so is ambiguously defined).
# To demonstrate this we will add the top part of the coronary mesh to this example
gfx set vis heart off
gfx read node $example/coro0000.exnode
gfx read element $example/coro.exelem
gfx create material coronaries ambient 1 0.3 0 diffuse 1 0.12 0 emission 0 0 0 specular 0.5 0.5 0.5 alpha 1 shininess 0.8; #orange
# Define an xi_coordinates field in 1D equivalent.
# Note that an xi_texture_coordinates field is just a shorthand for an integration
# of a constant 1.0 with respect to xi coordinates.
gfx def field /coro/one constant number_of_values 1 values 1.0
gfx def field /coro/coronary_xi_texture integration seed_element 516 integrand one coordinate xi
gfx mod g_e coro lines material coronaries spectrum default data coronary_xi_texture as coro_lines
gfx modify spectrum default autorange
#
# Now integrate the length of the coronaries from the entry point. 
gfx def field /coro/coronary_length integration seed_element 516 integrand one coordinate rc-coords magnitude_coordinates;
gfx mod g_e coro lines material coronaries spectrum default data coronary_length as coro_lines
gfx modify spectrum default autorange
#
# Finally integrate the reciprocal of the velocity and get a value representing the time
# taken for fluid to travel to that part of the coronaries.
gfx define field /coro/velocity composite general.2
gfx define field /coro/reciprocal_velocity divide_components fields one general.2
gfx def field /coro/flow_time integration seed_element 516 integrand reciprocal_velocity coordinate rc-coords magnitude_coordinates;
gfx mod g_e coro lines material coronaries spectrum default data flow_time as coro_lines
gfx modify spectrum default autorange
if ($TESTING)
{
  gfx define graphics_filter coro_only_filter match_region_path coro
  gfx define scene coro filter coro_only_filter
  gfx export vrml file coronaries.wrl scene coro
}

Files used by this example are:

Name             Modified     Size

example_aj.com 17-Mar-2014 6.7k COPYRIGHT 17-Mar-2014 504 coro.exelem 17-Mar-2014 114k coro0000.exnode 17-Mar-2014 2.0M heart.exelem 17-Mar-2014 376k heart.exnode 17-Mar-2014 47k htext1.rgb 17-Mar-2014 384k

Download the entire example:

Name                  Modified     Size

examples_a_aj.tar.gz 09-Mar-2016 2.4M

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxFailureSun Mar 6 00:05:21 20161
last breakThu Sep 11 00:01:00 20141
cmgui-wx-debugFailureSun Mar 6 00:05:22 20161
last breakThu Sep 11 00:01:00 20140
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:09:40 20161
last breakThu Sep 11 00:04:00 20142
cmgui-wx-debug-valgrindFailureSun Mar 6 00:55:04 201635
last breakTue Feb 24 00:12:00 201533
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:28 20160
last breakThu Sep 11 00:02:00 20141
cmgui-wx-debugFailureSun Mar 6 00:01:28 20161
last breakThu Sep 11 00:02:00 20140
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:29 20161
last breakThu Sep 11 00:02:00 20141
cmgui-wx-debug-valgrindFailureSun Mar 6 00:05:12 201629
last breakSun Mar 6 00:04:00 201629
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:06:28 201630

Testing status by file:


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

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


CMISS Help / Examples / a / aj