| Bsoft 2.0.5 Bernard's software package

bsymcomp.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 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16
17 // Usage assistance
18 const char* use[] = {
19 " ",
20 "Usage: bsymcomp [options] input.img output.img",
21 "----------------------------------------------",
22 "Finds the best orientation that fits a symmetrized template.",
23 "The output is the rotated input image.",
24 " ",
25 "Parameters:",
26 "-verbose 1 Verbosity of output",
27 "-datatype u Force writing of a new data type.",
28 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; default from input file; a single value can be given).",
29 "-origin 110,50,44 Origin for rotations of the template (default taken from template image).",
30 "-angles 8.8,2.5,5.2 Step size for alpha, theta and phi, one value sets all (default 45 degrees).",
31 "-shift 0.5,3,-2.3 Shift to apply before symmetrization.",
32 "-symmetry C5 Point group symmetry.",
33 "-fill 0.02 Fill value (default image background).",
34 " ",
35 "Input:",
36 "-Template image.map Template with symmetry to search for.",
37 " ",
38 NULL
39 };
40
41
42 int main(int argc, char** argv)
43 {
44 // Initializing variables
45 DataType nudatatype(Unknown_Type); // Conversion to new type
46 Vector3<double> sam; // Units for the three axes (A/pixel)
47 Vector3<double> origin; // Template origin
48 int set_origin(0); // Flag to set origin
49 double alpha_step(M_PI_4); // Angular step size for alpha
50 double theta_step(M_PI_4); // Angular step size for theta
51 double phi_step(M_PI_4); // Angular step size for phi
52 Vector3<double> shift; // Shift to apply before symmetrization
53 int fill_type(FILL_BACKGROUND); // Use background
54 double fill(0); // Default fill is zero
55 Bsymmetry* sym = NULL; // Point group
56 Bstring template_file; // Symmmetric template
57
58 int i, optind;
59 Boption* option = get_option_list(use, argc, argv, optind);
60 Boption* curropt;
61 for ( curropt = option; curropt; curropt = curropt->next ) {
62 if ( curropt->tag == "datatype" )
63 nudatatype = curropt->datatype();
64 if ( curropt->tag == "sampling" )
65 sam = curropt->sampling();
66 if ( curropt->tag == "origin" ) {
67 if ( curropt->value[0] == 'c' ) {
68 set_origin = 2;
69 } else {
70 origin = curropt->origin();
71 set_origin = 1;
72 }
73 }
74 if ( curropt->tag == "angles" ) {
75 if ( ( i = curropt->values(alpha_step, theta_step, phi_step) ) < 1 )
76 cerr << "-angles: An angle step size must be specified" << endl;
77 else {
78 if ( i < 2 ) phi_step = theta_step = alpha_step;
79 else if ( i < 3 ) phi_step = theta_step;
80 alpha_step *= M_PI/180.0;
81 theta_step *= M_PI/180.0;
82 phi_step *= M_PI/180.0;
83 }
84 }
85 if ( curropt->tag == "shift" )
86 shift = curropt->vector3();
87 if ( curropt->tag == "symmetry" )
88 sym = curropt->symmetry();
89 if ( curropt->tag == "fill" )
90 fill = curropt->fill(fill_type);
91 if ( curropt->tag == "Template" )
92 template_file = curropt->filename();
93 }
94 option_kill(option);
95
96 double ti = timer_start();
97
98 // Read image file
99 Bimage* p = read_img(argv[optind++], 1, 0);
100
101 if ( !p ) {
102 cerr << "Error: No input file read!" << endl;
103 bexit(-1);
104 }
105
106 Bimage* ptemp = NULL;
107
108 if ( template_file.length() )
109 ptemp = read_img(template_file, 1, 0);
110
111 if ( !ptemp ) {
112 cerr << "Error: No template file read!" << endl;
113 bexit(-1);
114 }
115
116 if ( nudatatype == Unknown_Type )
117 nudatatype = p->data_type(); // Preserve the old type
118
119 if ( sam.volume() > 0 ) {
120 p->sampling(sam);
121 ptemp->sampling(sam);
122 }
123
124 if ( set_origin ) {
125 p->origin(origin);
126 }
127 if ( set_origin ) {
128 if ( set_origin == 2 ) {
129 p->origin(p->size()/2);
130 ptemp->origin(ptemp->size()/2);
131 } else {
132 p->origin(origin);
133 ptemp->origin(origin);
134 }
135 }
136
137 if ( fill_type == FILL_AVERAGE ) fill = p->average();
138 if ( fill_type == FILL_BACKGROUND ) {
139 if ( !p->background(long(0)) ) p->calculate_background();
140 fill = p->background(long(0));
141 }
142
143 p->background(fill);
144
145 Bimage* prot = p->find_symmetric_view(ptemp, sym,
146 phi_step, theta_step, alpha_step, shift);
147
148 // Write an output file if a name is given
149 if ( optind < argc ) {
150 prot->label(get_cmd_line(argc, argv));
151 prot->change_type(nudatatype);
152 write_img(argv[optind], prot, 0);
153 }
154
155 delete p;
156 delete ptemp;
157 delete prot;
158 kill_symmetry(sym);
159
160 if ( verbose & VERB_TIME )
161 timer_report(ti);
162
163 return 0;
164 }
165
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Boption::fill
double fill(int &fill_type)
Definition: options.h:138
use
const char * use[]
Definition: bsymcomp.cpp:18
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:174
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
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
Bimage::find_symmetric_view
Bimage * find_symmetric_view(Bimage *ptemp, Bsymmetry *sym, double phi_step, double theta_step, double alpha_step, Vector3< double > shift)
Finds the view that on symmetrizing fits best to a symmetric template.
Definition: Bimage_symmetry.cpp:1042
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:173
Bstring::length
long length() const
Definition: Bstring.cpp:263
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
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
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
verbose
int verbose
M_PI_4
#define M_PI_4
Definition: utilities.h:65
Bimage
General image parameter class.
Definition: Bimage.h:163
M_PI
#define M_PI
Definition: utilities.h:59
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
main
int main(int argc, char **argv)
Definition: bsymcomp.cpp:42
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:252
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::size
Vector3< long > size() const
Definition: Bimage.h:373
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
Bsymmetry
Definition: symmetry.h:38
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Boption::vector3
Vector3< double > vector3()
Definition: options.h:148
Vector3< double >
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
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bimage::average
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Definition: Bimage.cpp:1349
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
Vector3::volume
double volume()
Definition: Vector3.h:235
Bimage::background
double background(long nn)
Definition: Bimage.h:542
Bimage::data_type
DataType data_type()
Definition: Bimage.h:349
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
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::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563