Example a_backup/as: Digitising a pig torso: building a mesh over a CT image

Reads a CT-slice of a pig torso into a texture and displays it in the background of a graphics window. Sets up a 3-D projection onto the area of the texture for digitised points to be displayed on. Creates a group and coordinate field for newly digitised nodes and elements and sets the node_tool and element_creator up to create nodes and elements with the mouse in the graphics window. This allows you to build up a finite element model from real anatomy. Two image show the inital window presented when running this example and a possible state after creating 4 elements by clicking on the image.

Screenshot of example a_backup/as


The comfile run by this example is as follows:

#Example as: Digitising a pig torso: building a mesh over an CT image
#
# Reads a CT-slice of a pig torso into a texture and displays it in the
# background of a graphics window. Sets up a 3-D projection onto the area of
# the texture for digitised points to be displayed on. Creates a group and
# coordinate field for newly digitised nodes and elements and sets the
# node_tool and element_creator up to create nodes and elements with the mouse
# in the graphics window. This allows you to build up a finite element model
# from real anatomy.
#
# ----------
#
# Create some materials to colour the graphics.
#
gfx create material red ambient 1 0 0 diffuse 1 0 0
gfx create material green ambient 0 1 0 diffuse 0 1 0
gfx create material bluey ambient 0 0.25 0.5 diffuse 0 0.4 1 specular 0.5 0.5 0.5 shininess 0.3
gfx create material copper ambient 1 0.2 0 diffuse 0.6 0.3 0 specular 0.7 0.7 0.5 shininess 0.3
gfx create material gold ambient 1 0.4 0 diffuse 1 0.7 0 specular 0.5 0.5 0.5 shininess 0.8
gfx create material silver ambient 0.4 0.4 0.4 diffuse 0.7 0.7 0.7 emission 0 0 0 specular 0.7 0.7 0.7 alpha 1 shininess 0.6
#
# Draw axes with appropriate size and colour
gfx modify g_element "/" point glyph axes_xyz general size "10*10*10" select_on material bluey selected_material default;
#
# Create the 3-D graphics window.
#
gfx create window 1
#
# Read the slice into a texture, recording its physical size.
# For all the following calculations, this texture is understood to span from
# (-121,-233,53.9) at its top to (130,18,53.9) at its bottom. Note that it is
# drawn upside-down so that we are looking at the pig from the front, correct
# way up.
#
gfx create texture slice25 image example slice025.rgb height 251 width 251
#
# Set the projection in the graphics window. This has several parts:
# 1. the interest point is at the centre of the texture, (4.5 -107.5 53.9)
# 2. the viewer eye position is (4.5 -107.5 553.9), 500 units away from the
#    interest point in the z-direction.
# 3. The "up-vector" is in the y direction.
# 4. The near and far clipping planes are 200 and 800 units away from the eye,
#    and hence are symmetrical about the texture plane. This is important as
#    currently, new nodes are placed half-way between them.
# 5. A parallel projection is used.
# 6. The diagonal view_angle is used for a parallel projection as it is for
#    perspective mode - it is the angle from the eye_point to the diagonal span
#    of the texture at the interest_point distance 500 units away.
# 7. The users viewport_coordinates are defined such that the top-left of the
#    texture (when upside-down) is the top-left of the window, and the scale
#    factors of 2.04 pixels/unit, make its physical size of 251 expand to its
#    size in texels of 512 in each direction, with 1 texel per pixel.
# 8. The window is put in absolute_viewport mode, in which the projection is
#    drawn on the ndc_placement area in user viewport_coordinates.
# 9. The ndc_placement projects the viewing volume described by 1. to 6. onto
#    the user viewport_coordinates where the texture will be placed.
#
gfx modify window 1 view eye_point 4.5 -107.5 553.9 interest_point 4.5 -107.5 53.9 up_vector 0 1 0 near_clipping_plane 200 far_clipping_plane 800 parallel view_angle 39.086428 viewport_coordinates -121 18 2.04 2.04 absolute_viewport ndc_placement -121 18 251 251
#
# Draw the slice texture on the user viewport_coordinates of the window. Note
# that the top and height are flipped to draw the texture upside-down.
#
gfx modify window 1 background texture slice25 tex_placement -121 -233 251 -251
#
# In absolute viewport mode the transform function works in a special way to
# preserve the projection described above. Essentially, the projected space and
# the background texture zoom together.
#
#
# Now move on to setting up the mesh creation tools.
#
# Create a group to put the mesh into.
#
gfx cre egroup pig
#
# Establish views of the nodes, element lines and element numbers to make the
# mesh visible as it is being created.
# Note we have to pre-define the cmiss_number field so we can label nodes with
# it as soon as they are created:
gfx define field cmiss_number cmiss_number
#
gfx modify g_element pig lines material bluey
gfx modify g_element pig node_points glyph cross size 2 material gold label cmiss_number select_on
gfx modify g_element pig element_points material silver use_elements label cmiss_number
#
# Create a coordinate field for the new nodes and elements.
#
gfx define field coordinates finite_element number_of_components 3 real coordinate component_names x y z
#
# Enable editing and creating of nodes by the node tool - with the
# coordinate field and pig group. You can also double click on the node_tool
# icon in the graphics window to get these options.
#
gfx node_tool group pig coordinate_field coordinates edit create
#
# Set the node_tool as the current tool in the graphics window
#
gfx modify window 1 set node_tool
#
# Enable creation of 2-D elements in response to node selection.
#
gfx create element_creator
gfx element_creator group pig coordinate_field coordinates create dimension 2
#
# Now click in the 3-D window to create nodes on the image, nodes that will
# build up elements. Since we are making 2-D elements, click on the bottom
# left node first, then the bottom right, then the top left, then the top
# right. Local nodes in all elements change fastest over xi1, then xi2 etc.
# Once you have made a first element you can select existing nodes or make
# new nodes when building up subsequent elements. In this way, slowly build
# up a mesh representing some of the features of the CT images.
#
# Use the transform tool to translate and zoom in on the view with the middle
# and right buttons, respectively.
# Note you can hold down the Ctrl key to temporarily switch to transform mode
# when using any other tool in the graphics window.
#
# You will notice that as you add nodes to the element, they are listed in the
# element creator window. If you click on the wrong node at any time, you can
# click on the "Abort element creation" button to clear it.
#
# If you accidentally make a node in the wrong place you are able to move it
# to the correct place before releasing the mouse button if the "edit" function
# of the node tool is on - remember to double click on the icon to see its
# settings. The edit function also allows you to move existing nodes in the
# plane of the window.
#
# All this time you will note that the element creator is building elements out
# of any nodes you select. By turning off the "create elements" button, you
# can switch this off, making a tool for just creating points. However, with
# it on you can not only select nodes with the node tool in the graphics window
# you can also select individual nodes with the "gfx select node #" command,
# or by typing in a node number in the node viewer.
#
# Eventually you will place nodes and elements which you wish to delete. With
# elements, select the point in the centre with the "Element" tool icon in the
# graphics window. You can group select by clicking away from elements and
# and dragging with the mouse over the elements you wish to delete. a rubber
# band marks these out, and the selected elements will be highlighted. Now
# double click on the Element tool icon and click "Destroy Selected" in its
# dialog. Note that cmgui treats faces and lines of elements as elements as
# well as their top-level/parent element, but only the latter can be destroyed,
# and if it is, the faces and lines owned just by it are destroyed too. The
# "gfx destroy elements" command mirrors this functionality.
#
# Similarly, you can destroy nodes with the Node tool. However, make
# sure that you Abort any current element creation and stop creation of
# further elements or nodes before you do this. You are not able to destroy
# any nodes in use by elements, and this includes the element being constructed
# by the element creator. The "gfx destroy nodes" commands works similarly.
#
# Familiarise yourself with the controls of the node tool, element tool and
# element creator.
#
# Further notes:
#
# If you are just interested in digitising data points on the image, use the
# Data tool just as you have been using the Node tool.
#
# When using non-square textures make sure the NDC placement is onto a square
# part of the texture as it describes projection of a square frustum of space.
#
# The techniques shown here are readily extendable to multiple parallel planes
# of CT scans, but as we are currently limited to placing nodes half-way
# between the near and far clipping planes, care is required when specifying
# the projection as the view is changed from one plane to the next.
# In future we will introduce the concept of manifolds, a description of space
# that node placement is "locked-on" to, eg. planes, spheres and user-specified
# shapes.
#

Files used by this example are:

Name            Modified     Size

example_as.com 20-Apr-2012 8.7k COPYRIGHT 19-Apr-2012 504 slice025.rgb 20-Apr-2012 87k

Download the entire example:

Name                         Modified     Size

examples_a_backup_as.tar.gz 12-Aug-2014 784k

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxSuccessSun Mar 6 00:11:43 20163
cmgui-wx-debugSuccessSun Mar 6 00:11:25 20162
cmgui-wx-debug-memorycheckSuccessSun Mar 6 00:10:06 20163
cmgui-wx-debug-valgrindFailureSun Mar 6 01:02:21 201647
last breakSun Mar 6 01:01:00 201647
last successTue Feb 10 00:59:00 201547
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:36 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:06:00 20150
cmgui-wx-debugFailureSun Mar 6 00:01:36 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:05:00 20150
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:36 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:05:00 20151
cmgui-wx-debug-valgrindFailureSun Mar 6 00:02:34 20169
last breakSun Mar 6 00:02:00 20169
last successWed Jun 3 00:30:00 201533
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:02:14 20167

Testing status by file:


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

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


CMISS Help / Examples / a_backup / as