EMAN::LstIO Class Reference

A LST file is an ASCII file that contains a list of image file names. More...

#include <lstio.h>

Inheritance diagram for EMAN::LstIO:

Inheritance graph
[legend]
Collaboration diagram for EMAN::LstIO:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 LstIO (const string &filename, IOMode rw_mode=READ_ONLY)
 ~LstIO ()
bool is_single_image_format () const
 Is this image format only storing 1 image or not.
int get_nimg ()
 Return the number of images in this image file.

Static Public Member Functions

static bool is_valid (const void *first_block)

Public Attributes

 DEFINE_IMAGEIO_FUNC

Private Member Functions

int calc_ref_image_index (int image_index)

Private Attributes

string filename
IOMode rw_mode
FILE * lst_file
bool is_big_endian
bool initialized
int nimg
ImageIOimageio
string ref_filename
int last_lst_index
int last_ref_index

Static Private Attributes

static const char * MAGIC = "#LST"

Detailed Description

A LST file is an ASCII file that contains a list of image file names.

Each line of a LST file has the following format: reference_image_index reference-image-filename comments

Definition at line 49 of file lstio.h.


Constructor & Destructor Documentation

LstIO::LstIO ( const string &  filename,
IOMode  rw_mode = READ_ONLY 
) [explicit]

Definition at line 56 of file lstio.cpp.

References imageio, initialized, is_big_endian, EMAN::ByteOrder::is_host_big_endian(), last_lst_index, last_ref_index, nimg, and ref_filename.

00057 :       filename(file), rw_mode(rw), lst_file(0)
00058 {
00059         is_big_endian = ByteOrder::is_host_big_endian();
00060         initialized = false;
00061         nimg = 0;
00062         imageio = 0;
00063         ref_filename = "";
00064         last_lst_index = -1;
00065         last_ref_index = -1;
00066 }

LstIO::~LstIO (  ) 

Definition at line 68 of file lstio.cpp.

References imageio, lst_file, and ref_filename.

00069 {
00070         if (lst_file) {
00071                 fclose(lst_file);
00072                 lst_file = 0;
00073         }
00074         ref_filename = "";
00075         if(imageio) {
00076                 delete imageio;
00077                 imageio = 0;
00078         }
00079 }


Member Function Documentation

int LstIO::calc_ref_image_index ( int  image_index  )  [private]

Definition at line 131 of file lstio.cpp.

References filename, EMAN::EMUtil::get_imageio(), imageio, last_lst_index, last_ref_index, LOGERR, lst_file, ref_filename, and rw_mode.

00132 {
00133         if (image_index == last_lst_index) {
00134                 return last_ref_index;
00135         }
00136         else {
00137                 char buf[MAXPATHLEN];
00138                 int step = image_index - last_lst_index;
00139 
00140                 if (step < 0) {
00141                         rewind(lst_file);
00142                         step = image_index + 1;
00143                 }
00144 
00145                 for (int i = 0; i < step; i++) {
00146                         if (!fgets(buf, MAXPATHLEN, lst_file)) {
00147                                 LOGERR("reach EOF in file '%s' before reading %dth image",
00148                                            filename.c_str(), image_index);
00149                                 return 1;
00150                         }
00151                         if (buf[0] == '#') {
00152                                 i--;
00153                         }
00154                 }
00155                 int ref_image_index = 0;
00156                 char ref_image_path[MAXPATHLEN];
00157                 char unused[256];
00158                 sscanf(buf, " %d %s %[ .,0-9-]", &ref_image_index, ref_image_path, unused);
00159 
00160                 char fullpath[MAXPATHLEN];
00161 
00162                 char sep = '/';
00163 #ifdef WIN32
00164                 sep = '\\';
00165 #endif
00166                 if (ref_image_path[0] == sep) {
00167                         strcpy(fullpath, ref_image_path);
00168                 }
00169                 else {
00170                         if (strrchr(filename.c_str(), sep)) {
00171                                 strcpy(fullpath, filename.c_str());
00172                         }
00173                         else {
00174 #ifndef WIN32
00175                                 getcwd(fullpath, MAXPATHLEN);
00176 #else
00177                                 //GetCurrentDirectory(MAXPATHLEN, fullpath);
00178 #endif
00179                         }
00180 
00181                         char *p_basename = strrchr(fullpath, sep);
00182                         if (p_basename) {
00183                                 //p_basename++;
00184                                 //*p_basename = '\0';
00185                                 char ssep[2];
00186                                 ssep[0] = sep;
00187                                 ssep[1] = '\0';
00188                                 strcat(fullpath, ssep);
00189                                 strcat(fullpath, ref_image_path);
00190                         }
00191                 }
00192 
00193                 ref_filename = string(fullpath);
00194                 imageio = EMUtil::get_imageio(ref_filename, rw_mode);
00195 
00196                 last_ref_index = ref_image_index;
00197         }
00198 
00199         last_lst_index = image_index;
00200 
00201         return last_ref_index;
00202 }

int LstIO::get_nimg (  )  [virtual]

Return the number of images in this image file.

Reimplemented from EMAN::ImageIO.

Definition at line 260 of file lstio.cpp.

References EMAN::ImageIO::init(), and nimg.

00261 {
00262         init();
00263         return nimg;
00264 }

bool EMAN::LstIO::is_single_image_format (  )  const [inline, virtual]

Is this image format only storing 1 image or not.

Some image formats like MRC only store 1 image in a file, so this function returns 'true' for them. Other image formats like IMAGIC/HDF5 may store mutliple images, so this function returns 'false' for them.

Reimplemented from EMAN::ImageIO.

Definition at line 58 of file lstio.h.

00059                 {
00060                         return false;
00061                 }

bool LstIO::is_valid ( const void *  first_block  )  [static]

Definition at line 115 of file lstio.cpp.

References EMAN::Util::check_file_by_magic(), ENTERFUNC, EXITFUNC, and MAGIC.

Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type().

00116 {
00117         ENTERFUNC;
00118         bool result = false;
00119 
00120         if (!first_block) {
00121                 result = false;
00122         }
00123         else {
00124                 result = Util::check_file_by_magic(first_block, MAGIC);
00125         }
00126 
00127         EXITFUNC;
00128         return result;
00129 }


Member Data Documentation

EMAN::LstIO::DEFINE_IMAGEIO_FUNC

Definition at line 55 of file lstio.h.

string EMAN::LstIO::filename [private]

Definition at line 64 of file lstio.h.

Referenced by calc_ref_image_index().

ImageIO* EMAN::LstIO::imageio [private]

Definition at line 72 of file lstio.h.

Referenced by calc_ref_image_index(), LstIO(), and ~LstIO().

bool EMAN::LstIO::initialized [private]

Definition at line 69 of file lstio.h.

Referenced by LstIO().

bool EMAN::LstIO::is_big_endian [private]

Definition at line 68 of file lstio.h.

Referenced by LstIO().

int EMAN::LstIO::last_lst_index [private]

Definition at line 75 of file lstio.h.

Referenced by calc_ref_image_index(), and LstIO().

int EMAN::LstIO::last_ref_index [private]

Definition at line 76 of file lstio.h.

Referenced by calc_ref_image_index(), and LstIO().

FILE* EMAN::LstIO::lst_file [private]

Definition at line 66 of file lstio.h.

Referenced by calc_ref_image_index(), and ~LstIO().

const char * LstIO::MAGIC = "#LST" [static, private]

Definition at line 79 of file lstio.h.

Referenced by is_valid().

int EMAN::LstIO::nimg [private]

Definition at line 70 of file lstio.h.

Referenced by get_nimg(), and LstIO().

string EMAN::LstIO::ref_filename [private]

Definition at line 73 of file lstio.h.

Referenced by calc_ref_image_index(), LstIO(), and ~LstIO().

IOMode EMAN::LstIO::rw_mode [private]

Definition at line 65 of file lstio.h.

Referenced by calc_ref_image_index().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 12:43:16 2013 for EMAN2 by  doxygen 1.4.7