Example a/fit_vessels: fit_vessels: Fitting curves to vessel data points

This example shows how to use cmgui to generate a sequence of fitted curves to grouped sets of data points.

Screenshot of example a/fit_vessels


The comfile run by this example is as follows:

# fit_snakes.com
# This command file is used to create high-order fits of vessels
# 'segments.txt' must be exported previously detailing the range
# of data points for each fitted segment.

use strict;

{
# read the piecewise points for fitting and lines for comparison later
gfx read data $example/vessel_data.exnode;
# new node group to put the new elements into
gfx cre ngroup smoothed

#now read in all the segments
$filename="$example/segments.txt";
CORE::open(IN,$filename) || die("could not open file $filename!");
@segs=<IN>;
close(IN);

#Define a weight field, normal_weight for normal nodes and
#normal_weight+end_weight for the two end points of each segment

gfx define field normal_weight constant 1;
gfx define field end_weight constant 100;
gfx define field end_point_number_1 constant 1;
gfx define field end_point_number_2 constant 1;
gfx define field filter_end_1 equal_to fields cmiss_number end_point_number_1;
gfx define field filter_end_2 equal_to fields cmiss_number end_point_number_2;
gfx define field end_points or fields filter_end_1 filter_end_2;
gfx define field end_weights multiply fields end_points end_weight;
gfx define field weight add fields normal_weight end_weights;

# just go ahead and fit the whole thing with radius (pixelcount) and intensity included
foreach $nodes (@segs) {
		printf " selecting and fitting segment $nodes...\n";
		gfx unsel da all;	# unselection bug fixed 29 Mar 2006 :)
		cmiss("gfx sel da $nodes");
		@bounds=split(/\./,$nodes);
		$num_els=int(($bounds[2]-$bounds[0])/4);	# average 4 data points per element

		#Set the first and last points into the correct fields
		gfx define field end_point_number_1 constant $bounds[0];
		gfx define field end_point_number_2 constant $bounds[2];

		if ($num_els<1) { $num_els=1; }

		#Don't need much smoothing
		gfx create snake coord coordinates dest smoothed number_of_elements $num_els density 0 stiffness 0.00001 number_of_fitting_fields 3 fitting_fields coordinates pixelcount intensity weight_field weight;
}

if ($TESTING)
  {
	 gfx write nodes group smoothed smoothed.exnode;
	 gfx write elements group smoothed smoothed.exelem;
  }
else
  {
	 # Rendering detail
	 # create b/w spectrum for visualisation
	 gfx modify spectrum default clear overwrite_colour;
	 gfx modify spectrum default log exaggeration 1 left range 0 253 extend_above extend_below red colour_range 0 1 ambient diffuse component 1;
	 gfx modify spectrum default log exaggeration 1 left range 0 253 extend_above extend_below green colour_range 0 1 ambient diffuse component 1;
	 gfx modify spectrum default log exaggeration 1 left range 0 253 extend_above extend_below blue colour_range 0 1 ambient diffuse component 1;

	 # show cylinders of fitted vessels
	 gfx modify g_element smoothed general clear circle_discretization 12 default_coordinate coordinates element_discretization "15*4*4" native_discretization none;
	 gfx modify g_element smoothed cylinders radius_scalar pixelcount select_on material default data intensity spectrum default selected_material default_selected;
	 #gfx modify g_element smoothed lines select_on material default data intensity spectrum default selected_material default_selected;

	 # hide data points
	 gfx modify g_element vessel_data general clear circle_discretization 6 default_coordinate coordinates element_discretization "4*4*4" native_discretization none;
	 #gfx modify g_element vessel_data data_points glyph diamond general size "1*1*1" centre 0,0,0 font default select_on material blue selected_material default_selected;

	 # Use a shiny per pixel lighting material
	 gfx create material default per_pixel ambient 0.21 0.21 0.26 diffuse 0.59 0.61 0.64 emission 0 0 0 specular 0.89 0.89 0.89 alpha 1 shininess 0.96;

	 gfx create window 1;
  }


}

Files used by this example are:

Name                Modified     Size

fit_vessels.com 17-Mar-2014 3.7k COPYRIGHT 17-Mar-2014 504 segments.txt 17-Mar-2014 2.6k vessel_data.exnode 17-Mar-2014 474k

Download the entire example:

Name                           Modified     Size

examples_a_fit_vessels.tar.gz 09-Mar-2016 715k

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxFailureSun Mar 6 00:05:39 20161
last breakTue Mar 31 00:14:00 20152
cmgui-wx-debugFailureSun Mar 6 00:09:54 20162
last breakTue Mar 31 00:16:00 20153
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:16:12 20163
last breakTue Mar 31 00:28:00 20154
cmgui-wx-debug-valgrindFailureSun Mar 6 01:36:08 2016118
last breakTue Mar 31 02:00:00 2015116
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:31 20160
last breakThu Apr 2 00:18:00 20152
cmgui-wx-debugFailureSun Mar 6 00:01:46 20161
last breakThu Apr 2 00:25:00 20152
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:47 20162
last breakThu Apr 2 00:27:00 20153
cmgui-wx-debug-valgrindFailureSun Mar 6 00:08:17 201699
last breakSun Mar 6 00:06:00 201699
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:10:11 2016111

Testing status by file:


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

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


CMISS Help / Examples / a / fit_vessels