Skip to content

Commit

Permalink
Added new giv command $pixelsize to change the pixelsize for a measur…
Browse files Browse the repository at this point in the history
…ements
  • Loading branch information
dov committed Apr 4, 2022
1 parent 99e78f3 commit 10eb535
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 15 deletions.
27 changes: 27 additions & 0 deletions src/giv-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ enum
STRING_HIDE,
STRING_IGNORE,
STRING_TEXT_STYLE,
STRING_PIXEL_SIZE
};

#define COLOR_NONE 0xfffe
Expand Down Expand Up @@ -453,6 +454,10 @@ parse_string (const WordBoundaries& wb,
{
type = STRING_HIDE;
}
if (wb.CheckMatch(0, "$pixelsize"))
{
type = STRING_PIXEL_SIZE;
}
#if 0
if (type == -1)
{
Expand Down Expand Up @@ -926,6 +931,19 @@ giv_parser_giv_marks_data_add_line(GivParser *gp,
g_free(text_style);
break;
}
case STRING_PIXEL_SIZE:
{
double pixel_size = wb.GetFloat(1);
char *pixelsize_unit = NULL;
if (wb.size() > 1)
pixelsize_unit = strdup(wb.GetRestAsString(2));
if (gp->cb_set_pixelsize)
(*(gp->cb_set_pixelsize))(pixel_size, pixelsize_unit, gp->cb_set_pixelsize_data);
if (pixelsize_unit)
g_free(pixelsize_unit);

break;
}
default:
;
#if 0
Expand Down Expand Up @@ -1089,6 +1107,15 @@ giv_parser_set_orientation_callback(GivParser *gp,
gp->cb_set_orientation_data = user_data;
}

void
giv_parser_set_pixelsize_callback(GivParser *gp,
giv_parser_set_pixelsize_t cb,
gpointer user_data)
{
gp->cb_set_pixelsize = cb;
gp->cb_set_pixelsize_data = user_data;
}

void
giv_parser_set_vlock_callback(GivParser *gp,
giv_parser_set_vlock_t cb,
Expand Down
16 changes: 12 additions & 4 deletions src/giv-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@ typedef void (*giv_parser_set_orientation_t)(giv_parser_orientation_t horint,
giv_parser_orientation_t vorint,
gpointer data);

typedef void (*giv_parser_set_pixelsize_t)(double pixel_size,
const gchar *pixelsize_unit,
gpointer data);
typedef void (*giv_parser_set_vlock_t)(gboolean vlock, gpointer data);

typedef struct {
struct GivParser {
GPtrArray* giv_datasets;
GHashTable *style_hash;
giv_parser_file_reference_t cb_file_reference;
giv_parser_file_reference_t cb_file_reference=nullptr;
gpointer cb_file_reference_data;
giv_parser_set_orientation_t cb_set_orientation;
giv_parser_set_orientation_t cb_set_orientation=nullptr;
gpointer cb_set_orientation_data;
giv_parser_set_vlock_t cb_set_vlock;
gpointer cb_set_vlock_data;
giv_parser_set_pixelsize_t cb_set_pixelsize;
gpointer cb_set_pixelsize_data;

// Bounding box of data
double global_mark_max_x;
Expand All @@ -41,7 +46,7 @@ typedef struct {
double global_mark_min_y;

double quiver_scale;
} GivParser;
};

GivParser *giv_parser_new();
void giv_parser_free(GivParser *giv_parser);
Expand All @@ -51,6 +56,9 @@ void giv_parser_set_reference_callback(GivParser *giv_parser,
void giv_parser_set_orientation_callback(GivParser *giv_parser,
giv_parser_set_orientation_t fr,
gpointer user_data);
void giv_parser_set_pixelsize_callback(GivParser *giv_parser,
giv_parser_set_pixelsize_t cb,
gpointer user_data);
void giv_parser_set_vlock_callback(GivParser *giv_parser,
giv_parser_set_vlock_t vlock,
gpointer user_data);
Expand Down
24 changes: 21 additions & 3 deletions src/giv-widget.gob
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ static void cb_image_reference(const char *filename,
gpointer self);
static void cb_set_orientation(giv_parser_orientation_t hflip,
giv_parser_orientation_t vflip,
gpointer self);
gpointer user_data);
static void cb_set_pixelsize(double pixelsize,
const gchar *unit,
gpointer user_data);
static void cb_set_vlock(gboolean vlock,
gpointer self);
gpointer user_data);

%}

Expand Down Expand Up @@ -142,6 +145,9 @@ class Giv:Widget from Gtk:Image:Viewer
&cb_image_reference, (gpointer)self);
giv_parser_set_orientation_callback(selfp->giv_parser,
&cb_set_orientation, (gpointer)self);
giv_parser_set_pixelsize_callback(selfp->giv_parser,
&cb_set_pixelsize,
(gpointer)self);
giv_parser_set_vlock_callback(selfp->giv_parser,
&cb_set_vlock,
(gpointer)self);
Expand Down Expand Up @@ -250,7 +256,7 @@ class Giv:Widget from Gtk:Image:Viewer
mark_set->path_name);
else {
GString *balloon_string = g_string_new("");
g_string_sprintfa(balloon_string, "label = %d", label);
g_string_append_printf(balloon_string, "label = %d", label);
gtk_label_set_text(GTK_LABEL(selfp->w_balloon_label),
balloon_string->str);
g_string_free(balloon_string, TRUE);
Expand Down Expand Up @@ -674,6 +680,8 @@ class Giv:Widget from Gtk:Image:Viewer
signal last NONE (POINTER)
void file_reference(self, const gchar *filename);

signal last NONE (DOUBLE, POINTER)
void set_pixelsize(self, double pixelsize, const gchar *unit);
}

%{
Expand Down Expand Up @@ -1065,6 +1073,16 @@ static void cb_set_orientation(giv_parser_orientation_t orientation_hflip,
hflip, vflip);
}

static void cb_set_pixelsize(double pixelsize,
const gchar *unit,
gpointer user_data)
{
GivWidget *self = GIV_WIDGET(user_data);

// Emit a signal
giv_widget_set_pixelsize(self, pixelsize, unit);
}

static void cb_set_vlock(gboolean vlock,
gpointer user_data)
{
Expand Down
35 changes: 27 additions & 8 deletions src/giv-win.gob
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ static void cb_change_pseudo_color(GtkRadioAction* action,
static void cb_image_reference(GtkWidget *widget,
const char *filename,
gpointer user_data);
static void cb_set_pixelsize(GtkWidget *widget,
double pixelsize,
const gchar *pixelsize_unit,
gpointer user_data);
static void menu_add_widget (GtkUIManager *ui, GtkWidget *widget, GtkContainer *container);
static void
cb_balloon_changed(GtkWidget *widget,
Expand Down Expand Up @@ -859,6 +863,8 @@ class Giv:Win from Gtk:Window
gtk_widget_show(selfp->w_imgv);
g_signal_connect(selfp->w_imgv, "file-reference",
G_CALLBACK(cb_image_reference), self);
g_signal_connect(selfp->w_imgv, "set-pixelsize",
G_CALLBACK(cb_set_pixelsize), self);
g_signal_connect(selfp->w_imgv, "button-press-event",
G_CALLBACK(cb_button_press_event), self);
g_signal_connect(selfp->w_imgv, "button-release-event",
Expand Down Expand Up @@ -1063,7 +1069,7 @@ class Giv:Win from Gtk:Window
}

selfp->idle_index = selfp->filename_list_index;
selfp->do_fit_on_load_image = TRUE;
selfp->do_fit_on_load_image = FALSE;
selfp->idle_handle = g_idle_add(cb_load_image_when_idle,
self);
#if 0
Expand Down Expand Up @@ -2122,9 +2128,9 @@ cb_motion_event(GtkWidget *widget,
do_update_label = false;
}
else if (selfp->do_show_sub_pixel)
g_string_sprintf(info_label, " (%7.3f, %7.3f)", x, y);
g_string_printf(info_label, " (%7.3f, %7.3f)", x, y);
else
g_string_sprintf(info_label, " (%4.0f, %4.0f)", floor(x), floor(y));
g_string_printf(info_label, " (%4.0f, %4.0f)", floor(x), floor(y));

if (do_update_measure_distance) {
double m_dist = sqrt(sqr(selfp->measure_x2 - selfp->measure_x1)
Expand Down Expand Up @@ -2153,11 +2159,11 @@ cb_motion_event(GtkWidget *widget,
// TBD - clean this up so it works for arbitrary size date
double val = giv_image_get_value(selfp->img_org,
(int)x, (int)y, selfp->current_slice);
g_string_sprintfa(info_label, " [");
g_string_sprintfa(info_label,
g_string_append_printf(info_label, " [");
g_string_append_printf(info_label,
selfp->format,
val);
g_string_sprintfa(info_label,
g_string_append_printf(info_label,
"] = #%02X",
(int)val);
if (selfp->w_contrast_view)
Expand All @@ -2168,7 +2174,7 @@ cb_motion_event(GtkWidget *widget,
|| selfp->img_org->img_type == GIVIMAGE_RGBA_U16) {
GivImageRgbAlpha16 rgba = giv_image_get_rgba_value(selfp->img_org,
(int)x, (int)y, selfp->current_slice);
g_string_sprintfa(info_label,
g_string_append_printf(info_label,
" [%3d %3d %3d %3d] = #%08lX",
rgba.red, rgba.green, rgba.blue, rgba.alpha,
(unsigned long)(rgba.red<<24)
Expand All @@ -2179,7 +2185,7 @@ cb_motion_event(GtkWidget *widget,
else {
GivImageRgb16 rgb = giv_image_get_rgb_value(selfp->img_org,
(int)x, (int)y, 0);
g_string_sprintfa(info_label,
g_string_append_printf(info_label,
" [%3d %3d %3d] = #%6X",
rgb.red, rgb.green, rgb.blue,
(int)(rgb.red<<16) + (rgb.green<<8) + rgb.blue);
Expand Down Expand Up @@ -3669,6 +3675,19 @@ static void cb_image_reference(GtkWidget *widget,

}

// Update the pixel size from the giv file
static void cb_set_pixelsize(GtkWidget *widget,
double pixelsize,
const gchar *pixelsize_unit,
gpointer user_data)
{
GivWin *self = (GivWin *)user_data;
selfp->pixelsize = pixelsize;
if (selfp->pixelsize_unit)
g_free(selfp->pixelsize_unit);
selfp->pixelsize_unit = g_strdup(pixelsize_unit);
}

#if 0
static void cb_set_orientation(giv_parser_orientation_t hflip,
giv_parser_orientation_t vflip,
Expand Down

0 comments on commit 10eb535

Please sign in to comment.