| Bsoft 2.0.5 Bernard's software package

bdif.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: bdif [options] [input.img] output.img",
21 "--------------------------------------------",
22 "Analyzes diffraction patterns.",
23 " ",
24 "Actions:",
25 "-findorigin Find the origin of the diffraction pattern.",
26 " ",
27 "Parameters:",
28 "-verbose 7 Verbosity of output.",
29 "-datatype u Force writing of a new data type.",
30 "-origin 60.4,-32.2,44 Origin of image (voxels).",
31 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
32 "-resolution 4.5,130 Resolution range for correlation (default 0 - 1e6 angstrom).",
33 "-angle 36.8 Angle for directional averages (default 0).",
34 " ",
35 NULL
36 };
37
38 int main(int argc, char* argv[])
39 {
40 // Initialize variables
41 DataType nudatatype(Unknown_Type); // Conversion to new type
42 Vector3<double> sam; // Units for the three axes (A/pixel)
43 int find_origin(0);
44 int set_origin(0);
45 Vector3<double> origin; // Origin in file
46 double angle(0); // Angle for directional averages
47 double hires(0), lores(0); // Limiting resolution range (hires must be > 0 to be set)
48
49 int optind;
50 Boption* option = get_option_list(use, argc, argv, optind);
51 Boption* curropt;
52 for ( curropt = option; curropt; curropt = curropt->next ) {
53 if ( curropt->tag == "findorigin" )
54 find_origin = 1;
55 if ( curropt->tag == "datatype" )
56 nudatatype = curropt->datatype();
57 if ( curropt->tag == "sampling" )
58 sam = curropt->sampling();
59 if ( curropt->tag == "origin" ) {
60 if ( curropt->value[0] == 'c' ) {
61 set_origin = 2;
62 } else {
63 origin = curropt->origin();
64 set_origin = 1;
65 }
66 }
67 if ( curropt->tag == "resolution" )
68 if ( curropt->values(hires, lores) < 1 )
69 cerr << "-resolution: A high resolution limit must be specified" << endl;
70 if ( curropt->tag == "angle" )
71 angle = curropt->value.real() * M_PI/180.0;
72 }
73 option_kill(option);
74
75 double ti = timer_start();
76
77 Bimage* p = read_img(argv[optind++], 1, -1);
78 Bimage* pmask = NULL;
79
80 if ( !p ) {
81 cerr << "Error: No input file read!" << endl;
82 bexit(-1);
83 }
84
85 if ( nudatatype == Unknown_Type ) nudatatype = p->data_type(); // Preserve the old type
86
87 if ( nudatatype >= Float ) p->change_type(nudatatype); // Convert for efficiency
88
89 if ( set_origin ) {
90 if ( set_origin == 2 ) p->origin(p->default_origin());
91 else p->origin(origin);
92 }
93
94 if ( sam.volume() ) p->sampling(sam);
95
96 if ( hires < p->sampling()[0] ) hires = p->sampling()[0]*10;
97 if ( lores < hires ) lores = hires*100;
98
99 double radius(p->sizeX()/4.0);
100 if ( find_origin ) p->find_center(pmask, hires, lores, radius, 0, 1);
101
102 long i, len(p->sizeX()/2);
103 Vector3<double> end(cos(angle)*len, sin(angle)*len, 0);
104 Bimage* prad = p->radial(0, len, 1);
105 Bimage* pdir1 = p->extract_line(0, p->image->origin(), end, 5);;
106 end = Vector3<double>(sin(angle)*len, cos(angle)*len, 0);
107 Bimage* pdir2 = p->extract_line(0, p->image->origin(), end, 5);;
108
109 cout << "Radius\ts\tAvg\tDir1\tDir2" << endl;
110 for ( i=1; i<prad->sizeX(); i++ )
111 cout << i << tab << p->sizeX()*p->sampling()[0]/i << tab << (*prad)[i] << tab << (*pdir1)[i] << tab << (*pdir2)[i] << endl;
112 cout << endl;
113
114 delete prad;
115 delete pdir1;
116 delete pdir2;
117
118 // Write an output file if a file name is given
119 if ( optind < argc ) {
120 p->change_type(nudatatype);
121 p->label(get_cmd_line(argc, argv));
122 write_img(argv[optind], p, 0);
123 }
124
125 delete p;
126 delete pmask;
127
128 if ( verbose & VERB_TIME )
129 timer_report(ti);
130
131 bexit(0);
132 }
133
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::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
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.
Float
Definition: utilities.h:157
Bimage
General image parameter class.
Definition: Bimage.h:163
Bimage::extract_line
Bimage * extract_line(long nn, Vector3< double > start, Vector3< double > end, long width)
Extracts a line from an image into a new image.
Definition: Bimage_extract.cpp:509
main
int main(int argc, char *argv[])
Definition: bdif.cpp:38
M_PI
#define M_PI
Definition: utilities.h:59
use
const char * use[]
Definition: bdif.cpp:18
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
verbose
int verbose
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bimage::find_center
int find_center(Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Finds the center of mass of an image by cross-correlation with its inverse.
Definition: Bimage_correlate.cpp:1233
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
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::radial
Bimage * radial(long minrad, long maxrad, double rad_step=1, int wrap=0)
Calculates the radial average of an image.
Definition: Bimage_polar.cpp:33
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
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563