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

SER (Series File Format) is a file format created by Dr. More...

#include <serio.h>

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

List of all members.

Classes

struct  SerHeader

Public Member Functions

 SerIO (const string &filename, IOMode rw_mode=READ_ONLY)
 ~SerIO ()
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  SerImgMode { oneD = 0x4120, twoD = 0x4122 }
enum  SerTagType { timeOnly = 0x4152, posTime = 0x4122 }
enum  SerDataMode {
  SER_UCHAR = 1, SER_USHORT, SER_UINT, SER_CHAR,
  SER_SHORT, SER_INT, SER_FLOAT, SER_DOUBLE,
  SER_COMPLEX8, SER_COMPLEX16, UNKNOWN
}

Private Member Functions

void read_dim_arr (Dict &dict, int idx)
 helper function to read attributes in dimension array
void read_data_element (Dict &dict)
 helper function to read header attributes in data element
void read_data_tag (Dict &dict)
 helper function to read header attributes in data tag

Private Attributes

string filename
IOMode rw_mode
FILE * serfile
bool initialized
bool is_new_file
SerHeader serh
int * data_offset_array
int * tag_offset_array
int nimg
int nx
int ny
int nz
int datatypeid
int datamode

Detailed Description

SER (Series File Format) is a file format created by Dr.

Chris Boothroyd. The file format is used by TIA (Tecnai imaging and analysis), which is the program used on FEI Tecnai and Titan microscopes for acquiring and displaying scanned images and spectra.

Each .ser file stores a number of 1D or 2D images. We do not support complex SER image for now.

http://www.microscopy.cen.dtu.dk/~cbb/info/TIAformat/index.html

Definition at line 53 of file serio.h.


Member Enumeration Documentation

enum EMAN::SerIO::SerDataMode [private]
Enumerator:
SER_UCHAR 
SER_USHORT 
SER_UINT 
SER_CHAR 
SER_SHORT 
SER_INT 
SER_FLOAT 
SER_DOUBLE 
SER_COMPLEX8 
SER_COMPLEX16 
UNKNOWN 

Definition at line 74 of file serio.h.

enum EMAN::SerIO::SerImgMode [private]
Enumerator:
oneD 
twoD 

Definition at line 64 of file serio.h.

                                {
                        oneD = 0x4120,
                        twoD = 0x4122
                };
enum EMAN::SerIO::SerTagType [private]
Enumerator:
timeOnly 
posTime 

Definition at line 69 of file serio.h.

                                {
                        timeOnly = 0x4152,
                        posTime  = 0x4122
                };

Constructor & Destructor Documentation

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

Definition at line 49 of file serio.cpp.

                                           :
                filename(file), rw_mode(rw), serfile(0), initialized(false),
                is_new_file(false), data_offset_array(0),tag_offset_array(0),
                nimg(0), nx(0), ny(0), nz(0), datatypeid(0), datamode(0)
{
}
SerIO::~SerIO ( )

Definition at line 56 of file serio.cpp.

References data_offset_array, serfile, and tag_offset_array.

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

        if (data_offset_array) {
                delete [] data_offset_array;
                data_offset_array = 0;
        }

        if (tag_offset_array) {
                delete [] tag_offset_array;
                tag_offset_array = 0;
        }
}

Member Function Documentation

int SerIO::get_nimg ( ) [virtual]

Return the number of images in this image file.

Reimplemented from EMAN::ImageIO.

Definition at line 347 of file serio.cpp.

References filename, ImageReadException, EMAN::ImageIO::init(), nimg, portable_fseek(), serfile, and ValidNumberElementsOffset.

                    {
        init();

        portable_fseek(serfile, ValidNumberElementsOffset, SEEK_SET);
        int nimg;
        if (fread(&nimg, sizeof(int), 1, serfile) != 1) {
                throw ImageReadException(filename, "SER header");
        }

        return nimg;
}
bool SerIO::is_valid ( const void *  first_block) [static]

Definition at line 98 of file serio.cpp.

References data, ENTERFUNC, and EXITFUNC.

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

{
        ENTERFUNC;

        if (!first_block) {
                return false;
        }

        const short *data = static_cast < const short *>(first_block);
        short ByteOrder = data[0];
        short SeriesID = data[1];

        if(ByteOrder != 0x4949 || SeriesID != 0x0197) {
                return false;
        }

        EXITFUNC;
        return true;
}
void SerIO::read_data_element ( Dict dict) [private]

helper function to read header attributes in data element

Definition at line 420 of file serio.cpp.

References datamode, datatypeid, filename, ImageReadException, nx, ny, nz, oneD, serfile, and twoD.

{
        if(this->datatypeid == oneD) {  //1D image
                double hitem4[2];
                if (fread(hitem4, sizeof(double), 2, serfile) != 2) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.CalibrationOffset"]   = hitem4[0];
                dict["SER.CalibrationDelta"]    = hitem4[1];

                int cali;
                if (fread(&cali, sizeof(int), 1, serfile) != 1) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.CalibrationElement"] = cali;

                short datatype;
                if (fread(&datatype, sizeof(short), 1, serfile) != 1) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.DataType"] = datatype;

                int arrlen;
                if (fread(&arrlen, sizeof(int), 1, serfile) != 1) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["nx"] = arrlen;
                dict["ny"] = 1;
                dict["nz"] = 1;

                nx = arrlen;
                ny = 1;
                nz = 1;
        }
        else if(this->datatypeid == twoD) {     //2D image
                double hitem4[2];
                if (fread(hitem4, sizeof(double), 2, serfile) != 2) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.CalibrationOffsetX"]  = hitem4[0];
                dict["SER.CalibrationDeltaX"]   = hitem4[1];

                int calix;
                if (fread(&calix, sizeof(int), 1, serfile) != 1) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.CalibrationElementX"] = calix;

                double hitem5[2];
                if (fread(hitem5, sizeof(double), 2, serfile) != 2) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.CalibrationOffsetX"]  = hitem5[0];
                dict["SER.CalibrationDeltaX"]   = hitem5[1];

                int caliy;
                if (fread(&caliy, sizeof(int), 1, serfile) != 1) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.CalibrationElementY"] = caliy;

                short datatype;
                if (fread(&datatype, sizeof(short), 1, serfile) != 1) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.DataType"] = datatype;
                this->datamode = datatype;

                int arrsize[2];
                if (fread(&arrsize, sizeof(int), 2, serfile) != 2) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["nx"] = arrsize[0];
                dict["ny"] = arrsize[1];
                dict["nz"] = 1;

                nx = arrsize[0];
                ny = arrsize[1];
                nz = 1;
        }
}
void SerIO::read_data_tag ( Dict dict) [private]

helper function to read header attributes in data tag

Definition at line 502 of file serio.cpp.

References filename, ImageReadException, posTime, serfile, and timeOnly.

{
        int tag_type = (int)dict["SER.TagTypeID"];
        if( tag_type == timeOnly ) {
                short tagtype;
                if (fread(&tagtype, sizeof(short), 1, serfile) != 1) {
                        throw ImageReadException(filename, "SER header");
                }
                assert((int)tagtype == tag_type);

                int sertime;
                if (fread(&sertime, sizeof(int), 1, serfile) != 1) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.Time"] = sertime;
        }
        else if( tag_type == posTime ) {
                short tagtype;
                if (fread(&tagtype, sizeof(short), 1, serfile) != 1) {
                        throw ImageReadException(filename, "SER header");
                }
                assert((int)tagtype == tag_type);

                int sertime;
                if (fread(&sertime, sizeof(int), 1, serfile) != 1) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.Time"] = sertime;

                double pos[2];
                if (fread(&pos, sizeof(double), 2, serfile) != 2) {
                        throw ImageReadException(filename, "SER header");
                }
                dict["SER.PosionX"] = pos[0];
                dict["SER.PosionY"] = pos[1];
        }
        else {
                throw ImageReadException(filename, "SER header, wrong TagTypeID");
        }
}
void SerIO::read_dim_arr ( Dict dict,
int  idx 
) [private]

helper function to read attributes in dimension array

Definition at line 359 of file serio.cpp.

References filename, ImageReadException, EMAN::Util::int2str(), and serfile.

{
        int dimsize;
        if (fread(&dimsize, sizeof(int), 1, serfile) != 1) {
                throw ImageReadException(filename, "SER header");
        }

        string sidx = Util::int2str(idx);
        dict["SER.DimensionSize"+sidx]  = dimsize;

        double hitem3[2];
        if (fread(hitem3, sizeof(double), 2, serfile) != 2) {
                throw ImageReadException(filename, "SER header");
        }
        dict["SER.CalibrationOffset"+sidx]      = hitem3[0];
        dict["SER.CalibrationDelta"+sidx]       = hitem3[1];

        int celement;
        if (fread(&celement, sizeof(int), 1, serfile) != 1) {
                throw ImageReadException(filename, "SER header");
        }
        dict["SER.CalibrationElement"+sidx]     = celement;

        int desclen;
        if (fread(&desclen, sizeof(int), 1, serfile) != 1) {
                throw ImageReadException(filename, "SER header");
        }
        dict["SER.DescriptionLength"+sidx]      = desclen;

        if(desclen != 0) {
                char * descr = new char[desclen+1];
                //char descr[desclen+1];
                if (fread(descr, sizeof(char), desclen, serfile) != (unsigned int)desclen) {
                        throw ImageReadException(filename, "SER header");
                }
                descr[desclen] = '\0';
                string sdescr(descr);
                dict["SER.Description"+sidx] = sdescr;
                delete [] descr;
        }

        int unitslen;
        if (fread(&unitslen, sizeof(int), 1, serfile) != 1) {
                throw ImageReadException(filename, "SER header");
        }
        dict["SER.UnitsLength"+sidx] = unitslen;

        if(unitslen != 0) {
                char * units = new char[unitslen+1];
                //char units[unitslen+1];
                if (fread(units, sizeof(int), unitslen, serfile) != (unsigned int)unitslen) {
                        throw ImageReadException(filename, "SER header");
                }
                units[unitslen] = '\0';
                string sunits(units);
                dict["SER.Units"+sidx] = sunits;
                delete [] units;
        }

}

Member Data Documentation

Definition at line 110 of file serio.h.

Referenced by ~SerIO().

int EMAN::SerIO::datamode [private]

Definition at line 117 of file serio.h.

Referenced by read_data_element().

int EMAN::SerIO::datatypeid [private]

Definition at line 116 of file serio.h.

Referenced by read_data_element().

Definition at line 59 of file serio.h.

string EMAN::SerIO::filename [private]

Definition at line 102 of file serio.h.

Referenced by get_nimg(), read_data_element(), read_data_tag(), and read_dim_arr().

bool EMAN::SerIO::initialized [private]

Definition at line 105 of file serio.h.

bool EMAN::SerIO::is_new_file [private]

Definition at line 106 of file serio.h.

int EMAN::SerIO::nimg [private]

Definition at line 112 of file serio.h.

Referenced by get_nimg().

int EMAN::SerIO::nx [private]

Definition at line 113 of file serio.h.

Referenced by read_data_element().

int EMAN::SerIO::ny [private]

Definition at line 114 of file serio.h.

Referenced by read_data_element().

int EMAN::SerIO::nz [private]

Definition at line 115 of file serio.h.

Referenced by read_data_element().

Definition at line 103 of file serio.h.

FILE* EMAN::SerIO::serfile [private]

Definition at line 104 of file serio.h.

Referenced by get_nimg(), read_data_element(), read_data_tag(), read_dim_arr(), and ~SerIO().

Definition at line 108 of file serio.h.

Definition at line 111 of file serio.h.

Referenced by ~SerIO().


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