Example a_backup/indexed_volume: Interactive control of segmented parts of a volume render.

segmented parts of a volume render. The volume can be displayed with the original texture colours or arbitrary fake colours. The segmentation is encoded into the alpha channel of the volume texture. This is done using the pack_image.com script in this directory, using a

Screenshot of example a_backup/indexed_volume

If you are using the firefox web browser and have installed the Zinc extension you can view this example online by using one of the links below:

For more information about running either version see The Zinc web page.

The comfile run by this example is as follows:

# Author: Rita Yassi (taken from example a/volume_renderer
#       : Shane Blackett (added colour_lookup_spectrum to interactively toggle segmented components)
# Created: 12/10/06
# Aim: to stack all the segmented images from labview in 3D

# the dimentions are the REAL dimensions not the pixel dimensions, so i am going to create a box or a cube with real dimensions
# my images are 3500 width x3000 height pixels, since we took the images at 8.22 microns AND we downsampled the images by half 
# in labview, the real size is therefore 
# (3500x8.22e-6x2 = 57.54 mm , 3000x8.22e-6x2 = 49.32 mm)
# depth: 650 images at 50 microns steps (50x650) = 32.5 mm
gfx create texture GOJ width 57.54 height 49.32 depth 32.5 clamp_wrap nearest_filter image $example/gojmontage_joined00000.png number_pattern "00000" number_series 00200 00220 5;

 # Create a material containing the texture that we may select along
 # with appropriate texture coordinates, to visualise the 3-D image
 # on our graphics.
 gfx create material GOJ texture GOJ;

 # Read in a 256x400x128 mm single-element block to view the texture in.
 # These dimensions match the physical size and location of the texture.
 # Later we will use the "coordinates" field as texture coordinates.
 gfx read nodes $example/texture_block.exnode
 gfx read elements $example/texture_block.exelem

 #Clear the lines out and set the lowest discritisation as we are only going to 
 #make planes as geometry.
 gfx modify g_element texture_block general clear circle_discretization 6 default_coordinate coordinates element_discretization "1*1*1" native_discretization none;

#gfx modify light default point position 0 100 -100;

 #Create our volume viewing window
 gfx create window 1;
 gfx modify window 1 view perspective eye_point 126.1 861.711 818.194 interest_point 128 200 64 up_vector 0.700925 -0.535256 0.471386 view_angle 40 near_clipping_plane 10.0333 far_clipping_plane 3585.56 relative_viewport ndc_placement -1 1 2 2 viewport_coordinates 0 0 1 1;

 # Fields for aligning with the window view
gfx define field ndc_projection window_projection window 1 from world to normalised_window_fill;
gfx define field minus_one constant -1
gfx define field negative_ndc projection field coordinates projection_matrix ndc_projection;
gfx define field ndc multiply field negative_ndc minus_one

 gfx define field ndc.3 coordinate_system rectangular_cartesian composite ndc.3;

 gfx mod mat GOJ alpha 0.15;
 gfx modify g_element texture_block lines select_on material default selected_material default_selected;

 gfx mod win 1 image view_all;

  my $i;
  my @iso_values;
  my $num_isosurface_planes = 1024;
  my $far_depth = 0.99;
  my $near_depth = 0.978;

  #gfx modify g_element texture_block iso_surfaces iso_scalar ndc.3 iso_value 0.4 use_elements select_on material GOJ texture_coordinates coordinates selected_material default_selected render_shaded delete;
  for ($i = 0; $i < $num_isosurface_planes; $i++) 
    push (@iso_values, $far_depth + (($i / ($num_isosurface_planes - 1.0)) * ($near_depth - $far_depth)));

  gfx modify g_element texture_block iso_surfaces iso_scalar ndc.3 iso_values @iso_values use_elements select_on material GOJ texture_coordinates coordinates selected_material default_selected render_shaded;

  # To help visualise what is going on you can draw the lines around each of the iso_surface planes
  # observing how they update as you adjust your viewing direction
  #gfx modify g_element texture_block iso_surfaces iso_scalar ndc.3 iso_values @iso_values use_faces select_on material blue texture_coordinates coordinates selected_material default_selected render_shaded;


sub define_object
	 my $name = shift;
	 my $range = shift;
	 my $colour = shift;
	 my $alpha_mask_field = shift;
	 my $fake_colour_field = shift;

	 #Give us a constant value we can turn on and off for each object
	 gfx define field show_${name} constant 1;
	 gfx define field ${name}_inputs composite ${$range}[0] ${$range}[1] @$colour input_colour_alpha show_${name};

	 gfx define field visible_${name} function source_field ${name}_inputs result_field object_visible reference_field function_arguments;
	 gfx define field visible_colour_${name} function source_field ${name}_inputs result_field object_visible_colour reference_field function_arguments;

	 my $new_alpha_mask_field = $alpha_mask_field . $name;
	 my $new_fake_colour_field = $fake_colour_field . $name;

	 gfx define field $new_alpha_mask_field or fields $alpha_mask_field visible_${name};
	 gfx define field $new_fake_colour_field add fields $fake_colour_field visible_colour_${name};

	 #The spectrum does not know that the fields have been updated at the moment
	 #so we modify the material to regenerate.
	 eval "sub toggle_${name} { \$${name}_visible = (\$${name}_visible || !defined \$${name}_visible) ? 0 : 1 ; cmiss(\"gfx define field show_${name} constant \$${name}_visible\"); cmiss(\"gfx modify material GOJ colour_lookup_alpha;\");  } ";

	 return ($new_alpha_mask_field, $new_fake_colour_field);


#Define a dummy eight value field to base our function on
gfx define field function_arguments constant 0 0 0.0 0.0 0.0 0.0 0 0;
#Split these seven values up to give them better names
gfx define field value_low composite function_arguments.1;
gfx define field value_high composite function_arguments.2;
gfx define field object_fake_colour composite function_arguments.3 function_arguments.4 function_arguments.5 function_arguments.6;
gfx define field object_alpha composite function_arguments.7;
gfx define field show_object composite function_arguments.8;
gfx define field lower_alpha less_than fields value_low object_alpha;
gfx define field higher_alpha greater_than fields value_high object_alpha;
gfx define field is_object and fields lower_alpha higher_alpha;
gfx define field object_visible and fields is_object show_object;
gfx define field object_visible_colour multiply fields object_fake_colour object_visible;

#The input field does not matter, it is just the start for the operations
#However by using the sample texture field we can create element points that show the
#output at a select number of locations.
gfx define field input_colour sample_texture field GOJ coordinates coordinates;

gfx define field input_colour_alpha composite input_colour.4;

gfx define field alpha constant 0.0;
gfx define field fake_colour constant 0.0 0.0 0.0 0.0;

$alpha_mask = "alpha";
$fake_colour = "fake_colour";

#Specify the object names, alpha ranges and fake_colours.
($alpha_mask, $fake_colour) = define_object("Crura", [0.796, 0.797], [1.0, 0.0, 0.0, 1.0], $alpha_mask, $fake_colour);

($alpha_mask, $fake_colour) = define_object("Background", [0.24, 0.25], [0.0, 0.6, 0.6, 0.004], $alpha_mask, $fake_colour);

($alpha_mask, $fake_colour) = define_object("CircularMuscleLayer", [0.44, 0.45], [0.6, 0.6, 0.0, 1.0], $alpha_mask, $fake_colour);

($alpha_mask, $fake_colour) = define_object("Nerves", [0.47, 0.48], [0.6, 0.3, 0.9, 1.0], $alpha_mask, $fake_colour);

($alpha_mask, $fake_colour) = define_object("Epithelium", [0.34, 0.35], [0.9, 0.3, 0.3, 1.0], $alpha_mask, $fake_colour);

($alpha_mask, $fake_colour) = define_object("LongitudinalMuscleLayer", [0.59, 0.61], [0.0, 0.9, 0.1, 1.0], $alpha_mask, $fake_colour);

gfx define field filtered_alpha composite $alpha_mask;
gfx create spectrum filtered_alpha_spectrum clear overwrite;
gfx modify spectrum filtered_alpha_spectrum field alpha input input_colour_alpha output filtered_alpha;

gfx define field filtered_fake_colour composite $fake_colour;
gfx create spectrum filtered_fake_colour_spectrum clear overwrite;
gfx modify spectrum filtered_fake_colour_spectrum field input input_colour_alpha output filtered_fake_colour;

sub show_true_colour
	 gfx modify material GOJ colour_lookup_spectrum filtered_alpha_spectrum per_pixel colour_lookup_alpha;

sub show_fake_colour
	 gfx modify material GOJ colour_lookup_spectrum filtered_fake_colour_spectrum per_pixel colour_lookup_alpha;

#Use functions show_fake_colour and show_true_colour to change the displayed colour

#Hide the B as it is much of the surrounding tissue (even though we have made it pretty transparent).
#Use this functions like this toggle_OBJECT_NAME to toggle each object on or off.

#gfx modify g_element texture_block element_points glyph sphere_hires general size "1*1*1" centre 0,0,0 font default label visible_Crura use_elements exact_xi xi 0.3,0.3,0.6 select_on material default selected_material default_selected;

#Leave some lines to click on to toggle things
if (0)


Files used by this example are:

Name                        Modified     Size

indexed_volume.com 20-Apr-2012 8.5k COPYRIGHT 19-Apr-2012 504 gojmontage_image00200.png 20-Apr-2012 41k gojmontage_image00205.png 20-Apr-2012 44k gojmontage_image00210.png 20-Apr-2012 45k gojmontage_image00215.png 20-Apr-2012 45k gojmontage_image00220.png 20-Apr-2012 50k gojmontage_joined00200.png 20-Apr-2012 52k gojmontage_joined00205.png 20-Apr-2012 54k gojmontage_joined00210.png 20-Apr-2012 54k gojmontage_joined00215.png 20-Apr-2012 55k gojmontage_joined00220.png 20-Apr-2012 59k gojmontage_mask00200.png 20-Apr-2012 5.9k gojmontage_mask00205.png 20-Apr-2012 5.3k gojmontage_mask00210.png 20-Apr-2012 5.1k gojmontage_mask00215.png 20-Apr-2012 5.1k gojmontage_mask00220.png 20-Apr-2012 5.1k pack_images.com 20-Apr-2012 1.6k square.exelem 20-Apr-2012 1.5k square.exnode 20-Apr-2012 400 texture_block.exelem 20-Apr-2012 3.5k texture_block.exnode 20-Apr-2012 444

Download the entire example:

Name                                     Modified     Size

examples_a_backup_indexed_volume.tar.gz 12-Aug-2014 1.1M

Testing status by version:

StatusTestedReal time (s)
cmgui-wxSuccessSun Mar 6 00:11:47 20163
cmgui-wx-debugSuccessSun Mar 6 00:11:03 20163
cmgui-wx-debug-memorycheckSuccessSun Mar 6 00:11:48 20162
cmgui-wx-debug-valgrindFailureSun Mar 6 01:01:43 201640
last breakSun Mar 6 01:01:00 201640
last successTue Feb 10 00:54:00 201544
cmgui-wxFailureSun Mar 6 00:01:37 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:05:00 20151
cmgui-wx-debugFailureSun Mar 6 00:01:37 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:05:00 20151
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:37 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:05:00 20151
cmgui-wx-debug-valgrindFailureSun Mar 6 00:03:09 20169
last breakSun Mar 6 00:03:00 20169
last successWed Jun 3 00:31:00 201535
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:02:16 20167

Testing status by file:

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

Input last modified: Fri Apr 20 15:59:49 2012

CMISS Help / Examples / a_backup / indexed_volume