Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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,
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_INVALID
00092                 };
00093 
00094                 // note there are no floats in these files. Floats are stored as ints with
00095                 // a scaling factor.
00096                 struct PifFileHeader
00097                 {
00098                         int magic[2];           // magic number; identify PIF file
00099                         char scalefactor[16];   // to convert float ints -> floats
00100                         int nimg;                       // number of images in file
00101                         int endian;                     // endianness, 0 -> vax,intel (little), 1 -> SGI, PowerPC (big)
00102                         char program[32];       // program which generated image
00103                         int htype;                      // 1 - all images same number of pixels and depth, 0 - otherwise
00104                         int nx;                         // number of columns
00105                         int ny;                         // number of rows
00106                         int nz;                         // number of sections
00107                         int mode;                       // image data type
00108                         int pad[107];
00109                 };
00110 
00111                 struct PifColorMap
00112                 {                                               // color map for depthcued images
00113                         short r[256];
00114                         short g[256];
00115                         short b[256];
00116                 };
00117 
00118                 struct PifImageHeader
00119                 {
00120                         int nx;
00121                         int ny;
00122                         int nz;                         // size of this image
00123                         int mode;                       // image data type
00124                         int bkg;                        // background value
00125                         int radius;                     // boxed image radius
00126                         int xstart;
00127                         int ystart;
00128                         int zstart;                     // starting number of each axis
00129                         int mx;
00130                         int my;
00131                         int mz;                         // intervals along x,y,z
00132                         int xlen;
00133                         int ylen;
00134                         int zlen;                       // cell dimensions (floatints)
00135                         int alpha;
00136                         int beta;
00137                         int gamma;                      // angles (floatints)
00138                         int mapc;
00139                         int mapr;
00140                         int maps;                       // axes->sections (1,2,3=x,y,z)
00141                         int min;
00142                         int max;
00143                         int mean;
00144                         int sigma;                      // statistics (floatints)
00145                         int ispg;                       // spacegroup
00146                         int nsymbt;                     // bytes for symmetry ops
00147                         int xorigin;
00148                         int yorigin;            // origin (floatint)
00149                         char title[80];
00150                         char time[32];
00151                         char imagenum[16];      // unique micrograph number
00152                         char scannum[8];        // scan number of micrograph
00153                         int aoverb;
00154                         int mapabang;
00155                         int pad[63];            // later use
00156                 };
00157           
00158                 int get_mode_size(PifDataMode mode);
00159                 bool is_float_int(int mode);
00160                 void fseek_to(int image_index);
00161                 int to_em_datatype(int pif_datatype);
00162                 int to_pif_datatype(int em_datatype);
00163 
00164             string filename;
00165                 IOMode rw_mode;
00166                 PifFileHeader pfh;
00167                 FILE *pif_file;
00168                 int mode_size;
00169                 bool is_big_endian;
00170                 bool initialized;
00171                 bool is_new_file;
00172                 float real_scale_factor;
00173         };
00174 
00175 }
00176 
00177 
00178 #endif  //eman__pifio_h__

Generated on Tue May 25 17:34:11 2010 for EMAN2 by  doxygen 1.4.4