Example a/create_slices: Creating slices for digitisation from nodal and derivative values of a curve

This example shows how to produce images for a sequence of planes through a 3D volume texture. Each plane image corresponds to the values of the volume texture on the surface of that plane. The slices through the volume texture can be used as input data for the digitisor.

The exnode and exelem plane files used to specify the position of the slice are created using a perl script CreateSlices.pl This script generates a sequence of node and element files corresponding to orthogonal planes centered on the nodes of a curve file given as an argument to the CreatesSlices script as shown below.

perl CreateSlices.pl curve.exnode

The load_slices.com file loads up the generated slices with the associated curve nodes to check whether generation has produced the desired plane positions.

Created by Peter Bier, October 2002.

Generated planes

Screenshot of example a/create_slices

The comfile run by this example is as follows:

# Project volume texture onto a set of planes and write out each projected
# image to a file.  

# Author: Peter Bier

# set number of planes to read in

# directory containing scanned image files, in this case dicom format
# directory containing exnode and exelem files for the block to contain the
# texture, includes texture files specifing texture coordinates
# directory containing exnode and exelem files for each plane
# directory images will be written to

# read in a block to view the texture in
gfx read nodes $block_dir/tex_block.exnode
gfx read elements $block_dir/tex_block.exelem

# define the texture coordinates which vary from 0 to 1 along the axes
gfx read nodes $block_dir/tex_coords.exnode
gfx read elements $block_dir/tex_coords.exelem

# read in mri data and create a volume texture
gfx create texture original_tract image dcm:$image_dir/IMAGE_5_000.ima number_pattern 000 number_series 327 342 1 width 1 height 1 depth 1 distortion 0 0 0 colour 0 0 0 alpha 0 decal linear_filter resize_nearest_filter clamp_wrap;

# use linear interpolation
gfx modify texture original_tract linear

# create a sample field for tract
gfx define field tex sample_texture coordinates xi field original_tract;

# rescale the intensity in the sample_texture field
gfx define field rescaled_tex rescale_intensity_filter field tex output_min 0 output_max 1;
gfx cre spectrum monochrome clear;
gfx modify spectrum monochrome linear range 0 1 extend_above extend_below monochrome colour_range 0 1 ambient diffuse component 1;
#create a texture using the rescaled sample_texture field 
gfx create texture tract linear;
gfx modify texture tract width 1 height 1 depth 1 distortion 0 0 0 colour 0 0 0 alpha 0 decal linear_filter resize_nearest_filter clamp_wrap specify_number_of_bytes 2 evaluate field rescaled_tex element_group texture_block spectrum monochrome texture_coordinate xi fail_material transparent_gray50;

# create a material containing the texture so that we can select along
# with appropriate texture coordinates to visualise the 3D image
gfx create material tract texture tract

# create some useful materials to colour parts of our picture
gfx create material purple ambient 0 0 0 diffuse 0.55 0.35 1 emission 0 0 0 specular 0.5 0.5 0.5 alpha 1 shininess 0.5 
gfx cre mat bluey ambient 0 0.25 0.5 diffuse 0 0.4 1 emission 0 0 0 specular 0.5 0.5 0.5 alpha 1 shininess 0.3

# Define the components of the coordinate field as individual scalar
# fields for defining slice planes
gfx define field x component coordinates.x;
gfx define field y component coordinates.y;
gfx define field z component coordinates.z;

# Draw the 3-D texture on the surface z = 0 

gfx modify g_element "/" general clear;
gfx modify g_element texture_block lines coordinate coordinates material default;
gfx modify g_element texture_block iso_surfaces coordinate coordinates iso_scalar z iso_value 0 use_elements select_on material tract texture_coordinates tex_coords selected_material default_selected render_shaded;

# Create a 3d window
gfx create window 1
gfx mod win 1 view perspective
gfx mod win 1 image view_all

# create an gray_spectrum spectrum
gfx cre spectrum gray_spectrum clear;
gfx modify spectrum gray_spectrum linear range 0 1 extend_above extend_below red colour_range 0 1 ambient diffuse component 1
gfx modify spectrum gray_spectrum linear range 0 1 extend_above extend_below green colour_range 0 1 ambient diffuse component 1
gfx modify spectrum gray_spectrum linear range 0 1 extend_above extend_below blue colour_range 0 1 ambient diffuse component 1

# create a texture coordinate field which can be evaluated using only 
# coordinates.  We need this otherwise we run into problems when creating 
# a sample texture for our plane as the plane only knows about the 
# coordinates field, it has no access to the tex_coords field
gfx define field lookup_tex_coords compose texture_coordinates coordinates group texture_block element_dimension 3 find_element_xi coordinates calculate_values_field tex_coords;

# create a sample texture field which we can use to evaluate the texture
# values for each plane 
gfx define field colour_slice sample_texture field tract coordinates lookup_tex_coords;

# cycle through each plane, project volume texture onto plane and write 
# the image to a file


sub run

while ($plane_number <= $max_plane_number) {

# load in a plane to project onto
   $plane_name = sprintf("plane%03d", $plane_number);
   gfx read node $slice_dir."/".$plane_name.".exnode";
   gfx read elem $slice_dir."/".$plane_name.".exelem";

# create a texture for each plane which will be used each time to evaluate
# the colour_slice field.  This is an unnecessary waste of textures, as we could
# otherwise just reuse the same texture over and over but doing it this way
# means we end up with all the textures showing in the slices in the correct places.
# Alternatively just make a single texture and set the $texture_name to point at it.
   $texture_name = sprintf("plane_texture%03d", $plane_number);
	gfx create texture $texture_name width 1 height 1 clamp_wrap decal;
	gfx modify texture $texture_name linear;
	gfx create material $texture_name texture $texture_name;

# link up the plane just loaded to the material for this plane
   gfx modify g_element $plane_name surfaces material $texture_name texture_coord xi;

# evaluate the texture field colour_slice over the surface of the plane

   #We don't want the source fields depth so we specify_depth 1
   gfx modify texture $texture_name specify_width 256 specify_height 256 specify_depth 1 specify_format i evaluate element_group $plane_name element_dimension 2 field colour_slice spectrum gray_spectrum texture_coordinates xi;

# write out the image as a png file
   gfx write texture $texture_name file $output_dir."/".$plane_name.".png"

   print "Processed plane $plane_number\n";


if ($TESTING) {
# only test one plane

# write output to current directory

	#Check it read in properly and is 16bit = 2 bytes per component
   gfx list texture field tract;

	# list the generated 
   gfx list texture field plane_texture001;

# Type run to begin projecting the volume texture onto the slices
# note this takes several minutes to execute on an O2
# Using hpc2 will reduce execution time to a few seconds

Files used by this example are:

Name               Modified     Size

create_slices.com 17-Mar-2014 6.4k COPYRIGHT 17-Mar-2014 504 CreateSlices.pl 17-Mar-2014 10k block/ 18-Mar-2014 - curve.exnode 17-Mar-2014 1.2k images/ 18-Mar-2014 - load_slices.com 17-Mar-2014 1.1k slices/ 18-Mar-2014 -

Download the entire example:

Name                             Modified     Size

examples_a_create_slices.tar.gz 09-Mar-2016 2.9M

Testing status by version:

StatusTestedReal time (s)
cmgui-wxFailureSun Mar 6 00:18:36 20164
last breakTue Feb 24 03:21:00 20154
cmgui-wx-debugFailureSun Mar 6 00:19:31 20165
last breakTue Feb 24 03:22:00 20155
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:21:19 20167
last breakTue Feb 24 03:24:00 20156
cmgui-wx-debug-valgrindFailureSun Mar 6 01:47:49 2016203
last breakSun Mar 6 01:44:00 2016203
cmgui-wxFailureSun Mar 6 00:01:30 20161
last breakSun Mar 6 00:01:00 20161
cmgui-wx-debugFailureSun Mar 6 00:01:30 20161
last breakSun Mar 6 00:01:00 20161
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:29 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debug-valgrindFailureSun Mar 6 00:02:25 20169
last breakSun Mar 6 00:02:00 20169
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:02:26 20167

Testing status by file:

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

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

CMISS Help / Examples / a / create_slices