#include <pifio.h>
Inheritance diagram for EMAN::PifIO:
A PIF file = file header + (image header + image data) + (image header + image data) ...
A PIF file has a overall file header followed by n images. Each image has a header and data block.
EMAN only supports homogeneous PIF file, which means all images n a PIF should have the same dimensions. We also assume the (nx,ny,nz) in PifFileHeader are equal to (nx,ny,nz) in each Image header.
Definition at line 56 of file pifio.h.
anonymous enum [private] |
enum EMAN::PifIO::PifDataMode [private] |
Definition at line 77 of file pifio.h.
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 };
PifIO::PifIO | ( | const string & | filename, | |
IOMode | rw_mode = READ_ONLY | |||
) | [explicit] |
Definition at line 48 of file pifio.cpp.
References initialized, is_big_endian, EMAN::ByteOrder::is_host_big_endian(), is_new_file, mode_size, pfh, pif_file, and real_scale_factor.
00049 : filename(pif_filename), rw_mode(rw) 00050 { 00051 pif_file = 0; 00052 mode_size = 0; 00053 is_big_endian = ByteOrder::is_host_big_endian(); 00054 initialized = false; 00055 real_scale_factor = 1; 00056 is_new_file = false; 00057 memset(&pfh, 0, sizeof(PifFileHeader)); 00058 }
PifIO::~PifIO | ( | ) |
void PifIO::fseek_to | ( | int | image_index | ) | [private] |
Definition at line 198 of file pifio.cpp.
References mode_size, pif_file, and portable_fseek().
00199 { 00200 int pih_sz = sizeof(PifImageHeader); 00201 int image_size = 0; 00202 00203 #if 0 00204 // this works for some images that PURDUE people gave to me. 00205 // But those images don't follow the PIF specification. So 00206 // I believe they are in wrong format. 00207 if (pfh.nimg == 1) { 00208 image_size = pfh.nx * pfh.ny * pfh.nz; 00209 } 00210 else { 00211 image_size = pfh.nx * pfh.ny; 00212 } 00213 #endif 00214 image_size = pfh.nx * pfh.ny * pfh.nz; 00215 00216 size_t file_offset = sizeof(PifFileHeader) + 00217 (pih_sz + image_size * mode_size) * image_index; 00218 00219 portable_fseek(pif_file, file_offset, SEEK_SET); 00220 }
int PifIO::get_mode_size | ( | PifDataMode | mode | ) | [private] |
Definition at line 69 of file pifio.cpp.
References PIF_BOXED_DATA, PIF_BOXED_FLOAT_INT, PIF_CHAR, PIF_FLOAT, PIF_FLOAT_COMPLEX, PIF_FLOAT_INT, PIF_FLOAT_INT_COMPLEX, PIF_MAP_FLOAT_INT, PIF_MAP_FLOAT_INT_2, PIF_MAP_FLOAT_SHORT, PIF_SHORT, PIF_SHORT_COMPLEX, PIF_SHORT_FLOAT, and PIF_SHORT_FLOAT_COMPLEX.
00070 { 00071 int size = 0; 00072 00073 switch (mode) { 00074 case PIF_CHAR: 00075 case PIF_BOXED_DATA: 00076 size = sizeof(char); 00077 break; 00078 case PIF_SHORT: 00079 case PIF_SHORT_FLOAT: 00080 case PIF_SHORT_COMPLEX: 00081 case PIF_SHORT_FLOAT_COMPLEX: 00082 case PIF_MAP_FLOAT_SHORT: 00083 size = sizeof(short); 00084 break; 00085 case PIF_FLOAT: 00086 case PIF_FLOAT_COMPLEX: 00087 size = sizeof(float); 00088 break; 00089 case PIF_FLOAT_INT: 00090 case PIF_FLOAT_INT_COMPLEX: 00091 case PIF_MAP_FLOAT_INT: 00092 case PIF_MAP_FLOAT_INT_2: 00093 case PIF_BOXED_FLOAT_INT: 00094 size = sizeof(int); 00095 break; 00096 default: 00097 break; 00098 } 00099 return size; 00100 }
int PifIO::get_nimg | ( | ) | [virtual] |
Return the number of images in this image file.
Reimplemented from EMAN::ImageIO.
Definition at line 545 of file pifio.cpp.
References EMAN::ImageIO::init().
bool PifIO::is_float_int | ( | int | mode | ) | [private] |
Definition at line 102 of file pifio.cpp.
References PIF_BOXED_FLOAT_INT, PIF_FLOAT_INT, PIF_FLOAT_INT_COMPLEX, PIF_MAP_FLOAT_INT, PIF_MAP_FLOAT_INT_2, PIF_MAP_FLOAT_SHORT, PIF_SHORT_FLOAT, and PIF_SHORT_FLOAT_COMPLEX.
00103 { 00104 PifDataMode mode = static_cast < PifDataMode > (m); 00105 switch (mode) { 00106 case PIF_SHORT_FLOAT: 00107 case PIF_SHORT_FLOAT_COMPLEX: 00108 //case PIF_FLOAT: 00109 case PIF_FLOAT_INT: 00110 //case PIF_FLOAT_COMPLEX: 00111 case PIF_FLOAT_INT_COMPLEX: 00112 case PIF_MAP_FLOAT_SHORT: 00113 case PIF_MAP_FLOAT_INT: 00114 case PIF_MAP_FLOAT_INT_2: 00115 case PIF_BOXED_FLOAT_INT: 00116 return true; 00117 default: 00118 break; 00119 } 00120 return false; 00121 }
bool EMAN::PifIO::is_single_image_format | ( | ) | const [inline, virtual] |
Is this image format only storing 1 image or not.
Some image formats like MRC only store 1 image in a file, so this function returns 'true' for them. Other image formats like IMAGIC/HDF5 may store mutliple images, so this function returns 'false' for them.
Reimplemented from EMAN::ImageIO.
Definition at line 65 of file pifio.h.
bool PifIO::is_valid | ( | const void * | first_block | ) | [static] |
Definition at line 169 of file pifio.cpp.
References data, ENTERFUNC, EXITFUNC, EMAN::ByteOrder::is_host_big_endian(), PIF_MAGIC_NUM, and EMAN::ByteOrder::swap_bytes().
Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type().
00170 { 00171 ENTERFUNC; 00172 bool result = false; 00173 00174 if (first_block) { 00175 const int *data = static_cast < const int *>(first_block); 00176 int m1 = data[0]; 00177 int m2 = data[1]; 00178 int endian = data[7]; 00179 bool data_big_endian = false; 00180 if (endian) { 00181 data_big_endian = true; 00182 } 00183 00184 if (data_big_endian != ByteOrder::is_host_big_endian()) { 00185 ByteOrder::swap_bytes(&m1); 00186 ByteOrder::swap_bytes(&m2); 00187 } 00188 00189 if (m1 == PIF_MAGIC_NUM && m2 == PIF_MAGIC_NUM) { 00190 result = true; 00191 } 00192 } 00193 00194 EXITFUNC; 00195 return result; 00196 }
int PifIO::to_em_datatype | ( | int | pif_datatype | ) | [private] |
Definition at line 552 of file pifio.cpp.
References EMAN::EMUtil::EM_CHAR, EMAN::EMUtil::EM_FLOAT, EMAN::EMUtil::EM_FLOAT_COMPLEX, EMAN::EMUtil::EM_SHORT, EMAN::EMUtil::EM_SHORT_COMPLEX, EMAN::EMUtil::EM_UNKNOWN, PIF_BOXED_DATA, PIF_BOXED_FLOAT_INT, PIF_CHAR, PIF_FLOAT, PIF_FLOAT_COMPLEX, PIF_FLOAT_INT, PIF_FLOAT_INT_COMPLEX, PIF_INVALID, PIF_MAP_FLOAT_INT, PIF_MAP_FLOAT_INT_2, PIF_MAP_FLOAT_SHORT, PIF_SHORT, PIF_SHORT_COMPLEX, PIF_SHORT_FLOAT, and PIF_SHORT_FLOAT_COMPLEX.
00553 { 00554 PifDataMode mode = static_cast < PifDataMode > (p); 00555 EMUtil::EMDataType e = EMUtil::EM_UNKNOWN; 00556 00557 switch (mode) { 00558 case PIF_CHAR: 00559 case PIF_BOXED_DATA: 00560 e = EMUtil::EM_CHAR; 00561 break; 00562 00563 case PIF_SHORT: 00564 case PIF_SHORT_FLOAT: 00565 case PIF_MAP_FLOAT_SHORT: 00566 e = EMUtil::EM_SHORT; 00567 break; 00568 00569 case PIF_SHORT_COMPLEX: 00570 case PIF_SHORT_FLOAT_COMPLEX: 00571 e = EMUtil::EM_SHORT_COMPLEX; 00572 break; 00573 00574 case PIF_FLOAT: 00575 case PIF_FLOAT_INT: 00576 case PIF_MAP_FLOAT_INT: 00577 case PIF_MAP_FLOAT_INT_2: 00578 case PIF_BOXED_FLOAT_INT: 00579 e = EMUtil::EM_FLOAT; 00580 break; 00581 case PIF_FLOAT_COMPLEX: 00582 case PIF_FLOAT_INT_COMPLEX: 00583 e = EMUtil::EM_FLOAT_COMPLEX; 00584 break; 00585 case PIF_INVALID: 00586 e = EMUtil::EM_UNKNOWN; 00587 break; 00588 } 00589 return e; 00590 }
int PifIO::to_pif_datatype | ( | int | em_datatype | ) | [private] |
Definition at line 592 of file pifio.cpp.
References EMAN::EMUtil::EM_CHAR, EMAN::EMUtil::EM_FLOAT, EMAN::EMUtil::EM_FLOAT_COMPLEX, EMAN::EMUtil::EM_SHORT, EMAN::EMUtil::EM_SHORT_COMPLEX, LOGERR, PIF_BOXED_DATA, PIF_FLOAT_COMPLEX, PIF_FLOAT_INT, PIF_INVALID, PIF_SHORT, and PIF_SHORT_COMPLEX.
00593 { 00594 PifDataMode m = PIF_INVALID; 00595 00596 switch (e) { 00597 case EMUtil::EM_CHAR: 00598 m = PIF_BOXED_DATA; 00599 break; 00600 case EMUtil::EM_SHORT: 00601 m = PIF_SHORT; 00602 break; 00603 case EMUtil::EM_SHORT_COMPLEX: 00604 m = PIF_SHORT_COMPLEX; 00605 break; 00606 case EMUtil::EM_FLOAT: 00607 m = PIF_FLOAT_INT; 00608 break; 00609 case EMUtil::EM_FLOAT_COMPLEX: 00610 m = PIF_FLOAT_COMPLEX; 00611 break; 00612 default: 00613 LOGERR("unknown PIF mode: %d", e); 00614 } 00615 00616 return m; 00617 }
string EMAN::PifIO::filename [private] |
bool EMAN::PifIO::initialized [private] |
bool EMAN::PifIO::is_big_endian [private] |
bool EMAN::PifIO::is_new_file [private] |
int EMAN::PifIO::mode_size [private] |
PifFileHeader EMAN::PifIO::pfh [private] |
FILE* EMAN::PifIO::pif_file [private] |
float EMAN::PifIO::real_scale_factor [private] |
IOMode EMAN::PifIO::rw_mode [private] |