EMAN2
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Attributes
EMAN::EmIO Class Reference

EmIO defines I/O operations on EM image format. More...

#include <emio.h>

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

List of all members.

Classes

struct  EMHeader

Public Member Functions

 EmIO (const string &filename, IOMode rw_mode=READ_ONLY)
 ~EmIO ()

Static Public Member Functions

static bool is_valid (const void *first_block, off_t file_size=0)
static size_t get_mode_size (char data_type)
static int get_machine_type ()
static int to_em_datatype (char t)

Public Attributes

 DEFINE_IMAGEIO_FUNC

Private Types

enum  DataType {
  EM_EM_CHAR = 1, EM_EM_SHORT = 2, EM_EM_INT = 4, EM_EM_FLOAT = 5,
  EM_EM_COMPLEX = 8, EM_EM_DOUBLE = 9, EM_EM_UNKNOWN
}
enum  MachineType {
  EM_OS8 = 0, EM_VAX = 1, EM_CONVEX = 2, EM_SGI = 3,
  EM_MAC = 5, EM_PC = 6, EM_UNKNOWN_MACHINE
}

Private Attributes

string filename
IOMode rw_mode
FILE * em_file
EMHeader emh
size_t mode_size
DataType mode
bool is_big_endian
bool initialized
bool is_new_file

Detailed Description

EmIO defines I/O operations on EM image format.

EM image = header + data with (data = nx * ny * nz).

An EM image file stores 1 single 2D or 3D image.

Definition at line 48 of file emio.h.


Member Enumeration Documentation

enum EMAN::EmIO::DataType [private]
Enumerator:
EM_EM_CHAR 
EM_EM_SHORT 
EM_EM_INT 
EM_EM_FLOAT 
EM_EM_COMPLEX 
EM_EM_DOUBLE 
EM_EM_UNKNOWN 

Definition at line 77 of file emio.h.

enum EMAN::EmIO::MachineType [private]
Enumerator:
EM_OS8 
EM_VAX 
EM_CONVEX 
EM_SGI 
EM_MAC 
EM_PC 
EM_UNKNOWN_MACHINE 

Definition at line 88 of file emio.h.

                {
                        EM_OS8 = 0,
                        EM_VAX = 1,
                        EM_CONVEX = 2,
                        EM_SGI = 3,
                        EM_MAC = 5,
                        EM_PC = 6,
                        EM_UNKNOWN_MACHINE
                };

Constructor & Destructor Documentation

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

Definition at line 43 of file emio.cpp.

References EM_EM_UNKNOWN, emh, is_big_endian, EMAN::ByteOrder::is_host_big_endian(), is_new_file, mode, and mode_size.

:       filename(file), rw_mode(rw), em_file(0), initialized(false)
{
        mode_size = 0;
        mode = EM_EM_UNKNOWN;
        is_big_endian = ByteOrder::is_host_big_endian();
        is_new_file = false;
        memset(&emh, 0, sizeof(EMHeader));
}
EmIO::~EmIO ( )

Definition at line 53 of file emio.cpp.

References em_file.

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

Member Function Documentation

int EmIO::get_machine_type ( ) [static]

Definition at line 329 of file emio.cpp.

References EM_MAC, EM_PC, EM_SGI, and EM_UNKNOWN_MACHINE.

{
        int m = EM_UNKNOWN_MACHINE;
#ifdef __sgi
        m = EM_SGI;
#elif defined __linux__
        m = EM_PC;
#elif defined __CYGWIN__
        m = EM_PC;
#elif defined WIN32
        m = EM_PC;
#elif defined MACOS
        m = EM_MAC;
#elif defined macintosh
        m = EM_MAC;
#elif defined __darwin__
        m = EM_MAC;
#elif defined __APPLE__
        m = EM_MAC;
#else
        m = EM_UNKNOWN_MACHINE;
#endif
        return m;
}
size_t EmIO::get_mode_size ( char  data_type) [static]

Definition at line 354 of file emio.cpp.

References EM_EM_CHAR, EM_EM_COMPLEX, EM_EM_DOUBLE, EM_EM_FLOAT, EM_EM_INT, EM_EM_SHORT, and mode.

Referenced by is_valid().

{
        int mode = (int) data_type;
        switch (mode) {
        case EM_EM_CHAR:
                return sizeof(char);
        case EM_EM_SHORT:
                return sizeof(short);
        case EM_EM_INT:
        case EM_EM_FLOAT:
        case EM_EM_COMPLEX:
                return sizeof(int);
        case EM_EM_DOUBLE:
                return sizeof(double);
        }
        return 0;
}
bool EmIO::is_valid ( const void *  first_block,
off_t  file_size = 0 
) [static]

Definition at line 100 of file emio.cpp.

References data, EM_EM_CHAR, EM_EM_DOUBLE, EM_OS8, EM_PC, ENTERFUNC, get_mode_size(), EMAN::ByteOrder::is_data_big_endian(), EMAN::ByteOrder::is_host_big_endian(), nx, ny, and EMAN::ByteOrder::swap_bytes().

Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type().

{
        ENTERFUNC;

        if (!first_block) {
                return false;
        }

        const char *data = static_cast < const char *>(first_block);
        char machine = data[0];
        char is_new_ver = data[1];
        char data_type = data[3];

        const int *data1 = static_cast < const int *>(first_block);
        int nx = data1[1];
        int ny = data1[2];
        int nz = data1[3];

        bool data_big_endian = ByteOrder::is_data_big_endian(&nz);
        if (data_big_endian != ByteOrder::is_host_big_endian()) {
                ByteOrder::swap_bytes(&nx);
                ByteOrder::swap_bytes(&ny);
                ByteOrder::swap_bytes(&nz);
        }

        const int max_dim = 1 << 20;

        if (((int) machine >= EM_OS8 && machine <= EM_PC) &&
                (is_new_ver == 0 || is_new_ver == 1) &&
                (data_type >= EM_EM_CHAR && data_type <= EM_EM_DOUBLE) &&
                (nx > 1 && nx < max_dim) && (ny > 0 && ny < max_dim) && (nz > 0 && nz < max_dim)) {
                if (file_size > 0) {
                        off_t file_size1 = (off_t)nx * (off_t)ny * (off_t)nz * (off_t)get_mode_size(data_type) + (off_t)sizeof(EMHeader);
                        if (file_size == file_size1) {
                                return true;
                        }
                }
                else {
                        return true;
                }
        }

        return false;
}
int EmIO::to_em_datatype ( char  t) [static]

Member Data Documentation

Definition at line 54 of file emio.h.

FILE* EMAN::EmIO::em_file [private]

Definition at line 102 of file emio.h.

Referenced by ~EmIO().

Definition at line 103 of file emio.h.

Referenced by EmIO().

string EMAN::EmIO::filename [private]

Definition at line 100 of file emio.h.

bool EMAN::EmIO::initialized [private]

Definition at line 108 of file emio.h.

bool EMAN::EmIO::is_big_endian [private]

Definition at line 107 of file emio.h.

Referenced by EmIO().

bool EMAN::EmIO::is_new_file [private]

Definition at line 109 of file emio.h.

Referenced by EmIO().

Definition at line 106 of file emio.h.

Referenced by EmIO(), and get_mode_size().

size_t EMAN::EmIO::mode_size [private]

Definition at line 105 of file emio.h.

Referenced by EmIO().

Definition at line 101 of file emio.h.


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