#include <pifio.h>
Inheritance diagram for EMAN::PifIO:


Public Member Functions | |
| PifIO (const string &filename, IOMode rw_mode=READ_ONLY) | |
| ~PifIO () | |
| bool | is_single_image_format () const |
| Is this image format only storing 1 image or not. | |
| int | get_nimg () |
| Return the number of images in this image file. | |
Static Public Member Functions | |
| bool | is_valid (const void *first_block) |
Public Attributes | |
| DEFINE_IMAGEIO_FUNC | |
Private Types | |
| enum | { PIF_MAGIC_NUM = 8 } |
| enum | PifDataMode { PIF_CHAR = 0, PIF_SHORT = 1, PIF_FLOAT_INT = 2, PIF_SHORT_COMPLEX = 3, PIF_FLOAT_INT_COMPLEX = 4, PIF_BOXED_DATA = 6, PIF_SHORT_FLOAT = 7, PIF_SHORT_FLOAT_COMPLEX = 8, PIF_FLOAT = 9, PIF_FLOAT_COMPLEX = 10, PIF_MAP_FLOAT_SHORT = 20, PIF_MAP_FLOAT_INT = 21, PIF_INVALID } |
Private Member Functions | |
| int | get_mode_size (PifDataMode mode) |
| bool | is_float_int (int mode) |
| void | fseek_to (int image_index) |
| int | to_em_datatype (int pif_datatype) |
| int | to_pif_datatype (int em_datatype) |
Private Attributes | |
| string | filename |
| IOMode | rw_mode |
| PifFileHeader | pfh |
| FILE * | pif_file |
| int | mode_size |
| bool | is_big_endian |
| bool | initialized |
| bool | is_new_file |
| float | real_scale_factor |
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.
|
|
Definition at line 72 of file pifio.h. 00073 {
00074 PIF_MAGIC_NUM = 8
00075 };
|
|
|
Definition at line 77 of file pifio.h. Referenced by is_float_int(), to_em_datatype(), and to_pif_datatype(). 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 };
|
|
||||||||||||
|
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 }
|
|
|
Definition at line 60 of file pifio.cpp. References pif_file. 00061 {
00062 if (pif_file) {
00063 fclose(pif_file);
00064 pif_file = 0;
00065 }
00066 }
|
|
|
Definition at line 194 of file pifio.cpp. References EMAN::PifIO::PifFileHeader::nimg, EMAN::PifIO::PifFileHeader::nx, EMAN::PifIO::PifFileHeader::ny, EMAN::PifIO::PifFileHeader::nz, pfh, pif_file, and portable_fseek(). 00195 {
00196 int pih_sz = sizeof(PifImageHeader);
00197 int image_size = 0;
00198
00199 #if 0
00200 // this works for some images that PURDUE people gave to me.
00201 // But those images don't follow the PIF specification. So
00202 // I believe they are in wrong format.
00203 if (pfh.nimg == 1) {
00204 image_size = pfh.nx * pfh.ny * pfh.nz;
00205 }
00206 else {
00207 image_size = pfh.nx * pfh.ny;
00208 }
00209 #endif
00210 image_size = pfh.nx * pfh.ny * pfh.nz;
00211
00212 size_t file_offset = sizeof(PifFileHeader) +
00213 (pih_sz + image_size * mode_size) * image_index;
00214
00215 portable_fseek(pif_file, file_offset, SEEK_SET);
00216 }
|
|
|
Definition at line 69 of file pifio.cpp. References PIF_BOXED_DATA, PIF_CHAR, PIF_FLOAT, PIF_FLOAT_COMPLEX, PIF_FLOAT_INT, PIF_FLOAT_INT_COMPLEX, PIF_MAP_FLOAT_INT, 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 size = sizeof(int);
00093 break;
00094 default:
00095 break;
00096 }
00097 return size;
00098 }
|
|
|
Return the number of images in this image file.
Reimplemented from EMAN::ImageIO. Definition at line 541 of file pifio.cpp. References EMAN::ImageIO::init(), EMAN::PifIO::PifFileHeader::nimg, and pfh.
|
|
|
Definition at line 100 of file pifio.cpp. References PIF_FLOAT_INT, PIF_FLOAT_INT_COMPLEX, PIF_MAP_FLOAT_INT, PIF_MAP_FLOAT_SHORT, PIF_SHORT_FLOAT, PIF_SHORT_FLOAT_COMPLEX, and PifDataMode. 00101 {
00102 PifDataMode mode = static_cast < PifDataMode > (m);
00103 switch (mode) {
00104 case PIF_SHORT_FLOAT:
00105 case PIF_SHORT_FLOAT_COMPLEX:
00106 //case PIF_FLOAT:
00107 case PIF_FLOAT_INT:
00108 //case PIF_FLOAT_COMPLEX:
00109 case PIF_FLOAT_INT_COMPLEX:
00110 case PIF_MAP_FLOAT_SHORT:
00111 case PIF_MAP_FLOAT_INT:
00112 return true;
00113 default:
00114 break;
00115 }
00116 return false;
00117 }
|
|
|
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. 00066 {
00067 return false;
00068 }
|
|
|
Definition at line 165 of file pifio.cpp. References data, 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(). 00166 {
00167 ENTERFUNC;
00168 bool result = false;
00169
00170 if (first_block) {
00171 const int *data = static_cast < const int *>(first_block);
00172 int m1 = data[0];
00173 int m2 = data[1];
00174 int endian = data[7];
00175 bool data_big_endian = false;
00176 if (endian) {
00177 data_big_endian = true;
00178 }
00179
00180 if (data_big_endian != ByteOrder::is_host_big_endian()) {
00181 ByteOrder::swap_bytes(&m1);
00182 ByteOrder::swap_bytes(&m2);
00183 }
00184
00185 if (m1 == PIF_MAGIC_NUM && m2 == PIF_MAGIC_NUM) {
00186 result = true;
00187 }
00188 }
00189
00190 EXITFUNC;
00191 return result;
00192 }
|
|
|
Definition at line 548 of file pifio.cpp. References PIF_BOXED_DATA, PIF_CHAR, PIF_FLOAT, PIF_FLOAT_COMPLEX, PIF_FLOAT_INT, PIF_FLOAT_INT_COMPLEX, PIF_INVALID, PIF_MAP_FLOAT_INT, PIF_MAP_FLOAT_SHORT, PIF_SHORT, PIF_SHORT_COMPLEX, PIF_SHORT_FLOAT, PIF_SHORT_FLOAT_COMPLEX, and PifDataMode. 00549 {
00550 PifDataMode mode = static_cast < PifDataMode > (p);
00551 EMUtil::EMDataType e = EMUtil::EM_UNKNOWN;
00552
00553 switch (mode) {
00554 case PIF_CHAR:
00555 case PIF_BOXED_DATA:
00556 e = EMUtil::EM_CHAR;
00557 break;
00558
00559 case PIF_SHORT:
00560 case PIF_SHORT_FLOAT:
00561 case PIF_MAP_FLOAT_SHORT:
00562 e = EMUtil::EM_SHORT;
00563 break;
00564
00565 case PIF_SHORT_COMPLEX:
00566 case PIF_SHORT_FLOAT_COMPLEX:
00567 e = EMUtil::EM_SHORT_COMPLEX;
00568 break;
00569
00570 case PIF_FLOAT:
00571 case PIF_FLOAT_INT:
00572 case PIF_MAP_FLOAT_INT:
00573 e = EMUtil::EM_FLOAT;
00574 break;
00575 case PIF_FLOAT_COMPLEX:
00576 case PIF_FLOAT_INT_COMPLEX:
00577 e = EMUtil::EM_FLOAT_COMPLEX;
00578 break;
00579 case PIF_INVALID:
00580 e = EMUtil::EM_UNKNOWN;
00581 break;
00582 }
00583 return e;
00584 }
|
|
|
Definition at line 586 of file pifio.cpp. References LOGERR, and PifDataMode. 00587 {
00588 PifDataMode m = PIF_INVALID;
00589
00590 switch (e) {
00591 case EMUtil::EM_CHAR:
00592 m = PIF_BOXED_DATA;
00593 break;
00594 case EMUtil::EM_SHORT:
00595 m = PIF_SHORT;
00596 break;
00597 case EMUtil::EM_SHORT_COMPLEX:
00598 m = PIF_SHORT_COMPLEX;
00599 break;
00600 case EMUtil::EM_FLOAT:
00601 m = PIF_FLOAT_INT;
00602 break;
00603 case EMUtil::EM_FLOAT_COMPLEX:
00604 m = PIF_FLOAT_COMPLEX;
00605 break;
00606 default:
00607 LOGERR("unknown PIF mode: %d", e);
00608 }
00609
00610 return m;
00611 }
|
|
|
|
|
|
|
|
|
Definition at line 170 of file pifio.h. Referenced by PifIO(). |
|
|
Definition at line 169 of file pifio.h. Referenced by PifIO(). |
|
|
Definition at line 171 of file pifio.h. Referenced by PifIO(). |
|
|
Definition at line 168 of file pifio.h. Referenced by PifIO(). |
|
|
Definition at line 166 of file pifio.h. Referenced by fseek_to(), get_nimg(), and PifIO(). |
|
|
Definition at line 167 of file pifio.h. Referenced by fseek_to(), PifIO(), and ~PifIO(). |
|
|
Definition at line 172 of file pifio.h. Referenced by PifIO(). |
|
|
|
1.3.9.1