Bsoft  2.1.0
Bernard's software package
bheight.cpp
Go to the documentation of this file.
1 
9 #include "rwimg.h"
10 #include "symmetry.h"
11 #include "ps_views.h"
12 #include "linked_list.h"
13 #include "options.h"
14 #include "utilities.h"
15 #include "timer.h"
16 
17 // Declaration of global variables
18 extern int verbose; // Level of output to the screen
19 
20 
21 // Usage assistance
22 const char* use[] = {
23 " ",
24 "Usage: bheight [options] input.img output.img",
25 "---------------------------------------------",
26 "Calculates 2D height images from a 3D map.",
27 " ",
28 "Actions:",
29 "-axis y Project down a major axis (x, y, z or 0, 1, 2).",
30 "-View 0.3,-0.5,0.8,33 View to generate symmetry-related projections.",
31 "-Tilt -65,72,2.5,55 Tilt series of projections with angle min, max, step and axis angle.",
32 "-side 15 Generate side view projections within the given angle from the equator.",
33 "-random 24 Generate a number of random projections.",
34 " ",
35 "Parameters:",
36 "-verbose 7 Verbosity of output.",
37 "-datatype u Force writing of a new data type.",
38 "-origin 10,-10,20 Origin for rotation (voxels, default 0,0,0).",
39 "-sampling 2,3.5,1 Sampling (angstrom/voxel, a single value sets all three).",
40 "-symmetry D6 Symmetry: Point group identifier.",
41 "-angles 8,6 Step sizes for theta and phi in the asymmetric unit, one value sets both.",
42 "-threshold 1.2 Density threshold to indicate boundary of object (default 0).",
43 " ",
44 "Output:",
45 "-Plotviews plot.ps Output postscript file with a plot of projection vectors.",
46 " ",
47 NULL
48 };
49 
50 int main(int argc, char **argv)
51 {
52  // Initialize variables
53  DataType nudatatype(Unknown_Type); // Conversion to new type
54  char axis('n'); // Projection axis
55  Vector3<double> origin; // Origin
56  int set_origin(0); // Flag to set origin
57  Vector3<double> sam; // Units for the three axes (A/pixel)
58  Bstring symmetry_string("C1"); // Default: asymmetric or C1 point group
59  double theta_step(0); // Angular step size for theta
60  double phi_step(0); // Angular step size for phi
61  double ang_min(0), ang_max(0), ang_step(0), ang_axis(0); // Tilt series
62  double side_ang(-1); // Side view variation angle
63  int nviews(0); // Number of views
64  int view_flag(1); // Flag for projection generation
65  View theview; // View to generate symmetry-related projections
66  int symviews(0); // Flag to generate symmetry-related projections
67  double threshold(0); // Density threshold
68  int ps_flag(0); // Flag for postscript output
69  Bstring ps_file;
70 
71  int i, optind;
72  Boption* option = get_option_list(use, argc, argv, optind);
73  Boption* curropt;
74  for ( curropt = option; curropt; curropt = curropt->next ) {
75  if ( curropt->tag == "axis" )
76  if ( ( axis = curropt->value[0] ) < 'a' )
77  cerr << "-axis: An axis for projection must be specified!" << endl;
78  if ( curropt->tag == "datatype" )
79  nudatatype = curropt->datatype();
80  if ( curropt->tag == "origin" ) {
81  if ( curropt->value[0] == 'c' ) {
82  set_origin = 2;
83  } else {
84  origin = curropt->origin();
85  set_origin = 1;
86  }
87  }
88  if ( curropt->tag == "sampling" )
89  sam = curropt->scale();
90  if ( curropt->tag == "random" )
91  if ( ( nviews = curropt->value.integer() ) < 1 )
92  cerr << "-random: A number of views must be specified!" << endl;
93  if ( curropt->tag == "symmetry" )
94  symmetry_string = curropt->symmetry_string();
95  if ( curropt->tag == "angles" ) {
96  if ( ( i = curropt->values(theta_step, phi_step) ) < 1 )
97  cerr << "-angles: An angle step size must be specified!" << endl;
98  else {
99  theta_step *= M_PI/180.0;
100  if ( i < 2 ) phi_step = theta_step;
101  else phi_step *= M_PI/180.0;
102  }
103  }
104  if ( curropt->tag == "View" ) {
105  theview = curropt->view();
106  symviews = ps_flag = 1;
107  }
108  if ( curropt->tag == "Tilt" ) {
109  if ( curropt->values(ang_min, ang_max, ang_step, ang_axis) < 3 )
110  cerr << "-Tilt: Three angles must be specified!" << endl;
111  else {
112  ang_min *= M_PI/180.0;
113  ang_max *= M_PI/180.0;
114  ang_step *= M_PI/180.0;
115  ang_axis *= M_PI/180.0;
116  }
117  }
118  if ( curropt->tag == "side" ) {
119  if ( ( side_ang = curropt->value.real() ) < 1 )
120  cerr << "-side: One angle must be specified!" << endl;
121  else
122  side_ang *= M_PI/180.0;
123  }
124  if ( curropt->tag == "threshold" )
125  if ( ( threshold = curropt->value.real() ) < 0 )
126  cerr << "-threshold: A positive value must be specified!" << endl;
127  if ( curropt->tag == "Plotviews" )
128  ps_file = curropt->filename();
129  }
130  option_kill(option);
131 
132  double ti = timer_start();
133 
134  Bsymmetry* sym = init_point_group_symmetry(symmetry_string);
135  View* views = NULL;
136 
137  if ( axis == 'n' ) {
138  if ( nviews ) {
139  views = random_views(nviews);
140  } else if ( side_ang > -1 ) {
141  views = side_views(sym, side_ang, theta_step, phi_step);
142  } else if ( ang_step ) {
143  views = tilt_views(ang_min, ang_max, ang_step, ang_axis);
144  } else if ( symviews ) {
145  views = symmetry_get_all_views(sym, theview);
146  } else if ( theta_step && phi_step ) {
147  views = asymmetric_unit_views(sym, theta_step, phi_step, view_flag);
148  ps_flag = 1;
149  }
150  if ( views ) {
151  nviews = count_list((char *) views);
152  if ( verbose )
153  cout << "Generating " << nviews << " projections" <<endl << endl;
154  if ( ps_file.length() )
155  ps_views(ps_file, symmetry_string, views, ps_flag);
156  }
157  } else if ( axis == 'z' ) {
158  views = new View(0,0,1,0);
159  } else if ( axis == 'y' ) {
160  views = new View(0,1,0,0);
161  } else if ( axis == 'x' ) {
162  views = new View(1,0,0,0);
163  }
164 
165  kill_symmetry(sym);
166 
167  if ( optind >= argc ) {
168  if ( views ) kill_list((char *) views, sizeof(View));
169  bexit(0);
170  }
171 
172  // Read image file
173  int dataflag(0);
174  if ( optind < argc - 1 ) dataflag = 1;
175 
176  Bimage* p = read_img(argv[optind++], dataflag, -1);
177  if ( p == NULL ) bexit(-1);
178 
179  if ( nudatatype == Unknown_Type )
180  nudatatype = p->data_type(); // Preserve the old type
181 
182  if ( sam.volume() ) p->sampling(sam);
183 
184  if ( set_origin ) {
185  if ( set_origin == 2 ) p->origin(p->default_origin());
186  else p->origin(origin);
187  }
188 
190 
191  Bimage* pheight = p->height(views, threshold);
192 
193  if ( views ) kill_list((char *) views, sizeof(View));
194 
195  if ( optind < argc ) {
196  pheight->change_type(nudatatype);
197  write_img(argv[optind], pheight, 0);
198  }
199 
200  delete p;
201  delete pheight;
202 
203  if ( verbose & VERB_TIME )
204  timer_report(ti);
205 
206  bexit(0);
207 }
208 
209 
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::height
Bimage * height(View *views, double threshold=0)
Calculates a set of height images from a 3D density map.
Definition: Bimage_topo.cpp:230
Boption::scale
Vector3< double > scale()
Definition: options.h:190
symmetry_get_all_views
View * symmetry_get_all_views(Bsymmetry *sym, View asu_view)
Get all symmetry-related views of one given view.
Definition: symmetry.cpp:442
use
const char * use[]
Definition: bheight.cpp:22
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
Bstring
Definition: Bstring.h:29
verbose
int verbose
Bstring::integer
long integer()
Definition: Bstring.cpp:547
Boption::datatype
DataType datatype()
Definition: options.h:93
symmetry.h
Header file for general symmetry functions.
random_views
View * random_views(int nviews)
Calculates a set of random views.
Definition: View.cpp:147
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
Bimage::default_origin
Vector3< double > default_origin()
Definition: Bimage.h:592
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
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
asymmetric_unit_views
View * asymmetric_unit_views(Bsymmetry *sym, double theta_step, double phi_step, int flag)
Initializes a well-distributed set of views in an asymmetric unit.
Definition: symmetry.cpp:564
View
Definition: View.h:26
Boption::origin
Vector3< double > origin()
Definition: options.h:180
Boption::view
View view()
Definition: options.h:247
Bsymmetry
Definition: symmetry.h:38
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
Boption::tag
Bstring tag
Definition: options.h:29
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Boption::value
Bstring value
Definition: options.h:30
Bimage
General image parameter class.
Definition: Bimage.h:177
timer.h
Utilities for timing functions.
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
Boption::symmetry_string
Bstring symmetry_string()
Definition: options.h:233
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
ps_views
int ps_views(Bstring &filename, Bstring &symmetry_string, View *view, int flags)
Generates postscript plot of views on the unit sphere.
Definition: ps_views.cpp:34
side_views
View * side_views(Bsymmetry *sym, double side_ang, double theta_step, double phi_step)
Initializes a set of views around the z-axis for helical projection.
Definition: symmetry.cpp:763
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
Bimage::data_type
DataType data_type()
Definition: Bimage.h:362
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
Bstring::length
long length() const
Definition: Bstring.cpp:263
init_point_group_symmetry
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
Definition: symmetry.cpp:39
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
Vector3::volume
double volume()
Definition: Vector3.h:237
rwimg.h
Header file for 2D and 3D image I/O.
main
int main(int argc, char **argv)
Definition: bheight.cpp:50
tilt_views
View * tilt_views(double ang_min, double ang_max, double ang_step, double axis)
Initializes a set of views tilted around the y axis.
Definition: View.cpp:70
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
linked_list.h
Header file for generalized linked list functions.
Boption::filename
Bstring filename()
Definition: options.h:85
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
DataType
DataType
Base data type specifier.
Definition: utilities.h:150
ps_views.h
Header file for postscript tools dealing with views.