hdfsee.c 6.25 KB
Newer Older
Thomas White's avatar
Thomas White committed
1
2
3
4
5
/*
 * hdfsee.c
 *
 * Quick yet non-crappy HDF viewer
 *
Thomas White's avatar
Thomas White committed
6
 * (c) 2006-2010 Thomas White <taw@physics.org>
Thomas White's avatar
Thomas White committed
7
8
9
10
11
12
13
14
15
16
17
 *
 * Part of CrystFEL - crystallography with a FEL
 *
 */


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

#include <gtk/gtk.h>
18
#include <getopt.h>
Thomas White's avatar
Thomas White committed
19

20
#include "dw-hdfsee.h"
Thomas White's avatar
Thomas White committed
21
#include "utils.h"
22
#include "render.h"
Thomas White's avatar
Thomas White committed
23
24
25
26
27
28
29


/* Global program state */
DisplayWindow *main_window_list[64];
size_t main_n_windows = 0;


30
31
32
33
34
35
36
37
38
static void show_help(const char *s)
{
	printf("Syntax: %s [options] image.h5\n\n", s);
	printf(
"Quick HDF5 image viewer.\n"
"\n"
"  -h, --help                       Display this help message.\n"
"\n"
"  -p, --peak-overlay=<filename>    Draw circles in positions listed in file.\n"
39
"      --ring-size=<n>              Set the size for those circles.\n"
40
"  -i, --int-boost=<n>              Multiply intensity by <n>.\n"
41
"  -b, --binning=<n>                Set display binning to <n>.\n"
42
43
44
45
46
"      --filter-cm                  Perform common-mode noise subtraction.\n"
"      --filter-noise               Apply an aggressive noise filter which\n"
"                                    sets all pixels in each 3x3 region to\n"
"                                    zero if any of them have negative\n"
"                                    values.\n"
47
48
"      --show-rings                 Overlay rings that indicate resolution.\n"
"      --simple-rings=XX,YY,...     Overlay rings at specified radii XX, YY, ...\n"
Thomas White's avatar
Thomas White committed
49
"                                    in pixel units.\n"
50
51
52
53
54
55
"  -c, --colscale=<scale>           Use the given colour scale.  Choose from:\n"
"                                    mono    : Greyscale, black is zero.\n"
"                                    invmono : Greyscale, white is zero.\n"
"                                    colour  : Colour scale:\n"
"                                               black-blue-pink-red-orange-\n"
"                                               -yellow-white.\n"
Thomas White's avatar
Thomas White committed
56
57
"  -e, --image=<element>            Start up displaying this image from the\n"
"                                    HDF5 file.  Example: /data/data0.\n"
Thomas White's avatar
Thomas White committed
58
"  -g, --geometry=<filename>        Use geometry from file for display.\n"
59
60
61
62
"\n");
}


Thomas White's avatar
Thomas White committed
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
/* Called to notify that an image display window has been closed */
void hdfsee_window_closed(DisplayWindow *dw)
{
	size_t i;

	for ( i=0; i<main_n_windows; i++ ) {

		if ( main_window_list[i] == dw ) {

			size_t j;

			for ( j=i+1; j<main_n_windows; j++ ) {
				main_window_list[j] = main_window_list[j+1];
			}

		}

	}

	main_n_windows--;

	if ( main_n_windows == 0 ) gtk_exit(0);

}


int main(int argc, char *argv[])
{
91
92
93
94
	int c;
	size_t i;
	int nfiles;
	char *peaks = NULL;
95
96
	int boost = 1;
	int binning = 2;
97
98
	int config_cmfilter = 0;
	int config_noisefilter = 0;
Thomas White's avatar
Thomas White committed
99
	int config_showrings = 0;
100
101
	int colscale = SCALE_COLOUR;
	char *cscale = NULL;
Thomas White's avatar
Thomas White committed
102
	char *element = NULL;
103
	char *geometry = NULL;
104
	double ring_size = 5.0;
105
106
107
	char *reslist = NULL;
	double ring_radii[128];
	int n_rings = -1;
Thomas White's avatar
Thomas White committed
108

109
110
111
112
	/* Long options */
	const struct option longopts[] = {
		{"help",               0, NULL,               'h'},
		{"peak-overlay",       1, NULL,               'p'},
113
114
		{"int-boost",          1, NULL,               'i'},
		{"binning",            1, NULL,               'b'},
115
116
		{"filter-cm",          0, &config_cmfilter,    1},
		{"filter-noise",       0, &config_noisefilter, 1},
117
		{"colscale",           1, NULL,               'c'},
Thomas White's avatar
Thomas White committed
118
		{"image",              1, NULL,               'e'},
119
		{"geometry",           1, NULL,               'g'},
Thomas White's avatar
Thomas White committed
120
		{"show-rings",         0, &config_showrings,   1},
121
		{"ring-size",          1, NULL,                2},
122
		{"simple-rings",       1, NULL,               'r'},
123
124
125
		{0, 0, NULL, 0}
	};

Thomas White's avatar
Thomas White committed
126
127
	gtk_init(&argc, &argv);

128
	/* Short options */
129
	while ((c = getopt_long(argc, argv, "hp:b:i:c:e:g:2:",
130
	                        longopts, NULL)) != -1) {
Thomas White's avatar
Thomas White committed
131

132
133
		char *test;

134
		switch (c) {
Thomas White's avatar
Thomas White committed
135
		case 'h' :
136
137
			show_help(argv[0]);
			return 0;
Thomas White's avatar
Thomas White committed
138

Thomas White's avatar
Thomas White committed
139
		case 'p' :
140
141
			peaks = strdup(optarg);
			break;
Thomas White's avatar
Thomas White committed
142

Thomas White's avatar
Thomas White committed
143
		case 'i' :
144
145
146
147
			boost = atoi(optarg);
			if ( boost < 1 ) {
				ERROR("Intensity boost must be a positive"
				      " integer.\n");
148
				return 1;
149
150
151
			}
			break;

Thomas White's avatar
Thomas White committed
152
		case 'b' :
153
			binning = atoi(optarg);
154
			if ( binning < 1 ) {
155
				ERROR("Binning must be a positive integer.\n");
156
				return 1;
157
158
159
			}
			break;

160
161
162
163
		case 'c' :
			cscale = strdup(optarg);
			break;

Thomas White's avatar
Thomas White committed
164
165
166
167
		case 'e' :
			element = strdup(optarg);
			break;

168
169
170
171
		case 'g' :
			geometry = strdup(optarg);
			break;

172
173
174
175
176
177
		case 2 :
			ring_size = strtod(optarg, &test);
			if ( test == optarg ) {
				ERROR("Ring size must be numerical.\n");
				return 1;
			}
Thomas White's avatar
Thomas White committed
178

179
180
181
182
183
184
		case 'r' :
			config_showrings = 1;
			reslist = strdup(optarg);
			int nchar = strlen(reslist);
			char thisvalue[128];
			int i;
Thomas White's avatar
Thomas White committed
185
			int j = 0;
186
187
			n_rings = 0;
			for ( i=0; i<=nchar; i++ ) {
Thomas White's avatar
Thomas White committed
188
189
190
				if ( ( reslist[i] != ',' )
				  && ( reslist[i] != '\0' ) )
				{
191
192
193
					thisvalue[j] = reslist[i];
					j++;
				} else {
Thomas White's avatar
Thomas White committed
194
					thisvalue[j] = '\0';
195
196
					ring_radii[n_rings] = atof(thisvalue);
					n_rings++;
Thomas White's avatar
Thomas White committed
197
					j = 0;
198
199
200
				}
			}
			break;
Thomas White's avatar
Thomas White committed
201

Thomas White's avatar
Thomas White committed
202
		case 0 :
203
			break;
Thomas White's avatar
Thomas White committed
204

Thomas White's avatar
Thomas White committed
205
		default :
206
207
			return 1;
		}
Thomas White's avatar
Thomas White committed
208
209
210

	}

211
212
213
214
215
216
217
	nfiles = argc-optind;

	if ( nfiles < 1 ) {
		ERROR("You need to give me a file to open!\n");
		return -1;
	}

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
	if ( cscale == NULL ) cscale = strdup("colour");
	if ( strcmp(cscale, "mono") == 0 ) {
		colscale = SCALE_MONO;
	} else if ( strcmp(cscale, "invmono") == 0 ) {
		colscale = SCALE_INVMONO;
	} else if ( strcmp(cscale, "colour") == 0 ) {
		colscale = SCALE_COLOUR;
	} else if ( strcmp(cscale, "color") == 0 ) {
		colscale = SCALE_COLOUR;
	} else {
		ERROR("Unrecognised colour scale '%s'\n", cscale);
		return 1;
	}
	free(cscale);

233
	for ( i=0; i<nfiles; i++ ) {
234
		main_window_list[i] = displaywindow_open(argv[optind+i], peaks,
235
		                                         boost, binning,
236
		                                         config_cmfilter,
237
		                                         config_noisefilter,
238
		                                         colscale, element,
Thomas White's avatar
Thomas White committed
239
		                                         geometry,
240
		                                         config_showrings,
241
242
		                                         ring_radii,
		                                         n_rings,
243
		                                         ring_size);
244
245
246
247
248
249
		if ( main_window_list[i] == NULL ) {
			ERROR("Couldn't open display window\n");
		} else {
			main_n_windows++;
		}
	}
250
251

	if ( main_n_windows == 0 ) return 0;
Thomas White's avatar
Thomas White committed
252
253
254
255
	gtk_main();

	return 0;
}