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 bool is_single_image_format() const 00086 { 00087 return false; 00088 } 00089 00090 int get_nimg(); 00091 00092 private: 00093 static const char *REAL_TYPE_MAGIC; 00094 static const char *CTF_MAGIC; 00095 00096 00097 enum DataType 00098 { 00099 IMAGIC_CHAR, 00100 IMAGIC_SHORT, 00101 IMAGIC_FLOAT, 00102 IMAGIC_FLOAT_COMPLEX, 00103 IMAGIC_FFT_FLOAT_COMPLEX, 00104 IMAGIC_UNKNOWN_TYPE 00105 }; 00106 00107 enum 00108 { 00109 NUM_4BYTES_PRE_IXOLD = 14, 00110 NUM_4BYTES_AFTER_IXOLD = 14, 00111 NUM_4BYTES_AFTER_SPACE = 207 00112 }; 00113 00114 enum RealType 00115 { 00116 VAX_VMS = 16777216, //for VAX/VMS 00117 LINUX_WINDOWS = 33686018, //for OSF, ULTRIX, LINUX, MS WINDOWS 00118 SGI_IBM = 67372036 //for SiliconGraphics, SUN, HP, IBM 00119 }; 00120 00124 struct Imagic4D { 00125 int imnum; //1 image location number (1,2,3,...) 00126 int count; //2 total # images in file (1st record only), total number of images - 1 (0,1,2,...) 00127 int error; //3 error code for this image during IMAGIC run 00128 int headrec;//4 number of header records per image (=1 always) 00129 int month; //5 creation month 00130 int mday; //6 creation day 00131 int year; //7 creation year 00132 int hour; //8 creation hour 00133 int minute; //9 creation minute 00134 int sec; //10 creation second 00135 int reals; //11 image size in bytes 00136 int izold; //12 top left Z co-ordinate before THREED-CUT 00137 int ny; //13 number of lines per image (for 1D data IYLP1=1) 00138 int nx; //14 number of pixels per line 00139 char type[4]; //15 only 'REAL', or 'INTG' are implemented for EMAN 00140 // 4 characters determining the image type 00141 // REAL : REAL/float 00142 // INTG : INTEGER*2/short 00143 // PACK : PACK/byte 00144 // COMP : 2 REAL / 2 float 00145 // RECO : complex format with 0 in imaginary part) 00146 int ixold; //16 top left X co-ordinate before CUT-IMAGE (boxing) 00147 int iyold; //17 top left Y co-ordinate before CUT-IMAGE (boxing) 00148 float avdens; //18 average density in image 00149 float sigma; //19 standard deviation of density 00150 float user1; //20 at user's own disposal 00151 float user2; //21 at user's own disposal 00152 float densmax; //22 highest density in image 00153 float densmin; //23 minimal density in image 00154 int complex; //24 label indicating that data is always complex 00155 float defocus1; //25 defocus value 1 00156 float defocus2; //26 defocus value 2 00157 float defangle; //27 defocus angle 00158 float sinostart; //28 start angle if image is a sinogram 00159 float sinoend; //29 end angle if image is a sinogram 00160 char label[80]; //30-49 coded NAME/TITLE of the image (80 characters) 00161 float ccc3d; //50 3D simularity criteria 00162 int ref3d; //51 3D membership 00163 int mident; //52 micrograph identification number 00164 int ezshift; //53 equivalent shift in Z direction 00165 int ealpha; //54 equivalent Euler angle alpha 00166 int ebeta; //55 equivalent Euler angle beta 00167 int egamma; //56 equivalent Euler angle gamma 00168 int unused1; //57 currently not used 00169 int unused2 //58 currently not used 00170 int nalisum; //59 number of image summed 00171 int pgroup; //60 point-group symmetry in international notation (622, for example) 00172 int izlp; //61 number of 2D planes in 3D data (for 1D/2D: IZLP1=1) 00173 int i4lp; //62 number of objects in file: 00174 // 1D (IXLP=1): number of 1D spectra 00175 // 2D (IZLP=1): number of 2D images 00176 // 3D (IZLP>1): number of 3D volumes 00177 int i5lp; //63 00178 int i6lp; //64 00179 float alpha; //65 Euler angle alpha (3D and Angular Reconst.) 00180 float beta; //66 Euler angle beta (3D and Angular Reconst.) 00181 float gamma; //67 Euler angle gamma (3D and Angular Reconst.) 00182 int imavers; //68 IMAGIC version, which created the file (yyyymmdd) 00183 int realtype; //69 floating point type, machine stamp 00184 // 16777216 for VAX/VMS 00185 // 33686018 for OSF,ULTRIX, LINUX, MS Windows 00186 // 67372036 for SiliconGraphics, SUN, HP, IBM 00187 char buffer[120]; //70-99 Variables that control the buffering 00188 // during read/write in IMAGIC-5 programs. 00189 // PLEASE DO NOT TOUCH ! 00190 float angle; //100 last rotation angle 00191 float voltage; //101 acceleration voltage (kv) 00192 int spaberr; //102 sperical aberration (mm) 00193 int pcoher; //103 partial coherence 00194 float ccc; //104 cross correlation peak hight 00195 float errar; //105 error in angular reconstitution, if -1.0: the file is a special file (FABOSA) 00196 float err3d; //106 error in 3D reconstruction 00197 int ref; //107 (multi-) reference number 00198 float classno; //108 class number in MSA classification 00199 float locold; //109 location number before CUT-IMAGE (boxing), or before copy in ANG-RECONST and EX-COPY 00200 float repqual; //110 representation quality, used in MSA-RUN and MSA (eigen) filtering 00201 float zshift; //111 last shift in Z direction 00202 float xshift; //112 last shift in X direction 00203 float yshift; //113 last shift in Y direction 00204 float numcls; //114 number members in the class specified in CLASSNO, if this image represents a class average (class-sum image) 00205 float ovqual; //115 overall quality of the class in CLASSNO 00206 float eangle; //116 equivalent angle 00207 float exshift; //117 equivalent shift in X direction 00208 float eyshift; //118 equivalent shift in Y direction 00209 float cmtotvar; //119 total variance in data matrix relative to center of mass (MSA calculations) 00210 float informat; //120 Gauss norm / real*FT Space information of the data set 00211 int numeigen; //121 number of eigen values in MSA 00212 int niactive; //122 number of active images in MSA calculations 00213 float resolx; //123 Angstrom per pixel/voxel in X direction, if DAT1(105) = -1.0 (FABOSA): mm per pixel 00214 float resoly; //124 Angstrom per pixel/voxel in Y direction 00215 float resolz; //125 Angstrom per pixel/voxel in Z direction 00216 float alpha2; //126 Euler angle alpha (from projection matching), Special FABOSA variables if DAT1(105) = -1.0 00217 float beta2; //127 Euler angle beta (from projection matching), Special FABOSA variables if DAT1(105) = -1.0 00218 float gamma2; //128 Euler angle gamma (from projection matching), Special FABOSA variables if DAT1(105) = -1.0 00219 float nmetric; //129 Metric used in MSA calculations 00220 float actmsa; //130 a flag indicating whether the "image" is active or not. Used during MSA calculations 00221 float coosmsa[69]; //131-199 co-ordinates of "image" along factorial axis 00222 // number 1 through 69 (maximum possible). 00223 // Used during MSA calculations. 00224 //150 eigval, eigenvalues if the "images" represent eigenimages (eigenvalue #1 into loc#1 etc.) 00225 char history[228]; //220-256 coded history of image (228 characters) 00226 }; 00227 00228 size_t get_datatype_size(DataType t); 00229 int to_em_datatype(DataType t); 00230 void make_header_host_endian(ImagicHeader & hed); 00231 void swap_header(ImagicHeader & hed); 00232 DataType get_datatype_from_name(const char *name); 00233 00235 Ctf * read_ctf(const ImagicHeader& hed) const; 00236 void write_ctf(const Ctf * const ctf, int image_index = 0); 00237 00238 private: 00239 string filename; 00240 string hed_filename; 00241 string img_filename; 00242 00243 IOMode rw_mode; 00244 FILE *hed_file; 00245 FILE *img_file; 00246 00247 Imagic4D imagich; 00248 bool is_big_endian; 00249 bool initialized; 00250 bool is_new_hed; 00251 bool is_new_img; 00252 00253 DataType datatype; 00254 }; 00255 00256 } 00257 00258 00259 #endif //eman__imagicio2_h__