/***************************************************************************//**
 * Command modifier function which converts field into type 'determinant'
 * (if it is not already) and allows its contents to be modified.
 */
int define_Computed_field_type_determinant(struct Parse_state *state,
	void *field_modify_void, void *computed_field_matrix_operators_package_void)
{
	int return_code;

	ENTER(define_Computed_field_type_determinant);
	USE_PARAMETER(computed_field_matrix_operators_package_void);
	Computed_field_modify_data *field_modify =
		reinterpret_cast<Computed_field_modify_data*>(field_modify_void);
	if (state && field_modify)
	{
		return_code = 1;
		cmzn_field_id source_field = 0;
		if (NULL != field_modify->get_field() &&
			(computed_field_determinant_type_string ==
			 Computed_field_get_type_string(field_modify->get_field())))
		{
			source_field = cmzn_field_get_source_field(field_modify->get_field(), 1);
		}
		Option_table *option_table = CREATE(Option_table)();
		Option_table_add_help(option_table,
			"Creates a field returning the scalar real determinant of a square matrix. "
			"Only supports 1, 4 (2x2) and 9 (3x3) component source fields.");
		struct Set_Computed_field_conditional_data set_source_field_data =
		{
			Computed_field_is_square_matrix,
			/*user_data*/0,
			field_modify->get_field_manager()
		};
		Option_table_add_entry(option_table, "field", &source_field,
			&set_source_field_data, set_Computed_field_conditional);
		return_code = Option_table_multi_parse(option_table, state);
		if (return_code)
		{
			return_code = field_modify->update_field_and_deaccess(
				cmzn_fieldmodule_create_field_determinant(field_modify->get_field_module(),
					source_field));
		}
		DESTROY(Option_table)(&option_table);
		if (source_field)
		{
			cmzn_field_destroy(&source_field);
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_determinant.  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_matrix_invert(struct Parse_state *state,
	void *field_modify_void, void *computed_field_matrix_operators_package_void)
/*******************************************************************************
LAST MODIFIED : 25 August 2006

DESCRIPTION :
Converts <field> into type 'matrix_invert' (if it is not already) and allows its
contents to be modified.
==============================================================================*/
{
	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_matrix_invert);
	USE_PARAMETER(computed_field_matrix_operators_package_void);
	if (state&&(field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code = 1;
		source_field = (struct Computed_field *)NULL;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_matrix_invert_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code = Computed_field_get_type_matrix_invert(field_modify->get_field(), &source_field);
		}
		if (return_code)
		{
			if (source_field)
			{
				ACCESS(Computed_field)(source_field);
			}
			option_table = CREATE(Option_table)();
			Option_table_add_help(option_table,
			  "A matrix_invert field returns the inverse of a square matrix.  Here, a 9 component source field is interpreted as a (3 * 3) matrix with the first 3 components being the first row, the next 3 components being the middle row, and so on.  See a/current_density for an example of using the matrix_invert field.");
			set_source_field_data.conditional_function =
				Computed_field_is_square_matrix;
			set_source_field_data.conditional_function_user_data = (void *)NULL;
			set_source_field_data.computed_field_manager =
				field_modify->get_field_manager();
			Option_table_add_entry(option_table, "field", &source_field,
				&set_source_field_data, set_Computed_field_conditional);
			return_code = Option_table_multi_parse(option_table, state);
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					cmzn_fieldmodule_create_field_matrix_invert(field_modify->get_field_module(),
						source_field));
			}
			DESTROY(Option_table)(&option_table);
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_matrix_invert.  Invalid argument(s)");
		return_code=0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_matrix_invert */
int define_Computed_field_type_canny_edge_detection_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_CANNYEDGEDETECTIONFILTER (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int return_code;
	double variance;
	double maximumError;
	double upperThreshold;
	double lowerThreshold;

	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_canny_edge_detection_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;
		variance = 0;
		maximumError = 0.01;
		upperThreshold = 0;
		lowerThreshold = 0;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_canny_edge_detection_image_filter_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code =
				cmzn_field_get_type_canny_edge_detection_image_filter(field_modify->get_field(), &source_field,
				  &variance, &maximumError, &upperThreshold, &lowerThreshold);
		}
		if (return_code)
		{
			/* must access objects for set functions */
			if (source_field)
			{
				ACCESS(Computed_field)(source_field);
			}

			/* Discover the source field */
			option_table = CREATE(Option_table)();
			Option_table_add_help(option_table,
				"The canny_edge_detection field uses the itk::CannyEdgeDetectionImageFilter code to detect edges in a field. The <field> it operates on is usually a sample_texture field, based on a texture that has been created from image file(s).  Increasing the <variance> smooths the input image more, which reduces sensitivity to image noise at the expense of losing some detail. Decreasing the <maximum_error> also reduces edges detected as the result of noise.  The <upper_threshold> sets the level which a point must be above to use it as the start of the edge. The edge will then grow from that point until the level drops below the <lower_threshold>. Increasing the <upper_threshold> will decrease the number of edges detected. Increasing the <lower_threshold> will reduce the length of edges.  See a/testing/image_processing_2D for an example of using this field.");

			/* 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);
			/* variance */
			Option_table_add_double_entry(option_table, "variance",
				&variance);
			/* maximumError */
			Option_table_add_double_entry(option_table, "maximum_error",
				&maximumError);
			/* upperThreshold */
			Option_table_add_double_entry(option_table, "upper_threshold",
				&upperThreshold);
			/* lowerThreshold */
			Option_table_add_double_entry(option_table, "lower_threshold",
				&lowerThreshold);
			return_code = Option_table_multi_parse(option_table, state);
			DESTROY(Option_table)(&option_table);

			if (return_code)
			{
				if (!source_field)
				{
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_canny_edge_detection_image_filter.  "
						"Missing source field");
					return_code = 0;
				}
			}
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					cmzn_fieldmodule_create_field_imagefilter_canny_edge_detection(
						field_modify->get_field_module(), source_field, variance,
						maximumError, upperThreshold, lowerThreshold));
			}

			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_canny_edge_detection_image_filter.  Failed");
				}
			}

			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_canny_edge_detection_image_filter.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_canny_edge_detection_image_filter */
int define_Computed_field_type_mean_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_MEANIMAGEFILTER (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int dimension, expected_parameters, i, old_dimension, previous_state_index,
		*radius_sizes, return_code, *sizes;
	struct Computed_field *source_field, *texture_coordinate_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_mean_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_sizes = (int *)NULL;
		old_dimension = 0;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_mean_image_filter_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code =
				cmzn_field_get_type_mean_image_filter(field_modify->get_field(), &source_field,
					&radius_sizes);
			return_code = Computed_field_get_native_resolution(source_field,
				&old_dimension, &sizes, &texture_coordinate_field);
			if (return_code)
			{
				DEALLOCATE(sizes);
			}
		}
		if (return_code)
		{
			/* must access objects for set functions */
			if (source_field)
			{
				ACCESS(Computed_field)(source_field);
			}

			if ((!state->current_token) ||
				(strcmp(PARSER_HELP_STRING, state->current_token)&&
					strcmp(PARSER_RECURSIVE_HELP_STRING, state->current_token)))
			{

				previous_state_index = state->current_index;

				/* Discover the source field */
				option_table = CREATE(Option_table)();
				/* field */
				set_source_field_data.computed_field_manager =
					field_modify->get_field_manager();
				set_source_field_data.conditional_function = Computed_field_has_numerical_components;
				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);
				/* Ignore all the other entries */
				Option_table_ignore_all_unmatched_entries(option_table);
				return_code = Option_table_multi_parse(option_table, state);
				DESTROY(Option_table)(&option_table);
				/* Return back to where we were */
				shift_Parse_state(state, previous_state_index - state->current_index);
				/* no errors,not asking for help */
				if (return_code)
				{
					if (!source_field)
					{
						display_message(ERROR_MESSAGE,
							"define_Computed_field_type_mean_image_filter.  "
							"Missing source field");
						return_code = 0;
					}
				}
				if (return_code)
				{
					return_code = Computed_field_get_native_resolution(source_field,
						&dimension, &sizes, &texture_coordinate_field);
					if (return_code)
					{
						DEALLOCATE(sizes);

						if (!radius_sizes || (old_dimension != dimension))
						{
							REALLOCATE(radius_sizes, radius_sizes, int, dimension);
							for (i = old_dimension ; i < dimension ; i++)
							{
								radius_sizes[i] = 1;
							}
						}
						/* Read the radius sizes */
						option_table = CREATE(Option_table)();
						/* field */
						expected_parameters = 1;
						Option_table_add_ignore_token_entry(option_table, "field",
							&expected_parameters);
						/* radius_sizes */
						Option_table_add_int_vector_entry(option_table,
							"radius_sizes", radius_sizes, &dimension);
						return_code = Option_table_multi_parse(option_table, state);
						DESTROY(Option_table)(&option_table);
					}
					else
					{
						display_message(ERROR_MESSAGE,
							"define_Computed_field_type_mean_image_filter.  "
							"Source field does not have an image dimension.");
						return_code = 0;
					}
				}
				if (return_code)
				{
					return_code = field_modify->update_field_and_deaccess(
						cmzn_fieldmodule_create_field_imagefilter_mean(
							field_modify->get_field_module(),
							source_field, dimension, radius_sizes));
				}

				if (!return_code)
				{
					/* error */
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_mean_image_filter.  Failed");
				}
			}
			else
			{
				/* Write help */
					option_table = CREATE(Option_table)();
					Option_table_add_help(option_table,
				"The mean_filter field uses the itk::MeanImageFilter code to replace each pixel with the mean intensity of the pixel and its surrounding neighbours.  It is useful for reducing the level of noise.   The <field> it operates on is usually a sample_texture field, based on a texture that has been created from image file(s).   The size of the neighbourhood of pixels used to calculate the mean is determined be a list of <radius_sizes>, one value for each dimension.  Each radius size sets how many pixels to include either side of the central pixel for the corresponding dimension. If radius values are increased, more neighbouring pixels are included and the image becomes smoother. 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_has_numerical_components;
					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_sizes */
					Option_table_add_int_vector_entry(option_table,
						"radius_sizes", radius_sizes, &dimension);
					return_code = Option_table_multi_parse(option_table, state);
					DESTROY(Option_table)(&option_table);
			}
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
			if (radius_sizes)
			{
				DEALLOCATE(radius_sizes);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_mean_image_filter.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_mean_image_filter */
int define_Computed_field_type_gradient(struct Parse_state *state,
	void *field_modify_void,void *computed_field_derivatives_package_void)
/*******************************************************************************
LAST MODIFIED : 24 August 2006

DESCRIPTION :
Converts <field> into type 'gradient', if not already, and allows its contents
to be modified.
==============================================================================*/
{
	int return_code;
	struct Computed_field *coordinate_field,*source_field;
	Computed_field_modify_data *field_modify;
	struct Option_table *option_table;
	struct Set_Computed_field_conditional_data set_coordinate_field_data,
		set_source_field_data;

	ENTER(define_Computed_field_type_gradient);
	USE_PARAMETER(computed_field_derivatives_package_void);
	if (state&&(field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code=1;
		/* get valid parameters for projection field */
		coordinate_field=(struct Computed_field *)NULL;
		source_field=(struct Computed_field *)NULL;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_gradient_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code = Computed_field_get_type_gradient(field_modify->get_field(),
				&source_field, &coordinate_field);
		}
		if (return_code)
		{
			/* must access objects for set functions */
			if (coordinate_field)
			{
				ACCESS(Computed_field)(coordinate_field);
			}
			if (source_field)
			{
				ACCESS(Computed_field)(source_field);
			}

			option_table = CREATE(Option_table)();
			Option_table_add_help(option_table,
				"The gradient field calculates the partial derivatives of each of the "
				"source field components with respect to each of the coordinate field components.  "
				"The first values are each of the source field components with respect to the first "
				"coordinate component and then each of the source field components wrt to the second "
				"coordinate component and so on.  "
				"This field can now be used at both element_xi and nodal locations.  At element_xi "
				"locations the basis function supplied xi derivative is multiplied by the basis function "
				"coordinate field jacobian.  For nodal locations a finite difference approximation is "
				"calculated by perturbing each of the coordinate field values and reevaluating the source field.  "
				"See a/graph_axes for an example of using the gradient field to calculate the number of pixels "
				"per ndc coordinate.");

			/* coordinate */
			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=(void *)NULL;
			Option_table_add_entry(option_table,"coordinate",&coordinate_field,
				(void *)&set_coordinate_field_data,set_Computed_field_conditional);
			/* field */
			set_source_field_data.computed_field_manager=
				field_modify->get_field_manager();
			set_source_field_data.conditional_function=
				Computed_field_has_numerical_components;
			set_source_field_data.conditional_function_user_data=(void *)NULL;
			Option_table_add_entry(option_table,"field",&source_field,
				(void *)&set_source_field_data,set_Computed_field_conditional);
			return_code = Option_table_multi_parse(option_table,state);
			DESTROY(Option_table)(&option_table);
			/* no errors,not asking for help */
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					Computed_field_create_gradient(field_modify->get_field_module(),
						source_field, coordinate_field));
			}
			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_gradient.  Failed");
				}
			}
			if (coordinate_field)
			{
				DEACCESS(Computed_field)(&coordinate_field);
			}
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_gradient.  Invalid argument(s)");
		return_code=0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_gradient */
예제 #7
0
파일: glyph_app.cpp 프로젝트: alan-wu/cmgui
/**
 * Executes a GFX DEFINE GLYPH command.
 */
int gfx_define_glyph(struct Parse_state *state,
	void *glyph_name_void, void *define_glyph_data_void)
{
	int return_code = 1;
	Define_glyph_data *define_glyph_data = static_cast<Define_glyph_data *>(define_glyph_data_void);
	if ((state) && (define_glyph_data))
	{
		if (state->current_token)
		{
			const char *glyph_name = static_cast<char *>(glyph_name_void);
			bool process = false;
			if (glyph_name)
			{
				process = true;
			}
			else
			{
				if (Parse_state_help_mode(state))
				{
					glyph_name = "GLYPH_NAME";
					Option_table *option_table = CREATE(Option_table)();
					Option_table_add_entry(option_table, "GLYPH_NAME",
						(void *)glyph_name, define_glyph_data_void, gfx_define_glyph);
					return_code = Option_table_parse(option_table, state);
					DESTROY(Option_table)(&option_table);
				}
				else
				{
					glyph_name = state->current_token;
					shift_Parse_state(state, 1);
					process = true;
				}
			}
			if (process)
			{
				char *scene_path_name = 0;
				struct Option_table *option_table = CREATE(Option_table)();
				Option_table_add_help(option_table,
					"The 'scene' option defines a static glyph from the named graphics "
					"at the region/scene path.");
				/* scene (graphics) */
				Option_table_add_string_entry(option_table, "scene",
					&scene_path_name, " [/REGION_PATH.]GRAPHICS_NAME");

				return_code = Option_table_multi_parse(option_table, state);
				if (return_code)
				{
					cmzn_graphics* graphics = 0;
					const char *scene_name = 0;
					const char *graphics_name = 0;
					if (scene_path_name)
						export_object_name_parser(scene_path_name, &scene_name, &graphics_name);
					cmzn_region *input_region =
						cmzn_region_find_subregion_at_path(define_glyph_data->root_region, scene_name);
					if (input_region && graphics_name)
					{
						cmzn_scene_id scene = cmzn_region_get_scene(input_region);
						graphics = cmzn_scene_find_graphics_by_name(scene, graphics_name);
						cmzn_scene_destroy(&scene);
					}
					if (!graphics)
					{
						display_message(ERROR_MESSAGE,
							"gfx_define_glyph.  Invalid scene region path or graphics name");
						return_code = 0;
					}
					else
					{
						cmzn_glyphmodule_begin_change(define_glyph_data->glyphmodule);
						cmzn_glyph_id glyph = cmzn_glyphmodule_find_glyph_by_name(define_glyph_data->glyphmodule, glyph_name);
						if (glyph)
						{
							struct GT_object *graphics_object = cmzn_graphics_copy_graphics_object(
								graphics);
							if (!cmzn_glyph_set_graphics_object(glyph, graphics_object))
							{
								display_message(ERROR_MESSAGE, "gfx_define_glyph.  Unable to change glyph");
								return_code = 0;
							}
							DEACCESS(GT_object)(&graphics_object);
						}
						else
						{
							glyph = cmzn_glyphmodule_create_static_glyph_from_graphics(define_glyph_data->glyphmodule,
								graphics);
							if ((CMZN_OK != cmzn_glyph_set_name(glyph, glyph_name)) ||
								(CMZN_OK != cmzn_glyph_set_managed(glyph, true)))
							{
								display_message(ERROR_MESSAGE, "gfx_define_glyph.  Failed");
								return_code = 0;
							}
						}
						cmzn_glyph_destroy(&glyph);
						cmzn_glyphmodule_end_change(define_glyph_data->glyphmodule);
					}
					cmzn_graphics_destroy(&graphics);
					cmzn_region_destroy(&input_region);
					if (scene_name)
						DEALLOCATE(scene_name);
					if (graphics_name)
						DEALLOCATE(graphics_name);
				}
				if (scene_path_name)
					DEALLOCATE(scene_path_name);
				DESTROY(Option_table)(&option_table);
			}
		}
		else
		{
			display_message(ERROR_MESSAGE, "Missing glyph name");
			display_parse_state_location(state);
			return_code=0;
		}
	}
	else
	{
		display_message(ERROR_MESSAGE, "gfx_define_glyph.  Invalid argument(s)");
		return_code = 0;
	}
	return (return_code);
}
int define_Computed_field_type_histogram_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 i, original_number_of_components, previous_state_index, return_code;
	int *numberOfBins;
	double marginalScale, *histogramMinimum, *histogramMaximum;
	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_histogram_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;
		numberOfBins = (int *)NULL;
		histogramMinimum = (double *)NULL;
		histogramMaximum = (double *)NULL;
		marginalScale = 10.0;
		original_number_of_components = 0;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_histogram_image_filter_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code =
				Cmiss_field_get_type_histogram_image_filter(field_modify->get_field(), &source_field,
					&numberOfBins, &marginalScale, &histogramMinimum, &histogramMaximum);
			original_number_of_components = source_field->number_of_components;
		}
		if (return_code)
		{
			/* must access objects for set functions */
			if (source_field)
			{
				ACCESS(Computed_field)(source_field);
			}

			if (state->current_token &&
				(!(strcmp(PARSER_HELP_STRING, state->current_token)&&
					strcmp(PARSER_RECURSIVE_HELP_STRING, state->current_token))))
			{
				/* Handle help separately */
				option_table = CREATE(Option_table)();
				Option_table_add_help(option_table,
					"The histogram_filter field uses the itk::ImageToHistogramGenerator code to generate binned values representing the relative frequency of the various pixel intensities.  There should be a number_of_bins for each component direction, and so the total number of bins will be a product of these, so that for a 3 component image you would get a volume histogram.  "
						"If you wanted a histogram for a single component then set the number_of_bins for the other components to 1. "
						"If you do not set the optional histogram_minimums or histogram_maximums (which is a vector of values, 1 for each source component) then the histogram will automatically range the values to the minimum and maximum values in the source image.");

				/* field */
				set_source_field_data.computed_field_manager =
					field_modify->get_field_manager();
				set_source_field_data.conditional_function = Computed_field_has_numerical_components;
				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);
				/* histogramMinimum */
				double dummyHistogramMinimum = 0.0;
				Option_table_add_double_entry(option_table, "histogram_minimums",
					&dummyHistogramMinimum);
				/* histogramMinimum */
				double dummyHistogramMaximum = 1.0;
				Option_table_add_double_entry(option_table, "histogram_maximums",
					&dummyHistogramMaximum);
				/* numberOfBins */
				int dummyNumberOfBins = 64;
				Option_table_add_int_positive_entry(option_table, "number_of_bins",
					&dummyNumberOfBins);
				/* marginalScale */
				Option_table_add_double_entry(option_table, "marginal_scale",
					&marginalScale);

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

			if (return_code)
			{
				// store previous state so that we can return to it
				previous_state_index = state->current_index;

				/* parse the source field so we know the dimension. */

				option_table = CREATE(Option_table)();
				/* field */
				set_source_field_data.computed_field_manager =
					field_modify->get_field_manager();
				set_source_field_data.conditional_function = Computed_field_has_numerical_components;
				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);

				/* Ignore all the other entries */
				Option_table_ignore_all_unmatched_entries(option_table);
				return_code = Option_table_multi_parse(option_table, state);
				DESTROY(Option_table)(&option_table);

				/* Return back to where we were */
				shift_Parse_state(state, previous_state_index - state->current_index);
				if (!source_field)
				{
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_histogram_image_filter.  "
						"Missing source field");
					return_code = 0;
				}
			}
			if (return_code)
			{
				if (source_field->number_of_components != original_number_of_components)
				{
					REALLOCATE(numberOfBins, numberOfBins, int,
						source_field->number_of_components);
					for (i = 0 ; i < source_field->number_of_components ; i++)
					{
						numberOfBins[i] = 64;
					}
				}

				option_table = CREATE(Option_table)();

				/* field, ignore as we have already got it */
				int field_expected_parameters = 1;
				Option_table_add_ignore_token_entry(
					option_table, "field", &field_expected_parameters);
				/* histogramMinimum */
				int histogramMinimumLength = 0;
				if (histogramMinimum)
					histogramMinimumLength = original_number_of_components;
				Option_table_add_variable_length_double_vector_entry(option_table, "histogram_minimums",
					&histogramMinimumLength, &histogramMinimum);
				/* histogramMaximum */
				int histogramMaximumLength = 0;
				if (histogramMaximum)
					histogramMaximumLength = original_number_of_components;
				Option_table_add_variable_length_double_vector_entry(option_table, "histogram_maximums",
					&histogramMaximumLength, &histogramMaximum);
				/* numberOfBins */
				Option_table_add_int_vector_entry(option_table, "number_of_bins",
					numberOfBins, &source_field->number_of_components);
				/* marginalScale */
				Option_table_add_double_entry(option_table, "marginal_scale",
					&marginalScale);

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

				if (histogramMinimum && histogramMinimumLength != source_field->number_of_components)
				{
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_histogram_image_filter.  Length of histogram_minimums vector does not match source field compontents");
					return_code = 0;
				}
				if (histogramMaximum && histogramMaximumLength != source_field->number_of_components)
				{
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_histogram_image_filter.  Length of histogram_Maximums vector does not match source field compontents");
					return_code = 0;
				}

				if (return_code)
				{
					return_code = field_modify->update_field_and_deaccess(
						Cmiss_field_module_create_histogram_image_filter(
							field_modify->get_field_module(),
							source_field, numberOfBins, marginalScale, histogramMinimum, histogramMaximum));
				}

				if (!return_code)
				{
					/* error */
					display_message(ERROR_MESSAGE,
						"define_Computed_field_type_histogram_image_filter.  Failed");
				}
			}
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
			if (numberOfBins)
			{
				DEALLOCATE(numberOfBins);
			}
		}
예제 #9
0
int define_Computed_field_type_compose(struct Parse_state *state,
	void *field_modify_void, void *computed_field_compose_package_void)
/*******************************************************************************
LAST MODIFIED : 24 August 2006

DESCRIPTION :
Converts <field> into type COMPUTED_FIELD_COMPOSE (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int return_code;
	Computed_field_compose_package *computed_field_compose_package;
	Computed_field_modify_data *field_modify;
	struct Option_table *find_option_table, *option_table,
		*out_of_bounds_option_table;
	struct Set_Computed_field_conditional_data set_calculate_values_field_data,
		set_find_element_xi_field_data, set_texture_coordinates_field_data;

	ENTER(define_Computed_field_type_compose);
	if (state && (field_modify=(Computed_field_modify_data *)field_modify_void) &&
		(computed_field_compose_package =
			(Computed_field_compose_package *)
			computed_field_compose_package_void))
	{
		return_code = 1;
		Cmiss_mesh_id mesh = 0;
		char *search_group_name = 0;
		Cmiss_field_id calculate_values_field = 0;
		Cmiss_field_id find_element_xi_field = 0;
		Cmiss_field_id texture_coordinates_field = 0;
		char find_nearest_flag = 0;
		char find_exact_flag = 0;
		char use_point_five_when_out_of_bounds_flag = 0;
		char fail_when_out_of_bounds_flag = 0;
		int use_point_five_when_out_of_bounds = 0;
		int element_dimension = 0;
		/* Maintain the existing behaviour as the default */
		int find_nearest = 0;
		/* get valid parameters for composite field */
		if (field_modify->get_field())
		{
			Computed_field_compose* compose_core =
				dynamic_cast<Computed_field_compose*>(field_modify->get_field()->core);
			if (compose_core)
			{
				return_code = compose_core->get_type(
					&calculate_values_field, &find_element_xi_field,
					&texture_coordinates_field, &mesh,
					&find_nearest, &use_point_five_when_out_of_bounds);
				if (mesh)
				{
					Cmiss_mesh_access(mesh);
					element_dimension = Cmiss_mesh_get_dimension(mesh);
				}
			}
		}
		if (return_code)
		{
			/* must access objects for set functions */
			if (calculate_values_field)
			{
				ACCESS(Computed_field)(calculate_values_field);
			}
			if (find_element_xi_field)
			{
				ACCESS(Computed_field)(find_element_xi_field);
			}
			if (texture_coordinates_field)
			{
				ACCESS(Computed_field)(texture_coordinates_field);
			}

			option_table = CREATE(Option_table)();
			Option_table_add_help(option_table,
				"The value of a compose field is found by evaluating the <texture_coordinates_field>, "
				"then searching for matching values of the <find_element_xi_field> in the elements of "
				"the <mesh> (alternatively specified by <group> and <element_dimension>) and then "
				"finally evaluating the <calculate_values_field> at this found location.  You can "
				"specify the outcome if the matching values cannot be found in the mesh with "
				"<use_point_five_when_out_of_bounds> or <fail_when_out_of_bounds>.  See examples "
				"a/resample_texture or a/create_slices where the compose field is used to find the "
				"equivalent coordinate in another element to evaluate a texture.");
			/* calculate_values_field */
			set_calculate_values_field_data.computed_field_manager =
				field_modify->get_field_manager();
			set_calculate_values_field_data.conditional_function =
				Computed_field_has_numerical_components;
			set_calculate_values_field_data.conditional_function_user_data =
				(void *)NULL;
			Option_table_add_entry(option_table, "calculate_values_field",
				&calculate_values_field, &set_calculate_values_field_data,
				set_Computed_field_conditional);
			Option_table_add_int_positive_entry(option_table,"element_dimension",
				&element_dimension);
			/* find_element_xi_field */
			set_find_element_xi_field_data.computed_field_manager =
				field_modify->get_field_manager();
			set_find_element_xi_field_data.conditional_function =
				Computed_field_has_numerical_components;
			set_find_element_xi_field_data.conditional_function_user_data =
				(void *)NULL;
			Option_table_add_entry(option_table, "find_element_xi_field",
				&find_element_xi_field, &set_find_element_xi_field_data,
				set_Computed_field_conditional);
			find_option_table=CREATE(Option_table)();
			Option_table_add_char_flag_entry(find_option_table,"find_nearest",
				&find_nearest_flag);
			Option_table_add_char_flag_entry(find_option_table,"find_exact",
				&find_exact_flag);
			Option_table_add_suboption_table(option_table, find_option_table);
			/* group */
			Option_table_add_string_entry(option_table, "group",
				 &search_group_name, " GROUP_NAME");
			// mesh
			Option_table_add_mesh_entry(option_table, "mesh", field_modify->get_region(), &mesh);
			/* texture_coordinates_field */
			set_texture_coordinates_field_data.computed_field_manager =
				field_modify->get_field_manager();
			set_texture_coordinates_field_data.conditional_function =
				Computed_field_has_numerical_components;
			set_texture_coordinates_field_data.conditional_function_user_data =
				(void *)NULL;
			Option_table_add_entry(option_table, "texture_coordinates_field",
				&texture_coordinates_field, &set_texture_coordinates_field_data,
				set_Computed_field_conditional);
			out_of_bounds_option_table=CREATE(Option_table)();
			/* use_point_five_when_out_of_bounds */
			Option_table_add_char_flag_entry(out_of_bounds_option_table,
				"use_point_five_when_out_of_bounds",
				&use_point_five_when_out_of_bounds_flag);
			Option_table_add_char_flag_entry(out_of_bounds_option_table,
				"fail_when_out_of_bounds",
				&fail_when_out_of_bounds_flag);
			Option_table_add_suboption_table(option_table, out_of_bounds_option_table);
			return_code = Option_table_multi_parse(option_table, state);

			if (return_code && !mesh)
			{
				mesh = Cmiss_field_module_find_mesh_by_dimension(
					field_modify->get_field_module(), element_dimension);
				if (search_group_name)
				{
					Cmiss_field_id group_field = Cmiss_field_module_find_field_by_name(field_modify->get_field_module(), search_group_name);
					Cmiss_field_group_id group = Cmiss_field_cast_group(group_field);
					Cmiss_field_element_group_id element_group = Cmiss_field_group_get_element_group(group, mesh);
					Cmiss_mesh_destroy(&mesh);
					mesh = Cmiss_mesh_group_base_cast(Cmiss_field_element_group_get_mesh(element_group));
					Cmiss_field_element_group_destroy(&element_group);
					Cmiss_field_group_destroy(&group);
					Cmiss_field_destroy(&group_field);
				}
			}
			if (return_code && !mesh)
			{
				display_message(ERROR_MESSAGE, "You must specify a mesh (or element_dimension and optional group).");
				return_code = 0;
			}
			if (return_code)
			{
				if (find_nearest_flag && find_exact_flag)
				{
					display_message(ERROR_MESSAGE,
						"Specify only one of find_nearest and find_exact");
					return_code = 0;
				}
				if (find_nearest_flag)
				{
					find_nearest = 1;
				}
				else if (find_exact_flag)
				{
					find_nearest = 0;
				}
				if (use_point_five_when_out_of_bounds_flag &&
					fail_when_out_of_bounds_flag)
				{
					display_message(ERROR_MESSAGE,
						"Specify only one of use_point_five_when_out_of_bounds "
						"and fail_when_out_of_bounds");
					return_code = 0;
				}
				if (use_point_five_when_out_of_bounds_flag)
				{
					use_point_five_when_out_of_bounds = 1;
				}
				else if (fail_when_out_of_bounds_flag)
				{
					use_point_five_when_out_of_bounds = 0;
				}
			}
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					Computed_field_create_compose(field_modify->get_field_module(),
						texture_coordinates_field, find_element_xi_field,
						calculate_values_field, mesh,
						find_nearest, use_point_five_when_out_of_bounds));
			}
			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_compose.  Failed");
				}
			}
			Cmiss_mesh_destroy(&mesh);
			if (calculate_values_field)
			{
				DEACCESS(Computed_field)(&calculate_values_field);
			}
			if (find_element_xi_field)
			{
				DEACCESS(Computed_field)(&find_element_xi_field);
			}
			if (search_group_name)
			{
				DEALLOCATE(search_group_name);
			}
			if (texture_coordinates_field)
			{
				DEACCESS(Computed_field)(&texture_coordinates_field);
			}
			DESTROY(Option_table)(&option_table);
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_compose.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_compose */
예제 #10
0
int define_Computed_field_type_quaternion_SLERP(struct Parse_state *state,
	void *field_modify_void, void *computed_field_lookup_package_void)
/*******************************************************************************
LAST MODIFIED : 25 August 2006

DESCRIPTION :
Converts <field> into type 'quaterions' (if it is not already) and allows its
contents to be modified.
==============================================================================*/
{
	int return_code;
	Computed_field_lookup_package *computed_field_lookup_package;
	Computed_field_modify_data *field_modify;

	ENTER(define_Computed_field_type_quaternion_SLERP);
	if (state&&(field_modify=(Computed_field_modify_data *)field_modify_void) &&
		 (computed_field_lookup_package=
				(Computed_field_lookup_package *)
				computed_field_lookup_package_void))
	{
		return_code = 1;
		Cmiss_field_id source_field = 0;
		char *nodeset_name = duplicate_string("cmiss_nodes");
		char node_flag = 0;
		int node_identifier = 0;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_quaternion_SLERP_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			Cmiss_node_id lookup_node = 0;
			return_code = Computed_field_get_type_quaternion_SLERP(field_modify->get_field(),
				 &source_field, &lookup_node);
			if (source_field)
			{
				 ACCESS(Computed_field)(source_field);
			}
			if (lookup_node)
			{
				node_identifier = get_FE_node_identifier(lookup_node);
				FE_region *fe_region = FE_node_get_FE_region(lookup_node);
				if (!FE_region_contains_FE_node(fe_region, lookup_node))
				{
					DEALLOCATE(nodeset_name);
					nodeset_name = duplicate_string("cmiss_data");
				}
				node_flag = 1;
			}
		}

		Option_table *option_table = CREATE(Option_table)();
		Option_table_add_help(option_table,
			 "A 4 components quaternion field. The components of "
			 "the quaternion field are expected to be the w, x, y, z components"
			 "of a quaternion (4 components in total). The quaternion field  is"
			 "evaluated and interpolated using SLERP at a normalised time between two"
			 "quaternions (read in from the exnode generally). This quaternion field"
			 "can be convert to a matrix with quaternion_to_matrix field, the resulting"
			 "matrix can be used to create a smooth time dependent rotation for an object"
			 "using the quaternion_to_matrix field. This field must be define directly from"
			 "exnode file or from a matrix_to_quaternion field");
		Set_Computed_field_conditional_data set_source_field_data;
		set_source_field_data.computed_field_manager = field_modify->get_field_manager();
		set_source_field_data.conditional_function = Computed_field_has_4_components;
		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);
		/* identifier of the node to lookup */
		Option_table_add_entry(option_table, "node", &node_identifier,
			&node_flag, set_int_and_char_flag);
		/* the nodeset the node is from */
		Option_table_add_string_entry(option_table, "nodeset", &nodeset_name,
			" NODE_GROUP_FIELD_NAME|[GROUP_NAME.]cmiss_nodes|cmiss_data[cmiss_nodes]");
		return_code = Option_table_multi_parse(option_table, state);
		DESTROY(Option_table)(&option_table);

		if (return_code && node_flag)
		{
			Cmiss_nodeset_id nodeset = Cmiss_field_module_find_nodeset_by_name(field_modify->get_field_module(), nodeset_name);
			Cmiss_node_id node = Cmiss_nodeset_find_node_by_identifier(nodeset, node_identifier);
			if (node)
			{
				return_code = field_modify->update_field_and_deaccess(
					Computed_field_create_quaternion_SLERP(field_modify->get_field_module(),
						source_field, node));
			}
			else
			{
				display_message(ERROR_MESSAGE,
					"define field quaternion_SLERP.  Invalid node %d", node_identifier);
				return_code = 0;
			}
			Cmiss_node_destroy(&node);
			Cmiss_nodeset_destroy(&nodeset);
		}
		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_quaternion_SLERP.  Failed");
			}
		}
		DEALLOCATE(nodeset_name);
		REACCESS(Computed_field)(&source_field, NULL);
	}
	else
	{
		 display_message(ERROR_MESSAGE,
				"define_Computed_field_type_quaternion_SLERP.  Invalid argument(s)");
		 return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_quaternion_SLERP */
예제 #11
0
int define_Computed_field_type_nodal_lookup(struct Parse_state *state,
	void *field_modify_void, void *computed_field_lookup_package_void)
/*******************************************************************************
LAST MODIFIED : 25 August 2006

DESCRIPTION :
Converts <field> into type COMPUTED_FIELD_NODAL_LOOKUP (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int return_code;
	Computed_field_lookup_package *computed_field_lookup_package;
	Computed_field_modify_data *field_modify;

	if (state&&(field_modify=(Computed_field_modify_data *)field_modify_void) &&
		(computed_field_lookup_package=
		(Computed_field_lookup_package *)
		computed_field_lookup_package_void))
	{
		return_code = 1;
		Cmiss_field_id source_field = 0;
		char *nodeset_name = duplicate_string("cmiss_nodes");
		char node_flag = 0;
		int node_identifier = 0;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_nodal_lookup_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			Cmiss_node_id lookup_node = 0;
			return_code = Computed_field_get_type_nodal_lookup(field_modify->get_field(),
				&source_field, &lookup_node);
			if (source_field)
			{
				 ACCESS(Computed_field)(source_field);
			}
			if (lookup_node)
			{
				node_identifier = get_FE_node_identifier(lookup_node);
				FE_region *fe_region = FE_node_get_FE_region(lookup_node);
				if (!FE_region_contains_FE_node(fe_region, lookup_node))
				{
					DEALLOCATE(nodeset_name);
					nodeset_name = duplicate_string("cmiss_data");
				}
				node_flag = 1;
			}
		}

		Option_table *option_table = CREATE(Option_table)();
		/* source field */
		Set_Computed_field_conditional_data set_source_field_data;
		set_source_field_data.computed_field_manager = field_modify->get_field_manager();
		set_source_field_data.conditional_function = Computed_field_has_numerical_components;
		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);
		/* the node to nodal_lookup */
		Option_table_add_entry(option_table, "node", &node_identifier,
			&node_flag, set_int_and_char_flag);
		/* the nodeset the node is from */
		Option_table_add_string_entry(option_table, "nodeset", &nodeset_name,
			" NODE_GROUP_FIELD_NAME|[GROUP_NAME.]cmiss_nodes|cmiss_data[cmiss_nodes]");
		return_code = Option_table_multi_parse(option_table,state);
		DESTROY(Option_table)(&option_table);

		if (return_code && node_flag)
		{
			Cmiss_nodeset_id nodeset = Cmiss_field_module_find_nodeset_by_name(field_modify->get_field_module(), nodeset_name);
			Cmiss_node_id node = Cmiss_nodeset_find_node_by_identifier(nodeset, node_identifier);
			if (node)
			{
				return_code = field_modify->update_field_and_deaccess(
					Computed_field_create_nodal_lookup(field_modify->get_field_module(),
						source_field, node));
			}
			else
			{
				display_message(ERROR_MESSAGE,
					"define field nodal lookup.  Invalid node %d", node_identifier);
				return_code = 0;
			}
			Cmiss_node_destroy(&node);
			Cmiss_nodeset_destroy(&nodeset);
		}
		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_time_nodal_lookup.  Failed");
			}
		}
		DEALLOCATE(nodeset_name);
		REACCESS(Computed_field)(&source_field, NULL);
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_nodal_lookup.  Invalid argument(s)");
		return_code = 0;
	}
	return (return_code);
}
int define_Computed_field_type_gradient_magnitude_recursive_gaussian_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 GRADIENT_MAGNITUDE_RECURSIVE_GAUSSIAN (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int return_code;
	double sigma;
	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_gradient_magnitude_recursive_gaussian_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;
		sigma = 2.0;

		if ((NULL != field_modify->get_field()) &&
			(computed_field_gradient_magnitude_recursive_gaussian_image_filter_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code =
				cmzn_field_get_type_gradient_magnitude_recursive_gaussian_image_filter(field_modify->get_field(), &source_field,
					&sigma);
		}
		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 gradient_magnitude_recursive_filter field uses the itk::GradientMagnitudeRecursiveImageFilter code to compute the magnitude of the image gradient at each location in the field. It is useful for identifying regions where the pixel intensities change rapidly.  The <field> it operates on is usually a sample_texture field, based on a texture that has been created from image file(s).  The filter first smooths the image using a discrete gaussian image subfilter before calculating the gradient and magnitudes.  Increasing <sigma> increases the width of the gaussian distribution used during the smoothing and hence the number of pixels used to calculate the weighted average. This smooths the image more.  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);
			/* sigma */
			Option_table_add_double_entry(option_table, "sigma",&sigma);

			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_gradient_magnitude_recursive_gaussian_image_filter.  "
						"Missing source field");
					return_code = 0;
				}
			}
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					cmzn_fieldmodule_create_field_imagefilter_gradient_magnitude_recursive_gaussian(
						field_modify->get_field_module(),
						source_field, sigma));
			}

			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_gradient_magnitude_recursive_gaussian_image_filter.  Failed");
				}
			}
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_gradient_magnitude_recursive_gaussian_image_filter.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_gradient_magnitude_recursive_gaussian_image_filter */
int define_Computed_field_type_if(struct Parse_state *state,
	void *field_modify_void,void *computed_field_conditional_package_void)
/*******************************************************************************
LAST MODIFIED : 27 July 2007

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

	ENTER(define_Computed_field_type_if);
	USE_PARAMETER(computed_field_conditional_package_void);
	if (state && (field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code=1;
		/* get valid parameters for projection field */
		source_fields = (struct Computed_field **)NULL;
		if (ALLOCATE(source_fields, struct Computed_field *, 3))
		{
			source_fields[0] = (struct Computed_field *)NULL;
			source_fields[1] = (struct Computed_field *)NULL;
			source_fields[2] = (struct Computed_field *)NULL;
			if ((NULL != field_modify->get_field()) &&
				(computed_field_if_type_string ==
					Computed_field_get_type_string(field_modify->get_field())))
			{
				return_code=Computed_field_get_type_if(field_modify->get_field(),
					source_fields, source_fields + 1, source_fields + 2);
			}
			if (return_code)
			{
				/* must access objects for set functions */
				if (source_fields[0])
				{
					ACCESS(Computed_field)(source_fields[0]);
				}
				if (source_fields[1])
				{
					ACCESS(Computed_field)(source_fields[1]);
				}
				if (source_fields[2])
				{
					ACCESS(Computed_field)(source_fields[2]);
				}

				option_table = CREATE(Option_table)();
				Option_table_add_help(option_table,
					"The if field uses three input fields.  "
					"The first field is evaluated and for each component "
					"if the value of the component is not zero (== true) then "
					"the value for that component is copied from the second field.  "
					"Otherwise (the first field value was zero == false) "
					"the value for that component is copied from the third field");

				/* fields */
				set_source_field_data.computed_field_manager=
					field_modify->get_field_manager();
				set_source_field_data.conditional_function=
		  Computed_field_has_numerical_components;
				set_source_field_data.conditional_function_user_data=(void *)NULL;
				set_source_field_array_data.number_of_fields=3;
				set_source_field_array_data.conditional_data= &set_source_field_data;
				Option_table_add_entry(option_table,"fields",source_fields,
					&set_source_field_array_data,set_Computed_field_array);
				return_code=Option_table_multi_parse(option_table,state);
				/* no errors,not asking for help */
				if (return_code)
				{
					return_code = field_modify->update_field_and_deaccess(
						Computed_field_create_if(field_modify->get_field_module(),
							source_fields[0], source_fields[1], source_fields[2]));
				}
				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_if.  Failed");
					}
				}
				if (source_fields[0])
				{
					DEACCESS(Computed_field)(&source_fields[0]);
				}
				if (source_fields[1])
				{
					DEACCESS(Computed_field)(&source_fields[1]);
				}
				if (source_fields[2])
				{
					DEACCESS(Computed_field)(&source_fields[2]);
				}
				DESTROY(Option_table)(&option_table);
			}
			DEALLOCATE(source_fields);
		}
		else
		{
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);
}
예제 #15
0
int gfx_define_font(struct Parse_state *state,
	void *dummy_to_be_modified,void *graphics_module_void)
/*******************************************************************************
LAST MODIFIED : 12 March 2008

DESCRIPTION :
Executes a GFX DEFINE FONT command.
==============================================================================*/
{
	const char *current_token, *font_name;
	int return_code;
	Cmiss_graphics_module_id graphics_module = 0;

	if (state && (graphics_module = (Cmiss_graphics_module_id)graphics_module_void))
	{
		if (NULL != (current_token = state->current_token))
		{
			if (strcmp(PARSER_HELP_STRING,current_token)&&
				strcmp(PARSER_RECURSIVE_HELP_STRING,current_token))
			{
				font_name = current_token;
				if (shift_Parse_state(state,1)&&
					(current_token=state->current_token))
				{
					Cmiss_graphics_font_id font = Cmiss_graphics_module_find_font_by_name(
						graphics_module, font_name);
					if (!font)
					{
						font = Cmiss_graphics_module_create_font(graphics_module);
						Cmiss_graphics_font_set_name(font, font_name);
					}
					Cmiss_graphics_font_type font_type = Cmiss_graphics_font_get_type(font);
					Cmiss_graphics_font_true_type true_type = Cmiss_graphics_font_get_true_type(font);
					char *font_type_string = 0;
					char *true_type_string = 0;
					int number_of_valid_strings_font_type = 0;
					int number_of_valid_strings_true_type = 0;
					const char **valid_font_type_strings = ENUMERATOR_GET_VALID_STRINGS(Cmiss_graphics_font_type)(
						&number_of_valid_strings_font_type,
						(ENUMERATOR_CONDITIONAL_FUNCTION(Cmiss_graphics_font_type) *)NULL,
						(void *)NULL);
					std::string all_font_types = " ";
					for (int i = 0; i < number_of_valid_strings_font_type; i++)
					{
						if (i)
							all_font_types += "|";

						all_font_types += valid_font_type_strings[i];
					}
					const char *all_font_types_help = all_font_types.c_str();
					const char **valid_font_true_type_strings = ENUMERATOR_GET_VALID_STRINGS(Cmiss_graphics_font_true_type)(
						&number_of_valid_strings_true_type,
						(ENUMERATOR_CONDITIONAL_FUNCTION(Cmiss_graphics_font_true_type) *)NULL,
						(void *)NULL);
					std::string all_font_true_types = " ";
					for (int i = 0; i < number_of_valid_strings_true_type; i++)
					{
						if (i)
							all_font_true_types += "|";

						all_font_true_types += valid_font_true_type_strings[i];
					}
					const char *all_font_true_types_help = all_font_true_types.c_str();

					struct Option_table *option_table = CREATE(Option_table)();
					int bold_flag = 0;
					int italic_flag = 0;
					float depth = (float)Cmiss_graphics_font_get_depth(font);
					int size = Cmiss_graphics_font_get_size(font);
					/* bold */
					Option_table_add_entry(option_table, "bold",
						(void *)&bold_flag, NULL, set_char_flag);
					Option_table_add_entry(option_table, "italic",
						(void *)&italic_flag, NULL, set_char_flag);
					Option_table_add_entry(option_table,"depth",
						&(depth),NULL,set_float);
					Option_table_add_entry(option_table,"size",
						&(size),NULL,set_int_non_negative);
					Option_table_add_string_entry(option_table, "font_type",
						&font_type_string, all_font_types_help);
					Option_table_add_string_entry(option_table, "true_type",
						&true_type_string, all_font_true_types_help);
					return_code = Option_table_multi_parse(option_table, state);
					if (return_code)
					{
						if (font_type_string)
						{
							STRING_TO_ENUMERATOR(Cmiss_graphics_font_type)(font_type_string,
								&font_type);
							if (CMISS_GRAPHICS_FONT_TYPE_INVALID == font_type)
							{
								display_message(ERROR_MESSAGE,
									"gfx_define_font:  Invalid font type %s", font_type_string);
								return_code = 0;
							}
						}
						else
						{
							display_message(ERROR_MESSAGE,
								"gfx_define_font:  Missing font_type argument");
							return_code = 0;
						}
						if (true_type_string)
						{
							STRING_TO_ENUMERATOR(Cmiss_graphics_font_true_type)(true_type_string,
								&true_type);
							if (CMISS_GRAPHICS_FONT_TRUE_TYPE_INVALID == true_type)
							{
								display_message(ERROR_MESSAGE,
									"gfx_define_font:  Invalid true type %s", true_type_string);
								return_code = 0;
							}
						}
						else
						{
							display_message(ERROR_MESSAGE,
								"gfx_define_font:  Missing true_type argument");
							return_code = 0;
						}
						if (font)
						{
							Cmiss_graphics_font_set_bold(font, bold_flag);
							Cmiss_graphics_font_set_italic(font, italic_flag);
							Cmiss_graphics_font_set_depth(font, depth);
							Cmiss_graphics_font_set_size(font, size);
							Cmiss_graphics_font_set_true_type(font, true_type);
							Cmiss_graphics_font_set_type(font, font_type);
						}

					}

					Cmiss_graphics_font_destroy(&font);
					DEALLOCATE(font_type_string);
					DEALLOCATE(true_type_string);
					DESTROY(Option_table)(&option_table);
				}
				else
				{
					display_message(WARNING_MESSAGE,"Missing font string.");
					display_parse_state_location(state);
					return_code=0;
				}
			}
예제 #16
0
int gfx_modify_rendition_general(struct Parse_state *state,
	void *cmiss_region_void, void *group_void)
{
	int return_code = 0;

	ENTER(gfx_modify_rendition_general);
	Cmiss_region_id cmiss_region = reinterpret_cast<Cmiss_region_id>(cmiss_region_void);
	Cmiss_field_group_id group = reinterpret_cast<Cmiss_field_group_id>(group_void);
	if (state && cmiss_region)
	{
		/* if possible, get defaults from element_group on default scene */
		Cmiss_rendition_id rendition = Cmiss_region_get_rendition_internal(cmiss_region);
		if (rendition)
		{
			Cmiss_field_id default_coordinate_field = rendition->default_coordinate_field;
			if (default_coordinate_field)
			{
				Cmiss_field_access(default_coordinate_field);
			}
			int clear_flag = 0;

			Option_table *option_table = CREATE(Option_table)();
			Option_table_add_help(option_table,
				"The clear option removes all graphics from the rendition. "
				"Option 'circle_discretization' is deprecated: use circle_discretization option on cylinders instead. "
				"Option 'default_coordinate' is deprecated: use coordinate option on individual graphics instead. "
				"Option 'element_discretization' is deprecated: use tessellation option on individual graphics instead. "
				"Option 'native_discretization' is deprecated: use native_discretization option on individual graphics instead. ");
			/* circle_discretization */
			Option_table_add_entry(option_table, "circle_discretization",
				(void *)&rendition->circle_discretization, (void *)NULL,
				set_Circle_discretization);
			/* clear */
			Option_table_add_entry(option_table, "clear",
				(void *)&clear_flag, NULL, set_char_flag);
			/* default_coordinate */
			Set_Computed_field_conditional_data set_coordinate_field_data;
			set_coordinate_field_data.computed_field_manager=
				Cmiss_region_get_Computed_field_manager(cmiss_region);
			set_coordinate_field_data.conditional_function=
				Computed_field_has_up_to_3_numerical_components;
			set_coordinate_field_data.conditional_function_user_data=(void *)NULL;
			Option_table_add_entry(option_table, "default_coordinate",
				(void *)&default_coordinate_field, (void *)&set_coordinate_field_data,
				set_Computed_field_conditional);
			/* element_discretization */
			Option_table_add_divisions_entry(option_table, "element_discretization",
				&(rendition->element_divisions), &(rendition->element_divisions_size));
			/* native_discretization */
			Set_FE_field_conditional_FE_region_data native_discretization_field_conditional_data;
			native_discretization_field_conditional_data.conditional_function =
				(LIST_CONDITIONAL_FUNCTION(FE_field) *)NULL;
			native_discretization_field_conditional_data.user_data = (void *)NULL;
			native_discretization_field_conditional_data.fe_region =
				Cmiss_region_get_FE_region(cmiss_region);
			Option_table_add_entry(option_table, "native_discretization",
				(void *)&rendition->native_discretization_field,
				(void *)&native_discretization_field_conditional_data,
				set_FE_field_conditional_FE_region);
			return_code = Option_table_multi_parse(option_table, state);
			DESTROY(Option_table)(&option_table);
			if (return_code)
			{
				if (clear_flag)
				{
					if (group)
					{
						// remove only graphics using group as subgroup field
						Cmiss_rendition_begin_change(rendition);
						Cmiss_field_id group_field = Cmiss_field_group_base_cast(group);
						// support legacy command files by changing visibility of each graphic using group as its subgroup field
						Cmiss_graphic_id graphic = Cmiss_rendition_get_first_graphic(rendition);
						while (graphic)
						{
							Cmiss_graphic_id this_graphic = graphic;
							graphic = Cmiss_rendition_get_next_graphic(rendition, this_graphic);
							Cmiss_field_id subgroup_field = 0;
							Cmiss_graphic_get_subgroup_field(this_graphic, &subgroup_field);
							if (subgroup_field == group_field)
							{
								Cmiss_rendition_remove_graphic(rendition, this_graphic);
							}
							Cmiss_graphic_destroy(&this_graphic);
						}
						Cmiss_rendition_end_change(rendition);
					}
					else
					{
						return_code = Cmiss_rendition_remove_all_graphics(rendition);
					}
				}
				if (default_coordinate_field)
				{
					if (rendition->default_coordinate_field && default_coordinate_field &&
						(rendition->default_coordinate_field != default_coordinate_field))
					{
						display_message(WARNING_MESSAGE,
							"Change of default_coordinate field can have unexpected results. "
							"Please specify coordinate field for each graphic instead.");
						display_parse_state_location(state);
					}
					Cmiss_rendition_set_default_coordinate_field(rendition, default_coordinate_field);
				}
			}
			if (default_coordinate_field)
			{
				DEACCESS(Computed_field)(&default_coordinate_field);
			}
			Cmiss_rendition_destroy(&rendition);
		}
		else
		{
int define_Computed_field_type_divergence(struct Parse_state *state,
	void *field_modify_void,void *computed_field_derivatives_package_void)
/*******************************************************************************
LAST MODIFIED : 24 August 2006

DESCRIPTION :
Converts <field> into type COMPUTED_FIELD_DIVERGENCE (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int return_code;
	struct Computed_field *coordinate_field,*vector_field;
	Computed_field_modify_data *field_modify;
	struct Option_table *option_table;
	struct Set_Computed_field_conditional_data set_coordinate_field_data,
		set_vector_field_data;

	ENTER(define_Computed_field_type_divergence);
	USE_PARAMETER(computed_field_derivatives_package_void);
	if (state&&(field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code=1;
		/* get valid parameters for projection field */
		coordinate_field=(struct Computed_field *)NULL;
		vector_field=(struct Computed_field *)NULL;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_divergence_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code=Computed_field_get_type_divergence(field_modify->get_field(),
				&vector_field,&coordinate_field);
		}
		if (return_code)
		{
			/* must access objects for set functions */
			if (coordinate_field)
			{
				ACCESS(Computed_field)(coordinate_field);
			}
			if (vector_field)
			{
				ACCESS(Computed_field)(vector_field);
			}

			option_table = CREATE(Option_table)();
			/* coordinate */
			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=(void *)NULL;
			Option_table_add_entry(option_table,"coordinate",&coordinate_field,
				(void *)&set_coordinate_field_data,set_Computed_field_conditional);
			/* vector */
			set_vector_field_data.computed_field_manager=
				field_modify->get_field_manager();
			set_vector_field_data.conditional_function=
				Computed_field_has_up_to_3_numerical_components;
			set_vector_field_data.conditional_function_user_data=(void *)NULL;
			Option_table_add_entry(option_table,"vector",&vector_field,
				(void *)&set_vector_field_data,set_Computed_field_conditional);
			return_code=Option_table_multi_parse(option_table,state);
			DESTROY(Option_table)(&option_table);
			/* no errors,not asking for help */
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					Computed_field_create_divergence(field_modify->get_field_module(),
						vector_field, coordinate_field));
			}
			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_divergence.  Failed");
				}
			}
			if (coordinate_field)
			{
				DEACCESS(Computed_field)(&coordinate_field);
			}
			if (vector_field)
			{
				DEACCESS(Computed_field)(&vector_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_divergence.  Invalid argument(s)");
		return_code=0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_divergence */
int define_Computed_field_type_fast_marching_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_FAST_MARCHING_IMAGE_FILTER (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	double stopping_value;
	int num_seed_points;
	int dimension;
	double *seed_points;
	double *seed_values;
	int *output_size;
	int length_seed_points;
	int return_code;
	int previous_state_index;
	int i;

	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_fast_marching_image_filter);
	USE_PARAMETER(computed_field_simple_package_void);
	if (state && (field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code = 1;

		source_field = (struct Computed_field *)NULL;
		stopping_value = 100;
		num_seed_points = 1;
		dimension  = 2;
		length_seed_points = num_seed_points * dimension;

		seed_points = (double *)NULL;
		seed_values = (double *)NULL;
		output_size = (int *)NULL;

		ALLOCATE(seed_points, double, length_seed_points);
		ALLOCATE(seed_values, double, num_seed_points);
		ALLOCATE(output_size, int, dimension);

		// should probably default to having 1 seed
		seed_points[0] = 0.5;  // pjb: is this ok?
		seed_points[1] = 0.5;
		seed_values[0] = 0.0;
		output_size[0] = 128;
		output_size[1] = 128;

		/* get valid parameters for projection field */
		if ((NULL != field_modify->get_field()) &&
			(computed_field_fast_marching_image_filter_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code =
				cmzn_field_get_type_fast_marching_image_filter(field_modify->get_field(), &source_field,
				  &stopping_value, &num_seed_points, &dimension, &seed_points, &seed_values, &output_size);
		}
		if (return_code)
		{

			if (source_field)
			{
				ACCESS(Computed_field)(source_field);
			}

			if (state->current_token &&
				(!(strcmp(PARSER_HELP_STRING, state->current_token)&&
					strcmp(PARSER_RECURSIVE_HELP_STRING, state->current_token))))
			{
				/* Handle help separately */
				option_table = CREATE(Option_table)();
				Option_table_add_help(option_table,
					"The fast_marching_filter field uses the itk::FastMarchingImageFilter code to segment a field. The segmentation is based on a level set algorithm.  The <field> it operates on is used as a speed term, to govern where the level set curve grows quickly.  The speed term is usually some function (eg a sigmoid) of an image gradient field.  The output field is a time crossing map, where the value at is each pixel is the time take to reach that location from the specified seed points.  Values typically range from 0 through to extremely large (10 to the 38).  To convert the time cross map into a segmented region use a binary threshold filter. To specify the seed points first set the <num_seed_points> and the <dimension> of the image.  The <seed_points> are a list of the coordinates for the first and any subsequent seed points.   It is also possible to specify non-zero initial <seed_values> if desired and to set the <output_size> of the time crossing map. See a/segmentation 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);
				/* stopping_value */
				Option_table_add_double_entry(option_table, "stopping_value",
																			&stopping_value);
				/* num_seed_points */
				Option_table_add_int_positive_entry(option_table, "num_seed_points",
																						&num_seed_points);
				/* dimension */
				Option_table_add_int_positive_entry(option_table, "dimension",
																						&dimension);
				/* seed_points */
				Option_table_add_double_vector_entry(option_table, "seed_points",
																						 seed_points, &length_seed_points);
				/* seed_values */
				Option_table_add_double_vector_entry(option_table, "seed_values",
																						 seed_values, &num_seed_points);
				/* output_size */
				Option_table_add_int_vector_entry(option_table, "output_size",
																						 output_size, &dimension);

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

			if (return_code)
			{

				// store previous state so that we can return to it
				previous_state_index = state->current_index;

				/* parse the two options which determine the number of seed values
					 and hence the size of the array that must be created to read in
					 the number of seed values. */

				option_table = CREATE(Option_table)();
				/* num_seed_points */
				Option_table_add_int_positive_entry(option_table, "num_seed_points",
																						&num_seed_points);
				/* dimension */
				Option_table_add_int_positive_entry(option_table, "dimension",
																						&dimension);
				/* Ignore all the other entries */
				Option_table_ignore_all_unmatched_entries(option_table);
				return_code = Option_table_multi_parse(option_table, state);
				DESTROY(Option_table)(&option_table);

				/* Return back to where we were */
				shift_Parse_state(state, previous_state_index - state->current_index);

			}

			/* parse the rest of the table */
			if (return_code)
			{
				length_seed_points = num_seed_points * dimension;

				/* reallocate memory for arrays */
				REALLOCATE(seed_points, seed_points, double, length_seed_points);
				REALLOCATE(seed_values, seed_values, double, num_seed_points);
				REALLOCATE(output_size, output_size, int, dimension);

				/* set default values, in case options are not specified in field definition. */
				for (i=0; i < length_seed_points ;i++) {
					seed_points[i] = 0;
				}
				for (i=0; i < num_seed_points ;i++) {
					seed_values[i] = 0;
				}
				for (i=0; i < dimension ;i++) {
					output_size[i] = 128;
				}

				option_table = CREATE(Option_table)();
				/* 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);
				/* stopping_value */
				Option_table_add_double_entry(option_table, "stopping_value",
					&stopping_value);
				int num_seed_points_expected_parameters = 1;
				Option_table_add_ignore_token_entry(option_table, "num_seed_points",
					&num_seed_points_expected_parameters);
				int dimension_expected_parameters = 1;
				Option_table_add_ignore_token_entry(option_table, "dimension",
					&dimension_expected_parameters);
				Option_table_add_double_vector_entry(option_table, "seed_points",
					seed_points, &length_seed_points);
				Option_table_add_double_vector_entry(option_table, "seed_values",
					seed_values, &num_seed_points);
				Option_table_add_int_vector_entry(option_table, "output_size",
					output_size, &dimension);

				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_fast_marching_image_filter.  "
						"Missing source field");
					return_code = 0;
				}
			}
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					cmzn_fieldmodule_create_field_imagefilter_fast_marching(
						field_modify->get_field_module(),
						source_field, stopping_value, num_seed_points, dimension,
						seed_points, seed_values, output_size));
			}

			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_fast_marching_image_filter.  Failed");
				}
			}

			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}

			if (seed_points) {
				DEALLOCATE(seed_points);
			}

			if (seed_values) {
				DEALLOCATE(seed_values);
			}

			if (output_size) {
				DEALLOCATE(output_size);
			}

		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_fast_marching_image_filter.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_fast_marching_image_filter */
int define_Computed_field_type_derivative(struct Parse_state *state,
	void *field_modify_void,void *computed_field_derivatives_package_void)
/*******************************************************************************
LAST MODIFIED : 24 August 2006

DESCRIPTION :
Converts <field> into type COMPUTED_FIELD_DERIVATIVE (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int return_code, xi_index;
	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);
	USE_PARAMETER(computed_field_derivatives_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;
		xi_index = 1;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_derivative_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code=Computed_field_get_type_derivative(field_modify->get_field(),
				&source_field, &xi_index);
			xi_index++;
		}
		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 field has two modes of operation.  For normal "
				"finite element fields it simply promotes the derivative "
				"values corresponding to <xi_index> calculated by the input "
				"<field> to be the field values.  These derivatives are with "
				"respect to xi. "
				"If the input <field> cannot cannot calculate element based "
				"derivatives then if the input field has a native resolution "
				"then this field uses the ITK DerivativeImageFilter to calculate "
				"a pixel based derivative at that same resolution.  "
				"The derivative filter will use the image pixel physical spacing "
				"if that is defined for ITK.  Note that as the derivative is a "
				"signed value you may want to offset and scale the resultant "
				"values if you intend to store them in an unsigned pixel format.");

			/* field */
			set_source_field_data.computed_field_manager=
				field_modify->get_field_manager();
			set_source_field_data.conditional_function =
				Computed_field_has_numerical_components;
			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);
			/* xi_index */
			Option_table_add_entry(option_table,"xi_index",&xi_index,
				NULL,set_int_positive);
			return_code=Option_table_multi_parse(option_table,state);
			DESTROY(Option_table)(&option_table);
			/* no errors,not asking for help */
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					Computed_field_create_derivative(field_modify->get_field_module(),
						source_field, xi_index - 1));
			}
			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.  Failed");
				}
			}
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_derivative.  Invalid argument(s)");
		return_code=0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_derivative */
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_sigmoid_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 COMPUTED_FIELD_SIGMOIDIMAGEFILTER (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	int return_code;
		double min, max, alpha, beta;
	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_sigmoid_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;
		min = 0.0;
		max = 1.0;
		alpha = 0.25;
		beta = 0.5;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_sigmoid_image_filter_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code =
				cmzn_field_get_type_sigmoid_image_filter(field_modify->get_field(), &source_field,
					&min, &max, &alpha, &beta);
		}
		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 sigmoid_filter field uses the itk::SigmoidImageFilter code to nonlinearly scale the pixel intensity to vary between the specified minimum and maximum intensity values according to a sigmoid curve. It is useful for focusing attention on a particular set of values while providing a smooth transition at the borders of the range. The <field> it operates on is usually a sample_texture field, based on a texture that has been created from image file(s).  Intensity values are rescaled to vary from the <minimum> to the <maximum> value using a sigmoid curve which has a width and centre defined by <alpha> and <beta>.  Increasing the <alpha> parameter widens the curve while increasing the <beta> parameter moves the centre of the curve to the right. 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);
			/* minimum */
			Option_table_add_double_entry(option_table, "minimum",
				&min);
			/* maximum */
			Option_table_add_double_entry(option_table, "maximum",
				&max);
			/* alpha */
			Option_table_add_double_entry(option_table, "alpha",
				&alpha);
			/* beta */
			Option_table_add_double_entry(option_table, "beta",
				&beta);

			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_sigmoid_image_filter.  "
						"Missing source field");
					return_code = 0;
				}
			}
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					cmzn_fieldmodule_create_field_imagefilter_sigmoid(
						field_modify->get_field_module(),
						source_field, min, max, alpha, beta));
			}

			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_sigmoid_image_filter.  Failed");
				}
			}
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_sigmoid_image_filter.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_sigmoid_image_filter */
예제 #22
0
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 */
예제 #23
0
int define_Computed_field_type_time_lookup(struct Parse_state *state,
	void *field_modify_void,void *computed_field_time_package_void)
/*******************************************************************************
LAST MODIFIED : 25 August 2006

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

	ENTER(define_Computed_field_type_time_lookup);
	USE_PARAMETER(computed_field_time_package_void);
	if (state&&(field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code=1;
		/* get valid parameters for projection field */
		source_fields = (struct Computed_field **)NULL;
		if (ALLOCATE(source_fields, struct Computed_field *, 2))
		{
			source_fields[0] = (struct Computed_field *)NULL;
			source_fields[1] = (struct Computed_field *)NULL;
			if ((NULL != field_modify->get_field()) &&
				(computed_field_time_lookup_type_string ==
					Computed_field_get_type_string(field_modify->get_field())))
			{
				return_code=Computed_field_get_type_time_lookup(field_modify->get_field(),
					source_fields, source_fields + 1);
			}
			if (return_code)
			{
				/* must access objects for set functions */
				if (source_fields[0])
				{
					ACCESS(Computed_field)(source_fields[0]);
				}
				if (source_fields[1])
				{
					ACCESS(Computed_field)(source_fields[1]);
				}

				option_table = CREATE(Option_table)();
				/* fields */
				set_source_field_data.computed_field_manager=
					field_modify->get_field_manager();
				set_source_field_data.conditional_function=Computed_field_has_numerical_components;
				set_source_field_data.conditional_function_user_data=(void *)NULL;
				Option_table_add_entry(option_table,"field",&source_fields[0],
					&set_source_field_data,set_Computed_field_conditional);
				set_time_field_data.computed_field_manager=
					field_modify->get_field_manager();
				set_time_field_data.conditional_function=Computed_field_is_scalar;
				set_time_field_data.conditional_function_user_data=(void *)NULL;
				Option_table_add_entry(option_table,"time_field",&source_fields[1],
					&set_time_field_data,set_Computed_field_conditional);
				return_code=Option_table_multi_parse(option_table,state);
				/* no errors,not asking for help */
				if (return_code)
				{
					return_code = field_modify->update_field_and_deaccess(
						Cmiss_field_module_create_time_lookup(field_modify->get_field_module(),
							source_fields[0], source_fields[1]));
				}
				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_time_lookup.  Failed");
					}
				}
				if (source_fields[0])
				{
					DEACCESS(Computed_field)(&source_fields[0]);
				}
				if (source_fields[1])
				{
					DEACCESS(Computed_field)(&source_fields[1]);
				}
				DESTROY(Option_table)(&option_table);
			}
			DEALLOCATE(source_fields);
		}
		else
		{
예제 #24
0
int gfx_modify_spectrum_settings_field(struct Parse_state *state,
	void *modify_spectrum_data_void,void *spectrum_command_data_void)
/*******************************************************************************
LAST MODIFIED : 11 April 2007

DESCRIPTION :
Executes a GFX MODIFY SPECTRUM FIELD 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.
==============================================================================*/
{
	enum Spectrum_settings_colour_mapping colour_mapping;
	int component, return_code;
	struct Computed_field *input_field, *output_field;
	struct Modify_spectrum_data *modify_spectrum_data;
	struct Option_table *option_table;
	struct Set_Computed_field_conditional_data set_input_field_data,
		set_output_field_data;
	struct Spectrum_settings *settings;

	ENTER(gfx_modify_spectrum_settings_field);
	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_FIELD);

				colour_mapping = Spectrum_settings_get_colour_mapping(settings);
				component = Spectrum_settings_get_component_number(settings);

				input_field = (struct Computed_field *)NULL;
				output_field = (struct Computed_field *)NULL;
				if (settings->input_field)
				{
					input_field = ACCESS(Computed_field)(settings->input_field);
				}
				if (settings->output_field)
				{
					output_field = ACCESS(Computed_field)(settings->output_field);
				}

				option_table = CREATE(Option_table)();
				/* component */
				Option_table_add_int_positive_entry(option_table, "component",
					&component);
				/* input_field */
				set_input_field_data.computed_field_manager=
					modify_spectrum_data->computed_field_manager;
				set_input_field_data.conditional_function=
					Computed_field_has_numerical_components;
				set_input_field_data.conditional_function_user_data=(void *)NULL;
				Option_table_add_entry(option_table,"input",
					&input_field ,&set_input_field_data,
					set_Computed_field_conditional);
				/* output_field */
				set_output_field_data.computed_field_manager=
					modify_spectrum_data->computed_field_manager;
				set_output_field_data.conditional_function=
					Computed_field_has_numerical_components;
				set_output_field_data.conditional_function_user_data=(void *)NULL;
				Option_table_add_entry(option_table,"output",
					&output_field, &set_output_field_data,
					set_Computed_field_conditional);
				/* conversion_mode */
				Option_table_add_enumerator_Spectrum_settings_colour_mapping(
					option_table, &colour_mapping);

				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)
				{
					if (!input_field)
					{
						display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_field.  "
							"You must specify a numerical input field.");
						return_code=0;
					}
					if (!output_field)
					{
						display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_field.  "
							"You must specify a numerical input field.");
						return_code=0;
					}
				}
				if (return_code)
				{
					if (input_field != settings->input_field)
					{
						REACCESS(Computed_field)(&settings->input_field,
							input_field);
						settings->settings_changed = 1;
					}
					if (output_field != settings->output_field)
					{
						REACCESS(Computed_field)(&settings->output_field,
							output_field);
						settings->settings_changed = 1;
					}
					Spectrum_settings_set_component_number(settings,
						component);
					Spectrum_settings_set_colour_mapping(settings,
						colour_mapping);
				}
				DEACCESS(Computed_field)(&input_field);
				DEACCESS(Computed_field)(&output_field);
			}
			else
			{
				display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_field.  "
					"Could not create settings");
				return_code=0;
			}
		}
		else
		{
			display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_field.  "
				"No modify data");
			return_code=0;
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_field.  Missing state");
		return_code=0;
	}
	LEAVE;

	return (return_code);
} /* gfx_modify_spectrum_field */
int define_Computed_field_type_eigenvectors(struct Parse_state *state,
	void *field_modify_void,void *computed_field_matrix_operators_package_void)
/*******************************************************************************
LAST MODIFIED : 25 August 2006

DESCRIPTION :
Converts <field> into type 'eigenvectors' (if it is not  already) and allows
its contents to be modified.
==============================================================================*/
{
	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_eigenvectors);
	USE_PARAMETER(computed_field_matrix_operators_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;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_eigenvectors_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code=Computed_field_get_type_eigenvectors(field_modify->get_field(), &source_field);
		}
		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,
			  "An eigenvectors field returns vectors corresponding to each eigenvalue from a source eigenvalues field.  For example, if 3 eigenvectors have been computed for a (3 * 3) matrix = 9 component field, the eigenvectors will be a 9 component field with the eigenvector corresponding to the first eigenvalue in the first 3 components, the second eigenvector in the next 3 components, and so on.  See a/large_strain for an example of using the eigenvalues and eigenvectors fields.");
			/* field */
			set_source_field_data.computed_field_manager =
				field_modify->get_field_manager();
			set_source_field_data.conditional_function =
				Computed_field_is_type_eigenvalues_conditional;
			set_source_field_data.conditional_function_user_data = (void *)NULL;
			Option_table_add_entry(option_table, "eigenvalues", &source_field,
				&set_source_field_data, set_Computed_field_conditional);
			return_code = Option_table_multi_parse(option_table, state);
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					cmzn_fieldmodule_create_field_eigenvectors(field_modify->get_field_module(),
						source_field));
			}
			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}
			DESTROY(Option_table)(&option_table);
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_eigenvectors.  Invalid argument(s)");
		return_code=0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_eigenvectors */
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 define_Computed_field_type_matrix_multiply(struct Parse_state *state,
	void *field_modify_void,void *computed_field_matrix_operators_package_void)
/*******************************************************************************
LAST MODIFIED : 25 August 2006

DESCRIPTION :
Converts <field> into type COMPUTED_FIELD_MATRIX_MULTIPLY (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	const char *current_token;
	int i, number_of_rows, return_code;
	struct Computed_field **source_fields;
	Computed_field_modify_data *field_modify;
	struct Option_table *option_table;
	struct Set_Computed_field_array_data set_field_array_data;
	struct Set_Computed_field_conditional_data set_field_data;

	ENTER(define_Computed_field_type_matrix_multiply);
	USE_PARAMETER(computed_field_matrix_operators_package_void);
	if (state&&(field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code=1;
		if (ALLOCATE(source_fields,struct Computed_field *,2))
		{
			/* get valid parameters for matrix_multiply field */
			number_of_rows = 1;
			source_fields[0] = (struct Computed_field *)NULL;
			source_fields[1] = (struct Computed_field *)NULL;
			if ((NULL != field_modify->get_field()) &&
				(computed_field_matrix_multiply_type_string ==
					Computed_field_get_type_string(field_modify->get_field())))
			{
				return_code=Computed_field_get_type_matrix_multiply(field_modify->get_field(),
					&number_of_rows,&(source_fields[0]),&(source_fields[1]));
			}
			if (return_code)
			{
				/* ACCESS the source fields for set_Computed_field_array */
				for (i=0;i<2;i++)
				{
					if (source_fields[i])
					{
						ACCESS(Computed_field)(source_fields[i]);
					}
				}
				/* try to handle help first */
				current_token=state->current_token;
				if (current_token != 0)
				{
					if (!(strcmp(PARSER_HELP_STRING,current_token)&&
						strcmp(PARSER_RECURSIVE_HELP_STRING,current_token)))
					{
						option_table = CREATE(Option_table)();
						Option_table_add_help(option_table,
						  "A matrix_mutliply field calculates the product of two matrices, giving a new m by n matrix.  The product is represented as a field with a list of (m * n) components.   The components of the matrix are listed row by row.  The <number_of_rows> m is used to infer the dimensions of the source matrices.  The two source <fields> are multiplied, with the components of the first interpreted as a matrix with dimensions m by s and the second as a matrix with dimensions s by n.  If the matrix dimensions are not consistent then an error is returned.  See a/curvature for an example of using the matrix_multiply field.");
						Option_table_add_entry(option_table,"number_of_rows",
							&number_of_rows,NULL,set_int_positive);
						set_field_data.conditional_function=
							Computed_field_has_numerical_components;
						set_field_data.conditional_function_user_data=(void *)NULL;
						set_field_data.computed_field_manager=
							field_modify->get_field_manager();
						set_field_array_data.number_of_fields=2;
						set_field_array_data.conditional_data= &set_field_data;
						Option_table_add_entry(option_table,"fields",source_fields,
							&set_field_array_data,set_Computed_field_array);
						return_code=Option_table_multi_parse(option_table,state);
						DESTROY(Option_table)(&option_table);
					}
					else
					{
						/* if the "number_of_rows" token is next, read it */
						if (fuzzy_string_compare(current_token,"number_of_rows"))
						{
							option_table = CREATE(Option_table)();
							/* number_of_rows */
							Option_table_add_entry(option_table,"number_of_rows",
								&number_of_rows,NULL,set_int_positive);
							return_code = Option_table_parse(option_table,state);
							DESTROY(Option_table)(&option_table);
						}
						if (return_code)
						{
							option_table = CREATE(Option_table)();
							set_field_data.conditional_function=
								Computed_field_has_numerical_components;
							set_field_data.conditional_function_user_data=(void *)NULL;
							set_field_data.computed_field_manager=
								field_modify->get_field_manager();
							set_field_array_data.number_of_fields=2;
							set_field_array_data.conditional_data= &set_field_data;
							Option_table_add_entry(option_table,"fields",source_fields,
								&set_field_array_data,set_Computed_field_array);
							return_code = Option_table_multi_parse(option_table, state);
							if (return_code)
							{
								return_code = field_modify->update_field_and_deaccess(
									cmzn_fieldmodule_create_field_matrix_multiply(field_modify->get_field_module(),
										number_of_rows, source_fields[0], source_fields[1]));
							}
							DESTROY(Option_table)(&option_table);
						}
						if (!return_code)
						{
							/* error */
							display_message(ERROR_MESSAGE,
								"define_Computed_field_type_matrix_multiply.  Failed");
						}
					}
				}
				else
				{
					display_message(ERROR_MESSAGE, "Missing command options");
					return_code = 0;
				}
				for (i=0;i<2;i++)
				{
					if (source_fields[i])
					{
						DEACCESS(Computed_field)(&(source_fields[i]));
					}
				}
			}
			DEALLOCATE(source_fields);
		}
		else
		{
예제 #28
0
int define_Computed_field_type_fibre_axes(struct Parse_state *state,
	void *field_modify_void,void *computed_field_fibres_package_void)
/*******************************************************************************
LAST MODIFIED : 24 August 2006

DESCRIPTION :
Converts <field> into type COMPUTED_FIELD_FIBRE_AXES (if it is not already) and
allows its contents to be modified.
==============================================================================*/
{
	int return_code;
	struct Computed_field *coordinate_field, *fibre_field;
	Computed_field_modify_data *field_modify;
	struct Option_table *option_table;
	struct Set_Computed_field_conditional_data set_coordinate_field_data,
		set_fibre_field_data;

	ENTER(define_Computed_field_type_fibre_axes);
	USE_PARAMETER(computed_field_fibres_package_void);
	if (state&&(field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code=1;
		coordinate_field=(struct Computed_field *)NULL;
		fibre_field=(struct Computed_field *)NULL;
		if ((NULL != field_modify->get_field()) &&
			(computed_field_fibre_axes_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code = Computed_field_get_type_fibre_axes(field_modify->get_field(),
				&fibre_field, &coordinate_field);
		}
		if (return_code)
		{
			/* have ACCESS/DEACCESS because set_Computed_field does */
			if (coordinate_field)
			{
				ACCESS(Computed_field)(coordinate_field);
			}
			if (fibre_field)
			{
				ACCESS(Computed_field)(fibre_field);
			}
			option_table = CREATE(Option_table)();
			/* coordinate */
			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=
				(void *)NULL;
			Option_table_add_entry(option_table,"coordinate",
				&coordinate_field,&set_coordinate_field_data,
				set_Computed_field_conditional);
			/* fibre */
			set_fibre_field_data.computed_field_manager=
				field_modify->get_field_manager();
			set_fibre_field_data.conditional_function=
				Computed_field_has_up_to_3_numerical_components;
			set_fibre_field_data.conditional_function_user_data=(void *)NULL;
			Option_table_add_entry(option_table,"fibre",
				&fibre_field,&set_fibre_field_data,set_Computed_field_conditional);
			return_code = Option_table_multi_parse(option_table,state);
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					Computed_field_create_fibre_axes(
						field_modify->get_field_module(), fibre_field, coordinate_field));
			}
			DESTROY(Option_table)(&option_table);
			if (coordinate_field)
			{
				DEACCESS(Computed_field)(&coordinate_field);
			}
			if (fibre_field)
			{
				DEACCESS(Computed_field)(&fibre_field);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_fibre_axes.  Invalid argument(s)");
		return_code=0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_fibre_axes */
int define_Computed_field_type_connected_threshold_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_CONNECTED_THRESHOLD_IMAGE_FILTER (if it is not
already) and allows its contents to be modified.
==============================================================================*/
{
	double lower_threshold, upper_threshold, replace_value;
	int num_seed_points;
	int seed_dimension;
  double *seed_points;
	int return_code;
	int seed_points_length;
	int previous_state_index, expected_parameters;

	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_connected_threshold_image_filter);
	USE_PARAMETER(computed_field_simple_package_void);
	if (state && (field_modify=(Computed_field_modify_data *)field_modify_void))
	{
		return_code = 1;

		source_field = (struct Computed_field *)NULL;
		lower_threshold = 0.0;
		upper_threshold = 1.0;
		replace_value = 1;
		num_seed_points = 0;
		seed_dimension  = 2;
		seed_points = (double *)NULL;

		// should probably default to having 1 seed point
		//		seed_points[0] = 0.5;  // pjb: is this ok?
		//		seed_points[1] = 0.5;
		seed_points_length = 0;

		/* get valid parameters for projection field */
		if ((NULL != field_modify->get_field()) &&
			(computed_field_connected_threshold_image_filter_type_string ==
				Computed_field_get_type_string(field_modify->get_field())))
		{
			return_code =
				Cmiss_field_get_type_connected_threshold_image_filter(field_modify->get_field(), &source_field,
				&lower_threshold, &upper_threshold, &replace_value,
		  &num_seed_points, &seed_dimension, &seed_points);
		}
		if (return_code)
		{

			if (source_field)
			{
				ACCESS(Computed_field)(source_field);
			}

			if (state->current_token &&
				(!(strcmp(PARSER_HELP_STRING, state->current_token)&&
					strcmp(PARSER_RECURSIVE_HELP_STRING, state->current_token))))
			{
				/* Handle help separately */
				option_table = CREATE(Option_table)();
			Option_table_add_help(option_table,
				"The connected_threshold_filter field uses the itk::ConnectedThresholdImageFilter code to segment a field. The <field> it operates on is usually a sample_texture field, based on a texture that has been created from image file(s).  The segmentation is based on a region growing algorithm which requires at least one seed point.  To specify the seed points first set the <num_seed_points> and the <dimension> of the image.  The <seed_points> are a list of the coordinates for the first and any subsequent seed points.  Starting from the seed points any neighbouring pixels with an intensity between <lower_threshold> and the <upper_threshold> are added to the region.  Pixels within the region have their pixel intensity set to <replace_value> while the remaining pixels are set to 0. 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);
				/* lower_threshold */
				Option_table_add_double_entry(option_table, "lower_threshold",
																			&lower_threshold);
				/* upper_threshold */
				Option_table_add_double_entry(option_table, "upper_threshold",
																			&upper_threshold);
				/* replace_value */
				Option_table_add_double_entry(option_table, "replace_value",
																			&replace_value);
				/* num_seed_points */
				Option_table_add_int_positive_entry(option_table, "num_seed_points",
																						&num_seed_points);
				Option_table_add_int_positive_entry(option_table, "dimension",
																						&seed_dimension);
				Option_table_add_double_vector_entry(option_table, "seed_points",
																						 seed_points, &seed_points_length);
				return_code = Option_table_multi_parse(option_table, state);
				DESTROY(Option_table)(&option_table);
			}

			if (return_code)
			{

				// store previous state so that we can return to it
				previous_state_index = state->current_index;

				/* parse the two options which determine the number of seed values
					 and hence the size of the array that must be created to read in
					 the number of seed values. */

				option_table = CREATE(Option_table)();
				/* num_seed_points */
				Option_table_add_int_positive_entry(option_table, "num_seed_points",
																						&num_seed_points);
				/* dimension */
				Option_table_add_int_positive_entry(option_table, "dimension",
																						&seed_dimension);
				/* Ignore all the other entries */
				Option_table_ignore_all_unmatched_entries(option_table);
				return_code = Option_table_multi_parse(option_table, state);
				DESTROY(Option_table)(&option_table);
				/* Return back to where we were */
				shift_Parse_state(state, previous_state_index - state->current_index);

			}

			/* parse the rest of the table */
			if (return_code)
			{
				seed_points_length = num_seed_points * seed_dimension;

				REALLOCATE(seed_points, seed_points, double, seed_points_length);
				// pjb: should I populate array with dummy values?

				option_table = CREATE(Option_table)();
				/* 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);
				/* lower_threshold */
				Option_table_add_double_entry(option_table, "lower_threshold",
																			&lower_threshold);
				/* upper_threshold */
				Option_table_add_double_entry(option_table, "upper_threshold",
																			&upper_threshold);
				/* replace_value */
				Option_table_add_double_entry(option_table, "replace_value",
																			&replace_value);
				expected_parameters = 1;
				Option_table_add_ignore_token_entry(option_table, "num_seed_points",
																						&expected_parameters);
				expected_parameters = 1;
				Option_table_add_ignore_token_entry(option_table, "dimension",
																						&expected_parameters);
				Option_table_add_double_vector_entry(option_table, "seed_points",
																						 seed_points, &seed_points_length);
				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_connected_threshold_image_filter.  "
						"Missing source field");
					return_code = 0;
				}
			}
			if (return_code)
			{
				return_code = field_modify->update_field_and_deaccess(
					Cmiss_field_module_create_connected_threshold_image_filter(
						field_modify->get_field_module(),
						source_field, lower_threshold, upper_threshold, replace_value,
						num_seed_points, seed_dimension, seed_points));
			}

			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_connected_threshold_image_filter.  Failed");
				}
			}

			if (source_field)
			{
				DEACCESS(Computed_field)(&source_field);
			}

			if (seed_points) {
				DEALLOCATE(seed_points);
			}
		}
	}
	else
	{
		display_message(ERROR_MESSAGE,
			"define_Computed_field_type_connected_threshold_image_filter.  Invalid argument(s)");
		return_code = 0;
	}
	LEAVE;

	return (return_code);
} /* define_Computed_field_type_connected_threshold_image_filter */
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 */