Example a_backup/ap: Element Xi Coordinates : Fitting a face to a fox

Shows how to create embedded Element Xi nodes in the front end. Then error vectors showing the distance from the embedded point to element_xi point can be generated. These will interactively update whenever the host mesh is adjusted.

Screenshot of example a_backup/ap

The comfile run by this example is as follows:

#Example_ap: Element Xi Coordinates : Fitting a face to a fox
# This example shows how to convert ipxi to cmgui elementxi, an example of 
# converting exnode and exelem to ipnode and ipelem (this is not generic
# unfortunately), some fitting with cmiss, 
set dir example ap
gfx create material aqua_blue ambient 0.1 0.9 1 diffuse 0.1 0.9 1 emission 0 0 0 specular 0.8 0.8 0.8 alpha 1 shininess 0.8
gfx create material jade ambient 0.1 0.56 0 diffuse 0.1 0.39 0 emission 0 0 0 specular 0.8 0.8 0.8 alpha 1 shininess 0.8
gfx create material purple ambient 0.72 0 1 diffuse 0.5 0 1 emission 0 0 0 specular 1 1 1 alpha 1 shininess 0.8
gfx create material red ambient 1 0 0 diffuse 1 0 0 emission 0 0 0 specular 0.8 0.8 0.8 alpha 1 shininess 0.8
if (!$TESTING)
	gfx create window 1;
	gfx modify window 1 view parallel eye_point 360.515 -98.2134 593.377 interest_point 27.6929 18.9214 48.7295 up_vector 0.0456354 0.981996 0.183306 view_angle 41.4883 near_clipping_plane 6.48947 far_clipping_plane 2319.12 relative_viewport ndc_placement -1 1 2 2 viewport_coordinates 0 0 1 1;

# Read in the four cubic elements in which we will embed our mesh
gfx read nodes example host.exnode
gfx read elements example host.exelem
# Read in the embedded face mesh in its original position.
gfx read nodes example new_source.exnode
gfx read elements example new_mesh.exelem
gfx modify g_element mesh surfaces material jade
gfx modify g_element mesh node_points glyph sphere size "5*5*5" centre 0,0,0 no_select material purple
# Calculate xi positions for each of these embedded nodes.
# This will be done in cm.  The host mesh was converted to ipnode
# and ipelem using the fortran program ex2ip.  This program is available
# here but makes many assumptions about the file structure, specifically 
# the number of derivatives and where some of the spaces are.
# It can usually be modified to work with other exnode and exelem files.
# The new_source nodes must be converted to ipdata. This was done with the 
# fortran program ex2ipdata.
# Now we can run cmiss to calculate the xi points.
gfx create cmiss
set dir example ap
open comfile example anthro_xi.com exec
# This generates a file called face.ipxi
# By converting this file to element xi we can graphically visualise the 
# error between the xi positions and the data positions.  An awk script
# is available here to convert ipxi to and exnode or exdata file which 
# can be read in.
system "awk -f $example/ipxi2ex.awk < face.ipxi > face_xi.exnode"
gfx read nodes face_xi.exnode
# Now each of the embedded nodes has two 3D coordinates.  An explicit
# original coordinate and an element_xi_coordinate.  By drawing a line
# between these positions we get to see the error.  Because we just 
# calculated the xi's there shouldn't be any error at this point.
# In addition, read in a third coordinate at the target positions, then we can
# interactively see the error in the fit represented as red lines.
gfx read nodes example new_target.exnode
gfx define field error coordinate_system rectangular_cartesian add fields target_coordinates element_xi_coordinate scale_factors 1 -1
gfx modify g_element mesh node_points glyph line size "0*1.8*1.8" centre 0,0,0 orientation error scale_factors "1*0*0" no_select material red
# If we edit the positions of the host mesh the error vectors update.
gfx modify g_element host node_points glyph sphere size "5*5*5" centre 0,0,0 select_on material aqua_blue
# Now choose select mode in the graphics window and drag the host mesh nodes.
# We can use cmiss to calculate an optimal host mesh.
gfx create cmiss
set dir example ap
open comfile example anthro_fit.com exec
gfx read node host_fit.exnode
# The error vectors update with the host mesh.  You can see how difficult it was
# to fit around the snout.  Element_xi coordinates cannot be interpolated by 
# elements like normal nodes, to draw the lines and elements at the fitted
# positions the actual coordinates of the element_xi nodes must be explicitly
# calculated and stored as real numbers.
gfx evaluate ngroup mesh source element_xi_coordinate destination coordinates
# So what?  Wasn't that a very complicated way to move the nodes?
# True but now we have a mapping from the first face to the second so
# can update a high res version of the first face to approximate the second,
# or if we had a standard human body model we can fit some important markers
# measured on a specific individual, fit to those and then update the whole
# model to approximate that individual.

Files used by this example are:

Name               Modified     Size

example_ap.com 20-Apr-2012 4.5k COPYRIGHT 19-Apr-2012 504 anthro_fit.com 20-Apr-2012 833 anthro_xi.com 20-Apr-2012 479 ex2ip 20-Apr-2012 21k ex2ip.f 20-Apr-2012 5.5k ex2ip2.f 20-Apr-2012 5.5k ex2ipdata 20-Apr-2012 16k ex2ipdata.f 20-Apr-2012 2.7k face.exdata 20-Apr-2012 8.4k face.ipxi 20-Apr-2012 7.8k face_xi.exnode 20-Apr-2012 8.5k host.com 20-Apr-2012 298 host.exelem 20-Apr-2012 9.2k host.exnode 20-Apr-2012 5.9k host.ipbase 20-Apr-2012 6.0k host.ipcoor 20-Apr-2012 588 host.ipelem 20-Apr-2012 1.5k host.ipelfd 20-Apr-2012 1.1k host.ipfiel 20-Apr-2012 16k host.ipmesh 20-Apr-2012 1.0k host.ipnode 20-Apr-2012 3.9k host_fit.exelem 20-Apr-2012 12k host_fit.exnode 20-Apr-2012 11k host_fit.ipfit 20-Apr-2012 1.9k ipxi2ex.awk 20-Apr-2012 314 new_mesh.exelem 20-Apr-2012 18k new_source.exnode 20-Apr-2012 4.1k new_source.ipdata 20-Apr-2012 4.7k new_target.exnode 20-Apr-2012 4.1k new_target.ipdata 20-Apr-2012 4.7k

Download the entire example:

Name                         Modified     Size

examples_a_backup_ap.tar.gz 12-Aug-2014 176k

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

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

CMISS Help / Examples / a_backup / ap