aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am7
-rw-r--r--src/iprtest.c171
-rw-r--r--src/refine.c6
-rw-r--r--src/refine.h3
-rw-r--r--src/reproject.c8
5 files changed, 190 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 759a667..d51f2bb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,8 +1,13 @@
-bin_PROGRAMS = dtr
+bin_PROGRAMS = dtr iprtest
+
dtr_SOURCES = main.c displaywindow.c trackball.c reflections.c readpng.c mrc.c imagedisplay.c utils.c itrans.c qdrp.c cache.c \
itrans-threshold.c itrans-zaefferer.c itrans-stat.c control.c mapping.c reproject.c prealign.c basis.c \
dirax.c image.c refine.c gtk-valuegraph.c intensities.c glbits.c
dtr_LDADD = @LIBS@ @GTK_LIBS@ -lm @GTKGLEXT_LIBS@ -lgsl -lgslcblas -lutil
+
+iprtest_SOURCES = iprtest.c reflections.c basis.c utils.c reproject.c image.c refine.c mapping.c
+iprtest_LDADD = @LIBS@ @GTK_LIBS@ -lm -lgsl -lgslcblas -lutil
+
AM_CFLAGS = -Wall -g @CFLAGS@ @GTK_CFLAGS@ @GTKGLEXT_CFLAGS@
AM_CPPFLAGS = -DDATADIR=\""$(datadir)"\"
diff --git a/src/iprtest.c b/src/iprtest.c
new file mode 100644
index 0000000..1fd96d9
--- /dev/null
+++ b/src/iprtest.c
@@ -0,0 +1,171 @@
+/*
+ * iprtest.c
+ *
+ * Unit test for IPR
+ *
+ * (c) 2007-2008 Thomas White <taw27@cam.ac.uk>
+ *
+ * dtr - Diffraction Tomography Reconstruction
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "basis.h"
+#include "reflections.h"
+#include "image.h"
+#include "reproject.h"
+#include "refine.h"
+#include "utils.h"
+
+typedef struct {
+
+ ImageRecord *image;
+
+ Basis *cell;
+ ReflectionList *reflections;
+ ReflectionList *gen;
+
+} IPRTestContext;
+
+static gint main_window_closed(GtkWidget *window, IPRTestContext *ctx) {
+ gtk_exit(0);
+ return 0;
+}
+
+static gboolean main_window_expose(GtkWidget *drawing, GdkEventExpose *event, IPRTestContext *ctx) {
+
+ cairo_t *cr;
+ ImageFeature *f;
+ size_t i;
+
+ cr = gdk_cairo_create(drawing->window);
+
+ cairo_new_path(cr);
+ cairo_rectangle(cr, 0.0, 0.0, 640.0, 640.0);
+ cairo_set_source_rgb(cr, 0.0, 0.0, 0.4);
+ cairo_fill(cr);
+
+ f = ctx->image->features->features;
+ cairo_set_source_rgb(cr, 0.0, 0.9, 0.0);
+ for ( i=0; i<ctx->image->features->n_features; i++ ) {
+ cairo_new_path(cr);
+ cairo_arc(cr, f[i].x, f[i].y, 2.5, 0, 2*M_PI);
+ cairo_fill(cr);
+ }
+
+ f = ctx->image->rflist->features;
+ cairo_set_source_rgb(cr, 0.6, 0.0, 0.0);
+ for ( i=0; i<ctx->image->rflist->n_features; i++ ) {
+
+ cairo_new_path(cr);
+ cairo_arc(cr, f[i].x, f[i].y, 5.0, 0, 2*M_PI);
+ cairo_stroke(cr);
+
+ if ( f[i].partner != NULL ) {
+
+ cairo_new_path(cr);
+ cairo_move_to(cr, f[i].x, f[i].y);
+ cairo_line_to(cr, f[i].partner->x, f[i].partner->y);
+ cairo_stroke(cr);
+
+ }
+
+ }
+
+ cairo_destroy(cr);
+
+ return FALSE;
+
+}
+
+static gboolean main_button_press(GtkWidget *drawing, GdkEventButton *event, IPRTestContext *ctx) {
+
+ if ( (event->type == GDK_BUTTON_PRESS) && (event->button == 1) ) {
+ refine_fit_image(ctx->cell, ctx->image);
+ image_feature_list_free(ctx->image->rflist);
+ reflection_list_from_new_cell(ctx->gen, ctx->cell);
+ ctx->image->rflist = reproject_get_reflections(ctx->image, ctx->gen);
+ gdk_window_invalidate_rect(drawing->window, &drawing->allocation, FALSE);
+ }
+
+ return FALSE;
+}
+
+int main(int argc, char *argv[]) {
+
+ GtkWidget *window;
+ GtkWidget *drawing;
+ IPRTestContext *ctx;
+
+ gtk_init(&argc, &argv);
+
+ ctx = malloc(sizeof(IPRTestContext));
+
+ ctx->image = malloc(sizeof(ImageRecord));
+ ctx->image->image = NULL;
+ ctx->image->tilt = 0.0;
+ ctx->image->omega = 0.0;
+ ctx->image->slop = 0.0;
+ ctx->image->fmode = FORMULATION_PIXELSIZE;
+ ctx->image->pixel_size = 1e8;
+ ctx->image->camera_len = 0.0;
+ ctx->image->lambda = lambda(1000000);
+ ctx->image->resolution = 1.0;
+ ctx->image->width = 640;
+ ctx->image->height = 640;
+ ctx->image->x_centre = 320;
+ ctx->image->y_centre = 320;
+ ctx->image->features = NULL;
+ ctx->image->rflist = NULL;
+
+ ctx->cell = malloc(sizeof(Basis));
+ /* The "true" cell */
+ ctx->cell->a.x = 5.0e9; ctx->cell->a.y = 0.0; ctx->cell->a.z = 0.0;
+ ctx->cell->b.x = 0.0; ctx->cell->b.y = 5.0e9; ctx->cell->b.z = 0.0;
+ ctx->cell->c.x = 0.0; ctx->cell->c.y = 0.0; ctx->cell->c.z = 5.0e9;
+ ctx->reflections = reflection_list_from_cell(ctx->cell);
+ ctx->image->features = reproject_get_reflections(ctx->image, ctx->reflections);
+ /* The "model" cell */
+ ctx->cell->a.x = 5.9e9; ctx->cell->a.y = 0.1e9; ctx->cell->a.z = 0.0;
+ ctx->cell->b.x = 0.0; ctx->cell->b.y = 5.1e9; ctx->cell->b.z = 0.0;
+ ctx->cell->c.x = 0.0; ctx->cell->c.y = 0.0; ctx->cell->c.z = 5.0e9;
+ ctx->gen = reflection_list_from_cell(ctx->cell);
+ ctx->image->rflist = reproject_get_reflections(ctx->image, ctx->gen);
+
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), "IPR Test");
+ gtk_window_set_default_size(GTK_WINDOW(window), 640, 640);
+ g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(main_window_closed), ctx);
+
+ drawing = gtk_drawing_area_new();
+ gtk_container_add(GTK_CONTAINER(window), drawing);
+ g_signal_connect(G_OBJECT(drawing), "expose_event", G_CALLBACK(main_window_expose), ctx);
+ gtk_widget_add_events(drawing, GDK_BUTTON_PRESS_MASK);
+ g_signal_connect(GTK_OBJECT(drawing), "button_press_event", G_CALLBACK(main_button_press), ctx);
+
+ gtk_widget_show_all(window);
+
+ gtk_main();
+
+ return 0;
+
+}
+
+/* Dummy function stubs */
+#include "displaywindow.h"
+#include "gtk-valuegraph.h"
+void displaywindow_update_imagestack(DisplayWindow *dw) { };
+void displaywindow_enable_cell_functions(DisplayWindow *dw, gboolean g) { };
+void displaywindow_update(DisplayWindow *dw) { };
+void displaywindow_error(const char *msg, DisplayWindow *dw) { };
+guint gtk_value_graph_get_type() { return 0; };
+GtkWidget *gtk_value_graph_new() { return NULL; };
+void gtk_value_graph_set_data(GtkValueGraph *vg, double *data, unsigned int n) { };
+
diff --git a/src/refine.c b/src/refine.c
index 99dcebe..f173e99 100644
--- a/src/refine.c
+++ b/src/refine.c
@@ -40,7 +40,7 @@ typedef enum {
} Axis;
/* Use the IPR algorithm to make "cell" fit the given image */
-static ImageFeature *refine_fit_image(Basis *cell, ImageRecord *image, ReflectionList *cell_lattice) {
+ImageFeature *refine_fit_image(Basis *cell, ImageRecord *image) {
ImageFeatureList *flist;
gsl_matrix *M;
@@ -214,7 +214,7 @@ static int refine_sequence_sweep(ControlContext *ctx, double *fit, double *warp)
/* Fit this image and update ctx->cell_lattice, index the selected pattern */
if ( !image->rflist ) image->rflist = reproject_get_reflections(image, ctx->cell_lattice);
- refine_fit_image(ctx->cell, image, ctx->cell_lattice);
+ refine_fit_image(ctx->cell, image);
reproject_cell_to_lattice(ctx);
image->rflist = reproject_get_reflections(image, ctx->cell_lattice);
@@ -326,7 +326,7 @@ void refine_do_image(ControlContext *ctx) {
ImageFeature *fitted;
- fitted = refine_fit_image(ctx->cell, &ctx->images->images[ctx->dw->cur_image], ctx->cell_lattice);
+ fitted = refine_fit_image(ctx->cell, &ctx->images->images[ctx->dw->cur_image]);
ctx->images->images[ctx->dw->cur_image].rflist = NULL;
reproject_lattice_changed(ctx);
diff --git a/src/refine.h b/src/refine.h
index 7a01e83..b15e56e 100644
--- a/src/refine.h
+++ b/src/refine.h
@@ -17,7 +17,10 @@
#endif
#include "control.h"
+#include "image.h"
+#include "reflections.h"
+extern ImageFeature *refine_fit_image(Basis *cell, ImageRecord *image);
extern void refine_do_stack(ControlContext *ctx);
extern void refine_do_image(ControlContext *ctx);
diff --git a/src/reproject.c b/src/reproject.c
index 4d2d889..41ec8c5 100644
--- a/src/reproject.c
+++ b/src/reproject.c
@@ -37,6 +37,8 @@ void reproject_partner_features(ImageFeatureList *rflist, ImageRecord *image) {
if ( (d <= 20.0) && partner ) {
rflist->features[i].partner = partner;
rflist->features[i].partner_d = d;
+ } else {
+ rflist->features[i].partner = NULL;
}
}
@@ -200,7 +202,11 @@ ImageFeatureList *reproject_get_reflections(ImageRecord *image, ReflectionList *
} while ( reflection );
- reproject_partner_features(flist, image);
+ /* Partner features only if the image has a feature list. This allows the test
+ * program to use this function to generate simulated data. */
+ if ( image->features != NULL ) {
+ reproject_partner_features(flist, image);
+ }
return flist;