Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

dm4io.h

Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  *
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  *
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  *
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  *
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033  *
00034  * */
00035 
00036 #ifndef __dm4io_h__
00037 #define __dm4io_h__
00038 
00039 #include "imageio.h"
00040 
00041 namespace EMAN
00042 {
00043         namespace GatanDM4
00044         {
00045                 class TagTable
00046                 {
00047                   public:
00048                         TagTable();
00049                         ~TagTable();
00050 
00051                         void add(const string & name, const string & value);
00052                         void add_data(char *data);
00053 
00054                         string get_string(const string & name);
00055                         int get_int(const string & name);
00056                         float get_float(const string & name);
00057                         double get_double(const string & name);
00058 
00059                         int get_xsize() const;
00060                         int get_ysize() const;
00061                         int get_datatype() const;
00062                         char *get_data() const;
00063 
00064                         void dump() const;
00065 
00066                         template < class T > void become_host_endian(T * data, int n = 1) {
00067                                 if (is_big_endian != ByteOrder::is_host_big_endian()) {
00068                                         ByteOrder::swap_bytes(data, n);
00069                                 }
00070                         }
00071 
00072                         void set_endian(bool big_endian)
00073                         {
00074                                 is_big_endian = big_endian;
00075                         }
00076 
00077                   private:
00078                         static const char *IMAGE_WIDTH_TAG;
00079                         static const char *IMAGE_HEIGHT_TAG;
00080                         static const char *IMAGE_DATATYPE_TAG;
00081                         static const char *IMAGE_THUMB_INDEX_TAG;
00082                         void set_thumb_index(int i);
00083 
00084                   private:
00085                         int img_index;
00086                         bool is_big_endian;
00087                         std::map < string, string > tags;
00088                         vector < int >x_list;
00089                         vector < int >y_list;
00090                         vector < int >datatype_list;
00091                         vector < char *>data_list;
00092                 };
00093 
00094                 class TagData
00095                 {
00096                   public:
00097                         enum Type
00098                         {
00099                                 UNKNOWN = 0,
00100                                 SHORT = 2,
00101                                 INT = 3,
00102                                 USHORT = 4,
00103                                 UINT = 5,
00104                                 FLOAT = 6,
00105                                 DOUBLE = 7,
00106                                 BOOLEAN = 8,
00107                                 CHAR = 9,
00108                                 OCTET = 10,
00109                                 OCTEU = 11,
00110                                 OCTEV = 12,
00111                                 STRUCT = 15,
00112                                 STRING = 18,
00113                                 ARRAY = 20
00114                         };
00115 
00116                         TagData(FILE * data_file, TagTable * tagtable, const string & tagname);
00117                         ~TagData();
00118 
00119                         int read(bool nodata = false);
00120 
00121                   private:
00122                         size_t typesize() const;
00123                         size_t typesize(int type) const;
00124                         int read_any(bool nodata = false);
00125 
00126                         vector < int >read_array_types();
00127                         int read_array_data(vector < int >item_types, bool nodata = false);
00128                         vector < int >read_struct_types();
00129                         string read_native(bool is_value_stored);
00130                         string read_string(int size);
00131 
00132                   private:
00133                         FILE * in;
00134                         TagTable *tagtable;
00135                         string name;
00136                         long tag_type;
00137                 };
00138 
00139 
00140                 class TagGroup
00141                 {
00142                   public:
00143                         TagGroup(FILE * data_file, TagTable * tagtable, const string & groupname);
00144                         ~TagGroup();
00145 
00146                         int read(bool nodata = false);
00147                         string get_name() const;
00148                         int get_entry_id();
00149 
00150                   private:
00151                         FILE * in;
00152                         TagTable *tagtable;
00153                         string name;
00154                         int entry_id;
00155                 };
00156 
00157 
00158                 class TagEntry
00159                 {
00160                   public:
00161                         enum EntryType
00162                         {
00163                                 GROUP_TAG = 20,
00164                                 DATA_TAG = 21
00165                         };
00166 
00167                         TagEntry(FILE * data_file, TagTable * tagtable, TagGroup * parent_group);
00168                         ~TagEntry();
00169 
00170                         int read(bool nodata = false);
00171 
00172                   private:
00173                         FILE * in;
00174                         TagTable *tagtable;
00175                         TagGroup *parent_group;
00176                         string name;
00177                 };
00178 
00179 
00180                 class DataType
00181                 {
00182                   public:
00183                         enum GatanDataType
00184                         {
00185                                 NULL_DATA,
00186                                 SIGNED_INT16_DATA,
00187                                 REAL4_DATA,
00188                                 COMPLEX8_DATA,
00189                                 OBSELETE_DATA,
00190                                 PACKED_DATA,
00191                                 UNSIGNED_INT8_DATA,
00192                                 SIGNED_INT32_DATA,
00193                                 RGB_DATA,
00194                                 SIGNED_INT8_DATA,
00195                                 UNSIGNED_INT16_DATA,
00196                                 UNSIGNED_INT32_DATA,
00197                                 REAL8_DATA,
00198                                 COMPLEX16_DATA,
00199                                 BINARY_DATA,
00200                                 RGB_UINT8_0_DATA,
00201                                 RGB_UINT8_1_DATA,
00202                                 RGB_UINT16_DATA,
00203                                 RGB_FLOAT32_DATA,
00204                                 RGB_FLOAT64_DATA,
00205                                 RGBA_UINT8_0_DATA,
00206                                 RGBA_UINT8_1_DATA,
00207                                 RGBA_UINT8_2_DATA,
00208                                 RGBA_UINT8_3_DATA,
00209                                 RGBA_UINT16_DATA,
00210                                 RGBA_FLOAT32_DATA,
00211                                 RGBA_FLOAT64_DATA,
00212                                 POINT2_SINT16_0_DATA,
00213                                 POINT2_SINT16_1_DATA,
00214                                 POINT2_SINT32_0_DATA,
00215                                 POINT2_FLOAT32_0_DATA,
00216                                 RECT_SINT16_1_DATA,
00217                                 RECT_SINT32_1_DATA,
00218                                 RECT_FLOAT32_1_DATA,
00219                                 RECT_FLOAT32_0_DATA,
00220                                 SIGNED_INT64_DATA,
00221                                 UNSIGNED_INT64_DATA,
00222                                 LAST_DATA
00223                         };
00224                 };
00225 
00226                 int to_em_datatype(int gatan_datatype);
00227                 const char *to_str(GatanDM4::TagData::Type type);
00228                 const char *to_str(GatanDM4::TagEntry::EntryType type);
00229                 const char *to_str(GatanDM4::DataType::GatanDataType type);
00230 
00231         }
00232 
00250         class DM4IO : public ImageIO
00251         {
00252           public:
00253                 explicit DM4IO(const string & filename, IOMode rw_mode = READ_ONLY);
00254                 ~DM4IO();
00255 
00256                 DEFINE_IMAGEIO_FUNC;
00257                 static bool is_valid(const void *first_block);
00258 
00259           private:
00260                 enum { NUM_ID_INT = 4 };        //actually its int+long+int=16 bytes
00261 
00262                 string filename;
00263                 IOMode rw_mode;
00264                 FILE *dm4file;
00265                 bool is_big_endian;
00266                 bool initialized;
00267                 GatanDM4::TagTable * tagtable;
00268         };
00269 
00270 
00271 
00272 
00273 }
00274 
00275 #endif  //__dm4io_h__

Generated on Tue Jun 11 13:40:37 2013 for EMAN2 by  doxygen 1.3.9.1