| Bsoft 2.0.5 Bernard's software package

bplane.cpp
Go to the documentation of this file.
1
9 #include "model_create.h"
10 #include "model_plane.h"
11 #include "model_transform.h"
12 #include "model_views.h"
13 #include "model_links.h"
14 #include "model_util.h"
15 #include "utilities.h"
16 #include "options.h"
17 #include "timer.h"
18
19 // Declaration of global variables
20 extern int verbose; // Level of output to the screen
21
22
23 /* Usage assistance */
24 const char* use[] = {
25 " ",
26 "Usage: bplane [options] in.star",
27 "-------------------------------",
28 "Generates and manipulates plane models.",
29 " ",
30 "Actions for creation:",
31 "-plane 386,125 Generate a plane with the given length and width.",
32 "-setviews Fit a plane to the model and set the component views.",
33 "-fit Use the input model as guide to generate a plane model.",
34 " ",
35 "Actions:",
36 "-view 0.5,-0.2,0.3,35 View to orient plane: vector=normal, angle=in-plane rotation.",
37 "-guide poly.star Input guide model to adjust the plane to.",
38 " ",
39 "Parameters:",
40 "-verbose 7 Verbosity of output.",
41 "-separation 14.5 New component separation (default 10).",
42 "-sigma 150 Smoothness of the fit (default 100).",
43 "-componentradius 0.5 Component display radius.",
44 "-linkradius 0.5 Link display radius.",
45 " ",
46 "Input:",
47 "-map density.map Input map file.",
48 " ",
49 "Output:",
50 "-output newmod.star Output model file.",
51 " ",
52 NULL
53 };
54
55 int main(int argc, char **argv)
56 {
57 /* Initialize variables */
58 double length(0), width(0); // Length and width of new plane model
59 int setviews(0); // Flag to set the views based on a plane fit
60 int fit(0); // Generate a fitted plane model
61 View view; // Orientation for plane
62 double separation(10); // New component separation
63 double sigma(100); // Smoothness of fit to guide
64 // int normal(0); // Move components only along view vector
65 double compradius(0); // Component display radius
66 double linkradius(0); // Link display radius
67 Bstring paramfile; // Input parameter file name
68 Bstring guidefile; // Input guide model file name
69 Bstring mapfile; // Input map file name
70 Bstring outfile; // Output parameter file name
71
72 int optind;
73 Boption* option = get_option_list(use, argc, argv, optind);
74 Boption* curropt;
75 for ( curropt = option; curropt; curropt = curropt->next ) {
76 if ( curropt->tag == "plane" )
77 if ( curropt->values(length, width) < 2 )
78 cerr << "-plane: Both length and width must be specified!" << endl;
79 if ( curropt->tag == "setviews" ) setviews = 1;
80 if ( curropt->tag == "fit" ) fit = 1;
81 if ( curropt->tag == "view" )
82 view = curropt->view();
83 if ( curropt->tag == "separation" )
84 if ( ( separation = curropt->value.real() ) < 0.01 )
85 cerr << "-separation: The component separation must be specified!" << endl;
86 if ( curropt->tag == "sigma" )
87 if ( ( sigma = curropt->value.real() ) < 0.01 )
88 cerr << "-sigma: A distance must be specified!" << endl;
89 if ( curropt->tag == "componentradius" )
90 if ( ( compradius = curropt->value.real() ) < 1 )
91 cerr << "-componentradius: The component display radius must be specified!" << endl;
92 if ( curropt->tag == "linkradius" )
93 if ( ( linkradius = curropt->value.real() ) < 1 )
94 cerr << "-linkradius: The link display radius must be specified!" << endl;
95 if ( curropt->tag == "guide" )
96 guidefile = curropt->filename();
97 if ( curropt->tag == "map" )
98 mapfile = curropt->filename();
99 if ( curropt->tag == "output" )
100 outfile = curropt->filename();
101 }
102 option_kill(option);
103
104 double ti = timer_start();
105
106 // Read all the parameter files
107 Bstring* file_list = NULL;
108 Bmodel* model = NULL;
109 Bmodel* guide = NULL;
110
111 if ( length > 0 && width > 0 ) {
112 model = model_create_plane(length, width, 0, separation);
113 if ( !model ) {
114 cerr << "Error: The model creation failed!" << endl;
115 bexit(-1);
116 }
117 model_rotate(model, view);
118 model_set_views(model, view);
119 } else {
120 while ( optind < argc ) string_add(&file_list, argv[optind++]);
121 if ( file_list ) {
122 model = read_model(file_list, paramfile);
123 string_kill(file_list);
124 }
125 }
126
127 if ( guidefile.length() ) {
128 guide = read_model(guidefile, paramfile);
129 if ( !model ) model = guide;
130 }
131
132 if ( compradius ) models_process(model, compradius, model_set_component_radius);
133
134 if ( linkradius ) models_process(model, linkradius, model_set_link_radius);
135
136 if ( mapfile.length() ) model->fmap = mapfile;
137
138 if ( setviews ) model_fit_plane(model);
139
140 if ( fit ) {
141 guide = model;
142 model = model_generate_from_plane_guide(guide, separation, sigma);
143 model_kill (guide);
144 if ( !model ) {
145 cerr << "Error: The model creation from a guide failed!" << endl;
146 bexit(-1);
147 }
148 }
149
150 // Write an output parameter format file if a name is given
151 if ( outfile.length() && model ) {
152 model_update_comment(model, argc, argv);
153 write_model(outfile, model);
154 }
155
156 model_kill(model);
157
158 if ( verbose & VERB_TIME )
159 timer_report(ti);
160
161 bexit(0);
162 }
163
164
165
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
model_create.h
Library routines used for model creation.
model_create_plane
Bmodel * model_create_plane(double length, double width, double z, double distance)
Creates a plane with the given length, width, height, and component separation.
Definition: model_create.cpp:1170
model_views.h
Library routines used for analysing model component views.
utilities.h
Header file for general utilities.
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
use
const char * use[]
Definition: bplane.cpp:24
Bstring::length
long length() const
Definition: Bstring.cpp:263
model_set_views
long model_set_views(Bmodel *model, View view)
Sets views.
Definition: model_views.cpp:81
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
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1124
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
Boption::view
View view()
Definition: options.h:259
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
model_fit_plane
Vector3< double > model_fit_plane(Bmodel *model)
Fits a plane through a model.
Definition: model_plane.cpp:30
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
length
double length(vector< T > v)
Definition: Vector3.h:528
main
int main(int argc, char **argv)
Definition: bplane.cpp:55
verbose
int verbose
model_rotate
long model_rotate(Bmodel *model, Matrix3 mat)
Rotates the model.
Definition: model_transform.cpp:238
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::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Bmodel::fmap
Bstring fmap
Definition: rwmodel.h:125
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
View
Definition: View.h:26
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
model_generate_from_plane_guide
Bmodel * model_generate_from_plane_guide(Bmodel *guide, double separation, double sigma)
Generates a plane model and fits a plane through it.
Definition: model_plane.cpp:186
Bmodel
Definition: rwmodel.h:119
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
model_transform.h
Library routines used for model transformation.
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
model_plane.h
Library routines used for plane models.
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760