| Bsoft 2.0.5 Bernard's software package

bhead.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "utilities.h"
11 #include "options.h"
12 #include "timer.h"
13
14 #include <iostream>
15 using namespace std;
16
17 // Declaration of global variables
18 extern int verbose; // Level of output to the screen
19
20 // Usage assistance
21 const char* use[] = {
22 " ",
23 "Usage: bhead [options] input.img output.img",
24 "-------------------------------------------",
25 "Reports on and modifies image parameters in the image header.",
26 "Image format extensions supported:",
27 "BioRad (pic), Brix (brx), CCP4 (map), Digital Instruments (di)",
28 "EM (em), Goodford (pot), GRD (grd), Imagic (img), MFF (mff)",
29 "Image Magick (miff), MRC (mrc), PIC (bp), PIF (pif), Spider (spi)",
30 "Suprim (spm), TIFF (tif), RAW (raw)",
31 "Background calculation flag:",
32 " 1=outside enclosing circle",
33 " 2=inside enclosing circle",
34 " 3=inside half-radius circle",
35 " ",
36 "Actions:",
37 "-information Show sub-image information.",
38 "-moments 6 Show sub-image moments up to the indicated order.",
39 "-get size Show selected information.",
40 "-recalculate Force recalculation of statistics.",
41 "-slices Interpret multiple 2D images as z-slices of a single 3D image.",
42 "-images Interpret slices of a single 3D image as 2D images.",
43 "-background 1 Calculate new background values (image not modified).",
44 "-Background 2 Calculate new background values and mask the background.",
45 "-subtractbackground Subtract the background.",
46 "-shiftbackground 1.6 Shift the background to this value.",
47 " ",
48 "Parameters:",
49 "-verbose 7 Verbosity of output.",
50 "-datatype u Force writing of a new data type.",
51 "-select 1 Select an image (first image = 0; default: all images).",
52 "-origin 0,-10.5,30 Set the origin.",
53 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
54 "-Sampling 1.5,1.5,1.5 Sets sampling and unit cell dimensions to fill image (A/pixel).",
55 "-setbackground 0.5 Set the background to this value.",
56 "-symmetry D6 Point group identifier.",
57 "-spacegroup 90 Set space group.",
58 "-unitcell 82,82.3,100,90,66.7,70 Set unit cell parameters (A and degrees).",
59 "-View 0.3,0.5,-0.2,35 Sets the view parameters for every image.",
60 "-label \"New title\" Give a new title or label in the header.",
61 "-fixtype 8 or 16 bit integer types are switched between signed and unsigned.",
62 " ",
63 NULL
64 };
65
66 int main(int argc, char **argv)
67 {
68 // Initialize variables
69 DataType nudatatype(Unknown_Type); // Conversion to new type
70 int show_sub_images(0); // Flag to show sub-image info
71 int show_moments(0); // Flag to show sub-image moments
72 Bstring get; // Tag for selected information
73 long setimg(-1); // Select all images
74 Vector3<double> origin; // Origin
75 int set_origin(0); // Flag to set origin
76 int set_stats(0);
77 int set_sampling(0); // 1=set sampling, 2=set sampling and reset unitcell
78 Vector3<double> sam; // Units for the three axes (A/pixel)
79 Bstring symmetry_string; // No symmetry specified
80 int spacegroup(0); // Space group
81 UnitCell uc; // Unit cell parameters
82 int calc_background(0); // Flag to calculate background values
83 int correct_background(0); // Flag to correct backgrounds
84 int set_background(0); // Flag to set backgrounds
85 int subtract_background(0); // Flag to subtract backgrounds
86 int shift_background(0); // Flag to shift backgrounds
87 double newbackground(0); // New background
88 View view; // View parameters
89 int set_view(0); // Flag to set the view
90 Bstring label; // Header title or label
91 int znswitch(0); // 0=not, 1=n2z, 2=z2n
92 int fixtype(0); // Flag to switch between signed and unsigned
93 int dataflag(0); // Flag to set if data must be read
94
95 int optind;
96 Boption* option = get_option_list(use, argc, argv, optind);
97 Boption* curropt;
98 for ( curropt = option; curropt; curropt = curropt->next ) {
99 if ( curropt->tag == "datatype" )
100 nudatatype = curropt->datatype();
101 if ( curropt->tag == "information" )
102 show_sub_images = 1;
103 if ( curropt->tag == "moments" )
104 if ( ( show_moments = curropt->value.integer() ) < 0 )
105 cerr << "-moments: A number of orders must be specified!" << endl;
106 if ( curropt->tag == "get" )
107 get = curropt->value.lower();
108 if ( curropt->tag == "recalculate" )
109 set_stats = dataflag = 1;
110 if ( curropt->tag == "select" )
111 if ( ( setimg = curropt->value.integer() ) < 0 )
112 cerr << "-select: An image number must be specified!" << endl;
113 if ( curropt->tag == "origin" ) {
114 if ( curropt->value[0] == 'c' ) {
115 set_origin = 2;
116 } else {
117 origin = curropt->origin();
118 set_origin = 1;
119 }
120 }
121 if ( curropt->tag == "sampling" ) {
122 sam = curropt->sampling();
123 set_sampling = 1;
124 }
125 if ( curropt->tag == "Sampling" ) {
126 sam = curropt->sampling();
127 if ( sam[0] > 0 ) set_sampling = 2;
128 }
129 if ( curropt->tag == "symmetry" )
130 symmetry_string = curropt->symmetry_string();
131 if ( curropt->tag == "spacegroup" )
132 if ( ( spacegroup = curropt->value.integer() ) < 1 )
133 cerr << "-spacegroup: A valid space group must be specified!" << endl;
134 if ( curropt->tag == "unitcell" )
135 uc = curropt->unit_cell();
136 if ( curropt->tag == "background" ) {
137 dataflag = 1;
138 if ( ( calc_background = curropt->value.integer() ) < 1 )
139 cerr << "-background: A calculation type must be specified!" << endl;
140 }
141 if ( curropt->tag == "Background" ) {
142 dataflag = 1;
143 if ( ( correct_background = curropt->value.integer() ) < 1 )
144 cerr << "-Background: A calculation type must be specified!" << endl;
145 }
146 if ( curropt->tag == "setbackground" ) {
147 newbackground = curropt->value.real();
148 set_background = 1;
149 }
150 if ( curropt->tag == "subtractbackground" )
151 subtract_background = dataflag = 1;
152 if ( curropt->tag == "shiftbackground" ) {
153 newbackground = curropt->value.real();
154 shift_background = dataflag = 1;
155 }
156 if ( curropt->tag == "View" ) {
157 view = curropt->view();
158 set_view = 1;
159 }
160 if ( curropt->tag == "label" )
161 label = curropt->value;
162 if ( curropt->tag == "slices" )
163 znswitch = 1;
164 if ( curropt->tag == "images" )
165 znswitch = 2;
166 if ( curropt->tag == "fixtype" )
167 fixtype = 1;
168 }
169 option_kill(option);
170
171 double ti = timer_start();
172
173 if ( verbose & VERB_PROCESS ) systype(1);
174
175 if ( verbose & VERB_PROCESS ) cout << "Number of processors: " << system_processors() << endl;
176
177 // Read image file
178 if ( set_stats || show_moments || calc_background || optind < argc - 1 ) dataflag = 1;
179 Bimage* p = read_img(argv[optind++], dataflag, setimg);
180 if ( !p ) bexit(-1);
181
182 if ( fixtype ) p->fix_type();
183
184 if ( znswitch == 1 )
185 if ( p->images_to_slices() < 0 ) bexit(-1);
186
187 if ( znswitch == 2 )
188 if ( p->slices_to_images() < 0 ) bexit(-1);
189
190 if ( set_stats ) {
191 p->statistics();
192 if (verbose ) show_sub_images = 1;
193 }
194
195 if ( calc_background ) {
196 p->calculate_background(calc_background);
197 if (verbose ) show_sub_images = 1;
198 }
199
200 if ( optind < argc ) {
201 if ( correct_background ) {
202 p->correct_background(correct_background);
203 if (verbose ) show_sub_images = 1;
204 }
205
206 if ( set_background ) {
207 p->background(newbackground);
208 if (verbose ) show_sub_images = 1;
209 }
210
211 if ( shift_background ) {
212 p->shift_background(newbackground);
213 if (verbose ) show_sub_images = 1;
214 }
215
216 if ( subtract_background ) {
217 p->subtract_background();
218 if (verbose ) show_sub_images = 1;
219 }
220
221 if ( set_view ) p->view(view);
222
223 /* if ( set_minmax ) {
224 p->min = p->smin = min;
225 p->max = p->smax = max;
226 }
227 */
228 if ( set_sampling ) {
229 p->sampling(sam);
230 if ( set_sampling > 1 ) p->unit_cell(UnitCell());
231 }
232
233 if ( set_origin ) {
234 if ( set_origin == 2 ) p->origin(p->default_origin());
235 else p->origin(origin);
236 }
237
238 if ( symmetry_string.length() ) p->symmetry(symmetry_string.str());
239
240 if ( uc.check() ) p->unit_cell(uc);
241
242 if ( spacegroup ) p->space_group(spacegroup);
243
244 if ( nudatatype != Unknown_Type ) p->change_type(nudatatype);
245
246 if ( label.length() ) p->label(label.str());
247 else p->label(get_cmd_line(argc, argv));
248
249 write_img(argv[optind], p, 0);
250 }
251
252 if ( show_sub_images ) p->subimage_information();
253
254 if ( show_moments ) p->moments(show_moments);
255
256 if ( get.length() ) p->get(get);
257
258 delete p;
259
260 if ( verbose & VERB_TIME )
261 timer_report(ti);
262
263 bexit(0);
264 }
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Boption::unit_cell
UnitCell unit_cell()
Definition: options.h:291
UnitCell
Definition: UnitCell.h:22
Bstring::real
double real()
Definition: Bstring.cpp:545
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Boption::symmetry_string
Bstring symmetry_string()
Definition: options.h:245
Bimage::slices_to_images
int slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
Definition: Bimage.cpp:2052
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
system_processors
size_t system_processors()
Returns the number of processors.
Definition: utilities.cpp:186
Bimage::fix_type
void fix_type()
Determines the replacement data type.
Definition: Bimage.cpp:1718
Bstring::length
long length() const
Definition: Bstring.cpp:263
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
Bimage::shift_background
int shift_background(double bkg)
Sets the background for each sub-image to a given value.
Definition: Bimage_background.cpp:351
Bimage::subimage_information
int subimage_information()
Prints out header information for all sub-images.
Definition: Bimage.cpp:2564
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
Bimage::subtract_background
int subtract_background()
Subtracts the background for each sub-image.
Definition: Bimage_background.cpp:337
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
Bimage::correct_background
int correct_background(long nn, int flag)
Corrects the background for one sub-image.
Definition: Bimage_background.cpp:202
Boption::view
View view()
Definition: options.h:259
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bimage::unit_cell
void unit_cell(UnitCell uc)
Definition: Bimage.h:601
use
const char * use[]
Definition: bhead.cpp:21
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
Bimage::get
double get(long nn, long xx, long yy, long zz, long cc=0)
Returns the data value at the given coordinates.
Definition: Bimage.cpp:937
Bimage::space_group
long space_group()
Definition: Bimage.h:591
Bimage::view
void view(double vx, double vy, double vz, double va)
Definition: Bimage.h:589
main
int main(int argc, char **argv)
Definition: bhead.cpp:66
verbose
int verbose
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Bimage::images_to_slices
int images_to_slices()
Changes the 2D images to slices in a 3D image.
Definition: Bimage.cpp:2093
Bimage::default_origin
Vector3< double > default_origin()
Definition: Bimage.h:585
Vector3< double >
Bimage::symmetry
string & symmetry()
Definition: Bimage.h:596
Boption::origin
Vector3< double > origin()
Definition: options.h:180
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
Bstring::lower
Bstring lower()
Definition: Bstring.cpp:308
View
Definition: View.h:26
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
UnitCell::check
bool check()
Definition: UnitCell.h:34
systype
SysType systype(int show)
Finds the system type - mostly just for byte order.
Definition: utilities.cpp:144
Bimage::background
double background(long nn)
Definition: Bimage.h:542
Bstring::str
string str()
Definition: Bstring.h:42
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
Bimage::moments
int moments(long max_order)
Prints out moments for all sub-images.
Definition: Bimage.cpp:2600
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563