#include <sspiderio.h>
Inheritance diagram for EMAN::SingleSpiderIO:
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 |
For Spider and Single Spider image format, please refer spiderio.h.
Definition at line 48 of file sspiderio.h.
SingleSpiderIO::SingleSpiderIO | ( | const string & | filename, | |
IOMode | rw_mode = READ_ONLY | |||
) | [explicit] |
SingleSpiderIO constructor.
filename | The filename of a single spider image file. | |
rw_mode | Read/Write file open mode. |
Definition at line 44 of file sspiderio.cpp.
00045 : SpiderIO(file, rw) 00046 { 00047 }
SingleSpiderIO::~SingleSpiderIO | ( | ) |
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.
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().
00076 { 00077 ENTERFUNC; 00078 bool result = false; 00079 00080 if (first_block) { 00081 const float *data = static_cast < const float *>(first_block); 00082 float nslice = data[0]; 00083 float nrow = data[1]; 00084 float iform = data[4]; 00085 float nsam = data[11]; 00086 float labrec = data[12]; //NO. of records in file header 00087 float labbyt = data[21]; //total NO. of bytes in header 00088 float lenbyt = data[22]; //record length in bytes 00089 float istack = data[23]; 00090 00091 bool big_endian = ByteOrder::is_float_big_endian(nslice); 00092 if (big_endian != ByteOrder::is_host_big_endian()) { 00093 ByteOrder::swap_bytes(&nslice); 00094 ByteOrder::swap_bytes(&nrow); 00095 ByteOrder::swap_bytes(&iform); 00096 ByteOrder::swap_bytes(&nsam); 00097 ByteOrder::swap_bytes(&labrec); 00098 ByteOrder::swap_bytes(&labbyt); 00099 ByteOrder::swap_bytes(&lenbyt); 00100 ByteOrder::swap_bytes(&istack); 00101 } 00102 00103 if( int(nslice) != nslice || int(nrow) != nrow 00104 || int(iform) != iform || int(nsam) != nsam 00105 || int(labrec) != labrec || int(labbyt) != labbyt 00106 || int(lenbyt) != lenbyt ) { 00107 result = false; 00108 } 00109 else { 00110 int itype = static_cast < int >(iform); 00111 if( int(istack) != SINGLE_IMAGE_HEADER ) { 00112 result = false; //istack>0 for overall header, istack<0 for indexed stack of image 00113 } 00114 else if( itype == IMAGE_2D_FFT_ODD || itype == IMAGE_2D_FFT_EVEN 00115 || itype == IMAGE_3D_FFT_ODD || itype == IMAGE_3D_FFT_EVEN ) { 00116 result = false; //Complex SPIDER image not supported in EMAN2 00117 } 00118 else if (itype == IMAGE_2D || itype == IMAGE_3D) { 00119 result = true; 00120 } 00121 } 00122 00123 int ilabrec = static_cast<int>(labrec); 00124 int ilabbyt = static_cast<int>(labbyt); 00125 int ilenbyt = static_cast<int>(lenbyt); 00126 if( ilabbyt != ilabrec * ilenbyt ) { 00127 result = false; 00128 } 00129 } 00130 00131 EXITFUNC; 00132 return result; 00133 }
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
first_block | the pointer to first block of the file |
Reimplemented from EMAN::SpiderIO.
Definition at line 136 of file sspiderio.cpp.
References is_valid().
00137 { 00138 return SingleSpiderIO::is_valid(first_block); 00139 }
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.
data | An array storing the data. | |
image_index | The index of the image to write. | |
area | The region to write data to. | |
filestoragetype | The image data type used in the output file. | |
use_host_endian | Whether to use the host machine endian to write out or not. If false, use the endian opposite to the host machine's endian. |
Implements EMAN::ImageIO.
Definition at line 67 of file sspiderio.cpp.
References EMAN::SpiderIO::first_h, and EMAN::SpiderIO::write_single_data().
00069 { 00070 size_t offset = (int) first_h->headlen; 00071 return write_single_data(data, area, first_h, offset, 0, 1, use_host_endian); 00072 }
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.
dict | A keyed-dictionary storing the header information. | |
image_index | The index of the image to write. | |
area | The region to write data to. | |
filestoragetype | The image data type used in the output file. | |
use_host_endian | Whether to use the host machine endian to write out or not. If false, use the endian opposite to the host machine's endian. |
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().
00057 { 00058 size_t offset = 0; 00059 int image_index = 0; 00060 // if(!use_host_endian) { 00061 // ByteOrder::swap_bytes((float*)first_h, NUM_FLOATS_IN_HEADER); 00062 // } 00063 return write_single_header(dict, area, image_index, offset, first_h, SINGLE_IMAGE_HEADER, 1, 1, use_host_endian); 00064 }