コード例 #1
0
ファイル: surface.c プロジェクト: cbuehler/gwyddion
static GObject*
gwy_surface_deserialize(const guchar *buffer,
                        gsize size,
                        gsize *position)
{
    guint32 datasize = 0;
    GwySIUnit *si_unit_xy = NULL, *si_unit_z = NULL;
    GwySurface *surface;
    GwyXYZ *data = NULL;
    GwySerializeSpec spec[] = {
        { 'o', "si_unit_xy", &si_unit_xy, NULL, },
        { 'o', "si_unit_z", &si_unit_z, NULL, },
        { 'D', "data", &data, &datasize, },
    };

    g_return_val_if_fail(buffer, NULL);

    if (!gwy_serialize_unpack_object_struct(buffer, size, position,
                                            GWY_SURFACE_TYPE_NAME,
                                            G_N_ELEMENTS(spec), spec)) {
        g_free(data);
        GWY_OBJECT_UNREF(si_unit_xy);
        GWY_OBJECT_UNREF(si_unit_z);
        return NULL;
    }
    if (datasize % 3 != 0) {
        g_critical("Serialized %s data size %u not a multiple of 3",
                   GWY_SURFACE_TYPE_NAME, datasize);
        g_free(data);
        GWY_OBJECT_UNREF(si_unit_xy);
        GWY_OBJECT_UNREF(si_unit_z);
        return NULL;
    }

    surface = gwy_surface_new();

    g_free(surface->data);
    surface->data = data;
    surface->n = datasize/3;

    if (si_unit_z) {
        GWY_OBJECT_UNREF(surface->priv->si_unit_z);
        surface->priv->si_unit_z = si_unit_z;
    }
    if (si_unit_xy) {
        GWY_OBJECT_UNREF(surface->priv->si_unit_xy);
        surface->priv->si_unit_xy = si_unit_xy;
    }

    return (GObject*)surface;
}
コード例 #2
0
ファイル: surface.c プロジェクト: svn2github/gwyddion
void
test_surface_units_assign(void)
{
    GwySurface *surface = gwy_surface_new(), *surface2 = gwy_surface_new();
    GwyUnit *xyunit = gwy_surface_get_xyunit(surface);
    GwyUnit *zunit = gwy_surface_get_zunit(surface);
    guint count_xy = 0;
    guint count_z = 0;

    g_signal_connect_swapped(xyunit, "changed",
                             G_CALLBACK(record_signal), &count_xy);
    g_signal_connect_swapped(zunit, "changed",
                             G_CALLBACK(record_signal), &count_z);

    gwy_unit_set_from_string(gwy_surface_get_xyunit(surface), "m", NULL);
    g_assert_cmpuint(count_xy, ==, 1);
    g_assert_cmpuint(count_z, ==, 0);

    gwy_unit_set_from_string(gwy_surface_get_zunit(surface), "s", NULL);
    g_assert_cmpuint(count_xy, ==, 1);
    g_assert_cmpuint(count_z, ==, 1);

    gwy_surface_assign(surface, surface2);
    g_assert_cmpuint(count_xy, ==, 2);
    g_assert_cmpuint(count_z, ==, 2);
    g_assert(gwy_surface_get_xyunit(surface) == xyunit);
    g_assert(gwy_surface_get_zunit(surface) == zunit);

    // Try again to see if the signal counts change.
    gwy_surface_assign(surface, surface2);
    g_assert_cmpuint(count_xy, ==, 2);
    g_assert_cmpuint(count_z, ==, 2);
    g_assert(gwy_surface_get_xyunit(surface) == xyunit);
    g_assert(gwy_surface_get_zunit(surface) == zunit);

    g_object_unref(surface2);
    g_object_unref(surface);
}
コード例 #3
0
ファイル: surface.c プロジェクト: svn2github/gwyddion
        }
        g_object_unref(surface);
    }

    g_rand_free(rng);
}

void
test_surface_get_data(void)
{
    const GwyXYZ data[] = {
        { .x = 1.0, .y = G_PI, .z = -1.25 },
        { .x = 1.5, .y = G_SQRT2, .z = GWY_SQRT3 },
    };
    guint count_n = 0;
    GwySurface *surface = gwy_surface_new();
    g_signal_connect_swapped(surface, "notify::n-points",
                             G_CALLBACK(record_signal), &count_n);
    gwy_surface_set_data_full(surface, data, G_N_ELEMENTS(data));
    g_assert_cmpuint(count_n, ==, 1);
    g_assert_cmpuint(surface->n, ==, G_N_ELEMENTS(data));
    g_assert((const GwyXYZ*)surface->data != data);
    guint n;
    const GwyXYZ *surfacedata = gwy_surface_get_data_full(surface, &n);
    g_assert_cmpuint(n, ==, G_N_ELEMENTS(data));
    g_assert(surfacedata == (const GwyXYZ*)surface->data);
    for (guint i = 0; i < n; i++) {
        g_assert_cmpfloat(surfacedata[i].x, ==, data[i].x);
        g_assert_cmpfloat(surfacedata[i].y, ==, data[i].y);
        g_assert_cmpfloat(surfacedata[i].z, ==, data[i].z);
    }