00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef eman__spiderio_h__
00037 #define eman__spiderio_h__ 1
00038
00039 #include "imageio.h"
00040
00041 namespace EMAN
00042 {
00075 class SpiderIO:public ImageIO
00076 {
00077 public:
00078 explicit SpiderIO(const string & filename, IOMode rw_mode = READ_ONLY);
00079 ~SpiderIO();
00080
00081 DEFINE_IMAGEIO_FUNC;
00082 static bool is_valid(const void *first_block);
00083
00084 bool is_single_image_format() const { return false; }
00085
00089 int get_nimg();
00090
00091 protected:
00092 struct SpiderHeader
00093 {
00094 float nslice;
00095 float nrow;
00096 float irec;
00097 float nhistrec;
00098
00107 float type;
00108
00114 float mmvalid;
00115 float max;
00116 float min;
00117 float mean;
00118 float sigma;
00119 float ihist;
00120 float nsam;
00121 float headrec;
00122 float angvalid;
00123 float phi;
00124 float theta;
00125 float gamma;
00126 float dx;
00127 float dy;
00128 float dz;
00129 float scale;
00130 float headlen;
00131 float reclen;
00132
00145 float istack;
00146 float inuse;
00152 float maxim;
00156 float imgnum;
00157
00160 float lastindx;
00161
00162 float u6;
00163 float u7;
00164
00170 float Kangle;
00171 float phi1;
00172 float theta1;
00173 float psi1;
00174 float phi2;
00175 float theta2;
00176 float psi2;
00177 char u8[48];
00178 float xf[27];
00179 float u9[135];
00180 char date[11];
00181 char time[8];
00182 char title[160];
00183 };
00184
00185 enum SpiderType
00186 {
00187 IMAGE_2D = 1,
00188 IMAGE_3D = 3,
00189 IMAGE_2D_FFT_ODD = -11,
00190 IMAGE_2D_FFT_EVEN = -12,
00191 IMAGE_3D_FFT_ODD = -21,
00192 IMAGE_3D_FFT_EVEN = -22
00193 };
00194
00195 enum
00196 {
00197 SINGLE_IMAGE_HEADER = 0,
00198 OVERALL_STACK_HEADER = 2,
00199 NUM_FLOATS_IN_HEADER = 211
00200 };
00201
00215
00216 int write_single_header(const Dict & dict, const Region* area, int image_index, size_t offset,
00217 SpiderHeader *& hp, int ISTACK, int MAXIM=1, int IMGNUM=1, bool use_host_endian=true);
00218
00230 int write_single_data(float *data, const Region * area, SpiderHeader *& hp,
00231 size_t offset, int img_index, int max_nimg, bool use_host_endian=true);
00232
00237 virtual bool is_valid_spider(const void *first_block);
00238
00239 protected:
00240 bool need_swap() const;
00241 void swap_data(float *data, size_t nitems);
00242 void swap_header(SpiderHeader * header);
00243
00244 protected:
00245 string filename;
00246 IOMode rw_mode;
00247
00248 FILE *spider_file;
00249 SpiderHeader *first_h;
00250 SpiderHeader *cur_h;
00251
00252 bool is_big_endian;
00253 bool initialized;
00254 bool is_new_file;
00255 };
00256 }
00257
00258 #endif //eman__spiderio_h__