| Bsoft 2.0.5 Bernard's software package

bcyl.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 int img_plot_max_vs_angle(Bimage* p);
18
19 // Usage assistance
20 const char* use[] = {
21 " ",
22 "Usage: bcyl [options] input.img output.img",
23 "------------------------------------------",
24 "Unwraps an image to its cylindrical projection.",
25 " ",
26 "Actions:",
27 "-symmetrize Symmetrizes a map cylindrically around the origin.",
28 "-unwrap 1.5 Unwraps an image to its cylindrical projection with the given angle.",
29 "-autocorrelate Autocorrelates the unwrapped map and outputs the autocorrelation map.",
30 "-rescale -0.1,5.2 Rescale data to average and standard deviation (after -truncate).",
31 "-shells Calculate cylindrical shells projecting along the y-axis.",
32 "-reslice yzx Reslice (switch axes) after unwrapping.",
33 " ",
34 "Parameters:",
35 "-verbose 7 Verbosity of output.",
36 "-datatype u Force writing of a new data type.",
37 "-origin 0,-10.5,30 Set the origin.",
38 "-resolution 4.5,130 Resolution range for correlation (default 0 - 1e6 angstrom).",
39 " ",
40 NULL
41 };
42
43 int main(int argc, char **argv)
44 {
45 // Initialize variables
46 int symmetrize(0); // Flag to symmetrize cylindrically
47 double unwrap_angle(0); // Angle for cylindrical unwrapping
48 int autocorrelate(0); // Flag to autocorrelate the unwrapped map
49 int shells(0); // Flag to calculate cylindrical shells
50 int setrescale(0);
51 double nuavg(0), nustd(0); // Rescaling to average and stdev
52 int setreslice(0);
53 Bstring order("xyz");
54 DataType nudatatype = Unknown_Type; // Conversion to new type
55 Vector3<double> origin {0,0,0}; // Origin
56 int set_origin(0); // Flag to set origin
57 double hires(0), lores(1e6); // Limiting resolution range (hires must be > 0 to be set)
58
59 int optind;
60 Boption* option = get_option_list(use, argc, argv, optind);
61 Boption* curropt;
62 for ( curropt = option; curropt; curropt = curropt->next ) {
63 if ( curropt->tag == "symmetrize" ) symmetrize = 1;
64 if ( curropt->tag == "unwrap" ) {
65 if ( ( unwrap_angle = curropt->value.real() ) < 0.1 )
66 cerr << "-unwrap: An angle must be specified!" << endl;
67 else
68 unwrap_angle *= M_PI/180.0;
69 }
70 if ( curropt->tag == "autocorrelate" ) autocorrelate = 1;
71 if ( curropt->tag == "shells" ) shells = 1;
72 if ( curropt->tag == "rescale" ) {
73 if ( curropt->values(nuavg, nustd) < 2 )
74 cerr << "-rescale: Both average and standard deviation must be specified!" << endl;
75 else
76 setrescale = 1;
77 if ( nustd <= 0 ) setrescale = 0;
78 }
79 if ( curropt->tag == "reslice" ) {
80 if ( curropt->value.length() < 3 )
81 cerr << "-reslice: The order of x, y and z must be specified!" << endl;
82 else {
83 order = curropt->value;
84 setreslice = 1;
85 }
86 }
87 if ( curropt->tag == "datatype" )
88 nudatatype = curropt->datatype();
89 if ( curropt->tag == "origin" ) {
90 if ( curropt->value[0] == 'c' ) {
91 set_origin = 2;
92 } else {
93 origin = curropt->origin();
94 set_origin = 1;
95 }
96 }
97 if ( curropt->tag == "resolution" )
98 if ( curropt->values(hires, lores) < 1 )
99 cerr << "-resolution: A high resolution limit must be specified" << endl;
100 }
101 option_kill(option);
102
103 double ti = timer_start();
104
105 // Read image file
106 Bimage* p = read_img(argv[optind++], 1, -1);
107 if ( p == NULL ) bexit(-1);
108
109 if ( set_origin ) {
110 if ( set_origin == 2 ) p->origin(p->default_origin());
111 else p->origin(origin);
112 }
113
114 if ( symmetrize ) p->symmetrize_cylinder();
115
116 Bimage* pcyl = NULL;
117 if ( unwrap_angle > 0 ) {
118 pcyl = p->cartesian_to_cylindrical(p->sizeX()/2, TWOPI/unwrap_angle);
119 delete p;
120 p = pcyl;
121 if ( autocorrelate ) {
122 p->auto_correlate(hires, lores);
123 img_plot_max_vs_angle(p);
124 }
125 }
126
127 if ( shells ) p->cylindrical_shells();
128
129 if ( optind < argc ) {
130 if ( setrescale ) p->rescale_to_avg_std(nuavg, nustd);
131 if ( setreslice ) p->reslice(order);
132
133 p->change_type(nudatatype);
134
135 // Copy the command line to the label field of the image structure
136 p->label(get_cmd_line(argc, argv));
137
138 write_img(argv[optind], p, 0);
139 }
140
141 delete p;
142 order = 0;
143
144 if ( verbose & VERB_TIME )
145 timer_report(ti);
146
147 bexit(0);
148 }
149
150 int img_plot_max_vs_angle(Bimage* p)
151 {
152 long i, x, y(0), z, z1, z2, zm, n, dz(10);
153 double a, v, cc_max;
154
155 for ( n=0; n<p->images(); n++ ) {
156 z1 = 0; z2 = dz;
157 cout << "Image " << n+1 << ":" << endl << "Angle\tz\tCC" << endl;
158 for ( x=0; x<p->sizeX(); x++ ) {
159 a = x*TWOPI/p->sizeX();
160 for ( z=z1, zm=0, cc_max = p->minimum(); z<z2; z++ ) {
161 i = p->index(0, x, y, z, n);
162 v = (*p)[i];
163 if ( cc_max < v ) {
164 cc_max = v;
165 zm = z;
166 }
167 }
168 z1 = (zm > dz)? zm - dz: 0;
169 z2 = zm + dz;
170 cout << a*180.0/M_PI << tab << zm*p->sampling()[2] << tab << cc_max << endl;
171 }
172 cout << endl;
173 }
174
175 return 0;
176 }
177
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
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
Bimage::index
long index(long nx, long ny) const
Definition: Bimage.h:383
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bimage::symmetrize_cylinder
Bimage * symmetrize_cylinder(int flag)
Calculates a cylindrically symmetrized map.
Definition: Bimage_helix.cpp:524
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
Bimage::auto_correlate
int auto_correlate(double hires, double lores)
Calculates an autocorrelation map by Fast Fourier transformation.
Definition: Bimage_correlate.cpp:265
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
use
const char * use[]
Definition: bcyl.cpp:20
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
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
verbose
int verbose
Bimage::reslice
void reslice(const char *order)
Definition: Bimage.h:709
main
int main(int argc, char **argv)
Definition: bcyl.cpp:43
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
Bimage::default_origin
Vector3< double > default_origin()
Definition: Bimage.h:585
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::cylindrical_shells
int cylindrical_shells()
Calculates an image with slices representing cylindrical shell projections.
Definition: Bimage_polar.cpp:855
Bimage::cartesian_to_cylindrical
Bimage * cartesian_to_cylindrical(long nannuli, long nphi, int flag=0)
Calculates an image with cylindrical coordinates.
Definition: Bimage_polar.cpp:519
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::images
long images()
Definition: Bimage.h:491
img_plot_max_vs_angle
int img_plot_max_vs_angle(Bimage *p)
Definition: bcyl.cpp:150
Bimage::minimum
double minimum()
Definition: Bimage.h:534
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
TWOPI
#define TWOPI
Definition: utilities.h:68
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563