Example a_backup/region_io: Read and write regions and groups in Cmgui EX file format

This example reads a multi-region model consisting of a 2-D plate with a cube and tetrahedron on it, plus a "starburst" at the tip of the tetrahedron. It demonstrates use of the "Region" keyword and comments in EX files, both requiring Cmgui version 2.6 or greater. See: http://www.cmiss.org/cmgui/wiki/TheCmguiEXFormatGuideExnodeAndExelemFiles. Each region is read from a separate file. When run in testing mode the model is then exported in Cmgui EX format in several configurations including whole hierarchical model, model with specified fields, group without fields and others, each output file is re-read to confirm it is valid, and further outputs of the whole model are made to confirm it is unchanged.

Screenshot of example a_backup/region_io


The comfile run by this example is as follows:

# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is CMISS Region I/O example.
#
# The Initial Developer of the Original Code is
# Auckland Uniservices Ltd, Auckland, New Zealand.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
{

# This example creates a 2-D plate with a cube and tetrahedron on it,
# plus a "starburst" at the tip of the tetrahedron.
# It demonstrates how regions, sub-regions and groups can be read and
# written in Cmgui EX file format.
# Note: Requires cmgui version 2.6 or later

# read cube model directly into the root region
gfx read elements $example/cube.exregion;
# Currently need to manually draw root region

gfx read nodes $example/plate.exnode;
gfx read elements $example/plate.exelem;
# the above files contain a sub-group 'elevated'

# read a tetrahedron sub-region into root
gfx read elements $example/tetrahedron.exregion;

# read starburst file into the tetrahedron region
# this creates a sub-region of tetrahedron
gfx read elements region tetrahedron $example/starburst.exregion;

# Make the model pretty
gfx modify g_element "/" general clear circle_discretization 6 default_coordinate coordinates element_discretization "4*4*4" native_discretization none;
gfx modify g_element "/" point glyph axes_xyz general size "5*5*5" select_on material green selected_material default;
gfx modify g_element "/" lines select_on material default selected_material default_selected;
gfx modify g_element "/" surfaces select_on material red selected_material default_selected render_shaded;
gfx modify g_element plate general clear circle_discretization 6 default_coordinate coordinates element_discretization "4*4*4" native_discretization none;
gfx modify g_element plate lines select_on material default selected_material default_selected;
gfx modify g_element plate surfaces select_on material default data temperature spectrum default selected_material default_selected render_shaded;
gfx modify g_element plate/elevated general clear circle_discretization 6 default_coordinate coordinates element_discretization "4*4*4" native_discretization none;
gfx modify g_element plate/elevated cylinders constant_radius 0.1 select_on material default selected_material default_selected render_shaded;
gfx modify g_element plate/elevated node_points glyph sphere general size "0.4*0.4*0.4" centre 0,0,0 font default select_on material default selected_material default_selected;
gfx modify g_element tetrahedron general clear circle_discretization 6 default_coordinate coordinates element_discretization "4*4*4" native_discretization none;
gfx modify g_element tetrahedron lines select_on material default selected_material default_selected;
gfx modify g_element tetrahedron surfaces select_on material default data temperature spectrum default selected_material default_selected render_shaded;
gfx modify g_element tetrahedron/starburst general clear circle_discretization 6 default_coordinate coordinates element_discretization "4*4*4" native_discretization none;
gfx modify g_element tetrahedron/starburst lines select_on material default selected_material default_selected;
gfx modify spectrum default clear overwrite_colour;
gfx modify spectrum default linear reverse range 0 100 extend_above extend_below rainbow colour_range 0 1 component 1;

if ($TESTING) {
	# test writing of regions:
	# write everything including nodes and elements to single file:
	gfx write elements nodes output_model.exregion;
	# write only coordinate fields to single file; should warn about "bob" field not existing:
	gfx write elements nodes fields coordinates & bob output_model_coordinates.exregion;
	# write just the node and element identifiers for the "elevated" sub-group:
	gfx write nodes group plate/elevated fields none output_elevated_group.exnode;
	gfx write elements group plate/elevated fields none output_elevated_group.exelem;
	# write just the plate and its sub-group "elevated" relative to root region:
	gfx write elements nodes group plate recurse_subgroups output_plate.exregion;
	# write just the tetrahedron with itself as root region:
	gfx write elements nodes root tetrahedron non_recursive output_tetrahedron.exregion;
	# write the starburst region with tetrahedron as root:
	gfx write elements nodes root tetrahedron group starburst output_starburst.exregion;

	# check re-read the output files
	gfx read elements output_model.exregion;
	gfx read elements output_model_coordinates.exregion;
	gfx read nodes output_elevated_group.exnode;
	gfx read elements output_elevated_group.exelem;
	gfx read elements output_plate.exregion;
	gfx read elements region tetrahedron output_tetrahedron.exregion;
	gfx read elements region tetrahedron output_starburst.exregion;

	# re-check: write everything to separate node and element files to re-check:
	gfx write nodes output_model.exnode recursive;
	gfx write elements output_model.exelem recursive;
} else {
  gfx create window 1;
}

if ($TESTING) {
	# check it is an error to specify write filename more than once:
	# (test in a separate block since execution of the block ends on error)
	gfx write elements junk.exelem trash.exelem;
}

}

Files used by this example are:

Name                  Modified     Size

region_io.com 20-Apr-2012 6.4k COPYRIGHT 20-Apr-2012 504 cube.exregion 20-Apr-2012 3.7k plate.exelem 20-Apr-2012 15k plate.exnode 20-Apr-2012 7.6k starburst.exregion 20-Apr-2012 2.9k tetrahedron.exregion 20-Apr-2012 2.8k

Download the entire example:

Name                                Modified     Size

examples_a_backup_region_io.tar.gz 12-Aug-2014 147k

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxSuccessSun Mar 6 00:06:36 20161
cmgui-wx-debugSuccessSun Mar 6 00:06:36 20161
cmgui-wx-debug-memorycheckSuccessSun Mar 6 00:06:38 20161
cmgui-wx-debug-valgrindSuccessSun Mar 6 00:31:57 201618
x86_64-linux
cmgui-wxSuccessThu Jan 7 00:01:30 20160
cmgui-wx-debugSuccessThu Jan 7 00:01:30 20160
cmgui-wx-debug-memorycheckSuccessThu Jan 7 00:01:30 20160
cmgui-wx-debug-valgrindFailureSun Mar 6 00:04:02 201616
last breakSun Mar 6 00:03:00 201616
last successWed Jun 3 00:16:00 201515
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:04:38 201614

Testing status by file:


Html last generated: Sun Mar 6 05:51:00 2016

Input last modified: Thu Oct 11 23:53:01 2012


CMISS Help / Examples / a_backup / region_io