aboutsummaryrefslogtreecommitdiff
path: root/src/ipr.c
blob: 787106a3fb7e6a5fa8b7a333d3e2cf8da932c6a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
 * ipr.c
 *
 * Iterative Prediction-Refinement Reconstruction
 *
 * (c) 2007 Thomas White <taw27@cam.ac.uk>
 *
 *  dtr - Diffraction Tomography Reconstruction
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#include "control.h"
#include "reflections.h"
#include "itrans.h"
#include "utils.h"
#include "imagedisplay.h"
#include "reproject.h"
#include "ipr.h"
#include "displaywindow.h"
#include "basis.h"

static gint ipr_clicked(GtkWidget *widget, GdkEventButton *event, ControlContext *ctx) {

	ImageReflection *refl;
	size_t n, j;
	
	ctx->ipr_cur_image++;
	if ( ctx->ipr_cur_image == ctx->n_images ) ctx->ipr_cur_image = 0;
	
	imagedisplay_clear_circles(ctx->ipr_id);
	reflectionlist_clear_markers(ctx->reflectionlist);
	
	refl = reproject_get_reflections(ctx->images[ctx->ipr_cur_image], &n, ctx->ipr_lat, ctx);
	for ( j=0; j<n; j++ ) {
		imagedisplay_mark_circle(ctx->ipr_id, refl[j].x, refl[j].y);
	}
	
	imagedisplay_put_data(ctx->ipr_id, ctx->images[ctx->ipr_cur_image]);
	displaywindow_update(ctx->dw);
	
	return 0;

}

int ipr_refine(ControlContext *ctx) {
	
	Basis *basis;
	int finished;
	
	basis = basis_find(ctx);
	if ( !basis ) {
		printf("IP: Unable to find basis\n");
		return -1;
	}
	
	ctx->ipr_basis = basis;
	ctx->ipr_lat = reflection_list_from_cell(basis);
	
	printf("IP: Performing refinement...\n");
	finished = 0;
	do {
	
		size_t n, j;
		ImageReflection *refl;
		
		/* Select an image */
		ctx->ipr_cur_image = 0;
		
		ctx->ipr_id = imagedisplay_open_with_message(ctx->images[ctx->ipr_cur_image], "Current Image", "Click to change image",
					IMAGEDISPLAY_SHOW_CENTRE | IMAGEDISPLAY_SHOW_TILT_AXIS, G_CALLBACK(ipr_clicked), ctx);
		
		refl = reproject_get_reflections(ctx->images[ctx->ipr_cur_image], &n, ctx->ipr_lat, ctx);
		for ( j=0; j<n; j++ ) {
			imagedisplay_mark_circle(ctx->ipr_id, refl[j].x, refl[j].y);
		}
		
		finished = 1;
		
	} while ( !finished );
	
	return 0;

}