Discussion:
[Gwyddion-users] how to use gwy_app_data_window_change_square or similar
Mathias Müller
2014-07-18 08:42:08 UTC
Permalink
Hi,


I just wanted to write kind of module for gwyddion. However, I got stuck at the point where data is displayed which is physically squared but not pixel size.
Looking into the API it says one can get the pixel and physical size of a GwyDataView. How is it possible to reshape the view to make it squared (setting pixel size?)?
I did not find any reference to this. Do I need to find a way on my own by e.g. interpolating the data or is there kind of built-in function to apply?

I found some hints in the gwyddion source, but really don't wanna copy paste foreign code. This simply bloats up the code for this module.

Many thanks in advance!


Cheers,

Mathias
David Nečas (Yeti)
2014-07-20 15:54:16 UTC
Permalink
Post by Mathias Müller
I just wanted to write kind of module for gwyddion. However, I got
stuck at the point where data is displayed which is physically squared
but not pixel size. Looking into the API it says one can get the
pixel and physical size of a GwyDataView. How is it possible to
reshape the view to make it squared (setting pixel size?)?
The style is controled by /0/data/realsquare (for channel 0). TRUE
means physical; FALSE or unset means pixelwise. The function
gwy_app_data_window_change_square() only changes how the channel is
displayed and if this is what you need it is easy.

Otherwise I'm not sure what you want to change:

(a) The physical dimensions, but not the number of pixels, i.e. fix the
pixel size. This can be easily done by gwy_data_field_set_xreal() or
gwy_data_field_set_yreal().

(b) The number of pixels, but not the physical dimensions of the entire
image. This requires resampling. See e.g. square_samples() in
basicops.c.
Post by Mathias Müller
I found some hints in the gwyddion source, but really don't wanna copy
paste foreign code. This simply bloats up the code for this module.
Well, you may want a different logic of what and how to resample than
square_samples(). I would make a standard library function for squaring
the pixels if I was sure what it should do in all cases...

Regards,

Yeti
Mathias Müller
2014-07-21 07:54:42 UTC
Permalink
Yeti,


the first issue you mention is what I exactly intend to do. I have physically squared scans but not pixelwise.
My problem is I do not know where to find the function in the API (header). And if so, it has the structure of:

gwy_app_data_window_change_square (GtkWidget *item, gpointer user_data)

What I actually get in my code is only a GwyDataView to work with.
It will be displayed in the following way:

[code]
GwyContainer *data[2];
GwyDataField *data_field;
GwyDataView *data_view[2];
GwyLayerBasic *base_layer[3];

gwy_app_data_browser_get_current(GWY_APP_DATA_FIELD, &data_field, 0);

data[0] = gwy_container_new();
gwy_container_set_object_by_name(data[0], "/0/data", data_field) ;
data_view[0] = GWY_DATA_VIEW(gwy_data_view_new(data[0]));

base_layer[0] = GWY_LAYER_BASIC(gwy_layer_basic_new());
g_object_set(base_layer[0], "data-key", "/0/data", "gradient-key", "/0/base/palette", "range-type-key", "/0/base/range-type", NULL);
gwy_data_view_set_base_layer(data_view[0], (GwyPixmapLayer*) base_layer[0]);

gtk_container_add(GTK_CONTAINER(Viewport), GTK_WIDGET(data_view[0]));
[/code]

Is it sufficient to apply square_samples() to data[0] before adding the data_view[0] to the viewport?

Cheers,

/M
Post by David Nečas (Yeti)
Post by Mathias Müller
I just wanted to write kind of module for gwyddion. However, I got
stuck at the point where data is displayed which is physically squared
but not pixel size. Looking into the API it says one can get the
pixel and physical size of a GwyDataView. How is it possible to
reshape the view to make it squared (setting pixel size?)?
The style is controled by /0/data/realsquare (for channel 0). TRUE
means physical; FALSE or unset means pixelwise. The function
gwy_app_data_window_change_square() only changes how the channel is
displayed and if this is what you need it is easy.
(a) The physical dimensions, but not the number of pixels, i.e. fix the
pixel size. This can be easily done by gwy_data_field_set_xreal() or
gwy_data_field_set_yreal().
(b) The number of pixels, but not the physical dimensions of the entire
image. This requires resampling. See e.g. square_samples() in
basicops.c.
Post by Mathias Müller
I found some hints in the gwyddion source, but really don't wanna copy
paste foreign code. This simply bloats up the code for this module.
Well, you may want a different logic of what and how to resample than
square_samples(). I would make a standard library function for squaring
the pixels if I was sure what it should do in all cases...
Regards,
Yeti
David Nečas (Yeti)
2014-07-21 08:10:03 UTC
Permalink
Post by Mathias Müller
My problem is I do not know where to find the function in the API
gwy_app_data_window_change_square (GtkWidget *item, gpointer user_data)
This is an internal function that serves as a callback for activation of
the data window top-left corner menu. You should not call it and, in
fact, you can't.
Post by Mathias Müller
Is it sufficient to apply square_samples() to data[0] before adding the data_view[0] to the viewport?
As I said, square_samples() creates new data fields with *resampled*
Post by Mathias Müller
the first issue you mention is what I exactly intend to do. I have
physically squared scans but not pixelwise.
I'm assuming you just want to change how they are displayed (that was
the first issue). So just set

gwy_data_view_set_data_prefix(data_view, "/0/data");

which should be set anyway and then change the realsquare setting

gwy_container_set_boolean_by_name(container, "/0/data/realsquare", TRUE);

Regards,

Yeti
Mathias Müller
2014-07-21 08:31:41 UTC
Permalink
Yeti,

thanks. This works pretty well. But I have to skip gwy_data_view_set_data_prefix(data_view, "/0/data");. I receive a segmentation fault
when adding this line.

Another thing, the "realsquare" setting works, but only after changing the channel. The initial channel I display is still false. But I guess
I may fix this soon...

Cheers,

/M
Post by David Nečas (Yeti)
Post by Mathias Müller
My problem is I do not know where to find the function in the API
gwy_app_data_window_change_square (GtkWidget *item, gpointer user_data)
This is an internal function that serves as a callback for activation of
the data window top-left corner menu. You should not call it and, in
fact, you can't.
Post by Mathias Müller
Is it sufficient to apply square_samples() to data[0] before adding the data_view[0] to the viewport?
As I said, square_samples() creates new data fields with *resampled*
Post by Mathias Müller
the first issue you mention is what I exactly intend to do. I have
physically squared scans but not pixelwise.
I'm assuming you just want to change how they are displayed (that was
the first issue). So just set
gwy_data_view_set_data_prefix(data_view, "/0/data");
which should be set anyway and then change the realsquare setting
gwy_container_set_boolean_by_name(container, "/0/data/realsquare", TRUE);
Regards,
Yeti
David Nečas (Yeti)
2014-07-21 09:15:36 UTC
Permalink
Post by Mathias Müller
thanks. This works pretty well. But I have to skip gwy_data_view_set_data_prefix(data_view, "/0/data");. I receive a segmentation fault
when adding this line.
This is done in dozens of modules in Gwyddion so it should not crash.
Maybe if the widgets are set up in an unusual order? I cannot tell much
more without seeing the crash (or at least seeing the code and
backtrace).
Post by Mathias Müller
Another thing, the "realsquare" setting works, but only after changing
the channel.
This is because of the missing gwy_data_view_set_data_prefix(). Since
the data view does not watch the setting, it will notice the new value
just coincidentally when something else changes.

Regards,

Yeti
Mathias Müller
2014-07-21 09:22:14 UTC
Permalink
Indeed, I used at the wrong location. it works now flawless.

Many thanks, Yeti.


/M
Post by David Nečas (Yeti)
Post by Mathias Müller
thanks. This works pretty well. But I have to skip gwy_data_view_set_data_prefix(data_view, "/0/data");. I receive a segmentation fault
when adding this line.
This is done in dozens of modules in Gwyddion so it should not crash.
Maybe if the widgets are set up in an unusual order? I cannot tell much
more without seeing the crash (or at least seeing the code and
backtrace).
Post by Mathias Müller
Another thing, the "realsquare" setting works, but only after changing
the channel.
This is because of the missing gwy_data_view_set_data_prefix(). Since
the data view does not watch the setting, it will notice the new value
just coincidentally when something else changes.
Regards,
Yeti
Loading...