EMAN2
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes
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.

Classes

struct  PifColorMap
struct  PifFileHeader
struct  PifImageHeader

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_MAP_FLOAT_INT_2 = 40, PIF_BOXED_FLOAT_INT = 46, 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

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.

                {
                        PIF_MAGIC_NUM = 8
                };
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_MAP_FLOAT_INT_2 
PIF_BOXED_FLOAT_INT 
PIF_INVALID 

Definition at line 77 of file pifio.h.

                {
                        PIF_CHAR = 0,
                        PIF_SHORT = 1,
                        PIF_FLOAT_INT = 2,
                        PIF_SHORT_COMPLEX = 3,
                        PIF_FLOAT_INT_COMPLEX = 4,
                        PIF_BOXED_DATA = 6,                     // byte, read as 0
                        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_MAP_FLOAT_INT_2 = 40,                       // 4 byte floatint, read as 2
                        PIF_BOXED_FLOAT_INT = 46,               // 4 byte floatint, read as 2
                        PIF_INVALID
                };

Constructor & Destructor Documentation

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.

:       filename(pif_filename), rw_mode(rw)
{
        pif_file = 0;
        mode_size = 0;
        is_big_endian = ByteOrder::is_host_big_endian();
        initialized = false;
        real_scale_factor = 1;
        is_new_file = false;
        memset(&pfh, 0, sizeof(PifFileHeader));
}
PifIO::~PifIO ( )

Definition at line 60 of file pifio.cpp.

References pif_file.

{
        if (pif_file) {
                fclose(pif_file);
                pif_file = 0;
        }
}

Member Function Documentation

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

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

{
        int pih_sz = sizeof(PifImageHeader);
        int image_size = 0;

#if 0
        // this works for some images that PURDUE people gave to me.
        // But those images don't follow the PIF specification. So
        // I believe they are in wrong format.
        if (pfh.nimg == 1) {
                image_size = pfh.nx * pfh.ny * pfh.nz;
        }
        else {
                image_size = pfh.nx * pfh.ny;
        }
#endif
        image_size = pfh.nx * pfh.ny * pfh.nz;

        size_t file_offset = sizeof(PifFileHeader) +
                (pih_sz + image_size * mode_size) * image_index;

        portable_fseek(pif_file, file_offset, SEEK_SET);
}
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.

{
        int size = 0;

        switch (mode) {
        case PIF_CHAR:
        case PIF_BOXED_DATA:
                size = sizeof(char);
                break;
        case PIF_SHORT:
        case PIF_SHORT_FLOAT:
        case PIF_SHORT_COMPLEX:
        case PIF_SHORT_FLOAT_COMPLEX:
        case PIF_MAP_FLOAT_SHORT:
                size = sizeof(short);
                break;
        case PIF_FLOAT:
        case PIF_FLOAT_COMPLEX:
                size = sizeof(float);
                break;
        case PIF_FLOAT_INT:
        case PIF_FLOAT_INT_COMPLEX:
        case PIF_MAP_FLOAT_INT:
        case PIF_MAP_FLOAT_INT_2:
        case PIF_BOXED_FLOAT_INT:
                size = sizeof(int);
                break;
        default:
                break;
        }
        return size;
}
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(), EMAN::PifIO::PifFileHeader::nimg, and pfh.

{
        init();
        return pfh.nimg;
}
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.

{
        PifDataMode mode = static_cast < PifDataMode > (m);
        switch (mode) {
        case PIF_SHORT_FLOAT:
        case PIF_SHORT_FLOAT_COMPLEX:
        //case PIF_FLOAT:
        case PIF_FLOAT_INT:
        //case PIF_FLOAT_COMPLEX:
        case PIF_FLOAT_INT_COMPLEX:
        case PIF_MAP_FLOAT_SHORT:
        case PIF_MAP_FLOAT_INT:
        case PIF_MAP_FLOAT_INT_2:
        case PIF_BOXED_FLOAT_INT:
                return true;
        default:
                break;
        }
        return false;
}
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.

                {
                        return false;
                }
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().

{
        ENTERFUNC;
        bool result = false;

        if (first_block) {
                const int *data = static_cast < const int *>(first_block);
                int m1 = data[0];
                int m2 = data[1];
                int endian = data[7];
                bool data_big_endian = false;
                if (endian) {
                        data_big_endian = true;
                }

                if (data_big_endian != ByteOrder::is_host_big_endian()) {
                        ByteOrder::swap_bytes(&m1);
                        ByteOrder::swap_bytes(&m2);
                }

                if (m1 == PIF_MAGIC_NUM && m2 == PIF_MAGIC_NUM) {
                         result = true;
                }
        }

        EXITFUNC;
        return result;
}
int PifIO::to_em_datatype ( int  pif_datatype) [private]
int PifIO::to_pif_datatype ( int  em_datatype) [private]

Member Data Documentation

Definition at line 62 of file pifio.h.

string EMAN::PifIO::filename [private]

Definition at line 178 of file pifio.h.

bool EMAN::PifIO::initialized [private]

Definition at line 184 of file pifio.h.

Referenced by PifIO().

Definition at line 183 of file pifio.h.

Referenced by PifIO().

bool EMAN::PifIO::is_new_file [private]

Definition at line 185 of file pifio.h.

Referenced by PifIO().

int EMAN::PifIO::mode_size [private]

Definition at line 182 of file pifio.h.

Referenced by fseek_to(), and PifIO().

Definition at line 180 of file pifio.h.

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

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

Definition at line 181 of file pifio.h.

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

Definition at line 186 of file pifio.h.

Referenced by PifIO().

Definition at line 179 of file pifio.h.


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