Esempio n. 1
0
static void
prof_update_curve(ProfControls *controls,
                  gint i)
{
    GwyGraphCurveModel *gcmodel;
    gdouble xy[4], h;
    gint xl0, yl0, xl1, yl1;
    gint n, lineres;
    gchar *desc;

    g_return_if_fail(gwy_selection_get_object(controls->selection, i, xy));

    /* The ω=0 pixel is always at res/2, for even dimensions it means it is
     * shifted half-a-pixel to the right from the precise centre. */
    xl0 = gwy_data_field_get_xres(controls->psdffield)/2;
    yl0 = gwy_data_field_get_yres(controls->psdffield)/2;
    xl1 = floor(gwy_data_field_rtoj(controls->psdffield, xy[0]));
    yl1 = floor(gwy_data_field_rtoi(controls->psdffield, xy[1]));
    xy[0] += gwy_data_field_get_xoffset(controls->psdffield);
    xy[1] += gwy_data_field_get_yoffset(controls->psdffield);
    h = hypot(controls->hx*xy[0], controls->hy*xy[1])/hypot(xy[0], xy[1]);

    if (!controls->args->fixres) {
        lineres = GWY_ROUND(hypot(abs(xl0 - xl1) + 1, abs(yl0 - yl1) + 1));
        lineres = MAX(lineres, MIN_RESOLUTION);
    }
    else
        lineres = controls->args->resolution;

    gwy_data_field_get_profile(controls->psdffield, controls->line,
                               xl0, yl0, xl1, yl1,
                               lineres,
                               1,
                               controls->args->interpolation);
    gwy_data_line_multiply(controls->line, h);

    n = gwy_graph_model_get_n_curves(controls->gmodel);
    if (i < n) {
        gcmodel = gwy_graph_model_get_curve(controls->gmodel, i);
    }
    else {
        gcmodel = gwy_graph_curve_model_new();
        g_object_set(gcmodel,
                     "mode", GWY_GRAPH_CURVE_LINE,
                     "color", gwy_graph_get_preset_color(i),
                     NULL);
        gwy_graph_model_add_curve(controls->gmodel, gcmodel);
        g_object_unref(gcmodel);
    }

    gwy_graph_curve_model_set_data_from_dataline(gcmodel, controls->line, 0, 0);
    desc = g_strdup_printf(_("PSDF %.0f°"), 180.0/G_PI*atan2(-xy[1], xy[0]));
    g_object_set(gcmodel, "description", desc, NULL);
    g_free(desc);
}
Esempio n. 2
0
static gboolean
curvature_plot_graph(GwyDataField *dfield,
                     const Intersection *i1,
                     const Intersection *i2,
                     GwyGraphModel *gmodel)
{
    GwyGraphCurveModel *gcmodel;
    GwyDataLine *dline;
    gint xres, yres;
    guint i;

    if (!gwy_graph_model_get_n_curves(gmodel)) {
        GwySIUnit *siunitxy, *siunitz;
        gchar *s;

        siunitxy = gwy_si_unit_duplicate(gwy_data_field_get_si_unit_xy(dfield));
        siunitz = gwy_si_unit_duplicate(gwy_data_field_get_si_unit_z(dfield));
        g_object_set(gmodel,
                     "title", _("Curvature Sections"),
                     "si-unit-x", siunitxy,
                     "si-unit-y", siunitz,
                     NULL);
        g_object_unref(siunitxy);
        g_object_unref(siunitz);

        for (i = 0; i < 2; i++) {
            gcmodel = gwy_graph_curve_model_new();
            s = g_strdup_printf(_("Profile %d"), (gint)i+1);
            g_object_set(gcmodel,
                         "description", s,
                         "mode", GWY_GRAPH_CURVE_LINE,
                         "color", gwy_graph_get_preset_color(i),
                         NULL);
            g_free(s);
            gwy_graph_model_add_curve(gmodel, gcmodel);
            g_object_unref(gcmodel);
        }
    }
    else {
        g_assert(gwy_graph_model_get_n_curves(gmodel) == 2);
    }

    dline = gwy_data_line_new(1, 1.0, FALSE);
    xres = gwy_data_field_get_xres(dfield);
    yres = gwy_data_field_get_yres(dfield);
    for (i = 0; i < 2; i++) {
        gint col1 = gwy_data_field_rtoj(dfield, i1[i].x);
        gint row1 = gwy_data_field_rtoi(dfield, i1[i].y);
        gint col2 = gwy_data_field_rtoj(dfield, i2[i].x);
        gint row2 = gwy_data_field_rtoi(dfield, i2[i].y);

        gwy_data_field_get_profile(dfield, dline,
                                   CLAMP(col1, 0, xres-1),
                                   CLAMP(row1, 0, yres-1),
                                   CLAMP(col2, 0, xres-1),
                                   CLAMP(row2, 0, yres-1),
                                   -1, 1, GWY_INTERPOLATION_BILINEAR);
        gwy_data_line_set_offset(dline,
                                 i1[i].t/(i2[i].t - i1[i].t)
                                 * gwy_data_line_get_real(dline));
        gcmodel = gwy_graph_model_get_curve(gmodel, i);
        gwy_graph_curve_model_set_data_from_dataline(gcmodel, dline, 0, 0);
    }
    g_object_unref(dline);

    return TRUE;
}
Esempio n. 3
0
static void
preview(EntropyControls *controls)
{
    EntropyArgs *args = controls->args;
    GwyDataField *dfield = controls->dfield;
    GwyDataField *mfield = controls->mfield;
    GwyGraphModel *gmodel;
    GwyGraphCurveModel *gcmodel;
    GwyDataLine *ecurve;
    gchar buf[24];
    gdouble S, s, Smax = 0.0;

    ecurve = gwy_data_line_new(1, 1.0, FALSE);
    if (args->mode == ENTROPY_VALUES) {
        S = gwy_data_field_area_get_entropy_at_scales(dfield, ecurve,
                                                      mfield, args->masking,
                                                      0, 0,
                                                      dfield->xres,
                                                      dfield->yres,
                                                      0);
        s = gwy_data_field_area_get_rms_mask(dfield,
                                             mfield, args->masking,
                                             0, 0, dfield->xres, dfield->yres);
        Smax = ENTROPY_NORMAL + log(s);
    }
    else {
        GwyDataField *xder = gwy_data_field_new_alike(dfield, FALSE);
        GwyDataField *yder = gwy_data_field_new_alike(dfield, FALSE);

        compute_slopes(controls->dfield,
                       args->fit_plane ? args->kernel_size : 0, xder, yder);
        xder = fake_mask(xder, mfield, args->masking);
        yder = fake_mask(yder, mfield, args->masking);
        if (args->mode == ENTROPY_ANGLES)
            transform_to_sphere(xder, yder);

        S = gwy_data_field_get_entropy_2d_at_scales(xder, yder, ecurve, 0);
        if (args->mode == ENTROPY_SLOPES) {
            s = calculate_sigma2_2d(xder, yder);
            Smax = ENTROPY_NORMAL_2D + log(s);
        }

        g_object_unref(xder);
        g_object_unref(yder);
    }

    g_snprintf(buf, sizeof(buf), "%g", S);
    gtk_label_set_text(GTK_LABEL(controls->entropy), buf);

    if (args->mode != ENTROPY_ANGLES) {
        g_snprintf(buf, sizeof(buf), "%g", Smax - S);
        gtk_label_set_text(GTK_LABEL(controls->entropydef), buf);
    }
    else
        gtk_label_set_text(GTK_LABEL(controls->entropydef), _("N.A."));

    gmodel = gwy_graph_get_model(GWY_GRAPH(controls->graph));
    gwy_graph_model_remove_all_curves(gmodel);
    g_object_set(gmodel,
                 "axis-label-bottom", "log h",
                 "axis-label-left", "S",
                 "label-position", GWY_GRAPH_LABEL_NORTHWEST,
                 NULL);

    if (gwy_data_line_get_min(ecurve) > -0.5*G_MAXDOUBLE) {
        gcmodel = gwy_graph_curve_model_new();
        g_object_set(gcmodel,
                     "description", _("Entropy at scales"),
                     "mode", GWY_GRAPH_CURVE_LINE_POINTS,
                     "color", gwy_graph_get_preset_color(0),
                     NULL);
        gwy_graph_curve_model_set_data_from_dataline(gcmodel, ecurve, 0, 0);
        gwy_graph_model_add_curve(gmodel, gcmodel);
        g_object_unref(gcmodel);
    }

    if (S > -0.5*G_MAXDOUBLE) {
        GwyDataLine *best = gwy_data_line_duplicate(ecurve);
        gdouble *ydata = gwy_data_line_get_data(best);
        guint i, res = gwy_data_line_get_res(best);

        for (i = 0; i < res; i++)
            ydata[i] = S;

        gcmodel = gwy_graph_curve_model_new();
        g_object_set(gcmodel,
                     "description", _("Best estimate"),
                     "mode", GWY_GRAPH_CURVE_LINE,
                     "color", gwy_graph_get_preset_color(1),
                     NULL);
        gwy_graph_curve_model_set_data_from_dataline(gcmodel, best, 0, 0);
        gwy_graph_model_add_curve(gmodel, gcmodel);
        g_object_unref(gcmodel);
        g_object_unref(best);
    }

    g_object_unref(ecurve);

    zoom_in_changed(controls, GTK_TOGGLE_BUTTON(controls->zoom_in));
}
Esempio n. 4
0
static void
add_one_distribution(GwyContainer *container,
                     GwyDataField *dfield,
                     gint ngrains,
                     const gint *grains,
                     GwyGrainQuantity quantity,
                     gint resolution)
{
    static const GwyEnum titles[] = {
        { N_("Grain Projected Area Histogram"),
            GWY_GRAIN_VALUE_PROJECTED_AREA, },
        { N_("Grain Equivalent Square Side Histogram"),
            GWY_GRAIN_VALUE_EQUIV_SQUARE_SIDE, },
        { N_("Grain Equivalent Disc Radius Histogram"),
            GWY_GRAIN_VALUE_EQUIV_DISC_RADIUS, },
        { N_("Grain Surface Area Histogram"),
            GWY_GRAIN_VALUE_SURFACE_AREA, },
        { N_("Grain Maximum Value Histogram"),
            GWY_GRAIN_VALUE_MAXIMUM, },
        { N_("Grain Minimum Value Histogram"),
            GWY_GRAIN_VALUE_MINIMUM, },
        { N_("Grain Mean Value Histogram"),
            GWY_GRAIN_VALUE_MEAN, },
        { N_("Grain Median Value Histogram"),
            GWY_GRAIN_VALUE_MEDIAN, },
        { N_("Grain Projected Boundary Length Histogram"),
            GWY_GRAIN_VALUE_FLAT_BOUNDARY_LENGTH, },
        { N_("Grain Minimum Bounding Size Histogram"),
            GWY_GRAIN_VALUE_MINIMUM_BOUND_SIZE, },
        { N_("Grain Minimum Bounding Direction Histogram"),
            GWY_GRAIN_VALUE_MINIMUM_BOUND_ANGLE, },
        { N_("Grain Maximum Bounding Size Histogram"),
            GWY_GRAIN_VALUE_MAXIMUM_BOUND_SIZE, },
        { N_("Grain Maximum Bounding Direction Histogram"),
            GWY_GRAIN_VALUE_MAXIMUM_BOUND_ANGLE, },
        { N_("Grain Volume (Zero) Histogram"),
            GWY_GRAIN_VALUE_VOLUME_0, },
        { N_("Grain Volume (Minimum) Histogram"),
            GWY_GRAIN_VALUE_VOLUME_MIN, },
        { N_("Grain Volume (Laplacian) Histogram"),
            GWY_GRAIN_VALUE_VOLUME_LAPLACE, },
    };
    static const GwyEnum descriptions[] = {
        { N_("Grain proj. areas"),
            GWY_GRAIN_VALUE_PROJECTED_AREA, },
        { N_("Grain equiv. square sides"),
            GWY_GRAIN_VALUE_EQUIV_SQUARE_SIDE, },
        { N_("Grain equiv. disc radii"),
            GWY_GRAIN_VALUE_EQUIV_DISC_RADIUS, },
        { N_("Grain surf. areas"),
            GWY_GRAIN_VALUE_SURFACE_AREA, },
        { N_("Grain max. values"),
            GWY_GRAIN_VALUE_MAXIMUM, },
        { N_("Grain min. values"),
            GWY_GRAIN_VALUE_MINIMUM, },
        { N_("Grain mean values"),
            GWY_GRAIN_VALUE_MEAN, },
        { N_("Grain median values"),
            GWY_GRAIN_VALUE_MEDIAN, },
        { N_("Grain proj. boundary lengths"),
            GWY_GRAIN_VALUE_FLAT_BOUNDARY_LENGTH, },
        { N_("Grain min. bound. sizes"),
            GWY_GRAIN_VALUE_MINIMUM_BOUND_SIZE, },
        { N_("Grain min. bound. directions"),
            GWY_GRAIN_VALUE_MINIMUM_BOUND_ANGLE, },
        { N_("Grain max. bound. sizes"),
            GWY_GRAIN_VALUE_MAXIMUM_BOUND_SIZE, },
        { N_("Grain max. bound. directions"),
            GWY_GRAIN_VALUE_MAXIMUM_BOUND_ANGLE, },
        { N_("Grain volumes (zero)"),
            GWY_GRAIN_VALUE_VOLUME_0, },
        { N_("Grain volumes (minimum)"),
            GWY_GRAIN_VALUE_VOLUME_MIN, },
        { N_("Grain volumes (laplacian)"),
            GWY_GRAIN_VALUE_VOLUME_LAPLACE, },
    };
    GwyGraphCurveModel *cmodel;
    GwyGraphModel *gmodel;
    GwyDataLine *dataline;
    const gchar *s;

    dataline = gwy_data_field_grains_get_distribution(dfield, NULL, NULL,
                                                      ngrains, grains, quantity,
                                                      resolution);
    gmodel = gwy_graph_model_new();
    cmodel = gwy_graph_curve_model_new();
    gwy_graph_model_add_curve(gmodel, cmodel);
    g_object_unref(cmodel);

    s = gwy_enum_to_string(quantity, titles, G_N_ELEMENTS(titles));
    g_object_set(gmodel,
                 "title", _(s),
                 "axis-label-left", _("count"),
                 NULL);
    gwy_graph_model_set_units_from_data_line(gmodel, dataline);
    s = gwy_enum_to_string(quantity, descriptions, G_N_ELEMENTS(descriptions));
    g_object_set(cmodel, "description", s, NULL);
    gwy_graph_curve_model_set_data_from_dataline(cmodel, dataline, 0, 0);
    g_object_unref(dataline);

    gwy_app_data_browser_add_graph_model(gmodel, container, TRUE);
    g_object_unref(gmodel);
}