EMAN2
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
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]

Public Member Functions

 SingleSpiderIO (const string &fname, IOMode rw_mode=READ_ONLY)
 SingleSpiderIO constructor. More...
 
 ~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. More...
 
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. More...
 
bool is_single_image_format () const
 Is this image format only storing 1 image or not. More...
 
- Public Member Functions inherited from EMAN::SpiderIO
 SpiderIO (const string &fname, IOMode rw_mode=READ_ONLY)
 
 ~SpiderIO ()
 
int get_nimg ()
 get the number of images in this stacked SPIDER image More...
 
- Public Member Functions inherited from EMAN::ImageIO
 ImageIO (const string &fname, IOMode rw)
 
virtual ~ImageIO ()
 
virtual int read_header (Dict &dict, int image_index=0, const Region *area=0, bool is_3d=false)=0
 Read the header from an image. More...
 
virtual int read_data (float *data, int image_index=0, const Region *area=0, bool is_3d=false)=0
 Read the data from an image. More...
 
virtual int read_data_8bit (unsigned char *data, int image_index=0, const Region *area=0, bool is_3d=false, float minval=0.0f, float maxval=0.0f)
 Read the data from an image as an 8 bit array, regardless of format. More...
 
virtual int read_ctf (Ctf &ctf, int image_index=0)
 Read CTF data from this image. More...
 
virtual void write_ctf (const Ctf &ctf, int image_index=0)
 Write CTF data to this image. More...
 
virtual void flush ()=0
 Flush the IO buffer. More...
 
virtual bool is_complex_mode ()=0
 Is this an complex image or not. More...
 
virtual bool is_image_big_endian ()=0
 Is this image in big endian or not. More...
 
template<class T >
void become_host_endian (T *data, size_t n=1)
 Convert data of this image into host endian format. More...
 
string get_filename () const
 

Static Public Member Functions

static bool is_valid (const void *first_block)
 
- Static Public Member Functions inherited from EMAN::SpiderIO
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 More...
 
- Protected Member Functions inherited from EMAN::SpiderIO
int write_single_header (const Dict &dict, const Region *area, int image_index, size_t offset, SpiderHeader *&hp, int ISTACK, int MAXIM=1, int IMGNUM=1, bool use_host_endian=true)
 write a SPIDER header to spider_file More...
 
int write_single_data (float *data, const Region *area, SpiderHeader *&hp, size_t offset, int img_index, int max_nimg, bool use_host_endian=true)
 write a single image data More...
 
bool need_swap () const
 
void swap_data (float *data, size_t nitems)
 
void swap_header (SpiderHeader *header)
 
- Protected Member Functions inherited from EMAN::ImageIO
virtual void init ()=0
 Do some initialization before doing the read/write. More...
 
void check_read_access (int image_index)
 Validate 'image_index' in file reading. More...
 
void check_read_access (int image_index, const float *data)
 Validate 'image_index' and 'data' in file reading. More...
 
void check_write_access (IOMode rw_mode, int image_index, int max_nimg=0)
 Validate rw_mode and image_index in file writing. More...
 
void check_write_access (IOMode rw_mode, int image_index, int max_nimg, const float *data)
 Validate rw_mode, image_index, and data pointer in file writing. More...
 
void check_region (const Region *area, const FloatSize &max_size, bool is_new_file=false, bool inbounds_only=true)
 Validate image I/O region. More...
 
void check_region (const Region *area, const IntSize &max_size, bool is_new_file=false, bool inbounds_only=true)
 Validate image I/O region. More...
 
FILE * sfopen (const string &filename, IOMode mode, bool *is_new=0, bool overwrite=false)
 Run fopen safely. More...
 

Additional Inherited Members

- Public Types inherited from EMAN::ImageIO
enum  IOMode { READ_ONLY = 1 , READ_WRITE = 2 , WRITE_ONLY = 3 }
 
- Public Attributes inherited from EMAN::SpiderIO
 DEFINE_IMAGEIO_FUNC
 
- Protected Types inherited from EMAN::SpiderIO
enum  SpiderType {
  IMAGE_2D = 1 , IMAGE_3D = 3 , IMAGE_2D_FFT_ODD = -11 , IMAGE_2D_FFT_EVEN = -12 ,
  IMAGE_3D_FFT_ODD = -21 , IMAGE_3D_FFT_EVEN = -22
}
 
enum  { SINGLE_IMAGE_HEADER = 0 , OVERALL_STACK_HEADER = 2 , NUM_FLOATS_IN_HEADER = 211 }
 
- Protected Attributes inherited from EMAN::SpiderIO
SpiderHeaderfirst_h
 
SpiderHeadercur_h
 
bool is_big_endian
 
bool is_new_file
 
- Protected Attributes inherited from EMAN::ImageIO
string filename
 
IOMode rw_mode
 
FILE * file = nullptr
 
bool initialized = false
 

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 44 of file sspiderio.h.

Constructor & Destructor Documentation

◆ SingleSpiderIO()

SingleSpiderIO::SingleSpiderIO ( const string &  fname,
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 40 of file sspiderio.cpp.

41: SpiderIO(fname, rw)
42{
43}
SpiderIO(const string &fname, IOMode rw_mode=READ_ONLY)
Definition: spiderio.cpp:44

◆ ~SingleSpiderIO()

SingleSpiderIO::~SingleSpiderIO ( )

Definition at line 46 of file sspiderio.cpp.

47{
48}

Member Function Documentation

◆ is_single_image_format()

bool EMAN::SingleSpiderIO::is_single_image_format ( ) const
inlinevirtual

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 86 of file sspiderio.h.

87 {
88 return true;
89 }

◆ is_valid()

bool SingleSpiderIO::is_valid ( const void *  first_block)
static

Definition at line 71 of file sspiderio.cpp.

72{
74 bool result = false;
75
76 if (first_block) {
77 const float *data = static_cast < const float *>(first_block);
78 float nslice = data[0];
79 float nrow = data[1];
80 float iform = data[4];
81 float nsam = data[11];
82 float labrec = data[12]; //NO. of records in file header
83 float labbyt = data[21]; //total NO. of bytes in header
84 float lenbyt = data[22]; //record length in bytes
85 float istack = data[23];
86
87 bool big_endian = ByteOrder::is_float_big_endian(nslice);
88 if (big_endian != ByteOrder::is_host_big_endian()) {
89 ByteOrder::swap_bytes(&nslice);
93 ByteOrder::swap_bytes(&labrec);
94 ByteOrder::swap_bytes(&labbyt);
95 ByteOrder::swap_bytes(&lenbyt);
96 ByteOrder::swap_bytes(&istack);
97 }
98
99 if( int(nslice) != nslice || int(nrow) != nrow
100 || int(iform) != iform || int(nsam) != nsam
101 || int(labrec) != labrec || int(labbyt) != labbyt
102 || int(lenbyt) != lenbyt ) {
103 result = false;
104 }
105 else {
106 int itype = static_cast < int >(iform);
107 if( int(istack) != SINGLE_IMAGE_HEADER ) {
108 result = false; //istack>0 for overall header, istack<0 for indexed stack of image
109 }
110 else if( itype == IMAGE_2D_FFT_ODD || itype == IMAGE_2D_FFT_EVEN
111 || itype == IMAGE_3D_FFT_ODD || itype == IMAGE_3D_FFT_EVEN ) {
112 result = false; //Complex SPIDER image not supported in EMAN2
113 }
114 else if (itype == IMAGE_2D || itype == IMAGE_3D) {
115 result = true;
116 }
117 }
118
119 int ilabrec = static_cast<int>(labrec);
120 int ilabbyt = static_cast<int>(labbyt);
121 int ilenbyt = static_cast<int>(lenbyt);
122 if( ilabbyt != ilabrec * ilenbyt ) {
123 result = false;
124 }
125 }
126
127 EXITFUNC;
128 return result;
129}
static bool is_host_big_endian()
Definition: byteorder.cpp:40
static void swap_bytes(T *data, size_t n=1)
swap the byte order of data with 'n' T-type elements.
Definition: byteorder.h:131
static bool is_float_big_endian(float small_number)
given a small floating number, return whether the number is in big endian or not.
Definition: byteorder.cpp:59
@ SINGLE_IMAGE_HEADER
Definition: spiderio.h:193
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49

References 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().

◆ is_valid_spider()

bool SingleSpiderIO::is_valid_spider ( const void *  first_block)
protectedvirtual

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 132 of file sspiderio.cpp.

133{
134 return SingleSpiderIO::is_valid(first_block);
135}
static bool is_valid(const void *first_block)
Definition: sspiderio.cpp:71

References is_valid().

◆ write_data()

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 63 of file sspiderio.cpp.

65{
66 size_t offset = (int) first_h->headlen;
67 return write_single_data(data, area, first_h, offset, 0, 1, use_host_endian);
68}
int write_single_data(float *data, const Region *area, SpiderHeader *&hp, size_t offset, int img_index, int max_nimg, bool use_host_endian=true)
write a single image data
Definition: spiderio.cpp:616
SpiderHeader * first_h
Definition: spiderio.h:242

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

◆ write_header()

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 51 of file sspiderio.cpp.

53{
54 size_t offset = 0;
55 int image_index = 0;
56// if(!use_host_endian) {
57// ByteOrder::swap_bytes((float*)first_h, NUM_FLOATS_IN_HEADER);
58// }
59 return write_single_header(dict, area, image_index, offset, first_h, SINGLE_IMAGE_HEADER, 1, 1, use_host_endian);
60}
int write_single_header(const Dict &dict, const Region *area, int image_index, size_t offset, SpiderHeader *&hp, int ISTACK, int MAXIM=1, int IMGNUM=1, bool use_host_endian=true)
write a SPIDER header to spider_file
Definition: spiderio.cpp:400

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


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