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

imageio.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 eman__imageio_h__
00037 #define eman__imageio_h__ 1
00038 
00039 #include "byteorder.h"
00040 #include "emutil.h"
00041 
00042 using std::vector;
00043 using std::string;
00044 
00045 namespace EMAN
00046 {
00047         class Region;
00048         class FloatSize;
00049         class IntSize;
00050         class Ctf;
00051 
00130         class ImageIO
00131         {
00132           public:
00133                 enum IOMode
00134                 { READ_ONLY = 1, READ_WRITE = 2, WRITE_ONLY = 3 };
00135           public:
00136                 virtual ~ ImageIO();
00137 
00148                 virtual int read_header(Dict & dict, int image_index = 0,
00149                                                                 const Region * area = 0, bool is_3d = false) = 0;
00150 
00162                 virtual int write_header(const Dict & dict,
00163                                                                  int image_index = 0,
00164                                                                  const Region * area = 0,
00165                                                                  EMUtil::EMDataType filestoragetype = EMUtil::EM_FLOAT,
00166                                                                  bool use_host_endian = true) = 0;
00167 
00179                 virtual int read_data(float *data, int image_index = 0,
00180                                                           const Region * area = 0, bool is_3d = false) = 0;
00181 
00193                 virtual int write_data(float *data,
00194                                                            int image_index = 0,
00195                                                            const Region * area = 0,
00196                                                            EMUtil::EMDataType filestoragetype = EMUtil::EM_FLOAT,
00197                                                            bool use_host_endian = true) = 0;
00198 
00205                 virtual int read_ctf(Ctf & ctf, int image_index = 0);
00206 
00213                 virtual void write_ctf(const Ctf & ctf, int image_index = 0);
00214 
00217                 virtual void flush() = 0;
00218 
00220                 virtual int get_nimg();
00221 
00223                 virtual bool is_complex_mode() = 0;
00224 
00226                 virtual bool is_image_big_endian() = 0;
00227 
00234                 virtual bool is_single_image_format() const
00235                 {
00236                         return true;
00237                 }
00238 
00245                 template < class T > void become_host_endian(T * data, size_t n = 1)
00246                 {
00247                         if (is_image_big_endian() != ByteOrder::is_host_big_endian()) {
00248                                 ByteOrder::swap_bytes(data, n);
00249                         }
00250                 }
00251 
00252         protected:
00255                 virtual void init() = 0;
00256 
00262                 void check_read_access(int image_index);
00263 
00271                 void check_read_access(int image_index, const float *data);
00272 
00282                 void check_write_access(IOMode rw_mode, int image_index, int max_nimg = 0);
00283 
00294                 void check_write_access(IOMode rw_mode, int image_index, int max_nimg,
00295                                                                 const float *data);
00296 
00305                 void check_region(const Region * area, const FloatSize & max_size,
00306                                                   bool is_new_file = false, bool inbounds_only=true);
00307 
00317                 void check_region(const Region * area, const IntSize & max_size,
00318                                                   bool is_new_file = false, bool inbounds_only=true);
00319 
00329                 FILE *sfopen(const string & filename, IOMode mode,
00330                                          bool * is_new = 0, bool overwrite = false);
00331         };
00332 
00336 #define DEFINE_IMAGEIO_FUNC \
00337                 int read_header(Dict & dict, int image_index = 0, const Region* area = 0, bool is_3d = false); \
00338                 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); \
00339                 int read_data(float* data, int image_index = 0, const Region* area = 0, bool is_3d = false); \
00340                 int write_data(float* data, int image_index = 0, const Region * area = 0, EMUtil::EMDataType filestoragetype = EMUtil::EM_FLOAT, bool use_host_endian = true); \
00341                 void flush(); \
00342                 bool is_complex_mode(); \
00343                 bool is_image_big_endian(); \
00344                 void init()
00345 
00346 }
00347 
00348 
00349 #endif  //eman__imageio_h__

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