aboutsummaryrefslogtreecommitdiff
path: root/src/refine.c
blob: ede96cba3193a2222d8a66e345a5004696bf2f51 (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
/*
 * refine.c
 *
 * Refine the reconstruction
 *
 * (c) 2007 Thomas White <taw27@cam.ac.uk>
 *
 *  dtr - Diffraction Tomography Reconstruction
 *
 */

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

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

#include "displaywindow.h"
#include "gtk-valuegraph.h"
#include "basis.h"
#include "reflections.h"
#include "image.h"
#include "reproject.h"

static double refine_image_deviation(ImageRecord *image, ReflectionList *cell_lattice) {

	ImageFeatureList *rflist;
	ImageFeatureList *flist;
	double xc, yc;
	int i;
	double total;
	
	xc = image->x_centre;
	yc = image->y_centre;
	rflist = reproject_get_reflections(image, cell_lattice);
	flist = image->features;
	
	reproject_partner_features(rflist, image);
	
	total = 0.0;
	for ( i=0; i<rflist->n_features; i++ ) {
		
		double d;
		
		d = rflist->features[i].partner_d;
		total += d*d;
	
	}
	
	image_feature_list_free(rflist);
	
	return sqrt(total);

}

void refine_open(DisplayWindow *dw) {

	GtkWidget *window;
	GtkWidget *graph;
	double old_tilt;
	int n;
	double *values;
	size_t idx;
	double tilt;
	
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size(GTK_WINDOW(window), 640, 256);
	gtk_window_set_title(GTK_WINDOW(window), "Refinement Graph");
	graph = gtk_value_graph_new();
	
	dw->ctx->cell_lattice = reflection_list_from_cell(dw->ctx->cell);
	n = 0;
	idx = 0;
	old_tilt = dw->ctx->images->images[n].tilt;
	values = malloc(401*sizeof(double));
	for ( tilt=old_tilt-0.2; tilt<=old_tilt+0.2; tilt+=0.001 ) {
		dw->ctx->images->images[n].tilt = tilt;
		values[idx++] = refine_image_deviation(&dw->ctx->images->images[n], dw->ctx->cell_lattice);
	}
	dw->ctx->images->images[n].tilt = old_tilt;
	gtk_value_graph_set_data(GTK_VALUE_GRAPH(graph), values, idx);
	
	gtk_container_add(GTK_CONTAINER(window), graph);
	gtk_widget_show_all(window);

}