imagicio.h

Go to the documentation of this file.
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__imagicio_h__
00037 #define eman__imagicio_h__ 1
00038 
00039 #include "imageio.h"
00040 
00041 namespace EMAN
00042 {
00069         class ImagicIO:public ImageIO
00070         {
00071           public:
00072                 static const char *HED_EXT;
00073                 static const char *IMG_EXT;
00074                 
00075                 explicit ImagicIO(string filename, IOMode rw_mode = READ_ONLY);
00076                 ~ImagicIO();
00077 
00078                 DEFINE_IMAGEIO_FUNC;
00079                 static bool is_valid(const void *first_block);
00080                 
00081                 bool is_single_image_format() const
00082                 {
00083                         return false;
00084                 }
00085                 
00086                 int get_nimg();
00087                 
00088           private:
00089                 static const char *REAL_TYPE_MAGIC;
00090                 static const char *CTF_MAGIC;
00091 
00092 
00093                 enum DataType
00094                 {
00095                         IMAGIC_UCHAR,
00096                         IMAGIC_USHORT,
00097                         IMAGIC_FLOAT,
00098                         IMAGIC_FLOAT_COMPLEX,
00099                         IMAGIC_FFT_FLOAT_COMPLEX,
00100                         IMAGIC_UNKNOWN_TYPE
00101                 };
00102 
00103                 enum
00104                 {
00105                         NUM_4BYTES_PRE_IXOLD = 14,
00106                         NUM_4BYTES_AFTER_IXOLD = 14,
00107                         NUM_4BYTES_AFTER_SPACE = 207
00108                 };
00109 
00110                 struct ImagicHeader
00111                 {
00112                         int imgnum;                     // image number, [1,n]
00113                         int count;                      // total number of images - 1 (only first image), [0,n-1]
00114                         int error;                      // Error code for this image
00115                         int headrec;            // # of header records/image (always 1)
00116                         int mday;                       // image creation time
00117                         int month;
00118                         int year;
00119                         int hour;
00120                         int minute;
00121                         int sec;
00122                         int reals;                      // image size in reals
00123                         int pixels;                     // image size in pixels
00124                         int ny;                         // # of lines / image
00125                         int nx;                         // # of pixels / line
00126                         char type[4];           // PACK, INTG, REAL, COMP, RECO
00127                         int ixold;                      // Top left X-coord. in image before windowing 
00128                         int iyold;                      // Top left Y-coord. in image before windowing 
00129                         float avdens;           // average density
00130                         float sigma;            // deviation of density
00131                         float varia;            // variance of density
00132                         float oldav;            // old average density
00133                         float max;                      // max density
00134                         float min;                      // min density
00135                         int complex;            // not used
00136                         float cellx;            // not used
00137                         float celly;            // not used
00138                         float cellz;            // not used
00139                         float cella1;           // not used
00140                         float cella2;           // not used
00141                         char label[80];         // image id string
00142                         int space[8];
00143                         float mrc1[4];
00144                         int mrc2;
00145                         int space2[7];
00146                         int lbuf;                       // effective buffer len = nx
00147                         int inn;                        // lines in buffer = 1
00148                         int iblp;                       // buffer lines/image = ny
00149                         int ifb;                        // 1st line in buf = 0
00150                         int lbr;                        // last buf line read = -1
00151                         int lbw;                        // last buf line written = 0
00152                         int lastlr;                     // last line called for read = -1
00153                         int lastlw;                     // last line called for write = 1
00154                         int ncflag;                     // decode to complex = 0
00155                         int num;                        // file number = 40 (?)
00156                         int nhalf;                      // leff/2
00157                         int ibsd;                       // record size for r/w (words) = nx*2
00158                         int ihfl;                       // file # = 8
00159                         int lcbr;                       // lin count read buf = -1
00160                         int lcbw;                       // lin count wr buf = 1
00161                         int imstr;                      // calc stat on rd = -1
00162                         int imstw;                      // calc stat on wr = -1
00163                         int istart;                     // begin line in buf = 1
00164                         int iend;                       // end line in buf = nx
00165                         int leff;                       // eff line len = nx
00166                         int linbuf;                     // line len (16 bit) nx *2
00167                         int ntotbuf;            // total buf in pgm = -1
00168                         int space3[5];
00169                         int icstart;            // complex line start = 1
00170                         int icend;                      // complex line end = nx/2
00171                         int rdonly;                     // read only = 0
00172                         int misc[157];          // Remainder of header (EMAN1 specific settings not supported)
00173                 };
00174 
00175                 size_t get_datatype_size(DataType t);
00176                 int to_em_datatype(DataType t);
00177                 void make_header_host_endian(ImagicHeader & hed);
00178                 void swap_header(ImagicHeader & hed);
00179                 DataType get_datatype_from_name(const char *name);
00180 
00182                 Ctf * read_ctf(const ImagicHeader& hed) const;
00183                 void write_ctf(const Ctf * const ctf, int image_index = 0);
00184                 
00185           private:
00186                 string filename;
00187                 string hed_filename;
00188                 string img_filename;
00189 
00190                 IOMode rw_mode;
00191                 FILE *hed_file;
00192                 FILE *img_file;
00193 
00194                 ImagicHeader imagich;
00195                 bool is_big_endian;
00196                 bool initialized;
00197                 bool is_new_hed;
00198                 bool is_new_img;
00199 
00200                 DataType datatype;
00201                 int nz;
00202         };
00203 
00204 }
00205 
00206 
00207 #endif  //eman__imagicio_h__

Generated on Tue Jun 11 12:40:22 2013 for EMAN2 by  doxygen 1.4.7