| Bsoft 2.0.5 Bernard's software package

bmodmask.cpp
Go to the documentation of this file.
1
9 #include "rwmodel.h"
10 #include "model_mask.h"
11 #include "model_links.h"
12 #include "model_util.h"
13 #include "utilities.h"
14 #include "options.h"
15 #include "timer.h"
16
17 // Declaration of global variables
18 extern int verbose; // Level of output to the screen
19
20 /* Usage assistance */
21 const char* use[] = {
22 " ",
23 "Usage: bmodmask [options] in1.star [in2.star...]",
24 "------------------------------------------------",
25 "Generates a mask from a model if an output image is specified.",
26 " ",
27 "Actions:",
28 "-type hull Mask type: model, hull, shell, level.",
29 "-invert Invert the mask after creation.",
30 " ",
31 "Parameters:",
32 "-verbose 7 Verbose output.",
33 "-componentradius 8.4 Set display radius for all components.",
34 "-linkradius 5.1 Set display radius for all links.",
35 " ",
36 "Parameters for mask creation:",
37 "-datatype u Force writing of a new data type (default float).",
38 "-size 100,120,80 Mask size (default from model).",
39 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
40 "-origin 0.8,-10,15.7 Set the origin for the mask.",
41 "-edge 1.5 Edge width for model mask (default 1 angstrom).",
42 "-width 34.8 Shell mask width (default 1 angstrom).",
43 "-curved Flag to indicate curved hull or shell surface (default not).",
44 "-fast Use fast but less comprehensive algorithm for shell and hull masks.",
45 "-smooth 2 Edge smoothing in pixels (default 0).",
46 " ",
47 "Input:",
48 "-parameters param.star Input parameter file.",
49 " ",
50 "Output:",
51 "-output file.star Output model file.",
52 "-mask mask.map Output mask image.",
53 " ",
54 NULL
55 };
56
57 int main(int argc, char **argv)
58 {
59 /* Initialize variables */
60 DataType nudatatype = Float; // Mask data type
61 int mask_type(-1); // 0=model, 1=hull, 2=shell, 3=level
62 Vector3<long> mask_size; // Size for creating a mask
63 Vector3<double> sam; // Map sampling
64 Vector3<double> origin; // Mask origin
65 double edge(1); // Edge width for model mask
66 double shell_width(1); // Shell mask width
67 int curv_flag(0); // Curved surface flag for hull and shell masks
68 int invert(0); // Flag for mask inversion
69 double comprad(0); // Component display radius
70 double linkrad(0); // Link display radius
71 int smooth(0); // Edge smoothing in pixels
72 int fast(0); // Flag for fast algorithm for hull and shell masks
73 Bstring paramfile; // Input parameter file
74 Bstring outfile; // Output model file
75 Bstring maskfile; // Output mask file
76
77 int optind;
78 Boption* option = get_option_list(use, argc, argv, optind);
79 Boption* curropt;
80 for ( curropt = option; curropt; curropt = curropt->next ) {
81 if ( curropt->tag == "type" ) {
82 if ( curropt->value[0] == 'm' ) mask_type = 0;
83 if ( curropt->value[0] == 'h' ) mask_type = 1;
84 if ( curropt->value[0] == 's' ) mask_type = 2;
85 if ( curropt->value[0] == 'l' ) mask_type = 3;
86 }
87 if ( curropt->tag == "componentradius" )
88 if ( ( comprad = curropt->value.real() ) < 1 )
89 cerr << "-componentradius: A radius must be specified!" << endl;
90 if ( curropt->tag == "linkradius" )
91 if ( ( linkrad = curropt->value.real() ) < 1 )
92 cerr << "-linkradius: A radius must be specified!" << endl;
93 if ( curropt->tag == "invert" ) invert = 1;
94 if ( curropt->tag == "datatype" )
95 nudatatype = curropt->datatype();
96 if ( curropt->tag == "size" )
97 mask_size = curropt->size();
98 if ( curropt->tag == "sampling" )
99 sam = curropt->sampling();
100 if ( curropt->tag == "origin" )
101 origin = curropt->origin();
102 if ( curropt->tag == "edge" )
103 if ( ( edge = curropt->value.real() ) < 0.001 )
104 cerr << "-edge: The edge width must be specified!" << endl;
105 if ( curropt->tag == "width" )
106 if ( ( shell_width = curropt->value.real() ) < 1 )
107 cerr << "-width: The shell width must be specified!" << endl;
108 if ( curropt->tag == "curved" ) curv_flag = 1;
109 if ( curropt->tag == "smooth" )
110 if ( ( smooth = curropt->value.integer() ) < 1 )
111 cerr << "-smooth: The number of smoothing pixels must be specified!" << endl;
112 if ( curropt->tag == "fast" ) fast = 1;
113 if ( curropt->tag == "parameters" )
114 paramfile = curropt->filename();
115 if ( curropt->tag == "output" )
116 outfile = curropt->filename();
117 if ( curropt->tag == "mask" )
118 maskfile = curropt->filename();
119 }
120 option_kill(option);
121
122 double ti = timer_start();
123
124 // Read all the parameter files
125 Bstring* file_list = NULL;
126 while ( optind < argc ) string_add(&file_list, argv[optind++]);
127 if ( !file_list ) {
128 cerr << "Error: No parameter or image files specified!" << endl;
129 bexit(-1);
130 }
131
132 Bmodel* model = read_model(file_list, paramfile);
133 string_kill(file_list);
134
135 if ( !model ) {
136 cerr << "Error: Input file not read!" << endl;
137 bexit(-1);
138 }
139
140 if ( comprad ) models_process(model, comprad, model_set_component_radius);
141
142 if ( linkrad ) models_process(model, linkrad, model_set_link_radius);
143
144 Bimage* pmask = NULL;
145 if ( maskfile.length() && mask_size.volume() && mask_type >= 0 ) {
146 switch ( mask_type ) {
147 case 0:
148 pmask = model_create_mask(model, mask_size, origin, sam, edge);
149 break;
150 case 1:
151 pmask = model_create_hull_mask(model, mask_size, origin, sam, curv_flag, fast);
152 break;
153 case 2:
154 pmask = model_create_shell_mask(model, mask_size, origin, sam, shell_width, curv_flag, fast);
155 break;
156 case 3:
157 pmask = model_create_level_mask(model, mask_size, origin, sam);
158 break;
159 }
160 if ( invert ) pmask->mask_invert();
161 if ( smooth > 0 ) pmask->filter_average(2*smooth + 1);
162 pmask->change_type(nudatatype);
163 model->fmap = maskfile;
164 pmask->label(get_cmd_line(argc, argv));
165 write_img(maskfile, pmask, 0);
166 delete pmask;
167 }
168
169 // Write an output parameter format file if a name is given
170 if ( outfile.length() && model ) {
171 model_update_comment(model, argc, argv);
172 write_model(outfile, model);
173 }
174
175 model_kill(model);
176
177 if ( verbose & VERB_TIME )
178 timer_report(ti);
179
180 bexit(0);
181 }
182
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
model_set_component_radius
long model_set_component_radius(Bmodel *model, double comprad)
Set the display radius for all components to a specific value.
Definition: rwmodel.cpp:1264
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
main
int main(int argc, char **argv)
Definition: bmodmask.cpp:57
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
model_util.h
Library routines used for model processing.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
Bimage::mask_invert
long mask_invert()
Inverts a mask.
Definition: Bimage_mask.cpp:221
Bstring::length
long length() const
Definition: Bstring.cpp:263
model_create_shell_mask
Bimage * model_create_shell_mask(Bmodel *model, Vector3< long > size, Vector3< double > origin, Vector3< double > sam, double shell_width, int curv_flag, int fast)
Calculates a shell mask covering a model structure.
Definition: model_mask.cpp:191
model_create_mask
Bimage * model_create_mask(Bmodel *model, Vector3< long > size, Vector3< double > origin, Vector3< double > sam, double edge)
Calculates a mask of the components and links of a model structure.
Definition: model_mask.cpp:34
model_links.h
Library routines used for model link processing.
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
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Float
Definition: utilities.h:157
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1124
Bimage::filter_average
int filter_average(long kernel_size)
Applies an averaging filter to an image.
Definition: Bimage_filter.cpp:208
model_create_hull_mask
Bimage * model_create_hull_mask(Bmodel *model, Vector3< long > size, Vector3< double > origin, Vector3< double > sam, int curv_flag, int fast)
Calculates a mask based on the periphery of a model structure.
Definition: model_mask.cpp:103
model_set_link_radius
long model_set_link_radius(Bmodel *model, double linkrad)
Set the display radius for all links to a specific value.
Definition: model_links.cpp:139
use
const char * use[]
Definition: bmodmask.cpp:21
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
model_update_comment
int model_update_comment(Bmodel *model, int n, char **strings)
Puts a set of strings and time in the comment of a model.
Definition: rwmodel.cpp:1158
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
model
Bmodel * model
Definition: bshow.cpp:32
read_model
Bmodel * read_model(Bstring &filename)
Definition: rwmodel.cpp:28
write_model
int write_model(Bstring &filename, Bmodel *model)
Writes model parameters.
Definition: rwmodel.cpp:91
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Bmodel::fmap
Bstring fmap
Definition: rwmodel.h:125
rwmodel.h
Header file for reading and writing atomic model files.
Vector3< long >
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
model_create_level_mask
Bimage * model_create_level_mask(Bmodel *model, Vector3< long > size, Vector3< double > origin, Vector3< double > sam)
Calculates a mask with one level per model.
Definition: model_mask.cpp:285
model_mask.h
Functions to generate masks from models.
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
Bmodel
Definition: rwmodel.h:119
verbose
int verbose
options.h
Header file for option handlers.
models_process
long models_process(Bmodel *model, long(modfunc)(Bmodel *))
Process a list of models using the specified function.
Definition: model_util.cpp:36
Vector3::volume
double volume()
Definition: Vector3.h:235
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
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760