aboutsummaryrefslogtreecommitdiff
path: root/src/refinetest.c
blob: f24862c9ee0ae6a95806a4b898066e5d9664e202 (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
/*
 * refinectx.c
 *
 * Unit test for refinement procedure
 *
 * (c) 2007-2008 Thomas White <taw27@cam.ac.uk>
 *
 *  dtr - Diffraction Tomography Reconstruction
 *
 */

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

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

#include "basis.h"
#include "reflections.h"
#include "image.h"
#include "reproject.h"
#include "refine.h"
#include "utils.h"
#include "mapping.h"
#include "control.h"
#include "displaywindow.h"

int main(int argc, char *argv[]) {

	ControlContext *ctx;
	ReflectionList *reflections_real;
	Basis *cell_real;
	
	ctx = control_ctx_new();
	ctx->omega = deg2rad(0.0);
	ctx->lambda = lambda(300.0e3);	/* 300 keV */
	ctx->fmode = FORMULATION_PIXELSIZE;
	ctx->x_centre = 256;
	ctx->y_centre = 256;
	ctx->pixel_size = 5e7;
	image_add(ctx->images, NULL, 512, 512, deg2rad(0.0), ctx);
	ctx->images->images[0].features = image_feature_list_new();
	
	/* Fudge to avoid horrifying pointer-related death */
	ctx->dw = malloc(sizeof(DisplayWindow));
	ctx->dw->cur_image = 0;
	
	/* The "true" cell */
	cell_real = malloc(sizeof(Basis));
	cell_real->a.x = 5.0e9;  cell_real->a.y = 0.0e9;  cell_real->a.z = 0.0e9;
	cell_real->b.x = 0.0e9;  cell_real->b.y = 5.0e9;  cell_real->b.z = 0.0e9;
	cell_real->c.x = 0.0e9;  cell_real->c.y = 0.0e9;  cell_real->c.z = 5.0e9;
	/* The "real" reflections */
	reflections_real = reflection_list_from_cell(cell_real);
	ctx->images->images[0].features = reproject_get_reflections(&ctx->images->images[0], reflections_real);
	printf("RT: %i test features generated.\n", ctx->images->images[0].features->n_features);
	
	/* The "model" cell to be refined */
	ctx->cell = malloc(sizeof(Basis));
	ctx->cell->a.x = 5.2e9;  ctx->cell->a.y = 0.1e9;  ctx->cell->a.z = 0.0e9;
	ctx->cell->b.x = 0.2e9;  ctx->cell->b.y = 4.8e9;  ctx->cell->b.z = 0.0e9;
	ctx->cell->c.x = 0.0e9;  ctx->cell->c.y = 0.0e9;  ctx->cell->c.z = 5.0e9;
	ctx->cell_lattice = reflection_list_from_cell(ctx->cell);
	ctx->images->images[0].rflist = reproject_get_reflections(&ctx->images->images[0], ctx->cell_lattice);
	reproject_partner_features(ctx->images->images[0].rflist, &ctx->images->images[0]);
	
	refine_do_cell(ctx);
	image_feature_list_free(ctx->images->images[0].rflist);
	reflection_list_from_new_cell(ctx->cell_lattice, ctx->cell);
	ctx->images->images[0].rflist = reproject_get_reflections(&ctx->images->images[0], ctx->cell_lattice);
	
	free(ctx);
	
	return 0;
	
}

/* Dummy function stubs */
#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) { };