Example a/graph_axes: Draw graph axes

Shows how to use glyphs and normalised_window_coordinates to create graph axes.

Screenshot of example a/graph_axes


The comfile run by this example is as follows:

#Example graph_axes: Display data in a 2D graph style
#

#================ Read in nodal data ==============
#
# This file has the potential at 100ms at many nodes.
#

gfx read nodes $example/potential.0100.exnode.gz time 0;

#================ Plot data ==============

# By creating a coorindate field which sets one axis as the 
# first coordinate and the other axis as the second coordinate
# you can plot any fields you choose.

# Here we will plot the cmiss_number versus the potential.
# The potential needs to be scaled so that it's range is similar
# to the other axis.

gfx define field plotA composite cmiss_number potential;
gfx define field plot scale field plotA scale_factors 1 2e5;

# Set the coordinate field to use this plot field and draw the nodes.

gfx modify g_element potential_points general clear;
gfx modify g_element potential_points node_points as pointset coordinate plot glyph sphere general size "1000*1000*1000" centre 0,0,0 select_on material default data potential spectrum default selected_material default_selected;

gfx modify spectrum default auto;


# You are not restricted to drawing nodes in this way, isosurfaces,
# surfaces and lines can all be draw using this coordinate system.

#================ Create window ==============
#
# Make a window to view the data.  It is set in 2D mode to disable rotation, but panning and zooming
# still work.
#

gfx create window 1 double_buffer;
gfx modify window 1 image scene default infinite_viewer_lighting two_sided_lighting;
gfx modify window 1 image add_light default;
gfx modify window 1 image add_light default_ambient;
gfx modify window 1 layout 2d ortho_axes z y eye_spacing 0.25 width 800 height 400;
gfx modify window 1 set current_pane 1;
gfx modify window 1 background colour 0 0 0 texture none;

# Using a distorting_relative_viewport means that the graph will change aspect ratio when the window is resized
gfx modify window 1 view parallel eye_point 286120 3.0534e+06 795829 interest_point 286120 3.0534e+06 0 up_vector -0 -1 -0 view_angle 40.7385 near_clipping_plane 7958.29 far_clipping_plane 2.84402e+06 distorting_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 fast_transparency blend_normal;

#================ Create axes ==============
#
# Draw a node which is fixed relative to the window and label the axes with the unscaled coordinate fields
# using an window coordinate transformation.  As these are done with respect to a particular window
# that must be made first.
#

gfx read node $example/axes.exnode;

# The coordinate_system normalised_window_coordinates is a special coordinate system which lies in the
# screen window space rather than the 3D model space.
# (Not needed in new versions of cmgui; can use coordinates directly with normalised_window_fill coordinate system.)
#gfx define field ndc_coordinates coordinate_system normalised_window_coordinates composite coordinates;

gfx define field inverse_ndc_projection window_projection window 1 from normalised_window_fill to world;
gfx define field ndc_labelsA projection field coordinates projection_matrix inverse_ndc_projection;
#in old versions of cmgui replace this with:
#gfx define field ndc_labelsA window_projection field coordinates window 1 inverse_ndc_projection;
gfx define field ndc_labels scale field ndc_labelsA scale_factors 1 5e-6 1;
gfx define field ndc_label_x component ndc_labels.1;
gfx define field ndc_label_y component ndc_labels.2;
#Specify a matrix so we can specify the minor direction
gfx define field xaxis constant 1 0 0  0 1 0  0 0 1;
gfx define field yaxis constant 0 1 0  1 0 0  0 0 1;

#Define a field that is scaled by the actual pixels on the screen to control the label density so 
#that as the number of pixels reduce so does the number of labels
#The viewport_projections include the ndc projection so we have to work from the ndc_labelsA field

gfx define field viewport_projection window_projection window 1 from world to window_pixel_bottom_left;
gfx define field pixel_scalingA projection field ndc_labelsA projection_matrix viewport_projection;
#in old versions of cmgui replace this with:
#gfx define field pixel_scalingA window_projection field ndc_labelsA window 1 viewport_projection;
#We want the derivatives of this field to be the density
gfx define field pixel_scalingB gradient field pixel_scalingA coordinate coordinates;
#We need the diagonal components of this
gfx define field pixel_scalingC composite pixel_scalingB.1 pixel_scalingB.5 pixel_scalingB.9;
gfx define field pixel_scaling multiply fields pixel_scalingC [0.75,0.75,0.75];

#Make the cross ticks stay the same number of pixels long
gfx define field xtickscalingA composite 1.0 pixel_scaling.2 1.0;
gfx define field xtickscaling divide fields [1 100.0 1] xtickscalingA;
gfx define field ytickscalingA composite 1.0 pixel_scaling.1 1.0;
gfx define field ytickscaling divide fields [1 100.0 1] ytickscalingA;

gfx modify g_element axes general clear;
gfx modify g_element axes node_points as xaxis coordinate coordinates normalised_window_fill glyph line_ticks general size "0*1*1" centre 0,0,0 label ndc_label_x ldensity pixel_scaling.1 orientation xaxis scale_factors "1.8*0*0" variable_scale xtickscaling select_on material default selected_material default_selected;
gfx modify g_element axes node_points as yaxis coordinate coordinates normalised_window_fill glyph line_ticks general size "0*1*1" centre 0,0,0 label ndc_label_y ldensity pixel_scaling.2 orientation yaxis scale_factors "1.8*0*0" variable_scale ytickscaling select_on material default selected_material default_selected;
#gfx modify g_element axes node_points coordinate coordinates normalised_window_fill glyph point general size "0*1*1" centre 0,0,0 label pixel_scaling orientation yaxis scale_factors "1.8*0*0" select_on material default selected_material default_selected;

gfx modify window 1 layout 2d ortho_axes z -y eye_spacing 0.25 width 800 height 400;

#Try some formatted labels
gfx define field plot_labels format_output field plotA format_string "Test %2g %3.1E";
gfx modify g_element potential_points node_points as pointset coordinate plot glyph point general size "1000*1000*1000" centre 0,0,0 select_on material default data potential spectrum default selected_material default_selected label plot_labels;
#And try that again with no glyph
gfx modify g_element potential_points node_points as pointset coordinate plot glyph none general size "1000*1000*1000" centre 0,0,0 select_on material default data potential spectrum default selected_material default_selected label plot_labels;

#Set it back to the original
gfx modify g_element potential_points node_points as pointset coordinate plot glyph sphere general size "1000*1000*1000" centre 0,0,0 select_on material default data potential spectrum default selected_material default_selected label none;

Files used by this example are:

Name                      Modified     Size

graph_axes.com 09-Mar-2016 6.8k COPYRIGHT 17-Mar-2014 504 axes.exnode 17-Mar-2014 442 potential.0100.exnode.gz 17-Mar-2014 19k

Download the entire example:

Name                          Modified     Size

examples_a_graph_axes.tar.gz 09-Mar-2016 44k

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxFailureSun Mar 6 00:16:13 20163
last breakTue Feb 24 03:16:00 20153
cmgui-wx-debugFailureSun Mar 6 00:16:15 20163
last breakTue Feb 24 03:19:00 20153
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:15:07 20163
last breakTue Feb 24 03:18:00 20153
cmgui-wx-debug-valgrindFailureSun Mar 6 01:29:10 201697
last breakSun Mar 6 01:27:00 201697
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:30 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debugFailureSun Mar 6 00:01:30 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:30 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debug-valgrindFailureSun Mar 6 00:02:41 20169
last breakSun Mar 6 00:02:00 20169
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:02:29 20167

Testing status by file:


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

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


CMISS Help / Examples / a / graph_axes