hdfsee.c 5 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
"  -i, --int-boost=<n>              Multiply intensity by <n>.\n"
40
"  -b, --binning=<n>                Set display binning to <n>.\n"
41
42
43
44
45
"      --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"
46
47
48
49
50
51
"  -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
52
53
"  -e, --image=<element>            Start up displaying this image from the\n"
"                                    HDF5 file.  Example: /data/data0.\n"
Thomas White's avatar
Thomas White committed
54
"  -g, --geometry=<filename>        Use geometry from file for display.\n"
55
56
57
58
"\n");
}


Thomas White's avatar
Thomas White committed
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
/* 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[])
{
87
88
89
90
	int c;
	size_t i;
	int nfiles;
	char *peaks = NULL;
91
92
	int boost = 1;
	int binning = 2;
93
94
	int config_cmfilter = 0;
	int config_noisefilter = 0;
Thomas White's avatar
Thomas White committed
95
	int config_showrings = 0;
96
97
	int colscale = SCALE_COLOUR;
	char *cscale = NULL;
Thomas White's avatar
Thomas White committed
98
	char *element = NULL;
99
	char *geometry = NULL;
100
101
102
103
104

	/* Long options */
	const struct option longopts[] = {
		{"help",               0, NULL,               'h'},
		{"peak-overlay",       1, NULL,               'p'},
105
106
		{"int-boost",          1, NULL,               'i'},
		{"binning",            1, NULL,               'b'},
107
108
		{"filter-cm",          0, &config_cmfilter,    1},
		{"filter-noise",       0, &config_noisefilter, 1},
109
		{"colscale",           1, NULL,               'c'},
Thomas White's avatar
Thomas White committed
110
		{"image",              1, NULL,               'e'},
111
		{"geometry",           1, NULL,               'g'},
Thomas White's avatar
Thomas White committed
112
		{"show-rings",         0, &config_showrings,   1},
113
114
115
		{0, 0, NULL, 0}
	};

Thomas White's avatar
Thomas White committed
116
117
	gtk_init(&argc, &argv);

118
	/* Short options */
Thomas White's avatar
Thomas White committed
119
	while ((c = getopt_long(argc, argv, "hp:b:i:c:e:g:",
120
	                        longopts, NULL)) != -1) {
Thomas White's avatar
Thomas White committed
121

122
		switch (c) {
Thomas White's avatar
Thomas White committed
123
		case 'h' :
124
125
			show_help(argv[0]);
			return 0;
Thomas White's avatar
Thomas White committed
126

Thomas White's avatar
Thomas White committed
127
		case 'p' :
128
129
			peaks = strdup(optarg);
			break;
Thomas White's avatar
Thomas White committed
130

Thomas White's avatar
Thomas White committed
131
		case 'i' :
132
133
134
135
136
137
138
			boost = atoi(optarg);
			if ( boost < 1 ) {
				ERROR("Intensity boost must be a positive"
				      " integer.\n");
			}
			break;

Thomas White's avatar
Thomas White committed
139
		case 'b' :
140
141
142
143
144
145
			binning = atoi(optarg);
			if ( boost < 1 ) {
				ERROR("Binning must be a positive integer.\n");
			}
			break;

146
147
148
149
		case 'c' :
			cscale = strdup(optarg);
			break;

Thomas White's avatar
Thomas White committed
150
151
152
153
		case 'e' :
			element = strdup(optarg);
			break;

154
155
156
157
		case 'g' :
			geometry = strdup(optarg);
			break;

Thomas White's avatar
Thomas White committed
158
		case 0 :
159
			break;
Thomas White's avatar
Thomas White committed
160

Thomas White's avatar
Thomas White committed
161
		default :
162
163
			return 1;
		}
Thomas White's avatar
Thomas White committed
164
165
166

	}

167
168
169
170
171
172
173
	nfiles = argc-optind;

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

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
	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);

189
	for ( i=0; i<nfiles; i++ ) {
190
		main_window_list[i] = displaywindow_open(argv[optind+i], peaks,
191
		                                         boost, binning,
192
		                                         config_cmfilter,
193
		                                         config_noisefilter,
194
		                                         colscale, element,
Thomas White's avatar
Thomas White committed
195
196
		                                         geometry,
		                                         config_showrings);
197
198
199
200
201
202
		if ( main_window_list[i] == NULL ) {
			ERROR("Couldn't open display window\n");
		} else {
			main_n_windows++;
		}
	}
203
204

	if ( main_n_windows == 0 ) return 0;
Thomas White's avatar
Thomas White committed
205
206
207
208
	gtk_main();

	return 0;
}