image.h 4 KB
Newer Older
1
2
3
4
5
/*
 * image.h
 *
 * Handle images and image features
 *
Thomas White's avatar
Thomas White committed
6
 * (c) 2006-2010 Thomas White <taw@physics.org>
7
 *
Thomas White's avatar
Thomas White committed
8
 * Part of CrystFEL - crystallography with a FEL
9
10
11
12
13
14
15
16
17
18
19
20
 *
 */


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

#ifndef IMAGE_H
#define IMAGE_H

#include <stdint.h>
Thomas White's avatar
Thomas White committed
21
#include <complex.h>
Thomas White's avatar
Thomas White committed
22
#include <sys/types.h>
23

Thomas White's avatar
Thomas White committed
24
#include "utils.h"
Thomas White's avatar
Thomas White committed
25
#include "cell.h"
26
#include "detector.h"
Thomas White's avatar
Thomas White committed
27

28

Thomas White's avatar
Thomas White committed
29
30
31
#define MAX_CELL_CANDIDATES (32)


Thomas White's avatar
Thomas White committed
32
33
/* Structure describing a feature in an image */
struct imagefeature {
34

Thomas White's avatar
Thomas White committed
35
36
37
38
	struct image                    *parent;
	double                          x;
	double                          y;
	double                          intensity;
39
40

	/* Partner for this feature (in another feature list) or NULL */
Thomas White's avatar
Thomas White committed
41
	struct imagefeature_struct      *partner;
42
43

	/* Distance between this feature and its partner, if any. */
Thomas White's avatar
Thomas White committed
44
	double                          partner_d;
45

Thomas White's avatar
Thomas White committed
46
	/* Reciprocal space coordinates (m^-1 of course) of this feature */
Thomas White's avatar
Thomas White committed
47
48
49
	double                          rx;
	double                          ry;
	double                          rz;
Thomas White's avatar
Thomas White committed
50

51
	/* Internal use only */
Thomas White's avatar
Thomas White committed
52
	int                             valid;
53

Thomas White's avatar
Thomas White committed
54
	const char                      *name;
Thomas White's avatar
Thomas White committed
55
};
56

Thomas White's avatar
Thomas White committed
57
58
/* An opaque type representing a list of image features */
typedef struct _imagefeaturelist ImageFeatureList;
59

Thomas White's avatar
Thomas White committed
60

Thomas White's avatar
Thomas White committed
61
62
63
64
65
66
67
68
69
70
struct reflhit {
	signed int h;
	signed int k;
	signed int l;
	double min_distance;
	int x;
	int y;
};


Thomas White's avatar
Thomas White committed
71
/* Structure describing an image */
72
73
struct image {

Thomas White's avatar
Thomas White committed
74
75
76
77
78
79
	float                   *data;
	uint16_t                *flags;
	double                  *twotheta;
	UnitCell                *indexed_cell;
	UnitCell                *candidate_cells[MAX_CELL_CANDIDATES];
	int                     ncells;
Thomas White's avatar
Thomas White committed
80
	struct detector         *det;
81
	char                    *filename;
Thomas White's avatar
Thomas White committed
82
83
	struct reflhit          *hits;
	int                     n_hits;
84

85
86
	int                     id;   /* ID number of the thread
	                               * handling this image */
Thomas White's avatar
Thomas White committed
87

88
	/* Information about the crystal */
Thomas White's avatar
Thomas White committed
89
	struct quaternion       orientation;
90
	double                  m;  /* Mosaicity in radians */
91
92


93
94
95
96
97
98
99
	/* Information about the radiation */
	double                  lambda;        /* Wavelength in m */
	double                  div;           /* Divergence in radians */
	double                  bw;            /* Bandwidth as a fraction */
	double                  f0;            /* Incident intensity */
	int                     f0_available;  /* 0 if f0 wasn't available
	                                        * from the input. */
100

Thomas White's avatar
Thomas White committed
101
102
	int                     width;
	int                     height;
103

104
	ImageFeatureList        *features;
105

Thomas White's avatar
Thomas White committed
106
	/* DirAx auto-indexing low-level stuff */
Thomas White's avatar
Thomas White committed
107
108
109
110
111
	int                     dirax_pty;
	pid_t                   dirax_pid;
	char                    *dirax_rbuffer;
	int                     dirax_rbufpos;
	int                     dirax_rbuflen;
Thomas White's avatar
Thomas White committed
112
113

	/* DirAx auto-indexing high-level stuff */
Thomas White's avatar
Thomas White committed
114
115
116
117
118
119
	int                     dirax_step;
	int                     dirax_read_cell;
	int                     best_acl;
	int                     best_acl_nh;
	int                     acls_tried[MAX_CELL_CANDIDATES];
	int                     n_acls_tried;
120

121
122
};

Thomas White's avatar
Thomas White committed
123
124
/* An opaque type representing a list of images */
typedef struct _imagelist ImageList;
125
126


127
/* Image lists */
128
129
130
131
extern ImageList *image_list_new(void);

extern int image_add(ImageList *list, struct image *image);

132
133

/* Feature lists */
134
135
136
137
138
extern ImageFeatureList *image_feature_list_new(void);

extern void image_feature_list_free(ImageFeatureList *flist);

extern void image_add_feature(ImageFeatureList *flist, double x, double y,
139
140
                              struct image *parent, double intensity,
                              const char *name);
141

142
143
extern void image_remove_feature(ImageFeatureList *flist, int idx);

Thomas White's avatar
Thomas White committed
144
extern struct imagefeature *image_feature_closest(ImageFeatureList *flist,
145
146
147
                                                  double x, double y, double *d,
                                                  int *idx);

Thomas White's avatar
Thomas White committed
148
149
extern int image_feature_count(ImageFeatureList *flist);
extern struct imagefeature *image_get_feature(ImageFeatureList *flist, int idx);
150
151

#endif	/* IMAGE_H */