EMAN2
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
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]
LstIO::~LstIO ( )

Definition at line 68 of file lstio.cpp.

References imageio, lst_file, and ref_filename.

{
        if (lst_file) {
                fclose(lst_file);
                lst_file = 0;
        }
        ref_filename = "";
        if(imageio) {
                delete imageio;
                imageio = 0;
        }
}

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.

{
        if (image_index == last_lst_index) {
                return last_ref_index;
        }
        else {
                char buf[MAXPATHLEN];
                int step = image_index - last_lst_index;

                if (step < 0) {
                        rewind(lst_file);
                        step = image_index + 1;
                }

                for (int i = 0; i < step; i++) {
                        if (!fgets(buf, MAXPATHLEN, lst_file)) {
                                LOGERR("reach EOF in file '%s' before reading %dth image",
                                           filename.c_str(), image_index);
                                return 1;
                        }
                        if (buf[0] == '#') {
                                i--;
                        }
                }
                int ref_image_index = 0;
                char ref_image_path[MAXPATHLEN];
                char unused[256];
                sscanf(buf, " %d %s %[ .,0-9-]", &ref_image_index, ref_image_path, unused);

                char fullpath[MAXPATHLEN];

                char sep = '/';
#ifdef WIN32
                sep = '\\';
#endif
//              if (ref_image_path[0] == sep) {
                        strcpy(fullpath, ref_image_path);
//              }
//              else {
//                      if (strrchr(filename.c_str(), sep)) {
//                              strcpy(fullpath, filename.c_str());
//                      }
//                      else {
// #ifndef WIN32
//                              getcwd(fullpath, MAXPATHLEN);
// #else
//                              //GetCurrentDirectory(MAXPATHLEN, fullpath);
// #endif
//                      }
// 
//                      char *p_basename = strrchr(fullpath, sep);
//                      if (p_basename) {
//                              //p_basename++;
//                              //*p_basename = '\0';
//                              char ssep[2];
//                              ssep[0] = sep;
//                              ssep[1] = '\0';
//                              strcat(fullpath, ssep);
//                              strcat(fullpath, ref_image_path);
//                      }
//              }

                ref_filename = string(fullpath);
                imageio = EMUtil::get_imageio(ref_filename, rw_mode);

                last_ref_index = ref_image_index;
        }

        last_lst_index = image_index;

        return last_ref_index;
}
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.

{
        init();
        return nimg;
}
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.

                {
                        return false;
                }
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().

{
        ENTERFUNC;
        bool result = false;

        if (!first_block) {
                result = false;
        }
        else {
                result = Util::check_file_by_magic(first_block, MAGIC);
        }

        EXITFUNC;
        return result;
}

Member Data Documentation

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().

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().

Definition at line 68 of file lstio.h.

Referenced by LstIO().

Definition at line 75 of file lstio.h.

Referenced by calc_ref_image_index(), and LstIO().

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().

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: