EMAN2
dm3io.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 __dm3io_h__
33#define __dm3io_h__
34
35#include "imageio.h"
36
37using std::vector;
38using std::map;
39
40namespace EMAN
41{
42 namespace Gatan
43 {
45 {
46 public:
47 TagTable();
48 ~TagTable();
49
50 void add(const string & name, const string & value);
51 void add_data(char *data);
52
53 string get_string(const string & name);
54 int get_int(const string & name);
55 float get_float(const string & name);
56 double get_double(const string & name);
57
58 int get_xsize() const;
59 int get_ysize() const;
60 int get_datatype() const;
61 char *get_data() const;
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_DATATYPE_TAG;
80 static const char *IMAGE_THUMB_INDEX_TAG;
81 void set_thumb_index(int i);
82
83 private:
86 std::map < string, string > tags;
87 vector < int >x_list;
88 vector < int >y_list;
89 vector < int >datatype_list;
90 vector < char *>data_list;
91 };
92
93 class TagData
94 {
95 public:
96 enum Type
97 {
99 SHORT = 2,
100 INT = 3,
102 UINT = 5,
103 FLOAT = 6,
106 CHAR = 9,
107 OCTET = 10,
108 STRUCT = 15,
109 STRING = 18,
110 ARRAY = 20
111 };
112
113 TagData(FILE * data_file, TagTable * tagtable, const string & tagname);
114 ~TagData();
115
116 int read(bool nodata = false);
117
118 private:
119 size_t typesize() const;
120 size_t typesize(int type) const;
121 int read_any(bool nodata = false);
122
123 vector < int >read_array_types();
124 int read_array_data(vector < int >item_types, bool nodata = false);
125 vector < int >read_struct_types();
126 string read_native(bool is_value_stored);
127 string read_string(int size);
128
129 private:
130 FILE * in;
132 string name;
134 };
135
136
138 {
139 public:
140 TagGroup(FILE * data_file, TagTable * tagtable, const string & groupname);
141 ~TagGroup();
142
143 int read(bool nodata = false);
144 string get_name() const;
145 int get_entry_id();
146
147 private:
148 FILE * in;
150 string name;
152 };
153
154
156 {
157 public:
159 {
161 DATA_TAG = 21
162 };
163
164 TagEntry(FILE * data_file, TagTable * tagtable, TagGroup * parent_group);
165 ~TagEntry();
166
167 int read(bool nodata = false);
168
169 private:
170 FILE * in;
173 string name;
174 };
175
176
178 {
179 public:
181 {
220 };
221 };
222
223 int to_em_datatype(int gatan_datatype);
224 const char *to_str(Gatan::TagData::Type type);
225 const char *to_str(Gatan::TagEntry::EntryType type);
226 const char *to_str(Gatan::DataType::GatanDataType type);
227 }
228
242 class DM3IO : public ImageIO
243 {
244 public:
245 explicit DM3IO(const string & fname, IOMode rw_mode = READ_ONLY);
246 ~DM3IO();
247
249 static bool is_valid(const void *first_block);
250
251 private:
252 enum
253 { NUM_ID_INT = 3 };
254
255 private:
258 };
259
260}
261
262
263
264
265#endif //__dm3io_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 DM3 file is a hierarchical binary image format.
Definition: dm3io.h:243
DM3IO(const string &fname, IOMode rw_mode=READ_ONLY)
Definition: dm3io.cpp:634
@ NUM_ID_INT
Definition: dm3io.h:253
DEFINE_IMAGEIO_FUNC
Definition: dm3io.h:248
Gatan::TagTable * tagtable
Definition: dm3io.h:257
static bool is_valid(const void *first_block)
Definition: dm3io.cpp:694
bool is_big_endian
Definition: dm3io.h:256
int read_array_data(vector< int >item_types, bool nodata=false)
Definition: dm3io.cpp:296
string read_string(int size)
Definition: dm3io.cpp:263
int read_any(bool nodata=false)
Definition: dm3io.cpp:389
TagData(FILE *data_file, TagTable *tagtable, const string &tagname)
Definition: dm3io.cpp:157
vector< int > read_array_types()
Definition: dm3io.cpp:233
size_t typesize() const
Definition: dm3io.cpp:473
string read_native(bool is_value_stored)
Definition: dm3io.cpp:166
TagTable * tagtable
Definition: dm3io.h:131
vector< int > read_struct_types()
Definition: dm3io.cpp:354
int read(bool nodata=false)
Definition: dm3io.cpp:438
int read(bool nodata=false)
Definition: dm3io.cpp:579
TagEntry(FILE *data_file, TagTable *tagtable, TagGroup *parent_group)
Definition: dm3io.cpp:570
TagGroup * parent_group
Definition: dm3io.h:172
TagTable * tagtable
Definition: dm3io.h:171
TagTable * tagtable
Definition: dm3io.h:149
TagGroup(FILE *data_file, TagTable *tagtable, const string &groupname)
Definition: dm3io.cpp:519
int read(bool nodata=false)
Definition: dm3io.cpp:528
string get_name() const
Definition: dm3io.cpp:556
char * get_data() const
Definition: dm3io.cpp:137
vector< int > x_list
Definition: dm3io.h:87
static const char * IMAGE_HEIGHT_TAG
Definition: dm3io.h:78
int get_datatype() const
Definition: dm3io.cpp:132
vector< int > datatype_list
Definition: dm3io.h:89
int get_int(const string &name)
Definition: dm3io.cpp:97
double get_double(const string &name)
Definition: dm3io.cpp:107
string get_string(const string &name)
Definition: dm3io.cpp:92
void become_host_endian(T *data, int n=1)
Definition: dm3io.h:65
void add(const string &name, const string &value)
Definition: dm3io.cpp:61
static const char * IMAGE_THUMB_INDEX_TAG
Definition: dm3io.h:80
static const char * IMAGE_WIDTH_TAG
Definition: dm3io.h:77
void set_thumb_index(int i)
Definition: dm3io.cpp:142
void set_endian(bool big_endian)
Definition: dm3io.h:71
void dump() const
Definition: dm3io.cpp:112
void add_data(char *data)
Definition: dm3io.cpp:82
int get_xsize() const
Definition: dm3io.cpp:122
int get_ysize() const
Definition: dm3io.cpp:127
float get_float(const string &name)
Definition: dm3io.cpp:102
vector< char * > data_list
Definition: dm3io.h:90
vector< int > y_list
Definition: dm3io.h:88
static const char * IMAGE_DATATYPE_TAG
Definition: dm3io.h:79
std::map< string, string > tags
Definition: dm3io.h:86
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: dm3io.cpp:894
const char * to_str(Gatan::TagData::Type type)
Definition: dm3io.cpp:925
E2Exception class.
Definition: aligner.h:40