EMAN::PifIO Class Reference

PIF(Portable Image Format for EM Data) is an image format from Purdue University. More...

#include <pifio.h>

Inheritance diagram for EMAN::PifIO:

Inheritance graph
[legend]
Collaboration diagram for EMAN::PifIO:

Collaboration graph
[legend]

List of all members.

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

static 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

Classes

struct  PifColorMap
struct  PifFileHeader
struct  PifImageHeader


Detailed Description

PIF(Portable Image Format for EM Data) is an image format from Purdue University.

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.


Member Enumeration Documentation

anonymous enum [private]

Enumerator:
PIF_MAGIC_NUM 

Definition at line 72 of file pifio.h.

00073                 {
00074                         PIF_MAGIC_NUM = 8
00075                 };

enum EMAN::PifIO::PifDataMode [private]

Enumerator:
PIF_CHAR 
PIF_SHORT 
PIF_FLOAT_INT 
PIF_SHORT_COMPLEX 
PIF_FLOAT_INT_COMPLEX 
PIF_BOXED_DATA 
PIF_SHORT_FLOAT 
PIF_SHORT_FLOAT_COMPLEX 
PIF_FLOAT 
PIF_FLOAT_COMPLEX 
PIF_MAP_FLOAT_SHORT 
PIF_MAP_FLOAT_INT 
PIF_INVALID 

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,
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                 };


Constructor & Destructor Documentation

EMAN::PifIO::PifIO ( const string &  filename,
IOMode  rw_mode = READ_ONLY 
) [explicit]

PifIO::~PifIO (  ) 

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 }


Member Function Documentation

bool PifIO::is_valid ( const void *  first_block  )  [static]

Definition at line 165 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().

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 }

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.

00066                 {
00067                         return false;
00068                 }

int PifIO::get_nimg (  )  [virtual]

Return the number of images in this image file.

Reimplemented from EMAN::ImageIO.

Definition at line 537 of file pifio.cpp.

References EMAN::ImageIO::init(), EMAN::PifIO::PifFileHeader::nimg, and pfh.

00538 {
00539         init();
00540         return pfh.nimg;
00541 }

int PifIO::get_mode_size ( PifDataMode  mode  )  [private]

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 }

bool PifIO::is_float_int ( int  mode  )  [private]

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, and PIF_SHORT_FLOAT_COMPLEX.

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 }

void PifIO::fseek_to ( int  image_index  )  [private]

Definition at line 194 of file pifio.cpp.

References mode_size, 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 }

int PifIO::to_em_datatype ( int  pif_datatype  )  [private]

Definition at line 544 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_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, and PIF_SHORT_FLOAT_COMPLEX.

00545 {
00546         PifDataMode mode = static_cast < PifDataMode > (p);
00547         EMUtil::EMDataType e = EMUtil::EM_UNKNOWN;
00548 
00549         switch (mode) {
00550         case PIF_CHAR:
00551         case PIF_BOXED_DATA:
00552                 e = EMUtil::EM_CHAR;
00553                 break;
00554 
00555         case PIF_SHORT:
00556         case PIF_SHORT_FLOAT:
00557         case PIF_MAP_FLOAT_SHORT:
00558                 e = EMUtil::EM_SHORT;
00559                 break;
00560 
00561         case PIF_SHORT_COMPLEX:
00562         case PIF_SHORT_FLOAT_COMPLEX:
00563                 e = EMUtil::EM_SHORT_COMPLEX;
00564                 break;
00565 
00566         case PIF_FLOAT:
00567         case PIF_FLOAT_INT:
00568         case PIF_MAP_FLOAT_INT:
00569                 e = EMUtil::EM_FLOAT;
00570                 break;
00571         case PIF_FLOAT_COMPLEX:
00572         case PIF_FLOAT_INT_COMPLEX:
00573                 e = EMUtil::EM_FLOAT_COMPLEX;
00574                 break;
00575         case PIF_INVALID:
00576                 e = EMUtil::EM_UNKNOWN;
00577                 break;
00578         }
00579         return e;
00580 }

int PifIO::to_pif_datatype ( int  em_datatype  )  [private]

Definition at line 582 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.

00583 {
00584         PifDataMode m = PIF_INVALID;
00585 
00586         switch (e) {
00587         case EMUtil::EM_CHAR:
00588                 m = PIF_BOXED_DATA;
00589                 break;
00590         case EMUtil::EM_SHORT:
00591                 m = PIF_SHORT;
00592                 break;
00593         case EMUtil::EM_SHORT_COMPLEX:
00594                 m = PIF_SHORT_COMPLEX;
00595                 break;
00596         case EMUtil::EM_FLOAT:
00597                 m = PIF_FLOAT_INT;
00598                 break;
00599         case EMUtil::EM_FLOAT_COMPLEX:
00600                 m = PIF_FLOAT_COMPLEX;
00601                 break;
00602         default:
00603                 LOGERR("unknown PIF mode: %d", e);
00604         }
00605 
00606         return m;
00607 }


Member Data Documentation

Definition at line 62 of file pifio.h.

string EMAN::PifIO::filename [private]

Definition at line 164 of file pifio.h.

Definition at line 165 of file pifio.h.

Definition at line 166 of file pifio.h.

Referenced by fseek_to(), and get_nimg().

FILE* EMAN::PifIO::pif_file [private]

Definition at line 167 of file pifio.h.

Referenced by fseek_to(), and ~PifIO().

int EMAN::PifIO::mode_size [private]

Definition at line 168 of file pifio.h.

Referenced by fseek_to().

Definition at line 169 of file pifio.h.

bool EMAN::PifIO::initialized [private]

Definition at line 170 of file pifio.h.

bool EMAN::PifIO::is_new_file [private]

Definition at line 171 of file pifio.h.

Definition at line 172 of file pifio.h.


The documentation for this class was generated from the following files:

Generated on Sat Nov 21 02:20:22 2009 for EMAN2 by  doxygen 1.5.6