EMAN2
pifio.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__pifio_h__
00037 #define eman__pifio_h__ 1
00038 
00039 #include "imageio.h"
00040 
00041 namespace EMAN
00042 {
00056         class PifIO:public ImageIO
00057         {
00058           public:
00059                 explicit PifIO(const string & filename, IOMode rw_mode = READ_ONLY);
00060                 ~PifIO();
00061 
00062                 DEFINE_IMAGEIO_FUNC;
00063                 static bool is_valid(const void *first_block);
00064 
00065                 bool is_single_image_format() const
00066                 {
00067                         return false;
00068                 }
00069                 int get_nimg();
00070                 
00071           private:
00072                 enum
00073                 {
00074                         PIF_MAGIC_NUM = 8
00075                 };
00076 
00077                 enum PifDataMode
00078                 {
00079                         PIF_CHAR = 0,
00080                         PIF_SHORT = 1,
00081                         PIF_FLOAT_INT = 2,
00082                         PIF_SHORT_COMPLEX = 3,
00083                         PIF_FLOAT_INT_COMPLEX = 4,
00084                         PIF_BOXED_DATA = 6,                     // byte, read as 0
00085                         PIF_SHORT_FLOAT = 7,
00086                         PIF_SHORT_FLOAT_COMPLEX = 8,
00087                         PIF_FLOAT = 9,
00088                         PIF_FLOAT_COMPLEX = 10,
00089                         PIF_MAP_FLOAT_SHORT = 20,
00090                         PIF_MAP_FLOAT_INT = 21,
00091                         PIF_MAP_FLOAT_INT_2 = 40,                       // 4 byte floatint, read as 2
00092                         PIF_BOXED_FLOAT_INT = 46,               // 4 byte floatint, read as 2
00093                         PIF_INVALID
00094                 };
00095 
00096                 // note there are no floats in these files. Floats are stored as ints with
00097                 // a scaling factor.
00098                 struct PifFileHeader
00099                 {
00100                         int magic[2];           // magic number; identify PIF file
00101                         char scalefactor[16];   // to convert float ints -> floats
00102                         int nimg;                       // number of images in file
00103                         int endian;                     // endianness, 0 -> vax,intel (little), 1 -> SGI, PowerPC (big)
00104                         char program[32];       // program which generated image
00105                         int htype;                      // 1 - all images same number of pixels and depth, 0 - otherwise
00106                         int nx;                         // number of columns
00107                         int ny;                         // number of rows
00108                         int nz;                         // number of sections
00109                         int mode;                       // image data type
00110 
00111                         int even;
00112                         int mrcX;                       // MRC X dim
00113                         int mrcY;                       // MRC Y dim
00114                         int mrcZ;                       // MRC Z dim
00115                         char scale_fac[16];
00116                         char ctf_a0[13];
00117                         char ctf_a1[13];
00118                         char ctf_a2[13];
00119                         char ctf_a3[13];
00120                         char ctf_a4[13];
00121                         char ctf_a5[13];
00122                         char pad[318];
00123                 };
00124 
00125                 struct PifColorMap
00126                 {                                               // color map for depthcued images
00127                         short r[256];
00128                         short g[256];
00129                         short b[256];
00130                 };
00131 
00132                 struct PifImageHeader
00133                 {
00134                         int nx;
00135                         int ny;
00136                         int nz;                         // size of this image
00137                         int mode;                       // image data type
00138                         int bkg;                        // background value
00139                         int radius;                     // boxed image radius
00140                         int xstart;
00141                         int ystart;
00142                         int zstart;                     // starting number of each axis
00143                         int mx;
00144                         int my;
00145                         int mz;                         // intervals along x,y,z
00146                         int xlen;
00147                         int ylen;
00148                         int zlen;                       // cell dimensions (floatints)
00149                         int alpha;
00150                         int beta;
00151                         int gamma;                      // angles (floatints)
00152                         int mapc;
00153                         int mapr;
00154                         int maps;                       // axes->sections (1,2,3=x,y,z)
00155                         int min;
00156                         int max;
00157                         int mean;
00158                         int sigma;                      // statistics (floatints)
00159                         int ispg;                       // spacegroup
00160                         int nsymbt;                     // bytes for symmetry ops
00161                         int xorigin;
00162                         int yorigin;            // origin (floatint)
00163                         char title[80];
00164                         char time[32];
00165                         char imagenum[16];      // unique micrograph number
00166                         char scannum[8];        // scan number of micrograph
00167                         int aoverb;
00168                         int mapabang;
00169                         int pad[63];            // later use
00170                 };
00171           
00172                 int get_mode_size(PifDataMode mode);
00173                 bool is_float_int(int mode);
00174                 void fseek_to(int image_index);
00175                 int to_em_datatype(int pif_datatype);
00176                 int to_pif_datatype(int em_datatype);
00177 
00178             string filename;
00179                 IOMode rw_mode;
00180                 PifFileHeader pfh;
00181                 FILE *pif_file;
00182                 int mode_size;
00183                 bool is_big_endian;
00184                 bool initialized;
00185                 bool is_new_file;
00186                 float real_scale_factor;
00187         };
00188 
00189 }
00190 
00191 
00192 #endif  //eman__pifio_h__