EMAN2
dm4io.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef __dm4io_h__
33#define __dm4io_h__
34
35#include "imageio.h"
36
37namespace EMAN
38{
39 namespace GatanDM4
40 {
42 {
43 public:
44 TagTable();
45 ~TagTable();
46
47 void add(const string & name, const string & value);
48 void add_data(char *data);
49
50 string get_string(const string & name);
51 int get_int(const string & name);
52 float get_float(const string & name);
53 double get_double(const string & name);
54
55 int get_image_counted() const;
56 int get_xsize() const;
57 int get_ysize() const;
58 int get_datatype() const;
59 char *get_data() const;
60 int get_num_images_found() const;
61 void set_num_images_found(int num_found);
62
63 void dump() const;
64
65 template < class T > void become_host_endian(T * data, int n = 1) {
67 ByteOrder::swap_bytes(data, n);
68 }
69 }
70
71 void set_endian(bool big_endian)
72 {
73 is_big_endian = big_endian;
74 }
75
76 private:
77 static const char *IMAGE_WIDTH_TAG;
78 static const char *IMAGE_HEIGHT_TAG;
79 static const char *IMAGE_NIMG_TAG;
80 static const char *IMAGE_DATATYPE_TAG;
81 static const char *IMAGE_THUMB_INDEX_TAG;
82 void set_thumb_index(int i);
83
84 private:
89 std::map < string, string > tags;
90 vector < int >x_list;
91 vector < int >y_list;
92 vector < int >datatype_list;
93 vector < char *>data_list;
94 };
95
96 class TagData
97 {
98 public:
99 enum Type
100 {
102 SHORT = 2,
103 INT = 3,
105 UINT = 5,
106 FLOAT = 6,
109 CHAR = 9,
110 OCTET = 10,
111 OCTEU = 11,
112 OCTEV = 12,
113 STRUCT = 15,
114 STRING = 18,
115 ARRAY = 20
116 };
117
118 TagData(FILE * data_file, TagTable * tagtable, const string & tagname);
119 ~TagData();
120
121 int read_tag_data(bool nodata = false, int image_index = 0, int num_images = 1);
122
123 private:
124 size_t typesize() const;
125 size_t typesize(int type) const;
126 int read_any(bool nodata = false, int image_index = 0, int num_images = 1);
127
128 vector < int >read_array_types();
129 int read_array_data(vector < int >item_types, bool nodata = false, int image_index = 0, int num_images = 1);
130 vector < int >read_struct_types();
131 string read_native(bool is_value_stored);
132 string read_string(int size);
133
134 private:
135 FILE * in;
137 string name;
138 long long tag_type;
139 };
140
142 {
143 public:
144 TagGroup(FILE * data_file, TagTable * tagtable, const string & groupname);
145 ~TagGroup();
146
147 int read_tag_group(bool nodata = false, int image_index = 0, int num_images = 1);
148 string get_name() const;
149 int get_entry_id();
150
151 private:
152 FILE * in;
154 string name;
156 };
157
159 {
160 public:
162 {
164 DATA_TAG = 21
165 };
166
167 TagEntry(FILE * data_file, TagTable * tagtable, TagGroup * parent_group);
168 ~TagEntry();
169
170 int read_tag_entry(bool nodata = false, int image_index = 0, int num_images = 1);
171
172 private:
173 FILE * in;
176 string name;
177 };
178
180 {
181 public:
183 {
222 };
223 };
224
225 int to_em_datatype(int gatan_datatype);
226 const char *to_str(GatanDM4::TagData::Type type);
227 const char *to_str(GatanDM4::TagEntry::EntryType type);
229
230 }
231
249 class DM4IO : public ImageIO
250 {
251 public:
252 explicit DM4IO(const string & fname, IOMode rw_mode = READ_ONLY);
253 ~DM4IO();
254
256 static bool is_valid(const void *first_block);
257 int get_nimg();
258
259 private:
260 enum { NUM_ID_INT = 4 }; //actually its int+long+int=16 bytes
261
264 };
265}
266
267#endif //__dm4io_h__
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
Gatan DM$ was introduced with the GMS 2.0 release.
Definition: dm4io.h:250
int get_nimg()
Return the number of images in this image file.
Definition: dm4io.cpp:1037
GatanDM4::TagTable * tagtable
Definition: dm4io.h:263
@ NUM_ID_INT
Definition: dm4io.h:260
DM4IO(const string &fname, IOMode rw_mode=READ_ONLY)
Definition: dm4io.cpp:742
bool is_big_endian
Definition: dm4io.h:262
static bool is_valid(const void *first_block)
Definition: dm4io.cpp:811
DEFINE_IMAGEIO_FUNC
Definition: dm4io.h:255
int read_tag_data(bool nodata=false, int image_index=0, int num_images=1)
Definition: dm4io.cpp:493
long long tag_type
Definition: dm4io.h:138
string read_string(int size)
Definition: dm4io.cpp:294
TagData(FILE *data_file, TagTable *tagtable, const string &tagname)
Definition: dm4io.cpp:177
vector< int > read_array_types()
Definition: dm4io.cpp:265
int read_any(bool nodata=false, int image_index=0, int num_images=1)
Definition: dm4io.cpp:437
size_t typesize() const
Definition: dm4io.cpp:534
TagTable * tagtable
Definition: dm4io.h:136
int read_array_data(vector< int >item_types, bool nodata=false, int image_index=0, int num_images=1)
Definition: dm4io.cpp:327
string read_native(bool is_value_stored)
Definition: dm4io.cpp:186
vector< int > read_struct_types()
Definition: dm4io.cpp:402
TagTable * tagtable
Definition: dm4io.h:174
TagEntry(FILE *data_file, TagTable *tagtable, TagGroup *parent_group)
Definition: dm4io.cpp:587
TagGroup * parent_group
Definition: dm4io.h:175
int read_tag_entry(bool nodata=false, int image_index=0, int num_images=1)
Definition: dm4io.cpp:596
int read_tag_group(bool nodata=false, int image_index=0, int num_images=1)
Definition: dm4io.cpp:683
TagGroup(FILE *data_file, TagTable *tagtable, const string &groupname)
Definition: dm4io.cpp:674
TagTable * tagtable
Definition: dm4io.h:153
string get_name() const
Definition: dm4io.cpp:728
char * get_data() const
Definition: dm4io.cpp:145
static const char * IMAGE_HEIGHT_TAG
Definition: dm4io.h:78
std::map< string, string > tags
Definition: dm4io.h:89
int get_num_images_found() const
Definition: dm4io.cpp:165
int get_datatype() const
Definition: dm4io.cpp:140
int get_int(const string &name)
Definition: dm4io.cpp:100
vector< int > datatype_list
Definition: dm4io.h:92
void become_host_endian(T *data, int n=1)
Definition: dm4io.h:65
vector< int > y_list
Definition: dm4io.h:91
void set_endian(bool big_endian)
Definition: dm4io.h:71
double get_double(const string &name)
Definition: dm4io.cpp:110
static const char * IMAGE_NIMG_TAG
Definition: dm4io.h:79
void set_num_images_found(int num_found)
Definition: dm4io.cpp:170
string get_string(const string &name)
Definition: dm4io.cpp:95
void add(const string &name, const string &value)
Definition: dm4io.cpp:61
static const char * IMAGE_THUMB_INDEX_TAG
Definition: dm4io.h:81
int get_image_counted() const
Definition: dm4io.cpp:130
static const char * IMAGE_WIDTH_TAG
Definition: dm4io.h:77
void set_thumb_index(int i)
Definition: dm4io.cpp:150
void dump() const
Definition: dm4io.cpp:115
void add_data(char *data)
Definition: dm4io.cpp:85
int get_xsize() const
Definition: dm4io.cpp:125
vector< char * > data_list
Definition: dm4io.h:93
int get_ysize() const
Definition: dm4io.cpp:135
float get_float(const string &name)
Definition: dm4io.cpp:105
vector< int > x_list
Definition: dm4io.h:90
static const char * IMAGE_DATATYPE_TAG
Definition: dm4io.h:80
ImageIO classes are designed for reading/writing various electron micrography image formats,...
Definition: imageio.h:127
IOMode rw_mode
Definition: imageio.h:353
int to_em_datatype(int gatan_datatype)
Definition: dm4io.cpp:1051
const char * to_str(GatanDM4::TagData::Type type)
Definition: dm4io.cpp:1083
E2Exception class.
Definition: aligner.h:40