EMAN2
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Attributes | List of all members
EMAN::IcosIO Class Reference

ICOS file = header + data. More...

#include <icosio.h>

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

Classes

struct  IcosHeader
 

Public Member Functions

 IcosIO (const string &fname, IOMode rw_mode=READ_ONLY)
 
 ~IcosIO ()
 
- 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 write_header (const Dict &dict, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)=0
 Write a header to 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 write_data (float *data, int image_index=0, const Region *area=0, EMUtil::EMDataType filestoragetype=EMUtil::EM_FLOAT, bool use_host_endian=true)=0
 Write data to an image. 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 int get_nimg ()
 Return the number of images in this image file. 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...
 
virtual bool is_single_image_format () const
 Is this image format only storing 1 image 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)
 

Public Attributes

 DEFINE_IMAGEIO_FUNC
 

Private Types

enum  { STAMP = 72 , STAMP1 = 72 , STAMP2 = 20 , STAMP3 = 20 }
 

Private Attributes

IcosHeader icosh
 
bool is_big_endian
 
bool is_new_file
 

Additional Inherited Members

- Public Types inherited from EMAN::ImageIO
enum  IOMode { READ_ONLY = 1 , READ_WRITE = 2 , WRITE_ONLY = 3 }
 
- 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...
 
- Protected Attributes inherited from EMAN::ImageIO
string filename
 
IOMode rw_mode
 
FILE * file = nullptr
 
bool initialized = false
 

Detailed Description

ICOS file = header + data.

  1. header, defined in IcosHeader.
  2. data: ny*nz of rows. Each row = n1 + row-data + n2 where n1: an integer. n1 = nx*sizeof(float). n2: an integer. n2 = n1. row-data: nx numbers of float points.

An Icos file stores 1 2D or 3D image.

Definition at line 50 of file icosio.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
STAMP 
STAMP1 
STAMP2 
STAMP3 

Definition at line 60 of file icosio.h.

61{ STAMP = 72, STAMP1 = 72, STAMP2 = 20, STAMP3 = 20 };

Constructor & Destructor Documentation

◆ IcosIO()

IcosIO::IcosIO ( const string &  fname,
IOMode  rw_mode = READ_ONLY 
)
explicit

Definition at line 40 of file icosio.cpp.

41: ImageIO(fname, rw)
42{
44 is_new_file = false;
45 memset(&icosh, 0, sizeof(IcosHeader));
46}
static bool is_host_big_endian()
Definition: byteorder.cpp:40
bool is_big_endian
Definition: icosio.h:79
IcosHeader icosh
Definition: icosio.h:78
bool is_new_file
Definition: icosio.h:80
ImageIO(const string &fname, IOMode rw)
Definition: imageio.cpp:40

References icosh, is_big_endian, EMAN::ByteOrder::is_host_big_endian(), and is_new_file.

◆ ~IcosIO()

IcosIO::~IcosIO ( )

Definition at line 48 of file icosio.cpp.

49{
50 if (file) {
51 fclose(file);
52 file = 0;
53 }
54}
FILE * file
Definition: imageio.h:354

References EMAN::ImageIO::file.

Member Function Documentation

◆ is_valid()

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

Definition at line 80 of file icosio.cpp.

81{
83 bool result = false;
84 if (!first_block) {
85 result = false;
86 }
87 else {
88 const int *data = static_cast < const int *>(first_block);
89 int stamp = data[0];
90 int stamp1 = data[19];
91 int stamp2 = data[20];
92 int stamp3 = data[26];
93
94 bool data_big_endian = ByteOrder::is_data_big_endian(&stamp);
95
96 if (data_big_endian != ByteOrder::is_host_big_endian()) {
98 ByteOrder::swap_bytes(&stamp1);
99 ByteOrder::swap_bytes(&stamp2);
100 ByteOrder::swap_bytes(&stamp3);
101 }
102
103 if (stamp == STAMP && stamp1 == STAMP1 && stamp2 == STAMP2 && stamp3 == STAMP3) {
104 result = true;
105 }
106 }
107 EXITFUNC;
108 return result;
109}
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_data_big_endian(const T *small_num_addr)
given a pointer to a reasonable small integer number, return whether the number is big endian or not.
Definition: byteorder.h:76
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49

References ENTERFUNC, EXITFUNC, EMAN::ByteOrder::is_data_big_endian(), EMAN::ByteOrder::is_host_big_endian(), STAMP, STAMP1, STAMP2, STAMP3, and EMAN::ByteOrder::swap_bytes().

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

Member Data Documentation

◆ DEFINE_IMAGEIO_FUNC

EMAN::IcosIO::DEFINE_IMAGEIO_FUNC

Definition at line 56 of file icosio.h.

◆ icosh

IcosHeader EMAN::IcosIO::icosh
private

Definition at line 78 of file icosio.h.

Referenced by IcosIO().

◆ is_big_endian

bool EMAN::IcosIO::is_big_endian
private

Definition at line 79 of file icosio.h.

Referenced by IcosIO().

◆ is_new_file

bool EMAN::IcosIO::is_new_file
private

Definition at line 80 of file icosio.h.

Referenced by IcosIO().


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