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 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 gfx_modify_spectrum_settings_log(struct Parse_state *state, void *modify_spectrum_data_void,void *spectrum_command_data_void) /******************************************************************************* LAST MODIFIED : 17 January 2001 DESCRIPTION : Executes a GFX MODIFY SPECTRUM LOG command. If return_code is 1, returns the completed Modify_spectrum_data with the parsed settings. Note that the settings are ACCESSed once on valid return. ==============================================================================*/ { char ambient,amb_diff,diffuse,emission,extend_above, extend_below,fix_maximum,fix_minimum,left,reverse,right, specular,transparent_above,transparent_below; enum Spectrum_settings_colour_mapping colour_mapping; int black_band_int,component,number_of_bands,range_components,return_code; float band_ratio,exaggeration,step_value; FE_value colour_range[2],range[2]; struct Modify_spectrum_data *modify_spectrum_data; struct Option_table *option_table, *render_option_table; struct Spectrum_settings *settings; ENTER(gfx_modify_spectrum_settings_log); USE_PARAMETER(spectrum_command_data_void); if (state) { modify_spectrum_data=(struct Modify_spectrum_data *)modify_spectrum_data_void; if (modify_spectrum_data) { /* create the spectrum_settings: */ settings=modify_spectrum_data->settings=CREATE(Spectrum_settings)(); if (settings) { /* access since deaccessed in gfx_modify_spectrum */ ACCESS(Spectrum_settings)(modify_spectrum_data->settings); Spectrum_settings_set_type(settings,SPECTRUM_LOG); colour_mapping = Spectrum_settings_get_colour_mapping(settings); ambient = 0; amb_diff = 0; band_ratio = 0.01; diffuse = 0; emission = 0; extend_above = 0; extend_below = 0; fix_maximum=0; fix_minimum=0; left = 0; number_of_bands = 10; reverse = 0; right = 0; specular = 0; step_value = 0.5; transparent_above = 0; transparent_below = 0; range_components = 2; colour_range[0] = 0.0; colour_range[1] = 1.0; range[0] = (FE_value)(modify_spectrum_data->spectrum_minimum); range[1] = (FE_value)(modify_spectrum_data->spectrum_maximum); component = Spectrum_settings_get_component_number(settings); exaggeration = Spectrum_settings_get_exaggeration(settings); option_table = CREATE(Option_table)(); /* band_ratio */ Option_table_add_float_entry(option_table, "band_ratio", &band_ratio); /* colour_range */ Option_table_add_FE_value_vector_entry(option_table, "colour_range", colour_range, &range_components); /* component */ Option_table_add_int_positive_entry(option_table, "component", &component); /* exaggeration */ Option_table_add_float_entry(option_table, "exaggeration", &exaggeration); /* extend_above */ Option_table_add_char_flag_entry(option_table, "extend_above", &extend_above); /* extend_below */ Option_table_add_char_flag_entry(option_table, "extend_below", &extend_below); /* fix_maximum */ Option_table_add_char_flag_entry(option_table, "fix_maximum", &fix_maximum); /* fix_minimum */ Option_table_add_char_flag_entry(option_table, "fix_minimum", &fix_minimum); /* left */ Option_table_add_char_flag_entry(option_table, "left", &left); /* number_of_bands */ Option_table_add_int_positive_entry(option_table, "number_of_bands", &number_of_bands); /* position */ Option_table_add_int_non_negative_entry(option_table, "position", &(modify_spectrum_data->position)); /* range */ Option_table_add_FE_value_vector_entry(option_table, "range", range, &range_components); /* reverse */ Option_table_add_char_flag_entry(option_table, "reverse", &reverse); /* right */ Option_table_add_char_flag_entry(option_table, "right", &right); /* step_value */ Option_table_add_float_entry(option_table, "step_value", &step_value); /* transparent_above */ Option_table_add_char_flag_entry(option_table, "transparent_above", &transparent_above); /* transparent_below */ Option_table_add_char_flag_entry(option_table, "transparent_below", &transparent_below); /* conversion_mode */ Option_table_add_enumerator_Spectrum_settings_colour_mapping( option_table, &colour_mapping); /* render_option */ render_option_table = CREATE(Option_table)(); Option_table_add_char_flag_entry(render_option_table, "ambient", &ambient); Option_table_add_char_flag_entry(render_option_table, "amb_diff", &amb_diff); Option_table_add_char_flag_entry(render_option_table, "diffuse", &diffuse); Option_table_add_char_flag_entry(render_option_table, "emission", &emission); Option_table_add_char_flag_entry(render_option_table, "specular", &specular); Option_table_add_suboption_table(option_table, render_option_table); if (!(return_code=Option_table_multi_parse(option_table,state))) { DEACCESS(Spectrum_settings)(&(modify_spectrum_data->settings)); } DESTROY(Option_table)(&option_table); if (return_code) { Spectrum_settings_set_colour_mapping(settings, colour_mapping); Spectrum_settings_set_number_of_bands(settings, number_of_bands); black_band_int = (band_ratio * 1000.0 + 0.5); Spectrum_settings_set_black_band_proportion(settings, black_band_int); Spectrum_settings_set_step_value(settings, step_value); } if ( return_code ) { if (specular + emission > 1) { display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_linear. " "All spectrums are ambient diffuse. The specular and emission flags are ignored."); return_code=0; } } if ( return_code ) { if ( extend_above && transparent_above) { display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log. " "Specify only one of extend_above and transparent_above"); return_code=0; } else if (extend_above) { Spectrum_settings_set_extend_above_flag(settings, 1); } else if (transparent_above) { Spectrum_settings_set_extend_above_flag(settings, 0); } } if ( return_code ) { if ( extend_below && transparent_below) { display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log. " "Specify only one of extend_below and transparent_below"); return_code=0; } else if (extend_below) { Spectrum_settings_set_extend_below_flag(settings, 1); } else if (transparent_below) { Spectrum_settings_set_extend_below_flag(settings, 0); } } if ( return_code ) { if (left && right) { display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log. " "Specify only one of left or right"); return_code=0; } else if (left) { exaggeration = fabs(exaggeration); } else if (right) { exaggeration = -fabs(exaggeration); } Spectrum_settings_set_exaggeration(settings, exaggeration); } if ( return_code ) { Spectrum_settings_set_component_number(settings, component); Spectrum_settings_set_colour_value_minimum(settings, colour_range[0]); Spectrum_settings_set_colour_value_maximum(settings, colour_range[1]); Spectrum_settings_set_range_minimum(settings, range[0]); Spectrum_settings_set_range_maximum(settings, range[1]); Spectrum_settings_set_reverse_flag(settings, reverse); } /* Must set fix_maximum,fix_minimum after setting minimum and maximum range */ if ( return_code ) { if (fix_maximum) { Spectrum_settings_set_fix_maximum_flag(settings, 1); } } if ( return_code ) { if (fix_minimum) { Spectrum_settings_set_fix_minimum_flag(settings, 1); } } } else { display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log. " "Could not create settings"); return_code=0; } } else { display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log. " "No modify data"); return_code=0; } } else { display_message(ERROR_MESSAGE,"gfx_modify_spectrum_settings_log. Missing state"); return_code=0; } LEAVE; return (return_code); } /* gfx_modify_spectrum_log */
int define_Computed_field_type_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_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 */
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); } }