00001 00005 /* 00006 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu) 00007 * Copyright (c) 2000-2006 Baylor College of Medicine 00008 * 00009 * This software is issued under a joint BSD/GNU license. You may use the 00010 * source code in this file under either license. However, note that the 00011 * complete EMAN2 and SPARX software packages have some GPL dependencies, 00012 * so you are responsible for compliance with the licenses of these packages 00013 * if you opt to use BSD licensing. The warranty disclaimer below holds 00014 * in either instance. 00015 * 00016 * This complete copyright notice must be included in any revised version of the 00017 * source code. Additional authorship citations may be added, but existing 00018 * author citations must be preserved. 00019 * 00020 * This program is free software; you can redistribute it and/or modify 00021 * it under the terms of the GNU General Public License as published by 00022 * the Free Software Foundation; either version 2 of the License, or 00023 * (at your option) any later version. 00024 * 00025 * This program is distributed in the hope that it will be useful, 00026 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00028 * GNU General Public License for more details. 00029 * 00030 * You should have received a copy of the GNU General Public License 00031 * along with this program; if not, write to the Free Software 00032 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00033 * 00034 * */ 00035 00036 #ifndef eman__imagicio2_h__ 00037 #define eman__imagicio2_h__ 1 00038 00039 #include "imageio.h" 00040 00041 namespace EMAN 00042 { 00073 class ImagicIO2:public ImageIO 00074 { 00075 public: 00076 static const char *HED_EXT; 00077 static const char *IMG_EXT; 00078 00079 explicit ImagicIO2(string filename, IOMode rw_mode = READ_ONLY); 00080 ~ImagicIO2(); 00081 00082 DEFINE_IMAGEIO_FUNC; 00083 static bool is_valid(const void *first_block); 00084 00085 /* If returns -1, then we have an old-style Imagic file 00086 * 00087 * @return 0 for new Imagic4D file, -1 for old-style Imagic file*/ 00088 int init_test(); 00089 00093 bool is_single_image_format() const 00094 { 00095 return false; 00096 } 00097 00101 int get_nimg(); 00102 00103 private: 00104 static const char *REAL_TYPE_MAGIC; 00105 static const char *CTF_MAGIC; 00106 00107 00108 enum DataType 00109 { 00110 IMAGIC_CHAR, 00111 IMAGIC_SHORT, 00112 IMAGIC_FLOAT, 00113 IMAGIC_FLOAT_COMPLEX, 00114 IMAGIC_FFT_FLOAT_COMPLEX, 00115 IMAGIC_UNKNOWN_TYPE 00116 }; 00117 00118 /*This enum is used to skip those char type when swap bytes between big endian and little endian*/ 00119 enum 00120 { 00121 NUM_4BYTES_PRE_IYLP = 14, 00122 NUM_4BYTES_AFTER_IXOLD = 14, 00123 NUM_4BYTES_AFTER_NAME = 150 //before HISTORY 00124 }; 00125 00126 enum RealType 00127 { 00128 VAX_VMS = 16777216, //for VAX/VMS 00129 LINUX_WINDOWS = 33686018, //for OSF, ULTRIX, LINUX, MS WINDOWS 00130 SGI_IBM = 67372036 //for SiliconGraphics, SUN, HP, IBM 00131 }; 00132 00136 struct Imagic4D { 00137 int imgnum; //1 image location number (1,2,3,...) 00138 int count; //2 total # images in file (1st record only), total number of images - 1 (0,1,2,...) 00139 int error; //3 error code for this image during IMAGIC run 00140 int headrec;//4 number of header records per image (=1 always) 00141 int month; //5 creation month 00142 int mday; //6 creation day 00143 int year; //7 creation year 00144 int hour; //8 creation hour 00145 int minute; //9 creation minute 00146 int sec; //10 creation second 00147 int rsize; //11 image size in bytes 00148 int izold; //12 top left Z co-ordinate before THREED-CUT 00149 int ny; //13 number of lines per image (for 1D data IXLP1=1) 00150 int nx; //14 number of pixels per line (IYLP) 00151 char type[4]; //15 only 'REAL', or 'INTG' are implemented for EMAN 00152 // 4 characters determining the image type 00153 // REAL : REAL/float 00154 // INTG : INTEGER*2/short 00155 // PACK : PACK/byte 00156 // COMP : 2 REAL / 2 float 00157 // RECO : complex format with 0 in imaginary part) 00158 int ixold; //16 top left X co-ordinate before CUT-IMAGE (boxing) 00159 int iyold; //17 top left Y co-ordinate before CUT-IMAGE (boxing) 00160 float avdens; //18 average density in image 00161 float sigma; //19 standard deviation of density 00162 float user1; //20 at user's own disposal 00163 float user2; //21 at user's own disposal 00164 float densmax; //22 highest density in image 00165 float densmin; //23 minimal density in image 00166 int complex; //24 label indicating that data is always complex 00167 float defocus1; //25 defocus value 1 00168 float defocus2; //26 defocus value 2 00169 float defangle; //27 defocus angle 00170 float sinostart; //28 start angle if image is a sinogram 00171 float sinoend; //29 end angle if image is a sinogram 00172 char label[80]; //30-49 coded NAME/TITLE of the image (80 characters) 00173 float ccc3d; //50 3D simularity criteria 00174 int ref3d; //51 3D membership 00175 int mident; //52 micrograph identification number 00176 int ezshift; //53 equivalent shift in Z direction 00177 int ealpha; //54 equivalent Euler angle alpha 00178 int ebeta; //55 equivalent Euler angle beta 00179 int egamma; //56 equivalent Euler angle gamma 00180 int unused1; //57 currently not used 00181 int unused2; //58 currently not used 00182 int nalisum; //59 number of image summed 00183 int pgroup; //60 point-group symmetry in international notation (622, for example) 00184 int izlp; //61 number of 2D planes in 3D data (for 1D/2D: IZLP=1) 00185 int i4lp; //62 number of objects in file: 00186 // 1D (IXLP=1): number of 1D spectra 00187 // 2D (IZLP=1): number of 2D images 00188 // 3D (IZLP>1): number of 3D volumes 00189 int i5lp; //63 00190 int i6lp; //64 00191 float alpha; //65 Euler angle alpha (3D and Angular Reconst.) 00192 float beta; //66 Euler angle beta (3D and Angular Reconst.) 00193 float gamma; //67 Euler angle gamma (3D and Angular Reconst.) 00194 int imavers; //68 IMAGIC version, which created the file (yyyymmdd) 00195 int realtype; //69 floating point type, machine stamp 00196 // 16777216 for VAX/VMS 00197 // 33686018 for OSF,ULTRIX, LINUX, MS Windows 00198 // 67372036 for SiliconGraphics, SUN, HP, IBM 00199 char buffer[120]; //70-99 Variables that control the buffering 00200 // during read/write in IMAGIC-5 programs. 00201 // PLEASE DO NOT TOUCH ! 00202 float angle; //100 last rotation angle 00203 float voltage; //101 acceleration voltage (kv) 00204 int spaberr; //102 sperical aberration (mm) 00205 int pcoher; //103 partial coherence 00206 float ccc; //104 cross correlation peak hight 00207 float errar; //105 error in angular reconstitution, if -1.0: the file is a special file (FABOSA) 00208 float err3d; //106 error in 3D reconstruction 00209 int ref; //107 (multi-) reference number 00210 float classno; //108 class number in MSA classification 00211 float locold; //109 location number before CUT-IMAGE (boxing), or before copy in ANG-RECONST and EX-COPY 00212 float repqual; //110 representation quality, used in MSA-RUN and MSA (eigen) filtering 00213 float zshift; //111 last shift in Z direction 00214 float xshift; //112 last shift in X direction 00215 float yshift; //113 last shift in Y direction 00216 float numcls; //114 number members in the class specified in CLASSNO, if this image represents a class average (class-sum image) 00217 float ovqual; //115 overall quality of the class in CLASSNO 00218 float eangle; //116 equivalent angle 00219 float exshift; //117 equivalent shift in X direction 00220 float eyshift; //118 equivalent shift in Y direction 00221 float cmtotvar; //119 total variance in data matrix relative to center of mass (MSA calculations) 00222 float informat; //120 Gauss norm / real*FT Space information of the data set 00223 int numeigen; //121 number of eigen values in MSA 00224 int niactive; //122 number of active images in MSA calculations 00225 float resolx; //123 Angstrom per pixel/voxel in X direction, if DAT1(105) = -1.0 (FABOSA): mm per pixel 00226 float resoly; //124 Angstrom per pixel/voxel in Y direction 00227 float resolz; //125 Angstrom per pixel/voxel in Z direction 00228 float alpha2; //126 Euler angle alpha (from projection matching), Special FABOSA variables if DAT1(105) = -1.0 00229 float beta2; //127 Euler angle beta (from projection matching), Special FABOSA variables if DAT1(105) = -1.0 00230 float gamma2; //128 Euler angle gamma (from projection matching), Special FABOSA variables if DAT1(105) = -1.0 00231 float nmetric; //129 Metric used in MSA calculations 00232 float actmsa; //130 a flag indicating whether the "image" is active or not. Used during MSA calculations 00233 float coosmsa[69]; //131-199 co-ordinates of "image" along factorial axis 00234 // number 1 through 69 (maximum possible). 00235 // Used during MSA calculations. 00236 // float eigval; //150 eigval, eigenvalues if the "images" represent eigenimages (eigenvalue #1 into loc#1 etc.) 00237 char history[228]; //220-256 coded history of image (228 characters) 00238 }; 00239 00240 size_t get_datatype_size(DataType t) const; 00241 int to_em_datatype(DataType t) const; 00242 void make_header_host_endian(Imagic4D & hed) const; 00243 void swap_header(Imagic4D & hed) const; 00244 DataType get_datatype_from_name(const char *name) const; 00245 00247 Ctf * read_ctf(const Imagic4D& hed) const; 00248 void write_ctf(const Ctf * const ctf, int image_index = 0); 00249 00250 int generate_machine_stamp() const; 00251 private: 00252 string filename; 00253 string hed_filename; 00254 string img_filename; 00255 00256 IOMode rw_mode; 00257 FILE *hed_file; 00258 FILE *img_file; 00259 00260 Imagic4D imagich; 00261 bool is_big_endian; 00262 bool initialized; 00263 bool is_new_hed; 00264 bool is_new_img; 00265 00266 DataType datatype; 00267 int nz; 00268 }; 00269 00270 } 00271 00272 00273 #endif //eman__imagicio2_h__