blob: 80cf7ce8e38a21c7ebcf5be85c58ec7fac85de68 (
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
* control.c
*
* Common control structure
*
* (c) 2007 Thomas White <taw27@cam.ac.uk>
*
* dtr - Diffraction Tomography Reconstruction
*
*/
#include <inttypes.h>
#include <stdlib.h>
#include <math.h>
#include "control.h"
int control_add_image(ControlContext *ctx, uint16_t *image, int width, int height, double tilt) {
ctx->images[ctx->n_images].tilt = tilt;
ctx->images[ctx->n_images].omega = ctx->omega;
ctx->images[ctx->n_images].image = image;
ctx->images[ctx->n_images].width = width;
ctx->images[ctx->n_images].height = height;
ctx->images[ctx->n_images].lambda = ctx->lambda;
ctx->images[ctx->n_images].fmode = ctx->fmode;
ctx->images[ctx->n_images].x_centre = ctx->x_centre;
ctx->images[ctx->n_images].y_centre = ctx->y_centre;
ctx->images[ctx->n_images].slop = 0.0;
if ( ctx->fmode == FORMULATION_PIXELSIZE ) {
ctx->images[ctx->n_images].pixel_size = ctx->pixel_size;
ctx->images[ctx->n_images].camera_len = 0;
ctx->images[ctx->n_images].resolution = 0;
} else if ( ctx->fmode == FORMULATION_CLEN ) {
ctx->images[ctx->n_images].pixel_size = 0;
ctx->images[ctx->n_images].camera_len = ctx->camera_length;
ctx->images[ctx->n_images].resolution = ctx->resolution;
}
ctx->n_images++;
return ctx->n_images - 1;
}
ControlContext *control_ctx_new() {
ControlContext *ctx;
ctx = malloc(sizeof(ControlContext));
ctx->x_centre = 0;
ctx->y_centre = 0;
ctx->have_centres = 0;
ctx->cell = NULL;
ctx->dirax = NULL;
return ctx;
}
/* Return the minimum (most negative) tilt angle used */
double control_min_tilt(ControlContext *ctx) {
int i;
double min = 360;
for ( i=0; i<ctx->n_images; i++ ) {
if ( ctx->images[i].tilt < min ) min = ctx->images[i].tilt;
}
return min;
}
/* Return the maximum (most positive) tilt angle used */
double control_max_tilt(ControlContext *ctx) {
int i;
double max = -360;
for ( i=0; i<ctx->n_images; i++ ) {
if ( ctx->images[i].tilt > max ) max = ctx->images[i].tilt;
}
return max;
}
/* Return a reference to the image record with tilt closest to the given value */
ImageRecord *control_image_nearest_tilt(ControlContext *ctx, double tilt) {
int i;
double dev = 360;
ImageRecord *im = NULL;
for ( i=0; i<ctx->n_images; i++ ) {
if ( fabs(ctx->images[i].tilt - tilt) < dev ) {
dev = fabs(ctx->images[i].tilt - tilt);
im = &ctx->images[i];
}
}
return im;
}
|