aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/control.h2
-rw-r--r--src/imagedisplay.c328
-rw-r--r--src/imagedisplay.h59
-rw-r--r--src/ipr.c3
-rw-r--r--src/main.c42
-rw-r--r--src/mapping.c11
-rw-r--r--src/prealign.c14
-rw-r--r--src/readpng.c4
-rw-r--r--src/utils.c3
-rw-r--r--src/utils.h4
10 files changed, 270 insertions, 200 deletions
diff --git a/src/control.h b/src/control.h
index 2e16079..5ab8efd 100644
--- a/src/control.h
+++ b/src/control.h
@@ -49,7 +49,7 @@ typedef enum {
typedef struct imagerecord_struct {
- uint16_t *image;
+ uint16_t *image;
double tilt;
double omega;
diff --git a/src/imagedisplay.c b/src/imagedisplay.c
index b6d8af9..dfe54ca 100644
--- a/src/imagedisplay.c
+++ b/src/imagedisplay.c
@@ -23,21 +23,20 @@
#include "imagedisplay.h"
#include "utils.h"
+#include "control.h"
/* Free pixbuf data when reference count drops to zero */
static void imagedisplay_free_data(guchar *image_eightbit, ImageDisplay *imagedisplay) {
free(image_eightbit);
}
-static void imagedisplay_update(ImageDisplay *imagedisplay) {
+void imagedisplay_rescale(ImageDisplay *imagedisplay, unsigned int v_w, unsigned int v_h) {
- unsigned int w, h, v_w, v_h;
+ unsigned int w, h;
float aspect_image, aspect_window;
-
- w = imagedisplay->width;
- h = imagedisplay->height;
- v_w = imagedisplay->view_width;
- v_h = imagedisplay->view_height;
+
+ w = imagedisplay->imagerecord.width;
+ h = imagedisplay->imagerecord.height;
/* Preserve aspect ratio */
aspect_image = (float)w/h;
@@ -50,47 +49,44 @@ static void imagedisplay_update(ImageDisplay *imagedisplay) {
/* Create the scaled pixbuf from the 8-bit display data */
imagedisplay->pixbuf_scaled = gdk_pixbuf_scale_simple(imagedisplay->pixbuf, v_w, v_h, GDK_INTERP_BILINEAR);
-
- /* Create the image with the scaled pixbuf */
- if ( !imagedisplay->image ) {
- imagedisplay->image = gtk_image_new_from_pixbuf(imagedisplay->pixbuf_scaled);
- gtk_container_add(GTK_CONTAINER(imagedisplay->window), imagedisplay->image);
- gtk_widget_show(imagedisplay->image);
- } else {
- gtk_image_set_from_pixbuf(GTK_IMAGE(imagedisplay->image), GDK_PIXBUF(imagedisplay->pixbuf_scaled));
- }
+ imagedisplay->view_width = v_w;
+ imagedisplay->view_height = v_h;
}
static gboolean imagedisplay_configure_event(GtkWidget *widget, GdkEventConfigure *event, ImageDisplay *imagedisplay) {
- imagedisplay->view_width = event->width;
- imagedisplay->view_height = event->height;
- imagedisplay_update(imagedisplay);
-
+ imagedisplay->drawingarea_width = event->width;
+ imagedisplay->drawingarea_height = event->height;
+ imagedisplay_rescale(imagedisplay, event->width, event->height);
+
return FALSE;
}
-static void imagedisplay_put_data(ImageDisplay *imagedisplay, uint16_t *image16) {
+static void imagedisplay_put_data(ImageDisplay *imagedisplay, ImageRecord imagerecord) {
unsigned int x, y;
unsigned int w, h;
int min, max;
+ double c, scale;
- h = imagedisplay->height;
- w = imagedisplay->width;
+ h = imagerecord.height;
+ w = imagerecord.width;
min = 2<<15; max = 0;
for ( y=0; y<h; y++ ) {
for ( x=0; x<w; x++ ) {
uint16_t val;
- val = image16[x+w*y];
+ val = imagerecord.image[x+w*y];
if ( val > max ) max = val;
if ( val < min ) min = val;
}
}
- printf("min=%i, max=%i\n", min, max);
+
+ c = 0.1;
+ scale = 255.0 / log(1+c*(max-min));
+
/* Turn 16-bit image data into 8-bit display data */
imagedisplay->data = malloc(3*w*h);
for ( y=0; y<h; y++ ) {
@@ -98,8 +94,8 @@ static void imagedisplay_put_data(ImageDisplay *imagedisplay, uint16_t *image16)
uint16_t val16, val8;
- val16 = image16[x+w*y];
- val8 = (255*(val16-min)) / (max-min);
+ val16 = imagerecord.image[x+w*y];
+ val8 = scale * log(1+c*(val16-min));
imagedisplay->data[3*( x+w*(h-1-y) )] = val8;
imagedisplay->data[3*( x+w*(h-1-y) )+1] = val8;
@@ -112,169 +108,187 @@ static void imagedisplay_put_data(ImageDisplay *imagedisplay, uint16_t *image16)
imagedisplay->pixbuf = gdk_pixbuf_new_from_data(imagedisplay->data, GDK_COLORSPACE_RGB, FALSE, 8, w, h, w*3,
(GdkPixbufDestroyNotify)imagedisplay_free_data, imagedisplay);
- imagedisplay_update(imagedisplay);
-
}
static void imagedisplay_close(GtkWidget *widget, ImageDisplay *imagedisplay) {
+
+ ImageDisplayMark *cur;
+
+ if ( imagedisplay->flags & IMAGEDISPLAY_QUIT_IF_CLOSED ) {
+ gtk_exit(0);
+ }
+
+ g_object_unref(G_OBJECT(imagedisplay->gc_centre));
+ g_object_unref(G_OBJECT(imagedisplay->gc_tiltaxis));
+ g_object_unref(G_OBJECT(imagedisplay->gc_marks));
+
+ cur = imagedisplay->marks;
+ while ( cur ) {
+ ImageDisplayMark *next = cur->next;
+ free(cur);
+ cur = next;
+ }
+
free(imagedisplay);
+
}
-/* Display an image */
-ImageDisplay *imagedisplay_open(uint16_t *image, unsigned int width, unsigned int height, const char *title) {
+#define imagedisplay_draw_line(gc,x1,y1,x2,y2) (gdk_draw_line(drawingarea->window,gc, \
+ xoffs+(x1), yoffs+imagedisplay->view_height-(y1), \
+ xoffs+(x2), yoffs+imagedisplay->view_height-(y2)))
- ImageDisplay *imagedisplay;
- GdkGeometry geom;
+static gboolean imagedisplay_redraw(GtkWidget *drawingarea, GdkEventExpose *event, ImageDisplay *imagedisplay) {
- imagedisplay = malloc(sizeof(ImageDisplay));
- imagedisplay->image = NULL;
- imagedisplay->width = width;
- imagedisplay->height = height;
- imagedisplay->view_width = 512;
- imagedisplay->view_height = 512;
- imagedisplay->title = strdup(title);
-
- imagedisplay->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_title(GTK_WINDOW(imagedisplay->window), imagedisplay->title);
-
- imagedisplay_put_data(imagedisplay, image);
+ gint xoffs, yoffs;
+ double scale;
+ ImageDisplayMark *cur;
- g_signal_connect(GTK_OBJECT(imagedisplay->window), "destroy", G_CALLBACK(imagedisplay_close), imagedisplay);
- g_signal_connect(GTK_OBJECT(imagedisplay->window), "configure_event", G_CALLBACK(imagedisplay_configure_event), imagedisplay);
-
- geom.min_width = 128;
- geom.min_height = 128;
- gtk_window_set_geometry_hints(GTK_WINDOW(imagedisplay->window), GTK_WIDGET(imagedisplay->image), &geom, GDK_HINT_MIN_SIZE);
+ xoffs = (imagedisplay->drawingarea_width - imagedisplay->view_width) / 2;
+ yoffs = (imagedisplay->drawingarea_height - imagedisplay->view_height) / 2;
+ scale = (double)imagedisplay->view_width/imagedisplay->imagerecord.width;
- gtk_window_set_default_size(GTK_WINDOW(imagedisplay->window), 512, 512);
+ gdk_draw_pixbuf(drawingarea->window, drawingarea->style->bg_gc[GTK_WIDGET_STATE(drawingarea)], imagedisplay->pixbuf_scaled,
+ 0, 0, xoffs, yoffs, imagedisplay->view_width, imagedisplay->view_height,
+ GDK_RGB_DITHER_NONE, 0, 0);
- gtk_widget_show_all(imagedisplay->window);
+ if ( imagedisplay->flags & IMAGEDISPLAY_SHOW_TILT_AXIS ) {
+ imagedisplay_draw_line(imagedisplay->gc_tiltaxis,
+ imagedisplay->imagerecord.x_centre * scale,
+ imagedisplay->imagerecord.y_centre * scale,
+ (imagedisplay->imagerecord.x_centre + imagedisplay->imagerecord.width) * scale,
+ (imagedisplay->imagerecord.y_centre + imagedisplay->imagerecord.width
+ * tan(deg2rad(imagedisplay->imagerecord.omega))) * scale);
+ imagedisplay_draw_line(imagedisplay->gc_tiltaxis,
+ imagedisplay->imagerecord.x_centre * scale,
+ imagedisplay->imagerecord.y_centre * scale,
+ (imagedisplay->imagerecord.x_centre - imagedisplay->imagerecord.width) * scale,
+ (imagedisplay->imagerecord.y_centre - imagedisplay->imagerecord.width
+ * tan(deg2rad(imagedisplay->imagerecord.omega))) * scale);
+ }
- return imagedisplay;
+ if ( imagedisplay->flags & IMAGEDISPLAY_SHOW_CENTRE ) {
+ imagedisplay_draw_line(imagedisplay->gc_centre,
+ imagedisplay->imagerecord.x_centre * scale - 10,
+ imagedisplay->imagerecord.y_centre * scale,
+ imagedisplay->imagerecord.x_centre * scale + 10,
+ imagedisplay->imagerecord.y_centre * scale);
+ imagedisplay_draw_line(imagedisplay->gc_centre,
+ imagedisplay->imagerecord.x_centre * scale,
+ imagedisplay->imagerecord.y_centre * scale - 10,
+ imagedisplay->imagerecord.x_centre * scale,
+ imagedisplay->imagerecord.y_centre * scale + 10);
+ }
-}
+ cur = imagedisplay->marks;
+ while ( cur ) {
+ gdk_draw_arc(drawingarea->window, imagedisplay->gc_marks, FALSE,
+ xoffs + cur->x*scale,
+ yoffs + cur->y*scale,
+ 10, 10, 0, 64*360);
+ cur = cur->next;
+ }
-void imagedisplay_add_tilt_axis(ImageDisplay *imagedisplay, double xc, double yc, double omega) {
+ return FALSE;
- guchar *image_eightbit;
- int w, h;
- double gradient;
+}
- if ( !imagedisplay->pixbuf ) return;
+static gint imagedisplay_realize(GtkWidget *widget, ImageDisplay *imagedisplay) {
- w = imagedisplay->width;
- h = imagedisplay->height; /* Size of pixbuf */
+ GdkColor colour;
+
+ imagedisplay->gc_centre = gdk_gc_new(imagedisplay->drawingarea->window);
+ gdk_color_parse("yellow", &colour);
+ gdk_gc_set_rgb_fg_color(imagedisplay->gc_centre, &colour);
+
+ imagedisplay->gc_tiltaxis = gdk_gc_new(imagedisplay->drawingarea->window);
+ gdk_color_parse("#6600dd", &colour);
+ gdk_gc_set_rgb_fg_color(imagedisplay->gc_tiltaxis, &colour);
- g_object_get(G_OBJECT(imagedisplay->pixbuf), "pixels", &image_eightbit, NULL);
-
- gradient = tan(M_PI*omega/180);
-
- if ( gradient > 1 ) {
- double xs;
- signed int x, y;
- gradient = 1/gradient;
- /* Start at the centre and draw a line out in each direction until it hits an edge.
- This makes the whole thing a lot easier. */
- xs = xc; y = yc;
- do {
- x = xs;
- image_eightbit[3*(x+w*(h-1-y))+0] = 255;
- image_eightbit[3*(x+w*(h-1-y))+1] = 255;
- image_eightbit[3*(x+w*(h-1-y))+2] = 0;
- y++;
- xs += gradient;
- } while ( (xs<w) && (y<h) && (xs>=0) && (y>=0) );
- xs = xc; y = yc;
- do {
- x = xs;
- image_eightbit[3*(x+w*(h-1-y))+0] = 255;
- image_eightbit[3*(x+w*(h-1-y))+1] = 255;
- image_eightbit[3*(x+w*(h-1-y))+2] = 0;
- y--;
- xs -= gradient;
- } while ( (xs<w) && (y<h) && (xs>=0) && (y>=0) );
- } else {
- double ys;
- signed int x, y;
- x = xc; ys = yc;
- do {
- y = ys;
- image_eightbit[3*(x+w*(h-1-y))+0] = 255;
- image_eightbit[3*(x+w*(h-1-y))+1] = 255;
- image_eightbit[3*(x+w*(h-1-y))+2] = 0;
- x++;
- ys += gradient;
- } while ( (x<w) && (ys<h) && (x>=0) && (ys>=0) );
-
- x = xc; ys = yc;
- do {
- y = ys;
- image_eightbit[3*(x+w*(h-1-y))+0] = 255;
- image_eightbit[3*(x+w*(h-1-y))+1] = 255;
- image_eightbit[3*(x+w*(h-1-y))+2] = 0;
- x--;
- ys -= gradient;
- } while ( (x<w) && (ys<h) && (x>=0) && (ys>=0) );
- }
+ imagedisplay->gc_marks = gdk_gc_new(imagedisplay->drawingarea->window);
+ gdk_color_parse("#dd0000", &colour);
+ gdk_gc_set_rgb_fg_color(imagedisplay->gc_marks, &colour);
+
+ return 0;
}
-void imagedisplay_mark_point(ImageDisplay *imagedisplay, unsigned int x, unsigned int y) {
-
- guchar *image_eightbit;
- int xd, yd;
- int w, h;
+/* Display an image */
+ImageDisplay *imagedisplay_open_with_message(ImageRecord imagerecord, const char *title, const char *message,
+ ImageDisplayFlags flags, GCallback mouse_click_func) {
- if ( !imagedisplay->pixbuf ) return;
+ ImageDisplay *imagedisplay;
+ GdkGeometry geom;
- w = imagedisplay->width;
- h = imagedisplay->height;
-
- g_object_get(G_OBJECT(imagedisplay->pixbuf), "pixels", &image_eightbit, NULL);
+ imagedisplay = malloc(sizeof(ImageDisplay));
+ imagedisplay->imagerecord = imagerecord;
+ imagedisplay->view_width = 512;
+ imagedisplay->view_height = 512;
+ imagedisplay->title = strdup(title);
+ imagedisplay->message = message;
+ imagedisplay->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ imagedisplay->mouse_click_func = mouse_click_func;
+ imagedisplay->flags = flags;
+ imagedisplay->marks = NULL;
+ gtk_window_set_title(GTK_WINDOW(imagedisplay->window), imagedisplay->title);
- if ( (y >= 0) && (y < h) ) {
- for ( xd=biggest(x-3, 0); xd<=smallest(x+3, w-1); xd++ ) {
- imagedisplay->data[3*( xd+w*(h-1-y) )] = 255;
- imagedisplay->data[3*( xd+w*(h-1-y) )+1] = 0;
- imagedisplay->data[3*( xd+w*(h-1-y) )+2] = 0;
- }
+ imagedisplay_put_data(imagedisplay, imagerecord);
+
+ imagedisplay->vbox = gtk_vbox_new(FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(imagedisplay->window), imagedisplay->vbox);
+
+ if ( message ) {
+ GtkWidget *label;
+ label = gtk_label_new(message);
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+ gtk_box_pack_start(GTK_BOX(imagedisplay->vbox), label, FALSE, TRUE, 3);
}
- if ( (x >= 0) && (x < w) ) {
- for ( yd=biggest(y-3, 0); yd<=smallest(y+3, h-1); yd++ ) {
- imagedisplay->data[3*( x+w*(h-1-yd) )] = 255;
- imagedisplay->data[3*( x+w*(h-1-yd) )+1] = 0;
- imagedisplay->data[3*( x+w*(h-1-yd) )+2] = 0;
- }
+
+ imagedisplay->drawingarea = gtk_drawing_area_new();
+ gtk_box_pack_start(GTK_BOX(imagedisplay->vbox), imagedisplay->drawingarea, TRUE, TRUE, 0);
+
+ if ( imagedisplay->mouse_click_func ) {
+ gtk_widget_add_events(GTK_WIDGET(imagedisplay->drawingarea), GDK_BUTTON_PRESS_MASK);
+ g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "button-press-event",
+ G_CALLBACK(imagedisplay->mouse_click_func), imagedisplay);
}
-
+
+ g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "realize", G_CALLBACK(imagedisplay_realize), imagedisplay);
+ g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "destroy", G_CALLBACK(imagedisplay_close), imagedisplay);
+ g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "configure_event", G_CALLBACK(imagedisplay_configure_event), imagedisplay);
+ g_signal_connect(GTK_OBJECT(imagedisplay->drawingarea), "expose-event", G_CALLBACK(imagedisplay_redraw), imagedisplay);
+
+ geom.min_width = 128; geom.min_height = 128;
+ gtk_window_set_geometry_hints(GTK_WINDOW(imagedisplay->window), GTK_WIDGET(imagedisplay->drawingarea), &geom, GDK_HINT_MIN_SIZE);
+
+ gtk_window_set_default_size(GTK_WINDOW(imagedisplay->window), 512, 512);
+
+ gtk_widget_show_all(imagedisplay->window);
+
+ return imagedisplay;
+
}
-void imagedisplay_mark_circle(ImageDisplay *imagedisplay, unsigned int x, unsigned int y) {
+ImageDisplay *imagedisplay_open(ImageRecord image, const char *title, ImageDisplayFlags flags) {
+ return imagedisplay_open_with_message(image, title, NULL, flags, NULL);
+}
- guchar *image_eightbit;
- int xd, yd;
- int w, h;
+void imagedisplay_mark_circle(ImageDisplay *imagedisplay, double x, double y) {
- if ( !imagedisplay->pixbuf ) return;
+ ImageDisplayMark *new;
- w = imagedisplay->width;
- h = imagedisplay->height;
-
- g_object_get(G_OBJECT(imagedisplay->pixbuf), "pixels", &image_eightbit, NULL);
+ new = malloc(sizeof(ImageDisplayMark));
+ new->x = x; new->y = y;
+ new->type = IMAGEDISPLAY_MARK_CIRCLE;
+ new->next = NULL;
- if ( (y >= 0) && (y < h) ) {
- for ( xd=biggest(x-3, 0); xd<=smallest(x+3, w-1); xd++ ) {
- imagedisplay->data[3*( xd+w*(h-1-y) )] = 0;
- imagedisplay->data[3*( xd+w*(h-1-y) )+1] = 255;
- imagedisplay->data[3*( xd+w*(h-1-y) )+2] = 0;
- }
- }
- if ( (x >= 0) && (x < w) ) {
- for ( yd=biggest(y-3, 0); yd<=smallest(y+3, h-1); yd++ ) {
- imagedisplay->data[3*( x+w*(h-1-yd) )] = 0;
- imagedisplay->data[3*( x+w*(h-1-yd) )+1] = 255;
- imagedisplay->data[3*( x+w*(h-1-yd) )+2] = 0;
+ if ( !imagedisplay->marks ) {
+ imagedisplay->marks = new;
+ } else {
+ ImageDisplayMark *cur = imagedisplay->marks;
+ while ( cur->next ) {
+ cur = cur->next;
}
+ cur->next = new;
}
}
diff --git a/src/imagedisplay.h b/src/imagedisplay.h
index 94e6c13..5cff4b0 100644
--- a/src/imagedisplay.h
+++ b/src/imagedisplay.h
@@ -19,29 +19,56 @@
#include <stdint.h>
#include <gtk/gtk.h>
+#include "control.h"
+
+typedef enum {
+ IMAGEDISPLAY_NONE = 0,
+ IMAGEDISPLAY_SHOW_CENTRE = 1<<1,
+ IMAGEDISPLAY_SHOW_TILT_AXIS = 1<<2,
+ IMAGEDISPLAY_QUIT_IF_CLOSED = 1<<3
+} ImageDisplayFlags;
+
+typedef enum {
+ IMAGEDISPLAY_MARK_CIRCLE
+} ImageDisplayMarkType;
+
+typedef struct struct_imagedisplaymark {
+ double x;
+ double y;
+ ImageDisplayMarkType type;
+ struct struct_imagedisplaymark *next;
+} ImageDisplayMark;
+
typedef struct struct_imagedisplay {
- unsigned int width;
- unsigned int height; /* Of underlying image */
- char *title;
-
- guchar *data;
+ ImageRecord imagerecord;
+ ImageDisplayFlags flags;
+ ImageDisplayMark *marks;
+ const char *title;
+ const char *message;
+ guchar *data;
- GtkWidget *window;
- GdkPixbuf *pixbuf;
- GdkPixbuf *pixbuf_scaled;
- GtkWidget *image;
+ GtkWidget *window;
+ GdkPixbuf *pixbuf;
+ GdkPixbuf *pixbuf_scaled;
+ GtkWidget *drawingarea;
+ GtkWidget *vbox;
+ GCallback mouse_click_func;
+ GdkGC *gc_centre;
+ GdkGC *gc_tiltaxis;
+ GdkGC *gc_marks;
- unsigned int view_width;
- unsigned int view_height; /* Of window */
+ unsigned int drawingarea_width;
+ unsigned int drawingarea_height; /* Size of the drawing area */
+ unsigned int view_width;
+ unsigned int view_height; /* Size of the picture inside the drawing area */
} ImageDisplay;
-extern ImageDisplay *imagedisplay_open(uint16_t *image, unsigned int width, unsigned int height, const char *title);
-extern void imagedisplay_mark_point(ImageDisplay *imagedisplay, unsigned int x, unsigned int y);
-extern void imagedisplay_mark_circle(ImageDisplay *imagedisplay, unsigned int x, unsigned int y);
-#include "control.h"
-extern void imagedisplay_add_tilt_axis(ImageDisplay *imagedisplay, double xc, double yc, double omega);
+extern ImageDisplay *imagedisplay_open(ImageRecord image, const char *title, ImageDisplayFlags flags);
+extern ImageDisplay *imagedisplay_open_with_message(ImageRecord image, const char *title, const char *message,
+ ImageDisplayFlags flags, GCallback mouse_click_func);
+extern void imagedisplay_mark_circle(ImageDisplay *imagedisplay, double x, double y);
#endif /* IMAGEDISPLAY_H */
diff --git a/src/ipr.c b/src/ipr.c
index bc58788..0043eec 100644
--- a/src/ipr.c
+++ b/src/ipr.c
@@ -263,8 +263,7 @@ int ipr_refine(ControlContext *ctx) {
/* Select an image */
i = ipr_random_image(ctx);
- i = 25;
- cur = imagedisplay_open(ctx->images[i].image, ctx->images[i].width, ctx->images[i].height, "Current Image");
+ cur = imagedisplay_open(ctx->images[i], "Current Image", IMAGEDISPLAY_SHOW_CENTRE | IMAGEDISPLAY_SHOW_TILT_AXIS);
refl = reproject_get_reflections(ctx->images[i], &n, lat, ctx);
for ( j=0; j<n; j++ ) {
diff --git a/src/main.c b/src/main.c
index 125909b..a6ad44c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,6 +33,29 @@
#include "mapping.h"
#include "prealign.h"
+static void main_do_reconstruction(ControlContext *ctx, int val) {
+
+ if ( ctx->inputfiletype != INPUT_CACHE ) {
+ mapping_create(ctx);
+ }
+
+ if ( (ctx->inputfiletype != INPUT_CACHE) && !val && ctx->reflectionctx && ctx->savecache ) {
+ cache_save(ctx->filename, ctx->reflectionctx);
+ }
+
+ if ( !val && (ctx->rmode == RECONSTRUCTION_PREDICTION) && (ctx->reflectionctx) ) {
+ val = ipr_refine(ctx);
+ }
+
+ if ( !val && (ctx->reflectionctx) ) {
+ displaywindow_open(ctx);
+ } else {
+ fprintf(stderr, "Reconstruction failed.\n");
+ gtk_exit(0);
+ }
+
+}
+
static gint main_method_window_response(GtkWidget *method_window, gint response, ControlContext *ctx) {
if ( response == GTK_RESPONSE_OK ) {
@@ -81,25 +104,8 @@ static gint main_method_window_response(GtkWidget *method_window, gint response,
if ( ctx->prealign ) {
prealign_do_series(ctx);
- }
-
- if ( ctx->inputfiletype != INPUT_CACHE ) {
- mapping_create(ctx);
- }
-
- if ( (ctx->inputfiletype != INPUT_CACHE) && !val && ctx->reflectionctx && ctx->savecache ) {
- cache_save(ctx->filename, ctx->reflectionctx);
- }
-
- if ( !val && (ctx->rmode == RECONSTRUCTION_PREDICTION) && (ctx->reflectionctx) ) {
- val = ipr_refine(ctx);
- }
-
- if ( !val && (ctx->reflectionctx) ) {
- displaywindow_open(ctx);
} else {
- fprintf(stderr, "Reconstruction failed.\n");
- gtk_exit(0);
+ main_do_reconstruction(ctx, val);
}
} else {
diff --git a/src/mapping.c b/src/mapping.c
index 6d74ddd..86bf752 100644
--- a/src/mapping.c
+++ b/src/mapping.c
@@ -34,6 +34,7 @@ ReflectionContext *mapping_create(ControlContext *ctx) {
int x, y;
uint16_t *image_total;
ImageDisplay *sum_id;
+ ImageRecord total_record;
/* Find centre of image stack
* Determine maximum size of image to accommodate, and allocate memory */
@@ -75,9 +76,13 @@ ReflectionContext *mapping_create(ControlContext *ctx) {
}
/* Display */
- sum_id = imagedisplay_open(image_total, twidth, theight, "Sum of All Images");
- imagedisplay_mark_point(sum_id, max_x, max_y);
- imagedisplay_add_tilt_axis(sum_id, max_x, max_y, ctx->omega);
+ total_record.image = image_total;
+ total_record.width = twidth;
+ total_record.height = theight;
+ total_record.x_centre = max_x;
+ total_record.y_centre = max_y;
+ total_record.omega = ctx->omega;
+ sum_id = imagedisplay_open(total_record, "Sum of All Images", IMAGEDISPLAY_SHOW_CENTRE | IMAGEDISPLAY_SHOW_TILT_AXIS);
}
diff --git a/src/prealign.c b/src/prealign.c
index 86c0089..d7499f8 100644
--- a/src/prealign.c
+++ b/src/prealign.c
@@ -14,13 +14,27 @@
#include <string.h>
#include "control.h"
+#include "imagedisplay.h"
+
+static gint prealign_clicked() {
+
+ printf("Click!\n");
+
+ return 0;
+
+}
/* No peak-detection nor 3D mapping has been done yet.
Ask the user to give a rough idea (i.e. as accurately as possible...)
of the centre of each image. */
void prealign_do_series(ControlContext *ctx) {
+ int i;
+ i = 0;
+ imagedisplay_open_with_message(ctx->images[i], "Image Pre-alignment",
+ "Click the centre of the zero-order beam as accurately as you can.", IMAGEDISPLAY_QUIT_IF_CLOSED,
+ G_CALLBACK(prealign_clicked));
}
diff --git a/src/readpng.c b/src/readpng.c
index 0ea87fe..41d589d 100644
--- a/src/readpng.c
+++ b/src/readpng.c
@@ -144,9 +144,7 @@ int readpng_read(const char *filename, double tilt, ControlContext *ctx) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
fclose(fh);
- if ( control_add_image(ctx, image, width, height, tilt) == 0 ) {
- imagedisplay_open(image, width, height, "First image");
- }
+ control_add_image(ctx, image, width, height, tilt);
return 0;
diff --git a/src/utils.c b/src/utils.c
index fdc245f..35f4b88 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -4,6 +4,8 @@
* Utility stuff
*
* (c) 2007 Thomas White <taw27@cam.ac.uk>
+ * Gordon Ball <gfb21@cam.ac.uk>
+ *
* dtr - Diffraction Tomography Reconstruction
*
*/
@@ -67,3 +69,4 @@ void matrix_renormalise(gsl_matrix *m) {
gsl_matrix_scale(m,1./(max-min));
}
+
diff --git a/src/utils.h b/src/utils.h
index 1d5cb3c..ff49fea 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -27,4 +27,8 @@ extern double angle_between(double x1, double y1, double z1, double x2, double y
extern double lambda(double voltage);
extern void matrix_renormalise(gsl_matrix *m);
+#define rad2deg(a) ((a)*180/M_PI)
+#define deg2rad(a) ((a)*M_PI/180)
+
#endif /* UTILS_H */
+