Bsoft  2.1.0
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 Bplot* img_plot_radial(Bimage* p, Bstring& title);
18 
19 // Usage assistance
20 const char* use[] = {
21 " ",
22 "Usage: bradsec [options] input.img output.img",
23 "---------------------------------------------",
24 "Generates symmetry-adjusted radial sections from 3D images.",
25 "The symmetry for O must be either O-3 or O-4.",
26 "The symmetry for I must be either I-3 or I-5.",
27 " ",
28 "Parameters:",
29 "-verbose 7 Verbosity of output.",
30 "-datatype u Force writing of a new data type.",
31 "-sampling 1.5,1.5,1.5 Sampling (default from image; a single value can be given).",
32 "-origin 0,-10,30 Set the origin for radial profile (default image origin).",
33 "-radii 14,123,2.68 Start, end and step size for radial shell calculation (default from input).",
34 "-symmetry C5 Point group symmetry.",
35 "-fraction 0.3 Spherical fraction (1=spherical shells, 0=symmetry-related shells).",
36 "-fill 127 Fill value for excluded region: average (default), background, or value.",
37 " ",
38 "Output:",
39 "-Postscript radsec.ps Symmetry-adjusted profile.",
40 " ",
41 NULL
42 };
43 
44 int main(int argc, char **argv)
45 {
46  // Initialize variables
47  DataType nudatatype(Unknown_Type); // Conversion to new type
48  Vector3<double> sam; // Sampling
49  Vector3<double> origin; // Origin
50  int set_origin(0); // Flag to set origin
51  double rad_start(0), rad_end(0); // Radial limits
52  double rad_step(0); // Radial step size
53  Bsymmetry* sym = NULL; // Point group
54  double spherical_fraction(0); // Spherical fraction
55  double fill(0); // Fill value for excluded region
56  int fill_type(FILL_AVERAGE); // Fill type for excluded region
57  Bstring outfile; // Output image file
58  Bstring psfile; // Output profile file
59 
60  int optind;
61  Boption* option = get_option_list(use, argc, argv, optind);
62  Boption* curropt;
63  for ( curropt = option; curropt; curropt = curropt->next ) {
64  if ( curropt->tag == "datatype" )
65  nudatatype = curropt->datatype();
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 == "sampling" )
75  sam = curropt->scale();
76  if ( curropt->tag == "radii" )
77  if ( curropt->values(rad_start, rad_end, rad_step) < 2 )
78  cerr << "-radii: A range and step size must be specified!" << endl;
79  if ( curropt->tag == "symmetry" )
80  sym = curropt->symmetry();
81  if ( curropt->tag == "fraction" )
82  if ( ( spherical_fraction = curropt->value.real() ) <= 0 )
83  cerr << "-fraction: A fraction must be specified!" << endl;
84  if ( curropt->tag == "fill" )
85  fill = curropt->fill(fill_type);
86  if ( curropt->tag == "Postscript" )
87  psfile = curropt->filename();
88  }
89  option_kill(option);
90 
91  double ti = timer_start();
92 
93  Bimage* p = read_img(argv[optind++], 1, -1);
94  if ( p == NULL ) {
95  cerr << "Error: No input file read!" << endl;
96  bexit(-1);
97  }
98 
99  // Get the output image file name
100  if ( optind < argc ) outfile = argv[optind];
101 
102  if ( nudatatype == Unknown_Type )
103  nudatatype = p->data_type(); // Preserve the old type
104 
105  if ( set_origin ) {
106  if ( set_origin == 2 ) p->origin(p->size()/2);
107  else p->origin(origin);
108  }
109 
110  if ( !sym ) sym = init_point_group_symmetry("C1");
111 
112  Bimage* prad = p->radial_sections(rad_start, rad_end, rad_step, spherical_fraction, sym, fill_type, fill);
113  if ( !prad ) {
114  cerr << "Error: No output image generated!" << endl;
115  bexit(-1);
116  }
117 
118  if ( psfile.length() ) {
119  Bstring title = "Symmetry-adjusted radial average: " + sym->label;
120  Bimage* prof = p->radial_symmetry_adjusted(rad_start, rad_end, rad_step, spherical_fraction, sym);
121  Bplot* plot = img_plot_radial(prof, title);
122  if ( plot ) {
123  ps_plot(psfile, plot);
124  delete plot;
125  }
126  delete prof;
127  }
128 
129  if ( outfile.length() ) {
130  prad->change_type(nudatatype);
131  write_img(outfile, prad, 0);
132  }
133 
134  delete p;
135  delete prad;
136  kill_symmetry(sym);
137 
138  if ( verbose & VERB_TIME )
139  timer_report(ti);
140 
141  bexit(0);
142 }
143 
144 
146 {
147  long i, k, ncol(p->images()*p->channels() + 1);
148 
149  Bplot* plot = new Bplot(1, p->sizeX(), ncol);
150  plot->title(title);
151  plot->page(0).title(title);
152  plot->page(0).columns(ncol);
153  plot->page(0).column(0).label("Distance(A)");
154  plot->page(0).column(0).axis(1);
155  for ( i=1; i<ncol; ++i ) {
156  plot->page(0).column(i).number(i);
157  plot->page(0).column(i).type(2);
158  plot->page(0).column(i).label("Average");
159  plot->page(0).column(i).axis(3);
160  }
161 // plot->page(0).axis(1).min(minrad);
162 // plot->page(0).axis(1).max(maxrad);
163  plot->page(0).axis(3).min(p->minimum());
164  plot->page(0).axis(3).max(p->maximum());
165 
166  for ( i=0; i<plot->rows(); ++i )
167  (*plot)[i] = p->sampling(0)[0]*i;
168 
169  for ( i=0, k=plot->rows(); i<p->data_size(); ++i, ++k )
170  (*plot)[k] = (*p)[i];
171 
172  return plot;
173 }
Boption
A class for a command line input option.
Definition: options.h:26
verbose
int verbose
ps_plot
int ps_plot(Bstring filename, Bplot *plot)
Generates postscript graphs.
Definition: ps_plot.cpp:129
Boption::scale
Vector3< double > scale()
Definition: options.h:190
Bstring
Definition: Bstring.h:29
Bplot::rows
void rows(long n)
Definition: Bplot.h:212
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
main
int main(int argc, char **argv)
Definition: bradsec.cpp:44
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
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
Bplot
Definition: Bplot.h:146
Bstring::real
double real()
Definition: Bstring.cpp:553
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:177
options.h
Header file for option handlers.
Bcolumn::type
long type()
Definition: Bplot.h:66
Boption::origin
Vector3< double > origin()
Definition: options.h:180
Bsymmetry
Definition: symmetry.h:38
Bimage::maximum
double maximum()
Definition: Bimage.h:542
Bcolumn::axis
long axis()
Definition: Bplot.h:68
Bpage::axis
Baxis & axis(long id)
Definition: Bplot.h:117
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:240
Bpage::title
Bstring & title()
Definition: Bplot.h:100
Bimage::images
long images()
Definition: Bimage.h:504
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
Bimage::radial_symmetry_adjusted
Bimage * radial_symmetry_adjusted(double rad_start, double rad_end, double rad_step, double spherical_fraction, Bsymmetry *sym)
Calculates the symmetry-adjusted radial average of an image.
Definition: Bimage_polar.cpp:209
Boption::value
Bstring value
Definition: options.h:30
Bimage
General image parameter class.
Definition: Bimage.h:177
timer.h
Utilities for timing functions.
Bpage::column
Bcolumn & column(long i)
Definition: Bplot.h:110
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
Bplot::title
Bstring & title()
Definition: Bplot.h:194
Bimage::radial_sections
Bimage * radial_sections(double rad_start, double rad_end, double rad_step, double spherical_fraction, Bsymmetry *sym, int fill_type=FILL_USER, double fill=0)
Calculates an image with slices giving the radial section projections.
Definition: Bimage_polar.cpp:1134
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
Baxis::min
double min()
Definition: Bplot.h:30
use
const char * use[]
Definition: bradsec.cpp:20
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
utilities.h
Header file for general utilities.
Boption::fill
double fill(int &fill_type)
Definition: options.h:138
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
rwimg.h
Header file for 2D and 3D image I/O.
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
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::minimum
double minimum()
Definition: Bimage.h:541
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
Bcolumn::label
Bstring & label()
Definition: Bplot.h:63
Bplot::page
Bpage & page(long i)
Definition: Bplot.h:216
DataType
DataType
Base data type specifier.
Definition: utilities.h:150
Bsymmetry::label
Bstring label
Definition: symmetry.h:41
Bcolumn::number
long number()
Definition: Bplot.h:61
Bimage::channels
long channels()
Definition: Bimage.h:384
Baxis::max
double max()
Definition: Bplot.h:32
Bpage::columns
void columns(long ncol)
Definition: Bplot.h:105
img_plot_radial
Bplot * img_plot_radial(Bimage *p, Bstring &title)
Definition: bradsec.cpp:145