static GObject* gwy_spectra_duplicate_real(GObject *object) { gint i; GwySpectra *spectra, *duplicate; GwyDataLine *dataline; g_return_val_if_fail(GWY_IS_SPECTRA(object), NULL); spectra = GWY_SPECTRA(object); duplicate = gwy_spectra_new_alike(spectra); duplicate->title = g_strdup(spectra->title); if (spectra->si_unit_xy) duplicate->si_unit_xy = gwy_si_unit_duplicate(spectra->si_unit_xy); g_array_append_vals(duplicate->spectra, spectra->spectra->data, spectra->spectra->len); /* Duplicate the spectra themselves */ for (i = 0; i < duplicate->spectra->len; i++) { dataline = g_array_index(duplicate->spectra, GwySpectrum, i).ydata; g_array_index(duplicate->spectra, GwySpectrum, i).ydata = gwy_data_line_duplicate(dataline); } return (GObject*)duplicate; }
/** * gwy_spectra_get_spectra_interp: * @spectra: A spectra object. * @x: x coordinate for spectrum * @y: y coordinate fro spectrum * * In future will: * Interpolates a spectrum at some arbitary point specified by x,y. * If the point is within the triangle made by three measured spectra * then these are used else it is interpolated from the nearest two or one. * But currently: * Returns a newly created dataline, corresponding to the nearest spectrum. * * Returns: A newly created dataline. **/ GwyDataLine* gwy_spectra_get_spectra_interp(GwySpectra *spectra, gdouble x, gdouble y) { guint i; /* TODO: Function to do a proper interpolation. */ g_return_val_if_fail(GWY_IS_SPECTRA(spectra), NULL); if (spectra->ncurves == 0) { g_critical("Contains no spectra"); return NULL; } i = gwy_spectra_xytoi(spectra, x, y); return gwy_data_line_duplicate(gwy_spectra_get_spectrum(spectra, i)); }
static void gwy_spectra_clone_real(GObject *source, GObject *copy) { GwySpectra *spectra, *clone; GwyDataLine *dataline; guint i; g_return_if_fail(GWY_IS_SPECTRA(source)); g_return_if_fail(GWY_IS_SPECTRA(copy)); spectra = GWY_SPECTRA(source); clone = GWY_SPECTRA(copy); /* Title */ g_free(clone->title); clone->title = g_strdup(spectra->title); /* Remove any existing datalines in the clone */ for (i = 0; i < clone->spectra->len; i++) { g_object_unref(g_array_index(clone->spectra, GwySpectrum, i).ydata); } /* Copy the spectra to clone */ g_array_set_size(clone->spectra, 0); g_array_append_vals(clone->spectra, spectra->spectra->data, spectra->spectra->len); /* Clone the spectra theselves */ for (i = 0; i < spectra->spectra->len; i++) { dataline = g_array_index(clone->spectra, GwySpectrum, i).ydata; g_array_index(clone->spectra, GwySpectrum, i).ydata = gwy_data_line_duplicate(dataline); } /* SI Units can be NULL */ if (spectra->si_unit_xy && clone->si_unit_xy) gwy_serializable_clone(G_OBJECT(spectra->si_unit_xy), G_OBJECT(clone->si_unit_xy)); else if (spectra->si_unit_xy && !clone->si_unit_xy) clone->si_unit_xy = gwy_si_unit_duplicate(spectra->si_unit_xy); else if (!spectra->si_unit_xy && clone->si_unit_xy) gwy_object_unref(clone->si_unit_xy); }
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)); }