Esempio n. 1
0
static void
prof_execute(ProfControls *controls,
             GwyContainer *data)
{
    GwyGraphCurveModel *gcmodel;
    GwyGraphModel *gmodel;
    ProfArgs *args = controls->args;
    gchar *s;
    gint i, n;

    n = gwy_selection_get_data(controls->selection, NULL);
    g_return_if_fail(n);

    g_object_set(controls->gmodel, "label-visible", TRUE, NULL);
    if (!args->separate) {
        gwy_app_add_graph_or_curves(controls->gmodel,
                                    data, &args->target_graph, 1);
        return;
    }

    for (i = 0; i < n; i++) {
        gmodel = gwy_graph_model_new_alike(controls->gmodel);
        gcmodel = gwy_graph_model_get_curve(controls->gmodel, i);
        gcmodel = gwy_graph_curve_model_duplicate(gcmodel);
        gwy_graph_model_add_curve(gmodel, gcmodel);
        g_object_unref(gcmodel);
        g_object_get(gcmodel, "description", &s, NULL);
        g_object_set(gmodel, "title", s, NULL);
        g_free(s);
        gwy_app_data_browser_add_graph_model(gmodel, data, TRUE);
        g_object_unref(gmodel);
    }
}
Esempio n. 2
0
/**
 * gwy_app_add_graph_or_curves:
 * @gmodel: A graph model with curves to add.
 * @data: Data container where the graph would be added.
 * @target_graph: Graph where curves would be added.
 * @colorstep: Curve block size as in gwy_graph_model_append_curves().
 *
 * Puts the curves of a graph to another graph if possible, or adds the graph
 * as new.
 *
 * If the units of @gmodel are compatible with the units of the graph
 * identified by @target_graph the curves are copied to the target graph with
 * gwy_graph_model_append_curves().
 *
 * In all other cases, including when @target_graph does not refer to any
 * existing graph, the graph model is added to @data as a new graph.
 *
 * Either way, the caller usually need to release its own reference afterwards.
 *
 * This function is useful particularly in modules that create graphs and can
 * be run non-interactively.
 *
 * Returns: The numerical identifier of the newly-created graph of one was
 *          created.  Value -1 is returned if curves were added to
 *          @target_graph.
 *
 * Since: 2.41
 **/
gint
gwy_app_add_graph_or_curves(GwyGraphModel *gmodel,
                            GwyContainer *data,
                            const GwyAppDataId *target_graph,
                            gint colorstep)
{
    GwyAppDataId tgtgraph = *target_graph;

    if (gwy_app_data_id_verify_graph(&tgtgraph)) {
        GQuark quark = gwy_app_get_graph_key_for_id(tgtgraph.id);
        GwyContainer *data2 = gwy_app_data_browser_get(tgtgraph.datano);
        GwyGraphModel *target_gmodel = gwy_container_get_object(data2, quark);

        g_return_val_if_fail(GWY_IS_GRAPH_MODEL(target_gmodel), -1);
        if (gwy_graph_model_units_are_compatible(gmodel, target_gmodel)) {
            gwy_graph_model_append_curves(target_gmodel, gmodel, colorstep);
            return -1;
        }
    }
    g_return_val_if_fail(GWY_IS_CONTAINER(data), FALSE);
    return gwy_app_data_browser_add_graph_model(gmodel, data, TRUE);
}
Esempio n. 3
0
static void
extract_path_do(GwyContainer *data,
                GwyDataField *dfield, gboolean realsquare,
                GwySelection *selection,
                const ExtrPathArgs *args)
{
    GwyGraphModel *gmodel;
    GwySpline *spline;
    GwyXY *points, *tangents;
    GwySIUnit *xyunit;
    gdouble dx, dy, qx, qy, h, l, length, slackness;
    gdouble *xdata, *ydata;
    guint n, i;
    gboolean closed;

    /* This can only be satisfied in non-interactive use.  Doing nothing is
     * the best option in this case. */
    if (!selection || (n = gwy_selection_get_data(selection, NULL)) < 2)
        return;

    points = rescale_points(selection, dfield, realsquare, &dx, &dy, &qx, &qy);
    h = MIN(dx, dy);
    spline = gwy_spline_new_from_points(points, n);
    g_object_get(selection,
                 "slackness", &slackness,
                 "closed", &closed,
                 NULL);
    gwy_spline_set_closed(spline, closed);
    gwy_spline_set_slackness(spline, slackness);
    g_free(points);

    length = gwy_spline_length(spline);

    /* This would give natural sampling for a straight line along some axis. */
    n = GWY_ROUND(length + 1.0);
    points = g_new(GwyXY, n);
    tangents = g_new(GwyXY, n);
    xdata = g_new(gdouble, n);
    ydata = g_new(gdouble, n);
    gwy_spline_sample_uniformly(spline, points, tangents, n);
    qx *= dx;
    qy *= dy;
    for (i = 0; i < n; i++) {
        points[i].x *= qx;
        points[i].y *= qy;
        GWY_SWAP(gdouble, tangents[i].x, tangents[i].y);
        tangents[i].x *= qx;
        tangents[i].y *= -qy;
        l = sqrt(tangents[i].x*tangents[i].x + tangents[i].y*tangents[i].y);
        if (h > 0.0) {
            tangents[i].x /= l;
            tangents[i].y /= l;
        }
        xdata[i] = i/(n - 1.0)*length*h;
    }

    xyunit = gwy_data_field_get_si_unit_xy(dfield);
    if ((gmodel = create_graph_model(points, xdata, ydata, n,
                                     args->x, args->y))) {
        g_object_set(gmodel,
                     "axis-label-left", _("Position"),
                     "axis-label-bottom", _("Distance"),
                     "si-unit-x", xyunit,
                     "si-unit-y", xyunit,
                     NULL);
        gwy_app_data_browser_add_graph_model(gmodel, data, TRUE);
        g_object_unref(gmodel);
    }

    if ((gmodel = create_graph_model(tangents, xdata, ydata, n,
                                     args->vx, args->vy))) {
        g_object_set(gmodel,
                     "axis-label-left", _("Tangent"),
                     "axis-label-bottom", _("Distance"),
                     "si-unit-x", xyunit,
                     NULL);
        gwy_app_data_browser_add_graph_model(gmodel, data, TRUE);
        g_object_unref(gmodel);
    }

    g_free(ydata);
    g_free(xdata);
    g_free(points);
    g_free(tangents);
}
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);
}