int define_Computed_field_type_derivative_image_filter(struct Parse_state *state,
	void *field_modify_void, void *computed_field_simple_package_void)
/*******************************************************************************
LAST MODIFIED : 18 October 2006

DESCRIPTION :
Converts <field> into type DERIVATIVE (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int return_code;
		int order;
	int direction;
	struct Computed_field *source_field;
	Computed_field_modify_data *field_modify;
	struct Option_table *option_table;
	struct Set_Computed_field_conditional_data set_source_field_data;

	ENTER(define_Computed_field_type_derivative_image_filter);
	USE_PARAMETER(computed_field_simple_package_void);
	if (state && (field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code = 1;
		/* get valid parameters for projection field */
		source_field = (struct Computed_field *)NULL;
		order = 1;
		direction=1;

		if ((NULL != field_modify->get_field()) &&
			(computed_field_derivative_image_filter_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code =
				Cmiss_field_get_type_derivative_image_filter(field_modify->get_field(), &source_field,
					&order, &direction);
		}
		if (return_code)
		{
			/* must access objects for set functions */
			if (source_field)
			{
				ACCESS(Computed_field)(source_field);
			}

			option_table = CREATE(Option_table)();
			Option_table_add_help(option_table,
				"The derivative_filter field uses the itk::DerivativeImageFilter code to calculate the derivative of a field in a particular direction. The <field> it operates on is usually a sample_texture field, based on a texture that has been created from image file(s).  The <order> paramater sets the order of the derivative and the <direction> parameter is an integer value that specifies the direction to evaluate the derivative in.  0 corresponds to the x direction. See a/testing/image_processing_2D for an example of using this field. For more information see the itk software guide.");

			/* field */
			set_source_field_data.computed_field_manager =
				field_modify->get_field_manager();
			set_source_field_data.conditional_function = Computed_field_is_scalar;
			set_source_field_data.conditional_function_user_data = (void *)NULL;
			Option_table_add_entry(option_table, "field", &source_field,
				&set_source_field_data, set_Computed_field_conditional);
			/* order */
			Option_table_add_int_non_negative_entry(option_table, "order",
				&order);
			/*direciton*/
			Option_table_add_int_non_negative_entry(option_table, "direction",
				&direction);

			return_code = Option_table_multi_parse(option_table, state);
			DESTROY(Option_table)(&option_table);

			/* no errors,not asking for help */
			if (return_code)
			{
				if (!source_field)
				{
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_derivative_image_filter.  "
						"Missing source field");
					return_code = 0;
				}
			}
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					Cmiss_field_module_create_derivative_image_filter(
						field_modify->get_field_module(),
						source_field, order, direction));
			}

			if (!return_code)
			{
				if ((!state->current_token) ||
					(strcmp(PARSER_HELP_STRING, state->current_token)&&
						strcmp(PARSER_RECURSIVE_HELP_STRING, state->current_token)))
				{
					/* error */
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_derivative_image_filter.  Failed");
				}
			}
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_derivative_image_filter.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_derivative_image_filter */
int gfx_modify_spectrum_settings_log(struct Parse_state *state,
	void *modify_spectrum_data_void,void *spectrum_command_data_void)
/*******************************************************************************
LAST MODIFIED : 17 January 2001

DESCRIPTION :
Executes a GFX MODIFY SPECTRUM LOG command.
If return_code is 1, returns the completed Modify_spectrum_data with the
parsed settings. Note that the settings are ACCESSed once on valid return.
==============================================================================*/
{
	char ambient,amb_diff,diffuse,emission,extend_above,
		extend_below,fix_maximum,fix_minimum,left,reverse,right,
		specular,transparent_above,transparent_below;
	enum Spectrum_settings_colour_mapping colour_mapping;
	int black_band_int,component,number_of_bands,range_components,return_code;
	float band_ratio,exaggeration,step_value;
	FE_value colour_range[2],range[2];
	struct Modify_spectrum_data *modify_spectrum_data;
	struct Option_table *option_table, *render_option_table;
	struct Spectrum_settings *settings;

	ENTER(gfx_modify_spectrum_settings_log);
	USE_PARAMETER(spectrum_command_data_void);
	if (state)
	{
		modify_spectrum_data=(struct Modify_spectrum_data *)modify_spectrum_data_void;
		if (modify_spectrum_data)
		{
			/* create the spectrum_settings: */
			settings=modify_spectrum_data->settings=CREATE(Spectrum_settings)();
			if (settings)
			{
				/* access since deaccessed in gfx_modify_spectrum */
				ACCESS(Spectrum_settings)(modify_spectrum_data->settings);

				Spectrum_settings_set_type(settings,SPECTRUM_LOG);

				colour_mapping = Spectrum_settings_get_colour_mapping(settings);
				ambient = 0;
				amb_diff = 0;
				band_ratio = 0.01;
				diffuse = 0;
				emission = 0;
				extend_above = 0;
				extend_below = 0;
				fix_maximum=0;
				fix_minimum=0;
				left = 0;
				number_of_bands = 10;
				reverse = 0;
				right = 0;
				specular = 0;
				step_value = 0.5;
				transparent_above = 0;
				transparent_below = 0;
				range_components = 2;
				colour_range[0] = 0.0;
				colour_range[1] = 1.0;
				range[0] = (FE_value)(modify_spectrum_data->spectrum_minimum);
				range[1] = (FE_value)(modify_spectrum_data->spectrum_maximum);
				component = Spectrum_settings_get_component_number(settings);
				exaggeration = Spectrum_settings_get_exaggeration(settings);

				option_table = CREATE(Option_table)();
				/* band_ratio */
				Option_table_add_float_entry(option_table, "band_ratio",
					&band_ratio);
				/* colour_range */
				Option_table_add_FE_value_vector_entry(option_table, "colour_range",
					colour_range, &range_components);
				/* component */
				Option_table_add_int_positive_entry(option_table, "component",
					&component);
				/* exaggeration */
				Option_table_add_float_entry(option_table, "exaggeration",
					&exaggeration);
				/* extend_above */
				Option_table_add_char_flag_entry(option_table, "extend_above",
					&extend_above);
				/* extend_below */
				Option_table_add_char_flag_entry(option_table, "extend_below",
					&extend_below);
				/* fix_maximum */
				Option_table_add_char_flag_entry(option_table, "fix_maximum",
					&fix_maximum);
				/* fix_minimum */
				Option_table_add_char_flag_entry(option_table, "fix_minimum",
					&fix_minimum);
				/* left */
				Option_table_add_char_flag_entry(option_table, "left",
					&left);
				/* number_of_bands */
				Option_table_add_int_positive_entry(option_table, "number_of_bands",
					&number_of_bands);
				/* position */
				Option_table_add_int_non_negative_entry(option_table, "position",
					&(modify_spectrum_data->position));
				/* range */
				Option_table_add_FE_value_vector_entry(option_table, "range",
					range, &range_components);
				/* reverse */
				Option_table_add_char_flag_entry(option_table, "reverse",
					&reverse);
				/* right */
				Option_table_add_char_flag_entry(option_table, "right",
					&right);
				/* step_value */
				Option_table_add_float_entry(option_table, "step_value",
					&step_value);
				/* transparent_above */
				Option_table_add_char_flag_entry(option_table, "transparent_above",
					&transparent_above);
				/* transparent_below */
				Option_table_add_char_flag_entry(option_table, "transparent_below",
					&transparent_below);
				/* conversion_mode */
				Option_table_add_enumerator_Spectrum_settings_colour_mapping(
					option_table, &colour_mapping);
				/* render_option */
				render_option_table = CREATE(Option_table)();
				Option_table_add_char_flag_entry(render_option_table, "ambient",
					&ambient);
				Option_table_add_char_flag_entry(render_option_table, "amb_diff",
					&amb_diff);
				Option_table_add_char_flag_entry(render_option_table, "diffuse",
					&diffuse);
				Option_table_add_char_flag_entry(render_option_table, "emission",
					&emission);
				Option_table_add_char_flag_entry(render_option_table, "specular",
					&specular);
				Option_table_add_suboption_table(option_table, render_option_table);


				if (!(return_code=Option_table_multi_parse(option_table,state)))
				{
					DEACCESS(Spectrum_settings)(&(modify_spectrum_data->settings));
				}
				DESTROY(Option_table)(&option_table);
				if (return_code)
				{
					Spectrum_settings_set_colour_mapping(settings,
						colour_mapping);
					Spectrum_settings_set_number_of_bands(settings,
						number_of_bands);
					black_band_int = (band_ratio * 1000.0 + 0.5);
					Spectrum_settings_set_black_band_proportion(settings,
						black_band_int);
					Spectrum_settings_set_step_value(settings, step_value);
				}
				if ( return_code )
				{
					if (specular + emission > 1)
					{
						display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_linear.  "
							"All spectrums are ambient diffuse.  The specular and emission flags are ignored.");
						return_code=0;
					}
				}
				if ( return_code )
				{
					if ( extend_above && transparent_above)
					{
						display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log.  "
							"Specify only one of extend_above and transparent_above");
						return_code=0;
					}
					else if (extend_above)
					{
						Spectrum_settings_set_extend_above_flag(settings, 1);
					}
					else if (transparent_above)
					{
						Spectrum_settings_set_extend_above_flag(settings, 0);
					}
				}
				if ( return_code )
				{
					if ( extend_below && transparent_below)
					{
						display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log.  "
							"Specify only one of extend_below and transparent_below");
						return_code=0;
					}
					else if (extend_below)
					{
						Spectrum_settings_set_extend_below_flag(settings, 1);
					}
					else if (transparent_below)
					{
						Spectrum_settings_set_extend_below_flag(settings, 0);
					}
				}
				if ( return_code )
				{
					if (left && right)
					{
						display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log.  "
							"Specify only one of left or right");
						return_code=0;
					}
					else if (left)
					{
						exaggeration = fabs(exaggeration);
					}
					else if (right)
					{
						exaggeration = -fabs(exaggeration);
					}
					Spectrum_settings_set_exaggeration(settings,
						exaggeration);
				}
				if ( return_code )
				{
					Spectrum_settings_set_component_number(settings,
						component);
					Spectrum_settings_set_colour_value_minimum(settings,
						colour_range[0]);
					Spectrum_settings_set_colour_value_maximum(settings,
						colour_range[1]);
					Spectrum_settings_set_range_minimum(settings,
						range[0]);
					Spectrum_settings_set_range_maximum(settings,
						range[1]);
					Spectrum_settings_set_reverse_flag(settings,
						reverse);
				}
				/* Must set fix_maximum,fix_minimum after setting minimum and maximum range */
				if ( return_code )
				{
					if (fix_maximum)
					{
						Spectrum_settings_set_fix_maximum_flag(settings, 1);
					}
				}
				if ( return_code )
				{
					if (fix_minimum)
					{
						Spectrum_settings_set_fix_minimum_flag(settings, 1);
					}
				}
			}
			else
			{
				display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log.  "
					"Could not create settings");
				return_code=0;
			}
		}
		else
		{
			display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log.  "
				"No modify data");
			return_code=0;
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log.  Missing state");
		return_code=0;
	}
	LEAVE;

	return (return_code);
} /* gfx_modify_spectrum_log */
int define_Computed_field_type_binary_dilate_image_filter(struct Parse_state *state,
	void *field_modify_void, void *computed_field_simple_package_void)
/*******************************************************************************
LAST MODIFIED : 30 August 2006

DESCRIPTION :
Converts <field> into type COMPUTED_FIELD_BINARYDILATEFILTER (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int radius;
	double dilate_value;
	int return_code;
	struct Computed_field *source_field;
	Computed_field_modify_data *field_modify;
	struct Option_table *option_table;
	struct Set_Computed_field_conditional_data set_source_field_data;

	ENTER(define_Computed_field_type_binary_dilate_image_filter);
	USE_PARAMETER(computed_field_simple_package_void);
	if (state && (field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code = 1;
		/* get valid parameters for projection field */
		source_field = (struct Computed_field *)NULL;
		radius = 1;
		dilate_value = 1;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_binary_dilate_image_filter_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code =
				Cmiss_field_get_type_binary_dilate_image_filter(field_modify->get_field(), &source_field,
					&radius, &dilate_value);
		}
		if (return_code)
		{
			/* must access objects for set functions */
			if (source_field)
			{
				ACCESS(Computed_field)(source_field);
			}

			option_table = CREATE(Option_table)();
			Option_table_add_help(option_table,
				"The binary_dilate_filter field uses the itk::BinaryDilateImageFilter code to produce an output field which is a dilation of a binary image (an image where each pixel has 1 of 2 values).  The region identified by the pixels with intensity <dilate_value> is dilate (enlarged), by replacing each pixel with a ball.  The size of the ball is set by specifying the <radius>. The <field> it operates on is usually a thresholded or segmented field. See a/testing/image_processing_2D for an example of using this field.  For more information see the itk software guide.");

			/* field */
			set_source_field_data.computed_field_manager =
				field_modify->get_field_manager();
			set_source_field_data.conditional_function = Computed_field_is_scalar;
			set_source_field_data.conditional_function_user_data = (void *)NULL;
			Option_table_add_entry(option_table, "field", &source_field,
				&set_source_field_data, set_Computed_field_conditional);
			/* radius */
			Option_table_add_int_non_negative_entry(option_table, "radius",
				&radius);
			/* dilate_value */
			Option_table_add_double_entry(option_table, "dilate_value",
				&dilate_value);

			return_code = Option_table_multi_parse(option_table, state);
			DESTROY(Option_table)(&option_table);

			/* no errors,not asking for help */
			if (return_code)
			{
				if (!source_field)
				{
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_binary_dilate_image_filter.  "
						"Missing source field");
					return_code = 0;
				}
			}
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					Cmiss_field_module_create_binary_dilate_image_filter(
						field_modify->get_field_module(),
						source_field, radius, dilate_value));
			}

			if (!return_code)
			{
				if ((!state->current_token) ||
					(strcmp(PARSER_HELP_STRING, state->current_token)&&
						strcmp(PARSER_RECURSIVE_HELP_STRING, state->current_token)))
				{
					/* error */
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_binary_dilate_image_filter.  Failed");
				}
			}
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_binary_dilate_image_filter.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_binary_dilate_image_filter */
int define_Computed_field_type_integration(Parse_state *state,
	void *field_modify_void,void *computed_field_integration_package_void)
/*******************************************************************************
LAST MODIFIED : 24 August 2006

DESCRIPTION :
Converts <field> into type COMPUTED_FIELD_INTEGRATION (if it is not already)
and allows its contents to be modified.
==============================================================================*/
{
	int return_code = 1;
	ENTER(define_Computed_field_type_integration);
	Computed_field_modify_data *field_modify = reinterpret_cast<Computed_field_modify_data *>(field_modify_void);
	USE_PARAMETER(computed_field_integration_package_void);
	if (state && field_modify)
	{
		cmzn_region_id region = field_modify->get_region();
		cmzn_mesh_id mesh = 0;
		cmzn_field_id coordinate_field = 0;
		cmzn_field_id integrand = 0;
		int magnitude_coordinates_flag = 0;
		int seed_element_identifier = 0;
		float time_update = 0;
		if ((NULL != field_modify->get_field()) &&
			Computed_field_is_type_integration(field_modify->get_field()))
		{
			cmzn_element_id seed_element;
			return_code = Computed_field_get_type_integration(field_modify->get_field(),
				&mesh, &seed_element, &integrand, &magnitude_coordinates_flag, &coordinate_field);
			if (seed_element)
			{
				seed_element_identifier = cmzn_element_get_identifier(seed_element);
				cmzn_element_destroy(&seed_element);
			}
		}
		if (coordinate_field)
		{
			ACCESS(Computed_field)(coordinate_field);
		}
		if (integrand)
		{
			ACCESS(Computed_field)(integrand);
		}
		else
		{
			/* Make a default integrand of one */
			double value = 1.0;
			// use temporary field module to supply different defaults
			cmzn_fieldmodule *temp_field_module = cmzn_region_get_fieldmodule(region);
			cmzn_fieldmodule_set_field_name(temp_field_module, "constant_1.0");
			integrand = Computed_field_create_constant(temp_field_module,
				/*number_of_components*/1, &value);
			if (NULL == integrand)
			{
				display_message(ERROR_MESSAGE,
					"define_Computed_field_type_integration.  Unable to create constant integrand");
				return_code = 0;
			}
			cmzn_fieldmodule_destroy(&temp_field_module);
		}
		char *group_name = 0;

		Option_table *option_table = CREATE(Option_table)();
		/* coordinate */
		Set_Computed_field_conditional_data set_coordinate_field_data;
		set_coordinate_field_data.computed_field_manager = field_modify->get_field_manager();
		set_coordinate_field_data.conditional_function = Computed_field_has_up_to_3_numerical_components;
		set_coordinate_field_data.conditional_function_user_data = 0;
		Option_table_add_Computed_field_conditional_entry(option_table, "coordinate",
			&coordinate_field, &set_coordinate_field_data);
		/* integrand */
		Set_Computed_field_conditional_data set_integrand_field_data;
		set_integrand_field_data.computed_field_manager = field_modify->get_field_manager();
		set_integrand_field_data.conditional_function = Computed_field_is_scalar;
		set_integrand_field_data.conditional_function_user_data = 0;
		Option_table_add_Computed_field_conditional_entry(option_table, "integrand",
			&integrand, &set_integrand_field_data);
		/* magnitude_coordinates|no_magnitude_coordinates */
		Option_table_add_switch(option_table, "magnitude_coordinates", "no_magnitude_coordinates",
			&magnitude_coordinates_flag);
		// mesh
		Option_table_add_mesh_entry(option_table, "mesh", region, &mesh);
		/* region - legacy group name */
		Option_table_add_string_entry(option_table, "region", &group_name, " GROUP_NAME(DEPRECATED)");
		/* seed_element */
		Option_table_add_int_non_negative_entry(option_table, "seed_element",
			&seed_element_identifier);
		/* update_time_integration */
		Option_table_add_entry(option_table,"update_time_integration",
			&time_update, NULL, set_float);
		return_code = Option_table_multi_parse(option_table,state);
		DESTROY(Option_table)(&option_table);

		if (return_code && !mesh)
		{
			int dimension = FE_region_get_highest_dimension(cmzn_region_get_FE_region(region));
			mesh = cmzn_fieldmodule_find_mesh_by_dimension(field_modify->get_field_module(), dimension);
			if (group_name)
			{
				cmzn_field_id group_field = cmzn_fieldmodule_find_field_by_name(field_modify->get_field_module(), group_name);
				cmzn_field_group_id group = cmzn_field_cast_group(group_field);
				cmzn_field_element_group_id element_group = cmzn_field_group_get_field_element_group(group, mesh);
				cmzn_mesh_destroy(&mesh);
				mesh = cmzn_mesh_group_base_cast(cmzn_field_element_group_get_mesh_group(element_group));
				cmzn_field_element_group_destroy(&element_group);
				cmzn_field_group_destroy(&group);
				cmzn_field_destroy(&group_field);
			}
		}
		if (return_code && !mesh)
		{
			display_message(ERROR_MESSAGE, "You must specify a mesh.");
			return_code = 0;
		}
		if (return_code && !coordinate_field)
		{
			display_message(ERROR_MESSAGE, "You must specify a coordinate field.");
			return_code = 0;
		}
		if (return_code && !integrand)
		{
			display_message(ERROR_MESSAGE, "You must specify an integrand field.");
			return_code = 0;
		}
		cmzn_element_id seed_element = 0;
		if (return_code)
		{
			seed_element = cmzn_mesh_find_element_by_identifier(mesh, seed_element_identifier);
			if (!seed_element)
			{
				display_message(ERROR_MESSAGE, "Could not find seed_element %d in mesh.", seed_element_identifier);
				return_code = 0;
			}
		}
		if (return_code)
		{
			if (time_update && (NULL != field_modify->get_field()) &&
				Computed_field_is_type_integration(field_modify->get_field()))
			{
				display_message(ERROR_MESSAGE,
					"The update_time_integration code has not been updated"
					"with the latest changes.");
				return_code=0;
			}
			else
			{
				return_code = field_modify->update_field_and_deaccess(
					Computed_field_create_integration(field_modify->get_field_module(),
						mesh, seed_element, integrand, magnitude_coordinates_flag, coordinate_field));
			}
		}
		if (group_name)
		{
			DEALLOCATE(group_name);
		}
		cmzn_element_destroy(&seed_element);
		cmzn_mesh_destroy(&mesh);
		cmzn_field_destroy(&coordinate_field);
		cmzn_field_destroy(&integrand);
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_integration.  Invalid argument(s)");
		return_code=0;
	}
	LEAVE;

	return (return_code);
}
int define_Computed_field_type_xi_texture_coordinates(Parse_state *state,
	void *field_modify_void,void *computed_field_integration_package_void)
/*******************************************************************************
LAST MODIFIED : 24 August 2006

DESCRIPTION :
Converts <field> into type COMPUTED_FIELD_XI_TEXTURE_COORDINATES (if it is not already)
and allows its contents to be modified.
==============================================================================*/
{
	int return_code = 1;
	ENTER(define_Computed_field_type_xi_texture_coordinates);
	Computed_field_modify_data *field_modify = reinterpret_cast<Computed_field_modify_data *>(field_modify_void);
	USE_PARAMETER(computed_field_integration_package_void);
	if (state && field_modify)
	{
		cmzn_region_id region = field_modify->get_region();
		cmzn_mesh_id mesh = 0;
		int seed_element_identifier = 0;
		char *group_name = 0;

		Option_table *option_table = CREATE(Option_table)();
		// mesh
		Option_table_add_mesh_entry(option_table, "mesh", region, &mesh);
		/* region - legacy group name */
		Option_table_add_string_entry(option_table, "region", &group_name, " GROUP_NAME(OBSOLETE)");
		/* seed_element */
		Option_table_add_int_non_negative_entry(option_table, "seed_element",
			&seed_element_identifier);
		return_code = Option_table_multi_parse(option_table,state);
		DESTROY(Option_table)(&option_table);

		if (return_code && !mesh)
		{
			int dimension = FE_region_get_highest_dimension(cmzn_region_get_FE_region(region));
			mesh = cmzn_fieldmodule_find_mesh_by_dimension(field_modify->get_field_module(), dimension);
			if (group_name)
			{
				cmzn_field_id group_field = cmzn_fieldmodule_find_field_by_name(field_modify->get_field_module(), group_name);
				cmzn_field_group_id group = cmzn_field_cast_group(group_field);
				cmzn_field_element_group_id element_group = cmzn_field_group_get_field_element_group(group, mesh);
				cmzn_mesh_destroy(&mesh);
				mesh = cmzn_mesh_group_base_cast(cmzn_field_element_group_get_mesh_group(element_group));
				cmzn_field_element_group_destroy(&element_group);
				cmzn_field_group_destroy(&group);
				cmzn_field_destroy(&group_field);
			}
		}
		if (return_code && !mesh)
		{
			display_message(ERROR_MESSAGE, "Must specify mesh.");
			return_code = 0;
		}
		cmzn_element_id seed_element = 0;
		if (return_code)
		{
			seed_element = cmzn_mesh_find_element_by_identifier(mesh, seed_element_identifier);
			if (!seed_element)
			{
				display_message(ERROR_MESSAGE, "Could not find seed_element %d in mesh.", seed_element_identifier);
				return_code = 0;
			}
		}
		// use temporary field module to supply different defaults
		cmzn_field_id coordinate_field = FIRST_OBJECT_IN_MANAGER_THAT(Computed_field)(
			Computed_field_is_type_xi_coordinates, (void *)NULL,
			field_modify->get_field_manager());
		if (coordinate_field)
		{
			ACCESS(Computed_field)(coordinate_field);
		}
		else
		{
			if ((!state->current_token) ||
				(strcmp(PARSER_HELP_STRING, state->current_token)&&
					strcmp(PARSER_RECURSIVE_HELP_STRING, state->current_token)))
			{
				display_message(ERROR_MESSAGE,
					"define_Computed_field_type_xi_texture_coordinates.  xi field not found");
			}
			return_code = 0;
		}
		double value = 1.0;
		cmzn_fieldmodule *temp_field_module = cmzn_region_get_fieldmodule(region);
		cmzn_fieldmodule_set_field_name(temp_field_module, "constant_1.0");
		Computed_field *integrand = Computed_field_create_constant(temp_field_module,
			/*number_of_components*/1, &value);
		cmzn_fieldmodule_destroy(&temp_field_module);
		if (NULL == integrand)
		{
			display_message(ERROR_MESSAGE,
				"define_Computed_field_type_xi_texture_coordinates.  Unable to create constant field");
			return_code = 0;
		}
		if (return_code)
		{
			return_code = field_modify->update_field_and_deaccess(
				Computed_field_create_integration(field_modify->get_field_module(),
					mesh, seed_element, integrand, /*magnitude_coordinates*/0, coordinate_field));
		}
		if (group_name)
		{
			DEALLOCATE(group_name);
		}
		cmzn_element_destroy(&seed_element);
		cmzn_mesh_destroy(&mesh);
		cmzn_field_destroy(&coordinate_field);
		cmzn_field_destroy(&integrand);
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_xi_texture_coordinates.  Invalid argument(s)");
		return_code=0;
	}
	LEAVE;

	return (return_code);
}
int define_Computed_field_type_curvature_anisotropic_diffusion_image_filter(struct Parse_state *state,
	void *field_modify_void, void *computed_field_simple_package_void)
/*******************************************************************************
LAST MODIFIED : 18 October 2006

DESCRIPTION :
Converts <field> into type DISCRETEGAUSSIAN (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int return_code;
		double timeStep;
	double conductance;
	int numIterations;
	struct Computed_field *source_field;
	Computed_field_modify_data *field_modify;
	struct Option_table *option_table;
	struct Set_Computed_field_conditional_data set_source_field_data;

	ENTER(define_Computed_field_type_curvature_anisotropic_diffusion_image_filter);
	USE_PARAMETER(computed_field_simple_package_void);
	if (state && (field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code = 1;
		/* get valid parameters for projection field */
		source_field = (struct Computed_field *)NULL;
		timeStep = 0.125;
		conductance=3.0;
		numIterations = 5;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_curvature_anisotropic_diffusion_image_filter_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code =
				Cmiss_field_get_type_curvature_anisotropic_diffusion_image_filter(field_modify->get_field(), &source_field,
					&timeStep, &conductance, &numIterations);
		}
		if (return_code)
		{
			/* must access objects for set functions */
			if (source_field)
			{
				ACCESS(Computed_field)(source_field);
			}

			option_table = CREATE(Option_table)();
			Option_table_add_help(option_table,
				"The curvature_anisotropic_filter field uses the itk::CurvatureAnisotropicImageFilter code to smooth a field to reduce noise (or unwanted detail) while preserving edges. The <field> it operates on is usually a sample_texture field, based on a texture that has been created from image file(s).  The smoothing is accomplished by numerically solving a modified curvature diffusion equation.  The accuracy of the numerical solution can be adjusted by varying the <time_step> and <num_iterations> used.  The <conductance> is a parameter used by the diffusion equation.  A high value of conductance causes the image to diffuse (smooth) more, while a low value puts more emphasis on preserving features.  Typical conductance values are often in the range 0.5 to 2. See a/testing/image_processing_2D for an example of using this field. For more information see the itk software guide.");

			/* field */
			set_source_field_data.computed_field_manager =
				field_modify->get_field_manager();
			set_source_field_data.conditional_function = Computed_field_is_scalar;
			set_source_field_data.conditional_function_user_data = (void *)NULL;
			Option_table_add_entry(option_table, "field", &source_field,
				&set_source_field_data, set_Computed_field_conditional);
			/* timeStep */
			Option_table_add_double_entry(option_table, "time_step",
				&timeStep);
			/* conductance */
			Option_table_add_double_entry(option_table, "conductance",
				&conductance);
			/* numIterations */
			Option_table_add_int_non_negative_entry(option_table, "num_iterations",
																							(int*) &numIterations);

			return_code = Option_table_multi_parse(option_table, state);
			DESTROY(Option_table)(&option_table);

			/* no errors,not asking for help */
			if (return_code)
			{
				if (!source_field)
				{
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_curvature_anisotropic_diffusion_image_filter.  "
						"Missing source field");
					return_code = 0;
				}
			}
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					Cmiss_field_module_create_curvature_anisotropic_diffusion_image_filter(
						field_modify->get_field_module(),
						source_field, timeStep, conductance, numIterations));
			}

			if (!return_code)
			{
				if ((!state->current_token) ||
					(strcmp(PARSER_HELP_STRING, state->current_token)&&
						strcmp(PARSER_RECURSIVE_HELP_STRING, state->current_token)))
				{
					/* error */
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_curvature_anisotropic_diffusion_image_filter.  Failed");
				}
			}
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_curvature_anisotropic_diffusion_image_filter.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_curvature_anisotropic_diffusion_image_filter */