| Bsoft 2.0.5 Bernard's software package

bradsec.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
18 // Usage assistance
19 const char* use[] = {
20 " ",
21 "Usage: bradsec [options] input.img output.img",
22 "---------------------------------------------",
23 "Generates radial sections from 3D images.",
24 "The symmetry for O must be either O-3 or O-4.",
25 "The symmetry for I must be either I-3 or I-5.",
26 " ",
27 "Parameters:",
28 "-verbose 7 Verbosity of output.",
29 "-datatype u Force writing of a new data type.",
30 "-sampling 1.5,1.5,1.5 Sampling (default from image; a single value can be given).",
31 "-origin 0,-10,30 Set the origin for radial profile (default image origin).",
32 "-radii 14,123,2.68 Start, end and step size for radial shell calculation (default from input).",
33 "-symmetry C5 Point group symmetry.",
34 "-fraction 0.3 Spherical fraction (1=spherical shells, 0=symmetry-related shells).",
35 " ",
36 NULL
37 };
38
39 int main(int argc, char **argv)
40 {
41 // Initialize variables
42 DataType nudatatype(Unknown_Type); // Conversion to new type
43 Vector3<double> sam;
44 Vector3<double> origin; // Origin
45 int set_origin(0); // Flag to set origin
46 double rad_start(0), rad_end(0); // Radial limits
47 double rad_step(0); // Radial step size
48 Bsymmetry* sym = NULL; // Point group
49 double spherical_fraction(0); // Spherical fraction
50 Bstring outfile; // Output image file
51
52 int optind;
53 Boption* option = get_option_list(use, argc, argv, optind);
54 Boption* curropt;
55 for ( curropt = option; curropt; curropt = curropt->next ) {
56 if ( curropt->tag == "datatype" )
57 nudatatype = curropt->datatype();
58 if ( curropt->tag == "origin" ) {
59 if ( curropt->value[0] == 'c' ) {
60 set_origin = 2;
61 } else {
62 origin = curropt->origin();
63 set_origin = 1;
64 }
65 }
66 if ( curropt->tag == "sampling" )
67 sam = curropt->sampling();
68 if ( curropt->tag == "radii" )
69 if ( curropt->values(rad_start, rad_end, rad_step) < 2 )
70 cerr << "-radii: A range and step size must be specified!" << endl;
71 if ( curropt->tag == "symmetry" )
72 sym = curropt->symmetry();
73 if ( curropt->tag == "fraction" )
74 if ( ( spherical_fraction = curropt->value.real() ) <= 0 )
75 cerr << "-fraction: A fraction must be specified!" << endl;
76 }
77 option_kill(option);
78
79 double ti = timer_start();
80
81 Bimage* p = read_img(argv[optind++], 1, -1);
82 if ( p == NULL ) {
83 cerr << "Error: No input file read!" << endl;
84 bexit(-1);
85 }
86
87 // Get the output image file name
88 if ( optind < argc ) outfile = argv[optind];
89
90 if ( nudatatype == Unknown_Type )
91 nudatatype = p->data_type(); // Preserve the old type
92
93 if ( set_origin ) {
94 if ( set_origin == 2 ) p->origin(p->size()/2);
95 else p->origin(origin);
96 }
97
98 Bimage* prad = p->radial_sections(rad_start, rad_end, rad_step, spherical_fraction, sym);
99 if ( !prad ) {
100 cerr << "Error: No output image generated!" << endl;
101 bexit(-1);
102 }
103
104 if ( outfile.length() ) {
105 prad->change_type(nudatatype);
106 prad->label(get_cmd_line(argc, argv));
107 write_img(outfile, prad, 0);
108 }
109
110 delete p;
111 delete prad;
112 kill_symmetry(sym);
113
114 if ( verbose & VERB_TIME )
115 timer_report(ti);
116
117 bexit(0);
118 }
119
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bstring::real
double real()
Definition: Bstring.cpp:545
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
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
Bstring::length
long length() const
Definition: Bstring.cpp:263
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
verbose
int verbose
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
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
main
int main(int argc, char **argv)
Definition: bradsec.cpp:39
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::radial_sections
Bimage * radial_sections(double rad_start, double rad_end, double rad_step, double spherical_fraction, Bsymmetry *sym)
Calculates an image with slices giving the radial section projections.
Definition: Bimage_polar.cpp:1027
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
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
use
const char * use[]
Definition: bradsec.cpp:19
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
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
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
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