static void preview(FacetsControls *controls, FacetsArgs *args) { GwyDataField *dtheta, *dphi, *mask, *mfield = NULL; GwyContainer *data, *fdata; data = controls->mydata; fdata = controls->fdata; add_mask_field(GWY_DATA_VIEW(controls->view), NULL); add_mask_field(GWY_DATA_VIEW(controls->fview), &mask_color); mask = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/mask")); dtheta = GWY_DATA_FIELD(gwy_container_get_object_by_name(fdata, "/theta")); dphi = GWY_DATA_FIELD(gwy_container_get_object_by_name(fdata, "/phi")); gwy_container_gis_object_by_name(fdata, "/1/mask", (GObject**)&mfield); gwy_data_field_mark_facets(dtheta, dphi, args->theta0, args->phi0, args->tolerance, mask); if (mfield && args->combine) { if (args->combine_type == GWY_MERGE_UNION) gwy_data_field_grains_add(mask, mfield); else if (args->combine_type == GWY_MERGE_INTERSECTION) gwy_data_field_grains_intersect(mask, mfield); } gwy_data_field_data_changed(mask); facets_mark_fdata(args, fdata); }
static gboolean maskcor_kernel_filter(GwyContainer *data, gint id, gpointer user_data) { GwyAppDataId *object = (GwyAppDataId*)user_data; GwyDataField *kernel, *dfield; GQuark quark; quark = gwy_app_get_data_key_for_id(id); kernel = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); data = gwy_app_data_browser_get(object->datano); quark = gwy_app_get_data_key_for_id(object->id); dfield = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); if (gwy_data_field_get_xreal(kernel) <= gwy_data_field_get_xreal(dfield)/4 && gwy_data_field_get_yreal(kernel) <= gwy_data_field_get_yreal(dfield)/4 && !gwy_data_field_check_compatibility(kernel, dfield, GWY_DATA_COMPATIBILITY_LATERAL | GWY_DATA_COMPATIBILITY_VALUE)) return TRUE; return FALSE; }
static gboolean immerse_data_filter(GwyContainer *data, gint id, gpointer user_data) { GwyAppDataId *object = (GwyAppDataId*)user_data; GwyDataField *image, *detail; GQuark quark; quark = gwy_app_get_data_key_for_id(id); detail = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); data = gwy_app_data_browser_get(object->datano); quark = gwy_app_get_data_key_for_id(object->id); image = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); /* It does not make sense to immerse itself */ if (detail == image) return FALSE; if (gwy_data_field_check_compatibility(image, detail, GWY_DATA_COMPATIBILITY_LATERAL | GWY_DATA_COMPATIBILITY_VALUE)) return FALSE; if (gwy_data_field_get_xreal(image) < gwy_data_field_get_xreal(detail) || gwy_data_field_get_xreal(image) < gwy_data_field_get_xreal(detail)) return FALSE; return TRUE; }
static void preview_selection_updated(GwySelection *selection, G_GNUC_UNUSED gint id, FacetsControls *controls) { GwyDataField *dfield; gdouble theta, phi, xy[2]; gint i, j; if (controls->in_update) return; dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->mydata, "/0/data")); if (!gwy_selection_get_object(selection, 0, xy)) return; j = gwy_data_field_rtoj(dfield, xy[0]); i = gwy_data_field_rtoi(dfield, xy[1]); dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->fdata, "/theta")); theta = gwy_data_field_get_val(dfield, j, i); dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->fdata, "/phi")); phi = gwy_data_field_get_val(dfield, j, i); facet_view_select_angle(controls, theta, phi); }
static gboolean prewitt_vertical(GwyContainer *data, GwyRunType run) { GObject *shadefield; GwyDataField *dfield; g_assert(run & GRADIENT_RUN_MODES); dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); gwy_app_undo_checkpoint(data, "/0/show", NULL); if (gwy_container_gis_object_by_name(data, "/0/show", &shadefield)) { gwy_data_field_resample(GWY_DATA_FIELD(shadefield), gwy_data_field_get_xres(dfield), gwy_data_field_get_yres(dfield), GWY_INTERPOLATION_NONE); } else { shadefield = gwy_serializable_duplicate(G_OBJECT(dfield)); gwy_container_set_object_by_name(data, "/0/show", shadefield); g_object_unref(shadefield); } gwy_data_field_area_copy(dfield, GWY_DATA_FIELD(shadefield), 0, 0, gwy_data_field_get_xres(dfield), gwy_data_field_get_yres(dfield), 0, 0); gwy_data_field_area_filter_prewitt(GWY_DATA_FIELD(shadefield), GTK_ORIENTATION_VERTICAL, 0, 0, gwy_data_field_get_xres(dfield), gwy_data_field_get_yres(dfield)); return TRUE; }
static gboolean outliers(GwyContainer *data, GwyRunType run) { GObject *maskfield; GwyDataField *dfield; gdouble thresh; g_assert(run & OUTLIERS_RUN_MODES); dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); gwy_app_undo_checkpoint(data, "/0/mask", NULL); if (!gwy_container_gis_object_by_name(data, "/0/mask", &maskfield)) { maskfield = gwy_data_field_new(gwy_data_field_get_xres(dfield), gwy_data_field_get_yres(dfield), gwy_data_field_get_xreal(dfield), gwy_data_field_get_yreal(dfield), TRUE); gwy_container_set_object_by_name(data, "/0/mask", maskfield); g_object_unref(maskfield); } thresh = 3.0; gwy_data_field_mask_outliers(dfield, GWY_DATA_FIELD(maskfield), thresh); return TRUE; }
static void unrotate_dialog_update(UnrotateControls *controls, UnrotateArgs *args) { gchar *lab; GwyPlaneSymmetry symm; GwyDataField *dfield, *rfield; GwyContainer *data; gdouble phi; gwy_enum_combo_box_set_active(GTK_COMBO_BOX(controls->interp), args->interp); gwy_enum_combo_box_set_active(GTK_COMBO_BOX(controls->symmetry), args->symmetry); symm = args->symmetry ? args->symmetry : controls->guess; phi = controls->correction[symm]; lab = g_strdup_printf("%.2f %s", 180.0/G_PI*phi, _("deg")); gtk_label_set_text(GTK_LABEL(controls->corrlabel), lab); g_free(lab); data = gwy_data_view_get_data(GWY_DATA_VIEW(controls->data_view)); dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); rfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/show")); gwy_data_field_copy(dfield, rfield, FALSE); gwy_data_field_rotate(rfield, phi, args->interp); gwy_data_field_data_changed(rfield); }
static gboolean wshed_ok(WshedControls *controls, WshedArgs *args, GwyContainer *data) { GwyDataField *dfield; GObject *maskfield; if (controls->computed) { maskfield = gwy_container_get_object_by_name(controls->mydata, "/0/mask"); gwy_app_undo_checkpoint(data, "/0/mask", NULL); gwy_container_set_object_by_name(data, "/0/mask", maskfield); return TRUE; } dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); maskfield = gwy_serializable_duplicate(G_OBJECT(dfield)); if (mask_process(dfield, GWY_DATA_FIELD(maskfield), args, GTK_WIDGET(gwy_app_data_window_get_for_data(data)))) { gwy_app_undo_checkpoint(data, "/0/mask", NULL); gwy_container_set_object_by_name(data, "/0/mask", maskfield); controls->computed = TRUE; } g_object_unref(maskfield); return controls->computed; }
static gboolean xydenoise_data_filter(GwyContainer *data, gint id, gpointer user_data) { GwyAppDataId *object = (GwyAppDataId*)user_data; GwyDataField *op1, *op2; GQuark quark; quark = gwy_app_get_data_key_for_id(id); op1 = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); data = gwy_app_data_browser_get(object->datano); quark = gwy_app_get_data_key_for_id(object->id); op2 = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); /* It does not make sense to xydenoiserelate with itself */ if (op1 == op2) return FALSE; return !gwy_data_field_check_compatibility(op1, op2, GWY_DATA_COMPATIBILITY_RES | GWY_DATA_COMPATIBILITY_REAL | GWY_DATA_COMPATIBILITY_LATERAL | GWY_DATA_COMPATIBILITY_VALUE); }
static void run_noninteractive(FacetsArgs *args, GwyContainer *data, GwyContainer *fdata, GwyDataField *dfield, GwyDataField *mfield, GQuark mquark) { GwyDataField *dtheta, *dphi, *mask; gwy_app_undo_qcheckpointv(data, 1, &mquark); mask = create_mask_field(dfield); dtheta = GWY_DATA_FIELD(gwy_container_get_object_by_name(fdata, "/theta")); dphi = GWY_DATA_FIELD(gwy_container_get_object_by_name(fdata, "/phi")); gwy_data_field_mark_facets(dtheta, dphi, args->theta0, args->phi0, args->tolerance, mask); if (mfield && args->combine) { if (args->combine_type == GWY_MERGE_UNION) gwy_data_field_grains_add(mfield, mask); else if (args->combine_type == GWY_MERGE_INTERSECTION) gwy_data_field_grains_intersect(mfield, mask); gwy_data_field_data_changed(mfield); } else if (mfield) { gwy_data_field_copy(mask, mfield, FALSE); gwy_data_field_data_changed(mfield); } else { gwy_container_set_object(data, mquark, mask); } g_object_unref(mask); }
static void merge_do_none(MergeArgs *args) { GwyDataField *dfield1, *dfield2; gint xres1, xres2, yres1, yres2; gint px1, py1, px2, py2; GwyContainer *data1, *data2; GQuark quark; data1 = gwy_app_data_browser_get(args->op1.datano); quark = gwy_app_get_data_key_for_id(args->op1.id); dfield1 = GWY_DATA_FIELD(gwy_container_get_object(data1, quark)); data2 = gwy_app_data_browser_get(args->op2.datano); quark = gwy_app_get_data_key_for_id(args->op2.id); dfield2 = GWY_DATA_FIELD(gwy_container_get_object(data2, quark)); xres1 = gwy_data_field_get_xres(dfield1); xres2 = gwy_data_field_get_xres(dfield2); yres1 = gwy_data_field_get_yres(dfield1); yres2 = gwy_data_field_get_yres(dfield2); if (args->direction == GWY_MERGE_DIRECTION_UP) { px1 = px2 = 0; py1 = yres2; py2 = 0; } else if (args->direction == GWY_MERGE_DIRECTION_DOWN) { px1 = px2 = 0; py1 = 0; py2 = yres1; } else if (args->direction == GWY_MERGE_DIRECTION_LEFT) { py1 = py2 = 0; px1 = xres2; px2 = 0; } else if (args->direction == GWY_MERGE_DIRECTION_RIGHT) { py1 = py2 = 0; px1 = 0; px2 = xres1; } else { g_assert_not_reached(); } create_merged_field(data1, args->op1.id, dfield1, dfield2, px1, py1, px2, py2, args->boundary, args->direction, args->create_mask, args->crop_to_rectangle); }
static GdkPixbuf* gwy_layer_basic_paint(GwyPixmapLayer *layer) { GwyLayerBasic *basic_layer; GwyDataField *data_field; GwyLayerBasicRangeType range_type; GwyContainer *data; gdouble min, max; basic_layer = GWY_LAYER_BASIC(layer); data = GWY_DATA_VIEW_LAYER(layer)->data; data_field = GWY_DATA_FIELD(layer->data_field); if (basic_layer->show_field) data_field = GWY_DATA_FIELD(basic_layer->show_field); g_return_val_if_fail(data && data_field, NULL); /* Special-case full range, as gwy_pixbuf_draw_data_field() is simplier, * it doesn't have to deal with outliers */ range_type = gwy_layer_basic_get_range_type(basic_layer); gwy_pixmap_layer_make_pixbuf(layer, FALSE); if (range_type == GWY_LAYER_BASIC_RANGE_FULL) gwy_pixbuf_draw_data_field(layer->pixbuf, data_field, basic_layer->gradient); else if (range_type == GWY_LAYER_BASIC_RANGE_ADAPT) gwy_pixbuf_draw_data_field_adaptive(layer->pixbuf, data_field, basic_layer->gradient); else { if (basic_layer->show_field) { /* Ignore fixed range in for presentations. */ if (range_type == GWY_LAYER_BASIC_RANGE_FIXED) gwy_pixbuf_draw_data_field(layer->pixbuf, data_field, basic_layer->gradient); else { gwy_data_field_get_autorange(data_field, &min, &max); gwy_pixbuf_draw_data_field_with_range(layer->pixbuf, data_field, basic_layer->gradient, min, max); } } else { gwy_layer_basic_get_range(basic_layer, &min, &max); gwy_pixbuf_draw_data_field_with_range(layer->pixbuf, data_field, basic_layer->gradient, min, max); } } return layer->pixbuf; }
static void rotate_preview_draw(RotateControls *controls, RotateArgs *args) { GwyDataField *dfield, *rfield; GwyContainer *data; data = gwy_data_view_get_data(GWY_DATA_VIEW(controls->data_view)); dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); rfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/show")); gwy_data_field_copy(dfield, rfield, FALSE); gwy_data_field_rotate(rfield, args->angle, args->interp); gwy_data_field_data_changed(rfield); }
static GwyDataField* get_right_tip_field(GwyDataField *tip, GwyDataField *surface, gboolean *freetip) { GwyDataField *buffer; gdouble tipxstep, tipystep; gdouble surfxstep, surfystep; *freetip = FALSE; tipxstep = tip->xreal/tip->xres; surfxstep = surface->xreal/surface->xres; tipystep = tip->yreal/tip->yres; surfystep = surface->yreal/surface->yres; if (fabs(tipxstep/surfxstep - 1.0) > 0.01 || fabs(tipystep/surfystep - 1.0) > 0.01) { buffer = GWY_DATA_FIELD(gwy_data_field_new(tip->xres, tip->yres, tip->xreal, tip->yreal, FALSE)); gwy_data_field_copy(tip, buffer); gwy_data_field_resample(buffer, tip->xres/surfxstep*tipxstep, tip->yres/surfystep*tipystep, GWY_INTERPOLATION_BILINEAR); *freetip = TRUE; return buffer; } else return tip; }
static void preview(GEdgeControls *controls, GEdgeArgs *args) { GwyDataField *mask, *dfield; GwyPixmapLayer *layer; dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->mydata, "/0/data")); /* Set up the mask */ if (!gwy_container_gis_object_by_name(controls->mydata, "/0/mask", &mask)) { mask = create_mask_field(dfield); gwy_container_set_object_by_name(controls->mydata, "/0/mask", mask); g_object_unref(mask); layer = gwy_layer_mask_new(); gwy_pixmap_layer_set_data_key(layer, "/0/mask"); gwy_layer_mask_set_color_key(GWY_LAYER_MASK(layer), "/0/mask"); gwy_data_view_set_alpha_layer(GWY_DATA_VIEW(controls->view), layer); } gwy_data_field_copy(dfield, mask, FALSE); gedge_process(dfield, mask, args); gwy_data_field_data_changed(mask); }
static gboolean asciiexport_save(GwyContainer *data, const gchar *filename) { GwyDataField *dfield; gint xres, yres, i, j; gdouble *d; FILE *fh; if (!(fh = fopen(filename, "w"))) return FALSE; dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); xres = gwy_data_field_get_xres(dfield); yres = gwy_data_field_get_yres(dfield); d = gwy_data_field_get_data(dfield); for (i = 0; i < yres; i++) { for (j = 0; j < xres; j++) { if (fprintf(fh, "%g%c", d[i*xres + j], j == xres-1 ? '\n' : '\t') < 2) { unlink(filename); return FALSE; } } } fclose(fh); return TRUE; }
static void preview(WshedControls *controls, WshedArgs *args) { GwyDataField *maskfield, *dfield; GwyPixmapLayer *layer; dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->mydata, "/0/data")); /*set up the mask*/ if (gwy_container_contains_by_name(controls->mydata, "/0/mask")) { maskfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->mydata, "/0/mask")); gwy_data_field_resample(maskfield, gwy_data_field_get_xres(dfield), gwy_data_field_get_yres(dfield), GWY_INTERPOLATION_NONE); gwy_data_field_copy(dfield, maskfield); if (!gwy_data_view_get_alpha_layer(GWY_DATA_VIEW(controls->view))) { layer = GWY_PIXMAP_LAYER(gwy_layer_mask_new()); gwy_data_view_set_alpha_layer(GWY_DATA_VIEW(controls->view), layer); } } else { maskfield = GWY_DATA_FIELD(gwy_serializable_duplicate(G_OBJECT(dfield))); gwy_container_set_object_by_name(controls->mydata, "/0/mask", G_OBJECT(maskfield)); g_object_unref(maskfield); layer = GWY_PIXMAP_LAYER(gwy_layer_mask_new()); gwy_data_view_set_alpha_layer(GWY_DATA_VIEW(controls->view), layer); } wshed_dialog_update_values(controls, args); controls->computed = mask_process(dfield, maskfield, args, controls->dialog); if (controls->computed) gwy_data_view_update(GWY_DATA_VIEW(controls->view)); }
static void fix_scales(EZDSection *section, gint idx, GwyContainer *container) { GwyDataField *dfield; GwySIUnit *siunit; gchar key[40]; gint power10; gdouble r; g_snprintf(key, sizeof(key), "/%d/data", idx); dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(container, key)); /* Fix value scale */ siunit = gwy_si_unit_new_parse(section->zrange.unit, &power10); gwy_data_field_set_si_unit_z(dfield, siunit); g_object_unref(siunit); r = pow10(power10); gwy_data_field_multiply(dfield, r*section->zrange.range); gwy_data_field_add(dfield, r*section->zrange.min); /* Fix lateral scale */ siunit = gwy_si_unit_new_parse(section->xrange.unit, &power10); gwy_data_field_set_si_unit_xy(dfield, siunit); g_object_unref(siunit); gwy_data_field_set_xreal(dfield, pow10(power10)*section->xrange.range); siunit = gwy_si_unit_new_parse(section->yrange.unit, &power10); gwy_data_field_set_yreal(dfield, pow10(power10)*section->yrange.range); g_object_unref(siunit); /* Some metadata */ if (section->zrange.name) { const gchar *s; switch (section->direction) { case SCAN_FORWARD: s = " forward"; break; case SCAN_BACKWARD: s = " backward"; break; default: s = ""; break; } g_snprintf(key, sizeof(key), "/%d/data/title", idx); gwy_container_set_string_by_name(container, key, g_strdup_printf("%s%s", section->zrange.name, s)); } }
static gboolean height_dist(GwyContainer *data, GwyRunType run) { GString *lab; GtkWidget *graph; GwyDataWindow *data_window; GwyGraphAutoProperties prop; GwyDataLine *dataline; GwyDataField *dfield; GwyDataField *mfield; GwySIValueFormat *units; g_return_val_if_fail(run & DIST_RUN_MODES, FALSE); g_return_val_if_fail(gwy_container_contains_by_name(data, "/0/mask"), FALSE); graph = gwy_graph_new(); gwy_graph_get_autoproperties(GWY_GRAPH(graph), &prop); prop.is_point = 0; prop.is_line = 1; gwy_graph_set_autoproperties(GWY_GRAPH(graph), &prop); dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); mfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/mask")); dataline = (GwyDataLine*)gwy_data_line_new(10, 10, TRUE); gwy_data_field_grains_get_height_distribution(dfield, mfield, dataline); lab = g_string_new(_("Grain height histogram")); units = gwy_si_unit_get_format(dfield->si_unit_xy, dataline->real, NULL); gwy_graph_add_dataline_with_units(GWY_GRAPH(graph), dataline, 0, lab, NULL, units->magnitude, 1, units->units, " "); data_window = gwy_app_data_window_get_for_data(data); gwy_app_graph_window_create_for_window(GWY_GRAPH(graph), data_window, _("Grain height distribution")); g_string_free(lab, TRUE); g_object_unref(dataline); g_free(units); return FALSE; }
static void tip_process(TipModelArgs *args, TipModelControls *controls) { const GwyTipModelPreset *preset; GwyDataField *dfield; GwyDataField *sfield; GQuark quark; gchar label[64]; gint xres, yres; gdouble xstep, ystep, min, max, zrange; gdouble params[2]; preset = gwy_tip_model_get_preset(args->type); g_return_if_fail(preset); tip_model_dialog_update_values(controls, args); /* estimate x and y size */ dfield = controls->tip; quark = gwy_app_get_data_key_for_id(args->object.id); sfield = GWY_DATA_FIELD(gwy_container_get_object(args->object.data, quark)); gwy_data_field_set_xreal(dfield, gwy_data_field_get_xmeasure(sfield) *gwy_data_field_get_xres(dfield)); gwy_data_field_set_yreal(dfield, gwy_data_field_get_ymeasure(sfield) *gwy_data_field_get_yres(dfield)); params[0] = args->nsides; params[1] = args->angle*G_PI/180; gwy_data_field_get_min_max(sfield, &min, &max); zrange = max - min; preset->guess(sfield, zrange, args->radius, params, &xres, &yres); /* process tip */ /* FIXME: this must be solved within guess functions */ xres = CLAMP(xres, 20, 1000); yres = CLAMP(yres, 20, 1000); g_snprintf(label, sizeof(label), _("Tip resolution: %d × %d pixels"), xres, yres); gtk_label_set_text(GTK_LABEL(controls->labsize), label); xstep = gwy_data_field_get_xmeasure(dfield); ystep = gwy_data_field_get_ymeasure(dfield); gwy_data_field_resample(dfield, xres, yres, GWY_INTERPOLATION_NONE); gwy_data_field_set_xreal(dfield, xstep*xres); gwy_data_field_set_yreal(dfield, ystep*yres); preset->func(dfield, zrange, args->radius, args->theta*G_PI/180, params); tip_update(controls, args); }
static gboolean tip_dilation_do(TipDilationArgs *args) { GtkWidget *data_window; GwyContainer *data; GwyDataField *dfield, *dfield1, *dfield2; GwyDataWindow *operand1, *operand2; operand1 = args->win1; operand2 = args->win2; g_return_val_if_fail(operand1 != NULL && operand2 != NULL, FALSE); data = gwy_data_window_get_data(operand1); dfield1 = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); data = gwy_data_window_get_data(operand2); dfield2 = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); /*result fields - after computation result should be at dfield */ data = gwy_container_duplicate_by_prefix(data, "/0/data", "/0/base/palette", "/0/select", NULL); dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); gwy_app_wait_start(GTK_WIDGET(args->win2), "Initializing..."); dfield = gwy_tip_dilation(dfield1, dfield2, dfield, gwy_app_wait_set_fraction, gwy_app_wait_set_message); gwy_app_wait_finish(); /*set right output */ if (dfield) { data_window = gwy_app_data_window_create(data); gwy_app_data_window_set_untitled(GWY_DATA_WINDOW(data_window), NULL); } else g_object_unref(data); return TRUE; }
static void update_average_angle(FacetsControls *controls, G_GNUC_UNUSED FacetsArgs *args) { GwyDataField *dtheta, *dphi, *mask; gdouble theta, phi; gchar s[24]; dtheta = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->fdata, "/theta")); dphi = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->fdata, "/phi")); mask = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->mydata, "/0/mask")); calculate_average_angle(dtheta, dphi, mask, &theta, &phi); g_snprintf(s, sizeof(s), "%.2f deg", 180.0/G_PI*theta); gtk_label_set_text(GTK_LABEL(controls->mtheta_label), s); g_snprintf(s, sizeof(s), "%.2f deg", 180.0/G_PI*phi); gtk_label_set_text(GTK_LABEL(controls->mphi_label), s); }
static gboolean tip_blind_source_filter(GwyContainer *data, gint id, gpointer user_data) { GwyAppDataId *object = (GwyAppDataId*)user_data; GwyDataField *source, *orig; GQuark quark; quark = gwy_app_get_data_key_for_id(id); source = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); data = gwy_app_data_browser_get(object->datano); quark = gwy_app_get_data_key_for_id(object->id); orig = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); return !gwy_data_field_check_compatibility(source, orig, GWY_DATA_COMPATIBILITY_MEASURE | GWY_DATA_COMPATIBILITY_LATERAL | GWY_DATA_COMPATIBILITY_VALUE); }
static gboolean merge_data_filter(GwyContainer *data, gint id, gpointer user_data) { MergeArgs *args = (MergeArgs*)user_data; GwyDataCompatibilityFlags compatflags; GwyDataField *op1, *op2; gboolean ok; GQuark quark; quark = gwy_app_get_data_key_for_id(id); op2 = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); data = gwy_app_data_browser_get(args->op1.datano); quark = gwy_app_get_data_key_for_id(args->op1.id); op1 = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); if (op1 == op2) return FALSE; compatflags = (GWY_DATA_COMPATIBILITY_MEASURE | GWY_DATA_COMPATIBILITY_LATERAL | GWY_DATA_COMPATIBILITY_VALUE); ok = !gwy_data_field_check_compatibility(op1, op2, compatflags); if (args->mode == GWY_MERGE_MODE_JOIN) { if (args->direction == GWY_MERGE_DIRECTION_UP || args->direction == GWY_MERGE_DIRECTION_DOWN) { if (op1->xres != op2->xres) ok = FALSE; } if (args->direction == GWY_MERGE_DIRECTION_LEFT || args->direction == GWY_MERGE_DIRECTION_RIGHT) { if (op1->yres != op2->yres) ok = FALSE; } } return ok; }
static gboolean presentation_attach_filter(GwyContainer *source, gint id, gpointer user_data) { const GwyAppDataId *target = (const GwyAppDataId*)user_data; GwyDataField *source_dfield, *target_dfield; GwyContainer *data; GQuark quark; quark = gwy_app_get_data_key_for_id(id); source_dfield = GWY_DATA_FIELD(gwy_container_get_object(source, quark)); data = gwy_app_data_browser_get(target->datano); quark = gwy_app_get_data_key_for_id(target->id); target_dfield = GWY_DATA_FIELD(gwy_container_get_object(data, quark)); return !gwy_data_field_check_compatibility(source_dfield, target_dfield, GWY_DATA_COMPATIBILITY_RES | GWY_DATA_COMPATIBILITY_REAL | GWY_DATA_COMPATIBILITY_LATERAL); }
static void run_noninteractive(FacetsArgs *args, GwyContainer *data, GwyContainer *fdata, GwyDataField *dfield, GwyDataField *mfield, GQuark mquark) { GwyDataField *dtheta, *dphi; gwy_app_undo_qcheckpointv(data, 1, &mquark); if (!mfield) { mfield = create_mask_field(dfield); gwy_container_set_object(data, mquark, mfield); g_object_unref(mfield); } dtheta = GWY_DATA_FIELD(gwy_container_get_object_by_name(fdata, "/theta")); dphi = GWY_DATA_FIELD(gwy_container_get_object_by_name(fdata, "/phi")); gwy_data_field_mark_facets(dtheta, dphi, args->theta0, args->phi0, args->tolerance, mfield); gwy_data_field_data_changed(mfield); }
static void gwy_data_view_make_pixmap(GwyDataView *data_view) { GtkWidget *widget; GwyDataField *data_field; gint width, height, scwidth, scheight, src_width, src_height; data_field = GWY_DATA_FIELD( gwy_container_get_object_by_name(data_view->data, "/0/data")); src_width = gwy_data_field_get_xres(data_field); src_height = gwy_data_field_get_yres(data_field); if (!data_view->base_pixbuf) { data_view->base_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, BITS_PER_SAMPLE, src_width, src_height); gwy_debug_objects_creation(G_OBJECT(data_view->base_pixbuf)); } if (data_view->pixbuf) { width = gdk_pixbuf_get_width(data_view->pixbuf); height = gdk_pixbuf_get_height(data_view->pixbuf); } else width = height = -1; widget = GTK_WIDGET(data_view); data_view->zoom = MIN((gdouble)widget->allocation.width/src_width, (gdouble)widget->allocation.height/src_height); data_view->newzoom = data_view->zoom; scwidth = floor(src_width * data_view->zoom + 0.000001); scheight = floor(src_height * data_view->zoom + 0.000001); data_view->xmeasure = gwy_data_field_get_xreal(data_field)/scwidth; data_view->ymeasure = gwy_data_field_get_yreal(data_field)/scheight; data_view->xoff = (widget->allocation.width - scwidth)/2; data_view->yoff = (widget->allocation.height - scheight)/2; if (scwidth != width || scheight != height) { gwy_object_unref(data_view->pixbuf); data_view->pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, BITS_PER_SAMPLE, scwidth, scheight); gwy_debug_objects_creation(G_OBJECT(data_view->pixbuf)); gdk_pixbuf_fill(data_view->pixbuf, 0x00000000); gwy_data_view_paint(data_view); } }
static GdkPixbuf* gwy_layer_basic_paint(GwyPixmapLayer *layer) { GwyDataField *data_field; GwyLayerBasic *basic_layer; GwyContainer *data; gdouble min = 0.0, max = 0.0; gboolean fixedmin, fixedmax; gboolean fixedrange = FALSE; gwy_debug(" "); g_return_val_if_fail(GWY_IS_LAYER_BASIC(layer), NULL); basic_layer = GWY_LAYER_BASIC(layer); data = GWY_DATA_VIEW_LAYER(layer)->data; /* TODO Container */ if (!gwy_container_gis_object_by_name(data, "/0/show", (GObject**)&data_field)) { data_field = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); fixedrange = TRUE; } g_return_val_if_fail(GWY_IS_DATA_FIELD(data_field), layer->pixbuf); if (fixedrange) { fixedmin = gwy_container_gis_double_by_name(data, "/0/base/min", &min); fixedmax = gwy_container_gis_double_by_name(data, "/0/base/max", &max); if (fixedmin || fixedmax) { if (!fixedmin) min = gwy_data_field_get_min(data_field); if (!fixedmax) max = gwy_data_field_get_max(data_field); } else fixedrange = FALSE; } /* XXX */ /*if (GWY_LAYER_BASIC(layer)->changed)*/ { if (fixedrange) gwy_pixbuf_draw_data_field_with_range(layer->pixbuf, data_field, basic_layer->gradient, min, max); else gwy_pixbuf_draw_data_field(layer->pixbuf, data_field, basic_layer->gradient); basic_layer->changed = FALSE; } return layer->pixbuf; }
static void preview(FacetsControls *controls, FacetsArgs *args) { GwyDataField *dtheta, *dphi, *dfield, *mfield; GwyContainer *data, *fdata; data = controls->mydata; fdata = controls->fdata; add_mask_layer(GWY_DATA_VIEW(controls->view), NULL); add_mask_layer(GWY_DATA_VIEW(controls->fview), &mask_color); dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); mfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/mask")); dtheta = GWY_DATA_FIELD(gwy_container_get_object_by_name(fdata, "/theta")); dphi = GWY_DATA_FIELD(gwy_container_get_object_by_name(fdata, "/phi")); gwy_data_field_mark_facets(dtheta, dphi, args->theta0, args->phi0, args->tolerance, mfield); gwy_data_field_data_changed(mfield); facets_mark_fdata(args, fdata); facets_invalidate(controls); }
static gboolean tip_dilation_check(TipDilationArgs *args, GtkWidget *tip_dilation_window) { GtkWidget *dialog; GwyContainer *data; GwyDataField *dfield1, *dfield2; GwyDataWindow *operand1, *operand2; operand1 = args->win1; operand2 = args->win2; g_return_val_if_fail(GWY_IS_DATA_WINDOW(operand1) && GWY_IS_DATA_WINDOW(operand2), FALSE); data = gwy_data_window_get_data(operand1); dfield1 = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); data = gwy_data_window_get_data(operand2); dfield2 = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); if (fabs((dfield1->xreal/dfield1->xres) /(dfield2->xreal/dfield2->xres) - 1) > 0.01 || fabs((dfield1->yreal/dfield1->yres) /(dfield2->yreal/dfield2->yres) - 1) > 0.01) { dialog = gtk_message_dialog_new(GTK_WINDOW(tip_dilation_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, _("Tip has different range/resolution " "ratio than image. Tip will be " "resampled.")); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } return TRUE; }