Example a/image_sampling: Image sampling.

Evaluate a volume image at embedded gauss point locations and write the values.

Screenshot of example a/image_sampling


The comfile run by this example is as follows:

#Example image_sampling.com:  Evaluate a volume image at embedded gauss point locations and write the values.

$FileFormat="jpg"

$PATH="$example"
$CTPath="$PATH/ScannedCTSlices/$FileFormat"
$OutputPath="."


#================= Read texture mesh ==================
#
# Read in block geometry used to contain the volume texture read below

gfx read nodes     $PATH/texture_block.exnode;
gfx read elements  $PATH/texture_block.exelem;

gfx read nodes     $PATH/iso_block.exnode;
gfx read elements  $PATH/iso_block.exelem;

gfx define field x component coordinates.x;
gfx define field y component coordinates.y;
gfx define field z component coordinates.z;


#================= Read texture ==================
#
# Read in a scanned volume and create some fields that reference the volume data.
#

gfx create texture mandible width 170 height 170 depth 58 image $CTPath/Mandible0000.$FileFormat number_pattern "0000" number_series 0002 0118 1 compress;

# Align the texture to the first repetition (from 0-width, 0-height, 0-depth) and compensate
# for the fact that the depth is no longer expanded out to a power of two.
gfx define field offset_coordinates offset field coordinates offsets 0 -170 126.90598;

gfx define field tex sample_texture coordinates offset_coordinates field mandible;

# Define a grayscale spectrum useful for displaying the texture values.

gfx create spectrum grayscale clear overwrite_colour;
gfx modify spectrum grayscale linear range 0 1 extend_above extend_below red colour_range 0 1 ambi diffuse component 1;
gfx modify spectrum grayscale linear range 0 1 extend_above extend_below green colour_range 0 1 ambi diffuse component 1;
gfx modify spectrum grayscale linear range 0 1 extend_above extend_below blue colour_range 0 1 ambi diffuse component 1;

#================= Read in geometry ==================
#
# Read in the element geometry represent the jaw and in which the embedded points
# at which we want to evaluate the texture field will be located.

gfx read nodes     $PATH/FinalMandibleGeometry2.exnode;
gfx read elements  $PATH/FinalMandibleGeometry.exelem;


#================= Define graphics =====================

# Create materials
gfx create material bone ambient 0.7 0.7 0.3 diffuse 0.9 0.9 0.8 emission 0 0 0 specular 0.05 0.05 0.05 alpha 1 shininess 0.1;
gfx create material green ambient 0 1 0 diffuse 0 1 0
gfx create material mandible ambient 1 1 1 diffuse 1 1 1 emission 0 0 0 specular 0 0 0 alpha 0.65 shininess 0 texture mandible;

# Clear out the default graphics in the texture_block
gfx modify g_element texture_block general clear;

# Clear out the default graphics in the iso_block and set the resolution we want for the iso_surface display
gfx define tessellation fine16 minimum_divisions "16" refinement_factors "1";
gfx modify g_element iso_block general clear;

# Draw an iso_surface of this field
gfx modify g_element iso_block iso_surfaces coordinate coordinates tessellation fine16 iso_scalar tex iso_value 0.35 use_elements select_on material bone texture_coordinates coordinates selected_material default_selected render_shaded;


#================= Open graphics window =====================
#
# The graphics window is not required to calculate the texture values and the example will
# run much faster as the volume will not need to be loaded and compressed in the graphics card
# and the iso_surface will not be displayed and therefore not calculated.
#

if (! $TESTING)
{
  gfx create window 1 double_buffer;
  gfx modify window 1 image scene default light_model default;
  gfx modify window 1 image add_light default;
  gfx modify window 1 layout simple ortho_axes z -y eye_spacing 0.25 width 664 height 664;
  gfx modify window 1 set current_pane 1;
  gfx modify window 1 background colour 0.5 0.5 0.5 texture none;
  gfx modify window 1 view perspective eye_point 147.392 688.357 150.456 interest_point 77.385 253.245 -107.58 up_vector -0.00310034 -0.509712 0.860339 view_angle 31.6892 near_clipping_plane 5.10692 far_clipping_plane 1825.04 relative_viewport ndc_placement -1 1 2 2 viewport_coordinates 0 0 1 1;
  gfx modify window 1 set transform_tool current_pane 1 std_view_angle 40 normal_lines no_antialias slow_transparency blend_normal;
}

#================= Read embedded gauss point locations =====================
#
# The locations at which we want to sample the image field are gauss points, embedded within the
# mandible mesh, specified as locations at Element:Xi locations within that mesh.
#

gfx read data $PATH/GaussPointsFittedMandible.exdata;

# To view the data points, create an 'embedded' field returning the coordinates field
# from the host mesh evaluated at the element_xi location read in from the data points: 

gfx define field element_xi_coordinate embedded element_xi element_xi field coordinates;

gfx modify g_element GaussPointsMandible general clear;
gfx modify g_element GaussPointsMandible data_points coordinate element_xi_coordinate glyph sphere general size "1*1*1" centre 0,0,0 select_on material default selected_material default_selected;

#================= Display tex_mag on datapoints =====================
#
# To define the texture field on these embedded fields we need to define a field that connects the Element:Xi field with
# the texture sampling field.  The "tex_mag" field is the one we want to sample and the "element_xi" field is the embedded
# position we want to use.  (The "element_xi_coordinate" coordinate field is automatically generated for these datapoints
# but any other embedding fields need to be created manually).

gfx define field element_xi_tex embedded field tex element_xi element_xi;

# This embedded field can now be displayed on the data points
gfx modify g_element GaussPointsMandible data_points coordinate element_xi_coordinate glyph sphere general size "1*1*1" centre 0,0,0 select_on material default selected_material default_selected data element_xi_tex spectrum grayscale;

#================= Evaluate tex_mag at datapoints =====================
#
# To write out the values at the datapoints we need to explicitly evaluate the 
# tex_mag field into storage locations in the data points.

# Define a field that can store the grayscale value we want
gfx define field tex_values finite_element number_of_components 1 real coordinate component_names value;

# Define this field on each of the data points, the initial value will be zero.
gfx modify data group GaussPointsMandible define tex_values;

# Evaluate the element_xi_tex_mag field at each data point into this storage.
gfx evaluate dgroup GaussPointsMandible source element_xi_tex destination tex_values;

# Write out these values.
gfx write data group GaussPointsMandible field tex_values "$OutputPath/tex_mag_values.exdata";

# Additionally more fields could be evaluated and written out, such as the coordinate field or
# maybe the tex with some image processing applied as shown in many of the examples in this directory.


Files used by this example are:

Name                              Modified     Size

image_sampling.com 17-Mar-2014 6.8k COPYRIGHT 17-Mar-2014 504 FinalMandibleGeometry.exelem 17-Mar-2014 576k FinalMandibleGeometry2.exnode 17-Mar-2014 320k GaussPointsFittedMandible.exdata 17-Mar-2014 1.1M ScannedCTSlices/ 18-Mar-2014 - iso_block.exelem 17-Mar-2014 1.6M iso_block.exnode 17-Mar-2014 264k texture_block.exelem 17-Mar-2014 3.6k texture_block.exnode 17-Mar-2014 1.0k

Download the entire example:

Name                              Modified     Size

examples_a_image_sampling.tar.gz 09-Mar-2016 5.5M

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxFailureSun Mar 6 00:15:38 20164
last breakMon Aug 25 13:03:00 20149
cmgui-wx-debugFailureSun Mar 6 00:16:47 20164
last breakMon Aug 25 13:03:00 20149
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:19:36 20165
last breakMon Aug 25 13:06:00 201413
cmgui-wx-debug-valgrindFailureSun Mar 6 01:33:03 2016118
last breakTue Feb 24 00:40:00 2015110
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:48 20162
last breakFri Aug 15 00:27:00 20143
cmgui-wx-debugFailureSun Mar 6 00:01:49 20163
last breakFri Aug 15 00:27:00 20144
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:02:01 20163
last breakFri Aug 15 00:27:00 20144
cmgui-wx-debug-valgrindFailureSun Mar 6 00:09:25 2016120
last breakSun Mar 6 00:07:00 2016120
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:08:57 201691

Testing status by file:


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

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


CMISS Help / Examples / a / image_sampling