Example a/graph_overlays: Drawing graphs (from UnEmap signals) in overlay scenes.

Warning! This example is broken and needs updating to work without unemap and remove use of overlay scenes which are no longer supported (use window-relative graphics instead.

This example tries to illustrate the process of drawing some interesting graphs in overlay scenes that sit in front of your animated model, as shown below. The data for the graphs comes from a unemap signal file which is read into unemap (so you need the special version of cmgui that has unemap built in — i.e., cmgui-unemap). Each graph is then drawn in its own scene and all the graph scenes are composited into a single overlay scene for the window. Coloured spheres are used as time markers on the graphs and move to reflect the current time in cmgui. Matching spheres are drawn in the mesh to illustrate the spatial location for given graphs. The text2sig utility is useful for turning any text file of numbers into a unemap signal file for use in this type of application.

A problem with the use of unemap is that it isn't really designed for non-interactive use, so this example is broken into two parts. If you run the example a bunch of stuff will get read in and a unemap analysis window will pop up. Once control is returned back to the cmgui command window you can call the "doIt" function which will complete the rest of the command file to generate the pretty picture. This is required to avoid a crash if you try to read in the unemap signal file before the analysis window is completely realised.

This example and all data used come from the PhD of David Nickerson, Bioengineering Institute, The University of Auckland.

Screenshot of example a/graph_overlays


The comfile run by this example is as follows:

if (!defined $example) {
    $example = ".";
}


if (!defined $output) {
    $output = "$example/results";
}

# The materials to use for the graphs (need to make sure
# you have enough for all the graphs you want).
@materials = ("red","green","blue","magenta","cyan","orange","black","yellow","silver");

# Turn off automatically adding things to the default scene
gfx mod scene default manual;

# define the time interval we're interested in
if (!defined $tStart) {
    $tStart = 0;
}
if (!defined $tEnd) {
    $tEnd = 1000;
}
if (!defined $dT) {
    $dT = 10;
}

# Used to scale the actual window size when printing out
# an image sequence (i.e. set to a bigger number if you want
# high resolution images for a poster).
if (!defined $sizeFactor) {
    $sizeFactor = 1;
}

# Set the size of the window (default is DVD resolution?)
if (!defined $windowWidth) {
    $windowWidth = 720;
}
if (!defined $windowHeight) {
    $windowHeight = 576;
}

# A flag to draw the mechanics graphs
if (!defined $mechanics) {
    $mechanics = 1;
}

# Define the subroutines used to create the plot scenes.
read com "$example/createPlotScene.com" execute;

# This command file reads in the mesh and sets up the
# model (LV) view
read com "$example/view.com" execute;

# Unemap isn't really designed for batch scripting 
# so we need to do this in two steps
unemap open analysis;

# Create some cool materials
gfx create material cyan ambient 0 0 0.5 diffuse 0 1 1 emission 0 0 0 specular 0.2 0.2 0.2 alpha 1 shininess 0.2;
gfx create material magenta ambient 0.5 0 0 diffuse 1 0 1 emission 0 0 0 specular 0.2 0.2 0.2 alpha 1 shininess 0.2;
gfx create material yellow ambient 0.5 0.5 0 diffuse 1 1 0 emission 0 0 0 specular 0.2 0.2 0.2 alpha 1 shininess 0.2;
gfx create material orange ambient 0.5 0.5 0 diffuse 1 0.5 0 emission 0 0 0 specular 0.2 0.2 0.2 alpha 1 shininess 0.2;

# A function to create the main graphics window
sub createWindow {

    my $sceneName = shift;
    my $overlaySceneName = shift;
    my $width = shift;
    my $height = shift;

    # put the scene into a window
    gfx create window $sceneName double_buffer;
    gfx modify window $sceneName image scene $sceneName light_model default;
    gfx modify window $sceneName image add_light default;
    gfx modify window $sceneName layout simple ortho_axes z -y eye_spacing 0.25 width $width height $height;
    gfx modify window $sceneName set current_pane 1;
    gfx modify window $sceneName background colour 1 1 1 texture none;
    gfx modify window $sceneName view parallel eye_point -25.748 -193.272 94.1902 interest_point 7.59247 -5.80426 2.43882 up_vector -0.936404 0.273903 0.219373 view_angle 28.0052 near_clipping_plane 2.11363 far_clipping_plane 755.339 relative_viewport ndc_placement -1 1 2 2 viewport_coordinates 0 0 1 1;
    gfx modify window $sceneName set transform_tool current_pane 1 std_view_angle 40 normal_lines no_antialias fast_transparency blend_normal;
    
    gfx modify window $sceneName overlay scene $overlaySceneName;
    gfx modify window $sceneName set slow_transparency;
}

# Define a function which will create all the graphs and draw
# them once the unemap signal has been read in.
sub doIt {

    my $scene = "mesh";
    
    # Hopefully, by the time this function gets called the
    # unemap analysis window will be up and this won't cause
    # a segfault to crash cmgui
    unemap read signal "$output/all.signal";

    # The free wall apex grid point
    my %point1;
    $point1{gp} = 17162;
    $point1{potentialNode} = 196;
    $point1{lambdaNode} = 214;
    $point1{tensionNode} = 205;
    $point1{element} = 6;
    $point1{elementXi} = "0.413,1,0.88";

    # The free wall base grid point
    my %point2;
    $point2{gp} = 40490;
    $point2{potentialNode} = 197;
    $point2{lambdaNode} = 215;
    $point2{tensionNode} = 206;
    $point2{element} = 14;
    $point2{elementXi} = "0.413,1,0.88";

    # The septal wall base grid point
    my %point3;
    $point3{gp} = 46323;
    $point3{potentialNode} = 198;
    $point3{lambdaNode} = 216;
    $point3{tensionNode} = 207;
    $point3{element} = 16;
    $point3{elementXi} = "0.47,1,0.88";

    # free wall epi
    my %fwEpi;
    $fwEpi{gp} = 113724;
    $fwEpi{potentialNode} = 199;
    $fwEpi{lambdaNode} = 217;
    $fwEpi{tensionNode} = 208;
    $fwEpi{element} = 42;
    $fwEpi{elementXi} = "1,1,0.875";
    # free wall mid
    my %fwMid;
    $fwMid{gp} = 29160;
    $fwMid{potentialNode} = 200;
    $fwMid{lambdaNode} = 218;
    $fwMid{tensionNode} = 209;
    $fwMid{element} = 10;
    $fwMid{elementXi} = "1,1,1";
    # free wall endo
    my %fwEndo;
    $fwEndo{gp} = 26892;
    $fwEndo{potentialNode} = 201;
    $fwEndo{lambdaNode} = 219;
    $fwEndo{tensionNode} = 210;
    $fwEndo{element} = 90;
    $fwEndo{elementXi} = "0.0,0.0,0.125";

    # septal epi
    my %sepEpi;
    $sepEpi{gp} = 118908;
    $sepEpi{potentialNode} = 202;
    $sepEpi{lambdaNode} = 220;
    $sepEpi{tensionNode} = 211;
    $sepEpi{element} = 44;
    $sepEpi{elementXi} = "1,1,0.875";
    # septal mid
    my %sepMid;
    $sepMid{gp} = 34992;
    $sepMid{potentialNode} = 203;
    $sepMid{lambdaNode} = 221;
    $sepMid{tensionNode} = 212;
    $sepMid{element} = 12;
    $sepMid{elementXi} = "1,1,1";
    # septal endo
    my %sepEndo;
    $sepEndo{gp} = 32724;
    $sepEndo{potentialNode} = 204;
    $sepEndo{lambdaNode} = 222;
    $sepEndo{tensionNode} = 213;
    $sepEndo{element} = 12;
    $sepEndo{elementXi} = "1,1,0.125";

    # The points we want to plot
    my @PTP = ();
    push @PTP,\%fwEndo;
    push @PTP,\%fwMid;
    push @PTP,\%fwEpi;
    push @PTP,\%sepEndo;
    push @PTP,\%sepMid;
    push @PTP,\%sepEpi;


    # The potential traces
    my @nodeList = ();
    foreach my $n (@PTP) {
        push @nodeList,$n->{potentialNode};
    }
    #                                name           element   ts  tend yMin yMax xSF  ySF  xOff yOff  nodes....
    my ($element) = &createPlotScene("potential",     1000,    0,$tEnd, -85, 30, 0.5, 0.5, 0.7,  0.5, @nodeList);

    if ($mechanics) {
        # The tension traces
        @nodeList = ();
        foreach my $n (@PTP) {
            push @nodeList,$n->{tensionNode};
        }
        ($element) = &createPlotScene("tension",      $element,    0,$tEnd,   0, 60, 0.5, 0.5, 0.7,-0.25, @nodeList);
        
        # The lambda traces
        @nodeList = ();
        foreach my $n (@PTP) {
            push @nodeList,$n->{lambdaNode};
        }
        ($element) = &createPlotScene("lambda",       $element,    0,$tEnd,0.85,1.2, 0.5, 0.5, 0.7, -0.9, @nodeList);
    }

    # Need this since unemap selects a node when it opens the 
    # signal file.
    gfx unselect all nodes;

    # Draw the grid points that match the plots
    # This is a messy way to do it, but it works
    my $i = 0;
    foreach my $n (@PTP) {
        my $name = sprintf "GP%d",$i;
        gfx create egroup $name add_ranges $n->{element};
        gfx draw group $name scene $scene;
        gfx modify g_element $name general clear circle_discretization 6 default_coordinate coordinates element_discretization "4*4*4" native_discretization none scene mesh;
        gfx modify g_element $name element_points coordinate deformed glyph sphere_hires general size "3*3*3" centre 0,0,0 use_elements exact_xi xi $n->{elementXi} select_on material $materials[$i] selected_material $materials[$i] scene $scene;
        $i++;
    }

    # change materials array to get different colour traces
    @materials = ("red","blue","gold","green","black");
    if (!defined $pMin) {
        $pMin = 0;
    }
    if (!defined $pMax) {
        $pMax = 15.5;
    }
    if (!defined $volMin) {
        $volMin = 25;
    }
    if (!defined $volMax) {
        $volMax = 52;
    }

    if ($mechanics) {
        ($element) = &createPlotScene("pressure",     $element,    0,$tEnd,$pMin,$pMax, 0.5, 0.5,-1.2,  -0.9, 233);
        ($element) = &createPlotScene("volume",       $element,    0,$tEnd,$volMin,$volMax, 0.5, 0.5,-1.2, 0.5, 234);
    }

    gfx create scene plotMaster;
    gfx modify scene plotMaster add_light default;
    gfx draw child_scene potential scene plotMaster;
    if ($mechanics) {
        gfx draw child_scene tension scene plotMaster;
        gfx draw child_scene lambda scene plotMaster;
        gfx draw child_scene pressure scene plotMaster;
        gfx draw child_scene volume scene plotMaster;
    }

    if (!defined $noText) {
        my $labelMaterial = "black";
        gfx create annotation as Vm_label material $labelMaterial position 0.77 0.4 0 text "Potential";
        gfx draw Vm_label scene plotMaster;
        if ($mechanics) {
            gfx create annotation as T_label material $labelMaterial position 0.77 -0.35 0 text "Tension";
            gfx draw T_label scene plotMaster;
            gfx create annotation as L_label material $labelMaterial position 0.77 -0.95 0 text "Length";
            gfx draw L_label scene plotMaster;
            gfx create annotation as P_label material $labelMaterial position -1.19 -0.95 0 text "Pressure";
            gfx draw P_label scene plotMaster;
            gfx create annotation as V_label material $labelMaterial position -1.19 0.4 0 text "Volume";
            gfx draw V_label scene plotMaster;
        }
        
        my $t;
        for ($t=$tStart;$t<=$tEnd;$t+=$dT) {
            my $label = sprintf "%03d",$t;
            gfx create annotation as time_label material tissue position -1.2 0.92 0 text "$label ms" time $t;
        }
        gfx draw time_label scene plotMaster;
    }

    &createWindow($scene,"plotMaster",$windowWidth,$windowHeight);

    &setTime(0);

}

sub makeMovie {
    my $imageDir = shift;
    my $window = shift;
    my $width = shift;
    my $height = shift;

    my $t;
    $width *= $sizeFactor;
    $height *= $sizeFactor;
    for ($t=$tStart;$t<=$tEnd;$t+=$dT) {
        my $image = sprintf "$imageDir/%05d.sgi",$t;
        &setTime($t);
        gfx print window $window file $image antialias 8 width $width height $height;
    }
}

# Just do it! would be easier if we could properly
# script UnEmap

# &doIt;

Files used by this example are:

Name                         Modified     Size

graph_overlays.com 17-Mar-2014 9.9k COPYRIGHT 17-Mar-2014 504 createPlotScene.com 17-Mar-2014 6.8k filter.pl 17-Mar-2014 213 plot_marker_template.exnode 17-Mar-2014 49 plot_template.exelem 17-Mar-2014 1.3k plot_template.exnode 17-Mar-2014 164 results/ 18-Mar-2014 - view.com 17-Mar-2014 7.4k

Download the entire example:

Name                              Modified     Size

examples_a_graph_overlays.tar.gz 09-Mar-2016 14M

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

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


CMISS Help / Examples / a / graph_overlays