 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
25 ifstream fprm(filename.
c_str());
27 cerr <<
"Error: A text file specifying 2D transformations must be given!" << endl;
32 cout <<
"Reading 2D transformations from " << filename << endl;
35 fprm >> a[0] >> a[1] >> a[2] >> a[3] >> dx >> dy;
36 mg->
tilt_axis = (atan2(-a[0], a[1]) + atan2(-a[3], -a[2]))/2.0;
37 mg->
origin[0] -= a[0]*dx + a[2]*dy;
38 mg->
origin[1] -= a[1]*dx + a[3]*dy;
53 ifstream fprm(filename.
c_str());
55 cerr <<
"Error: A text file specifying tilt angles must be given!" << endl;
60 cout <<
"Reading tilt angles from " << filename << endl;
76 int mark_id(0), first(1);
81 ifstream fprm(filename.
c_str());
83 cerr <<
"Error: A text file specifying the 3D marker model must be given!" << endl;
87 fprm >> mark_id >> x >> y >> z >> dum >> dum;
88 while ( fprm >> word ) {
89 if ( word ==
"Pix:" ) fprm >> rec->
voxel_size[0];
90 if ( word ==
"Dim:" )
break;
97 cout <<
"Getting reconstruction parameters from " << filename << endl;
100 cout <<
"Getting reconstruction parameters from " << rec->
frec << endl;
107 cout << setprecision(3) <<
"Voxel size = " << rec->
voxel_size <<
" Origin = " << rec->
origin << endl;
109 while ( !fprm.eof() ) {
110 if ( first ) first = 0;
111 else fprm >> mark_id >> x >> y >> z >> dum >> dum;
112 if ( fprm.fail() )
break;
121 cout << mark_id <<
tab << x <<
tab << y <<
tab << z << endl;
134 ifstream fprm(filename.
c_str());
136 cerr <<
"Error: A binary IMOD file specifying the fiducial markers must be given!" << endl;
141 cout <<
"Reading markers from " << filename << endl;
151 fprm.read((
char *)tag, 4);
152 if ( fprm.fail() )
return -2;
154 fprm.read((
char *)tag, 4);
155 if ( fprm.fail() )
return -2;
159 if ( fprm.fail() )
return -2;
161 swapbytes((
unsigned char *) &imod->objsize, 4);
164 cout <<
"number of objects = " << imod->objsize << endl;
166 fprm.read((
char *)tag, 4);
167 if ( fprm.fail() )
return -2;
170 if ( fprm.fail() )
return -2;
172 swapbytes((
unsigned char *) &objt->contsize, 4);
175 cout <<
"number of contours = " << objt->contsize << endl;
177 for ( i=0; i<objt->contsize; i++ ) {
178 fprm.read((
char *)tag, 4);
179 if ( fprm.fail() )
return -2;
182 if ( fprm.fail() )
return -2;
184 swapbytes((
unsigned char *) &cont->psize, 4);
187 cout <<
"number of points = " << cont->psize << endl;
189 psize = 3*cont->psize*
sizeof(float);
190 point =
new float[3*cont->psize];
192 fprm.read((
char *)point, psize);
193 if ( fprm.fail() )
return -2;
195 swapbytes(psize, (
unsigned char *) point, 4);
204 cout << mg->
id <<
tab << mark->
id <<
tab << mark->
loc << endl;
244 if ( file_list->
empty() ) {
245 cerr <<
"No filenames given to create a project!" << endl;
261 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next ) {
265 cout <<
"DEBUG read_project_imod: reading " << file << endl;
271 cerr <<
"Error: Image file " << imgfile <<
" not read!" << endl;
272 error_show(
"read_project_imod", __FILE__, __LINE__);
283 for ( n=0; n<p->
images(); n++ ) {
286 if ( !field->
mg ) field->
mg = mg;
296 cout <<
"Creating field " << field->
id <<
", with " << n <<
" micrographs" << endl;
297 cout <<
"Pixel size: " << field->
mg->
pixel_size << endl;
298 cout <<
"Origin: " << field->
mg->
origin << endl;
305 if ( imgfile.
length() < 1 ) {
306 cerr <<
"Error: No image file provided!" << endl;
307 error_show(
"read_project_imod", __FILE__, __LINE__);
313 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next ) {
341 ofstream fprm(paramfile.
c_str());
343 error_show(
"write_imod_xf", __FILE__, __LINE__);
348 cout <<
"Writing 2D transformations to " << paramfile << endl;
357 fprm << setprecision(7);
358 for (
int i=0; i<4; ++i ) fprm <<
" " << setw(12) << a[i];
359 fprm << setprecision(3) <<
" " << setw(12) << a[0]*d[0] + a[1]*d[1]
360 <<
" " << setw(12) << a[2]*d[0] + a[3]*d[1] << endl;
379 ofstream fprm(paramfile.
c_str());
381 error_show(
"write_imod_tlt", __FILE__, __LINE__);
386 cout <<
"Writing tilt angles to " << paramfile << endl;
403 ofstream fprm(paramfile.
c_str());
405 error_show(
"write_project_imod", __FILE__, __LINE__);
410 cout <<
"Writing the 3D marker model to " << paramfile << endl;
412 for ( mark = rec->
mark; mark; mark = mark->
next ) {
413 fprm << setw(4) << mark->
id
414 << setprecision(2) << setw(10) << mark->
loc[0] + rec->
origin[0]
415 << setw(10) << mark->
loc[1] + rec->
origin[1]
416 << setw(10) << mark->
loc[2]
417 << setw(7) << 1 << setw(5) << mark->
id;
418 if ( mark == rec->
mark )
419 fprm <<
" Pix: " << setprecision(5) << setw(11) << rec->
voxel_size[0]
420 <<
" Dim: " << setprecision(0) << setw(6) << 2*rec->
origin[0]
421 << setw(6) << 2*rec->
origin[1];
int project_mg_tilt_to_matrix(Bproject *project)
Sets the matrix from the tilt and axis angles for each micrograph.
Bfield * field_add(Bfield **field, Bstring &field_id)
Adds a field-of-view parameter structure to a linked list.
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Vector3< double > voxel_size
Vector3< double > micrograph_get_nominal_origin(Bmicrograph *mg)
Gets the nominal origin for a micrograph.
string base(string &filename)
int write_project_imod(Bstring &imodfile, Bproject *project)
Creates IMOD parameter files from a project structure.
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Vector3< long > size() const
int read_imod_tlt(Bstring &filename, Bproject *project)
int read_imod_xyz(Bstring &filename, Breconstruction *rec)
int read_imod_fid(Bstring &filename, Bproject *project)
int write_imod_xyz(Bstring &imodfile, Bproject *project)
Converts between IMOD files and a micrograph parameter file.
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Header file for reading and writing micrograph parameters.
int slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
void swapbytes(unsigned char *v, size_t n)
Swaps bytes.
General image parameter class.
int write_imod_tlt(Bstring &imodfile, Bproject *project)
Header file for image processing from micrograph structures.
ostream & tab(ostream &out)
int read_imod_xf(Bstring &filename, Bproject *project)
int read_project_imod(Bstring *file_list, Bproject *project, int flag)
Creates a project structure using IMOD parameters.
Header file for 2D and 3D image I/O.
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
Header file for generalized linked list functions.
Vector3< double > pixel_size
void sampling(long nn, Vector3< double > u)
bool contains(const Bstring &s)
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
int write_imod_xf(Bstring &imodfile, Bproject *project)
Header file for single particle image processing in Bsoft.