Example a_backup/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_backup/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
$max_plane_number=10;

# directory containing scanned image files, in this case dicom format
$image_dir="$example/images";
# directory containing exnode and exelem files for the block to contain the
# texture, includes texture files specifing texture coordinates
$block_dir="$example/block";
# directory containing exnode and exelem files for each plane
$slice_dir="$example/slices";
# directory images will be written to
$output_dir="$example/slices";

# 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

$plane_number=1;

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 depth 0 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 sgi rgb file
   gfx write texture $texture_name file $output_dir."/".$plane_name.".sgi"

   print "Processed plane $plane_number\n";
   $plane_number++;
}

}

if ($TESTING) {
# only test one plane
   $max_plane_number=1;

# write output to current directory
   $output_dir=".";
   run;

	#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 20-Apr-2012 6.4k COPYRIGHT 19-Apr-2012 504 CreateSlices.pl 20-Apr-2012 10k block/ 19-Apr-2012 - curve.exnode 20-Apr-2012 1.2k images/ 19-Apr-2012 - load_slices.com 20-Apr-2012 1.1k slices/ 19-Apr-2012 -

Download the entire example:

Name                                    Modified     Size

examples_a_backup_create_slices.tar.gz 12-Aug-2014 3.0M

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxSuccessSun Mar 6 00:16:55 20164
cmgui-wx-debugSuccessSun Mar 6 00:20:52 20165
cmgui-wx-debug-memorycheckSuccessSun Mar 6 00:21:32 20166
cmgui-wx-debug-valgrindFailureSun Mar 6 01:49:23 2016206
last breakSun Mar 6 01:45:00 2016206
last successTue Feb 10 01:55:00 2015211
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:36 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:05:00 20152
cmgui-wx-debugFailureSun Mar 6 00:01:36 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:06:00 20153
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:36 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:07:00 20153
cmgui-wx-debug-valgrindFailureSun Mar 6 00:03:06 201610
last breakSun Mar 6 00:02:00 201610
last successWed Jun 3 01:06:00 2015154
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:02:34 20167

Testing status by file:


Html last generated: Sun Mar 6 05:50:54 2016

Input last modified: Fri Apr 20 15:56:56 2012


CMISS Help / Examples / a_backup / create_slices