00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMPEM_IMAGE_HEADER_H
00009 #define IMPEM_IMAGE_HEADER_H
00010
00011 #include "em_config.h"
00012 #include "SpiderHeader.h"
00013 #include <IMP/algebra/Matrix2D.h>
00014 #include <IMP/algebra/utility.h>
00015 #include <IMP/algebra/endian.h>
00016 #include <cstdio>
00017 #include <iostream>
00018 #include <fstream>
00019 #include <cstring>
00020
00021 IMPEM_BEGIN_NAMESPACE
00022
00023
00024
00025
00026
00027 class IMPEMEXPORT ImageHeader
00028 {
00029 public:
00030
00031 typedef enum { IMG_BYTE = 0, IMG_IMPEM = 1,
00032 IMG_INT = 9,
00033 VOL_BYTE = 2, VOL_IMPEM = 3,
00034 VOL_INT = 10 ,
00035 IMG_FOURIER = -1, VOL_FOURIER = -3
00036 } img_type;
00037
00038
00039 ImageHeader() {
00040 clear();
00041 header_.fIform=(float)IMG_IMPEM;
00042 }
00043
00044
00045 ImageHeader(img_type im) {
00046 clear();
00047 header_.fIform=(float)im;
00048 }
00049
00050
00051 ImageHeader(float im) {
00052 clear();
00053 header_.fIform=im;
00054 }
00055
00056
00057 float get_image_type() const {
00058 return header_.fIform;
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 void set_image_type(img_type im) {
00070 this->set_image_type((float)im);
00071 }
00072
00073
00074
00075
00076
00077 void set_image_type(float im) {
00078 header_.fIform=im;
00079 }
00080
00081 #ifndef SWIG
00082
00083 friend std::ostream& operator<<(std::ostream& out, const ImageHeader& I) {
00084 out << "Image type : ";
00085 switch ((int) I.header_.fIform) {
00086 case IMG_BYTE:
00087 out << "2D Byte image";
00088 break;
00089 case IMG_IMPEM:
00090 out << "2D IMP EM image";
00091 break;
00092 case IMG_INT:
00093 out << "2D INT image";
00094 break;
00095 case VOL_BYTE:
00096 out << "3D Byte volume";
00097 break;
00098 case VOL_IMPEM:
00099 out << "3D IMP EM volume";
00100 break;
00101 case VOL_INT:
00102 out << "3D INT volume";
00103 break;
00104 case IMG_FOURIER:
00105 out << "2D Fourier image";
00106 break;
00107 case VOL_FOURIER:
00108 out << "3D Fourier volume";
00109 break;
00110 }
00111 out << std::endl;
00112 out << "Reversed : ";
00113 if (I.reversed_) {
00114 out << "TRUE" << std::endl;
00115 } else {
00116 out << "FALSE" << std::endl;
00117 }
00118 out << "dimensions : " << I.header_.fNslice << " x "
00119 << I.header_.fNrow << " x " << I.header_.fNcol
00120 << " (slices x rows x columns) " << std::endl;
00121
00122 out << "Euler angles (ZYZ convention): " << std::endl;
00123 out << " Phi (rotation around Z axis) = " <<
00124 I.header_.fPhi << std::endl;
00125 out << " Theta (tilt, rotation around new Y axis) = " <<
00126 I.header_.fTheta << std::endl;
00127 out << " Psi (third rotation around new Z axis) = " <<
00128 I.header_.fPsi << std::endl;
00129 out << "Origin Offsets : " << std::endl;
00130 out << " Xoff (origin offset in X-direction) = " <<
00131 I.header_.fXoff << std::endl;
00132 out << " Yoff (origin offset in Y-direction) = " <<
00133 I.header_.fYoff << std::endl;
00134 if (I.header_.fFlag == 1.0f || I.header_.fFlag == 2.0f) {
00135 out << " Phi1 = " << I.header_.fPhi1 ;
00136 out << " theta1 = " << I.header_.fTheta1 ;
00137 out << " Psi1 = " << I.header_.fPsi1 << std::endl;
00138 }
00139 if (I.header_.fFlag == 2.0f) {
00140 out << " Phi2 = " << I.header_.fPhi2 ;
00141 out << " theta2 = " << I.header_.fTheta2 ;
00142 out << " Psi2 = " << I.header_.fPsi2 << std::endl;
00143 }
00144 out << "Date : " << I.get_date() << std::endl;
00145 out << "Time : " << I.get_time() << std::endl;
00146 out << "Title : " << I.get_title() << std::endl;
00147 out << "Header size : " << I.get_header_size() << std::endl;
00148 out << "Weight : " << I.get_Weight() << std::endl;
00149 return out;
00150 }
00151 #endif
00152
00153
00154 void print_hard(std::ostream& out) const;
00155
00156
00157 inline void show_projection_params(std::ostream& out) const {
00158 out << "(Phi,Theta,Psi) = ( " << header_.fPhi << " , " << header_.fTheta
00159 << " , " << header_.fPsi << " ) " << " (y,x) = ( " << header_.fYoff
00160 << " , " << header_.fXoff << " ) " << std::endl;
00161 }
00162
00163
00164
00165 int read(const String filename, bool skip_type_check = false,
00166 bool force_reversed = false, bool skip_extra_checkings = false);
00167
00168
00169 bool read(std::ifstream& f, bool skip_type_check = false,
00170 bool force_reversed = false, bool skip_extra_checkings = false);
00171
00172
00173 void write(const String &filename, bool force_reversed = false);
00174
00175
00176 void write(std::ofstream& f, bool force_reversed = false);
00177
00178
00179 void clear();
00180
00181
00182 void set_header();
00183
00184
00185 bool get_reversed() const {
00186 return reversed_;
00187 }
00188
00189
00190 void set_reversed(bool value) {
00191 reversed_=value;
00192 }
00193
00194
00195 int get_header_size() const {
00196 return (int) header_.fNcol *(int) header_.fLabrec * sizeof(float);
00197 }
00198
00199
00200 float get_number_of_slices() const {
00201 return header_.fNslice;
00202 }
00203
00204
00205 void set_number_of_slices(float n) {
00206 header_.fNslice = n;
00207 }
00208
00209
00210 float get_number_of_rows() const {
00211 return header_.fNrow;
00212 }
00213
00214
00215 void set_number_of_rows(float n) {
00216 header_.fNrow = n;
00217 }
00218
00219
00220 float get_number_of_columns() const {
00221 return header_.fNcol;
00222 }
00223
00224
00225 void set_number_of_columns(float n) {
00226 header_.fNcol = n;
00227 }
00228
00229
00230 float get_old_rot() const {
00231 return header_.fAngle1;
00232 }
00233
00234
00235 void set_old_rot(float value) {
00236 header_.fAngle1= value;
00237 }
00238
00239
00240 float get_fAngle1() const {
00241 return header_.fAngle1;
00242 }
00243
00244
00245 void set_fAngle1(float value) {
00246 header_.fAngle1= value;
00247 }
00248
00249 float get_Scale() const {
00250 return header_.fScale;
00251 }
00252
00253 void set_Scale(float value) {
00254 header_.fScale=value;
00255 }
00256
00257
00258
00259
00260
00261 float get_Flip() const {
00262 return header_.Flip;
00263 }
00264
00265
00266
00267
00268 void set_Flip(float value) {
00269 header_.Flip=value;
00270 }
00271
00272 float get_Weight() const {
00273 return header_.Weight;
00274 }
00275
00276 void set_Weight(float value) {
00277 header_.Weight=value;
00278 }
00279
00280 float get_fNrec() const {
00281 return header_.fNrec;
00282 }
00283
00284 void set_fNrec(float value) {
00285 header_.fNrec = value;
00286 }
00287
00288 float get_fNlabel() const {
00289 return header_.fNlabel;
00290 }
00291
00292 void set_fNlabel(float value) {
00293 header_.fNlabel=value;
00294 }
00295
00296 float get_fIform() const {
00297 return header_.fIform;
00298 }
00299
00300 void set_fIform(float value) {
00301 header_.fIform = value;
00302 }
00303
00304 float get_fImami() const {
00305 return header_.fImami;
00306 }
00307
00308 void set_fImami(float value) {
00309 header_.fImami=value;
00310 }
00311
00312 float get_fFmax() const {
00313 return header_.fFmax;
00314 }
00315
00316 void set_fFmax(float value) {
00317 header_.fFmax= value;
00318 }
00319
00320 float get_fFmin() const {
00321 return header_.fFmin;
00322 }
00323
00324 void set_fFmin(float value) {
00325 header_.fFmin=value;
00326 }
00327
00328 float get_fAv() const {
00329 return header_.fAv;
00330 }
00331
00332 void set_fAv(float value) {
00333 header_.fAv=value;
00334 }
00335
00336 float get_fSig() const {
00337 return header_.fSig;
00338 }
00339
00340 void set_fSig(float value) {
00341 header_.fSig=value;
00342 }
00343
00344 float get_fIhist() const {
00345 return header_.fIhist;
00346 }
00347
00348 void set_fIhist(float value) {
00349 header_.fIhist=value;
00350 }
00351
00352 float get_fLabrec() const {
00353 return header_.fLabrec;
00354 }
00355
00356 void set_fLabrec(float value) {
00357 header_.fLabrec=value;
00358 }
00359
00360 float get_fIangle() const {
00361 return header_.fIangle;
00362 }
00363
00364 void set_fIangle(float value) {
00365 header_.fIangle=value;
00366 }
00367
00368 float get_xorigin() const {
00369 return header_.fXoff;
00370 }
00371
00372 void set_xorigin(float value) {
00373 header_.fXoff = value;
00374 }
00375
00376 float get_yorigin() const {
00377 return header_.fYoff;
00378 }
00379
00380 void set_yorigin(float value) {
00381 header_.fYoff = value;
00382 }
00383
00384 float get_zorigin() const {
00385 return header_.fZoff;
00386 }
00387
00388 void set_zorigin(float value) {
00389 header_.fZoff = value;
00390 }
00391
00392 float get_object_pixel_size() const {
00393 return header_.fScale;
00394 }
00395
00396 void set_object_pixel_size(float value) {
00397 header_.fScale = value;
00398 }
00399
00400 float get_fLabbyt() const {
00401 return header_.fLabbyt;
00402 }
00403
00404 void set_fLabbyt(float value) {
00405 header_.fLabbyt=value;
00406 }
00407
00408 float get_fLenbyt() const {
00409 return header_.fLenbyt;
00410 }
00411
00412 void set_fLenbyt(float value) {
00413 header_.fLenbyt=value;
00414 }
00415
00416 IMP::algebra::Matrix2D< double > get_fGeo_matrix();
00417
00418
00419 void set_origin_offsets(float Yoff, float Xoff);
00420 void set_origin_offsets(float Zoff, float Yoff, float Xoff);
00421
00422
00423 void set_euler_angles(float Phi, float Theta, float Psi);
00424 void set_euler_angles1(float Phi1, float Theta1, float Psi1);
00425 void set_euler_angles2(float Phi2, float Theta2, float Psi2);
00426
00427
00428
00429
00430
00431
00432
00433
00434 float get_fFlag() const {
00435 return header_.fFlag;
00436 }
00437
00438
00439
00440
00441
00442
00443
00444
00445 void set_fFlag(float value) {
00446 header_.fFlag = value;
00447 }
00448
00449 template<typename T>
00450 void get_euler_angles(T& Phi, T& Theta, T& Psi) const {
00451 Phi = (T) header_.fPhi;
00452 Theta = (T) header_.fTheta;
00453 Psi = (T) header_.fPsi;
00454 }
00455
00456 template<typename T>
00457 void get_euler_angles1(T& Phi1, T& Theta1, T& Psi1) const {
00458 Phi1 = (T) header_.fPhi1;
00459 Theta1 = (T) header_.fTheta1;
00460 Psi1 = (T) header_.fPsi1;
00461 }
00462
00463 template<typename T>
00464 void get_euler_angles2(T& Phi2, T& Theta2, T& Psi2) const {
00465 Phi2 = (T) header_.fPhi2;
00466 Theta2 = (T) header_.fTheta2;
00467 Psi2 = (T) header_.fPsi2;
00468 }
00469
00470 template<typename T>
00471 void get_origin_offsets(T &Yoff, T &Xoff) const {
00472 Yoff = (T) header_.fYoff;
00473 Xoff = (T) header_.fXoff;
00474 }
00475
00476 template<typename T>
00477 void get_origin_offsets(T &Zoff,T &Yoff,T &Xoff) const {
00478 Zoff = (T) header_.fZoff;
00479 Yoff = (T) header_.fYoff;
00480 Xoff = (T) header_.fXoff;
00481 }
00482
00483 void set_Phi(float value) {
00484 header_.fIangle = 1;
00485 header_.fPhi=value;
00486 }
00487
00488 float get_Phi() const {
00489 return header_.fPhi;
00490 }
00491
00492 void set_Theta(float value) {
00493 header_.fIangle = 1;
00494 header_.fTheta=value;
00495 }
00496
00497 float get_Theta() const {
00498 return header_.fTheta;
00499 }
00500
00501 void set_Psi(float value) {
00502 header_.fIangle = 1;
00503 header_.fPsi=value;
00504 }
00505
00506 float get_Psi() const {
00507 return header_.fPsi;
00508 }
00509
00510 void set_Phi1(float value) {
00511 header_.fFlag = 1.f;
00512 header_.fPhi1=value;
00513 }
00514
00515 float get_Phi1() const {
00516 return header_.fPhi1;
00517 }
00518
00519 void set_Theta1(float value) {
00520 header_.fFlag = 1.f;
00521 header_.fTheta1=value;
00522 }
00523
00524 float get_Theta1() const {
00525 return header_.fTheta1;
00526 }
00527
00528 void set_Psi1(float value) {
00529 header_.fFlag = 1.f;
00530 header_.fPsi1=value;
00531 }
00532
00533 float get_Psi1() const {
00534 return header_.fPsi1;
00535 }
00536
00537 void set_Phi2(float value) {
00538 header_.fFlag = 2.f;
00539 header_.fPhi2=value;
00540 }
00541
00542 float get_Phi2() const {
00543 return header_.fPhi2;
00544 }
00545
00546 void set_Theta2(float value) {
00547 header_.fFlag = 2.f;
00548 header_.fTheta2=value;
00549 }
00550
00551 float get_Theta2() const {
00552 return header_.fTheta2;
00553 }
00554
00555 void set_Psi2(float value) {
00556 header_.fFlag = 2.f;
00557 header_.fPsi2=value;
00558 }
00559
00560 float get_Psi2() const {
00561 return header_.fPsi2;
00562 }
00563
00564 bool is_normalized() const {
00565 if(std::abs(this->get_fAv()) <1e-6 &&
00566 std::abs(this->get_fSig()-1.0) < 1e-6) {
00567 return true;
00568 }
00569 return false;
00570 }
00571
00572
00573 char* get_date() const;
00574 char* get_time() const;
00575 void set_date();
00576 void set_time();
00577
00578
00579 void set_dimensions(float Ydim, float Xdim);
00580
00581 void get_dimensions(float& Ydim, float& Xdim) const;
00582
00583 void set_dimensions(float Zdim,float Ydim, float Xdim);
00584
00585 void get_dimensions(float& Zdim,float& Ydim, float& Xdim) const;
00586
00587
00588 char* get_title() const;
00589
00590
00591 void set_title(String newName);
00592
00593 private:
00594
00595
00596 SpiderHeader header_;
00597 bool reversed_;
00598 };
00599
00600 IMPEM_END_NAMESPACE
00601
00602 #endif