EMAN2
Public Member Functions | Static Public Member Functions | Protected Member Functions
EMAN::SingleSpiderIO Class Reference

Single Spider Image I/O class. More...

#include <sspiderio.h>

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

List of all members.

Public Member Functions

 SingleSpiderIO (const string &filename, IOMode rw_mode=READ_ONLY)
 SingleSpiderIO constructor.
 ~SingleSpiderIO ()
int write_header (const Dict &dict, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)
 Write a single SPIDER format header to an image.
int write_data (float *data, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)
 Write data to an image.
bool is_single_image_format () const
 Is this image format only storing 1 image or not.

Static Public Member Functions

static bool is_valid (const void *first_block)

Protected Member Functions

bool is_valid_spider (const void *first_block)
 check the data block to see if it represents valid stacked SPIDER image file header

Detailed Description

Single Spider Image I/O class.

For Spider and Single Spider image format, please refer spiderio.h.

See also:
spiderio.h

Definition at line 48 of file sspiderio.h.


Constructor & Destructor Documentation

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

SingleSpiderIO constructor.

Parameters:
filenameThe filename of a single spider image file.
rw_modeRead/Write file open mode.

Definition at line 44 of file sspiderio.cpp.

:       SpiderIO(file, rw)
{
}
SingleSpiderIO::~SingleSpiderIO ( )

Definition at line 50 of file sspiderio.cpp.

{
}

Member Function Documentation

bool EMAN::SingleSpiderIO::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::SpiderIO.

Definition at line 90 of file sspiderio.h.

                {
                        return true;
                }
bool SingleSpiderIO::is_valid ( const void *  first_block) [static]

Reimplemented from EMAN::SpiderIO.

Definition at line 75 of file sspiderio.cpp.

References data, ENTERFUNC, EXITFUNC, EMAN::SpiderIO::IMAGE_2D, EMAN::SpiderIO::IMAGE_2D_FFT_EVEN, EMAN::SpiderIO::IMAGE_2D_FFT_ODD, EMAN::SpiderIO::IMAGE_3D, EMAN::SpiderIO::IMAGE_3D_FFT_EVEN, EMAN::SpiderIO::IMAGE_3D_FFT_ODD, EMAN::ByteOrder::is_float_big_endian(), EMAN::ByteOrder::is_host_big_endian(), EMAN::SpiderIO::SINGLE_IMAGE_HEADER, and EMAN::ByteOrder::swap_bytes().

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

{
        ENTERFUNC;
        bool result = false;
        
        if (first_block) {
                const float *data = static_cast < const float *>(first_block);
                float nslice = data[0];
                float nrow = data[1];
                float iform = data[4];
                float nsam = data[11];
                float labrec = data[12];        //NO. of records in file header
                float labbyt = data[21];        //total NO. of bytes in header
                float lenbyt = data[22];        //record length in bytes
                float istack = data[23];
                
                bool big_endian = ByteOrder::is_float_big_endian(nslice);
                if (big_endian != ByteOrder::is_host_big_endian()) {
                        ByteOrder::swap_bytes(&nslice);
                        ByteOrder::swap_bytes(&nrow);
                        ByteOrder::swap_bytes(&iform);
                        ByteOrder::swap_bytes(&nsam);
                        ByteOrder::swap_bytes(&labrec);
                        ByteOrder::swap_bytes(&labbyt);
                        ByteOrder::swap_bytes(&lenbyt);
                        ByteOrder::swap_bytes(&istack);
                }
                
                if( int(nslice) != nslice || int(nrow) != nrow
                                || int(iform) != iform || int(nsam) != nsam 
                                || int(labrec) != labrec || int(labbyt) != labbyt
                                || int(lenbyt) != lenbyt ) {
                        result =  false;
                }
                else {
                        int itype = static_cast < int >(iform);
                        if( int(istack) != SINGLE_IMAGE_HEADER ) {
                                result = false; //istack>0 for overall header, istack<0 for indexed stack of image
                        }
                        else if( itype == IMAGE_2D_FFT_ODD || itype == IMAGE_2D_FFT_EVEN 
                                        || itype == IMAGE_3D_FFT_ODD || itype == IMAGE_3D_FFT_EVEN ) {
                                result = false; //Complex SPIDER image not supported in EMAN2
                        }
                        else if (itype == IMAGE_2D || itype == IMAGE_3D) {
                                result = true;
                        }
                }
                
                int ilabrec = static_cast<int>(labrec);
                int ilabbyt = static_cast<int>(labbyt);
                int ilenbyt = static_cast<int>(lenbyt);
                if( ilabbyt != ilabrec * ilenbyt ) {
                        result = false;
                }
        }

        EXITFUNC;
        return result;
}
bool SingleSpiderIO::is_valid_spider ( const void *  first_block) [protected, virtual]

check the data block to see if it represents valid stacked SPIDER image file header

Parameters:
first_blockthe pointer to first block of the file
Returns:
boolean result of the check, true for valid stacked SPIDER image

Reimplemented from EMAN::SpiderIO.

Definition at line 136 of file sspiderio.cpp.

References is_valid().

{
        return SingleSpiderIO::is_valid(first_block);
}
int SingleSpiderIO::write_data ( float *  data,
int  image_index = 0,
const Region area = 0,
EMUtil::EMDataType  filestoragetype = EMUtil::EM_FLOAT,
bool  use_host_endian = true 
) [virtual]

Write data to an image.

Parameters:
dataAn array storing the data.
image_indexThe index of the image to write.
areaThe region to write data to.
filestoragetypeThe image data type used in the output file.
use_host_endianWhether to use the host machine endian to write out or not. If false, use the endian opposite to the host machine's endian.
Returns:
0 if OK; 1 if error.

Implements EMAN::ImageIO.

Definition at line 67 of file sspiderio.cpp.

References EMAN::SpiderIO::first_h, EMAN::SpiderIO::SpiderHeader::headlen, and EMAN::SpiderIO::write_single_data().

{
        size_t offset = (int) first_h->headlen;
        return write_single_data(data, area, first_h, offset, 0, 1, use_host_endian);
}
int SingleSpiderIO::write_header ( const Dict dict,
int  image_index = 0,
const Region area = 0,
EMUtil::EMDataType  filestoragetype = EMUtil::EM_FLOAT,
bool  use_host_endian = true 
) [virtual]

Write a single SPIDER format header to an image.

Parameters:
dictA keyed-dictionary storing the header information.
image_indexThe index of the image to write.
areaThe region to write data to.
filestoragetypeThe image data type used in the output file.
use_host_endianWhether to use the host machine endian to write out or not. If false, use the endian opposite to the host machine's endian.
Returns:
0 if OK; 1 if error.

Implements EMAN::ImageIO.

Definition at line 55 of file sspiderio.cpp.

References EMAN::SpiderIO::first_h, EMAN::SpiderIO::SINGLE_IMAGE_HEADER, and EMAN::SpiderIO::write_single_header().

{
        size_t offset = 0;
        int image_index = 0;
//      if(!use_host_endian) {
//              ByteOrder::swap_bytes((float*)first_h, NUM_FLOATS_IN_HEADER);
//      }
        return write_single_header(dict, area, image_index, offset, first_h, SINGLE_IMAGE_HEADER, 1, 1, use_host_endian);
}

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