| Bsoft 2.0.5 Bernard's software package

bcat.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "img_combine.h"
11 #include "linked_list.h"
12 #include "utilities.h"
13 #include "options.h"
14 #include "timer.h"
15
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18
19
20 // Usage assistance
21 const char* use[] = {
22 " ",
23 "Usage: bcat [options] input.images",
24 "----------------------------------",
25 "Catenates a list of images into a multi-image file.",
26 "Any number of input images may be given and may include the wild card \"*\".",
27 "(However, VMS does not support Unix style usage of wild cards).",
28 "All images must have the same data type.",
29 " ",
30 "Actions:",
31 "-rescale -0.1,5.2 Rescale input images to average and standard deviation.",
32 " ",
33 "Parameters:",
34 "-verbose 3 Verbosity of output.",
35 "-datatype u Force writing of a new data type.",
36 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
37 "-origin 0.8,-10,15.7 Set the origin (default from input image).",
38 "-reverse Reverse the order of catenation.",
39 "-slices Pack 2D images as z-slices (default pack as separate images).",
40 "-size 10,50,8 New image size (pixels).",
41 "-fill 125.5 Fill value for padding (default average).",
42 "-raw d=f#x=120,120,1 Formatting to reinterpret image files.",
43 " ",
44 "Output:",
45 "-output output.img Output image (default temp.miff).",
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 Vector3<double> sam; // Units for the three axes (A/pixel)
55 Vector3<double> origin; // New image origin
56 int set_origin(0); // Flag to set origin
57 Bstring catfile = "temp.pif";
58 Bstring rawstring;
59 int setZslices(0); // Pack slices as separate 2D images
60 Vector3<long> nusize;
61 int reverse(0);
62 double nuavg(0), nustd(0);
63 int fill_type(FILL_AVERAGE); // Fill type for smaller images
64 double fill(0);
65
66 int optind;
67 Boption* option = get_option_list(use, argc, argv, optind);
68 Boption* curropt;
69 for ( curropt = option; curropt; curropt = curropt->next ) {
70 if ( curropt->tag == "datatype" )
71 nudatatype = curropt->datatype();
72 if ( curropt->tag == "sampling" )
73 sam = curropt->sampling();
74 if ( curropt->tag == "origin" ) {
75 if ( curropt->value[0] == 'c' ) {
76 set_origin = 2;
77 } else {
78 origin = curropt->origin();
79 set_origin = 1;
80 }
81 }
82 if ( curropt->tag == "reverse" )
83 reverse = 1;
84 if ( curropt->tag == "slices" )
85 setZslices = 1;
86 if ( curropt->tag == "size" )
87 nusize = curropt->size();
88 if ( curropt->tag == "rescale" ) {
89 if ( curropt->values(nuavg, nustd) < 2 )
90 cerr << "-rescale: Both averge and standard deviation must be specified!" << endl;
91 if ( nustd < 0 ) nustd = 0;
92 }
93 if ( curropt->tag == "fill" )
94 fill = curropt->fill(fill_type);
95 if ( curropt->tag == "raw" ) {
96 rawstring = curropt->value;
97 if ( rawstring.length() < 1 )
98 cerr << "-raw: A valid format reinterpretation string must be specified!" << endl;
99 }
100 if ( curropt->tag == "output" ) {
101 catfile = curropt->value;
102 if ( catfile.length() < 1 )
103 cerr << "-output: An output file must be specified!" << endl;
104 }
105 }
106 option_kill(option);
107
108 if ( verbose && argc < 3 ) {
109 cerr << "Error: No input files given!" << endl;
110 bexit(-1);
111 }
112
113 double ti = timer_start();
114
115 // Read all the file names
116 Bstring* file_list = NULL;
117 while ( optind < argc ) string_add(&file_list, argv[optind++]);
118 if ( !file_list ) {
119 cerr << "Error: No image files specified!" << endl;
120 bexit(-1);
121 }
122
123 if ( reverse ) reverse_list((char **) &file_list);
124
125 Bimage* pcat = img_catenate(file_list, rawstring, nudatatype,
126 nusize, setZslices, fill_type, fill, nuavg, nustd);
127
128 string_kill(file_list);
129
130 if ( sam.volume() > 0 ) pcat->sampling(sam);
131
132 if ( set_origin ) {
133 if ( set_origin == 2 ) pcat->origin(pcat->default_origin());
134 else pcat->origin(origin);
135 }
136
137 pcat->calculate_background();
138 pcat->label(get_cmd_line(argc, argv));
139 write_img(catfile, pcat, 0);
140
141 delete pcat;
142
143 if ( verbose & VERB_TIME )
144 timer_report(ti);
145
146 bexit(0);
147 }
148
Boption::fill
double fill(int &fill_type)
Definition: options.h:138
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
reverse_list
long reverse_list(char **list)
Reverse the order of items in a linked list.
Definition: linked_list.cpp:252
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
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:173
Bstring::length
long length() const
Definition: Bstring.cpp:263
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
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
linked_list.h
Header file for generalized linked list functions.
main
int main(int argc, char **argv)
Definition: bcat.cpp:50
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
img_combine.h
Header file for combining two images in various ways.
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
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Bimage::default_origin
Vector3< double > default_origin()
Definition: Bimage.h:585
Vector3< double >
use
const char * use[]
Definition: bcat.cpp:21
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
img_catenate
Bimage * img_catenate(Bstring *file_list, Bstring &rawstring, DataType newdatatype, Vector3< long > nusize, int setZslices=0, int fill_type=0, double fill=0, double newavg=0, double newstd=0)
Catenates a list of images into a multi-image structure.
Definition: img_combine.cpp:163
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
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
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760